skademlia

package
v0.0.0-...-fa48a8f Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPrefixDiffLen = 128
	DefaultPrefixDiffMin = 32

	DefaultC1 = 16
	DefaultC2 = 16
)
View Source
const (
	KeyID = "skademlia.id"
)

Variables

View Source
var (
	ErrInvalidLengthRpc = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowRpc   = fmt.Errorf("proto: integer overflow")
)
View Source
var (
	ErrBucketFull = errors.New("bucket is full")
)

Functions

func RegisterOverlayServer

func RegisterOverlayServer(s *grpc.Server, srv OverlayServer)

Types

type Bucket

type Bucket struct {
	sync.RWMutex
	list.List
}

func (*Bucket) Len

func (b *Bucket) Len() int

type Client

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

func NewClient

func NewClient(addr string, keys *Keypair, opts ...Option) *Client

func (*Client) AllPeers

func (c *Client) AllPeers() []*grpc.ClientConn

func (*Client) Bootstrap

func (c *Client) Bootstrap() (results []*ID)

func (*Client) BucketSize

func (c *Client) BucketSize() int

func (*Client) ClosestPeerIDs

func (c *Client) ClosestPeerIDs() []*ID

func (*Client) ClosestPeers

func (c *Client) ClosestPeers(opts ...DialOption) []ClosestPeer

func (*Client) Dial

func (c *Client) Dial(addr string, opts ...DialOption) (*grpc.ClientConn, error)

func (*Client) DialContext

func (c *Client) DialContext(ctx context.Context, addr string) (*grpc.ClientConn, error)

func (*Client) DisconnectByAddress

func (c *Client) DisconnectByAddress(address string) error

func (*Client) FindNode

func (c *Client) FindNode(target *ID, k int, a int, d int) []*ID

func (*Client) ID

func (c *Client) ID() *ID

func (*Client) Keys

func (c *Client) Keys() *Keypair

func (*Client) Listen

func (c *Client) Listen(opts ...grpc.ServerOption) *grpc.Server

func (*Client) Logger

func (c *Client) Logger() *log.Logger

func (*Client) OnPeerJoin

func (c *Client) OnPeerJoin(fn func(*grpc.ClientConn, *ID))

func (*Client) OnPeerLeave

func (c *Client) OnPeerLeave(fn func(*grpc.ClientConn, *ID))

func (*Client) Protocol

func (c *Client) Protocol() Protocol

func (*Client) RefreshPeriodically

func (c *Client) RefreshPeriodically(stop chan struct{}, duration time.Duration)

RefreshPeriodically periodically refreshes the list of peers for a node given a time period.

func (*Client) SetCredentials

func (c *Client) SetCredentials(creds *noise.Credentials)

type ClosestPeer

type ClosestPeer struct {
	Conn *grpc.ClientConn
	ID   *ID
}

type DialOption

type DialOption func(o *dialOptions)

func WithTimeout

func WithTimeout(timeout time.Duration) DialOption

type FindNodeRequest

type FindNodeRequest struct {
	Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
}

func (*FindNodeRequest) Descriptor

func (*FindNodeRequest) Descriptor() ([]byte, []int)

func (*FindNodeRequest) GetId

func (m *FindNodeRequest) GetId() []byte

func (*FindNodeRequest) Marshal

func (m *FindNodeRequest) Marshal() (dAtA []byte, err error)

func (*FindNodeRequest) MarshalTo

func (m *FindNodeRequest) MarshalTo(dAtA []byte) (int, error)

func (*FindNodeRequest) ProtoMessage

func (*FindNodeRequest) ProtoMessage()

func (*FindNodeRequest) Reset

func (m *FindNodeRequest) Reset()

func (*FindNodeRequest) Size

func (m *FindNodeRequest) Size() (n int)

func (*FindNodeRequest) String

func (m *FindNodeRequest) String() string

func (*FindNodeRequest) Unmarshal

func (m *FindNodeRequest) Unmarshal(dAtA []byte) error

func (*FindNodeRequest) XXX_DiscardUnknown

func (m *FindNodeRequest) XXX_DiscardUnknown()

func (*FindNodeRequest) XXX_Marshal

func (m *FindNodeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*FindNodeRequest) XXX_Merge

func (m *FindNodeRequest) XXX_Merge(src proto.Message)

func (*FindNodeRequest) XXX_Size

func (m *FindNodeRequest) XXX_Size() int

func (*FindNodeRequest) XXX_Unmarshal

func (m *FindNodeRequest) XXX_Unmarshal(b []byte) error

type FindNodeResponse

type FindNodeResponse struct {
	Ids [][]byte `protobuf:"bytes,1,rep,name=ids,proto3" json:"ids,omitempty"`
}

func (*FindNodeResponse) Descriptor

func (*FindNodeResponse) Descriptor() ([]byte, []int)

func (*FindNodeResponse) GetIds

func (m *FindNodeResponse) GetIds() [][]byte

func (*FindNodeResponse) Marshal

func (m *FindNodeResponse) Marshal() (dAtA []byte, err error)

func (*FindNodeResponse) MarshalTo

func (m *FindNodeResponse) MarshalTo(dAtA []byte) (int, error)

func (*FindNodeResponse) ProtoMessage

func (*FindNodeResponse) ProtoMessage()

func (*FindNodeResponse) Reset

func (m *FindNodeResponse) Reset()

func (*FindNodeResponse) Size

func (m *FindNodeResponse) Size() (n int)

func (*FindNodeResponse) String

func (m *FindNodeResponse) String() string

func (*FindNodeResponse) Unmarshal

func (m *FindNodeResponse) Unmarshal(dAtA []byte) error

func (*FindNodeResponse) XXX_DiscardUnknown

func (m *FindNodeResponse) XXX_DiscardUnknown()

func (*FindNodeResponse) XXX_Marshal

func (m *FindNodeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*FindNodeResponse) XXX_Merge

func (m *FindNodeResponse) XXX_Merge(src proto.Message)

func (*FindNodeResponse) XXX_Size

func (m *FindNodeResponse) XXX_Size() int

func (*FindNodeResponse) XXX_Unmarshal

func (m *FindNodeResponse) XXX_Unmarshal(b []byte) error

type ID

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

func NewID

func NewID(address string, publicKey edwards25519.PublicKey, nonce [blake2b.Size256]byte) *ID

func UnmarshalID

func UnmarshalID(b io.Reader) (m ID, err error)

func (ID) Address

func (m ID) Address() string

func (ID) Checksum

func (m ID) Checksum() [blake2b.Size256]byte

func (ID) Marshal

func (m ID) Marshal() []byte

func (ID) Nonce

func (m ID) Nonce() [blake2b.Size256]byte

func (ID) PublicKey

func (m ID) PublicKey() edwards25519.PublicKey

func (ID) String

func (m ID) String() string

type InterceptedClientStream

type InterceptedClientStream struct {
	grpc.ClientStream
	// contains filtered or unexported fields
}

func (InterceptedClientStream) RecvMsg

func (s InterceptedClientStream) RecvMsg(m interface{}) error

func (InterceptedClientStream) SendMsg

func (s InterceptedClientStream) SendMsg(m interface{}) error

type InterceptedServerStream

type InterceptedServerStream struct {
	grpc.ServerStream
	// contains filtered or unexported fields
}

func (InterceptedServerStream) RecvMsg

func (s InterceptedServerStream) RecvMsg(m interface{}) error

func (InterceptedServerStream) SendMsg

func (s InterceptedServerStream) SendMsg(m interface{}) error

type Keypair

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

func LoadKeys

func LoadKeys(privateKey edwards25519.PrivateKey, c1, c2 int) (*Keypair, error)

func NewKeys

func NewKeys(c1, c2 int) (*Keypair, error)

func (*Keypair) ID

func (k *Keypair) ID(addr string) *ID

func (*Keypair) PrivateKey

func (k *Keypair) PrivateKey() edwards25519.PrivateKey

func (*Keypair) PublicKey

func (k *Keypair) PublicKey() edwards25519.PublicKey

type Option

type Option func(c *Client)

func WithC1

func WithC1(c1 int) Option

func WithC2

func WithC2(c2 int) Option

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) Option

func WithPrefixDiffLen

func WithPrefixDiffLen(prefixDiffLen int) Option

func WithPrefixDiffMin

func WithPrefixDiffMin(prefixDiffMin int) Option

type OverlayClient

type OverlayClient interface {
	DoPing(ctx context.Context, in *Ping, opts ...grpc.CallOption) (*Ping, error)
	FindNode(ctx context.Context, in *FindNodeRequest, opts ...grpc.CallOption) (*FindNodeResponse, error)
}

OverlayClient is the client API for Overlay service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewOverlayClient

func NewOverlayClient(cc *grpc.ClientConn) OverlayClient

type OverlayServer

type OverlayServer interface {
	DoPing(context.Context, *Ping) (*Ping, error)
	FindNode(context.Context, *FindNodeRequest) (*FindNodeResponse, error)
}

OverlayServer is the server API for Overlay service.

type Ping

type Ping struct {
}

func (*Ping) Descriptor

func (*Ping) Descriptor() ([]byte, []int)

func (*Ping) Marshal

func (m *Ping) Marshal() (dAtA []byte, err error)

func (*Ping) MarshalTo

func (m *Ping) MarshalTo(dAtA []byte) (int, error)

func (*Ping) ProtoMessage

func (*Ping) ProtoMessage()

func (*Ping) Reset

func (m *Ping) Reset()

func (*Ping) Size

func (m *Ping) Size() (n int)

func (*Ping) String

func (m *Ping) String() string

func (*Ping) Unmarshal

func (m *Ping) Unmarshal(dAtA []byte) error

func (*Ping) XXX_DiscardUnknown

func (m *Ping) XXX_DiscardUnknown()

func (*Ping) XXX_Marshal

func (m *Ping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Ping) XXX_Merge

func (m *Ping) XXX_Merge(src proto.Message)

func (*Ping) XXX_Size

func (m *Ping) XXX_Size() int

func (*Ping) XXX_Unmarshal

func (m *Ping) XXX_Unmarshal(b []byte) error

type Protocol

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

func (Protocol) Client

func (p Protocol) Client(
	info noise.Info, ctx context.Context, authority string, conn net.Conn,
) (net.Conn, error)

func (Protocol) DoPing

func (p Protocol) DoPing(context.Context, *Ping) (*Ping, error)

func (Protocol) FindNode

func (p Protocol) FindNode(ctx context.Context, req *FindNodeRequest) (*FindNodeResponse, error)

func (Protocol) Server

func (p Protocol) Server(info noise.Info, conn net.Conn) (net.Conn, error)

type Table

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

func NewTable

func NewTable(self *ID) *Table

func (*Table) Delete

func (t *Table) Delete(b *Bucket, target *ID) bool

func (*Table) Find

func (t *Table) Find(b *Bucket, target *ID) *list.Element

func (*Table) FindClosest

func (t *Table) FindClosest(target *ID, k int) []*ID

func (*Table) Update

func (t *Table) Update(target *ID) error

Jump to

Keyboard shortcuts

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