Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Fx from server implementation #138

Merged
merged 6 commits into from
Jul 27, 2023
Merged

Remove Fx from server implementation #138

merged 6 commits into from
Jul 27, 2023

Conversation

lthibault
Copy link
Collaborator

Embedding a Wetware server in a third-party application is currently tedious due to extensive boilerplate. This boilerplate comes from three sources:

  1. pkg/server uses Fx for dependency-injection but nonetheless requires us to instantiate, configure, start and stop the Fx application itself.
  2. server.Node comprises multiple sub-services whose startup/shutdown logic logic needs to be carefully orchestrated.
  3. 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:

  1. No use of Fx anywhere
  2. Use of blocking Serve / ListenAndServe methods, similar to net/http
  3. 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.

@lthibault lthibault added the enhancement New feature or request label Jul 27, 2023
@lthibault lthibault requested a review from mikelsr July 27, 2023 13:27
@lthibault lthibault self-assigned this Jul 27, 2023
@lthibault lthibault merged commit 06f4805 into v0.1.0 Jul 27, 2023
@lthibault lthibault deleted the feat/nofx-server branch July 27, 2023 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant