Documentation ¶
Overview ¶
NOTICE: This is a modified work of the basic_host.go implementation in Go Libp2p. See: https://github.com/libp2p/go-libp2p/blob/master/p2p/host/basic/basic_host.go
Original license:
The MIT License (MIT)
Copyright (c) 2014 Juan Batiz-Benet ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Variables
- func AddTransports(h host.Host, swrm transport.TransportNetwork, nodeOpts *NodeOpts, ...) (err error)
- func NewNetwork(ctx context.Context, nodeOpts *NodeOpts, opts *NetworkOpts) (transport.TransportNetwork, error)
- func NewNode(ctx context.Context, cfg *Config) (host.Host, error)
- type AddrsFactory
- type BasicHost
- func (h *BasicHost) Addrs() []ma.Multiaddr
- func (h *BasicHost) AllAddrs() []ma.Multiaddr
- func (h *BasicHost) Close() error
- func (h *BasicHost) ConnManager() connmgr.ConnManager
- func (h *BasicHost) Connect(ctx context.Context, pi peer.AddrInfo) error
- func (h *BasicHost) EventBus() event.Bus
- func (h *BasicHost) ID() peer.ID
- func (h *BasicHost) IDService() *identify.IDService
- func (h *BasicHost) Mux() protocol.Switch
- func (h *BasicHost) Network() network.Network
- func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)
- func (h *BasicHost) Peerstore() peerstore.Peerstore
- func (h *BasicHost) RemoveStreamHandler(pid protocol.ID)
- func (h *BasicHost) SetIDService(ids *identify.IDService)
- func (h *BasicHost) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)
- func (h *BasicHost) SetStreamHandlerMatch(pid protocol.ID, m func(string) bool, handler network.StreamHandler)
- func (h *BasicHost) SignalAddressChange()
- func (h *BasicHost) Start()
- type Config
- type HostOpts
- type NetworkOpts
- type NodeOpts
- type TransportOpts
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AddTransports ¶
func AddTransports(h host.Host, swrm transport.TransportNetwork, nodeOpts *NodeOpts, opts *TransportOpts) (err error)
func NewNetwork ¶
func NewNetwork(ctx context.Context, nodeOpts *NodeOpts, opts *NetworkOpts) (transport.TransportNetwork, error)
Types ¶
type AddrsFactory ¶
AddrsFactory functions can be passed to New in order to override addresses returned by Addrs.
type BasicHost ¶
type BasicHost struct { AddrsFactory AddrsFactory AutoNat autonat.AutoNAT // contains filtered or unexported fields }
BasicHost is the basic implementation of the host.Host interface. This particular host implementation:
- uses a protocol muxer to mux per-protocol streams
- uses an identity service to send + receive node information
- uses a nat service to establish NAT port mappings
func NewHost ¶
NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
func (*BasicHost) Addrs ¶
Addrs returns listening addresses that are safe to announce to the network. The output is the same as AllAddrs, but processed by AddrsFactory.
func (*BasicHost) AllAddrs ¶
AllAddrs returns all the addresses of BasicHost at this moment in time. It's ok to not include addresses if they're not available to be used now.
func (*BasicHost) ConnManager ¶
func (h *BasicHost) ConnManager() connmgr.ConnManager
func (*BasicHost) Connect ¶
Connect ensures there is a connection between this host and the peer with given peer.ID. If there is not an active connection, Connect will issue a h.Network.Dial, and block until a connection is open, or an error is returned. Connect will absorb the addresses in pi into its internal peerstore. It will also resolve any /dns4, /dns6, and /dnsaddr addresses.
func (*BasicHost) NewStream ¶
func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)
NewStream opens a new stream to given peer p, and writes a p2p/protocol header with given protocol.ID. If there is no connection to p, attempts to create one. If ProtocolID is "", writes no header. (Threadsafe)
func (*BasicHost) RemoveStreamHandler ¶
RemoveStreamHandler returns ..
func (*BasicHost) SetIDService ¶
SetIDService changes the identification service
func (*BasicHost) SetStreamHandler ¶
func (h *BasicHost) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)
SetStreamHandler sets the protocol handler on the Host's Mux. This is equivalent to:
host.Mux().SetHandler(proto, handler)
(Threadsafe)
func (*BasicHost) SetStreamHandlerMatch ¶
func (h *BasicHost) SetStreamHandlerMatch(pid protocol.ID, m func(string) bool, handler network.StreamHandler)
SetStreamHandlerMatch sets the protocol handler on the Host's Mux using a matching function to do protocol comparisons
func (*BasicHost) SignalAddressChange ¶
func (h *BasicHost) SignalAddressChange()
SignalAddressChange signals to the host that it needs to determine whether our listen addresses have recently changed. Warning: this interface is unstable and may disappear in the future.
type Config ¶
type Config struct { NodeOpts HostOpts NetworkOpts TransportOpts }
type HostOpts ¶
type HostOpts struct { // MultistreamMuxer is essential for the *BasicHost and will use a sensible default value if omitted. MultistreamMuxer *msmux.MultistreamMuxer // NegotiationTimeout determines the read and write timeouts on streams. // If 0 or omitted, it will use DefaultNegotiationTimeout. // If below 0, timeouts on streams will be deactivated. NegotiationTimeout time.Duration // AddrsFactory holds a function which can be used to override or filter the result of Addrs. // If omitted, there's no override or filtering, and the results of Addrs and AllAddrs are the same. AddrsFactory AddrsFactory // MultiaddrResolves holds the go-multiaddr-dns.Resolver used for resolving // /dns4, /dns6, and /dnsaddr addresses before trying to connect to a peer. MultiaddrResolver *madns.Resolver // NATManager takes care of setting NAT port mappings, and discovering external addresses. // If omitted, this will simply be disabled. NATManager func(network.Network) basichost.NATManager // ConnManager is a libp2p connection manager ConnManager connmgr.ConnManager // EnablePing indicates whether to instantiate the ping service EnablePing bool // UserAgent sets the user-agent for the host. Defaults to ClientVersion. UserAgent string // DisableSignedPeerRecord disables the generation of Signed Peer Records on this host. DisableSignedPeerRecord bool // EnableIdentify disables the default use of the identification background service. EnableIdentify bool // IDFirst makes the host run the libp2p identify protocol upon new streams and dials with peers. IDFirst bool }
HostOpts holds options that can be passed to NewHost in order to customize construction of the *BasicHost.