github.com/klaytn/klaytn@v1.12.1/consensus/protocol.go (about) 1 // Modifications Copyright 2018 The klaytn Authors 2 // Copyright 2017 The go-ethereum Authors 3 // This file is part of the go-ethereum library. 4 // 5 // The go-ethereum library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-ethereum library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from quorum/consensus/protocol.go (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 package consensus 22 23 import ( 24 "github.com/klaytn/klaytn/blockchain/types" 25 "github.com/klaytn/klaytn/common" 26 "github.com/klaytn/klaytn/networks/p2p" 27 ) 28 29 // Constants to match up protocol versions and messages 30 const ( 31 Klay62 = 62 32 Klay63 = 63 33 Klay64 = 64 34 Klay65 = 65 35 ) 36 37 var KlayProtocol = Protocol{ 38 Name: "klay", 39 Versions: []uint{Klay65, Klay64, Klay63, Klay62}, 40 Lengths: []uint64{21, 19, 17, 8}, 41 } 42 43 // Protocol defines the protocol of the consensus 44 type Protocol struct { 45 // Official short name of the protocol used during capability negotiation. 46 Name string 47 // Supported versions of the klaytn protocol (first is primary). 48 Versions []uint 49 // Number of implemented message corresponding to different protocol versions. 50 Lengths []uint64 51 } 52 53 // istanbul BFT 54 // Broadcaster defines the interface to enqueue blocks to fetcher and find peer 55 type Broadcaster interface { 56 // Enqueue add a block into fetcher queue 57 Enqueue(id string, block *types.Block) 58 // FindPeers retrives peers by addresses 59 FindPeers(map[common.Address]bool) map[common.Address]Peer 60 61 FindCNPeers(map[common.Address]bool) map[common.Address]Peer 62 63 GetCNPeers() map[common.Address]Peer 64 65 GetENPeers() map[common.Address]Peer 66 67 RegisterValidator(conType common.ConnType, validator p2p.PeerTypeValidator) 68 } 69 70 // Peer defines the interface to communicate with peer 71 type Peer interface { 72 // Send sends the message to this peer 73 Send(msgcode uint64, data interface{}) error 74 75 // RegisterConsensusMsgCode registers the channel of consensus msg. 76 RegisterConsensusMsgCode(msgCode uint64) error 77 }