Documentation
¶
Index ¶
- Constants
- Variables
- func Connectedness(c Message_ConnectionType) network.Connectedness
- func PBPeerToPeerInfo(pbp *Message_Peer) peer.AddrInfo
- func PBPeersToPeerInfos(pbps []*Message_Peer) []*peer.AddrInfo
- func Unmarshal(data []byte, m *Message) error
- type Message
- func (*Message) Descriptor() ([]byte, []int)deprecated
- func (x *Message) GetCloserPeers() []*Message_Peer
- func (m *Message) GetClusterLevel() int
- func (x *Message) GetClusterLevelRaw() int32
- func (x *Message) GetKey() []byte
- func (x *Message) GetProviderPeers() []*Message_Peer
- func (x *Message) GetRecord() *pb.Record
- func (x *Message) GetType() Message_MessageType
- func (*Message) ProtoMessage()
- func (x *Message) ProtoReflect() protoreflect.Message
- func (x *Message) Reset()
- func (m *Message) SetClusterLevel(level int)
- func (x *Message) String() string
- type MessageSender
- type MessageSenderWithDisconnect
- type Message_ConnectionType
- func (Message_ConnectionType) Descriptor() protoreflect.EnumDescriptor
- func (x Message_ConnectionType) Enum() *Message_ConnectionType
- func (Message_ConnectionType) EnumDescriptor() ([]byte, []int)deprecated
- func (x Message_ConnectionType) Number() protoreflect.EnumNumber
- func (x Message_ConnectionType) String() string
- func (Message_ConnectionType) Type() protoreflect.EnumType
- type Message_MessageType
- func (Message_MessageType) Descriptor() protoreflect.EnumDescriptor
- func (x Message_MessageType) Enum() *Message_MessageType
- func (Message_MessageType) EnumDescriptor() ([]byte, []int)deprecated
- func (x Message_MessageType) Number() protoreflect.EnumNumber
- func (x Message_MessageType) String() string
- func (Message_MessageType) Type() protoreflect.EnumType
- type Message_Peer
- func (m *Message_Peer) Addresses() []ma.Multiaddr
- func (*Message_Peer) Descriptor() ([]byte, []int)deprecated
- func (x *Message_Peer) GetAddrs() [][]byte
- func (x *Message_Peer) GetConnection() Message_ConnectionType
- func (x *Message_Peer) GetId() []byte
- func (*Message_Peer) ProtoMessage()
- func (x *Message_Peer) ProtoReflect() protoreflect.Message
- func (x *Message_Peer) Reset()
- func (x *Message_Peer) String() string
- type PeerRoutingInfo
- type ProtocolMessenger
- func (pm *ProtocolMessenger) GetClosestPeers(ctx context.Context, p peer.ID, id peer.ID) (closerPeers []*peer.AddrInfo, err error)
- func (pm *ProtocolMessenger) GetProviders(ctx context.Context, p peer.ID, key multihash.Multihash) (provs []*peer.AddrInfo, closerPeers []*peer.AddrInfo, err error)
- func (pm *ProtocolMessenger) GetValue(ctx context.Context, p peer.ID, key string) (record *recpb.Record, closerPeers []*peer.AddrInfo, err error)
- func (pm *ProtocolMessenger) Ping(ctx context.Context, p peer.ID) (err error)
- func (pm *ProtocolMessenger) PutProvider(ctx context.Context, p peer.ID, key multihash.Multihash, h host.Host) error
- func (pm *ProtocolMessenger) PutProviderAddrs(ctx context.Context, p peer.ID, key multihash.Multihash, self peer.AddrInfo) (err error)
- func (pm *ProtocolMessenger) PutValue(ctx context.Context, p peer.ID, rec *recpb.Record) (err error)
- type ProtocolMessengerOption
Constants ¶
const MaxPeerRecordSize = 8 << 10
MaxPeerRecordSize bounds the serialized size of a single Message_Peer on the wire. A peer record needs only a peer ID, its multiaddrs and a connection flag, so 8 KiB — the identify protocol's budget for a peer's entire signed self-description — is a generous per-record ceiling: comfortably more than any well-formed peer requires, while keeping records a predictable size both on the wire and in the peerstore. Addresses past the limit are dropped; the peer ID is always kept.
Variables ¶
var ( Message_MessageType_name = map[int32]string{ 0: "PUT_VALUE", 1: "GET_VALUE", 2: "ADD_PROVIDER", 3: "GET_PROVIDERS", 4: "FIND_NODE", 5: "PING", } Message_MessageType_value = map[string]int32{ "PUT_VALUE": 0, "GET_VALUE": 1, "ADD_PROVIDER": 2, "GET_PROVIDERS": 3, "FIND_NODE": 4, "PING": 5, } )
Enum value maps for Message_MessageType.
var ( Message_ConnectionType_name = map[int32]string{ 0: "NOT_CONNECTED", 1: "CONNECTED", 2: "CAN_CONNECT", 3: "CANNOT_CONNECT", } Message_ConnectionType_value = map[string]int32{ "NOT_CONNECTED": 0, "CONNECTED": 1, "CAN_CONNECT": 2, "CANNOT_CONNECT": 3, } )
Enum value maps for Message_ConnectionType.
var ErrTooManyPeerEntries = errors.New("dht message: too many peer entries")
ErrTooManyPeerEntries is returned when a DHT message carries more peer entries than its frame size can hold.
var File_github_com_libp2p_go_libp2p_kad_dht_pb_dht_proto protoreflect.FileDescriptor
Functions ¶
func Connectedness ¶
func Connectedness(c Message_ConnectionType) network.Connectedness
Connectedness returns an network.Connectedness associated with the Message_ConnectionType.
func PBPeerToPeerInfo ¶
func PBPeerToPeerInfo(pbp *Message_Peer) peer.AddrInfo
PBPeerToPeerInfo turns a *Message_Peer into its peer.AddrInfo counterpart. Invalid addresses are silently omitted. The address list is bounded to MaxPeerRecordSize before conversion, trimming pbp.Addrs in place.
func PBPeersToPeerInfos ¶
func PBPeersToPeerInfos(pbps []*Message_Peer) []*peer.AddrInfo
PBPeersToPeerInfos converts given []*Message_Peer into []peer.AddrInfo, as PBPeerToPeerInfo does for each record, trimming pbps[i].Addrs in place.
Types ¶
type Message ¶
type Message struct {
// defines what type of message it is.
Type Message_MessageType `protobuf:"varint,1,opt,name=type,proto3,enum=dht.pb.Message_MessageType" json:"type,omitempty"`
// defines what coral cluster level this query/response belongs to.
// in case we want to implement coral's cluster rings in the future.
ClusterLevelRaw int32 `protobuf:"varint,10,opt,name=clusterLevelRaw,proto3" json:"clusterLevelRaw,omitempty"`
// Used to specify the key associated with this message.
// PUT_VALUE, GET_VALUE, ADD_PROVIDER, GET_PROVIDERS
Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
// Used to return a value
// PUT_VALUE, GET_VALUE
Record *pb.Record `protobuf:"bytes,3,opt,name=record,proto3" json:"record,omitempty"`
// Used to return peers closer to a key in a query
// GET_VALUE, GET_PROVIDERS, FIND_NODE
CloserPeers []*Message_Peer `protobuf:"bytes,8,rep,name=closerPeers,proto3" json:"closerPeers,omitempty"`
// Used to return Providers
// GET_VALUE, ADD_PROVIDER, GET_PROVIDERS
ProviderPeers []*Message_Peer `protobuf:"bytes,9,rep,name=providerPeers,proto3" json:"providerPeers,omitempty"`
// contains filtered or unexported fields
}
func NewMessage ¶
func NewMessage(typ Message_MessageType, key []byte, level int) *Message
NewMessage constructs a new dht message with given type, key, and level
func (*Message) Descriptor
deprecated
func (*Message) GetCloserPeers ¶
func (x *Message) GetCloserPeers() []*Message_Peer
func (*Message) GetClusterLevel ¶
GetClusterLevel gets and adjusts the cluster level on the message. a +/- 1 adjustment is needed to distinguish a valid first level (1) and default "no value" protobuf behavior (0)
func (*Message) GetClusterLevelRaw ¶
func (*Message) GetProviderPeers ¶
func (x *Message) GetProviderPeers() []*Message_Peer
func (*Message) GetType ¶
func (x *Message) GetType() Message_MessageType
func (*Message) ProtoMessage ¶
func (*Message) ProtoMessage()
func (*Message) ProtoReflect ¶ added in v0.29.0
func (x *Message) ProtoReflect() protoreflect.Message
func (*Message) SetClusterLevel ¶
SetClusterLevel adjusts and sets the cluster level on the message. a +/- 1 adjustment is needed to distinguish a valid first level (1) and default "no value" protobuf behavior (0)
type MessageSender ¶ added in v0.12.0
type MessageSender interface {
// SendRequest sends a peer a message and waits for its response
SendRequest(ctx context.Context, p peer.ID, pmes *Message) (*Message, error)
// SendMessage sends a peer a message without waiting on a response
SendMessage(ctx context.Context, p peer.ID, pmes *Message) error
}
MessageSender handles sending wire protocol messages to a given peer
type MessageSenderWithDisconnect ¶ added in v0.24.1
type MessageSenderWithDisconnect interface {
MessageSender
OnDisconnect(context.Context, peer.ID)
}
type Message_ConnectionType ¶
type Message_ConnectionType int32
const ( // sender does not have a connection to peer, and no extra information // (default) Message_NOT_CONNECTED Message_ConnectionType = 0 // sender has a live connection to peer Message_CONNECTED Message_ConnectionType = 1 // sender recently connected to peer Message_CAN_CONNECT Message_ConnectionType = 2 // sender recently tried to connect to peer repeatedly but failed to connect // ("try" here is loose, but this should signal "made strong effort, // failed") Message_CANNOT_CONNECT Message_ConnectionType = 3 )
func ConnectionType ¶
func ConnectionType(c network.Connectedness) Message_ConnectionType
ConnectionType returns a Message_ConnectionType associated with the network.Connectedness.
func (Message_ConnectionType) Descriptor ¶ added in v0.29.0
func (Message_ConnectionType) Descriptor() protoreflect.EnumDescriptor
func (Message_ConnectionType) Enum ¶ added in v0.29.0
func (x Message_ConnectionType) Enum() *Message_ConnectionType
func (Message_ConnectionType) EnumDescriptor
deprecated
func (Message_ConnectionType) EnumDescriptor() ([]byte, []int)
Deprecated: Use Message_ConnectionType.Descriptor instead.
func (Message_ConnectionType) Number ¶ added in v0.29.0
func (x Message_ConnectionType) Number() protoreflect.EnumNumber
func (Message_ConnectionType) String ¶
func (x Message_ConnectionType) String() string
func (Message_ConnectionType) Type ¶ added in v0.29.0
func (Message_ConnectionType) Type() protoreflect.EnumType
type Message_MessageType ¶
type Message_MessageType int32
const ( Message_PUT_VALUE Message_MessageType = 0 Message_GET_VALUE Message_MessageType = 1 Message_ADD_PROVIDER Message_MessageType = 2 Message_GET_PROVIDERS Message_MessageType = 3 Message_FIND_NODE Message_MessageType = 4 Message_PING Message_MessageType = 5 )
func (Message_MessageType) Descriptor ¶ added in v0.29.0
func (Message_MessageType) Descriptor() protoreflect.EnumDescriptor
func (Message_MessageType) Enum ¶ added in v0.29.0
func (x Message_MessageType) Enum() *Message_MessageType
func (Message_MessageType) EnumDescriptor
deprecated
func (Message_MessageType) EnumDescriptor() ([]byte, []int)
Deprecated: Use Message_MessageType.Descriptor instead.
func (Message_MessageType) Number ¶ added in v0.29.0
func (x Message_MessageType) Number() protoreflect.EnumNumber
func (Message_MessageType) String ¶
func (x Message_MessageType) String() string
func (Message_MessageType) Type ¶ added in v0.29.0
func (Message_MessageType) Type() protoreflect.EnumType
type Message_Peer ¶
type Message_Peer struct {
// ID of a given peer.
Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
// multiaddrs for a given peer
Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs,proto3" json:"addrs,omitempty"`
// used to signal the sender's connection capabilities to the peer
Connection Message_ConnectionType `protobuf:"varint,3,opt,name=connection,proto3,enum=dht.pb.Message_ConnectionType" json:"connection,omitempty"`
// contains filtered or unexported fields
}
func PeerInfoToPBPeer ¶ added in v0.42.0
func PeerInfoToPBPeer(n network.Network, p peer.AddrInfo) *Message_Peer
PeerInfoToPBPeer converts a single peer.AddrInfo into a *Message_Peer ready to go out on the wire, setting the ConnectionType from the given network.Network. It is the one-peer form of PeerInfosToPBPeers.
func PeerInfosToPBPeers ¶
func PeerInfosToPBPeers(n network.Network, peers []peer.AddrInfo) []*Message_Peer
PeerInfosToPBPeers converts given []peer.AddrInfo into a set of []*Message_Peer, which can be written to a message and sent out. The key thing this function does (in addition to RawPeerInfosToPBPeers) is set the ConnectionType with information from the given network.Network.
func PeerRoutingInfosToPBPeers ¶
func PeerRoutingInfosToPBPeers(peers []PeerRoutingInfo) []*Message_Peer
func RawPeerInfosToPBPeers ¶
func RawPeerInfosToPBPeers(peers []peer.AddrInfo) []*Message_Peer
RawPeerInfosToPBPeers converts a slice of Peers into a slice of *Message_Peers, ready to go out on the wire.
func (*Message_Peer) Addresses ¶
func (m *Message_Peer) Addresses() []ma.Multiaddr
Addresses returns a multiaddr associated with the Message_Peer entry
func (*Message_Peer) Descriptor
deprecated
func (*Message_Peer) Descriptor() ([]byte, []int)
Deprecated: Use Message_Peer.ProtoReflect.Descriptor instead.
func (*Message_Peer) GetAddrs ¶
func (x *Message_Peer) GetAddrs() [][]byte
func (*Message_Peer) GetConnection ¶
func (x *Message_Peer) GetConnection() Message_ConnectionType
func (*Message_Peer) GetId ¶
func (x *Message_Peer) GetId() []byte
func (*Message_Peer) ProtoMessage ¶
func (*Message_Peer) ProtoMessage()
func (*Message_Peer) ProtoReflect ¶ added in v0.29.0
func (x *Message_Peer) ProtoReflect() protoreflect.Message
func (*Message_Peer) Reset ¶
func (x *Message_Peer) Reset()
func (*Message_Peer) String ¶
func (x *Message_Peer) String() string
type PeerRoutingInfo ¶
type PeerRoutingInfo struct {
peer.AddrInfo
network.Connectedness
}
type ProtocolMessenger ¶ added in v0.12.0
type ProtocolMessenger struct {
// contains filtered or unexported fields
}
ProtocolMessenger can be used for sending DHT messages to peers and processing their responses. This decouples the wire protocol format from both the DHT protocol implementation and from the implementation of the routing.Routing interface.
Note: the ProtocolMessenger's MessageSender still needs to deal with some wire protocol details such as using varint-delineated protobufs
func NewProtocolMessenger ¶ added in v0.12.0
func NewProtocolMessenger(msgSender MessageSender, opts ...ProtocolMessengerOption) (*ProtocolMessenger, error)
NewProtocolMessenger creates a new ProtocolMessenger that is used for sending DHT messages to peers and processing their responses.
func (*ProtocolMessenger) GetClosestPeers ¶ added in v0.12.0
func (pm *ProtocolMessenger) GetClosestPeers(ctx context.Context, p peer.ID, id peer.ID) (closerPeers []*peer.AddrInfo, err error)
GetClosestPeers asks a peer to return the K (a DHT-wide parameter) DHT server peers closest in XOR space to the id Note: If the peer happens to know another peer whose peerID exactly matches the given id it will return that peer even if that peer is not a DHT server node.
func (*ProtocolMessenger) GetProviders ¶ added in v0.12.0
func (pm *ProtocolMessenger) GetProviders(ctx context.Context, p peer.ID, key multihash.Multihash) (provs []*peer.AddrInfo, closerPeers []*peer.AddrInfo, err error)
GetProviders asks a peer for the providers it knows of for a given key. Also returns the K closest peers to the key as described in GetClosestPeers.
func (*ProtocolMessenger) GetValue ¶ added in v0.12.0
func (pm *ProtocolMessenger) GetValue(ctx context.Context, p peer.ID, key string) (record *recpb.Record, closerPeers []*peer.AddrInfo, err error)
GetValue asks a peer for the value corresponding to the given key. Also returns the K closest peers to the key as described in GetClosestPeers.
func (*ProtocolMessenger) Ping ¶ added in v0.12.0
Ping sends a ping message to the passed peer and waits for a response.
func (*ProtocolMessenger) PutProvider ¶ added in v0.12.0
func (pm *ProtocolMessenger) PutProvider(ctx context.Context, p peer.ID, key multihash.Multihash, h host.Host) error
PutProvider is deprecated please use ProtocolMessenger.PutProviderAddrs.
type ProtocolMessengerOption ¶ added in v0.12.0
type ProtocolMessengerOption func(*ProtocolMessenger) error