network

package
v1.1.3-0...-78a1a59 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBootstrapTimeout is the default timeout for bootstrapping with each peer.
	DefaultBootstrapTimeout = 10 * time.Second
	// DefaultPeerThreshold is the default threshold above which bootstrapping is considered successful
	DefaultPeerThreshold = 8
	MsgChanSize          = 64
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	From   noise.ID
	Code   byte // 0 for relay, 1 for broadcast
	Data   []byte
	SeqNum byte
	To     noise.PublicKey
}

func (Message) Marshal

func (msg Message) Marshal() []byte

func (Message) String

func (m Message) String() string

type Network

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

Network encapsulates the communication in a noise p2p network.

func New

func New(hostStr string, port uint16, privatekey noise.PrivateKey, logger *zap.Logger, logging bool) (*Network, error)

New creates and returns a new network instance.

func (*Network) AddressFromPK

func (ntw *Network) AddressFromPK(publicKey noise.PublicKey) string

AddressFromPK returns the address associated with the public key

func (*Network) Bootstrap

func (ntw *Network) Bootstrap(peerAddrs []string, timeout time.Duration, peerThreshold int) bool

Bootstrap bootstraps a network using a list of peer addresses and returns whether bootstrap finished before timeout.

func (*Network) BootstrapDefault

func (ntw *Network) BootstrapDefault(peerAddrs []string) bool

BootstrapDefault runs Bootstrap with default parameters.

func (*Network) Broadcast

func (ntw *Network) Broadcast(code byte, data []byte)

Broadcast broadcasts data to the entire p2p network.

func (*Network) Close

func (ntw *Network) Close()

func (*Network) DisconWithPeers

func (ntw *Network) DisconWithPeers(ids []noise.ID)

DisconWithPeers discionnects with the given ids

func (*Network) Discover

func (ntw *Network) Discover()

func (*Network) ExternalAddress

func (ntw *Network) ExternalAddress() string

func (*Network) FindPeer

func (ntw *Network) FindPeer(target noise.PublicKey) []noise.ID

func (*Network) GetBroadcastChan

func (ntw *Network) GetBroadcastChan() chan broadcast.Message

GetBroadcastChan returns the channel for broadcast messages.

func (*Network) GetNodeID

func (ntw *Network) GetNodeID() noise.ID

GetNodeID returns the network node's skademlia ID.

func (*Network) GetNumPeers

func (ntw *Network) GetNumPeers() int

GetNumPeers returns the number of peers the network node has.

func (*Network) GetPeerAddrs

func (ntw *Network) GetPeerAddrs() []noise.ID

peers prints out all peers we are already aware of.

func (*Network) GetRelayChan

func (ntw *Network) GetRelayChan() chan relay.Message

GetRelayChan returns the channel for relay messages.

func (*Network) Node

func (ntw *Network) Node() *noise.Node

func (*Network) Process

func (ntw *Network) Process()

func (*Network) Relay

func (ntw *Network) Relay(peerID noise.ID, code byte, data []byte)

func (*Network) RelayToPB

func (ntw *Network) RelayToPB(peerID noise.PublicKey, code byte, data []byte)

Jump to

Keyboard shortcuts

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