Documentation
¶
Index ¶
- type Capabilities
- type Capability
- type Config
- type ConfigOption
- func WithBindAddress(addr string) ConfigOption
- func WithBindPort(port int) ConfigOption
- func WithBootnodes(bootnodes []string) ConfigOption
- func WithLogger(logger *log.Logger) ConfigOption
- func WithMaxPeers(maxPeers int) ConfigOption
- func WithName(name string) ConfigOption
- func WithPeerStore(peerstore PeerStore) ConfigOption
- func WithProtocol(p *Protocol) ConfigOption
- type Dispatcher
- type EventType
- type Info
- type Instance
- type JSONPeerStore
- type Job
- type MemberEvent
- type NoopPeerStore
- type Peer
- type PeerStore
- type PeriodicDial
- type Protocol
- 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) 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) Start() error
- 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 Capabilities ¶
type Capabilities []*Capability
Capabilities is a list of capabilities of the peer
type Config ¶
type Config struct { Logger *log.Logger Name string BindAddress string BindPort int MaxPeers int Bootnodes []string DialTasks int DialBusyInterval time.Duration PeerStore PeerStore Protocols []*Protocol }
Config is the p2p server configuration
type ConfigOption ¶
type ConfigOption func(*Config)
func WithBindAddress ¶
func WithBindAddress(addr string) ConfigOption
func WithBindPort ¶
func WithBindPort(port int) ConfigOption
func WithBootnodes ¶
func WithBootnodes(bootnodes []string) ConfigOption
func WithLogger ¶
func WithLogger(logger *log.Logger) ConfigOption
func WithMaxPeers ¶
func WithMaxPeers(maxPeers int) ConfigOption
func WithName ¶
func WithName(name string) ConfigOption
func WithPeerStore ¶
func WithPeerStore(peerstore PeerStore) ConfigOption
func WithProtocol ¶
func WithProtocol(p *Protocol) ConfigOption
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher is used to track and launch pJobs
func (*Dispatcher) Add ¶
func (p *Dispatcher) Add(job Job, period time.Duration) error
Add adds a new job with an interval period to dispatch the job
func (*Dispatcher) Contains ¶
func (p *Dispatcher) Contains(id string) bool
Contains check if the job is on the dispatcher
func (*Dispatcher) Events ¶
func (p *Dispatcher) Events() chan Job
Events returns the channel of events
func (*Dispatcher) Remove ¶
func (p *Dispatcher) Remove(value string) error
Remove removes a job from the dispatcher
func (*Dispatcher) SetEnabled ¶
func (p *Dispatcher) SetEnabled(enabled bool)
SetEnabled is used to control if the periodic dispatcher is enabled
func (*Dispatcher) Tracked ¶
func (p *Dispatcher) Tracked() []Job
Tracked returns the object being tracked
type Info ¶
type Info struct { Client string Enode *enode.Enode Capabilities Capabilities ListenPort uint64 }
Info is the information of a peer
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 Stream, peer *Peer) error }
Protocol is a wire protocol
type ProtocolSpec ¶
ProtocolSpec is a specification of an etheruem protocol
type Server ¶
type Server struct { Name string EventCh chan MemberEvent Discovery discovery.Discovery Enode *enode.Enode // contains filtered or unexported fields }
Server is the ethereum client
func NewServer ¶
func NewServer(key *ecdsa.PrivateKey, transport Transport, opts ...ConfigOption) (*Server, error)
NewServer creates a new node
func (*Server) Disconnect ¶
func (s *Server) Disconnect()
func (*Server) GetPeerByPrefix ¶
GetPeerByPrefix searches a peer by his prefix
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 // 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 { // WriteMsg writes a message WriteMsg(code uint64, b []byte) error // ReadMsg reads a message from the stream ReadMsg() ([]byte, uint16, error) // Close closes the connection Close() error 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