Documentation ¶
Index ¶
- Constants
- Variables
- type ActorService
- type Message
- type MessageHandler
- type MoFactory
- type MsgID
- type MsgOrder
- type MsgReadWriter
- type MsgReader
- type MsgSigner
- type MsgWriter
- type NTContainer
- type NetworkTransport
- type PbMessage
- type PeerManager
- type PeerMeta
- type RemotePeer
- type ResponseReceiver
- type SubProtocol
- type SyncManager
Constants ¶
const ( // this magic number is useful only in handshaking MAGICMain uint32 = 0x47416841 MAGICTest uint32 = 0x2e415429 P2PVersion030 uint32 = 0x00000300 SigLength = 16 MaxPayloadLength = 1 << 23 // 8MB MaxBlockHeaderResponseCount = 10000 MaxBlockResponseCount = 2000 )
constants of p2p protocol since v0.3
const (
AergoP2PSub protocol.ID = "/aergop2p/0.3"
)
context of multiaddr, as higher type of p2p message
const IDLength = 16
Variables ¶
var (
EmptyID = MsgID(uuid.Nil)
)
Functions ¶
This section is empty.
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 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 { ParsePayload([]byte) (proto.Message, error) CheckAuth(msgHeader Message, msgBody proto.Message) error Handle(msgHeader Message, msgBody proto.Message) PreHandle() PostHandle(msgHeader Message, msgBody proto.Message) }
MessageHandler handle incoming subprotocol message
type MoFactory ¶
type MoFactory interface { NewMsgRequestOrder(expecteResponse bool, protocolID SubProtocol, message PbMessage) MsgOrder NewMsgBlockRequestOrder(respReceiver ResponseReceiver, protocolID SubProtocol, message PbMessage) MsgOrder NewMsgResponseOrder(reqID MsgID, protocolID SubProtocol, message PbMessage) MsgOrder NewMsgBlkBroadcastOrder(noticeMsg *types.NewBlockNotice) MsgOrder NewMsgTxBroadcastOrder(noticeMsg *types.NewTransactionsNotice) MsgOrder NewMsgBPBroadcastOrder(noticeMsg *types.BlockProducedNotice) MsgOrder }
type MsgID ¶
MsgID is
func MustParseBytes ¶
MustParseBytes return msgid from byte slice
func ParseBytesToMsgID ¶
type MsgOrder ¶
type MsgOrder interface { GetMsgID() MsgID // Timestamp is unit time value Timestamp() int64 IsRequest() bool IsNeedSign() bool GetProtocolID() SubProtocol // SendTo send message to remote peer. it return err if write fails, or nil if write is successful or ignored. SendTo(p RemotePeer) error }
msgOrder is abstraction information about the message that will be sent to peer some type of msgOrder, such as notice mo, should thread-safe and re-entrant
type MsgReadWriter ¶
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 MsgSigner ¶
type MsgSigner interface { // signMsg calulate signature and fill related fields in msg(peerid, pubkey, signature or etc) SignMsg(msg *types.P2PMessage) error // verifyMsg check signature is valid VerifyMsg(msg *types.P2PMessage, senderID peer.ID) error }
signHandler sign or verify p2p message
type NTContainer ¶
type NTContainer interface { GetNetworkTransport() NetworkTransport // ChainID return id of current chain. ChainID() *types.ChainID }
NTContainer can provide NetworkTransport interface.
type NetworkTransport ¶
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 PeerManager ¶
type PeerManager interface { Start() error Stop() error //NetworkTransport SelfMeta() PeerMeta SelfNodeID() peer.ID AddNewPeer(peer PeerMeta) // Remove peer from peer list. Peer dispose relative resources and stop itself, and then call RemovePeer to peermanager RemovePeer(peer RemotePeer) // 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(noHidden bool, showSelf bool) []*message.PeerInfo GetPeerBlockInfos() []types.PeerBlockInfo }
PeerManager is internal service that provide peer management
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 FromPeerAddress ¶
func FromPeerAddress(addr *types.PeerAddress) PeerMeta
FromPeerAddress convert PeerAddress to PeerMeta
func NewMetaFromStatus ¶
FromStatusToMeta create peerMeta from Status message
func (PeerMeta) ToPeerAddress ¶
func (m PeerMeta) ToPeerAddress() types.PeerAddress
ToPeerAddress convert PeerMeta to PeerAddress
type RemotePeer ¶
type RemotePeer interface { ID() peer.ID Meta() PeerMeta ManageNumber() uint32 Name() string State() types.PeerState LastNotice() *types.LastBlockStatus RunPeer() Stop() SendMessage(msg MsgOrder) SendAndWaitMessage(msg MsgOrder, ttl time.Duration) error PushTxsNotice(txHashes []types.TxID) ConsumeRequest(msgID MsgID) GetReceiver(id MsgID) ResponseReceiver // updateBlkCache add hash to block cache and return true if this hash already exists. UpdateBlkCache(blkHash []byte, blkNumber uint64) bool // updateTxCache add hashes to transaction cache and return newly added hashes. UpdateTxCache(hashes []types.TxID) []types.TxID // updateLastNotice change estimate of the last status of remote peer UpdateLastNotice(blkHash []byte, blkNumber uint64) // TODO MF() MoFactory }
type SubProtocol ¶
type SubProtocol uint32
SubProtocol identifies the lower type of p2p message
func (SubProtocol) String ¶
func (i SubProtocol) String() string
func (SubProtocol) Uint32 ¶
func (i SubProtocol) Uint32() uint32
type SyncManager ¶
type SyncManager interface { // handle notice from bp HandleBlockProducedNotice(peer RemotePeer, block *types.Block) // handle notice from other node HandleNewBlockNotice(peer RemotePeer, data *types.NewBlockNotice) HandleGetBlockResponse(peer RemotePeer, msg Message, resp *types.GetBlockResponse) HandleNewTxNotice(peer RemotePeer, hashes []types.TxID, data *types.NewTransactionsNotice) }