Documentation
¶
Overview ¶
Copyright 2018-2019 The trust-net Authors Configuration for P2P Layer initialization for DAG protocol library
Copyright 2018-2019 The trust-net Authors P2P Layer interface and implementation for DAG protocol library
Copyright 2018-2019 The trust-net Authors P2P message interface and implementation for DAG protocol library
Copyright 2018-2019 The trust-net Authors P2P Peer interface and implementation for DAG protocol library
Copyright 2018-2019 The trust-net Authors Mock DEVp2p implementations for use as test fixtures
Index ¶
- Constants
- func NewDEVp2pLayer(c Config, cb Runner) (*layerDEVp2p, error)
- func NewDEVp2pPeer(peer peerDEVp2pWrapper, rw p2p.MsgReadWriter) *peerDEVp2p
- func TestConn() *mockMsgReadWriter
- func TestDEVp2pPeer(name string) *p2p.Peer
- func TestMockPeer(name string) *mockPeer
- type Config
- type ECDSAKey
- type Layer
- type MockP2P
- func (p2p *MockP2P) Anchor(a *dto.Anchor) error
- func (p2p *MockP2P) Broadcast(msgId []byte, msgcode uint64, data interface{}) error
- func (p2p *MockP2P) Disconnect(peer Peer)
- func (p2p *MockP2P) Id() []byte
- func (p2p *MockP2P) Reset()
- func (p2p *MockP2P) Self() string
- func (p2p *MockP2P) Sign(data []byte) ([]byte, error)
- func (p2p *MockP2P) Start() error
- func (p2p *MockP2P) Stop()
- func (p2p *MockP2P) Verify(payload, sign, id []byte) bool
- type Msg
- type Peer
- type Runner
Constants ¶
View Source
const ( // Peer connected Connected = 0x00 // Peer disconnected Disconnected = 0x01 )
Variables ¶
This section is empty.
Functions ¶
func NewDEVp2pLayer ¶
create an instance of p2p layer using DEVp2p implementation
func NewDEVp2pPeer ¶
func NewDEVp2pPeer(peer peerDEVp2pWrapper, rw p2p.MsgReadWriter) *peerDEVp2p
func TestDEVp2pPeer ¶
func TestMockPeer ¶
func TestMockPeer(name string) *mockPeer
Types ¶
type Config ¶
type Config struct { // path to private key for p2p layer node KeyFile string `json:"key_file" gencodec:"required"` // type of private key for p2p layer node ("ECDSA_S256") KeyType string `json:"key_type" gencodec:"required"` // MaxPeers is the maximum number of peers that can be // connected. It must be greater than zero. MaxPeers int `json:"max_peers" gencodec:"required"` // Name sets the node name of this server. Name string `json:"node_name" gencodec:"required"` // Bootnodes are used to establish connectivity // with the rest of the network. Bootnodes []string `json:"boot_nodes"` // Name should contain the official protocol name, // often a three-letter word. ProtocolName string `json:"proto_name" gencodec:"required"` // Version should contain the version number of the protocol. ProtocolVersion uint `json:"proto_ver" gencodec:"required"` // Length should contain the number of message codes used // by the protocol. ProtocolLength uint64 // If ListenAddr is set to a non-nil address, the server // will listen for incoming connections. ListenAddr string `json:"listen_addr"` // If the port is zero, the operating system will pick a port. Port string `json:"listen_port"` // If set to true, the listening port is made available to the // Internet. NAT bool }
func TestConfig ¶
func TestConfig() Config
type MockP2P ¶
type MockP2P struct { IsStarted bool IsStopped bool DidBroadcast bool BroadcastCode uint64 BroadcastMsg interface{} IsAnchored bool Name string ID []byte }
func TestP2PLayer ¶
func (*MockP2P) Disconnect ¶
type Peer ¶
type Peer interface { // get identity of the peer node ID() []byte // get name of the peer node Name() string // get remove address of the peer node RemoteAddr() net.Addr // get local address in connection to the peer node LocalAddr() net.Addr // disconnect with peer node Disconnect() // connection status with peer node Status() int // a human readable representation of peer node String() string // send a message to peer node Send(msgId []byte, msgcode uint64, data interface{}) error // mark a message as seen for this peer Seen(msgId []byte) // reset seen set due to a sync ResetSeen() // read a message from peer node ReadMsg() (Msg, error) // save state during sync SetState(stateId int, stateData interface{}) error // fetch state during sync GetState(stateId int) interface{} // Shard children Q ShardChildrenQ() repo.Queue // push a transaction into stack for processing later ToBeFetchedStackPush(tx dto.Transaction) error // pop a transaction from stack for processing (nil if stack empty) ToBeFetchedStackPop() dto.Transaction // set logger SetLogger(logger log.Logger) // get logger Logger() log.Logger }
P2P layer's wrapper for extracting Peer interface from underlying implementations
Click to show internal directories.
Click to hide internal directories.