Documentation
¶
Index ¶
- type BoltDBPeerStore
- type Capabilities
- type Capability
- type Config
- type EventType
- type Info
- type Instance
- type JSONPeerStore
- type MemberEvent
- type NoopPeerStore
- type Peer
- type PeerStore
- type PeriodicDial
- type Protocol
- type ProtocolHandler
- type ProtocolSpec
- type Server
- func (s *Server) Close()
- func (s *Server) Dial(enode string)
- func (s *Server) DialSync(enode string) error
- func (s *Server) Disconnect()
- func (s *Server) Enqueue(id string, block *types.Block)
- func (s *Server) FindPeers(targets map[types.Address]bool) map[types.Address]consensus.Peer
- func (s *Server) GetPeer(id string) *Peer
- func (s *Server) GetPeerByPrefix(search string) (*Peer, bool)
- func (s *Server) GetPeers() []string
- func (s *Server) ID() enode.ID
- func (s *Server) RegisterProtocol(b []*Protocol) error
- func (s *Server) Schedule() error
- func (s *Server) SetConsensus(c consensus.Consensus)
- func (s *Server) SetPeerStore(p PeerStore)
- type Session
- type Status
- type Stream
- type Transport
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
type Capabilities ¶
type Capabilities []*Capability
Capabilities is a list of capabilities 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
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
type MemberEvent ¶
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
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) GetProtocol ¶
GetProtocol returns the protocol by name
func (*Peer) GetProtocols ¶
GetProtocols returns all the protocols 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
type Protocol ¶
type Protocol struct {
Spec ProtocolSpec
HandlerFn func(conn net.Conn, peer *Peer) (ProtocolHandler, error)
}
Protocol is a wire protocol
type ProtocolHandler ¶
ProtocolHandler is the handler of the protocol
type ProtocolSpec ¶
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) Disconnect ¶
func (s *Server) Disconnect()
func (*Server) GetPeerByPrefix ¶
GetPeerByPrefix searches a peer by his prefix
func (*Server) RegisterProtocol ¶
RegisterProtocol registers a protocol
func (*Server) SetConsensus ¶
SetConsensus sets the consensus
func (*Server) SetPeerStore ¶
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 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