Documentation ¶
Index ¶
- Constants
- Variables
- func CommonPrefixLen(a, b []byte) int
- func ConvertPeerID(id string) []byte
- func GetMyIP() (string, error)
- func NewKademliaNet(routingTable *RoutingTable, opt ...KademliaOpt) *kademliaNet
- func NewUUIDv4() string
- func RegisterKademliaServiceServer(s *grpc.Server, srv KademliaServiceServer)
- func XOR(a, b []byte) []byte
- type Bucket
- func (b *Bucket) Has(n Node) bool
- func (b *Bucket) Len() int
- func (b *Bucket) MoveToFront(n Node)
- func (b *Bucket) Nodes() []Node
- func (b *Bucket) PopBack() Node
- func (b *Bucket) PushFront(n Node)
- func (b *Bucket) Remove(n Node) bool
- func (b *Bucket) RemoveDeadNodes()
- func (b *Bucket) Split(cpl int, target []byte) *Bucket
- type KademliaOpt
- type KademliaServiceClient
- type KademliaServiceServer
- type Node
- type NodeInfo
- func (*NodeInfo) Descriptor() ([]byte, []int)
- func (m *NodeInfo) GetId() string
- func (m *NodeInfo) GetIp() string
- func (m *NodeInfo) GetPort() string
- func (*NodeInfo) ProtoMessage()
- func (m *NodeInfo) Reset()
- func (m *NodeInfo) String() string
- func (m *NodeInfo) XXX_DiscardUnknown()
- func (m *NodeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *NodeInfo) XXX_Merge(src proto.Message)
- func (m *NodeInfo) XXX_Size() int
- func (m *NodeInfo) XXX_Unmarshal(b []byte) error
- type Nodes
- func (*Nodes) Descriptor() ([]byte, []int)
- func (m *Nodes) GetNodes() []*NodeInfo
- func (*Nodes) ProtoMessage()
- func (m *Nodes) Reset()
- func (m *Nodes) String() string
- func (m *Nodes) XXX_DiscardUnknown()
- func (m *Nodes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Nodes) XXX_Merge(src proto.Message)
- func (m *Nodes) XXX_Size() int
- func (m *Nodes) XXX_Unmarshal(b []byte) error
- type Options
- type RoutingTable
- func (rt *RoutingTable) Find(id string) Node
- func (rt *RoutingTable) ListPeers() []Node
- func (rt *RoutingTable) NearestPeer(hashedID []byte) Node
- func (rt *RoutingTable) NearestPeers(hashedID []byte, count int) []Node
- func (rt *RoutingTable) Remove(n Node)
- func (rt *RoutingTable) RemoveDeadNodes()
- func (rt *RoutingTable) Size() int
- func (rt *RoutingTable) Update(n Node) (err error)
- type Target
- func (*Target) Descriptor() ([]byte, []int)
- func (m *Target) GetSender() *NodeInfo
- func (m *Target) GetTargetId() string
- func (*Target) ProtoMessage()
- func (m *Target) Reset()
- func (m *Target) String() string
- func (m *Target) XXX_DiscardUnknown()
- func (m *Target) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Target) XXX_Merge(src proto.Message)
- func (m *Target) XXX_Size() int
- func (m *Target) XXX_Unmarshal(b []byte) error
- type UnimplementedKademliaServiceServer
Constants ¶
const MaxTryConnCount = 3
Variables ¶
var ErrPeerRejectedNoCapacity = errors.New("peer rejected; insufficient capacity")
Functions ¶
func CommonPrefixLen ¶
func ConvertPeerID ¶
ConvertPeerID creates a DHT ID by hashing a Peer ID (Multihash)
func NewKademliaNet ¶
func NewKademliaNet(routingTable *RoutingTable, opt ...KademliaOpt) *kademliaNet
func RegisterKademliaServiceServer ¶
func RegisterKademliaServiceServer(s *grpc.Server, srv KademliaServiceServer)
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket holds a list of peers.
func (*Bucket) MoveToFront ¶
func (*Bucket) RemoveDeadNodes ¶
func (b *Bucket) RemoveDeadNodes()
type KademliaOpt ¶
type KademliaServiceClient ¶
type KademliaServiceClient interface {
FindNode(ctx context.Context, in *Target, opts ...grpc.CallOption) (*Nodes, error)
}
KademliaServiceClient is the client API for KademliaService service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewKademliaServiceClient ¶
func NewKademliaServiceClient(cc *grpc.ClientConn) KademliaServiceClient
type KademliaServiceServer ¶
KademliaServiceServer is the server API for KademliaService service.
type Node ¶
type Node struct { ID string HashedID []byte IP string Port string Conn *grpc.ClientConn FailedTryConnCount int }
func SortClosestPeers ¶
Sort the given peers by their ascending distance from the target. A new slice is returned.
type NodeInfo ¶
type NodeInfo struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Ip string `protobuf:"bytes,2,opt,name=ip,proto3" json:"ip,omitempty"` Port string `protobuf:"bytes,3,opt,name=port,proto3" json:"port,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*NodeInfo) Descriptor ¶
func (*NodeInfo) ProtoMessage ¶
func (*NodeInfo) ProtoMessage()
func (*NodeInfo) XXX_DiscardUnknown ¶
func (m *NodeInfo) XXX_DiscardUnknown()
func (*NodeInfo) XXX_Marshal ¶
func (*NodeInfo) XXX_Unmarshal ¶
type Nodes ¶
type Nodes struct { Nodes []*NodeInfo `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Nodes) Descriptor ¶
func (*Nodes) ProtoMessage ¶
func (*Nodes) ProtoMessage()
func (*Nodes) XXX_DiscardUnknown ¶
func (m *Nodes) XXX_DiscardUnknown()
func (*Nodes) XXX_Marshal ¶
func (*Nodes) XXX_Unmarshal ¶
type Options ¶
type Options struct { BucketSize int ID string IP string Port string PeerRemoved func(string) PeerAdded func(string) }
Options for initialize routing table
type RoutingTable ¶
type RoutingTable struct { // kBuckets define all the fingers to other nodes. Buckets []*Bucket PeerRemoved func(string) PeerAdded func(string) // contains filtered or unexported fields }
RoutingTable defines the routing table.
func NewRoutingTable ¶
func NewRoutingTable(options *Options) *RoutingTable
NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance.
func (*RoutingTable) Find ¶
func (rt *RoutingTable) Find(id string) Node
Find a specific peer by ID or return nil
func (*RoutingTable) ListPeers ¶
func (rt *RoutingTable) ListPeers() []Node
ListPeers takes a RoutingTable and returns a list of all peers from all buckets in the table.
func (*RoutingTable) NearestPeer ¶
func (rt *RoutingTable) NearestPeer(hashedID []byte) Node
NearestPeer returns a single peer that is nearest to the given ID
func (*RoutingTable) NearestPeers ¶
func (rt *RoutingTable) NearestPeers(hashedID []byte, count int) []Node
NearestPeers returns a list of the 'count' closest peers to the given ID
func (*RoutingTable) Remove ¶
func (rt *RoutingTable) Remove(n Node)
Remove deletes a peer from the routing table. This is to be used when we are sure a node has disconnected completely.
func (*RoutingTable) RemoveDeadNodes ¶
func (rt *RoutingTable) RemoveDeadNodes()
func (*RoutingTable) Size ¶
func (rt *RoutingTable) Size() int
Size returns the total number of peers in the routing table
func (*RoutingTable) Update ¶
func (rt *RoutingTable) Update(n Node) (err error)
Update adds or moves the given peer to the front of its respective bucket
type Target ¶
type Target struct { TargetId string `protobuf:"bytes,1,opt,name=target_id,json=targetId,proto3" json:"target_id,omitempty"` Sender *NodeInfo `protobuf:"bytes,2,opt,name=sender,proto3" json:"sender,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Target) Descriptor ¶
func (*Target) GetTargetId ¶
func (*Target) ProtoMessage ¶
func (*Target) ProtoMessage()
func (*Target) XXX_DiscardUnknown ¶
func (m *Target) XXX_DiscardUnknown()
func (*Target) XXX_Marshal ¶
func (*Target) XXX_Unmarshal ¶
type UnimplementedKademliaServiceServer ¶
type UnimplementedKademliaServiceServer struct { }
UnimplementedKademliaServiceServer can be embedded to have forward compatible implementations.