network

package
v0.0.0-...-8f649d9 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: LGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltDBPeerStore

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

BoltDBPeerStore stores the peers locally in boltdb

func NewBoltDBPeerStore

func NewBoltDBPeerStore(dir string) (*BoltDBPeerStore, error)

NewBoltDBPeerStore creates a boltdb peerstore

func (*BoltDBPeerStore) Close

func (p *BoltDBPeerStore) Close() error

Close implements the PeerStore interface

func (*BoltDBPeerStore) Load

func (p *BoltDBPeerStore) Load() ([]string, error)

Load implements the PeerStore interface

func (*BoltDBPeerStore) Update

func (p *BoltDBPeerStore) Update(peer string, status Status) error

Update implements the PeerStore interface

type Capabilities

type Capabilities []*Capability

Capabilities is a list of capabilities of the peer

type Capability

type Capability struct {
	Protocol Protocol
}

Capability is a feature of the peer

type Config

type Config struct {
	Name             string
	DataDir          string
	BindAddress      string
	BindPort         int
	MaxPeers         int
	Bootnodes        []string
	DialTasks        int
	DialBusyInterval time.Duration
}

Config is the p2p server configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration

type EventType

type EventType int
const (
	NodeJoin EventType = iota
	NodeLeave
	NodeHandshakeFail
)

func (EventType) String

func (t EventType) String() string

type Info

type Info struct {
	Client       string
	Enode        *enode.Enode
	Capabilities Capabilities
	ListenPort   uint64
}

Info is the information of a peer

type Instance

type Instance struct {
	Protocol *Protocol
	Handler  ProtocolHandler
}

type JSONPeerStore

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

JSONPeerStore stores the peers locally in json format

func NewJSONPeerStore

func NewJSONPeerStore(path string) *JSONPeerStore

NewJSONPeerStore creates a json peerstore

func (*JSONPeerStore) Close

func (p *JSONPeerStore) Close() error

Close implements the PeerStore interface

func (*JSONPeerStore) Load

func (p *JSONPeerStore) Load() ([]string, error)

Load implements the PeerStore interface

func (*JSONPeerStore) Update

func (p *JSONPeerStore) Update(addr string, status Status) error

Update implements the PeerStore interface

type MemberEvent

type MemberEvent struct {
	Type EventType
	Peer *Peer
}

type NoopPeerStore

type NoopPeerStore struct {
}

NoopPeerStore is a peerstore that does not store peers

func (*NoopPeerStore) Close

func (i *NoopPeerStore) Close() error

Close implements the PeerStore interface

func (*NoopPeerStore) Load

func (i *NoopPeerStore) Load() ([]string, error)

Load implements the PeerStore interface

func (*NoopPeerStore) Update

func (i *NoopPeerStore) Update(addr string, status Status) error

Update implements the PeerStore interface

type Peer

type Peer struct {
	Enode *enode.Enode
	Info  Info
	ID    string

	Status Status
	// contains filtered or unexported fields
}

Peer is each of the connected peers

func (*Peer) Close

func (p *Peer) Close() error

Close closes the peer connection

func (*Peer) GetProtocol

func (p *Peer) GetProtocol(name string) (*Instance, bool)

GetProtocol returns the protocol by name

func (*Peer) GetProtocols

func (p *Peer) GetProtocols() []*Instance

GetProtocols returns all the protocols of the peer

func (*Peer) IsClosed

func (p *Peer) IsClosed() bool

IsClosed checks if the connection is closed

func (*Peer) PrettyID

func (p *Peer) PrettyID() string

PrettyID returns a pretty version of the id

func (*Peer) Send

func (p *Peer) Send(msgcode uint64, data interface{}) error

func (*Peer) Session

func (p *Peer) Session() Session

Session returns the session of the peer

type PeerStore

type PeerStore interface {
	Load() ([]string, error)
	Update(addr string, status Status) error
	Close() error
}

PeerStore stores peers id

type PeriodicDial

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

PeriodicDial is the periodic dial of busy peers

func (*PeriodicDial) ID

func (p *PeriodicDial) ID() string

ID returns the id of the enode

type Protocol

type Protocol struct {
	Spec      ProtocolSpec
	HandlerFn func(conn net.Conn, peer *Peer) (ProtocolHandler, error)
}

Protocol is a wire protocol

type ProtocolHandler

type ProtocolHandler interface {
	Info() (map[string]interface{}, error)
}

ProtocolHandler is the handler of the protocol

type ProtocolSpec

type ProtocolSpec struct {
	Name    string
	Version uint
	Length  uint64
}

ProtocolSpec is a specification of an etheruem protocol

type Server

type Server struct {
	Name string

	EventCh chan MemberEvent

	Discovery discovery.Backend
	Enode     *enode.Enode
	// contains filtered or unexported fields
}

Server is the ethereum client

func NewServer

func NewServer(name string, key *ecdsa.PrivateKey, config *Config, logger hclog.Logger, transport Transport) *Server

NewServer creates a new node

func (*Server) Close

func (s *Server) Close()

func (*Server) Dial

func (s *Server) Dial(enode string)

Dial dials an enode (async)

func (*Server) DialSync

func (s *Server) DialSync(enode string) error

DialSync dials and waits for the result

func (*Server) Disconnect

func (s *Server) Disconnect()

func (*Server) Enqueue

func (s *Server) Enqueue(id string, block *types.Block)

func (*Server) FindPeers

func (s *Server) FindPeers(targets map[types.Address]bool) map[types.Address]consensus.Peer

func (*Server) GetPeer

func (s *Server) GetPeer(id string) *Peer

func (*Server) GetPeerByPrefix

func (s *Server) GetPeerByPrefix(search string) (*Peer, bool)

GetPeerByPrefix searches a peer by his prefix

func (*Server) GetPeers

func (s *Server) GetPeers() []string

GetPeers returns a copy of list of peers

func (*Server) ID

func (s *Server) ID() enode.ID

func (*Server) RegisterProtocol

func (s *Server) RegisterProtocol(b []*Protocol) error

RegisterProtocol registers a protocol

func (*Server) Schedule

func (s *Server) Schedule() error

Schedule starts all the tasks once all the protocols have been loaded

func (*Server) SetConsensus

func (s *Server) SetConsensus(c consensus.Consensus)

SetConsensus sets the consensus

func (*Server) SetPeerStore

func (s *Server) SetPeerStore(p PeerStore)

SetPeerStore sets the peerstore

type Session

type Session interface {
	// Stream returns the set of streams inside the session
	Streams() []Stream

	// Info returns the information of the network
	GetInfo() Info

	// Write raw message on connection
	WriteRawMsg(code uint64, buf []byte) error

	// CloseChan returns a read-only channel which is closed as
	// soon as the session is closed.
	CloseChan() <-chan struct{}

	// IsClosed returns if the session has been closed
	IsClosed() bool

	// Close closes the connection
	Close() error
}

Session is an open connection between two peers

type Status

type Status int
const (
	PeerActive Status = iota
	PeerPending
	PeerDisconnected
	PeerBusy
)

func (Status) String

func (s Status) String() string

type Stream

type Stream interface {
	net.Conn
	Protocol() ProtocolSpec
}

Stream is a stream inside a session

type Transport

type Transport interface {
	// Setup starts the protocol with the given private key
	Setup(priv *ecdsa.PrivateKey, backends []*Protocol, info *Info, config map[string]interface{}) error

	// DialTimeout connects to the address within a given timeout.
	DialTimeout(addr string, timeout time.Duration) (Session, error)

	// Accept accepts the new session
	Accept() (Session, error)

	// Close closes the transport
	Close() error
}

Transport is a generic network transport protocol

Directories

Path Synopsis
transport

Jump to

Keyboard shortcuts

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