0x-mesh: github.com/0xProject/0x-mesh/p2p Index | Files | Directories

package p2p

import "github.com/0xProject/0x-mesh/p2p"

package p2p is a low-level library responsible for peer discovery and sending/receiving messages.

Index

Package Files

bootstrap.go filters.go message.go node.go notifee.go opts.go

Constants

const DHTProtocolID = protocol.ID("/0x-mesh-dht/version/1")

Variables

var DefaultBootstrapList = []string{
    "/ip4/3.214.190.67/tcp/60558/ipfs/16Uiu2HAmGx8Z6gdq5T5AQE54GMtqDhDFhizywTy1o28NJbAMMumF",
    "/ip4/3.214.190.67/tcp/60559/ws/ipfs/16Uiu2HAmGx8Z6gdq5T5AQE54GMtqDhDFhizywTy1o28NJbAMMumF",
    "/dns4/bootstrap-0.mesh.0x.org/tcp/60558/ipfs/16Uiu2HAmGx8Z6gdq5T5AQE54GMtqDhDFhizywTy1o28NJbAMMumF",
    "/dns4/bootstrap-0.mesh.0x.org/tcp/60559/ws/ipfs/16Uiu2HAmGx8Z6gdq5T5AQE54GMtqDhDFhizywTy1o28NJbAMMumF",
    "/ip4/18.200.96.60/tcp/60558/ipfs/16Uiu2HAkwsDZk4LzXy2rnWANRsyBjB4fhjnsNeJmjgsBqxPGTL32",
    "/ip4/18.200.96.60/tcp/60559/ws/ipfs/16Uiu2HAkwsDZk4LzXy2rnWANRsyBjB4fhjnsNeJmjgsBqxPGTL32",
    "/dns4/bootstrap-1.mesh.0x.org/tcp/60558/ipfs/16Uiu2HAkwsDZk4LzXy2rnWANRsyBjB4fhjnsNeJmjgsBqxPGTL32",
    "/dns4/bootstrap-1.mesh.0x.org/tcp/60559/ws/ipfs/16Uiu2HAkwsDZk4LzXy2rnWANRsyBjB4fhjnsNeJmjgsBqxPGTL32",
    "/ip4/13.232.193.142/tcp/60558/ipfs/16Uiu2HAkykwoBxwyvoEbaEkuKMeKrmJDPZ2uKFPUKtqd2JbGHUNH",
    "/ip4/13.232.193.142/tcp/60559/ws/ipfs/16Uiu2HAkykwoBxwyvoEbaEkuKMeKrmJDPZ2uKFPUKtqd2JbGHUNH",
    "/dns4/bootstrap-2.mesh.0x.org/tcp/60558/ipfs/16Uiu2HAkykwoBxwyvoEbaEkuKMeKrmJDPZ2uKFPUKtqd2JbGHUNH",
    "/dns4/bootstrap-2.mesh.0x.org/tcp/60559/ws/ipfs/16Uiu2HAkykwoBxwyvoEbaEkuKMeKrmJDPZ2uKFPUKtqd2JbGHUNH",

    "/ip4/34.201.54.78/tcp/4001/ipfs/12D3KooWHwJDdbx73qiBpSCJfg4RuYyzqnLUwfLBqzn77TSy7kRX",
    "/ip4/18.204.221.103/tcp/4001/ipfs/12D3KooWQS6Gsr2kLZvF7DVtoRFtj24aar5jvz88LvJePrawM3EM",
}

DefaultBootstrapList is a list of addresses to use by default for bootstrapping the DHT.

func BootstrapListToAddrInfos Uses

func BootstrapListToAddrInfos(bootstrapList []string) ([]peer.AddrInfo, error)

func ConnectToBootstrapList Uses

func ConnectToBootstrapList(ctx context.Context, host host.Host, bootstrapList []string) error

func Filters Uses

func Filters(filters *filter.Filters) libp2p.Option

func NewDHT Uses

func NewDHT(ctx context.Context, storageDir string, host host.Host) (*dht.IpfsDHT, error)

NewDHT returns a new Kademlia DHT instance configured to work with 0x Mesh in native (pure Go) environments. storageDir is the directory to use for persisting the data with LevelDB.

type Config Uses

type Config struct {
    // Topic is a unique string representing the pubsub topic. Only Nodes which
    // have the same topic will share messages with one another.
    Topic 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
    // RendezvousString is a unique identifier for the rendezvous point. This node
    // will attempt to find peers with the same Rendezvous string.
    RendezvousString 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
    // DataDir is the directory to use for storing data.
    DataDir string
    // 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
}

Config contains configuration options for a Node.

type Message Uses

type Message struct {
    // From is the peer ID of the peer who sent the message.
    From peer.ID
    // Data is the underlying data for the message.
    Data []byte
}

type MessageHandler Uses

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([]*Message) error
    // GetMessagesToShare returns up to max messages to be shared with peers.
    GetMessagesToShare(max int) ([][]byte, error)
}

MessageHandler is an interface responsible for validating and storing messages as well as selecting messages which are ready to be shared.

type Node Uses

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 Uses

func New(ctx context.Context, config Config) (*Node, error)

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 Uses

func (n *Node) AddPeerScore(id peer.ID, tag string, diff int)

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 Uses

func (n *Node) Connect(peerInfo peer.AddrInfo, timeout time.Duration) error

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 Uses

func (n *Node) GetNumPeers() int

GetNumPeers returns the number of peers the node is connected to

func (*Node) ID Uses

func (n *Node) ID() peer.ID

ID returns the peer id of the node.

func (*Node) Multiaddrs Uses

func (n *Node) Multiaddrs() []ma.Multiaddr

Multiaddrs returns all multi addresses at which the node is dialable.

func (*Node) Send Uses

func (n *Node) Send(data []byte) error

Send sends a message continaing the given data to all connected peers.

func (*Node) SetPeerScore Uses

func (n *Node) SetPeerScore(id peer.ID, tag string, val int)

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) Start Uses

func (n *Node) Start() error

Start causes the Node to continuously send messages to and receive messages from its peers. It blocks until an error is encountered or `Stop` is called.

func (*Node) UnsetPeerScore Uses

func (n *Node) UnsetPeerScore(id peer.ID, tag string)

UnsetPeerScore removes any scores associated with the given tag for a peer (i.e., they will no longer be counted toward the peers total score).

Directories

PathSynopsis
banner
ratevalidator

Package p2p imports 34 packages (graph) and is imported by 2 packages. Updated 2019-11-26. Refresh now. Tools for package owners.