kademlia

package
v0.0.0-...-a24eca1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NeedRePublishTime = 120 * time.Second
	ExpiredTime       = 960 * time.Second
)
View Source
const (
	M     = 16
	K     = 10
	Alpha = 3

	UpdateInterval = 25 * time.Millisecond

	RemoteTryTime     = 3
	RemoteTryInterval = 25 * time.Millisecond

	RePublishInterval = 100 * time.Millisecond
)

Variables

View Source
var Log = logrus.New()
View Source
var Mod = big.NewInt(0).Exp(big.NewInt(2), big.NewInt(M), nil)

Functions

func Diag

func Diag(addr string) (*rpc.Client, error)

func Hash

func Hash(str string) big.Int

a SHA-1 hash, hash % mod, mod = 2^M

func LogInit

func LogInit()

func Ping

func Ping(addr string) error

Types

type AddrType

type AddrType struct {
	Ip string
	Id big.Int
}

A IP address store as a pair due to the hash value is frequently called

type BoolStrPair

type BoolStrPair struct {
	First  bool
	Second string
}

type ClosestList

type ClosestList struct {
	Size     int
	Standard big.Int
	List     [K]AddrType
}

func (*ClosestList) Insert

func (this *ClosestList) Insert(addr AddrType) (updated bool)

func (*ClosestList) Remove

func (this *ClosestList) Remove(addr AddrType) bool

type DataType

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

func (*DataType) Copy

func (this *DataType) Copy() map[string]string

func (*DataType) Delete

func (this *DataType) Delete(key string) (founded bool)

func (*DataType) Expire

func (this *DataType) Expire()

func (*DataType) Init

func (this *DataType) Init()

func (DataType) Load

func (this DataType) Load(key string) (founded bool, ret string)

func (*DataType) RePublishList

func (this *DataType) RePublishList() (republishList []string)

func (*DataType) Store

func (this *DataType) Store(key string, val string)

type FindNodeArg

type FindNodeArg struct {
	TarID  big.Int
	Sender AddrType
}

Arg and Ret Type

type FindValueArg

type FindValueArg struct {
	Key    string
	Hash   big.Int
	Sender AddrType
}

type FindValueRet

type FindValueRet struct {
	First  ClosestList
	Second string
}

type KBucketType

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

func (*KBucketType) Reflesh

func (this *KBucketType) Reflesh()

func (*KBucketType) Update

func (this *KBucketType) Update(addr AddrType)

type NodeType

type NodeType struct {
	Running bool
	Addr    AddrType
	// contains filtered or unexported fields
}

func NewNode

func NewNode(ip string) *NodeType

func (*NodeType) Create

func (this *NodeType) Create()

func (*NodeType) Display

func (this *NodeType) Display()

func (*NodeType) FindNode

func (this *NodeType) FindNode(tarID *big.Int) (closestList ClosestList)

func (*NodeType) FindValue

func (this *NodeType) FindValue(key string, hash *big.Int) FindValueRet

FindValue return value or K-closest nodes

func (*NodeType) Get

func (this *NodeType) Get(key string) (founded bool, value string)

func (*NodeType) Join

func (this *NodeType) Join(ip string) bool

func (*NodeType) NodeLookup

func (this *NodeType) NodeLookup(tarID *big.Int) (closestList ClosestList)

func (*NodeType) Put

func (this *NodeType) Put(key string, value string) bool

func (*NodeType) Quit

func (this *NodeType) Quit()

func (*NodeType) RePublish

func (this *NodeType) RePublish()

type ReceiverType

type ReceiverType struct {
	Node     *NodeType
	Server   *rpc.Server
	Listener net.Listener
}

func NewReceiver

func NewReceiver(ip string) *ReceiverType

func (*ReceiverType) FindNode

func (this *ReceiverType) FindNode(args *FindNodeArg, reply *ClosestList) error

func (*ReceiverType) FindValue

func (this *ReceiverType) FindValue(args *FindValueArg, reply *FindValueRet) error

func (*ReceiverType) Store

func (this *ReceiverType) Store(args *StoreArg, _ *int) error

type StoreArg

type StoreArg struct {
	Key    string
	Value  string
	Sender AddrType
}

type StrPair

type StrPair struct {
	First  string
	Second string
}

Jump to

Keyboard shortcuts

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