Documentation
¶
Index ¶
- Constants
- func NewHost(ctx context.Context, config *types.Libp2pConfig, ...) (host.Host, *dht.IpfsDHT, *pubsub.PubSub, error)
- func PeerPassFilter(peers []peer.AddrInfo, pf PeerFilter) []peer.AddrInfo
- type HandlerRegistry
- func (r *HandlerRegistry) RegisterHandlerWithBytesCallback(messageType types.MessageType, s StreamHandler, ...) error
- func (r *HandlerRegistry) RegisterHandlerWithStreamCallback(messageType types.MessageType, handler StreamHandler) error
- func (r *HandlerRegistry) SendMessageToLocalHandler(messageType types.MessageType, data []byte, peerID peer.ID)
- func (r *HandlerRegistry) UnregisterHandler(messageType types.MessageType)
- type Libp2p
- func (l *Libp2p) AcceptSubnetPeer(subnetID, peerID, ip string) error
- func (l *Libp2p) AddSubnetDNSRecords(subnetID string, records map[string]string) error
- func (l *Libp2p) AddSubnetPeer(subnetID, peerID, ip string) error
- func (l *Libp2p) Advertise(ctx context.Context, key string, data []byte) error
- func (l *Libp2p) BootstrapDHT(ctx context.Context) error
- func (l *Libp2p) ConnectToBootstrapNodes(ctx context.Context) error
- func (l *Libp2p) CreateSubnet(ctx context.Context, subnetID string, routingTable map[string]string) error
- func (l *Libp2p) DestroySubnet(subnetID string) error
- func (l *Libp2p) DiscoverDialPeers(ctx context.Context) error
- func (l *Libp2p) DumpDHTRoutingTable() ([]kbucket.PeerInfo, error)
- func (l *Libp2p) GetBroadcastScore() map[peer.ID]*PeerScoreSnapshot
- func (l *Libp2p) GetHostID() PeerID
- func (l *Libp2p) GetMultiaddr() ([]multiaddr.Multiaddr, error)
- func (l *Libp2p) GetPeerIP(p PeerID) string
- func (l *Libp2p) GetPeerPubKey(peerID PeerID) crypto.PubKey
- func (l *Libp2p) HandleMessage(messageType string, handler func(data []byte, peerId peer.ID)) error
- func (l *Libp2p) Init(cfg *config.Config) error
- func (l *Libp2p) KnownPeers() ([]peer.AddrInfo, error)
- func (l *Libp2p) MapPort(subnetID, protocol, sourceIP, sourcePort, destIP, destPort string) error
- func (l *Libp2p) Notify(ctx context.Context, preconnected func(peer.ID, []protocol.ID, int), ...) error
- func (l *Libp2p) OpenStream(ctx context.Context, addr string, messageType types.MessageType) (network.Stream, error)
- func (l *Libp2p) PeerConnected(p PeerID) bool
- func (l *Libp2p) Ping(ctx context.Context, peerIDAddress string, timeout time.Duration) (types.PingResult, error)
- func (l *Libp2p) Publish(ctx context.Context, topic string, data []byte) error
- func (l *Libp2p) Query(ctx context.Context, key string) ([]*commonproto.Advertisement, error)
- func (l *Libp2p) RegisterBytesMessageHandler(messageType types.MessageType, handler func(data []byte, peerId peer.ID)) error
- func (l *Libp2p) RegisterStreamMessageHandler(messageType types.MessageType, handler StreamHandler) error
- func (l *Libp2p) RemoveSubnetDNSRecord(subnetID, name string) error
- func (l *Libp2p) RemoveSubnetPeer(subnetID, peerID, ip string) error
- func (l *Libp2p) ResolveAddress(ctx context.Context, id string) ([]string, error)
- func (l *Libp2p) SendMessage(ctx context.Context, hostID string, msg types.MessageEnvelope, ...) error
- func (l *Libp2p) SendMessageSync(ctx context.Context, hostID string, msg types.MessageEnvelope, ...) error
- func (l *Libp2p) SetBroadcastAppScore(f func(peer.ID) float64)
- func (l *Libp2p) SetupBroadcastTopic(topic string, setup func(*Topic) error) error
- func (l *Libp2p) Start() error
- func (l *Libp2p) Stat() types.NetworkStats
- func (l *Libp2p) Stop() error
- func (l *Libp2p) Subscribe(ctx context.Context, topic string, handler func(data []byte), ...) (uint64, error)
- func (l *Libp2p) Unadvertise(ctx context.Context, key string) error
- func (l *Libp2p) UnmapPort(subnetID, protocol, sourceIP, sourcePort, destIP, destPort string) error
- func (l *Libp2p) UnregisterMessageHandler(messageType string)
- func (l *Libp2p) Unsubscribe(topic string, subID uint64) error
- func (l *Libp2p) VisiblePeers() []peer.AddrInfo
- type NoAddrIDFilter
- type PeerFilter
- type PeerID
- type PeerScoreSnapshot
- type ProtocolID
- type PubSub
- type StreamHandler
- type SubnetRoutingTable
- type Topic
- type ValidationResult
- type Validator
Constants ¶
const ( MB = 1024 * 1024 ValidationAccept = pubsub.ValidationAccept ValidationReject = pubsub.ValidationReject ValidationIgnore = pubsub.ValidationIgnore )
const ( IfaceMTU = 1420 PacketExchangeProtocolID = "/dms/subnet/packet-exchange/0.0.1" )
Variables ¶
This section is empty.
Functions ¶
func NewHost ¶
func NewHost(ctx context.Context, config *types.Libp2pConfig, appScore func(p peer.ID) float64, scoreInspect pubsub.ExtendedPeerScoreInspectFn) (host.Host, *dht.IpfsDHT, *pubsub.PubSub, error)
NewHost returns a new libp2p host with dht and other related settings.
func PeerPassFilter ¶
func PeerPassFilter(peers []peer.AddrInfo, pf PeerFilter) []peer.AddrInfo
Types ¶
type HandlerRegistry ¶
type HandlerRegistry struct {
// contains filtered or unexported fields
}
HandlerRegistry manages the registration of stream handlers for different protocols.
func NewHandlerRegistry ¶
func NewHandlerRegistry(host host.Host) *HandlerRegistry
NewHandlerRegistry creates a new handler registry instance.
func (*HandlerRegistry) RegisterHandlerWithBytesCallback ¶
func (r *HandlerRegistry) RegisterHandlerWithBytesCallback( messageType types.MessageType, s StreamHandler, handler func(data []byte, peerId peer.ID), ) error
RegisterHandlerWithBytesCallback registers a stream handler for a specific protocol and sends the bytes back to callback.
func (*HandlerRegistry) RegisterHandlerWithStreamCallback ¶
func (r *HandlerRegistry) RegisterHandlerWithStreamCallback(messageType types.MessageType, handler StreamHandler) error
RegisterHandlerWithStreamCallback registers a stream handler for a specific protocol.
func (*HandlerRegistry) SendMessageToLocalHandler ¶
func (r *HandlerRegistry) SendMessageToLocalHandler(messageType types.MessageType, data []byte, peerID peer.ID)
SendMessageToLocalHandler given the message type it sends data to the local handler found.
func (*HandlerRegistry) UnregisterHandler ¶
func (r *HandlerRegistry) UnregisterHandler(messageType types.MessageType)
UnregisterHandler unregisters a stream handler for a specific protocol.
type Libp2p ¶
type Libp2p struct { Host host.Host DHT *dht.IpfsDHT PS peerstore.Peerstore // contains filtered or unexported fields }
Libp2p contains the configuration for a Libp2p instance.
TODO-suggestion: maybe we should call it something else like Libp2pPeer, Libp2pHost or just Peer (callers would use libp2p.Peer...)
func New ¶
New creates a libp2p instance.
TODO-Suggestion: move types.Libp2pConfig to here for better readability. Unless there is a reason to keep within types.
func (*Libp2p) AcceptSubnetPeer ¶
func (*Libp2p) AddSubnetDNSRecords ¶
func (*Libp2p) AddSubnetPeer ¶
func (*Libp2p) BootstrapDHT ¶
Start dht bootstrapper
func (*Libp2p) ConnectToBootstrapNodes ¶
Connect to Bootstrap nodes
func (*Libp2p) CreateSubnet ¶
func (*Libp2p) DestroySubnet ¶
func (*Libp2p) DiscoverDialPeers ¶
DiscoverDialPeers discovers peers using rendezvous point
func (*Libp2p) DumpDHTRoutingTable ¶
func (*Libp2p) GetBroadcastScore ¶
func (l *Libp2p) GetBroadcastScore() map[peer.ID]*PeerScoreSnapshot
func (*Libp2p) GetMultiaddr ¶
GetMultiaddr returns the peer's multiaddr.
func (*Libp2p) GetPeerPubKey ¶
GetPeerPubKey returns the public key for the given peerID.
func (*Libp2p) HandleMessage ¶
HandleMessage registers a stream handler for a specific protocol and sends bytes to handler func.
func (*Libp2p) OpenStream ¶
func (l *Libp2p) OpenStream(ctx context.Context, addr string, messageType types.MessageType) (network.Stream, error)
OpenStream opens a stream to a remote address and returns the stream for the caller to handle.
func (*Libp2p) PeerConnected ¶
func (*Libp2p) Ping ¶
func (l *Libp2p) Ping(ctx context.Context, peerIDAddress string, timeout time.Duration) (types.PingResult, error)
Ping the remote address. The remote address is the encoded peer id which will be decoded and used here.
TODO (Return error once): something that was confusing me when using this method is that the error is returned twice if any. Once as a field of PingResult and one as a return value.
func (*Libp2p) Publish ¶
Publish publishes data to a topic. The requirements are that only one topic handler should exist per topic.
func (*Libp2p) Query ¶
func (l *Libp2p) Query(ctx context.Context, key string) ([]*commonproto.Advertisement, error)
Query return all the advertisements in the network related to a key. The network is queried to find providers for the given key, and peers which we aren't connected to can be retrieved.
func (*Libp2p) RegisterBytesMessageHandler ¶
func (l *Libp2p) RegisterBytesMessageHandler(messageType types.MessageType, handler func(data []byte, peerId peer.ID)) error
RegisterBytesMessageHandler registers a stream handler for a specific protocol and sends bytes to handler func.
func (*Libp2p) RegisterStreamMessageHandler ¶
func (l *Libp2p) RegisterStreamMessageHandler(messageType types.MessageType, handler StreamHandler) error
RegisterStreamMessageHandler registers a stream handler for a specific protocol.
func (*Libp2p) RemoveSubnetDNSRecord ¶
func (*Libp2p) RemoveSubnetPeer ¶
func (*Libp2p) ResolveAddress ¶
ResolveAddress resolves the address by given a peer id.
func (*Libp2p) SendMessage ¶
func (l *Libp2p) SendMessage(ctx context.Context, hostID string, msg types.MessageEnvelope, expiry time.Time) error
SendMessage asynchronously sends a message to a peer
func (*Libp2p) SendMessageSync ¶
func (l *Libp2p) SendMessageSync(ctx context.Context, hostID string, msg types.MessageEnvelope, expiry time.Time) error
SendMessageSync synchronously sends a message to a peer
func (*Libp2p) SetBroadcastAppScore ¶
func (*Libp2p) SetupBroadcastTopic ¶
func (*Libp2p) Stat ¶
func (l *Libp2p) Stat() types.NetworkStats
Stat returns the status about the libp2p network.
func (*Libp2p) Subscribe ¶
func (l *Libp2p) Subscribe(ctx context.Context, topic string, handler func(data []byte), validator Validator) (uint64, error)
Subscribe subscribes to a topic and sends the messages to the handler.
func (*Libp2p) Unadvertise ¶
Unadvertise removes the data from the dht.
func (*Libp2p) UnregisterMessageHandler ¶
UnregisterMessageHandler unregisters a stream handler for a specific protocol.
func (*Libp2p) Unsubscribe ¶
Unsubscribe cancels the subscription to a topic
func (*Libp2p) VisiblePeers ¶
type NoAddrIDFilter ¶
NoAddrIDFilter filters out peers with no listening addresses and a peer with a specific ID
type PeerFilter ¶
type PeerFilter interface {
// contains filtered or unexported methods
}
PeerFilter is an interface for filtering peers satisfaction of filter criteria allows the peer to pass
type PeerScoreSnapshot ¶
type PeerScoreSnapshot = pubsub.PeerScoreSnapshot
type ProtocolID ¶
type StreamHandler ¶
StreamHandler is a function type that processes data from a stream.
type SubnetRoutingTable ¶
type SubnetRoutingTable interface { Add(peerID peer.ID, addr string) Remove(peerID peer.ID, ip string) Get(peerID peer.ID) ([]string, bool) RemoveByIP(addr string) GetByIP(addr string) (peer.ID, bool) All() map[peer.ID][]string Clear() }
func NewRoutingTable ¶
func NewRoutingTable() SubnetRoutingTable
type ValidationResult ¶
type ValidationResult = pubsub.ValidationResult
type Validator ¶
type Validator func([]byte, interface{}) (ValidationResult, interface{})