p2psrv

package
v0.0.0-...-83a01c7 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Nodes

type Nodes []*discover.Node

Nodes slice of discovered nodes. It's rlp encode/decodable

func (*Nodes) DecodeRLP

func (ns *Nodes) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

type Options

type Options struct {
	// Name sets the node name of this server.
	// Use common.MakeName to create a name that follows existing conventions.
	Name string

	// This field must be set to a valid secp256k1 private key.
	PrivateKey *ecdsa.PrivateKey

	// MaxPeers is the maximum number of peers that can be
	// connected. It must be greater than zero.
	MaxPeers int

	// NoDiscovery can be used to disable the peer discovery mechanism.
	// Disabling is useful for protocol debugging (manual topology).
	NoDiscovery bool

	// If ListenAddr is set to a non-nil address, the server
	// will listen for incoming connections.
	//
	// If the port is zero, the operating system will pick a port. The
	// ListenAddr field will be updated with the actual address when
	// the server is started.
	ListenAddr string

	KnownNodes Nodes
	// BootstrapNodes are used to establish connectivity
	// with the rest of the network using the V5 discovery
	// protocol.
	BootstrapNodes Nodes

	// Connectivity can be restricted to certain IP networks.
	// If this option is set to a non-nil value, only hosts which match one of the
	// IP networks contained in the list are considered.
	NetRestrict *netutil.Netlist

	// If set to a non-nil value, the given NAT port mapper
	// is used to make the listening port available to the
	// Internet.
	NAT nat.Interface

	// If NoDial is true, the server will not dial any peers.
	NoDial bool
}

Options options for creating p2p server. Partially copied from ethereum p2p.Config.

type Protocol

type Protocol struct {
	p2p.Protocol

	DiscTopic string
}

Protocol represents a P2P subprotocol implementation.

type Server

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

Server p2p server wraps ethereum's p2p.Server, and handles discovery v5 stuff.

func New

func New(opts *Options) *Server

New create a p2p server.

func (*Server) AddStatic

func (s *Server) AddStatic(node *discover.Node)

AddStatic connects to the given node and maintains the connection until the server is shut down. If the connection fails for any reason, the server will attempt to reconnect the peer.

func (*Server) KnownNodes

func (s *Server) KnownNodes() Nodes

KnownNodes returns known nodes that can be saved for fast connecting next time.

func (*Server) NodeInfo

func (s *Server) NodeInfo() *p2p.NodeInfo

NodeInfo gathers and returns a collection of metadata known about the host.

func (*Server) RemoveStatic

func (s *Server) RemoveStatic(node *discover.Node)

RemoveStatic disconnects from the given node

func (*Server) Self

func (s *Server) Self() *discover.Node

Self returns self enode url. Only available when server is running.

func (*Server) Start

func (s *Server) Start(protocols []*Protocol) error

Start start the server.

func (*Server) Stop

func (s *Server) Stop()

Stop stop the server.

Directories

Path Synopsis
Package discv5 implements the RLPx v5 Topic Discovery Protocol.
Package discv5 implements the RLPx v5 Topic Discovery Protocol.

Jump to

Keyboard shortcuts

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