p2p

package
v0.9.3-testnet Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2018 License: MIT Imports: 38 Imported by: 8

README

Stuffs for p2p network

Documentation

Index

Constants

View Source
const (

	// time to determine which the remote designated peer is not working.
	DesignatedNodeTTL = time.Minute * 60
	// time to determine which the remote peer is not working.
	DefaultNodeTTL = time.Minute * 10
)

constants for peer communicating

View Source
const (
	SyncWorkTTL        = time.Second * 30
	AddBlockCheckpoint = 100
	AddBlockWaitTime   = time.Second * 10
)

constants for legacy sync algorithm. DEPRECATED newer sync loging in syncer package is used now.

View Source
const (
	DiscoveryQueryInterval = time.Minute * 5

	MaxAddrListSizePolaris = 200
	MaxAddrListSizePeer    = 50
)

constants for node discovery

View Source
const (
	DefaultGlobalBlockCacheSize = 300
	DefaultPeerBlockCacheSize   = 100

	DefaultGlobalTxCacheSize = 50000
	DefaultPeerTxCacheSize   = 2000
	// DefaultPeerTxQueueSize is maximum size of hashes in a single tx notice message
	DefaultPeerTxQueueSize = 40000
)

constants for caching TODO this value better related to max peer and block produce interval, not constant

View Source
const (
	// this magic number is useful only in handshaking
	MAGICMain uint32 = 0x47416841
	MAGICTest uint32 = 0x2e415429

	P2PVersion030 uint32 = 0x00000300

	SigLength = 16
	IDLength  = 16

	MaxPayloadLength = 1 << 23 // 8MB

	MaxBlockHeaderResponseCount = 10000
	MaxBlockResponseCount       = 2000
)

constants of p2p protocol since v0.3

View Source
const (
	LogPeerID   = "peer_id"
	LogProtoID  = "protocol_id"
	LogMsgID    = "msg_id"
	LogBlkHash  = "blk_hash"
	LogBlkCount = "blk_cnt"
	LogTxHash   = "tx_hash"
	LogTxCount  = "tx_cnt"
)

frequently used constants for indicating p2p log category

View Source
const ClientVersion = "0.2.0"

ClientVersion is the version of p2p protocol to which this codes are built FIXME version should be defined in more general ways

View Source
const (
	EmptyGetBlockResponseSize = 12 // roughly estimated maximum size if element is full
)

Variables

View Source
var (
	EmptyID = MsgID(uuid.Nil)
)
View Source
var TimeoutError error

Functions

func ComparePeerID

func ComparePeerID(pid1, pid2 peer.ID) int

ComparePeerID do byte-wise compare of two peerIDs,

func InitNodeInfo

func InitNodeInfo(cfg *config.P2PConfig, logger *log.Logger)

InitNodeInfo initializes node-specific informations like node id. Caution: this must be called before all the goroutines are started.

func MarshalMessage added in v0.9.4

func MarshalMessage(message proto.Message) ([]byte, error)

func NewNetworkTransport added in v0.9.4

func NewNetworkTransport(conf *cfg.P2PConfig, logger *log.Logger) *networkTransport

func NodeID

func NodeID() peer.ID

NodeID returns the node id.

func NodePrivKey

func NodePrivKey() crypto.PrivKey

NodePrivKey returns the private key of the node.

func NodePubKey

func NodePubKey() crypto.PubKey

NodePubKey returns the public key of the node.

func NodeSID

func NodeSID() string

NodeSID returns the string representation of the node id.

func P2PTxHashArrToString

func P2PTxHashArrToString(bbarray []TxHash) string

bytesArrToString converts array of byte array to json array of b58 encoded string.

func P2PTxHashArrToStringWithLimit

func P2PTxHashArrToStringWithLimit(bbarray []TxHash, limit int) string

func ParseMultiaddrWithResolve added in v0.9.4

func ParseMultiaddrWithResolve(str string) (multiaddr.Multiaddr, error)

ParseMultiaddrWithResolve parse string to multiaddr, additionally accept domain name with protocol /dns NOTE: this function is temporarilly use until go-multiaddr start to support dns.

func PrintHashList added in v0.9.4

func PrintHashList(blocks []*types.Block) string

func RandomUUID

func RandomUUID() string

RandomUUID generate random UUID and return in form of string

func SendProtoMessage

func SendProtoMessage(data proto.Message, rw *bufio.Writer) error

SendProtoMessage send proto.Message data over stream

func UnmarshalMessage added in v0.9.4

func UnmarshalMessage(data []byte, msgData proto.Message) error

Types

type ActorService

type ActorService interface {
	// TellRequest send actor request, which does not need to get return value, and forget it.
	TellRequest(actor string, msg interface{})
	// SendRequest send actor request, and the response is expected to go back asynchronously.
	SendRequest(actor string, msg interface{})
	// CallRequest send actor request and wait the handling of that message to finished,
	// and get return value.
	CallRequest(actor string, msg interface{}, timeout time.Duration) (interface{}, error)
	// CallRequestDefaultTimeout is CallRequest with default timeout
	CallRequestDefaultTimeout(actor string, msg interface{}) (interface{}, error)

	// FutureRequest send actor reqeust and get the Future object to get the state and return value of message
	FutureRequest(actor string, msg interface{}, timeout time.Duration) *actor.Future
	// FutureRequestDefaultTimeout is FutureRequest with default timeout
	FutureRequestDefaultTimeout(actor string, msg interface{}) *actor.Future

	GetChainAccessor() types.ChainAccessor
}

ActorService is collection of helper methods to use actor FIXME move to more general package. it used in p2p and rpc

type BaseMsgHandler

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

BaseMsgHandler contains common attributes of MessageHandler

type BlkHash

type BlkHash [blkhashLen]byte

func MustParseBlkHash

func MustParseBlkHash(bSlice []byte) BlkHash

func ParseToBlkHash

func ParseToBlkHash(bSlice []byte) (BlkHash, error)

func (BlkHash) Slice

func (h BlkHash) Slice() []byte

func (BlkHash) String

func (h BlkHash) String() string

type BlockHashByNoReceiver added in v0.8.2

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

BlocksChunkReceiver is send p2p getBlocksRequest to target peer and receive p2p responses till all requestes blocks are received It will send response actor message if all blocks are received or failed to receive, but not send response if timeout expired.

func NewBlockHashByNoReceiver added in v0.8.2

func NewBlockHashByNoReceiver(actor ActorService, peer RemotePeer, blockNo types.BlockNo, ttl time.Duration) *BlockHashByNoReceiver

func (*BlockHashByNoReceiver) ReceiveResp added in v0.8.2

func (br *BlockHashByNoReceiver) ReceiveResp(msg Message, msgBody proto.Message) (ret bool)

ReceiveResp must be called just in read go routine

func (*BlockHashByNoReceiver) StartGet added in v0.8.2

func (br *BlockHashByNoReceiver) StartGet()

type BlockHashesReceiver added in v0.8.1

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

BlocksChunkReceiver is send p2p getBlocksRequest to target peer and receive p2p responses till all requestes blocks are received It will send response actor message if all blocks are received or failed to receive, but not send response if timeout expired.

func NewBlockHashesReceiver added in v0.8.1

func NewBlockHashesReceiver(actor ActorService, peer RemotePeer, req *message.GetHashes, ttl time.Duration) *BlockHashesReceiver

func (*BlockHashesReceiver) ReceiveResp added in v0.8.1

func (br *BlockHashesReceiver) ReceiveResp(msg Message, msgBody proto.Message) (ret bool)

ReceiveResp must be called just in read go routine

func (*BlockHashesReceiver) StartGet added in v0.8.1

func (br *BlockHashesReceiver) StartGet()

type BlocksChunkReceiver added in v0.8.1

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

BlocksChunkReceiver is send p2p getBlocksRequest to target peer and receive p2p responses till all requestes blocks are received It will send response actor message if all blocks are received or failed to receive, but not send response if timeout expired.

func NewBlockReceiver added in v0.8.1

func NewBlockReceiver(actor ActorService, peer RemotePeer, blockHashes []message.BlockHash, ttl time.Duration) *BlocksChunkReceiver

func (*BlocksChunkReceiver) ReceiveResp added in v0.8.1

func (br *BlocksChunkReceiver) ReceiveResp(msg Message, msgBody proto.Message) (ret bool)

ReceiveResp must be called just in read go routine

func (*BlocksChunkReceiver) StartGet added in v0.8.1

func (br *BlocksChunkReceiver) StartGet()

type HSHandler added in v0.9.4

type HSHandler interface {
	// Handle peer handshake till ttl, and return msgrw for this connection, and status of remote peer.
	Handle(r io.Reader, w io.Writer, ttl time.Duration) (MsgReadWriter, *types.Status, error)
}

HSHandler will do handshake with remote peer

type HSHandlerFactory added in v0.9.4

type HSHandlerFactory interface {
	CreateHSHandler(outbound bool, pm PeerManager, actor ActorService, log *log.Logger, pid peer.ID) HSHandler
}

type HSHeader

type HSHeader struct {
	Magic   uint32
	Version uint32
}

func (HSHeader) Marshal

func (h HSHeader) Marshal() []byte

func (*HSHeader) Unmarshal

func (h *HSHeader) Unmarshal(b []byte)

type HandlerFactory

type HandlerFactory interface {
	// contains filtered or unexported methods
}

type InboundHSHandler added in v0.9.4

type InboundHSHandler struct {
	*PeerHandshaker
}

func (*InboundHSHandler) Handle added in v0.9.4

type LiteContainerService

type LiteContainerService struct {
	*component.BaseComponent
	// contains filtered or unexported fields
}

P2P is actor component for p2p

func NewNTContainer

func NewNTContainer(cfg *config.Config) *LiteContainerService

NewP2P create a new ActorService for p2p

func (*LiteContainerService) AfterStart

func (lntc *LiteContainerService) AfterStart()

func (*LiteContainerService) BeforeStart

func (lntc *LiteContainerService) BeforeStart()

BeforeStart starts p2p service.

func (*LiteContainerService) BeforeStop

func (lntc *LiteContainerService) BeforeStop()

BeforeStop is called before actor hub stops. it finishes underlying peer manager

func (*LiteContainerService) CallRequest

func (lntc *LiteContainerService) CallRequest(actor string, msg interface{}, timeout time.Duration) (interface{}, error)

CallRequest implement interface method of ActorService

func (*LiteContainerService) CallRequestDefaultTimeout

func (lntc *LiteContainerService) CallRequestDefaultTimeout(actor string, msg interface{}) (interface{}, error)

CallRequest implement interface method of ActorService

func (*LiteContainerService) FutureRequest

func (lntc *LiteContainerService) FutureRequest(actor string, msg interface{}, timeout time.Duration) *actor.Future

FutureRequest implement interface method of ActorService

func (*LiteContainerService) FutureRequestDefaultTimeout

func (lntc *LiteContainerService) FutureRequestDefaultTimeout(actor string, msg interface{}) *actor.Future

FutureRequestDefaultTimeout implement interface method of ActorService

func (*LiteContainerService) GetNetworkTransport

func (lntc *LiteContainerService) GetNetworkTransport() NetworkTransport

func (*LiteContainerService) Receive

func (lntc *LiteContainerService) Receive(context actor.Context)

Receive got actor message and then handle it.

func (*LiteContainerService) SendRequest

func (lntc *LiteContainerService) SendRequest(actor string, msg interface{})

SendRequest implement interface method of ActorService

func (*LiteContainerService) Statistics

func (lntc *LiteContainerService) Statistics() *map[string]interface{}

Statistics show statistic information of p2p module. NOTE: It it not implemented yet

func (*LiteContainerService) TellRequest

func (lntc *LiteContainerService) TellRequest(actor string, msg interface{})

TellRequest implement interface method of ActorService

type Message

type Message interface {
	Subprotocol() SubProtocol

	// Length is lenght of payload
	Length() uint32
	Timestamp() int64
	// ID is 16 bytes unique identifier
	ID() MsgID
	// OriginalID is message id of request which trigger this message. it will be all zero, if message is request or notice.
	OriginalID() MsgID

	// marshaled by google protocol buffer v3. object is determined by Subprotocol
	Payload() []byte
}

type MessageHandler

type MessageHandler interface {
	// contains filtered or unexported methods
}

MessageHandler handle incoming subprotocol message

type MsgID

type MsgID [IDLength]byte

MsgID is

func MustParseBytes

func MustParseBytes(b []byte) MsgID

MustParseBytes return msgid from byte slice

func NewMsgID

func NewMsgID() (m MsgID)

NewMsgID return random id

func ParseBytesToMsgID

func ParseBytesToMsgID(b []byte) (MsgID, error)

func (MsgID) String

func (id MsgID) String() string

func (MsgID) UUID

func (id MsgID) UUID() uuid.UUID

type MsgReadWriter

type MsgReadWriter interface {
	MsgReader
	MsgWriter
}

type MsgReader

type MsgReader interface {
	// ReadMsg return types.MsgHeader as header, proto.Message as data
	// The header and/or data can be nil if error is not nil
	ReadMsg() (Message, error)
}

MsgReader read stream and return message object

type MsgWriter

type MsgWriter interface {
	WriteMsg(msg Message) error
}

MsgWriter write message to stream

type NTContainer added in v0.9.4

type NTContainer interface {
	GetNetworkTransport() NetworkTransport
}

NTContainer can provide NetworkTransport interface.

type NetworkTransport added in v0.9.4

type NetworkTransport interface {
	host.Host
	Start() error
	Stop() error

	PrivateKey() crypto.PrivKey
	PublicKey() crypto.PubKey
	SelfMeta() PeerMeta
	SelfNodeID() peer.ID

	GetAddressesOfPeer(peerID peer.ID) []string

	// AddStreamHandler wrapper function which call host.SetStreamHandler after transport is initialized, this method is for preventing nil error.
	AddStreamHandler(pid protocol.ID, handler inet.StreamHandler)

	GetOrCreateStream(meta PeerMeta, protocolID protocol.ID) (inet.Stream, error)
	GetOrCreateStreamWithTTL(meta PeerMeta, protocolID protocol.ID, ttl time.Duration) (inet.Stream, error)

	FindPeer(peerID peer.ID) bool
	ClosePeerConnection(peerID peer.ID) bool
}

NetworkTransport do manager network connection TODO need refactoring. it has other role, pk management of self peer

type OutboundHSHandler added in v0.9.4

type OutboundHSHandler struct {
	*PeerHandshaker
}

func (*OutboundHSHandler) Handle added in v0.9.4

type P2P

type P2P struct {
	*component.BaseComponent
	// contains filtered or unexported fields
}

P2P is actor component for p2p

func NewP2P

func NewP2P(cfg *config.Config, chainsvc *chain.ChainService) *P2P

NewP2P create a new ActorService for p2p

func (*P2P) AfterStart

func (p2ps *P2P) AfterStart()

func (*P2P) BeforeStart

func (p2ps *P2P) BeforeStart()

BeforeStart starts p2p service.

func (*P2P) BeforeStop

func (p2ps *P2P) BeforeStop()

BeforeStop is called before actor hub stops. it finishes underlying peer manager

func (*P2P) CallRequest

func (p2ps *P2P) CallRequest(actor string, msg interface{}, timeout time.Duration) (interface{}, error)

CallRequest implement interface method of ActorService

func (*P2P) CallRequestDefaultTimeout

func (p2ps *P2P) CallRequestDefaultTimeout(actor string, msg interface{}) (interface{}, error)

CallRequest implement interface method of ActorService

func (*P2P) CreateHSHandler added in v0.9.0

func (p2ps *P2P) CreateHSHandler(outbound bool, pm PeerManager, actor ActorService, log *log.Logger, pid peer.ID) HSHandler

func (*P2P) FutureRequest

func (p2ps *P2P) FutureRequest(actor string, msg interface{}, timeout time.Duration) *actor.Future

FutureRequest implement interface method of ActorService

func (*P2P) FutureRequestDefaultTimeout

func (p2ps *P2P) FutureRequestDefaultTimeout(actor string, msg interface{}) *actor.Future

FutureRequestDefaultTimeout implement interface method of ActorService

func (*P2P) GetAddresses

func (p2ps *P2P) GetAddresses(peerID peer.ID, size uint32) bool

GetAddresses send getAddress request to other peer

func (*P2P) GetBlockHashByNo added in v0.8.2

func (p2ps *P2P) GetBlockHashByNo(context actor.Context, msg *message.GetHashByNo)

GetBlockHashes send request message to peer and make response message for block hashes

func (*P2P) GetBlockHashes added in v0.8.1

func (p2ps *P2P) GetBlockHashes(context actor.Context, msg *message.GetHashes)

GetBlockHashes send request message to peer and make response message for block hashes

func (*P2P) GetBlockHeaders

func (p2ps *P2P) GetBlockHeaders(msg *message.GetBlockHeaders) bool

GetBlockHeaders send request message to peer and

func (*P2P) GetBlocks

func (p2ps *P2P) GetBlocks(peerID peer.ID, blockHashes []message.BlockHash) bool

GetBlocks send request message to peer and

func (*P2P) GetBlocksChunk added in v0.8.1

func (p2ps *P2P) GetBlocksChunk(context actor.Context, msg *message.GetBlockChunks)

GetBlocksChunk send request message to peer and

func (*P2P) GetChainAccessor

func (p2ps *P2P) GetChainAccessor() types.ChainAccessor

GetChainAccessor implment interface method of ActorService

func (*P2P) GetMissingBlocks

func (p2ps *P2P) GetMissingBlocks(peerID peer.ID, hashes []message.BlockHash) bool

GetMissingBlocks send request message to peer about blocks which my local peer doesn't have

func (*P2P) GetNetworkTransport added in v0.9.0

func (p2ps *P2P) GetNetworkTransport() NetworkTransport

func (*P2P) GetSyncAncestor added in v0.8.1

func (p2ps *P2P) GetSyncAncestor(peerID peer.ID, hashes [][]byte) bool

Syncer.finder request remote peer to find ancestor

func (*P2P) GetTXs

func (p2ps *P2P) GetTXs(peerID peer.ID, txHashes []message.TXHash) bool

GetTXs send request message to peer and

func (*P2P) NotifyNewBlock

func (p2ps *P2P) NotifyNewBlock(newBlock message.NotifyNewBlock) bool

NotifyNewBlock send notice message of new block to a peer

func (*P2P) NotifyNewTX

func (p2ps *P2P) NotifyNewTX(newTXs message.NotifyNewTransactions) bool

NotifyNewTX notice tx(s) id created

func (*P2P) Receive

func (p2ps *P2P) Receive(context actor.Context)

Receive got actor message and then handle it.

func (*P2P) SendRequest

func (p2ps *P2P) SendRequest(actor string, msg interface{})

SendRequest implement interface method of ActorService

func (*P2P) Statistics

func (p2ps *P2P) Statistics() *map[string]interface{}

Statistics show statistic information of p2p module. NOTE: It it not implemented yet

func (*P2P) TellRequest

func (p2ps *P2P) TellRequest(actor string, msg interface{})

TellRequest implement interface method of ActorService

type PeerEventListener

type PeerEventListener interface {
	// OnAddPeer is called just after the peer is added.
	OnAddPeer(peerID peer.ID)

	// OnRemovePeer is called just before the peer is removed
	OnRemovePeer(peerID peer.ID)
}

PeerEventListener listen peer manage event

type PeerHandshaker

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

PeerHandshaker works to handshake to just connected peer, it detect chain networks and protocol versions, and then select InnerHandshaker for that protocol version.

type PeerManager

type PeerManager interface {
	Start() error
	Stop() error

	//NetworkTransport
	SelfMeta() PeerMeta
	SelfNodeID() peer.ID

	AddNewPeer(peer PeerMeta)
	RemovePeer(peerID peer.ID)
	// NotifyPeerHandshake is called after remote peer is completed handshake and ready to receive or send
	NotifyPeerHandshake(peerID peer.ID)
	NotifyPeerAddressReceived([]PeerMeta)

	// GetPeer return registered(handshaked) remote peer object
	GetPeer(ID peer.ID) (RemotePeer, bool)
	GetPeers() []RemotePeer
	GetPeerAddresses() ([]*types.PeerAddress, []bool, []*types.NewBlockNotice, []types.PeerState)
}

PeerManager is internal service that provide peer management

func NewPeerManager

func NewPeerManager(handlerFactory HandlerFactory, hsFactory HSHandlerFactory, iServ ActorService, cfg *cfg.Config, signer msgSigner, nt NetworkTransport, rm ReconnectManager, mm metric.MetricsManager, logger *log.Logger, mf moFactory) PeerManager

NewPeerManager creates a peer manager object.

type PeerMeta

type PeerMeta struct {
	ID peer.ID
	// IPAddress is human readable form of ip address such as "192.168.0.1" or "2001:0db8:0a0b:12f0:33:1"
	IPAddress  string
	Port       uint32
	Designated bool // Designated means this peer is designated in config file and connect to in startup phase

	Hidden   bool // Hidden means that meta info of this peer will not be sent to other peers when getting peer list
	Outbound bool
}

PeerMeta contains non changeable information of peer node during connected state TODO: PeerMeta is almost same as PeerAddress, so TODO to unify them.

func FromMultiAddr added in v0.9.4

func FromMultiAddr(targetAddr multiaddr.Multiaddr) (PeerMeta, error)

func FromMultiAddrString added in v0.9.4

func FromMultiAddrString(str string) (PeerMeta, error)

func FromPeerAddress

func FromPeerAddress(addr *types.PeerAddress) PeerMeta

FromPeerAddress convert PeerAddress to PeerMeta

func (PeerMeta) String

func (m PeerMeta) String() string

func (PeerMeta) TTL

func (m PeerMeta) TTL() time.Duration

TTL return node's ttl

func (PeerMeta) ToPeerAddress

func (m PeerMeta) ToPeerAddress() types.PeerAddress

ToPeerAddress convert PeerMeta to PeerAddress

type PeerPoolManager

type PeerPoolManager struct {
}

type ReconnectManager

type ReconnectManager interface {
	AddJob(meta PeerMeta)
	// CancelJob cancel from outer module to reconnectRunner
	CancelJob(pid peer.ID)

	Stop()
	// contains filtered or unexported methods
}

ReconnectManager manage reconnect job schedule

type RemotePeer

type RemotePeer interface {
	ID() peer.ID
	Meta() PeerMeta
	State() types.PeerState
	LastNotice() *types.NewBlockNotice

	GetReceiver(id MsgID) ResponseReceiver

	// TODO
	MF() moFactory
	// contains filtered or unexported methods
}

type ResponseReceiver added in v0.8.1

type ResponseReceiver func(msg Message, msgBody proto.Message) bool

ResponseReceiver returns true when receiver handled it, or false if this receiver is not the expected handler. NOTE: the return value is temporal works for old implementation and will be remove later.

type SubProtocol

type SubProtocol uint32

SubProtocol identifies the lower type of p2p message

const (
	StatusRequest SubProtocol
	PingRequest
	PingResponse
	GoAway
	AddressesRequest
	AddressesResponse
)
const (
	GetBlocksRequest SubProtocol = 0x010 + iota
	GetBlocksResponse
	GetBlockHeadersRequest
	GetBlockHeadersResponse
	GetMissingRequest
	GetMissingResponse
	NewBlockNotice
	GetAncestorRequest
	GetAncestorResponse
	GetHashesRequest
	GetHashesResponse
	GetHashByNoRequest
	GetHashByNoResponse
)
const (
	GetTXsRequest SubProtocol = 0x020 + iota
	GetTxsResponse
	NewTxNotice
)

func FindSubProtocol added in v0.8.2

func FindSubProtocol(code uint32) (SubProtocol, bool)

func ParseSubProtocol added in v0.8.2

func ParseSubProtocol(str string) (SubProtocol, bool)

func (SubProtocol) String

func (i SubProtocol) String() string

func (SubProtocol) Uint32

func (i SubProtocol) Uint32() uint32

type SyncManager

type SyncManager interface {
	HandleNewBlockNotice(peer RemotePeer, hash BlkHash, data *types.NewBlockNotice)
	HandleGetBlockResponse(peer RemotePeer, msg Message, resp *types.GetBlockResponse)
	HandleNewTxNotice(peer RemotePeer, hashes []TxHash, data *types.NewTransactionsNotice)

	DoSync(peer RemotePeer, hashes []message.BlockHash, stopHash message.BlockHash)
}

type TxHash

type TxHash [txhashLen]byte

func MustParseTxHash

func MustParseTxHash(bSlice []byte) TxHash

func ParseToTxHash

func ParseToTxHash(bSlice []byte) (TxHash, error)

func (TxHash) Slice

func (h TxHash) Slice() []byte

func (TxHash) String

func (h TxHash) String() string

type V020Wrapper

type V020Wrapper struct {
	*types.P2PMessage
	// contains filtered or unexported fields
}

func NewV020Wrapper

func NewV020Wrapper(message *types.P2PMessage, originalID string) *V020Wrapper

func (*V020Wrapper) ID

func (m *V020Wrapper) ID() MsgID

func (*V020Wrapper) Length

func (m *V020Wrapper) Length() uint32

func (*V020Wrapper) OriginalID

func (m *V020Wrapper) OriginalID() MsgID

func (*V020Wrapper) Payload

func (m *V020Wrapper) Payload() []byte

func (*V020Wrapper) Subprotocol

func (m *V020Wrapper) Subprotocol() SubProtocol

func (*V020Wrapper) Timestamp

func (m *V020Wrapper) Timestamp() int64

type V030HSMessage

type V030HSMessage struct {
	HSHeader
	Sigature  [SigLength]byte
	PubKeyB   []byte
	Timestamp uint64
	Nonce     uint16
}

type V030Handshaker

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

V030Handshaker exchange status data over protocol version .0.3.0

func (*V030Handshaker) GetMsgRW

func (h *V030Handshaker) GetMsgRW() MsgReadWriter

type V030Message

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

V030Message is basic form of p2p message v0.3

func NewV030Message added in v0.9.4

func NewV030Message(msgID, originalID MsgID, timestamp int64, protocol SubProtocol, payload []byte) *V030Message

NewV030Message create a new object

func (*V030Message) ID

func (m *V030Message) ID() MsgID

func (*V030Message) Length

func (m *V030Message) Length() uint32

func (*V030Message) OriginalID

func (m *V030Message) OriginalID() MsgID

func (*V030Message) Payload

func (m *V030Message) Payload() []byte

func (*V030Message) Subprotocol

func (m *V030Message) Subprotocol() SubProtocol

func (*V030Message) Timestamp

func (m *V030Message) Timestamp() int64

type V030ReadWriter

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

func NewV030ReadWriter

func NewV030ReadWriter(r *bufio.Reader, w *bufio.Writer) *V030ReadWriter

func (*V030ReadWriter) ReadMsg

func (rw *V030ReadWriter) ReadMsg() (Message, error)

func (*V030ReadWriter) WriteMsg

func (rw *V030ReadWriter) WriteMsg(msg Message) error

type V030Reader

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

func NewV030Reader

func NewV030Reader(rd *bufio.Reader) *V030Reader

func (*V030Reader) ReadMsg

func (r *V030Reader) ReadMsg() (Message, error)

ReadMsg() must be used in single thread

type V030Writer

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

func NewV030Writer

func NewV030Writer(wr *bufio.Writer) *V030Writer

func (*V030Writer) WriteMsg

func (w *V030Writer) WriteMsg(msg Message) error

WriteMsg() must be used in single thread

Directories

Path Synopsis
Package mock_p2p is a generated GoMock package.
Package mock_p2p is a generated GoMock package.

Jump to

Keyboard shortcuts

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