gossip

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const WorkerTimeout = 3 * time.Second

Variables

View Source
var File_gossip_proto protoreflect.FileDescriptor
View Source
var Gossip_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "gossip.Gossip",
	HandlerType: (*GossipServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Endpoint",
			Handler:    _Gossip_Endpoint_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Stream",
			Handler:       _Gossip_Stream_Handler,
			ClientStreams: true,
		},
	},
	Metadata: "gossip.proto",
}

Gossip_ServiceDesc is the grpc.ServiceDesc for Gossip service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func Marshal

func Marshal(msg *GossipMsg) []byte

Returns the data of a GossipMsg excluding the Signature as bytes

func RegisterGossipServer

func RegisterGossipServer(s grpc.ServiceRegistrar, srv GossipServer)

Types

type Ack

type Ack struct {
	Error string `protobuf:"bytes,1,opt,name=Error,proto3" json:"Error,omitempty"`
	// contains filtered or unexported fields
}

Generic response message providing an error message from remote servers

func (*Ack) Descriptor deprecated

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

Deprecated: Use Ack.ProtoReflect.Descriptor instead.

func (*Ack) GetError

func (x *Ack) GetError() string

func (*Ack) ProtoMessage

func (*Ack) ProtoMessage()

func (*Ack) ProtoReflect

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

func (*Ack) Reset

func (x *Ack) Reset()

func (*Ack) String

func (x *Ack) String() string

type Fingerprint

type Fingerprint [16]byte

Defines the type of Gossip message fingerprints hash(tag, origin, payload, signature)

func NewFingerprint

func NewFingerprint(preSum []byte) Fingerprint

NewFingerprint creates a new fingerprint from a byte slice of data

type FingerprintDigest

type FingerprintDigest func(msg *GossipMsg) Fingerprint

Passed into NewGossip to specify how fingerprints will be generated

type GossipClient

type GossipClient interface {
	Endpoint(ctx context.Context, in *GossipMsg, opts ...grpc.CallOption) (*Ack, error)
	Stream(ctx context.Context, opts ...grpc.CallOption) (Gossip_StreamClient, error)
}

GossipClient is the client API for Gossip service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewGossipClient

func NewGossipClient(cc grpc.ClientConnInterface) GossipClient

type GossipMsg

type GossipMsg struct {
	Tag       string `protobuf:"bytes,1,opt,name=Tag,proto3" json:"Tag,omitempty"`
	Origin    []byte `protobuf:"bytes,2,opt,name=Origin,proto3" json:"Origin,omitempty"`
	Payload   []byte `protobuf:"bytes,3,opt,name=Payload,proto3" json:"Payload,omitempty"`
	Signature []byte `protobuf:"bytes,4,opt,name=Signature,proto3" json:"Signature,omitempty"`
	Timestamp int64  `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// contains filtered or unexported fields
}

Generic message used for a variety of Gossip protocols

func (*GossipMsg) Descriptor deprecated

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

Deprecated: Use GossipMsg.ProtoReflect.Descriptor instead.

func (*GossipMsg) GetOrigin

func (x *GossipMsg) GetOrigin() []byte

func (*GossipMsg) GetPayload

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

func (*GossipMsg) GetSignature

func (x *GossipMsg) GetSignature() []byte

func (*GossipMsg) GetTag

func (x *GossipMsg) GetTag() string

func (*GossipMsg) GetTimestamp

func (x *GossipMsg) GetTimestamp() int64

func (*GossipMsg) ProtoMessage

func (*GossipMsg) ProtoMessage()

func (*GossipMsg) ProtoReflect

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

func (*GossipMsg) Reset

func (x *GossipMsg) Reset()

func (*GossipMsg) String

func (x *GossipMsg) String() string

type GossipServer

type GossipServer interface {
	Endpoint(context.Context, *GossipMsg) (*Ack, error)
	Stream(Gossip_StreamServer) error
	// contains filtered or unexported methods
}

GossipServer is the server API for Gossip service. All implementations must embed UnimplementedGossipServer for forward compatibility

type Gossip_StreamClient

type Gossip_StreamClient interface {
	Send(*GossipMsg) error
	CloseAndRecv() (*Ack, error)
	grpc.ClientStream
}

type Gossip_StreamServer

type Gossip_StreamServer interface {
	SendAndClose(*Ack) error
	Recv() (*GossipMsg, error)
	grpc.ServerStream
}

type Manager

type Manager struct {
	*UnimplementedGossipServer
	// contains filtered or unexported fields
}

Manager for various GossipProtocols that are accessed by tag

func NewManager

func NewManager(comms *connect.ProtoComms, flags ManagerFlags) *Manager

Creates a new Gossip Manager struct

func (*Manager) Delete

func (m *Manager) Delete(tag string)

Deletes a Protocol from the Manager

func (*Manager) Endpoint

func (m *Manager) Endpoint(ctx context.Context, msg *GossipMsg) (*Ack, error)

Generic endpoint for forwarding GossipMsg to correct Protocol

func (*Manager) Get

func (m *Manager) Get(tag string) (*Protocol, bool)

Returns the Gossip object for the provided tag from the Manager

func (*Manager) NewGossip

func (m *Manager) NewGossip(tag string, flags ProtocolFlags,
	receiver Receiver, verifier SignatureVerification, peers []*id.ID)

Creates and stores a new Protocol in the Manager

func (*Manager) Stream

func (m *Manager) Stream(stream Gossip_StreamServer) error

Generic streaming endpoint for forwarding GossipMsg to correct Protocol

type ManagerFlags

type ManagerFlags struct {
	// How long a message record should last in the buffer
	BufferExpirationTime time.Duration

	// Frequency with which to check the buffer.
	// Should be long, since the thread takes a lock each time it checks the buffer
	MonitorThreadFrequency time.Duration
}

func DefaultManagerFlags

func DefaultManagerFlags() ManagerFlags

type MessageRecord

type MessageRecord struct {
	Timestamp time.Time
	Messages  []*GossipMsg
}

Structure holding messages for a given tag, if the tag does not yet exist If the tag is not created in 5 minutes, the record should be deleted

type Protocol

type Protocol struct {

	// Marks a Protocol as Defunct such that it will ignore new messages
	IsDefunct bool
	// contains filtered or unexported fields
}

Generic interface representing various Gossip protocols

func (*Protocol) AddGossipPeer

func (p *Protocol) AddGossipPeer(id *id.ID) error

Adds a peer by ID to the Gossip protocol

func (*Protocol) Defunct

func (p *Protocol) Defunct()

Marks a Protocol as Defunct such that it will ignore new messages

func (*Protocol) GetPeers

func (p *Protocol) GetPeers() []*id.ID

Returns all peers in the gossip. Primarily for debugging.

func (*Protocol) Gossip

func (p *Protocol) Gossip(msg *GossipMsg) (int, []error)

Builds and sends a GossipMsg

func (*Protocol) RemoveGossipPeer

func (p *Protocol) RemoveGossipPeer(id *id.ID) error

Remove a peer by ID to the Gossip protocol

type ProtocolFlags

type ProtocolFlags struct {
	FanOut                  uint8         // Default = 0
	MaxRecordedFingerprints uint64        // Default = 10000000
	MaximumReSends          uint64        // Default = 3
	NumParallelSends        uint32        // Default = 5
	MaxGossipAge            time.Duration // Default = 10 * time.Second
	SelfGossip              bool          // Default = false
	Fingerprinter           FingerprintDigest
}

Gossip-related configuration flag

func DefaultProtocolFlags

func DefaultProtocolFlags() ProtocolFlags

Returns a ProtocolFlags object with all flags set to their defaults

type Receiver

type Receiver func(*GossipMsg) error

Passed into NewGossip to specify how Gossip messages will be handled

type SignatureVerification

type SignatureVerification func(*GossipMsg, []byte) error

Passed into NewGossip to specify how Gossip message signatures will be verified the byte slice will be used to pass in a merkle tree and signature on the trees root for multi-part gossips sent over streaming when streaming is implemented. Ignore it for non streaming implementations.

type UnimplementedGossipServer

type UnimplementedGossipServer struct {
}

UnimplementedGossipServer must be embedded to have forward compatible implementations.

func (UnimplementedGossipServer) Endpoint

func (UnimplementedGossipServer) Stream

type UnsafeGossipServer

type UnsafeGossipServer interface {
	// contains filtered or unexported methods
}

UnsafeGossipServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to GossipServer will result in compilation errors.

Jump to

Keyboard shortcuts

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