Add and use NetworkService class.

This generalises a large swathe of the BAPS service, and should make it
easier to write future network-based services.