devp2p

package
v0.0.0-...-7de8d3f Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DialTask      = metrics.DialTask
	DiscoveryTask = metrics.DiscoveryTask
)
View Source
const (
	PeerCount = metrics.DEVp2pPeers
	DiscPeers = metrics.DEVp2pDisconnectedPeers
)

Variables

View Source
var (
	ErrShuttingDown = errors.New("shutting down")
)

Functions

func RunTask

func RunTask(task task, server *Server, taskDone func())

func StopTask

func StopTask(task task)

Types

type Config

type Config struct {

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

	// DialRatio controls the ratio of inbound to dialed connections.
	// Example: a DialRatio of 2 allows 1/2 of connections to be dialed.
	// Setting DialRatio to zero defaults it to 3.
	DialRatio int

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

	// BootNodes are used to establish connectivity
	// with the rest of the network.
	BootNodes []INode

	// Static INodes are used as pre-configured connections which are always
	// maintained and re-connected on disconnects.
	StaticINodes []INode

	// Trusted INodes are used as pre-configured connections which are always
	// allowed to connect, even above the peer limit.
	TrustedINodes []INode

	// Protocols should contain the protocols supported
	// by the server. Matching protocols are launched for
	// each peer.
	Protocols []IProtocol

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

Config holds Server options.

type DiscReason

type DiscReason uint
const (
	DiscRequested DiscReason = iota
	DiscNetworkError
	DiscProtocolError
	DiscUselessPeer
	DiscTooManyPeers
	DiscAlreadyConnected
	DiscIncompatibleVersion
	DiscInvalidIdentity
	DiscQuitting
	DiscUnexpectedIdentity
	DiscSelf
	DiscReadTimeout
	DiscSubprotocolError = 0x10
)

func (DiscReason) Error

func (d DiscReason) Error() string

func (DiscReason) String

func (d DiscReason) String() string

type Peer

type Peer struct {
	*godes.Runner
	// contains filtered or unexported fields
}

Peer represents a connected remote INode.

func NewPeer

func NewPeer(server *Server, node INode) *Peer

func (*Peer) Close

func (p *Peer) Close(reason error)

func (*Peer) Disconnect

func (p *Peer) Disconnect(reason error)

Disconnect terminates the peer connection with the given reason. It returns immediately and does not wait until the connection is closed.

func (*Peer) HandleError

func (p *Peer) HandleError(err error) bool

func (*Peer) ID

func (p *Peer) ID() ID

ID returns the INode's public key.

func (*Peer) Inbound

func (p *Peer) Inbound() bool

Inbound returns true if the peer is an inbound connection

func (*Peer) IsClosed

func (p *Peer) IsClosed() bool

func (*Peer) Log

func (p *Peer) Log(a ...interface{})

func (*Peer) Name

func (p *Peer) Name() string

Name returns the INode name that the remote INode advertised.

func (*Peer) NewMsg

func (p *Peer) NewMsg(to INode, msgType string, content interface{}, responseTo *Message, handler func(m *Message)) *Message

func (*Peer) Node

func (p *Peer) Node() INode

func (*Peer) Run

func (p *Peer) Run()

func (*Peer) Self

func (p *Peer) Self() INode

func (*Peer) SendPingMsg

func (p *Peer) SendPingMsg()

func (*Peer) SendPongMsg

func (p *Peer) SendPongMsg(pingMsg IMessage)

func (*Peer) Server

func (p *Peer) Server() *Server

func (*Peer) String

func (p *Peer) String() string

String implements fmt.Stringer.

type PeerEventType

type PeerEventType string
const (
	// PeerEventTypeAdd is the type of event emitted when a peer is added
	// to a p2p.Server
	PeerEventTypeAdd PeerEventType = "add"

	// PeerEventTypeDrop is the type of event emitted when a peer is
	// dropped from a p2p.Server
	PeerEventTypeDrop PeerEventType = "drop"

	// PeerEventTypeMsgSend is the type of event emitted when a
	// message is successfully sent to a peer
	PeerEventTypeMsgSend PeerEventType = "msgsend"

	// PeerEventTypeMsgRecv is the type of event emitted when a
	// message is received from a peer
	PeerEventTypeMsgRecv PeerEventType = "msgrecv"
)

type Server

type Server struct {
	// Config fields may not be modified while the server is running.
	Config
	IMetricCollector
	// contains filtered or unexported fields
}

Server manages all peer connections.

func NewServer

func NewServer(node INode, metricCollector IMetricCollector) *Server

func (*Server) DeletePeer

func (srv *Server) DeletePeer(p *Peer)

func (*Server) FindPeer

func (srv *Server) FindPeer(node INode) IPeer

func (*Server) GetProtocolManager

func (srv *Server) GetProtocolManager() IProtocolManager

func (*Server) GetProtocols

func (srv *Server) GetProtocols() []IProtocol

func (*Server) PeerCount

func (srv *Server) PeerCount() int

func (*Server) Peers

func (srv *Server) Peers() []INode

func (*Server) Refresh

func (srv *Server) Refresh()

pobuduje taskove povezivanja sa peerovima kad se bilo koja promjena napravi ca se tice spojenih peer-ova potrebno je pozvat ovu metodu

func (*Server) RetrieveHandshakePeer

func (srv *Server) RetrieveHandshakePeer(node INode) IPeer

func (*Server) Self

func (srv *Server) Self() INode

Self returns the local INode's endpoint information.

func (*Server) SetOnline

func (srv *Server) SetOnline(online bool)
func (srv *Server) GetProtocolManager() IProtocolManager {
	return srv.pm
}

func (*Server) SetupConn

func (srv *Server) SetupConn(flags connFlag, node INode) error

SetupConn runs the handshakes and attempts to add the connection as a peer. It returns when the connection has been added as a peer or the handshakes have failed.

func (*Server) SetupPeerConn

func (srv *Server) SetupPeerConn(flags int32, node INode) error

func (*Server) Start

func (srv *Server) Start()

Start starts running the server. Servers can not be re-used after stopping.

func (*Server) Stop

func (srv *Server) Stop()

Stop terminates the server and all active peer connections. It blocks until all active connections have been closed.

func (*Server) String

func (srv *Server) String() string

Jump to

Keyboard shortcuts

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