server

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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"
)
View Source
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

func NameFromAddr(localAddr fmt.Stringer) string

NameFromAddr gives the local name (on the host) of the node using the NodeIndex

func Start

func Start(logger *zap.Logger, config *Config, up chan *Librarian) error

Start is the entry point for a Librarian server. It bootstraps peers for the Librarians's routing table and then begins listening for and handling requests. It notifies the up channel just before

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

func (c *Config) WithBootstrapAddrs(bootstrapAddrs []*net.TCPAddr) *Config

WithBootstrapAddrs sets the bootstrap addresses to the given value or the default if the given value is empty.

func (*Config) WithDBDir

func (c *Config) WithDBDir(dbDir string) *Config

WithDBDir sets the DB dir to the given value or the default if the given value is empty.

func (*Config) WithDataDir

func (c *Config) WithDataDir(dataDir string) *Config

WithDataDir sets the data dir to the given value or the default if the given value is empty.

func (*Config) WithDefaultBootstrapAddrs

func (c *Config) WithDefaultBootstrapAddrs() *Config

WithDefaultBootstrapAddrs sets the bootstrap addresses to a single address of the default IP and port.

func (*Config) WithDefaultDBDir

func (c *Config) WithDefaultDBDir() *Config

WithDefaultDBDir sets the DB dir to a local name subdir of the data dir.

func (*Config) WithDefaultDataDir

func (c *Config) WithDefaultDataDir() *Config

WithDefaultDataDir sets the data dir to a 'data' subdir of the current working directory..

func (*Config) WithDefaultIntroduce

func (c *Config) WithDefaultIntroduce() *Config

WithDefaultIntroduce sets the introduce parameters to the default values specified in the introduce package.

func (*Config) WithDefaultLocalMetricsPort added in v0.2.0

func (c *Config) WithDefaultLocalMetricsPort() *Config

WithDefaultLocalMetricsPort sets the local address to the default value.

func (*Config) WithDefaultLocalPort added in v0.2.0

func (c *Config) WithDefaultLocalPort() *Config

WithDefaultLocalPort sets the local address to the default value.

func (*Config) WithDefaultLocalProfilerPort added in v0.3.0

func (c *Config) WithDefaultLocalProfilerPort() *Config

WithDefaultLocalProfilerPort sets the local address to the default value.

func (*Config) WithDefaultLogLevel

func (c *Config) WithDefaultLogLevel() *Config

WithDefaultLogLevel sets the log level to INFO.

func (*Config) WithDefaultProfile added in v0.3.0

func (c *Config) WithDefaultProfile() *Config

WithDefaultProfile sets the default state for whether to enable the profiler.

func (*Config) WithDefaultPublicAddr

func (c *Config) WithDefaultPublicAddr() *Config

WithDefaultPublicAddr sets the public address to the local address, useful when just running a cluster locally.

func (*Config) WithDefaultPublicName

func (c *Config) WithDefaultPublicName() *Config

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

func (c *Config) WithDefaultReplicate() *Config

WithDefaultReplicate sets the subscription from parameters to the default.

func (*Config) WithDefaultReportMetrics added in v0.2.0

func (c *Config) WithDefaultReportMetrics() *Config

WithDefaultReportMetrics sets the default state for whether to report metrics.

func (*Config) WithDefaultRouting

func (c *Config) WithDefaultRouting() *Config

WithDefaultRouting sets the routing parameters to the default values specified in the routing module.

func (*Config) WithDefaultSearch

func (c *Config) WithDefaultSearch() *Config

WithDefaultSearch sets the search parameters to their default values specified in the search package.

func (*Config) WithDefaultStore

func (c *Config) WithDefaultStore() *Config

WithDefaultStore sets the store parameters to their default values specified in the store package.

func (*Config) WithDefaultSubscribeFrom

func (c *Config) WithDefaultSubscribeFrom() *Config

WithDefaultSubscribeFrom sets the subscription from parameters to the default.

func (*Config) WithDefaultSubscribeTo

func (c *Config) WithDefaultSubscribeTo() *Config

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

func (c *Config) WithLocalMetricsPort(localMetricsPort int) *Config

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

func (c *Config) WithLocalPort(localPort int) *Config

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

func (c *Config) WithLocalProfilerPort(localProfilerPort int) *Config

WithLocalProfilerPort sets config's local profiler address to the given value or to the default if the given value is nil.

func (*Config) WithLogLevel

func (c *Config) WithLogLevel(logLevel zapcore.Level) *Config

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) WithOrgID added in v0.5.0

func (c *Config) WithOrgID(orgID ecid.ID) *Config

WithOrgID sets the organization ID.

func (*Config) WithProfile added in v0.3.0

func (c *Config) WithProfile(profile bool) *Config

WithProfile sets whether to report metrics or not.

func (*Config) WithPublicAddr

func (c *Config) WithPublicAddr(publicAddr *net.TCPAddr) *Config

WithPublicAddr sets the public address to the given value or to the default if the given value is nil.

func (*Config) WithPublicName

func (c *Config) WithPublicName(publicName string) *Config

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

func (c *Config) WithReportMetrics(reportMetrics bool) *Config

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

func NewLibrarian(config *Config, logger *zap.Logger) (*Librarian, error)

NewLibrarian creates a new librarian instance.

func (*Librarian) Close

func (l *Librarian) Close() error

Close handles cleanup involved in closing down the server.

func (*Librarian) CloseAndRemove

func (l *Librarian) CloseAndRemove() error

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

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

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.

Directories

Path Synopsis
Package storage is a generated protocol buffer package.
Package storage is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL