kademlia

package
v0.0.0-...-e0a2cda Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ID_SIZE     int = 20
	BUCKET_SIZE int = 20
	K               = 8
)

Variables

This section is empty.

Functions

func SendMsg

func SendMsg(conn *net.UDPConn, returnAddress *net.UDPAddr, msg Message)

Types

type Kademlia

type Kademlia struct {
	Node       *Node
	Name       string // this is used as the chatroom ID
	Connection *net.UDPConn

	ResponseHandler map[string]ResponseFunc

	AwaitingResponse map[string]time.Time   // key is token - req/rep method
	ExtraInfo        map[string]interface{} // key is token. This is a store of random things that may be needed

	ResultChan map[string]chan interface{} // key is token
	// contains filtered or unexported fields
}

func NewKademlia

func NewKademlia() *Kademlia

func (*Kademlia) FindNode

func (dht *Kademlia) FindNode(remote *RemoteNode, cmp NodeID) string

func (*Kademlia) FindValue

func (dht *Kademlia) FindValue(remote *RemoteNode, key string) string

func (*Kademlia) LocalStore

func (dht *Kademlia) LocalStore(key string, value interface{})

LocalStore basically stores data in the local node

func (*Kademlia) Ping

func (dht *Kademlia) Ping(remote *RemoteNode) string

func (*Kademlia) PingIP

func (dht *Kademlia) PingIP(addr *net.UDPAddr) string

func (*Kademlia) Run

func (dht *Kademlia) Run()

func (*Kademlia) Store

func (dht *Kademlia) Store(remote *RemoteNode, key string, value interface{}) string

type Message

type Message struct {
	MessageType string
	SourceID    NodeID
	Token       string
	Message     interface{}
}

this is exported to allow for new query types although now only the 4 basic kademlia queries will be allowed

func NewMessage

func NewMessage() (Message, string)

func (*Message) InsertMessage

func (msg *Message) InsertMessage(message interface{})

type Node

type Node struct {
	ID            NodeID
	IP            string
	Port          int
	RoutingTable  *routingTable
	AddressToNode map[string]*RemoteNode

	Store map[string]interface{}
}

func NewNode

func NewNode() *Node

func (Node) Delete

func (node Node) Delete(remote *RemoteNode)

D

func (Node) GetClosestNodes

func (node Node) GetClosestNodes(n int) []*RemoteNode

func (Node) GetNClosestNodes

func (node Node) GetNClosestNodes(target NodeID, n int) []*RemoteNode

func (Node) GetNearestNode

func (node Node) GetNearestNode() *RemoteNode

func (Node) GetNode

func (node Node) GetNode(id NodeID) (remote *RemoteNode)

func (Node) GetNodeFromAddress

func (node Node) GetNodeFromAddress(address string) (remote *RemoteNode, exists bool)

R

func (Node) GetOrCreateNode

func (node Node) GetOrCreateNode(id NodeID, address string) (remote *RemoteNode)

func (Node) SpringClean

func (node Node) SpringClean()

spring clean basically purges the AddressToNode map, and refills it. spring cleaning should ideally happen every 10 minutes or so

func (Node) Update

func (node Node) Update(cmp *RemoteNode)

C & U

type NodeID

type NodeID []byte

func (NodeID) DistanceTo

func (id NodeID) DistanceTo(cmp NodeID) NodeID

func (NodeID) EqualsTo

func (id NodeID) EqualsTo(cmp NodeID) bool

func (NodeID) GetBucketID

func (id NodeID) GetBucketID() int

func (NodeID) LessThan

func (id NodeID) LessThan(cmp NodeID) bool

func (NodeID) String

func (id NodeID) String() string

type RemoteNode

type RemoteNode struct {
	ID      NodeID
	Address *net.UDPAddr
	// contains filtered or unexported fields
}

type ResponseFunc

type ResponseFunc func(*RemoteNode, string, NodeID, interface{})

Jump to

Keyboard shortcuts

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