Embedding a Wetware server in a third-party application is currently tedious due to extensive boilerplate. This boilerplate comes from three sources:
pkg/server uses Fx for dependency-injection but nonetheless requires us to instantiate, configure, start and stop the Fx application itself.
server.Node comprises multiple sub-services whose startup/shutdown logic logic needs to be carefully orchestrated.
Early iterations of Wetware focused heavily on configurability, so the public API for pkg/server exposes a lot of internals.
The goal of this PR is to provide a dead-simple mechanism for embedding servers. It adds a top level server/ package, within which all three sources of complexity are remedied as follows:
No use of Fx anywhere
Use of blocking Serve / ListenAndServe methods, similar to net/http
Reduced configuration options
A wetware server is now embedded as follows:
// config file is designed to take simple types, which makes it
// easier to populate from CLI parameters.
config := server.Config{
Logger: log.New(),
NS: "my-namespace",
Join: <optional array of bootstrap peers>
Discover: <optional multiaddr to discovery service>,
Meta: <optional map of key/value pairs>,
}
// blocks until the context expires; returns context's error
err := config.ListenAndServe(ctx, c.StringSlice("listen")...)
Contrary to the previous version, server capabilities are not directly accessible since there is no equivalent of the server.Node type. Applications requiring access to the server's capability will have to dial a client connection to the local server. Future work will facilitate this.
Embedding a Wetware server in a third-party application is currently tedious due to extensive boilerplate. This boilerplate comes from three sources:
pkg/server
uses Fx for dependency-injection but nonetheless requires us to instantiate, configure, start and stop the Fx application itself.server.Node
comprises multiple sub-services whose startup/shutdown logic logic needs to be carefully orchestrated.pkg/server
exposes a lot of internals.The goal of this PR is to provide a dead-simple mechanism for embedding servers. It adds a top level
server/
package, within which all three sources of complexity are remedied as follows:Serve
/ListenAndServe
methods, similar tonet/http
A wetware server is now embedded as follows:
Contrary to the previous version, server capabilities are not directly accessible since there is no equivalent of the
server.Node
type. Applications requiring access to the server's capability will have to dial a client connection to the local server. Future work will facilitate this.