kad

package module
v0.0.0-...-541b16f Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 17 Imported by: 0

README

go-kademlia

Kademlia DHT implementation in Go (for learning purposes)

Documentation

Index

Constants

View Source
const IDLength = 20

Variables

This section is empty.

Functions

func IsNetEOFError

func IsNetEOFError(err error) bool

func IsNetTimeoutError

func IsNetTimeoutError(err error) bool

Types

type Host

type Host interface {
	ID() ID

	ListenAddr() net.Addr
	LocalAddrInfo() PeerAddrInfo

	Bootstrap(ctx context.Context, peerAddresses ...PeerAddrInfo) error
	Ping(ctx context.Context, address PeerAddrInfo) (bool, error)
	FindNode(ctx context.Context, nodeID ID) ([]PeerInfo, error)
	Store(ctx context.Context, key string, value []byte) error
	FindValue(ctx context.Context, key string) ([]byte, bool, error)

	KBuckets() *KBuckets

	Close() error
}

func NewHost

func NewHost(listenAddress string, options ...NodeOption) (Host, error)

type ID

type ID []byte

func IDFromString

func IDFromString(s string) ID

func NewID

func NewID() ID

func (ID) DistanceTo

func (id ID) DistanceTo(other ID) int

func (ID) Equal

func (id ID) Equal(other ID) bool

func (ID) String

func (id ID) String() string

type KBuckets

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

func NewKBuckets

func NewKBuckets(node Host, k int, opts ...KBucketsOption) *KBuckets

func (*KBuckets) Entries

func (kb *KBuckets) Entries() [][]PeerInfo

func (*KBuckets) Insert

func (kb *KBuckets) Insert(peer PeerInfo) error

func (*KBuckets) KClosestTo

func (kb *KBuckets) KClosestTo(id ID) []PeerInfo

func (*KBuckets) Size

func (kb *KBuckets) Size() int

type KBucketsOption

type KBucketsOption func(entry *KBuckets)

func WithPingTimeout

func WithPingTimeout(timeout time.Duration) KBucketsOption

type NodeOption

type NodeOption func(*host)

func WithLogger

func WithLogger(logger *zap.Logger) NodeOption

type PeerAddrInfo

type PeerAddrInfo struct {
	Addresses []string
}

func PeerAddrInfoFromStrings

func PeerAddrInfoFromStrings(addresses ...string) PeerAddrInfo

type PeerConn

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

func ConnectToPeer

func ConnectToPeer(ctx context.Context, addr string) (*PeerConn, error)

func (*PeerConn) Close

func (pc *PeerConn) Close() error

func (*PeerConn) LocalAddr

func (pc *PeerConn) LocalAddr() net.Addr

func (*PeerConn) Receive

func (pc *PeerConn) Receive(ctx context.Context, message proto.Message) error

func (*PeerConn) RemoteAddr

func (pc *PeerConn) RemoteAddr() net.Addr

func (*PeerConn) Send

func (pc *PeerConn) Send(ctx context.Context, message proto.Message) error

type PeerInfo

type PeerInfo struct {
	ID       ID
	AddrInfo PeerAddrInfo
}

type PeerListener

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

func NewPeerListener

func NewPeerListener(listenAddress string) (*PeerListener, error)

func (*PeerListener) Accept

func (pl *PeerListener) Accept() (*PeerConn, error)

func (*PeerListener) Addr

func (pl *PeerListener) Addr() net.Addr

func (*PeerListener) Close

func (pl *PeerListener) Close() error

func (*PeerListener) Closed

func (pl *PeerListener) Closed() bool

func (*PeerListener) Port

func (pl *PeerListener) Port() int

type ValueStore

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

func NewValueStore

func NewValueStore() *ValueStore

func (*ValueStore) Get

func (v *ValueStore) Get(key string) ([]byte, bool)

func (*ValueStore) Put

func (v *ValueStore) Put(key string, value []byte)

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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