dht

package
v0.0.0-...-42befb5 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: MIT, MIT Imports: 8 Imported by: 0

README

SPACEMESH-DHT

In this package we'd like to implement a modern DHT with the following main properties:

  1. All comm between nodes is secure and authenticated (using spacemesh-swarm). This is sometimes known as s-kademlia.
  2. Coral improvements to Kademlia content distribution. aka mainlin dht. Implemented in libp2p-kad-dht and bittorrent clients
  3. Avoid the complexity and possible race conditions involved in go-eth-p2p-kad and libp2p-kad-dht. libp2p open-issues list is somewhat scary and libp2p-kad-dht is tightly coupled with its main client - ipfs.
  4. Have as little external deps as possible - e.g. multi-address, specific key-id schemes, etc...

This package contains heavily-modified code inspired by libp2p-kad-dht and libp2p-kbucket. The license file for both of these packages is included in this package as required by the MIT licensing terms.

DHT k-buckets fun facts

  • About 50% of peers observed by local node should be stored in the table.
  • The lower the bucket, the closer the peers are to the local node
  • The first bucket contains nodes that share 1 msb bit with the local node
  • Nodes may be dropped from the table if their buckets are getting full based on how far ago the local node communicated with them or learned about them.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func XOR

func XOR(a, b []byte) []byte

XOR is a helper method used to return a byte slice which is the XOR of 2 provided byte slices.

Types

type ID

type ID []byte

ID is a dht-compatible ID using the XOR keyspace.

func NewIDFromBase58String

func NewIDFromBase58String(s string) ID

NewIDFromBase58String creates a new dht ID from provided base58 encoded binary data.

func NewIDFromHexString

func NewIDFromHexString(s string) (ID, error)

NewIDFromHexString creates a new dht ID from provided hex-encoded string.

func NewIDFromNodeKey

func NewIDFromNodeKey(key []byte) ID

NewIDFromNodeKey creates a new dht id from provided binary data.

func (ID) Closer

func (id ID) Closer(id1 ID, id2 ID) bool

Closer returns true if id1 is closer to id3 than id2 using XOR arithmetic.

func (ID) CommonPrefixLen

func (id ID) CommonPrefixLen(o ID) int

CommonPrefixLen returns the common shared prefix length in BITS of the binary numbers represented by the ids.

func (ID) Distance

func (id ID) Distance(id1 ID) *big.Int

Distance returns the distance between ID and id1 encoded as a big int.

func (ID) Equals

func (id ID) Equals(other ID) bool

Equals returns true iff other equals the ID.

func (ID) Less

func (id ID) Less(o ID) bool

Less returns true iff the binary number represented by ID is less than the number represented by o.

func (ID) Pretty

func (id ID) Pretty() string

Pretty returns a readable string of the ID.

func (ID) SortByDistance

func (id ID) SortByDistance(ids []ID) []ID

SortByDistance ids based on xor-distance from ID.

func (ID) Xor

func (id ID) Xor(o ID) ID

Xor returns a XOR of the ID with o.

func (ID) ZeroPrefixLen

func (id ID) ZeroPrefixLen() int

ZeroPrefixLen returns the zero prefix length of the binary number represnted by ID in bits.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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