Documentation ¶
Index ¶
- Constants
- func ValidateKV(kv *KV) (bool, error)
- type Contact
- type ContactCandidates
- func (candidates *ContactCandidates) Append(contacts []Contact)
- func (candidates *ContactCandidates) GetContacts(count int) []Contact
- func (candidates *ContactCandidates) Len() int
- func (candidates *ContactCandidates) Less(i, j int) bool
- func (candidates *ContactCandidates) Sort()
- func (candidates *ContactCandidates) Swap(i, j int)
- type DHT
- type FindContactsReq
- type FindContactsResp
- type GetReq
- type GetResp
- type KV
- type Kademlia
- func (k *Kademlia) FindContact(kademliaID string, ctx context.Context) (Contact, error)
- func (k *Kademlia) FindContacts(kademliaID string, count int, ctx context.Context) ([]Contact, error)
- func (k *Kademlia) Get(id string, key string, replicationFactor int, ctx context.Context) ([]KV, error)
- func (k *Kademlia) GetContact() Contact
- func (k *Kademlia) LookupNode(id string, name string, ctx context.Context) (*p2p.Node, error)
- func (k *Kademlia) Put(id string, prvKey string, key string, value string, replicationFactor int, ...) error
- func (k *Kademlia) RegisterNetwork(bootstrapNode p2p.Node, kademliaID string, ctx context.Context) error
- func (k *Kademlia) RegisterNetworkWithAddr(bootstrapNodeAddr string, kademliaID string, ctx context.Context) error
- func (k *Kademlia) RegisterNode(id string, prvKey string, node *p2p.Node, ctx context.Context) error
- func (k *Kademlia) Shutdown()
- type KademliaID
- type PingReq
- type PingResp
- type PutReq
- type PutResp
- type RPCHeader
Constants ¶
View Source
const ( MSG_PING_REQ int = iota MSG_PING_RESP MSG_FIND_CONTACTS_REQ MSG_FIND_CONTACTS_RESP MSG_PUT_REQ MSG_PUT_RESP MSG_GET_REQ MSG_GET_RESP )
View Source
const ( FIND_CONTACTS_STATUS_SUCCESS = 0 FIND_CONTACTS_STATUS_ERROR = 1 )
View Source
const ( GET_STATUS_SUCCESS = 0 GET_STATUS_ERROR = 1 )
View Source
const ( PING_STATUS_SUCCESS = 0 PING_STATUS_ERROR = 1 )
View Source
const ( PUT_STATUS_SUCCESS = 0 PUT_STATUS_ERROR = 1 )
View Source
const ( ADD_CONTACT int = 0 FIND_CONTACTS int = 1 PUT int = 2 GET int = 3 STOP int = 100 )
View Source
const IDLength = 32
View Source
const MAX_COUNT = 100
View Source
const MaxPendingRequests = 10000
View Source
const RegistrationReplicationFactor = 10
Variables ¶
This section is empty.
Functions ¶
func ValidateKV ¶
Types ¶
type Contact ¶
type Contact struct { ID KademliaID `json:"kademliaid"` Node p2p.Node `json:"node"` // contains filtered or unexported fields }
func (*Contact) CalcDistance ¶
func (contact *Contact) CalcDistance(target KademliaID)
type ContactCandidates ¶
type ContactCandidates struct {
// contains filtered or unexported fields
}
func (*ContactCandidates) Append ¶
func (candidates *ContactCandidates) Append(contacts []Contact)
func (*ContactCandidates) GetContacts ¶
func (candidates *ContactCandidates) GetContacts(count int) []Contact
func (*ContactCandidates) Len ¶
func (candidates *ContactCandidates) Len() int
func (*ContactCandidates) Less ¶
func (candidates *ContactCandidates) Less(i, j int) bool
func (*ContactCandidates) Sort ¶
func (candidates *ContactCandidates) Sort()
func (*ContactCandidates) Swap ¶
func (candidates *ContactCandidates) Swap(i, j int)
type DHT ¶
type DHT interface { // Register adds a new node to the DHT network using a bootstrap node's address and a unique KademliaID. // The context allows for request cancellation and timeout control. RegisterNetwork(bootstrapNode p2p.Node, kademliaID string, ctx context.Context) error // RegisterNetworkWithAddr adds a new node to the DHT network using a bootstrap node's address and a unique KademliaID. RegisterNetworkWithAddr(bootstrapNodeAddr string, kademliaID string, ctx context.Context) error // FindContact retrieves information about a node identified by its KademliaID. // It returns a Contact structure with the node's information or an error if the node is not found. FindContact(kademliaID string, ctx context.Context) (Contact, error) // FindContacts finds up to 'count' number of contacts closest to the specified KademliaID. // It returns a slice of Contact structures or an error if the operation fails. FindContacts(kademliaID string, count int, ctx context.Context) ([]Contact, error) // Put stores a value in the DHT under a specified key. The key must adhere to a specific format // '/key1/key2/.../keyN' with 1 to 5 alphanumeric sublevels and no trailing slash. The 'replicationFactor' // determines the number of nodes across which the value is replicated. // The first key (key1) is referred to as the root key and is used by the DHT to find the correct node to store the value. Put(id string, prvKey string, key string, value string, replicationFactor int, ctx context.Context) error // Get retrieves all values stored under the subkeys of a given path from the DHT. // The key provided must follow the defined format '/key1/key2/.../keyN' with 1 to 5 alphanumeric sublevels // and no trailing slash. This method fetched data stored under the hierarchical key structure. // It returns a map of subkey-value pairs if successful or an error if the retrieval operation fails or if the // specified path does not exist. Get(id string, key string, replicationFactor int, ctx context.Context) ([]KV, error) // GetContact returns the contact information of the local DHT node. GetContact() Contact RegisterNode(id string, prvKey string, node *p2p.Node, ctx context.Context) error LookupNode(id string, name string, ctx context.Context) (*p2p.Node, error) // Shutdown gracefully stops the DHT node and releases all resources. Shutdown() }
DHT defines the operations supported by a Distributed Hash Table in a Kademlia network.
type FindContactsReq ¶
type FindContactsReq struct { Header RPCHeader `json:"header"` KademliaID string `json:"kademliaid"` Count int `json:"count"` }
func ConvertJSONToFindContactsReq ¶
func ConvertJSONToFindContactsReq(jsonStr string) (*FindContactsReq, error)
func (*FindContactsReq) ToJSON ¶
func (req *FindContactsReq) ToJSON() (string, error)
type FindContactsResp ¶
type FindContactsResp struct { Header RPCHeader `json:"header"` Contacts []Contact `json:"contacts"` Status int `json:"status"` Error string `json:"error"` }
func ConvertJSONToFindContactsResp ¶
func ConvertJSONToFindContactsResp(jsonStr string) (*FindContactsResp, error)
func (*FindContactsResp) ToJSON ¶
func (resp *FindContactsResp) ToJSON() (string, error)
type GetReq ¶
func ConvertJSONToGetReq ¶
type GetResp ¶
type GetResp struct { Header RPCHeader `json:"header"` KVS []KV `json:"kvs"` Status int `json:"status"` Error string `json:"error"` }
func ConvertJSONToGetResp ¶
type KV ¶
type Kademlia ¶
type Kademlia struct { Contact Contact // contains filtered or unexported fields }
func CreateKademlia ¶
func (*Kademlia) FindContact ¶
func (*Kademlia) FindContacts ¶
func (*Kademlia) GetContact ¶
func (*Kademlia) LookupNode ¶
func (*Kademlia) RegisterNetwork ¶
func (*Kademlia) RegisterNetworkWithAddr ¶
func (*Kademlia) RegisterNode ¶
type KademliaID ¶
func CreateKademliaID ¶
func CreateKademliaID(data string) KademliaID
func NewRandomKademliaID ¶
func NewRandomKademliaID() KademliaID
func (KademliaID) CalcDistance ¶
func (kademliaID KademliaID) CalcDistance(target KademliaID) KademliaID
func (KademliaID) Equals ¶
func (kademliaID KademliaID) Equals(otherKademliaID KademliaID) bool
func (KademliaID) Less ¶
func (kademliaID KademliaID) Less(otherKademliaID KademliaID) bool
func (*KademliaID) String ¶
func (kademliaID *KademliaID) String() string
type PingResp ¶
type PingResp struct { Header RPCHeader `json:"header"` Status int `json:"status"` Error string `json:"error"` }
func ConvertJSONToPingResp ¶
type PutReq ¶
func ConvertJSONToPutReq ¶
Source Files ¶
- bucket.go
- contact.go
- dht.go
- dht_node.go
- dispatcher.go
- handlers.go
- kademlia.go
- kademliaid.go
- kvstore.go
- msg_types.go
- operations.go
- parsers.go
- routingtable.go
- rpc_findcontacts_req.go
- rpc_findcontacts_resp.go
- rpc_get_req.go
- rpc_get_resp.go
- rpc_header.go
- rpc_ping_req.go
- rpc_ping_resp.go
- rpc_put_req.go
- rpc_put_resp.go
- states.go
- validation.go
Click to show internal directories.
Click to hide internal directories.