kademlia

package
v0.0.0-...-85dbdb0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NIL = ""

	M     = 160
	K     = 20
	B     = 5
	Alpha = 3

	PingAttempt   = 4
	DialAttempt   = 4
	DialTimeOut   = 300 * time.Millisecond
	PingTimeOut   = 500 * time.Millisecond
	LookupTimeOut = 500 * time.Millisecond

	ExpireTime        = 40 * time.Second
	RefreshInterval   = 30 * time.Second
	RepublishInterval = 30 * time.Second
)

Variables

View Source
var IDGenerator *rand.Rand

Functions

func NewBucketList

func NewBucketList(addr Address, pro *protocol) *bucketList

func NewKBucket

func NewKBucket(initRange *IDRange) *kBucket

func NewStorage

func NewStorage() *storage

func SharedPrefixLen

func SharedPrefixLen(x, y Identifer) int

Types

type Address

type Address = string

type BuckWithDist

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

type ContWithDist

type ContWithDist struct {
	Cont Contact
	Dist Identifer
}

type Contact

type Contact struct {
	Addr Address
	ID   Identifer
}

func NewContact

func NewContact(addr Address) *Contact

type ContactHeap

type ContactHeap []ContWithDist

func (ContactHeap) Len

func (h ContactHeap) Len() int

func (ContactHeap) Less

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

func (*ContactHeap) Pop

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

func (*ContactHeap) Push

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

func (ContactHeap) Swap

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

type DataPair

type DataPair struct {
	Key KeyType
	Val ValueType
}

type FindNodeReply

type FindNodeReply struct {
	LookupRet
}

type FindNodeRequest

type FindNodeRequest struct {
	RpcHeader
	ID Identifer
}

type FindValueReply

type FindValueReply struct {
	LookupRet
}

type FindValueRequest

type FindValueRequest struct {
	RpcHeader
	Key KeyType
}

type IDRange

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

type Identifer

type Identifer = *big.Int

func Distance

func Distance(x, y Identifer) Identifer

func IDpow2

func IDpow2(x int) Identifer

func NewID

func NewID(x int64) Identifer

func RandomID

func RandomID(interval IDRange) Identifer

type KademliaNode

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

func NewKademliaNode

func NewKademliaNode(addr Address) *KademliaNode

func (*KademliaNode) Create

func (k *KademliaNode) Create()

func (*KademliaNode) Delete

func (k *KademliaNode) Delete(key KeyType) bool

func (*KademliaNode) ForceQuit

func (k *KademliaNode) ForceQuit()

func (*KademliaNode) Get

func (k *KademliaNode) Get(key KeyType) (bool, ValueType)

func (*KademliaNode) Join

func (k *KademliaNode) Join(addr Address) bool

func (*KademliaNode) Ping

func (k *KademliaNode) Ping(addr Address) bool

func (*KademliaNode) Put

func (k *KademliaNode) Put(key KeyType, value ValueType) bool

func (*KademliaNode) Quit

func (k *KademliaNode) Quit()

func (*KademliaNode) Run

func (k *KademliaNode) Run()

type KeyType

type KeyType = string

type LookupRet

type LookupRet struct {
	Found   bool
	FoundBy Contact
	Cont    []ContWithDist
	Value   ValueType
}

type LookupRpc

type LookupRpc func(Contact, KeyType, Identifer) (LookupRet, error)

type PingReply

type PingReply struct {
	RpcHeader
}

type PingRequst

type PingRequst struct {
	RpcHeader
}

type RpcHeader

type RpcHeader struct {
	Sender Contact
}

type StoreReply

type StoreReply struct{}

type StoreRequest

type StoreRequest struct {
	RpcHeader
	Key        KeyType
	Val        ValueType
	Cached     bool
	ExpireTime time.Duration
}

type ValueType

type ValueType = string

Jump to

Keyboard shortcuts

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