kademlia

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

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

Go to latest
Published: May 7, 2016 License: MIT Imports: 11 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
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallHeader

type CallHeader struct {
	Sender    Contact
	NetworkID string
}

Generic call base

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 {
	CallHeader
	Target NodeID
}

type FindNodeResponse

type FindNodeResponse struct {
	CallHeader
	Contacts Contacts
}

type FindValueRequest

type FindValueRequest struct {
	CallHeader
	Target NodeID
}

type FindValueResponse

type FindValueResponse struct {
	CallHeader
	Contacts Contacts
	Value    []byte
}

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 {
	Storage   KademliaStorage
	Network   KademliaNetwork
	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) FindNodeHandler

func (k *Kademlia) FindNodeHandler(req FindNodeRequest, res *FindNodeResponse) error

func (*Kademlia) FindValue

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

func (*Kademlia) FindValueHandler

func (k *Kademlia) FindValueHandler(req FindValueRequest, res *FindValueResponse) error

func (*Kademlia) HandleCall

func (k *Kademlia) HandleCall(request CallHeader, response *CallHeader) error

Every call 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) NewStoreValueRequest

func (k *Kademlia) NewStoreValueRequest(target NodeID, value []byte) StoreValueRequest

func (*Kademlia) Ping

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

func (*Kademlia) PingHandler

func (k *Kademlia) PingHandler(req PingRequest, res *PingResponse) error

func (*Kademlia) StoreValue

func (k *Kademlia) StoreValue(contact Contact, target NodeID, value []byte) ([]Contact, error)

func (*Kademlia) StoreValueHandler

func (k *Kademlia) StoreValueHandler(req StoreValueRequest, res *StoreValueResponse) error

type KademliaClient

type KademliaClient interface {
	FindNode(req FindNodeRequest, res *FindNodeResponse) error
	FindValue(req FindValueRequest, res *FindValueResponse) error
	Ping(req PingRequest, res *PingResponse) error
	StoreValue(req StoreValueRequest, res *StoreValueResponse) error
}

type KademliaNetwork

type KademliaNetwork interface {
	Connect(contact Contact) (client KademliaClient, err error)
}

type KademliaNodeHandler

type KademliaNodeHandler interface {
	FindNodeHandler(req FindNodeRequest, res *FindNodeResponse) error
	FindValueHandler(req FindValueRequest, res *FindValueResponse) error
	PingHandler(req PingRequest, res *PingResponse) error
	StoreValueHandler(req StoreValueRequest, res *StoreValueResponse) error
}

type KademliaStorage

type KademliaStorage interface {
	Put(key NodeID, value []byte) error
	Get(key NodeID) (value []byte, err error)
}

type MapStorage

type MapStorage struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMapStorage

func NewMapStorage() *MapStorage

func (*MapStorage) Get

func (storage *MapStorage) Get(key NodeID) ([]byte, error)

func (*MapStorage) Put

func (storage *MapStorage) Put(key NodeID, value []byte) 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 {
	CallHeader
}

type PingResponse

type PingResponse struct {
	CallHeader
}

type RPCClientConnection

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

func (*RPCClientConnection) FindNode

func (c *RPCClientConnection) FindNode(req FindNodeRequest, res *FindNodeResponse) (err error)

func (*RPCClientConnection) FindValue

func (c *RPCClientConnection) FindValue(req FindValueRequest, res *FindValueResponse) (err error)

func (*RPCClientConnection) Ping

func (c *RPCClientConnection) Ping(req PingRequest, res *PingResponse) (err error)

func (*RPCClientConnection) StoreValue

func (c *RPCClientConnection) StoreValue(req StoreValueRequest, res *StoreValueResponse) (err error)

type RPCNetwork

type RPCNetwork struct{}

func NewRPCNetwork

func NewRPCNetwork() *RPCNetwork

func (*RPCNetwork) Connect

func (n *RPCNetwork) Connect(contact Contact) (c KademliaClient, err error)

type RPCNode

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

func NewRPCNode

func NewRPCNode(handler KademliaNodeHandler) *RPCNode

func (*RPCNode) Serve

func (n *RPCNode) Serve(address string) error

type RPCNodeCore

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

func (*RPCNodeCore) FindNodeRPC

func (n *RPCNodeCore) FindNodeRPC(req FindNodeRequest, res *FindNodeResponse) error

func (*RPCNodeCore) FindValueRPC

func (n *RPCNodeCore) FindValueRPC(req FindValueRequest, res *FindValueResponse) error

func (*RPCNodeCore) PingRPC

func (n *RPCNodeCore) PingRPC(req PingRequest, res *PingResponse) error

func (*RPCNodeCore) StoreValueRPC

func (n *RPCNodeCore) StoreValueRPC(req StoreValueRequest, res *StoreValueResponse) error

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)

type StoreValueRequest

type StoreValueRequest struct {
	CallHeader
	Target NodeID
	Value  []byte
}

type StoreValueResponse

type StoreValueResponse struct {
	CallHeader
	Contacts Contacts
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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