Kademlia

package
v0.0.0-...-3638f0a Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const IDlength int = 160
View Source
const K int = 48 // buckets size
View Source
const SleepTime time.Duration = 20 * time.Millisecond
View Source
const WaitTime time.Duration = 250 * time.Millisecond

Variables

This section is empty.

Functions

func CalHash

func CalHash(str string) (result *big.Int)

func GenerateClient

func GenerateClient(address string) (*rpc.Client, error)

func GetLocalIP

func GetLocalIP() string

func IfOnline

func IfOnline(address string) bool

func PingAndCheckOnline

func PingAndCheckOnline(self *Node, addr *AddrType) bool

func PrefixLen

func PrefixLen(Id *big.Int) int

func RemoteCall

func RemoteCall(self *Node, targetAddr *AddrType, serviceMethod string, args interface{}, reply interface{}) error

func Sort

func Sort(dataSet *[]ClosestListNode)

func WrappedAccept

func WrappedAccept(server *rpc.Server, lis net.Listener, ptr *Node)

func Xor

func Xor(node, other *big.Int) (result *big.Int)

Types

type AddrType

type AddrType struct {
	Ip string
	Id *big.Int
}

func CalNodeId

func CalNodeId(origin AddrType, adder int64) (result AddrType)

func GenerateAddr

func GenerateAddr(addr string) (result AddrType)

func (*AddrType) Copy

func (node *AddrType) Copy(other AddrType)

func (*AddrType) Equals

func (node *AddrType) Equals(other AddrType) bool

func (*AddrType) Less

func (node *AddrType) Less(other AddrType) bool

type ClosestListNode

type ClosestListNode struct {
	Key  *big.Int
	Addr AddrType
}

type Datamanager

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

type FindNodeArg

type FindNodeArg struct {
	ReqAddr AddrType
	Target  *big.Int
}

type FindNodeRep

type FindNodeRep struct {
	ReqAddr AddrType
	RepAddr AddrType
	Content []ClosestListNode
}

type FindValueArg

type FindValueArg struct {
	Key     string
	ReqAddr AddrType
}

type FindValueRep

type FindValueRep struct {
	ReqAddr AddrType
	RepAddr AddrType
	Content []ClosestListNode
	IfFind  bool
	Value   string
}

type Node

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

func (*Node) Background

func (ptr *Node) Background()

func (*Node) Create

func (ptr *Node) Create()

func (*Node) Delete

func (ptr *Node) Delete(key string) bool

func (*Node) Duplicate

func (ptr *Node) Duplicate()

func (*Node) Expire

func (ptr *Node) Expire()

func (*Node) FindClosestNode

func (ptr *Node) FindClosestNode(target AddrType) []ClosestListNode

func (*Node) ForceQuit

func (ptr *Node) ForceQuit()

func (*Node) Get

func (ptr *Node) Get(key string) (bool, string)

func (*Node) Init

func (ptr *Node) Init(port int)

func (*Node) Join

func (ptr *Node) Join(address string) bool

func (*Node) Ping

func (ptr *Node) Ping(requester string) bool

func (*Node) Put

func (ptr *Node) Put(key string, value string) bool

func (*Node) Quit

func (ptr *Node) Quit()

func (*Node) RangePut

func (ptr *Node) RangePut(request StoreArg)

func (*Node) Refresh

func (ptr *Node) Refresh()

func (*Node) Republic

func (ptr *Node) Republic()

func (*Node) Run

func (ptr *Node) Run()

type RoutingTable

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

func (*RoutingTable) FindClosest

func (ptr *RoutingTable) FindClosest(targetID *big.Int, count int) []ClosestListNode

func (*RoutingTable) InitRoutingTable

func (ptr *RoutingTable) InitRoutingTable(nodeAddr AddrType)

func (*RoutingTable) Update

func (ptr *RoutingTable) Update(contact *AddrType)

type RpcNode

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

func (*RpcNode) FindNode

func (ptr *RpcNode) FindNode(arg FindNodeArg, result *FindNodeRep) error

func (*RpcNode) FindValue

func (ptr *RpcNode) FindValue(input FindValueArg, result *FindValueRep) error

func (*RpcNode) Ping

func (ptr *RpcNode) Ping(requester AddrType, result *string) error

func (*RpcNode) Store

func (ptr *RpcNode) Store(arg StoreArg, result *string) error

type StoreArg

type StoreArg struct {
	Key   string
	Value string

	ReqAddr AddrType
	// contains filtered or unexported fields
}

type WrapNode

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

func GenerateWrapNode

func GenerateWrapNode(self *Node, addr string) WrapNode

func (*WrapNode) FindNode

func (ptr *WrapNode) FindNode(arg *FindNodeArg, rep *FindNodeRep) error

func (*WrapNode) FindValue

func (ptr *WrapNode) FindValue(arg *FindValueArg, rep *FindValueRep) error

func (*WrapNode) Ping

func (ptr *WrapNode) Ping(targetAddr AddrType) error

func (*WrapNode) Store

func (ptr *WrapNode) Store(arg *StoreArg) error

Jump to

Keyboard shortcuts

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