Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
P2P:support circuit config
Browse files Browse the repository at this point in the history
  • Loading branch information
lochjin committed Sep 6, 2021
1 parent 78bdf87 commit 50a125e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type Config struct {
Whitelist []string `long:"whitelist" description:"Add an IP network or IP,PeerID that will not be banned or ignore dual channel mode detection. (eg. 192.168.1.0/24 or ::1 or [peer id])"`
Blacklist []string `long:"blacklist" description:"Add some IP network or IP that will be banned. (eg. 192.168.1.0/24 or ::1)"`
MaxBadResp int `long:"maxbadresp" description:"maxbadresp is the maximum number of bad responses from a peer before we stop talking to it."`
Circuit bool `long:"circuit" description:"All peers will ignore dual channel mode detection"`
}

func (c *Config) GetMinningAddrs() []types.Address {
Expand Down
1 change: 1 addition & 0 deletions p2p/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ type Config struct {
Banning bool // Open or not ban module
DisableListen bool
LANPeers []string
IsCircuit bool
}
1 change: 1 addition & 0 deletions p2p/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ func NewService(cfg *config.Config, events *event.Feed, param *params.Params) (*
Banning: cfg.Banning,
DisableListen: cfg.DisableListen,
LANPeers: lanPeers,
IsCircuit: cfg.Circuit,
},
ctx: ctx,
cancel: cancel,
Expand Down
10 changes: 6 additions & 4 deletions p2p/synch/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,18 @@ func (s *Sync) bidirectionalChannelCapacity(pe *peers.Peer, conn network.Conn) b
pe.SetBidChanCap(time.Now())
return true
}
if s.p2p.Config().IsCircuit || s.IsWhitePeer(pe.GetID()) {
pe.SetBidChanCap(time.Now())
return true
}

bidChanLife := pe.GetBidChanCap()
if !bidChanLife.IsZero() {
if time.Since(bidChanLife) < timeForBidirChanLife {
return true
}
}
if s.IsWhitePeer(pe.GetID()) {
pe.SetBidChanCap(time.Time{})
return true
}

//
peAddr := conn.RemoteMultiaddr()
ipAddr := ""
Expand Down

0 comments on commit 50a125e

Please sign in to comment.