types

package
v0.0.0-...-8cb8a38 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageIDLengthBytes = 32
)
View Source
const (
	MinimumTTLSeconds = 1
)

Variables

View Source
var (
	ErrInvalidLengthBroadcastMessage        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowBroadcastMessage          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupBroadcastMessage = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	ErrMsgIDEmpty                = errors.New("message ID is empty")
	ErrMsgInsufficientRecipients = errors.New("not enough recipient peer IDs, requires at least 1")
	ErrMsgTTLTooShort            = errors.New("message TTL is too short, must be at least 1 second")
	ErrMsgExpired                = errors.New("message is expired")
)
View Source
var (
	ErrInvalidLengthTrace        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowTrace          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupTrace = fmt.Errorf("proto: unexpected end of group")
)

Functions

func NewBroadcastMessageID

func NewBroadcastMessageID() (string, error)

NewBroadcastMessageID returns a new broadcast message ID. This consists of random 32 bytes base58 encoded.

Types

type BroadcastMessage

type BroadcastMessage struct {
	// Unique ID of this message.
	ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// Original peer.ID that sent this message.
	From github_com_libp2p_go_libp2p_core_peer.ID `protobuf:"bytes,2,opt,name=from,proto3,customtype=github.com/libp2p/go-libp2p-core/peer.ID" json:"from"`
	// If this message is sent by the original broadcaster, where the from field
	// will match the sender peer.ID.
	IsBroadcaster bool `protobuf:"varint,3,opt,name=is_broadcaster,json=isBroadcaster,proto3" json:"is_broadcaster,omitempty"`
	// Selected recipients of the message, to partially restrict the broadcast to
	// a subset a peers.
	RecipientPeerIDs []github_com_libp2p_go_libp2p_core_peer.ID `` /* 163-byte string literal not displayed */
	// Customtype workaround for not having to use a separate protocgen.sh script
	Payload github_com_gogo_protobuf_types.Any `protobuf:"bytes,5,opt,name=payload,proto3,customtype=github.com/gogo/protobuf/types.Any" json:"payload"`
	// Timestamp when the message was broadcasted.
	Created time.Time `protobuf:"bytes,6,opt,name=created,proto3,stdtime" json:"created"`
	// Seconds after created time until the message expires. This requires
	// roughly synced times between peers
	TTLSeconds uint64 `protobuf:"varint,7,opt,name=ttl_seconds,json=ttlSeconds,proto3" json:"ttl_seconds,omitempty"`
	// Trace is used to track the message with opentelemetry.
	TraceContext *TraceContext `protobuf:"bytes,8,opt,name=trace_context,json=traceContext,proto3" json:"trace_context,omitempty"`
}

BroadcastMessage is used between peers to wrap messages for each protocol

func NewBroadcastMessage

func NewBroadcastMessage(
	ctx context.Context,
	payload PeerMessage,
	hostID peer.ID,
	recipientsPeerIDs []peer.ID,
	TTLSeconds uint64,
) (BroadcastMessage, error)

NewBroadcastMessage creates a new BroadcastMessage with the payload marshaled as Any.

func (*BroadcastMessage) Descriptor

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

func (*BroadcastMessage) Expired

func (msg *BroadcastMessage) Expired() bool

Expired returns true if the TTL is exceeded since created time.

func (*BroadcastMessage) GetAllPeersIDs

func (msg *BroadcastMessage) GetAllPeersIDs() []peer.ID

func (*BroadcastMessage) GetCreated

func (m *BroadcastMessage) GetCreated() time.Time

func (*BroadcastMessage) GetID

func (m *BroadcastMessage) GetID() string

func (*BroadcastMessage) GetIsBroadcaster

func (m *BroadcastMessage) GetIsBroadcaster() bool

func (*BroadcastMessage) GetTTLSeconds

func (m *BroadcastMessage) GetTTLSeconds() uint64

func (*BroadcastMessage) GetTraceContext

func (m *BroadcastMessage) GetTraceContext() *TraceContext

func (*BroadcastMessage) Marshal

func (m *BroadcastMessage) Marshal() (dAtA []byte, err error)

func (*BroadcastMessage) MarshalTo

func (m *BroadcastMessage) MarshalTo(dAtA []byte) (int, error)

func (*BroadcastMessage) MarshalToSizedBuffer

func (m *BroadcastMessage) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*BroadcastMessage) ProtoMessage

func (*BroadcastMessage) ProtoMessage()

func (*BroadcastMessage) Reset

func (m *BroadcastMessage) Reset()

func (*BroadcastMessage) Size

func (m *BroadcastMessage) Size() (n int)

func (*BroadcastMessage) String

func (m *BroadcastMessage) String() string

func (*BroadcastMessage) Unmarshal

func (m *BroadcastMessage) Unmarshal(dAtA []byte) error

func (*BroadcastMessage) UnpackPayload

func (msg *BroadcastMessage) UnpackPayload() (PeerMessage, error)

UnpackPayload unpacks the broadcast message payload into a PeerMessage.

func (*BroadcastMessage) Validate

func (msg *BroadcastMessage) Validate() error

Validate returns an error if the message is invalid.

func (*BroadcastMessage) XXX_DiscardUnknown

func (m *BroadcastMessage) XXX_DiscardUnknown()

func (*BroadcastMessage) XXX_Marshal

func (m *BroadcastMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BroadcastMessage) XXX_Merge

func (m *BroadcastMessage) XXX_Merge(src proto.Message)

func (*BroadcastMessage) XXX_Size

func (m *BroadcastMessage) XXX_Size() int

func (*BroadcastMessage) XXX_Unmarshal

func (m *BroadcastMessage) XXX_Unmarshal(b []byte) error

type HelloRequest

type HelloRequest struct {
	// Peer ID that sent this message, set by sender and validated by receiver.
	PeerID      github_com_libp2p_go_libp2p_core_peer.ID `protobuf:"bytes,1,opt,name=peer_id,json=peerId,proto3,customtype=github.com/libp2p/go-libp2p-core/peer.ID" json:"peer_id"`
	NodeMoniker string                                   `protobuf:"bytes,2,opt,name=node_moniker,json=nodeMoniker,proto3" json:"node_moniker,omitempty"`
}

func (*HelloRequest) Descriptor

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

func (*HelloRequest) GetNodeMoniker

func (m *HelloRequest) GetNodeMoniker() string

func (*HelloRequest) Marshal

func (m *HelloRequest) Marshal() (dAtA []byte, err error)

func (*HelloRequest) MarshalTo

func (m *HelloRequest) MarshalTo(dAtA []byte) (int, error)

func (*HelloRequest) MarshalToSizedBuffer

func (m *HelloRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*HelloRequest) ProtoMessage

func (*HelloRequest) ProtoMessage()

func (*HelloRequest) Reset

func (m *HelloRequest) Reset()

func (*HelloRequest) Size

func (m *HelloRequest) Size() (n int)

func (*HelloRequest) String

func (m *HelloRequest) String() string

func (*HelloRequest) Unmarshal

func (m *HelloRequest) Unmarshal(dAtA []byte) error

func (*HelloRequest) ValidateBasic

func (msg *HelloRequest) ValidateBasic() error

func (*HelloRequest) XXX_DiscardUnknown

func (m *HelloRequest) XXX_DiscardUnknown()

func (*HelloRequest) XXX_Marshal

func (m *HelloRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HelloRequest) XXX_Merge

func (m *HelloRequest) XXX_Merge(src proto.Message)

func (*HelloRequest) XXX_Size

func (m *HelloRequest) XXX_Size() int

func (*HelloRequest) XXX_Unmarshal

func (m *HelloRequest) XXX_Unmarshal(b []byte) error

type PeerMessage

type PeerMessage interface {
	proto.Message

	// ValidateBasic does a simple validation check that
	// doesn't require access to any other information.
	ValidateBasic() error
}

PeerMessage defines an interface that broadcast messages must implement.

type TraceContext

type TraceContext struct {
	Carrier map[string]string `` /* 155-byte string literal not displayed */
}

TraceContext contains the tracing context of a message, converted to a MapCarrier https://pkg.go.dev/go.opentelemetry.io/otel@v1.7.0/propagation#MapCarrier

func NewTraceContext

func NewTraceContext() *TraceContext

func (*TraceContext) Descriptor

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

func (*TraceContext) GetCarrier

func (t *TraceContext) GetCarrier() propagation.MapCarrier

func (*TraceContext) Inject

func (tctx *TraceContext) Inject(ctx context.Context)

func (*TraceContext) Marshal

func (m *TraceContext) Marshal() (dAtA []byte, err error)

func (*TraceContext) MarshalTo

func (m *TraceContext) MarshalTo(dAtA []byte) (int, error)

func (*TraceContext) MarshalToSizedBuffer

func (m *TraceContext) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*TraceContext) ProtoMessage

func (*TraceContext) ProtoMessage()

func (*TraceContext) Reset

func (m *TraceContext) Reset()

func (*TraceContext) Size

func (m *TraceContext) Size() (n int)

func (*TraceContext) String

func (m *TraceContext) String() string

func (*TraceContext) Unmarshal

func (m *TraceContext) Unmarshal(dAtA []byte) error

func (*TraceContext) XXX_DiscardUnknown

func (m *TraceContext) XXX_DiscardUnknown()

func (*TraceContext) XXX_Marshal

func (m *TraceContext) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TraceContext) XXX_Merge

func (m *TraceContext) XXX_Merge(src proto.Message)

func (*TraceContext) XXX_Size

func (m *TraceContext) XXX_Size() int

func (*TraceContext) XXX_Unmarshal

func (m *TraceContext) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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