p2p

package
v0.0.0-...-4273fad Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: MIT Imports: 17 Imported by: 0

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

View Source
const (
	// Peer connected
	Connected = 0x00
	// Peer disconnected
	Disconnected = 0x01
)

Variables

This section is empty.

Functions

func NewDEVp2pLayer

func NewDEVp2pLayer(c Config, cb Runner) (*layerDEVp2p, error)

create an instance of p2p layer using DEVp2p implementation

func NewDEVp2pPeer

func NewDEVp2pPeer(peer peerDEVp2pWrapper, rw p2p.MsgReadWriter) *peerDEVp2p

func TestConn

func TestConn() *mockMsgReadWriter

func TestDEVp2pPeer

func TestDEVp2pPeer(name string) *p2p.Peer

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 ECDSAKey

type ECDSAKey struct {
	Curve string
	X, Y  []byte
	D     []byte
}

type Layer

type Layer interface {
	// sign a transaction Anchor
	Anchor(a *dto.Anchor) error
	Start() error
	Stop()
	Disconnect(peer Peer)
	Self() string
	Id() []byte
	Sign(data []byte) ([]byte, error)
	Verify(data, sign, id []byte) bool
	Broadcast(msgId []byte, msgcode uint64, data interface{}) error
}

type MockP2P

type MockP2P struct {
	IsStarted     bool
	IsStopped     bool
	DidBroadcast  bool
	BroadcastCode uint64
	BroadcastMsg  interface{}
	IsAnchored    bool
	Name          string
	ID            []byte
}

func TestP2PLayer

func TestP2PLayer(name string) *MockP2P

func (*MockP2P) Anchor

func (p2p *MockP2P) Anchor(a *dto.Anchor) error

func (*MockP2P) Broadcast

func (p2p *MockP2P) Broadcast(msgId []byte, msgcode uint64, data interface{}) error

func (*MockP2P) Disconnect

func (p2p *MockP2P) Disconnect(peer Peer)

func (*MockP2P) Id

func (p2p *MockP2P) Id() []byte

func (*MockP2P) Reset

func (p2p *MockP2P) Reset()

func (*MockP2P) Self

func (p2p *MockP2P) Self() string

func (*MockP2P) Sign

func (p2p *MockP2P) Sign(data []byte) ([]byte, error)

func (*MockP2P) Start

func (p2p *MockP2P) Start() error

func (*MockP2P) Stop

func (p2p *MockP2P) Stop()

func (*MockP2P) Verify

func (p2p *MockP2P) Verify(payload, sign, id []byte) bool

type Msg

type Msg interface {
	Code() uint64
	Decode(val interface{}) error
	String() string
	Discard() error
}

wrapper interface for underlying p2p message implementation

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

type Runner

type Runner func(peer Peer) error

Jump to

Keyboard shortcuts

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