Documentation ¶
Index ¶
- Constants
- func NameFromAddr(localAddr fmt.Stringer) string
- func Start(logger *zap.Logger, config *Config, up chan *Librarian) error
- type Config
- func (c *Config) WithBootstrapAddrs(bootstrapAddrs []*net.TCPAddr) *Config
- func (c *Config) WithDBDir(dbDir string) *Config
- func (c *Config) WithDataDir(dataDir string) *Config
- func (c *Config) WithDefaultBootstrapAddrs() *Config
- func (c *Config) WithDefaultDBDir() *Config
- func (c *Config) WithDefaultDataDir() *Config
- func (c *Config) WithDefaultIntroduce() *Config
- func (c *Config) WithDefaultLocalMetricsPort() *Config
- func (c *Config) WithDefaultLocalPort() *Config
- func (c *Config) WithDefaultLocalProfilerPort() *Config
- func (c *Config) WithDefaultLogLevel() *Config
- func (c *Config) WithDefaultProfile() *Config
- func (c *Config) WithDefaultPublicAddr() *Config
- func (c *Config) WithDefaultPublicName() *Config
- func (c *Config) WithDefaultReplicate() *Config
- func (c *Config) WithDefaultReportMetrics() *Config
- func (c *Config) WithDefaultRouting() *Config
- func (c *Config) WithDefaultSearch() *Config
- func (c *Config) WithDefaultStore() *Config
- func (c *Config) WithDefaultSubscribeFrom() *Config
- func (c *Config) WithDefaultSubscribeTo() *Config
- func (c *Config) WithIntroduce(params *introduce.Parameters) *Config
- func (c *Config) WithLocalMetricsPort(localMetricsPort int) *Config
- func (c *Config) WithLocalPort(localPort int) *Config
- func (c *Config) WithLocalProfilerPort(localProfilerPort int) *Config
- func (c *Config) WithLogLevel(logLevel zapcore.Level) *Config
- func (c *Config) WithOrgID(orgID ecid.ID) *Config
- func (c *Config) WithProfile(profile bool) *Config
- func (c *Config) WithPublicAddr(publicAddr *net.TCPAddr) *Config
- func (c *Config) WithPublicName(publicName string) *Config
- func (c *Config) WithReplicate(params *replicate.Parameters) *Config
- func (c *Config) WithReportMetrics(reportMetrics bool) *Config
- func (c *Config) WithRouting(params *routing.Parameters) *Config
- func (c *Config) WithSearch(params *search.Parameters) *Config
- func (c *Config) WithStore(params *store.Parameters) *Config
- func (c *Config) WithSubscribeFrom(params *subscribe.FromParameters) *Config
- func (c *Config) WithSubscribeTo(params *subscribe.ToParameters) *Config
- type Librarian
- func (l *Librarian) Close() error
- func (l *Librarian) CloseAndRemove() error
- func (l *Librarian) Find(ctx context.Context, rq *api.FindRequest) (*api.FindResponse, error)
- func (l *Librarian) Get(ctx context.Context, rq *api.GetRequest) (*api.GetResponse, error)
- func (l *Librarian) Introduce(ctx context.Context, rq *api.IntroduceRequest) (*api.IntroduceResponse, error)
- func (l *Librarian) NewResponseMetadata(m *api.RequestMetadata) *api.ResponseMetadata
- func (l *Librarian) Put(ctx context.Context, rq *api.PutRequest) (*api.PutResponse, error)
- func (l *Librarian) StopAuxRoutines()
- func (l *Librarian) Store(ctx context.Context, rq *api.StoreRequest) (*api.StoreResponse, error)
- func (l *Librarian) Subscribe(rq *api.SubscribeRequest, from api.Librarian_SubscribeServer) error
- func (l *Librarian) Verify(ctx context.Context, rq *api.VerifyRequest) (*api.VerifyResponse, error)
- type RequestVerifier
Constants ¶
const ( // DefaultPort is the default port of both local and public addresses. DefaultPort = 20100 // DefaultMetricsPort is the default port to serve metrics from. DefaultMetricsPort = 20200 // DefaultProfilerPort is the default port to serve profiling from. DefaultProfilerPort = 20300 // DefaultIP is the default IP of both local and public addresses. DefaultIP = "localhost" // DefaultLogLevel is the default log level to use. DefaultLogLevel = zap.InfoLevel // DataSubdir is the name of the data directory. DataSubdir = "librarian-data" // DBSubDir is the default DB subdirectory within the data dir. DBSubDir = "db" )
const ( // LoggerPortKey is the logger key used for address ports. LoggerPortKey = "port" // LoggerSeeds is the logger key used for the seeds of a bootstrap operation. LoggerSeeds = "seeds" // LoggerNBootstrappedPeers is the logger key used for the number of peers found // during a bootstrap operation. LoggerNBootstrappedPeers = "n_peers" )
const ( // LoggerPeerID is a peer ID. LoggerPeerID = "peerId" // NumPeers is a number of peers. NumPeers = "numPeers" // NumBuckets is a number of routing table buckets. NumBuckets = "numBuckets" )
logger keys
Variables ¶
This section is empty.
Functions ¶
func NameFromAddr ¶
NameFromAddr gives the local name (on the host) of the node using the NodeIndex
Types ¶
type Config ¶
type Config struct { // LocalPort is the local port the main grpc server listens to. LocalPort int // LocalMetricsPort is the local port the metrics server listens to. LocalMetricsPort int // LocalProfilerPort is the local port the profile server listens to (when it is enabled). LocalProfilerPort int // PublicAddr is the public address clients make requests to. PublicAddr *net.TCPAddr // PublicName is the public facing name of the peer. PublicName string // OrgID is the organization ID of the peer, if one exists. OrgID ecid.ID // DataDir is the directory on the local machine where the state and output of all the // peer running on that machine are stored. DataDir string // DbDir is the local directory where this node's DB state is stored. DbDir string // BootstrapAddrs is a list of addresses for bootstrap peers. BootstrapAddrs []*net.TCPAddr // Routing defines parameters for the server's routing table. Routing *routing.Parameters // Introduce defines parameters for introductions the server performs. Introduce *introduce.Parameters // Search defines parameters for searches the server performs. Search *search.Parameters // Store defines parameters for stores the server performs. Store *store.Parameters // Replicate defines parameters for replications the server performs. Replicate *replicate.Parameters // SubscribeTo defines parameters for subscriptions to other peers. SubscribeTo *subscribe.ToParameters // SubscribeFrom defines parameters for subscriptions to other peers. SubscribeFrom *subscribe.FromParameters // ReportMetrics determines whether the server reports Prometheus metrics. ReportMetrics bool // Profile determines whether the profiler endpoint (/debug/pprof) is enabled. Profile bool // LogLevel is the log level LogLevel zapcore.Level }
Config is used to configure a Librarian server
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
NewDefaultConfig returns a reasonable default server configuration.
func (*Config) WithBootstrapAddrs ¶
WithBootstrapAddrs sets the bootstrap addresses to the given value or the default if the given value is empty.
func (*Config) WithDBDir ¶
WithDBDir sets the DB dir to the given value or the default if the given value is empty.
func (*Config) WithDataDir ¶
WithDataDir sets the data dir to the given value or the default if the given value is empty.
func (*Config) WithDefaultBootstrapAddrs ¶
WithDefaultBootstrapAddrs sets the bootstrap addresses to a single address of the default IP and port.
func (*Config) WithDefaultDBDir ¶
WithDefaultDBDir sets the DB dir to a local name subdir of the data dir.
func (*Config) WithDefaultDataDir ¶
WithDefaultDataDir sets the data dir to a 'data' subdir of the current working directory..
func (*Config) WithDefaultIntroduce ¶
WithDefaultIntroduce sets the introduce parameters to the default values specified in the introduce package.
func (*Config) WithDefaultLocalMetricsPort ¶ added in v0.2.0
WithDefaultLocalMetricsPort sets the local address to the default value.
func (*Config) WithDefaultLocalPort ¶ added in v0.2.0
WithDefaultLocalPort sets the local address to the default value.
func (*Config) WithDefaultLocalProfilerPort ¶ added in v0.3.0
WithDefaultLocalProfilerPort sets the local address to the default value.
func (*Config) WithDefaultLogLevel ¶
WithDefaultLogLevel sets the log level to INFO.
func (*Config) WithDefaultProfile ¶ added in v0.3.0
WithDefaultProfile sets the default state for whether to enable the profiler.
func (*Config) WithDefaultPublicAddr ¶
WithDefaultPublicAddr sets the public address to the local address, useful when just running a cluster locally.
func (*Config) WithDefaultPublicName ¶
WithDefaultPublicName sets the public name to the default value, which uses a hash of the public address.
func (*Config) WithDefaultReplicate ¶ added in v0.4.0
WithDefaultReplicate sets the subscription from parameters to the default.
func (*Config) WithDefaultReportMetrics ¶ added in v0.2.0
WithDefaultReportMetrics sets the default state for whether to report metrics.
func (*Config) WithDefaultRouting ¶
WithDefaultRouting sets the routing parameters to the default values specified in the routing module.
func (*Config) WithDefaultSearch ¶
WithDefaultSearch sets the search parameters to their default values specified in the search package.
func (*Config) WithDefaultStore ¶
WithDefaultStore sets the store parameters to their default values specified in the store package.
func (*Config) WithDefaultSubscribeFrom ¶
WithDefaultSubscribeFrom sets the subscription from parameters to the default.
func (*Config) WithDefaultSubscribeTo ¶
WithDefaultSubscribeTo sets the subscription to parameters to the default.
func (*Config) WithIntroduce ¶
func (c *Config) WithIntroduce(params *introduce.Parameters) *Config
WithIntroduce sets the introduce parameters to the given value or the default if it is nil.
func (*Config) WithLocalMetricsPort ¶ added in v0.2.0
WithLocalMetricsPort sets config's local metrics address to the given value or to the default if the given value is nil.
func (*Config) WithLocalPort ¶ added in v0.2.0
WithLocalPort sets config's local address to the given value or to the default if the given value is nil.
func (*Config) WithLocalProfilerPort ¶ added in v0.3.0
WithLocalProfilerPort sets config's local profiler address to the given value or to the default if the given value is nil.
func (*Config) WithLogLevel ¶
WithLogLevel sets the log level to the given value, though this doesn't have any direct effect on the creation of the logger instance.
func (*Config) WithProfile ¶ added in v0.3.0
WithProfile sets whether to report metrics or not.
func (*Config) WithPublicAddr ¶
WithPublicAddr sets the public address to the given value or to the default if the given value is nil.
func (*Config) WithPublicName ¶
WithPublicName sets the public name to the given value or the default if the given value is empty.
func (*Config) WithReplicate ¶ added in v0.4.0
func (c *Config) WithReplicate(params *replicate.Parameters) *Config
WithReplicate sets the subscription from parameters to the given value or the default it is nil.
func (*Config) WithReportMetrics ¶ added in v0.2.0
WithReportMetrics sets whether to report metrics or not.
func (*Config) WithRouting ¶
func (c *Config) WithRouting(params *routing.Parameters) *Config
WithRouting sets the routing parameters to the given value or the default if it is nil.
func (*Config) WithSearch ¶
func (c *Config) WithSearch(params *search.Parameters) *Config
WithSearch sets the search parameters to the given value or the default if it is nil.
func (*Config) WithStore ¶
func (c *Config) WithStore(params *store.Parameters) *Config
WithStore sets the store parameters to the given value or the default if it is nil.
func (*Config) WithSubscribeFrom ¶
func (c *Config) WithSubscribeFrom(params *subscribe.FromParameters) *Config
WithSubscribeFrom sets the subscription from parameters to the given value or the default it is nil.
func (*Config) WithSubscribeTo ¶
func (c *Config) WithSubscribeTo(params *subscribe.ToParameters) *Config
WithSubscribeTo sets the subscription to parameters to the given value or the default it it is nil.
type Librarian ¶
type Librarian struct { // RecentPubs is an LRU cache of recent publications librarian has received RecentPubs subscribe.RecentPublications // contains filtered or unexported fields }
Librarian is the main service of a single peer in the peer to peer network.
func NewLibrarian ¶
NewLibrarian creates a new librarian instance.
func (*Librarian) CloseAndRemove ¶
CloseAndRemove cleans up and removes any local state from the server.
func (*Librarian) Find ¶
func (l *Librarian) Find(ctx context.Context, rq *api.FindRequest) (*api.FindResponse, error)
Find returns either the value at a given target or the peers closest to it.
func (*Librarian) Get ¶
func (l *Librarian) Get(ctx context.Context, rq *api.GetRequest) (*api.GetResponse, error)
Get returns the value for a given key, if it exists. This endpoint handles the internals of searching for the key.
func (*Librarian) Introduce ¶
func (l *Librarian) Introduce(ctx context.Context, rq *api.IntroduceRequest) ( *api.IntroduceResponse, error)
Introduce receives and gives identifying information about the peer in the network.
func (*Librarian) NewResponseMetadata ¶
func (l *Librarian) NewResponseMetadata(m *api.RequestMetadata) *api.ResponseMetadata
NewResponseMetadata creates a new api.ResponseMatadata object with the same RequestID as that in the api.RequestMetadata.
func (*Librarian) Put ¶
func (l *Librarian) Put(ctx context.Context, rq *api.PutRequest) (*api.PutResponse, error)
Put stores a given key and value. This endpoint handles the internals of finding the right peers to store the value in and then sending them store requests.
func (*Librarian) StopAuxRoutines ¶
func (l *Librarian) StopAuxRoutines()
StopAuxRoutines ends the replicator and subscriptions auxiliary routines.
func (*Librarian) Store ¶
func (l *Librarian) Store(ctx context.Context, rq *api.StoreRequest) ( *api.StoreResponse, error)
Store stores the value.
func (*Librarian) Subscribe ¶
func (l *Librarian) Subscribe(rq *api.SubscribeRequest, from api.Librarian_SubscribeServer) error
Subscribe begins a subscription to the peer's publication stream (from its own subscriptions to other peers).
func (*Librarian) Verify ¶
func (l *Librarian) Verify( ctx context.Context, rq *api.VerifyRequest, ) (*api.VerifyResponse, error)
Verify returns either the MAC of a value (if the peer has it) or the peers closest to it.
type RequestVerifier ¶
type RequestVerifier interface {
Verify(ctx context.Context, msg proto.Message, meta *api.RequestMetadata) error
}
RequestVerifier verifies requests by checking the signature in the context.
func NewRequestVerifier ¶
func NewRequestVerifier() RequestVerifier
NewRequestVerifier creates a new RequestVerifier instance.