github.com/aergoio/aergo@v1.3.1/message/p2pmsg.go (about) 1 /** 2 * @file 3 * @copyright defined in aergo/LICENSE.txt 4 */ 5 6 package message 7 8 import ( 9 "fmt" 10 "github.com/aergoio/aergo/types" 11 "time" 12 ) 13 14 const P2PSvc = "p2pSvc" 15 16 // errors which async responses of p2p actor, such as GetBlockChunksRsp, can contains, 17 var ( 18 RemotePeerFailError = fmt.Errorf("remote peer return error") 19 PeerNotFoundError = fmt.Errorf("remote peer was not found") 20 MissingHashError = fmt.Errorf("some block hash not found") 21 UnexpectedBlockError = fmt.Errorf("unexpected blocks response") 22 TooFewBlocksError = fmt.Errorf("too few blocks received that expected") 23 TooManyBlocksError = fmt.Errorf("too many blocks received that expected") 24 TooBigBlockError = fmt.Errorf("block size limit exceeded") 25 InvalidArgumentError = fmt.Errorf("invalid argument") 26 ) 27 28 // PingMsg send types.Ping to each peer. 29 // The actor returns true if sending is successful. 30 type PingMsg struct { 31 ToWhom types.PeerID 32 } 33 34 // GetAddressesMsg send types.AddressesRequest to dest peer. the dest peer will send types.AddressesResponse. 35 // The actor returns true if sending is successful. 36 type GetAddressesMsg struct { 37 ToWhom types.PeerID 38 Size uint32 39 Offset uint32 40 } 41 42 // NotifyNewBlock send types.NewBlockNotice to other peers. The receiving peer will send GetBlockHeadersRequest or GetBlockRequest if needed. 43 // The actor returns true if sending is successful. 44 type NotifyNewBlock struct { 45 Produced bool 46 BlockNo uint64 47 Block *types.Block 48 } 49 50 type BlockHash []byte 51 type TXHash []byte 52 53 // NotifyNewTransactions send types.NewTransactionsNotice to other peers. 54 // The actor returns true if sending is successful. 55 type NotifyNewTransactions struct { 56 Txs []*types.Tx 57 } 58 59 // GetTransactions send types.GetTransactionsRequest to dest peer. The receiving peer will send types.GetTransactionsResponse 60 // The actor returns true if sending is successful. 61 type GetTransactions struct { 62 ToWhom types.PeerID 63 Hashes []TXHash 64 } 65 66 // TransactionsResponse is data from other peer, as a response of types.GetTransactionsRequest 67 // p2p module will send this to mempool actor. 68 type TransactionsResponse struct { 69 txs []*types.Tx 70 } 71 72 // GetBlockHeaders send type.GetBlockRequest to dest peer 73 // The actor returns true if sending is successful. 74 type GetBlockHeaders struct { 75 ToWhom types.PeerID 76 // Hash is the first block to get. Height will be used when Hash mi empty 77 Hash BlockHash 78 Height uint64 79 Asc bool 80 Offset uint64 81 MaxSize uint32 82 } 83 84 // BlockHeadersResponse is data from other peer, as a response of types.GetBlockRequest 85 // p2p module will send this to chainservice actor. 86 type BlockHeadersResponse struct { 87 Hashes []BlockHash 88 Headers []*types.BlockHeader 89 } 90 91 // GetBlockInfos send types.GetBlockRequest to dest peer. 92 // The actor returns true if sending is successful. 93 type GetBlockInfos struct { 94 ToWhom types.PeerID 95 Hashes []BlockHash 96 } 97 98 type GetBlockChunks struct { 99 Seq uint64 100 GetBlockInfos 101 TTL time.Duration 102 } 103 104 // BlockInfosResponse is data from other peer, as a response of types.GetBlockRequest 105 // p2p module will send this to chainservice actor. 106 type BlockInfosResponse struct { 107 FromWhom types.PeerID 108 Blocks []*types.Block 109 } 110 111 type GetBlockChunksRsp struct { 112 Seq uint64 113 ToWhom types.PeerID 114 Blocks []*types.Block 115 Err error 116 } 117 118 // GetPeers requests p2p actor to get remote peers that is connected. 119 // The actor returns *GetPeersRsp 120 type GetPeers struct { 121 NoHidden bool 122 ShowSelf bool 123 } 124 125 type PeerInfo struct { 126 Addr *types.PeerAddress 127 Version string 128 Hidden bool 129 CheckTime time.Time 130 LastBlockHash []byte 131 LastBlockNumber uint64 132 State types.PeerState 133 Self bool 134 } 135 136 // GetPeersRsp contains peer meta information and current states. 137 type GetPeersRsp struct { 138 Peers []*PeerInfo 139 } 140 141 type GetMetrics struct { 142 } 143 144 // GetSyncAncestor is sent from Syncer, send types.GetAncestorRequest to dest peer. 145 type GetSyncAncestor struct { 146 Seq uint64 147 ToWhom types.PeerID 148 Hashes [][]byte 149 } 150 151 // GetSyncAncestorRsp is data from other peer, as a response of types.GetAncestorRequest 152 type GetSyncAncestorRsp struct { 153 Seq uint64 154 Ancestor *types.BlockInfo 155 } 156 157 type GetHashes struct { 158 Seq uint64 159 ToWhom types.PeerID 160 PrevInfo *types.BlockInfo 161 Count uint64 162 } 163 164 type GetHashesRsp struct { 165 Seq uint64 166 PrevInfo *types.BlockInfo 167 Hashes []BlockHash 168 Count uint64 169 Err error 170 } 171 172 type GetHashByNo struct { 173 Seq uint64 174 ToWhom types.PeerID 175 BlockNo types.BlockNo 176 } 177 178 type GetHashByNoRsp struct { 179 Seq uint64 180 BlockHash BlockHash 181 Err error 182 } 183 184 type GetSelf struct { 185 } 186 187 type GetCluster struct { 188 BestBlockHash BlockHash 189 ReplyC chan *GetClusterRsp 190 } 191 192 type GetClusterRsp struct { 193 ClusterID uint64 194 ChainID BlockHash 195 Members []*types.MemberAttr 196 Err error 197 HardStateInfo *types.HardStateInfo 198 } 199 200 type GetRaftTransport struct { 201 Cluster interface{} 202 } 203 204 type RaftClusterEvent struct { 205 BPAdded []types.PeerID 206 BPRemoved []types.PeerID 207 } 208 209 // ChangeDesignatedPeers will trigger connect or disconnect peers 210 type ChangeDesignatedPeers struct { 211 Add []types.PeerAddress 212 Remove []types.PeerID 213 } 214 215 type SendRaft struct { 216 ToWhom types.PeerID 217 Body interface{} // for avoiding dependency cycle, though it must be raftpb.Message. 218 } 219 220 type SendRaftRsp struct { 221 Err error 222 } 223 224 type P2PWhiteListConfEnableEvent struct { 225 Name string 226 On bool 227 } 228 229 type P2PWhiteListConfSetEvent struct { 230 Name string 231 Values []string 232 }