skademlia

package
v1.1.1-0...-495e22c Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultC1 is the prefix-matching length for the static crypto puzzle.
	DefaultC1 = 8

	// DefaultC2 is the prefix-matching length for the dynamic crypto puzzle.
	DefaultC2 = 8

	// MaxPuzzleIterations is an internal limit for performing cryptographic puzzles for S/Kademlia.
	// This is set to stop the puzzle after about 1sec of failed continuous checks.
	MaxPuzzleIterations = 1000000
)
View Source
const (
	DefaultPrefixDiffLen = 128
	DefaultPrefixDiffMin = 32
)

Variables

View Source
var (
	ErrBucketFull = errors.New("kademlia: cannot add ID, bucket is full")
)

Functions

func Broadcast

func Broadcast(node *noise.Node, message noise.Message) (errs []error)

Broadcast sends a message denoted by its opcode and content to all S/Kademlia IDs closest in terms of XOR distance to that of a specified node instances ID.

Every message sent will be blocking. To have every message sent not block the current goroutine, refer to `BroadcastAsync(node *noise.Node, message noise.Message)`

It returns a list of errors which have occurred in sending any messages to peers closest to a given node instance.

func BroadcastAsync

func BroadcastAsync(node *noise.Node, message noise.Message)

BroadcastAsync sends a message denoted by its opcode and content to all S/Kademlia IDs closest in terms of XOR distance to that of a specified node instances ID.

Every message sent will be non-blocking. To have every message sent block the current goroutine, refer to `Broadcast(node *noise.Node, message noise.Message) (errs []error)`

func BucketSize

func BucketSize() int

func FindClosestPeers

func FindClosestPeers(t *table, target []byte, K int) (peers []protocol.ID)

FindClosestPeers returns a list of K peers with in order of ascending XOR distance.

func IDAddresses

func IDAddresses(ids []ID) (addrs []string)

func New

func New() *block

func PersistIDs

func PersistIDs(filepath string, ids []ID)

func Table

func Table(node *noise.Node) *table

func UpdateTable

func UpdateTable(node *noise.Node, target protocol.ID) (err error)

func VerifyPuzzle

func VerifyPuzzle(publicKey, id, nonce []byte, c1, c2 int) bool

VerifyPuzzle checks whether or not an id is a valid S/Kademlia id that suffices both S/Kademlia's static and dynamic puzzle given constants C1 and C2.

func WaitUntilAuthenticated

func WaitUntilAuthenticated(peer *noise.Peer)

Types

type Evict

type Evict struct{ noise.EmptyMessage }

type ID

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

ID contains S/Kademlia node identity & address info.

func FindNode

func FindNode(node *noise.Node, targetID ID, alpha int, numDisjointPaths int) (results []ID)

FindNode implements the `FIND_NODE` RPC method denoted in Section 4.4 of the S/Kademlia paper: `Lookup over disjoint paths`.

Given a node instance N, and a S/Kademlia ID as a target T, α disjoint lookups take place in parallel over all closest peers to N to target T, with at most D lookups happening at once.

Each disjoint lookup queries at most α peers.

It returns at most BUCKET_SIZE S/Kademlia peer IDs closest to that of a specified target T.

func LoadIDs

func LoadIDs(filepath string) (ids []ID)

func NewID

func NewID(address string, publicKey, nonce []byte) ID

func (ID) Address

func (a ID) Address() string

func (ID) Equals

func (a ID) Equals(other protocol.ID) bool

func (ID) Hash

func (a ID) Hash() []byte

func (ID) PublicKey

func (a ID) PublicKey() []byte

func (ID) Read

func (a ID) Read(reader payload.Reader) (msg noise.Message, err error)

func (ID) String

func (a ID) String() string

func (ID) Write

func (a ID) Write() []byte

type Keypair

type Keypair struct {
	Nonce  []byte
	C1, C2 int
	// contains filtered or unexported fields
}

func LoadKeys

func LoadKeys(privateKeyBuf []byte, c1, c2 int) (*Keypair, error)

LoadKeys loads a S/Kademlia given an Ed25519 private key, and validates it through both a static and dynamic crypto puzzle parameterized by constants C1 and C2 respectively.

func NewKeys

func NewKeys(c1, c2 int) *Keypair

NewKeys randomly generates a set of cryptographic keys by solving both a static and dynamic crypto puzzle parameterized by constants C1 and C2 respectively.

func RandomKeys

func RandomKeys() *Keypair

RandomKeys randomly generates a set of cryptographic keys by solving both a static and dynamic crypto puzzle parameterized by constants C1 = 8, and C2 = 8 respectively.

func (*Keypair) ID

func (p *Keypair) ID() []byte

func (*Keypair) PrivateKey

func (p *Keypair) PrivateKey() []byte

func (*Keypair) PublicKey

func (p *Keypair) PublicKey() []byte

func (*Keypair) String

func (p *Keypair) String() string

type LookupRequest

type LookupRequest struct{ ID }

func (LookupRequest) Read

func (m LookupRequest) Read(reader payload.Reader) (noise.Message, error)

type LookupResponse

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

func (LookupResponse) Read

func (l LookupResponse) Read(reader payload.Reader) (noise.Message, error)

func (LookupResponse) Write

func (l LookupResponse) Write() []byte

type Ping

type Ping struct{ ID }

func (Ping) Read

func (m Ping) Read(reader payload.Reader) (noise.Message, error)

Jump to

Keyboard shortcuts

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