github.com/annchain/OG@v0.0.9/og/message_router.go (about) 1 //// Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 //// 3 //// Licensed under the Apache License, Version 2.0 (the "License"); 4 //// you may not use this file except in compliance with the License. 5 //// You may obtain a copy of the License at 6 //// 7 //// http://www.apache.org/licenses/LICENSE-2.0 8 //// 9 //// Unless required by applicable law or agreed to in writing, software 10 //// distributed under the License is distributed on an "AS IS" BASIS, 11 //// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 //// See the License for the specific language governing permissions and 13 //// limitations under the License. 14 package og 15 16 // 17 //import ( 18 // "github.com/annchain/OG/common" 19 // "github.com/annchain/OG/consensus/bft" 20 // "github.com/annchain/OG/og/types" 21 // "github.com/annchain/OG/og/types/archive" 22 //) 23 // 24 //// messageRouter is a bridge between hub and components 25 //type messageRouter struct { 26 // Hub *Hub 27 // PingHandler PingHandler 28 // PongHandler PongHandler 29 // FetchByHashRequestHandler FetchByHashHandlerRequest 30 // FetchByHashResponseHandler FetchByHashResponseHandler 31 // NewTxHandler NewTxHandler 32 // NewTxsHandler NewTxsHandler 33 // NewSequencerHandler NewSequencerHandler 34 // GetMsgHandler GetMsgHandler 35 // ControlMsgHandler ControlMsgHandler 36 // SequencerHeaderHandler SequencerHeaderHandler 37 // BodiesRequestHandler BodiesRequestHandler 38 // BodiesResponseHandler BodiesResponseHandler 39 // TxsRequestHandler TxsRequestHandler 40 // TxsResponseHandler TxsResponseHandler 41 // HeaderRequestHandler HeaderRequestHandler 42 // HeaderResponseHandler HeaderResponseHandler 43 // CampaignHandler CampaignHandler 44 // TermChangeHandler TermChangeHandler 45 // ArchiveHandler ArchiveHandler 46 // ActionTxHandler ActionTxHandler 47 // ConsensusDkgDealHandler ConsensusDkgDealHandler 48 // ConsensusDkgDealResponseHandler ConsensusDkgDealResponseHandler 49 // ConsensusDkgSigSetsHandler ConsensusDkgSigSetsHandler 50 // ConsensusDkgGenesisPublicKeyHandler ConsensusDkgGenesisPublicKeyHandler 51 // ConsensusHandler ConsensusHandler 52 // TermChangeRequestHandler TermChangeRequestHandler 53 // TermChangeResponseHandler TermChangeResponseHandler 54 //} 55 // 56 //type ManagerConfig struct { 57 // AcquireTxQueueSize uint // length of the channel for tx acquiring 58 // BatchAcquireSize uint // length of the buffer for batch tx acquire for a single node 59 //} 60 // 61 //type PingHandler interface { 62 // HandlePing(peerId string) 63 //} 64 //type PongHandler interface { 65 // HandlePong() 66 //} 67 // 68 //type FetchByHashHandlerRequest interface { 69 // HandleFetchByHashRequest(req *p2p_message.MessageSyncRequest, sourceID string) 70 //} 71 // 72 //type FetchByHashResponseHandler interface { 73 // HandleFetchByHashResponse(resp *p2p_message.MessageSyncResponse, sourceID string) 74 //} 75 // 76 //type NewTxHandler interface { 77 // HandleNewTx(msg *p2p_message.MessageNewTx, peerId string) 78 //} 79 // 80 //type GetMsgHandler interface { 81 // HandleGetMsg(msg *p2p_message.MessageGetMsg, peerId string) 82 //} 83 // 84 //type ControlMsgHandler interface { 85 // HandleControlMsg(msg *archive.MessageControl, peerId string) 86 //} 87 // 88 //type NewTxsHandler interface { 89 // HandleNewTxs(newTxs *archive.MessageNewTxs, peerId string) 90 //} 91 // 92 //type NewSequencerHandler interface { 93 // HandleNewSequencer(msg *archive.MessageNewSequencer, peerId string) 94 //} 95 // 96 //type SequencerHeaderHandler interface { 97 // HandleSequencerHeader(msgHeader *archive.MessageSequencerHeader, peerId string) 98 //} 99 // 100 //type BodiesRequestHandler interface { 101 // HandleBodiesRequest(msgReq *archive.MessageBodiesRequest, peerID string) 102 //} 103 // 104 //type BodiesResponseHandler interface { 105 // HandleBodiesResponse(request *archive.MessageBodiesResponse, peerId string) 106 //} 107 // 108 //type TxsRequestHandler interface { 109 // HandleTxsRequest(msgReq *archive.MessageTxsRequest, peerID string) 110 //} 111 // 112 //type TxsResponseHandler interface { 113 // HandleTxsResponse(request *archive.MessageTxsResponse) 114 //} 115 // 116 //type HeaderRequestHandler interface { 117 // HandleHeaderRequest(request *archive.MessageHeaderRequest, peerID string) 118 //} 119 // 120 //type HeaderResponseHandler interface { 121 // HandleHeaderResponse(headerMsg *archive.MessageHeaderResponse, peerID string) 122 //} 123 // 124 //type CampaignHandler interface { 125 // HandleCampaign(request *types.MessageCampaign, peerId string) 126 //} 127 // 128 //type TermChangeHandler interface { 129 // HandleTermChange(request *types.MessageTermChange, peerId string) 130 //} 131 // 132 //type ArchiveHandler interface { 133 // HandleArchive(request *types.MessageNewArchive, peerId string) 134 //} 135 // 136 //type ActionTxHandler interface { 137 // HandleActionTx(request *archive.MessageNewActionTx, perid string) 138 //} 139 // 140 //type ConsensusDkgDealHandler interface { 141 // HandleConsensusDkgDeal(request *types.MessageConsensusDkgDeal, peerId string) 142 //} 143 // 144 //type ConsensusDkgDealResponseHandler interface { 145 // HandleConsensusDkgDealResponse(request *types.MessageConsensusDkgDealResponse, peerId string) 146 //} 147 // 148 //type ConsensusDkgSigSetsHandler interface { 149 // HandleConsensusDkgSigSets(request *types.MessageConsensusDkgSigSets, peerId string) 150 //} 151 // 152 //type ConsensusDkgGenesisPublicKeyHandler interface { 153 // HandleConsensusDkgGenesisPublicKey(request *types.MessageConsensusDkgGenesisPublicKey, peerId string) 154 //} 155 //type ConsensusHandler interface { 156 // HandleConsensus(request bft.BftMessage, peerId string) 157 //} 158 //type TermChangeRequestHandler interface { 159 // HandleTermChangeRequest(request *types.MessageTermChangeRequest, peerId string) 160 //} 161 //type TermChangeResponseHandler interface { 162 // HandleTermChangeResponse(request *types.MessageTermChangeResponse, peerId string) 163 //} 164 // 165 //func (m *messageRouter) Start() { 166 // m.Hub.BroadcastMessage(message.MessageTypePing, &archive.MessagePing{Data: []byte{}}) 167 //} 168 // 169 //func (m *messageRouter) Stop() { 170 // 171 //} 172 // 173 //func (m *messageRouter) Name() string { 174 // return "messageRouter" 175 //} 176 // 177 //func (m *messageRouter) RoutePing(msg *types) { 178 // m.PingHandler.HandlePing(msg.SourceID) 179 //} 180 // 181 //func (m *messageRouter) RoutePong(*types) { 182 // m.PongHandler.HandlePong() 183 //} 184 //func (m *messageRouter) RouteFetchByHashRequest(msg *types) { 185 // m.FetchByHashRequestHandler.HandleFetchByHashRequest(msg.Message.(*archive.MessageSyncRequest), msg.SourceID) 186 //} 187 // 188 //func (m *messageRouter) RouteFetchByHashResponse(msg *types) { 189 // m.FetchByHashResponseHandler.HandleFetchByHashResponse(msg.Message.(*archive.MessageSyncResponse), msg.SourceID) 190 //} 191 // 192 //func (m *messageRouter) RouteNewTx(msg *types) { 193 // m.NewTxHandler.HandleNewTx(msg.Message.(*archive.MessageNewTx), msg.SourceID) 194 //} 195 // 196 //func (m *messageRouter) RouteNewTxs(msg *types) { 197 // //maybe received more transactions 198 // m.NewTxsHandler.HandleNewTxs(msg.Message.(*archive.MessageNewTxs), msg.SourceID) 199 //} 200 // 201 //func (m *messageRouter) RouteNewSequencer(msg *types) { 202 // m.NewSequencerHandler.HandleNewSequencer(msg.Message.(*archive.MessageNewSequencer), msg.SourceID) 203 //} 204 // 205 //func (m *messageRouter) RouteGetMsg(msg *types) { 206 // m.GetMsgHandler.HandleGetMsg(msg.Message.(*archive.MessageGetMsg), msg.SourceID) 207 //} 208 // 209 //func (m *messageRouter) RouteControlMsg(msg *types) { 210 // m.ControlMsgHandler.HandleControlMsg(msg.Message.(*archive.MessageControl), msg.SourceID) 211 //} 212 // 213 //func (m *messageRouter) RouteSequencerHeader(msg *types) { 214 // m.SequencerHeaderHandler.HandleSequencerHeader(msg.Message.(*archive.MessageSequencerHeader), msg.SourceID) 215 //} 216 //func (m *messageRouter) RouteBodiesRequest(msg *types) { 217 // 218 // m.BodiesRequestHandler.HandleBodiesRequest(msg.Message.(*archive.MessageBodiesRequest), msg.SourceID) 219 //} 220 // 221 //func (m *messageRouter) RouteBodiesResponse(msg *types) { 222 // // A batch of block bodies arrived to one of our previous requests 223 // m.BodiesResponseHandler.HandleBodiesResponse(msg.Message.(*archive.MessageBodiesResponse), msg.SourceID) 224 //} 225 // 226 //func (m *messageRouter) RouteTxsRequest(msg *types) { 227 // // Decode the retrieval Message 228 // m.TxsRequestHandler.HandleTxsRequest(msg.Message.(*archive.MessageTxsRequest), msg.SourceID) 229 // 230 //} 231 //func (m *messageRouter) RouteTxsResponse(msg *types) { 232 // // A batch of block bodies arrived to one of our previous requests 233 // m.TxsResponseHandler.HandleTxsResponse(msg.Message.(*archive.MessageTxsResponse)) 234 // 235 //} 236 //func (m *messageRouter) RouteHeaderRequest(msg *types) { 237 // // Decode the complex header query 238 // m.HeaderRequestHandler.HandleHeaderRequest(msg.Message.(*archive.MessageHeaderRequest), msg.SourceID) 239 //} 240 // 241 //func (m *messageRouter) RouteHeaderResponse(msg *types) { 242 // // A batch of headers arrived to one of our previous requests 243 // m.HeaderResponseHandler.HandleHeaderResponse(msg.Message.(*archive.MessageHeaderResponse), msg.SourceID) 244 //} 245 // 246 //func (m *messageRouter) RouteCampaign(msg *types) { 247 // // A batch of headers arrived to one of our previous requests 248 // m.CampaignHandler.HandleCampaign(msg.Message.(*types.MessageCampaign), msg.SourceID) 249 //} 250 // 251 //func (m *messageRouter) RouteTermChange(msg *types) { 252 // m.TermChangeHandler.HandleTermChange(msg.Message.(*types.MessageTermChange), msg.SourceID) 253 //} 254 // 255 //func (m *messageRouter) RouteArchive(msg *types) { 256 // m.ArchiveHandler.HandleArchive(msg.Message.(*types.MessageNewArchive), msg.SourceID) 257 //} 258 // 259 //func (m *messageRouter) RouteActionTx(msg *types) { 260 // m.ActionTxHandler.HandleActionTx(msg.Message.(*archive.MessageNewActionTx), msg.SourceID) 261 //} 262 // 263 //func (m *messageRouter) RouteConsensusDkgDeal(msg *types) { 264 // m.ConsensusDkgDealHandler.HandleConsensusDkgDeal(msg.Message.(*types.MessageConsensusDkgDeal), msg.SourceID) 265 //} 266 // 267 //func (m *messageRouter) RouteConsensusDkgDealResponse(msg *types) { 268 // m.ConsensusDkgDealResponseHandler.HandleConsensusDkgDealResponse(msg.Message.(*types.MessageConsensusDkgDealResponse), msg.SourceID) 269 //} 270 // 271 //func (m *messageRouter) RouteConsensusDkgSigSets(msg *types) { 272 // m.ConsensusDkgSigSetsHandler.HandleConsensusDkgSigSets(msg.Message.(*types.MessageConsensusDkgSigSets), msg.SourceID) 273 //} 274 // 275 //func (m *messageRouter) RouteConsensusDkgGenesisPublicKey(msg *types) { 276 // m.ConsensusDkgGenesisPublicKeyHandler.HandleConsensusDkgGenesisPublicKey(msg.Message.(*types.MessageConsensusDkgGenesisPublicKey), msg.SourceID) 277 //} 278 // 279 //func (m *messageRouter) RouteTermChangeRequest(msg *types) { 280 // m.TermChangeRequestHandler.HandleTermChangeRequest(msg.Message.(*types.MessageTermChangeRequest), msg.SourceID) 281 //} 282 // 283 //func (m *messageRouter) RouteTermChangeResponse(msg *types) { 284 // m.TermChangeResponseHandler.HandleTermChangeResponse(msg.Message.(*types.MessageTermChangeResponse), msg.SourceID) 285 //} 286 // 287 //// BroadcastMessage send Message to all peers 288 //func (m *messageRouter) BroadcastMessage(messageType message.BinaryMessageType, message types.Message) { 289 // m.Hub.BroadcastMessage(messageType, message) 290 //} 291 // 292 //// MulticastMessage send Message to a randomly chosen peer 293 //func (m *messageRouter) MulticastMessage(messageType message.BinaryMessageType, message types.Message) { 294 // m.Hub.MulticastMessage(messageType, message) 295 //} 296 // 297 //func (m *messageRouter) MulticastToSource(messageType message.BinaryMessageType, message types.Message, sourceMsgHash *common.Hash) { 298 // m.Hub.MulticastToSource(messageType, message, sourceMsgHash) 299 //} 300 // 301 //func (m *messageRouter) BroadcastMessageWithLink(messageType message.BinaryMessageType, message types.Message) { 302 // m.Hub.BroadcastMessageWithLink(messageType, message) 303 //} 304 // 305 //func (m *messageRouter) SendToPeer(peerId string, messageType message.BinaryMessageType, msg types.Message) { 306 // err := m.Hub.SendToPeer(peerId, messageType, msg) 307 // if err != nil { 308 // message.msgLog.WithError(err).Warn("send failed") 309 // } 310 //}