comm

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 39 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PeerId     = "peer"
	ProtocolId = "protocol"
)
View Source
const (
	// NonceSize is the default NonceSize
	NonceSize = 24
)

Variables

View Source
var File_messages_proto protoreflect.FileDescriptor

Functions

func AddressToEndpoint

func AddressToEndpoint(endpoint string) (string, error)

func GetRandomBytes

func GetRandomBytes(len int) ([]byte, error)

GetRandomBytes returns len random looking bytes

func GetRandomNonce

func GetRandomNonce() ([]byte, error)

GetRandomNonce returns a random byte array of length NonceSize

func NewDelimitedReader

func NewDelimitedReader(r io2.Reader, maxSize int) io.ReadCloser

Types

type ConfigService

type ConfigService interface {
	GetString(key string) string
}

type EndpointService

type EndpointService interface {
	Resolve(party view2.Identity) (view2.Identity, map[view.PortName]string, []byte, error)
	GetIdentity(label string, pkID []byte) (view2.Identity, error)
}

type Metrics added in v0.3.0

type Metrics struct {
	BytesSent     metrics.Counter
	BytesReceived metrics.Counter
}

func NewMetrics added in v0.3.0

func NewMetrics(p metrics.Provider) *Metrics

type MetricsReporter added in v0.3.0

type MetricsReporter struct {
	// contains filtered or unexported fields
}

func NewReporter added in v0.3.0

func NewReporter(m *Metrics) *MetricsReporter

func (*MetricsReporter) GetBandwidthByPeer added in v0.3.0

func (r *MetricsReporter) GetBandwidthByPeer() map[peer.ID]metrics.Stats

func (*MetricsReporter) GetBandwidthByProtocol added in v0.3.0

func (r *MetricsReporter) GetBandwidthByProtocol() map[protocol.ID]metrics.Stats

func (*MetricsReporter) GetBandwidthForPeer added in v0.3.0

func (r *MetricsReporter) GetBandwidthForPeer(peer.ID) metrics.Stats

func (*MetricsReporter) GetBandwidthForProtocol added in v0.3.0

func (r *MetricsReporter) GetBandwidthForProtocol(protocol.ID) metrics.Stats

func (*MetricsReporter) GetBandwidthTotals added in v0.3.0

func (r *MetricsReporter) GetBandwidthTotals() metrics.Stats

func (*MetricsReporter) LogRecvMessage added in v0.3.0

func (r *MetricsReporter) LogRecvMessage(int64)

func (*MetricsReporter) LogRecvMessageStream added in v0.3.0

func (r *MetricsReporter) LogRecvMessageStream(size int64, proto protocol.ID, p peer.ID)

func (*MetricsReporter) LogSentMessage added in v0.3.0

func (r *MetricsReporter) LogSentMessage(int64)

func (*MetricsReporter) LogSentMessageStream added in v0.3.0

func (r *MetricsReporter) LogSentMessageStream(size int64, proto protocol.ID, p peer.ID)

type Network

type Network []*node

func NewVirtualNetwork

func NewVirtualNetwork(port int, numNodes int) (Network, error)

func (Network) Start

func (n Network) Start()

type NetworkStreamSession

type NetworkStreamSession struct {
	// contains filtered or unexported fields
}

NetworkStreamSession implements view.Session

func (*NetworkStreamSession) Close

func (n *NetworkStreamSession) Close()

Close releases all the resources allocated by this session

func (*NetworkStreamSession) Info

func (*NetworkStreamSession) Receive

func (n *NetworkStreamSession) Receive() <-chan *view.Message

Receive returns a channel of messages received from the endpoint

func (*NetworkStreamSession) Send

func (n *NetworkStreamSession) Send(payload []byte) error

Send sends the payload to the endpoint

func (*NetworkStreamSession) SendError

func (n *NetworkStreamSession) SendError(payload []byte) error

SendError sends an error to the endpoint with the passed payload

type P2PNode

type P2PNode struct {
	// contains filtered or unexported fields
}

func NewBootstrapNode

func NewBootstrapNode(ListenAddress string, keyDispenser PrivateKeyDispenser, metrics *Metrics) (*P2PNode, error)

func NewNode

func NewNode(ListenAddress, BootstrapNode string, keyDispenser PrivateKeyDispenser, metrics *Metrics) (*P2PNode, error)

func (*P2PNode) DeleteSessions

func (p *P2PNode) DeleteSessions(sessionID string)

func (*P2PNode) Lookup

func (p *P2PNode) Lookup(peerID string) (peer.AddrInfo, bool)

func (*P2PNode) MasterSession

func (p *P2PNode) MasterSession() (view.Session, error)

func (*P2PNode) NewSession

func (p *P2PNode) NewSession(callerViewID string, contextID string, endpoint string, pkid []byte) (view.Session, error)

func (*P2PNode) NewSessionWithID

func (p *P2PNode) NewSessionWithID(sessionID, contextID, endpoint string, pkid []byte, caller view.Identity, msg *view.Message) (view.Session, error)

func (*P2PNode) Start

func (p *P2PNode) Start(ctx context.Context)

func (*P2PNode) Stop

func (p *P2PNode) Stop()

type PrivateKeyDispenser

type PrivateKeyDispenser interface {
	PrivateKey() (crypto.PrivKey, error)
}

func GetPrivateKeyDispenser

func GetPrivateKeyDispenser(sp view2.ServiceProvider) PrivateKeyDispenser

type PrivateKeyFromCryptoKey

type PrivateKeyFromCryptoKey struct {
	Key crypto.PrivKey
}

func (*PrivateKeyFromCryptoKey) PrivateKey

func (p *PrivateKeyFromCryptoKey) PrivateKey() (crypto.PrivKey, error)

type PrivateKeyFromFile

type PrivateKeyFromFile struct {
	PrivateKeyFile string
}

func (*PrivateKeyFromFile) PrivateKey

func (p *PrivateKeyFromFile) PrivateKey() (crypto.PrivKey, error)

type Service

type Service struct {
	PrivateKeyDispenser PrivateKeyDispenser
	EndpointService     EndpointService
	ConfigService       ConfigService
	DefaultIdentity     view2.Identity
	Metrics             *Metrics

	Node     *P2PNode
	NodeSync sync.RWMutex
}

func NewService

func NewService(
	privateKeyDispenser PrivateKeyDispenser,
	endpointService EndpointService,
	configService ConfigService,
	defaultIdentity view2.Identity,
	metrics *Metrics,
) (*Service, error)

func (*Service) Addresses added in v0.3.0

func (s *Service) Addresses(id view2.Identity) ([]string, error)

func (*Service) DeleteSessions

func (s *Service) DeleteSessions(sessionID string)

func (*Service) MasterSession

func (s *Service) MasterSession() (view2.Session, error)

func (*Service) NewSession

func (s *Service) NewSession(caller string, contextID string, endpoint string, pkid []byte) (view2.Session, error)

func (*Service) NewSessionWithID

func (s *Service) NewSessionWithID(sessionID, contextID, endpoint string, pkid []byte, caller view2.Identity, msg *view2.Message) (view2.Session, error)

func (*Service) Start

func (s *Service) Start(ctx context.Context)

func (*Service) Stop

func (s *Service) Stop()

type ViewPacket

type ViewPacket struct {
	SessionID string `protobuf:"bytes,1,opt,name=sessionID,proto3" json:"sessionID,omitempty"`
	ContextID string `protobuf:"bytes,2,opt,name=contextID,proto3" json:"contextID,omitempty"`
	Status    int32  `protobuf:"varint,3,opt,name=status,proto3" json:"status,omitempty"`
	Payload   []byte `protobuf:"bytes,4,opt,name=payload,proto3" json:"payload,omitempty"`
	Caller    string `protobuf:"bytes,5,opt,name=caller,proto3" json:"caller,omitempty"`
	// contains filtered or unexported fields
}

func (*ViewPacket) Descriptor deprecated

func (*ViewPacket) Descriptor() ([]byte, []int)

Deprecated: Use ViewPacket.ProtoReflect.Descriptor instead.

func (*ViewPacket) GetCaller

func (x *ViewPacket) GetCaller() string

func (*ViewPacket) GetContextID

func (x *ViewPacket) GetContextID() string

func (*ViewPacket) GetPayload

func (x *ViewPacket) GetPayload() []byte

func (*ViewPacket) GetSessionID

func (x *ViewPacket) GetSessionID() string

func (*ViewPacket) GetStatus

func (x *ViewPacket) GetStatus() int32

func (*ViewPacket) ProtoMessage

func (*ViewPacket) ProtoMessage()

func (*ViewPacket) ProtoReflect

func (x *ViewPacket) ProtoReflect() protoreflect.Message

func (*ViewPacket) Reset

func (x *ViewPacket) Reset()

func (*ViewPacket) String

func (x *ViewPacket) String() string

Directories

Path Synopsis
io

Jump to

Keyboard shortcuts

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