dht_pb

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthDht        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowDht          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupDht = fmt.Errorf("proto: unexpected end of group")
)
View Source
var Message_ConnectionType_name = map[int32]string{
	0: "NOT_CONNECTED",
	1: "CONNECTED",
	2: "CAN_CONNECT",
	3: "CANNOT_CONNECT",
}
View Source
var Message_ConnectionType_value = map[string]int32{
	"NOT_CONNECTED":  0,
	"CONNECTED":      1,
	"CAN_CONNECT":    2,
	"CANNOT_CONNECT": 3,
}
View Source
var Message_MessageType_name = map[int32]string{
	0: "PUT_VALUE",
	1: "GET_VALUE",
	2: "ADD_PROVIDER",
	3: "GET_PROVIDERS",
	4: "FIND_NODE",
	5: "PING",
}
View Source
var Message_MessageType_value = map[string]int32{
	"PUT_VALUE":     0,
	"GET_VALUE":     1,
	"ADD_PROVIDER":  2,
	"GET_PROVIDERS": 3,
	"FIND_NODE":     4,
	"PING":          5,
}

Functions

func Connectedness

Connectedness returns an network.Connectedness associated with the Message_ConnectionType.

func PBPeerToPeerInfo

func PBPeerToPeerInfo(pbp Message_Peer) peer.AddrInfo

PBPeerToPeer turns a *Message_Peer into its peer.AddrInfo counterpart

func PBPeersToPeerInfos

func PBPeersToPeerInfos(pbps []Message_Peer) []*peer.AddrInfo

PBPeersToPeerInfos converts given []*Message_Peer into []peer.AddrInfo Invalid addresses will be silently omitted.

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"`
	// Used to return Providers
	// GET_VALUE, ADD_PROVIDER, GET_PROVIDERS
	ProviderPeers        []Message_Peer `protobuf:"bytes,9,rep,name=providerPeers,proto3" json:"providerPeers"`
	XXX_NoUnkeyedLiteral struct{}       `json:"-"`
	XXX_unrecognized     []byte         `json:"-"`
	XXX_sizecache        int32          `json:"-"`
}

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

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

func (*Message) GetCloserPeers

func (m *Message) GetCloserPeers() []Message_Peer

func (*Message) GetClusterLevel

func (m *Message) GetClusterLevel() int

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 (m *Message) GetClusterLevelRaw() int32

func (*Message) GetKey

func (m *Message) GetKey() []byte

func (*Message) GetProviderPeers

func (m *Message) GetProviderPeers() []Message_Peer

func (*Message) GetRecord

func (m *Message) GetRecord() *pb.Record

func (*Message) GetType

func (m *Message) GetType() Message_MessageType

func (*Message) Marshal

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

func (*Message) MarshalTo

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

func (*Message) MarshalToSizedBuffer

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

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) Reset

func (m *Message) Reset()

func (*Message) SetClusterLevel

func (m *Message) SetClusterLevel(level int)

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)

func (*Message) Size

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

func (*Message) String

func (m *Message) String() string

func (*Message) Unmarshal

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

func (*Message) XXX_DiscardUnknown

func (m *Message) XXX_DiscardUnknown()

func (*Message) XXX_Marshal

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

func (*Message) XXX_Merge

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

func (*Message) XXX_Size

func (m *Message) XXX_Size() int

func (*Message) XXX_Unmarshal

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

type MessageSender

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 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

ConnectionType returns a Message_ConnectionType associated with the network.Connectedness.

func (Message_ConnectionType) EnumDescriptor

func (Message_ConnectionType) EnumDescriptor() ([]byte, []int)

func (Message_ConnectionType) String

func (x Message_ConnectionType) String() string

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) EnumDescriptor

func (Message_MessageType) EnumDescriptor() ([]byte, []int)

func (Message_MessageType) String

func (x Message_MessageType) String() string

type Message_Peer

type Message_Peer struct {
	// ID of a given peer.
	Id byteString `protobuf:"bytes,1,opt,name=id,proto3,customtype=byteString" json:"id"`
	// 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"`
	XXX_NoUnkeyedLiteral struct{}               `json:"-"`
	XXX_unrecognized     []byte                 `json:"-"`
	XXX_sizecache        int32                  `json:"-"`
}

func PeerInfosToPBPeers

func PeerInfosToPBPeers(n network.Network, peers []peer.AddrInfo) []Message_Peer

PeersToPBPeers converts given []peer.Peer 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 PeersToPBPeers) 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

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

func (*Message_Peer) GetAddrs

func (m *Message_Peer) GetAddrs() [][]byte

func (*Message_Peer) GetConnection

func (m *Message_Peer) GetConnection() Message_ConnectionType

func (*Message_Peer) Marshal

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

func (*Message_Peer) MarshalTo

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

func (*Message_Peer) MarshalToSizedBuffer

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

func (*Message_Peer) ProtoMessage

func (*Message_Peer) ProtoMessage()

func (*Message_Peer) Reset

func (m *Message_Peer) Reset()

func (*Message_Peer) Size

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

func (*Message_Peer) String

func (m *Message_Peer) String() string

func (*Message_Peer) Unmarshal

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

func (*Message_Peer) XXX_DiscardUnknown

func (m *Message_Peer) XXX_DiscardUnknown()

func (*Message_Peer) XXX_Marshal

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

func (*Message_Peer) XXX_Merge

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

func (*Message_Peer) XXX_Size

func (m *Message_Peer) XXX_Size() int

func (*Message_Peer) XXX_Unmarshal

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

type PeerRoutingInfo

type PeerRoutingInfo struct {
	peer.AddrInfo
	network.Connectedness
}

type ProtocolMessenger

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

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

func (pm *ProtocolMessenger) GetClosestPeers(ctx context.Context, p peer.ID, id peer.ID) ([]*peer.AddrInfo, 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

func (pm *ProtocolMessenger) GetProviders(ctx context.Context, p peer.ID, key multihash.Multihash) ([]*peer.AddrInfo, []*peer.AddrInfo, 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

func (pm *ProtocolMessenger) GetValue(ctx context.Context, p peer.ID, key string) (*recpb.Record, []*peer.AddrInfo, 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

func (pm *ProtocolMessenger) Ping(ctx context.Context, p peer.ID) error

Ping sends a ping message to the passed peer and waits for a response.

func (*ProtocolMessenger) PutProvider

func (pm *ProtocolMessenger) PutProvider(ctx context.Context, p peer.ID, key multihash.Multihash, host host.Host) error

PutProvider asks a peer to store that we are a provider for the given key.

func (*ProtocolMessenger) PutValue

func (pm *ProtocolMessenger) PutValue(ctx context.Context, p peer.ID, rec *recpb.Record) error

PutValue asks a peer to store the given key/value pair.

type ProtocolMessengerOption

type ProtocolMessengerOption func(*ProtocolMessenger) error

Jump to

Keyboard shortcuts

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