Documentation ¶
Index ¶
- Constants
- Variables
- type DHT
- func (r *DHT) Discover(key string) (*peer.PeerInfo, error)
- func (r *DHT) FindPeersClosestTo(tk string, n int) ([]*peer.PeerInfo, error)
- func (r *DHT) GetAllProviders() (map[string][]string, error)
- func (r *DHT) GetPeerInfo(ctx context.Context, id string) (*peer.PeerInfo, error)
- func (r *DHT) GetProviders(ctx context.Context, key string) (chan *crypto.PublicKey, error)
- func (r *DHT) PutProviders(ctx context.Context, key string) error
- type PeerInfoRequest
- type PeerInfoResponse
- type Provider
- type ProviderRequest
- type ProviderResponse
- type QueryType
- type Store
Constants ¶
const (
PeerInfoRequestType = "nimona.io/dht/peerinfo.request"
)
const (
PeerInfoResponseType = "nimona.io/dht/peerinfo.response"
)
const (
ProviderRequestType = "nimona.io/dht/provider.request"
)
const (
ProviderResponseType = "nimona.io/dht/provider.response"
)
const (
ProviderType = "nimona.io/dht/provider"
)
Variables ¶
var ( ErrPeerAlreadyExists = errors.New("Peer already exists") ErrPeerNotFound = errors.New("Peer not found") )
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) FindPeersClosestTo ¶
FindPeersClosestTo returns an array of n peers closest to the given key by xor distance
func (*DHT) GetPeerInfo ¶
GetPeerInfo returns a peer's info from their id
func (*DHT) GetProviders ¶
GetProviders will look for peers that provide a key
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 ¶
FromObject populates the struct from 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 Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) GetAllProviders ¶
GetAllProviders returns all providers and the values they are providing