@benfrancis you already discussed about moving device specific api’s to a node server. Is there a possibility to do that (quickly) ? So that we don’t interfere with gecko.
There are a list of 30 APIs we’d like to remove from Gecko or migrate into local web services, 10 have been removed so far and at least one other is in progress.
We have a proof of concept WiFi daemon which could replace the WiFi API and serve as a blueprint for other system services, but as far as I know nobody is actively working on this (contributions welcome!).
However, it is basically impossible to build Boot to Gecko without “interfering” with Gecko as you put it. It may be possible to move some Gonk back ends for standard web APIs like the W3C Vibration API, W3C Battery API and W3C Wake Lock API out of the mozilla-central repository in some way, but as a minimum we need the Gonk widget layer and A/V back end, the Browser API, Input Method API and probably the Camera Control API. Out of those only the Browser API is used by Firefox.
Due to the monolithic nature of Gecko’s architecture and lack of embedding APIs it’s currently impossible to build B2G without having at least some code in mozilla-central. The B2G community could fork Gecko and create the “Boot to [fork of Gecko]” project, but maintaining a fork of an entire web rendering engine is a huge task and it would no longer really be “Boot to Gecko”.
So yes, we should be worried about it.
While we should be worried, we should also start the work of implementing those APIs outside of Gecko: that will prove that we are committed and serious, and at the same time lower the maintainance burden for everyone. Anyone disagrees ?
It would be like a big add-on or plugin ?
IMHO more like something completely separate handled at build time. The WiFi example linked by Ben earlier is what we should work on: node.js (or anything else) living next to Gecko.
I know some people would prefer we make use of Rust :). I’d be happy with any.
But we will have to send and receive data between gecko and this other server.js ? :-/
( ok, with a little script to split the system and front-end part, it could be automatic and I won’t have to take care about this communication to develop an app, but it’s a little bit ugly :-/ … and to debug … )
please explain the possibilities of adding nodejs & npm to b2g os ? We have many npm modules phone becomes a full fledged server
The big picture as Ben and Alex said is that we need a system daemon that gaia talks to. It’s not very different from what we do already for eg. bluetooth and even with the RIL daemon, except that these talk to gecko through some IPC.
Since gaia is web based and can’t use things like unix domain sockets for IPC, we will have to go with http and/or websocket (I think websocket is enough) to communicate with the daemon. I’m not worried about the performance here, this is not gonna be a high traffic service. What we need to figure out though is how to get that secure to prevent a random webpage to connect to the system websocket.
From an implementation point of view, I’m the Rust fan This is the perfect choice for such a system daemon. We should start with a simple case like wifi (rewriting the node.js one in Rust) to test the waters. Some features will be very hard to move out of gecko, like the telephony stack (look at http://searchfox.org/mozilla-central/source/dom/system/gonk/ril_worker.js for a taste of the complexity) but we can still start with all the easier ones.
I’m a Rust fan too, that’s the one language I almost understand a bit. I see the benefits in being independent from gecko code. Do you think we have the man-power and know-how to do something like that? How long may it take? And will Mozilla tolerate b2g code in gecko for so long?
The only way to really know is to try. That won’t be easy but it’s not impossible to achieve.
And coming from someone who was part of the early B2G kick starter, it means something
I have to admit I took part into that
Is a single system daemon that does all system-related tasks in one envisaged, or could it be a loosely coupled collection of system “micro-services” that each perform a separate job? e.g. network manager, RIL manager, etc etc.
The benefits of using D-Bus would be:
- Already builds on Android (see here); only dependency is glib, I think
- A large number of system services already talk to D-Bus, including:
- Flexible authentication
- Can handle starting and stopping services on-demand
- Rust support exists, so d-bus services that we lack could be written in Rust
- Any D-bus services written for B2G OS might get use/support from other projects as well.
- Can talk over TCP already.
Websockify allows us to wrap any TCP socket server and turn it into a websocket server, ideally talking the binary ws protocol. The benefits to using websockify would be:
- AS I understand it, emscripten has limited support for compiling BSD socket code from C into websockify code (see here). That may make it easier to get a dbus client on the web up and running.
- There are several implementations, including an nginx module – something will hopefully work on android, or we could write a rust version of websockify perhaps.
- Potentially zero coding necessary to get something basic going
It might be that this setup is far too heavy or dangerous to be used in production. However, we might still benefit from adopting the d-bus protocol even if we didn’t end up using d-bus itself. In that case, using d-bus itself to begin with would be a fast way to get going, and we could change it out for something leaner that quacks the same at a later stage. The same would go for using d-bus with any of the above services.
There are I’m sure lots of alternatives to websockify. We could for instance look into serializing the dbus protocol into JSON. I’ve had a quick look online and found the following existing efforts:
- The cockpit project has something called dbus-json3
- … err, that’s all.
Why not use D-Bus directly in an Add-on/pluggin instead of communicate by wraping all with websocket ?
This could be an option too. The reason not to go this way at the moment would be that we don’t have an addon/plugin system available in b2g (as far as I know).
However, if we are using dbus anyway then switching from a websocket to a native connection would presumably be easier than if we used some custom protocol
Traditionnal add-ons are not an option, since that would mean using chrome JS in gaia which is a no-go. So websockets are really the only option from a protocol point of view. I don’t expect performance issues, it’s not like we have that much data to transfer around.
About using d-bus, why not if that gives easier access to some features. Actually the first one to prototype would be mozAlarams since the old backend was removed from Gecko.
Is there any support for Rust in the Gonk build system to start developping a prototype devicesvcd in Rust?
For anyone interested, here’s what I have achieved so far: