kademlia

package module
v0.0.0-...-f901ba5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2015 License: MIT Imports: 12 Imported by: 0

README

kademlia

A golang implementation of the Kademlia DHT

Documentation

Index

Constants

View Source
const (
	Delta         = 3
	IDLength      = 20
	IDBytesLength = 8 * IDLength
	BucketSize    = 20
)
View Source
const (
	VALUES_DB_PATH = "db/values-"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Contact

type Contact struct {
	ID      NodeID
	Address string
}

func NewContact

func NewContact(node NodeID, address string) Contact

type ContactList

type ContactList *list.List

type Contacts

type Contacts []Contact

func (Contacts) Len

func (h Contacts) Len() int

func (Contacts) Less

func (h Contacts) Less(i, j int) bool

func (*Contacts) Pop

func (h *Contacts) Pop() interface{}

func (*Contacts) Push

func (h *Contacts) Push(x interface{})

func (Contacts) Swap

func (h Contacts) Swap(i, j int)

type FindNodeRequest

type FindNodeRequest struct {
	RPCHeader
	Target NodeID
}

type FindNodeResponse

type FindNodeResponse struct {
	RPCHeader
	Contacts Contacts
}

type FindValueRequest

type FindValueRequest struct {
	RPCHeader
	Target NodeID
}

type FindValueResponse

type FindValueResponse struct {
	RPCHeader
	Contacts Contacts
	Value    string
}

type KBucket

type KBucket struct {
	*list.List
}

func NewKBucket

func NewKBucket() *KBucket

func (*KBucket) Update

func (kb *KBucket) Update(contact Contact)

type Kademlia

type Kademlia struct {
	NetworkID string
	// contains filtered or unexported fields
}

func NewKademlia

func NewKademlia(self Contact, networkID string) *Kademlia

func (*Kademlia) Bootstrap

func (k *Kademlia) Bootstrap(target, self Contact) ([]Contact, error)

func (*Kademlia) FindNode

func (k *Kademlia) FindNode(contact Contact, target NodeID, done chan Contacts)

func (*Kademlia) FindValue

func (k *Kademlia) FindValue(contact Contact, target NodeID) ([]Contact, string,
	error)

func (*Kademlia) HandleRPC

func (k *Kademlia) HandleRPC(request RPCHeader, response *RPCHeader) error

Every RPC updates routing tables in Kademlia

func (*Kademlia) IterativeFindNode

func (k *Kademlia) IterativeFindNode(target NodeID, delta int, final chan Contacts)

func (*Kademlia) NewFindNodeRequest

func (k *Kademlia) NewFindNodeRequest(target NodeID) FindNodeRequest

func (*Kademlia) NewFindValueRequest

func (k *Kademlia) NewFindValueRequest(target NodeID) FindValueRequest

func (*Kademlia) NewPingRequest

func (k *Kademlia) NewPingRequest() PingRequest

func (*Kademlia) Ping

func (k *Kademlia) Ping(target Contact) error

func (*Kademlia) Serve

func (k *Kademlia) Serve() error

type KademliaCore

type KademliaCore struct {
	// contains filtered or unexported fields
}

func (*KademliaCore) FindNodeRPC

func (kc *KademliaCore) FindNodeRPC(req FindNodeRequest, res *FindNodeResponse) error

func (*KademliaCore) FindValueRPC

func (kc *KademliaCore) FindValueRPC(req FindValueRequest, res *FindValueResponse) error

func (*KademliaCore) PingRPC

func (kc *KademliaCore) PingRPC(req PingRequest, res *PingResponse) error

type NodeID

type NodeID [IDLength]byte

func NewNodeID

func NewNodeID(data string) (ret NodeID)

func NewRandomNodeID

func NewRandomNodeID() (ret NodeID)

func (NodeID) Equals

func (node NodeID) Equals(other NodeID) bool

func (NodeID) Less

func (node NodeID) Less(other interface{}) bool

func (NodeID) PrefixLen

func (node NodeID) PrefixLen(other NodeID) int

func (NodeID) String

func (node NodeID) String() string

func (NodeID) Xor

func (node NodeID) Xor(other NodeID) (ret NodeID)

type PingRequest

type PingRequest struct {
	RPCHeader
}

type PingResponse

type PingResponse struct {
	RPCHeader
}

type RPCHeader

type RPCHeader struct {
	Sender    Contact
	NetworkID string
}

Generic RPC base

type RoutingTable

type RoutingTable struct {
	// contains filtered or unexported fields
}

func NewRoutingTable

func NewRoutingTable(self Contact) *RoutingTable

func (*RoutingTable) FindClosest

func (rt *RoutingTable) FindClosest(target NodeID, delta int) Contacts

func (RoutingTable) Self

func (rt RoutingTable) Self() Contact

func (*RoutingTable) Update

func (rt *RoutingTable) Update(contact Contact)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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