kademlia

package module
v0.0.0-...-50909bd Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: MIT Imports: 15 Imported by: 4

README

kademlia

S/Kademlia in Go. Heavy WIP.

Documentation

Index

Constants

View Source
const (
	SizePublicKey  = ed25519.PublicKeySize
	SizePrivateKey = ed25519.PrivateKeySize
	SizeSeed       = ed25519.SeedSize
	SizeSignature  = ed25519.SignatureSize

	SizeNodeID = 32
	SizeX      = SizeNodeID

	MinSizeID = SizePublicKey + 1 + net.IPv4len + 2
	MaxSizeID = SizePublicKey + 1 + net.IPv6len + 2
)
View Source
const (
	SizeHandshakeRequest = 2*SizePublicKey + SizeSignature
	SizeFindNodeRequest  = SizePublicKey
)
View Source
const (
	DefaultC1 = 10
	DefaultC2 = 10
)
View Source
const (
	SizeTable         = SizePublicKey * 8
	DefaultBucketSize = 16
)

Variables

View Source
var (
	ZeroPublicKey  PublicKey
	ZeroPrivateKey PrivateKey
	ZeroSeed       Seed
	ZeroSignature  Signature

	ZeroNodeID NodeID
	ZeroX      X

	ZeroID ID
)

Functions

func GenerateKeys

func GenerateKeys(r io.Reader) (publicKey PublicKey, privateKey PrivateKey, err error)

func GeneratePuzzleKeys

func GeneratePuzzleKeys(r io.Reader, c1 int) (pub PublicKey, priv PrivateKey, err error)

GeneratePuzzleKeys takes O(2^c1).

Types

type FindNodeRequest

type FindNodeRequest struct {
	Target PublicKey `json:"public_key"`
}

func UnmarshalFindNodeRequest

func UnmarshalFindNodeRequest(buf []byte) (FindNodeRequest, []byte, error)

func (FindNodeRequest) AppendTo

func (r FindNodeRequest) AppendTo(dst []byte) []byte

type FindNodeResponse

type FindNodeResponse struct {
	Closest []ID `json:"closest"`
}

func UnmarshalFindNodeResponse

func UnmarshalFindNodeResponse(buf []byte) (FindNodeResponse, []byte, error)

func (FindNodeResponse) AppendTo

func (r FindNodeResponse) AppendTo(dst []byte) []byte

type HandshakeRequest

type HandshakeRequest struct {
	PublicKey  PublicKey `json:"public_key"`
	SessionKey PublicKey `json:"session_key"`
	Signature  Signature `json:"signature"`
}

func UnmarshalHandshakeRequest

func UnmarshalHandshakeRequest(buf []byte) (HandshakeRequest, []byte, error)

func (HandshakeRequest) AppendTo

func (p HandshakeRequest) AppendTo(dst []byte) []byte

type ID

type ID struct {
	Pub  PublicKey `json:"public_key"`
	Host net.IP    `json:"host"`
	Port uint16    `json:"port"`
}

func SortIDs

func SortIDs(pub PublicKey, ids []ID) []ID

func UnmarshalID

func UnmarshalID(buf []byte) (ID, []byte, error)

func (ID) AppendTo

func (id ID) AppendTo(dst []byte) []byte

func (ID) Validate

func (h ID) Validate() error

type NodeID

type NodeID [SizeNodeID]byte

func (NodeID) GenerateX

func (id NodeID) GenerateX(r io.Reader, c2 int) (x X, err error)

GenerateX takes O(2^c2).

func (NodeID) String

func (id NodeID) String() string

func (NodeID) Valid

func (id NodeID) Valid(c1 int) bool

func (NodeID) Zero

func (id NodeID) Zero() bool

type PrivateKey

type PrivateKey [SizePrivateKey]byte

func (PrivateKey) Public

func (p PrivateKey) Public() PublicKey

func (PrivateKey) Seed

func (p PrivateKey) Seed() Seed

func (PrivateKey) Sign

func (p PrivateKey) Sign(buf []byte) Signature

func (PrivateKey) String

func (p PrivateKey) String() string

func (PrivateKey) Zero

func (p PrivateKey) Zero() bool

type Protocol

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

func NewProtocol

func NewProtocol() (*Protocol, error)

func (*Protocol) Handshake

func (p *Protocol) Handshake(packet HandshakeRequest, addr net.Addr) error

func (Protocol) PrivateKey

func (p Protocol) PrivateKey() PrivateKey

func (Protocol) PublicKey

func (p Protocol) PublicKey() PublicKey

func (*Protocol) Read

func (p *Protocol) Read(buf []byte, addr net.Addr) error

type PublicKey

type PublicKey [SizePublicKey]byte

func (PublicKey) NodeID

func (p PublicKey) NodeID() NodeID

func (PublicKey) String

func (p PublicKey) String() string

func (PublicKey) Verify

func (p PublicKey) Verify(msg []byte, s Signature) bool

func (PublicKey) Zero

func (p PublicKey) Zero() bool

type Seed

type Seed [SizeSeed]byte

func (Seed) String

func (s Seed) String() string

func (Seed) Zero

func (s Seed) Zero() bool

type Signature

type Signature [SizeSignature]byte

func (Signature) String

func (s Signature) String() string

func (Signature) Verify

func (s Signature) Verify(pub PublicKey, msg []byte) bool

func (Signature) Zero

func (s Signature) Zero() bool

type Table

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

func NewTable

func NewTable(id PublicKey) *Table

func (Table) ClosestTo

func (t Table) ClosestTo(pub PublicKey, k int) []ID

O(min(k, bucket_size * num_buckets)) complexity.

func (*Table) Delete

func (t *Table) Delete(pub PublicKey) bool

O(bucket_size) complexity.

func (Table) Has

func (t Table) Has(pub PublicKey) bool

Has returns true if this table has pub.

func (Table) Len

func (t Table) Len() int

Len returns the number of entries in this table.

func (*Table) Update

func (t *Table) Update(id ID) UpdateResult

O(bucket_size) complexity.

type UpdateResult

type UpdateResult int
const (
	UpdateNew UpdateResult = iota
	UpdateOk
	UpdateFull
	UpdateFail
)

type X

type X [SizeX]byte

func (X) String

func (x X) String() string

func (X) Valid

func (x X) Valid(id NodeID, c2 int) bool

func (X) Zero

func (x X) Zero() bool

Directories

Path Synopsis
cmd
kad

Jump to

Keyboard shortcuts

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