dht

package
v0.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	PeerInfoRequestType = "nimona.io/dht/peerinfo.request"
)
View Source
const (
	PeerInfoResponseType = "nimona.io/dht/peerinfo.response"
)
View Source
const (
	ProviderRequestType = "nimona.io/dht/provider.request"
)
View Source
const (
	ProviderResponseType = "nimona.io/dht/provider.response"
)
View Source
const (
	ProviderType = "nimona.io/dht/provider"
)

Variables

View Source
var (
	ErrPeerAlreadyExists = errors.New("Peer already exists")
	ErrPeerNotFound      = errors.New("Peer not found")
)
View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type DHT

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

DHT is the struct that implements the dht protocol

func NewDHT

func NewDHT(key *crypto.PrivateKey, network net.Network, exchange exchange.Exchange,
	local *net.LocalInfo, bootstrapAddresses []string) (*DHT, error)

NewDHT returns a new DHT from a exchange and peer manager

func (*DHT) Discover

func (r *DHT) Discover(key string) (*peer.PeerInfo, error)

Discover returns a peer's info from their id

func (*DHT) FindPeersClosestTo

func (r *DHT) FindPeersClosestTo(tk string, n int) ([]*peer.PeerInfo, error)

FindPeersClosestTo returns an array of n peers closest to the given key by xor distance

func (*DHT) GetAllProviders

func (r *DHT) GetAllProviders() (map[string][]string, error)

func (*DHT) GetPeerInfo

func (r *DHT) GetPeerInfo(ctx context.Context, id string) (*peer.PeerInfo, error)

GetPeerInfo returns a peer's info from their id

func (*DHT) GetProviders

func (r *DHT) GetProviders(ctx context.Context, key string) (chan *crypto.PublicKey, error)

GetProviders will look for peers that provide a key

func (*DHT) PutProviders

func (r *DHT) PutProviders(ctx context.Context, key string) error

PutProviders adds a key of something we provide TODO Find a better name for this

type PeerInfoRequest

type PeerInfoRequest struct {
	RequestID   string `json:"requestID,omitempty"`
	Fingerprint string `json:"fingerprint"`
}

PeerInfoRequest payload

func (*PeerInfoRequest) FromObject

func (s *PeerInfoRequest) FromObject(o *object.Object) error

FromObject populates the struct from a f12n object

func (PeerInfoRequest) GetType

func (s PeerInfoRequest) GetType() string

GetType returns the object's type

func (PeerInfoRequest) ToObject

func (s PeerInfoRequest) ToObject() *object.Object

ToObject returns a f12n object

type PeerInfoResponse

type PeerInfoResponse struct {
	RequestID    string           `json:"requestID,omitempty"`
	PeerInfo     *peer.PeerInfo   `json:"peerInfo,omitempty"`
	ClosestPeers []*peer.PeerInfo `json:"closestPeers,omitempty"`
}

func (*PeerInfoResponse) FromObject

func (s *PeerInfoResponse) FromObject(o *object.Object) error

FromObject populates the struct from a f12n object

func (PeerInfoResponse) GetType

func (s PeerInfoResponse) GetType() string

GetType returns the object's type

func (PeerInfoResponse) ToObject

func (s PeerInfoResponse) ToObject() *object.Object

ToObject returns a f12n object

type Provider

type Provider struct {
	ObjectIDs []string          `json:"objectIDs"`
	Signature *crypto.Signature `json:"@signature"`
}

Provider payload

func (*Provider) FromObject

func (s *Provider) FromObject(o *object.Object) error

FromObject populates the struct from a f12n object

func (Provider) GetType

func (s Provider) GetType() string

GetType returns the object's type

func (Provider) ToObject

func (s Provider) ToObject() *object.Object

ToObject returns a f12n object

type ProviderRequest

type ProviderRequest struct {
	RequestID string `json:"requestID,omitempty"`
	Key       string `json:"key"`
}

ProviderRequest payload

func (*ProviderRequest) FromObject

func (s *ProviderRequest) FromObject(o *object.Object) error

FromObject populates the struct from a f12n object

func (ProviderRequest) GetType

func (s ProviderRequest) GetType() string

GetType returns the object's type

func (ProviderRequest) ToObject

func (s ProviderRequest) ToObject() *object.Object

ToObject returns a f12n object

type ProviderResponse

type ProviderResponse struct {
	RequestID    string           `json:"requestID,omitempty"`
	Providers    []*Provider      `json:"providers,omitempty"`
	ClosestPeers []*peer.PeerInfo `json:"closestPeers,omitempty"`
}

func (*ProviderResponse) FromObject

func (s *ProviderResponse) FromObject(o *object.Object) error

FromObject populates the struct from a f12n object

func (ProviderResponse) GetType

func (s ProviderResponse) GetType() string

GetType returns the object's type

func (ProviderResponse) ToObject

func (s ProviderResponse) ToObject() *object.Object

ToObject returns a f12n object

type QueryType

type QueryType int
const (
	PeerInfoQuery QueryType = iota
	ProviderQuery
)

type Store

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

func (*Store) GetAllProviders

func (s *Store) GetAllProviders() ([]*Provider, error)

GetAllProviders returns all providers and the values they are providing

func (*Store) GetProviders

func (s *Store) GetProviders(key string) ([]*Provider, error)

func (*Store) PutProvider

func (s *Store) PutProvider(provider *Provider) error

Jump to

Keyboard shortcuts

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