Documentation
¶
Overview ¶
package p2p is a low-level library responsible for peer discovery and sending/receiving messages.
Index ¶
- Constants
- Variables
- func BootstrapListToAddrInfos(bootstrapList []string) ([]peer.AddrInfo, error)
- func ConnectToBootstrapList(ctx context.Context, host host.Host, bootstrapList []string) error
- type Config
- type Message
- type MessageHandler
- type Node
- func (n *Node) AddPeerScore(id peer.ID, tag string, diff int)
- func (n *Node) Connect(peerInfo peer.AddrInfo, timeout time.Duration) error
- func (n *Node) GetNumPeers() int
- func (n *Node) ID() peer.ID
- func (n *Node) Multiaddrs() []ma.Multiaddr
- func (n *Node) Neighbors() []peer.ID
- func (n *Node) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)
- func (n *Node) Send(data []byte) error
- func (n *Node) SetPeerScore(id peer.ID, tag string, val int)
- func (n *Node) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)
- func (n *Node) Start() error
- func (n *Node) UnsetPeerScore(id peer.ID, tag string)
Constants ¶
const DHTProtocolID = protocol.ID("/0x-mesh-dht/version/1")
Variables ¶
var DefaultBootstrapList = []string{
"/ip4/34.136.24.16/tcp/4002/ws/p2p/16Uiu2HAmFxhJFSefdVYzDwDcGLj5RvH6ZaMnmZx7dXFFprVUz7fP",
}
DefaultBootstrapList is a list of addresses to use by default for bootstrapping the DHT.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// SubscribeTopic is the topic to subscribe to for new messages. Only messages
// that are published on this topic will be received and processed.
SubscribeTopic string
// PublishTopics are the topics to publish messages to. Messages may be
// published to more than one topic (e.g. a topic for all orders and a topic
// for orders with a specific asset).
PublishTopics []string
// TCPPort is the port on which to listen for incoming TCP connections.
TCPPort int
// WebSocketsPort is the port on which to listen for incoming WebSockets
// connections.
WebSocketsPort int
// Insecure controls whether or not messages should be encrypted. It should
// always be set to false in production.
Insecure bool
// PrivateKey is the private key which will be used for signing messages and
// generating a peer ID.
PrivateKey p2pcrypto.PrivKey
// MessageHandler is an interface responsible for validating, storing, and
// finding new messages to share.
MessageHandler MessageHandler
// RendezvousPoints is a unique identifier for one or more rendezvous points
// (in order of priority). This node will attempt to find peers with one or
// more matching rendezvous points.
RendezvousPoints []string
// UseBootstrapList determines whether or not to use the list of hard-coded
// peers to bootstrap the DHT for peer discovery.
UseBootstrapList bool
// BootstrapList is a list of multiaddress strings to use for bootstrapping
// the DHT. If empty, the default list will be used.
BootstrapList []string
// DB is a database instance that provides access to key value stores for
// the peerstore and the dht store.
DB *db.DB
// GlobalPubSubMessageLimit is the maximum number of messages per second that
// will be forwarded through GossipSub on behalf of other peers. It is an
// important mechanism for limiting our own upload bandwidth. Without a global
// limit, we could use an unbounded amount of upload bandwidth on propagating
// GossipSub messages sent by other peers. The global limit is required
// because we can receive GossipSub messages from peers that we are not
// connected to (so the per peer limit combined with a maximum number of peers
// is not, by itself, sufficient).
GlobalPubSubMessageLimit rate.Limit
// GlobalPubSubMessageBurst is the maximum number of messages that will be
// forwarded through GossipSub at once.
GlobalPubSubMessageBurst int
// PerPeerPubSubMessageLimit is the maximum number of messages per second that
// each peer is allowed to send through the GossipSub network. Any additional
// messages will be dropped.
PerPeerPubSubMessageLimit rate.Limit
// PerPeerPubSubMessageBurst is the maximum number of messages that each peer
// is allowed to send at once through the GossipSub network. Any additional
// messages will be dropped.
PerPeerPubSubMessageBurst int
// CustomMessageValidator is a custom validator for GossipSub messages. All
// incoming and outgoing messages will be dropped unless they are valid
// according to this custom validator, which will be run in addition to the
// default validators.
CustomMessageValidator pubsub.Validator
// MaxBytesPerSecond is the maximum number of bytes per second that a peer is
// allowed to send before failing the bandwidth check. Defaults to 5 MiB.
MaxBytesPerSecond float64
}
Config contains configuration options for a Node.
type MessageHandler ¶
type MessageHandler interface {
// HandleMessages is called whenever new messages are received. It should only
// return an error if there was a problem handling the messages. It should not
// return an error for invalid or duplicate messages.
HandleMessages(context.Context, []*Message) error
}
MessageHandler is an interface responsible for validating and storing messages as well as selecting messages which are ready to be shared.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is the main type for the p2p package. It represents a particpant in the 0x Mesh network who is capable of sending, receiving, validating, and storing messages.
func New ¶
New creates a new Node with the given context and config. The Node will stop all background operations if the context is canceled.
func (*Node) AddPeerScore ¶
AddPeerScore adds diff to the current score for a given peer. Tag is a unique identifier for the score. A peer's total score is the sum of the scores associated with each tag. Peers that end up with a low total score will eventually be disconnected.
func (*Node) Connect ¶
Connect ensures there is a connection between this host and the peer with given peerInfo. If there is not an active connection, Connect will dial the peer, and block until a connection is open, timeout is exceeded, or an error is returned.
func (*Node) GetNumPeers ¶
GetNumPeers returns the number of peers the node is connected to
func (*Node) Multiaddrs ¶
Multiaddrs returns all multi addresses at which the node is dialable.
func (*Node) Neighbors ¶
Neighbors returns a list of peer IDs that this node is currently connected to.
func (*Node) SetPeerScore ¶
SetPeerScore sets the current score for a given peer (overwriting any previous value with the same tag). Tag is a unique identifier for the score. A peer's total score is the sum of the scores associated with each tag. Peers that end up with a low total score will eventually be disconnected.
func (*Node) SetStreamHandler ¶
func (n *Node) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)
SetStreamHandler registers a handler for a custom protocol.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package validatorset offers a way to combine a set of libp2p.Validators into a single validator.
|
Package validatorset offers a way to combine a set of libp2p.Validators into a single validator. |