github.com/theQRL/go-zond@v0.2.1/zond/handler_zond.go (about) 1 // Copyright 2020 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package zond 18 19 import ( 20 "fmt" 21 22 "github.com/theQRL/go-zond/core" 23 "github.com/theQRL/go-zond/p2p/enode" 24 "github.com/theQRL/go-zond/zond/protocols/zond" 25 ) 26 27 // zondHandler implements the zond.Backend interface to handle the various network 28 // packets that are sent as replies or broadcasts. 29 type zondHandler handler 30 31 func (h *zondHandler) Chain() *core.BlockChain { return h.chain } 32 func (h *zondHandler) TxPool() zond.TxPool { return h.txpool } 33 34 // RunPeer is invoked when a peer joins on the `zond` protocol. 35 func (h *zondHandler) RunPeer(peer *zond.Peer, hand zond.Handler) error { 36 return (*handler)(h).runZondPeer(peer, hand) 37 } 38 39 // PeerInfo retrieves all known `zond` information about a peer. 40 func (h *zondHandler) PeerInfo(id enode.ID) interface{} { 41 if p := h.peers.peer(id.String()); p != nil { 42 return p.info() 43 } 44 return nil 45 } 46 47 // AcceptTxs retrieves whether transaction processing is enabled on the node 48 // or if inbound transactions should simply be dropped. 49 func (h *zondHandler) AcceptTxs() bool { 50 return h.synced.Load() 51 } 52 53 // Handle is invoked from a peer's message handler when it receives a new remote 54 // message that the handler couldn't consume and serve itself. 55 func (h *zondHandler) Handle(peer *zond.Peer, packet zond.Packet) error { 56 // Consume any broadcasts and announces, forwarding the rest to the downloader 57 switch packet := packet.(type) { 58 case *zond.NewPooledTransactionHashesPacket: 59 return h.txFetcher.Notify(peer.ID(), packet.Types, packet.Sizes, packet.Hashes) 60 61 case *zond.TransactionsPacket: 62 return h.txFetcher.Enqueue(peer.ID(), *packet, false) 63 64 case *zond.PooledTransactionsResponse: 65 return h.txFetcher.Enqueue(peer.ID(), *packet, true) 66 67 default: 68 return fmt.Errorf("unexpected zond packet type: %T", packet) 69 } 70 }