Documentation
¶
Index ¶
- Constants
- func AddrToHostPort(addr string) (string, uint16, error)
- func CreatePeers(host string, minPort uint16, numPeers int) ([]kad.ID, []*kad.Keypair, error)
- func RandBootstrapAddrs(peers []kad.ID, n int) []string
- func RandPeer(peers []kad.ID) kad.ID
- func RunPeers(peers []kad.ID, keypairs []*kad.Keypair, numBootstrapPeers int) (chan relay.Message, chan broadcast.Message)
- type Network
- func (ntw *Network) AddressFromPK(publicKey []byte) string
- func (ntw *Network) Bootstrap(peerAddrs []string, timeout time.Duration, peerThreshold int) bool
- func (ntw *Network) BootstrapDefault(peerAddrs []string) bool
- func (ntw *Network) Broadcast(code byte, data []byte)
- func (ntw *Network) GetBroadcastChan() chan broadcast.Message
- func (ntw *Network) GetNodeID() kad.ID
- func (ntw *Network) GetNumPeers() int
- func (ntw *Network) GetPeerAddrs() []string
- func (ntw *Network) GetPeerKadID(address string) kad.ID
- func (ntw *Network) GetRelayChan() chan relay.Message
- func (ntw *Network) HandlePeerDisconnection(peerCleanup disconCleanInterface)
- func (ntw *Network) Relay(peerID kad.ID, code byte, data []byte) error
Constants ¶
const ( // DefaultBootstrapTimeout is the default timeout for bootstrapping with each peer. DefaultBootstrapTimeout = time.Second * 10 // DefaultPeerThreshold is the default threshold above which bootstrapping is considered successful DefaultPeerThreshold = 8 )
Variables ¶
This section is empty.
Functions ¶
func AddrToHostPort ¶
AddrToHostPort splits an address-colon-host string into host and port.
func CreatePeers ¶
CreatePeers creates a number of peer identities starting at the minimum port number.
func RandBootstrapAddrs ¶
RandBootstrapAddrs returns up to n random addresses from peers.
Types ¶
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network encapsulates the communication in a noise p2p network.
func (*Network) AddressFromPK ¶
AddressFromPK returns the address associated with the public key
func (*Network) Bootstrap ¶
Bootstrap bootstraps a network using a list of peer addresses and returns whether bootstrap finished before timeout.
func (*Network) BootstrapDefault ¶
BootstrapDefault runs Bootstrap with default parameters.
func (*Network) GetBroadcastChan ¶
GetBroadcastChan returns the channel for broadcast messages.
func (*Network) GetNumPeers ¶
GetNumPeers returns the number of peers the network node has.
func (*Network) GetPeerAddrs ¶
GetPeerAddrs returns the peer addresses in the network node's kademlia table.
func (*Network) GetPeerKadID ¶
GetPeerKadID returns the KadID of the peer since it is randomly initialized sometimes
func (*Network) GetRelayChan ¶
GetRelayChan returns the channel for relay messages.
func (*Network) HandlePeerDisconnection ¶
func (ntw *Network) HandlePeerDisconnection(peerCleanup disconCleanInterface)
HandlePeerDisconnection registers the dinconnection callback with the interface