github.com/aergoio/aergo@v1.3.1/p2p/p2pcommon/remotepeer.go (about) 1 /* 2 * @file 3 * @copyright defined in aergo/LICENSE.txt 4 */ 5 6 //go:generate mockgen -source=remotepeer.go -package=p2pmock -destination=../p2pmock/mock_remotepeer.go 7 package p2pcommon 8 9 import ( 10 "github.com/aergoio/aergo/types" 11 "github.com/libp2p/go-libp2p-core/network" 12 "time" 13 ) 14 15 type PeerFactory interface { 16 CreateRemotePeer(meta PeerMeta, seq uint32, status *types.Status, stream network.Stream, rw MsgReadWriter) RemotePeer 17 } 18 19 type RemotePeer interface { 20 ID() types.PeerID 21 Meta() PeerMeta 22 ManageNumber() uint32 23 Name() string 24 Version() string 25 Role() PeerRole 26 ChangeRole(role PeerRole) 27 28 AddMessageHandler(subProtocol SubProtocol, handler MessageHandler) 29 30 State() types.PeerState 31 // LastStatus returns last observed status of remote peer. this value will be changed by notice, or ping 32 LastStatus() *types.LastBlockStatus 33 34 RunPeer() 35 Stop() 36 37 SendMessage(msg MsgOrder) 38 SendAndWaitMessage(msg MsgOrder, ttl time.Duration) error 39 40 PushTxsNotice(txHashes []types.TxID) 41 // utility method 42 43 ConsumeRequest(msgID MsgID) 44 GetReceiver(id MsgID) ResponseReceiver 45 46 // updateBlkCache add hash to block cache and return true if this hash already exists. 47 UpdateBlkCache(blkHash []byte, blkNumber uint64) bool 48 // updateTxCache add hashes to transaction cache and return newly added hashes. 49 UpdateTxCache(hashes []types.TxID) []types.TxID 50 // updateLastNotice change estimate of the last status of remote peer 51 UpdateLastNotice(blkHash []byte, blkNumber uint64) 52 53 // TODO 54 MF() MoFactory 55 }