centralized

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package centralized defines a client-server-based transport for the helium services. This transport is based on gRPC services.

Index

Constants

View Source
const (
	MaxMsgSize       = 1024 * 1024 * 32
	KeepaliveTime    = time.Second
	KeepaliveTimeout = time.Second
)
View Source
const (
	ClientConnectTimeout = 3 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CiphertextHandler

type CiphertextHandler interface {
	GetCiphertext(context.Context, helium.CiphertextID) (*helium.Ciphertext, error)
	PutCiphertext(context.Context, helium.Ciphertext) error
}

CiphertextHandler is an interface for the helium server to handle ciphertext-related requests from its peers. The interface implementation is provided by the NewHeliumServer method, and the created server makes calls to the interface methods when handling requests from its peers.

type Dialer

type Dialer = func(c context.Context, addr string) (net.Conn, error)

Dialer is a function that returns a net.Conn to the provided address.

type HeliumClient

type HeliumClient struct {
	pb.HeliumClient
	// contains filtered or unexported fields
}

HeliumClient is a client for the helium service. It is used by peer nodes to communicate with the helium server.

func NewHeliumClient

func NewHeliumClient(ownID, helperID helium.NodeID, helperAddress helium.NodeAddress) *HeliumClient

NewHeliumClient creates a new helium client.

func (*HeliumClient) Connect

func (hc *HeliumClient) Connect() error

Connect establishes a connection to the helium server.

func (*HeliumClient) ConnectWithDialer

func (hc *HeliumClient) ConnectWithDialer(dialer Dialer) error

ConnectWithDialer establishes a connection to the helium server using the provided dialer.

func (*HeliumClient) GetAggregationOutput

func (hc *HeliumClient) GetAggregationOutput(ctx context.Context, pd protocols.Descriptor) (*protocols.AggregationOutput, error)

GetAggregationOutput queries and returns the aggregation output for a given protocol descriptor.

func (*HeliumClient) GetCiphertext

func (hc *HeliumClient) GetCiphertext(ctx context.Context, ctID helium.CiphertextID) (*helium.Ciphertext, error)

GetCiphertext queries and returns a ciphertext.

func (*HeliumClient) GetStats

func (s *HeliumClient) GetStats() NetStats

func (*HeliumClient) HandleConn

func (s *HeliumClient) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn processes the Conn stats.

func (*HeliumClient) HandleRPC

func (s *HeliumClient) HandleRPC(_ context.Context, sta stats.RPCStats)

HandleRPC processes the RPC stats.

func (*HeliumClient) PutCiphertext

func (hc *HeliumClient) PutCiphertext(ctx context.Context, ct helium.Ciphertext) error

PutCiphertext sends a ciphertext to the helium server.

func (*HeliumClient) PutShare

func (hc *HeliumClient) PutShare(ctx context.Context, share protocols.Share) error

PutShare sends a share to the helium server.

func (*HeliumClient) Register

func (hc *HeliumClient) Register(ctx context.Context) (events <-chan coordinator.Event, present int, err error)

Register registers the client with the helium server and returns a channel for receiving events. It returns the current sequence number for the event log as present. Reading present+1 events from the returned channel will not block for longer than network-introduced delays.

func (*HeliumClient) TagConn

func (s *HeliumClient) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context

TagConn can attach some information to the given context. The returned context will be used for stats handling. For conn stats handling, the context used in HandleConn for this connection will be derived from the context returned. For RPC stats handling,

  • On server side, the context used in HandleRPC for all RPCs on this

connection will be derived from the context returned.

  • On client side, the context is not derived from the context returned.

func (*HeliumClient) TagRPC

func (s *HeliumClient) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context

TagRPC can attach some information to the given context. The context used for the rest lifetime of the RPC will be derived from the returned context.

type HeliumServer

type HeliumServer struct {

	// grpc API
	*grpc.Server
	*pb.UnimplementedHeliumServer
	// contains filtered or unexported fields
}

HeliumServer is the server-side of the helium transport. In the current implementation, the server is responsible for keeping the event log and a server cannot be restarted after it is closed. // TODO

func NewHeliumServer

func NewHeliumServer(id helium.NodeID, na helium.NodeAddress, nl helium.NodesList, protoHandler ProtocolHandler, ctxtHandler CiphertextHandler) *HeliumServer

NewHeliumServer creates a new helium server with the provided node information and handlers.

func (*HeliumServer) AppendEventToLog

func (hsv *HeliumServer) AppendEventToLog(event coordinator.Event) error

AppendEventToLog is called by the server side to append a new event to the log and send it to all connected peers.

func (*HeliumServer) CloseEventLog

func (hsv *HeliumServer) CloseEventLog()

CloseEventLog is called by the server side to close the event log and stop sending events to connected peers.

func (*HeliumServer) GetAggregationOutput

func (hsv *HeliumServer) GetAggregationOutput(inctx context.Context, apipd *pb.ProtocolDescriptor) (*pb.AggregationOutput, error)

GetAggregationOutput is a gRPC handler for the GetAggregationOutput method of the Helium service.

func (*HeliumServer) GetCiphertext

func (hsv *HeliumServer) GetCiphertext(inctx context.Context, ctid *pb.CiphertextID) (*pb.Ciphertext, error)

GetCiphertext is a gRPC handler for the GetCiphertext method of the Helium service.

func (*HeliumServer) GetStats

func (s *HeliumServer) GetStats() NetStats

func (*HeliumServer) HandleConn

func (s *HeliumServer) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn processes the Conn stats.

func (*HeliumServer) HandleRPC

func (s *HeliumServer) HandleRPC(_ context.Context, sta stats.RPCStats)

HandleRPC processes the RPC stats.

func (*HeliumServer) Logf

func (hsv *HeliumServer) Logf(msg string, v ...any)

func (*HeliumServer) NotifyRegister

func (hsv *HeliumServer) NotifyRegister(node helium.NodeID) (err error)

NotifyRegister notifies all registered watchers that a new peer has registered.

func (*HeliumServer) NotifyUnregister

func (hsv *HeliumServer) NotifyUnregister(node helium.NodeID) (err error)

NotifyUnregister notifies all registered watchers that a peer has unregistered.

func (*HeliumServer) PutCiphertext

func (hsv *HeliumServer) PutCiphertext(inctx context.Context, apict *pb.Ciphertext) (*pb.CiphertextID, error)

PutCiphertext is a gRPC handler for the PutCiphertext method of the Helium service.

func (*HeliumServer) PutShare

func (hsv *HeliumServer) PutShare(inctx context.Context, apiShare *pb.Share) (*pb.Void, error)

PutShare is a gRPC handler for the PutShare method of the Helium service.

func (*HeliumServer) Register

func (hsv *HeliumServer) Register(_ *pb.Void, stream pb.Helium_RegisterServer) error

Register is a gRPC handler for the Register method of the Helium service.

func (*HeliumServer) RegisterWatcher

func (hsv *HeliumServer) RegisterWatcher(nw NodeWatcher)

RegisterWatcher adds a new watcher to the server. The watcher will be notified when a new peer is registered

func (*HeliumServer) TagConn

func (s *HeliumServer) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context

TagConn can attach some information to the given context. The returned context will be used for stats handling. For conn stats handling, the context used in HandleConn for this connection will be derived from the context returned. For RPC stats handling,

  • On server side, the context used in HandleRPC for all RPCs on this

connection will be derived from the context returned.

  • On client side, the context is not derived from the context returned.

func (*HeliumServer) TagRPC

func (s *HeliumServer) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context

TagRPC can attach some information to the given context. The context used for the rest lifetime of the RPC will be derived from the returned context.

type NetStats

type NetStats struct {
	DataSent, DataRecv uint64
}

NetStats contains the network statistics of a connection.

func (NetStats) String

func (s NetStats) String() string

String returns a string representation of the network statistics.

type NodeWatcher

type NodeWatcher interface {
	// Register is called by the transport when a new peer register itself for the setup.
	Register(helium.NodeID) error

	// Unregister is called by the transport when a peer is unregistered from the setup.
	Unregister(helium.NodeID) error
}

NodeWatcher is an interface for the helium server to notify registered watchers when a new peer is registered or unregistered. See HeliumServer.RegisterWatcher.

type ProtocolHandler

type ProtocolHandler interface {
	PutShare(context.Context, protocols.Share) error
	GetAggregationOutput(context.Context, protocols.Descriptor) (*protocols.AggregationOutput, error)
}

ProtocolHandler is an interface for the helium server to handle protocol-related requests from its peers. The interface implementation is provided by the NewHeliumServer method, and the created server makes calls to the interface methods when handling requests from its peers.

type TLSConfig

type TLSConfig struct {
	InsecureChannels bool                     // if set, disables TLS authentication
	FromDirectory    string                   // path to a directory containing the TLS material as files
	PeerPKs          map[helium.NodeID]string // Mapping of <node, pubKey> where pubKey is PEM encoded
	PeerCerts        map[helium.NodeID]string // Mapping of <node, certifcate> where pubKey is PEM encoded ASN.1 DER string
	CACert           string                   // Root CA certificate as a PEM encoded ASN.1 DER string
	OwnCert          string                   // Own certificate as a PEM encoded ASN.1 DER string
	OwnPk            string                   // Own public key as a PEM encoded string
	OwnSk            string                   // Own secret key as a PEM encoded string
}

TLSConfig is a struct for specifying TLS-related configuration. TLS is not supported yet.

Jump to

Keyboard shortcuts

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