• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revision91fc4aacc4a828fb6b8b34e1082e1acf94c1f46a (tree)
Time2019-07-10 20:36:11
AuthorYahtoo Ma <yahtoo.ma@gmai...>
CommiterYahtoo Ma

Log Message

fix ban node failed

Change Summary

Incremental Difference

--- a/netsync/chainmgr/tool_test.go
+++ b/netsync/chainmgr/tool_test.go
@@ -48,6 +48,10 @@ func (p *P2PPeer) IsLAN() bool {
4848 return false
4949 }
5050
51+func (p *P2PPeer) RemoteAddrHost() string {
52+ return ""
53+}
54+
5155 func (p *P2PPeer) ServiceFlag() consensus.ServiceFlag {
5256 return p.flag
5357 }
@@ -89,7 +93,7 @@ func NewPeerSet() *PeerSet {
8993 return &PeerSet{}
9094 }
9195
92-func (ps *PeerSet) IsBanned(peerID string, level byte, reason string) bool {
96+func (ps *PeerSet) IsBanned(ip string, level byte, reason string) bool {
9397 return false
9498 }
9599
--- a/netsync/consensusmgr/block_fetcher_test.go
+++ b/netsync/consensusmgr/block_fetcher_test.go
@@ -12,7 +12,7 @@ import (
1212 type peerMgr struct {
1313 }
1414
15-func (pm *peerMgr) IsBanned(peerID string, level byte, reason string) bool {
15+func (pm *peerMgr) IsBanned(ip string, level byte, reason string) bool {
1616 return false
1717 }
1818
--- a/netsync/peers/peer.go
+++ b/netsync/peers/peer.go
@@ -36,6 +36,7 @@ var (
3636 type BasePeer interface {
3737 Addr() net.Addr
3838 ID() string
39+ RemoteAddrHost() string
3940 ServiceFlag() consensus.ServiceFlag
4041 TrafficStatus() (*flowrate.Status, *flowrate.Status)
4142 TrySend(byte, interface{}) bool
@@ -45,7 +46,7 @@ type BasePeer interface {
4546 //BasePeerSet is the intergace for connection level peer manager
4647 type BasePeerSet interface {
4748 StopPeerGracefully(string)
48- IsBanned(peerID string, level byte, reason string) bool
49+ IsBanned(ip string, level byte, reason string) bool
4950 }
5051
5152 type BroadcastMsg interface {
@@ -417,7 +418,8 @@ func (ps *PeerSet) ProcessIllegal(peerID string, level byte, reason string) {
417418 if peer == nil {
418419 return
419420 }
420- if banned := ps.IsBanned(peer.Addr().String(), level, reason); banned {
421+
422+ if banned := ps.IsBanned(peer.RemoteAddrHost(), level, reason); banned {
421423 ps.RemovePeer(peerID)
422424 }
423425 return
--- a/p2p/node_info.go
+++ b/p2p/node_info.go
@@ -86,7 +86,7 @@ func (info NodeInfo) listenHost() string {
8686 }
8787
8888 //remoteAddrHost peer external ip address
89-func (info NodeInfo) remoteAddrHost() string {
89+func (info NodeInfo) RemoteAddrHost() string {
9090 host, _, _ := net.SplitHostPort(info.RemoteAddr)
9191 return host
9292 }
--- a/p2p/switch.go
+++ b/p2p/switch.go
@@ -19,8 +19,8 @@ import (
1919 "github.com/vapor/p2p/discover/dht"
2020 "github.com/vapor/p2p/discover/mdns"
2121 "github.com/vapor/p2p/netutil"
22- "github.com/vapor/p2p/signlib"
2322 security "github.com/vapor/p2p/security"
23+ "github.com/vapor/p2p/signlib"
2424 "github.com/vapor/version"
2525 )
2626
@@ -199,7 +199,7 @@ func (sw *Switch) AddPeer(pc *peerConn, isLAN bool) error {
199199 }
200200
201201 peer := newPeer(pc, peerNodeInfo, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError, isLAN)
202- if err := sw.security.DoFilter(peer.remoteAddrHost(), peer.PubKey()); err != nil {
202+ if err := sw.security.DoFilter(peer.RemoteAddrHost(), peer.PubKey()); err != nil {
203203 return err
204204 }
205205
@@ -419,7 +419,7 @@ func (sw *Switch) dialPeerWorker(a *NetAddress, wg *sync.WaitGroup) {
419419 func (sw *Switch) dialPeers(addresses []*NetAddress) {
420420 connectedPeers := make(map[string]struct{})
421421 for _, peer := range sw.Peers().List() {
422- connectedPeers[peer.remoteAddrHost()] = struct{}{}
422+ connectedPeers[peer.RemoteAddrHost()] = struct{}{}
423423 }
424424
425425 var wg sync.WaitGroup
Show on old repository browser