59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package daemon
|
|
|
|
import (
|
|
"context"
|
|
"isle/bootstrap"
|
|
"isle/daemon/jsonrpc2"
|
|
"isle/daemon/network"
|
|
"isle/nebula"
|
|
"net/http"
|
|
)
|
|
|
|
// RPC defines the methods which the Daemon exposes over RPC (via the RPCHandler
|
|
// or HTTPHandler methods). Method documentation can be found on the Daemon
|
|
// type.
|
|
type RPC interface {
|
|
CreateNetwork(
|
|
ctx context.Context,
|
|
name string,
|
|
domain string,
|
|
ipNet nebula.IPNet,
|
|
hostName nebula.HostName,
|
|
) error
|
|
|
|
JoinNetwork(context.Context, network.JoiningBootstrap) error
|
|
|
|
GetNetworks(context.Context) ([]bootstrap.CreationParams, error)
|
|
|
|
// All network.RPC methods are automatically implemented by Daemon using the
|
|
// currently joined network. If no network is joined then any call to these
|
|
// methods will return ErrNoNetwork.
|
|
//
|
|
// All calls to these methods must be accompanied with a context produced by
|
|
// WithNetwork, in order to choose the network. These methods may return
|
|
// these errors, in addition to those documented on the individual methods:
|
|
//
|
|
// Errors:
|
|
// - ErrNoMatchingNetworks
|
|
// - ErrMultipleMatchingNetworks
|
|
network.RPC
|
|
}
|
|
|
|
// RPCHandler returns a jsonrpc2.Handler which will use the Daemon to serve all
|
|
// methods defined on the RPC interface.
|
|
func (d *Daemon) RPCHandler() jsonrpc2.Handler {
|
|
rpc := RPC(d)
|
|
return jsonrpc2.Chain(
|
|
jsonrpc2.NewMLogMiddleware(d.logger.WithNamespace("rpc")),
|
|
jsonrpc2.ExposeServerSideErrorsMiddleware,
|
|
)(
|
|
jsonrpc2.NewDispatchHandler(&rpc),
|
|
)
|
|
}
|
|
|
|
// HTTPRPCHandler returns an http.Handler which will use the Daemon to serve all
|
|
// methods defined on the RPC interface via the JSONRPC2 protocol.
|
|
func (d *Daemon) HTTPRPCHandler() http.Handler {
|
|
return jsonrpc2.NewHTTPHandler(d.RPCHandler())
|
|
}
|