Official Go implementation of the Bytom protocol
Revision | da4f422a72ec7b693d2792ba6af7aa797ab16819 (tree) |
---|---|
Time | 2019-08-16 13:35:18 |
Author | Yahtoo Ma <yahtoo.ma@gmai...> |
Commiter | Yahtoo Ma |
fix ban node failed
@@ -25,6 +25,7 @@ const ( | ||
25 | 25 | type BasePeer interface { |
26 | 26 | Addr() net.Addr |
27 | 27 | ID() string |
28 | + RemoteAddrHost() string | |
28 | 29 | ServiceFlag() consensus.ServiceFlag |
29 | 30 | TrafficStatus() (*flowrate.Status, *flowrate.Status) |
30 | 31 | TrySend(byte, interface{}) bool |
@@ -34,7 +35,7 @@ type BasePeer interface { | ||
34 | 35 | //BasePeerSet is the intergace for connection level peer manager |
35 | 36 | type BasePeerSet interface { |
36 | 37 | StopPeerGracefully(string) |
37 | - IsBanned(peerID string, level byte, reason string) bool | |
38 | + IsBanned(ip string, level byte, reason string) bool | |
38 | 39 | } |
39 | 40 | |
40 | 41 | // PeerInfo indicate peer status snap |
@@ -312,7 +313,7 @@ func (ps *peerSet) ProcessIllegal(peerID string, level byte, reason string) { | ||
312 | 313 | if peer == nil { |
313 | 314 | return |
314 | 315 | } |
315 | - if banned := ps.IsBanned(peer.Addr().String(), level, reason); banned { | |
316 | + if banned := ps.IsBanned(peer.RemoteAddrHost(), level, reason); banned { | |
316 | 317 | ps.removePeer(peerID) |
317 | 318 | } |
318 | 319 | return |
@@ -48,6 +48,10 @@ func (p *P2PPeer) IsLAN() bool { | ||
48 | 48 | return false |
49 | 49 | } |
50 | 50 | |
51 | +func (p *P2PPeer) RemoteAddrHost() string { | |
52 | + return "" | |
53 | +} | |
54 | + | |
51 | 55 | func (p *P2PPeer) ServiceFlag() consensus.ServiceFlag { |
52 | 56 | return p.flag |
53 | 57 | } |
@@ -89,7 +93,7 @@ func NewPeerSet() *PeerSet { | ||
89 | 93 | return &PeerSet{} |
90 | 94 | } |
91 | 95 | |
92 | -func (ps *PeerSet) IsBanned(peerID string, level byte, reason string) bool { | |
96 | +func (ps *PeerSet) IsBanned(ip string, level byte, reason string) bool { | |
93 | 97 | return false |
94 | 98 | } |
95 | 99 |
@@ -78,7 +78,7 @@ func (info *NodeInfo) listenHost() string { | ||
78 | 78 | } |
79 | 79 | |
80 | 80 | //RemoteAddrHost peer external ip address |
81 | -func (info *NodeInfo) remoteAddrHost() string { | |
81 | +func (info *NodeInfo) RemoteAddrHost() string { | |
82 | 82 | host, _, _ := net.SplitHostPort(info.RemoteAddr) |
83 | 83 | return host |
84 | 84 | } |
@@ -197,7 +197,7 @@ func (sw *Switch) AddPeer(pc *peerConn, isLAN bool) error { | ||
197 | 197 | } |
198 | 198 | |
199 | 199 | peer := newPeer(pc, peerNodeInfo, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError, isLAN) |
200 | - if err := sw.security.DoFilter(peer.remoteAddrHost(), peer.PubKey().String()); err != nil { | |
200 | + if err := sw.security.DoFilter(peer.RemoteAddrHost(), peer.PubKey().String()); err != nil { | |
201 | 201 | return err |
202 | 202 | } |
203 | 203 |
@@ -423,7 +423,7 @@ func (sw *Switch) dialPeerWorker(a *NetAddress, wg *sync.WaitGroup) { | ||
423 | 423 | func (sw *Switch) dialPeers(addresses []*NetAddress) { |
424 | 424 | connectedPeers := make(map[string]struct{}) |
425 | 425 | for _, peer := range sw.Peers().List() { |
426 | - connectedPeers[peer.remoteAddrHost()] = struct{}{} | |
426 | + connectedPeers[peer.RemoteAddrHost()] = struct{}{} | |
427 | 427 | } |
428 | 428 | |
429 | 429 | var wg sync.WaitGroup |