fix: only block and log if we are actually blocking, and make it all debug messages

This commit is contained in:
Derrick Hammer 2024-01-15 13:19:46 -05:00
parent d76bfc6daf
commit 5e80831335
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 27 additions and 9 deletions

View File

@ -190,28 +190,37 @@ func (p *P2PImpl) ConnectToNode(connectionUris []*url.URL, retried bool, fromPee
} }
if p.outgoingPeerBlocklist.Contains(idString) { if p.outgoingPeerBlocklist.Contains(idString) {
p.logger.Error("outgoing peer is on blocklist", zap.String("node", connectionUri.String())) p.logger.Debug("outgoing peer is on blocklist", zap.String("node", connectionUri.String()))
var fromPeerId string var fromPeerId string
if fromPeer != nil { if fromPeer != nil {
blocked := false
if fromPeer.Id() != nil { if fromPeer.Id() != nil {
fromPeerId, err = fromPeer.Id().ToString() fromPeerId, err = fromPeer.Id().ToString()
if err != nil { if err != nil {
return err return err
} }
if !p.incomingPeerBlockList.Contains(fromPeerId) {
p.incomingPeerBlockList.Put(fromPeerId, true) p.incomingPeerBlockList.Put(fromPeerId, true)
blocked = true
}
} }
fromPeerIP := fromPeer.GetIP() fromPeerIP := fromPeer.GetIP()
if !p.incomingIPBlocklist.Contains(fromPeerIP) {
p.incomingIPBlocklist.Put(fromPeerIP, true) p.incomingIPBlocklist.Put(fromPeerIP, true)
blocked = true
}
err = fromPeer.End() err = fromPeer.End()
if err != nil { if err != nil {
return err return err
} }
p.logger.Info("blocking peer for sending peer on blocklist", zap.String("node", connectionUri.String()), zap.String("peer", fromPeerId), zap.String("ip", fromPeerIP)) if blocked {
p.logger.Debug("blocking peer for sending peer on blocklist", zap.String("node", connectionUri.String()), zap.String("peer", fromPeerId), zap.String("ip", fromPeerIP))
}
} }
return nil return nil
} }
@ -235,7 +244,7 @@ func (p *P2PImpl) ConnectToNode(connectionUris []*url.URL, retried bool, fromPee
counter := uint(0) counter := uint(0)
if p.outgoingPeerFailures.Contains(idString) { if p.outgoingPeerFailures.Contains(idString) {
tmp := *p.outgoingPeerFailures.GetUInt(idString) tmp := *p.outgoingPeerFailures.GetUInt(idString)
counter = uint(tmp) counter = tmp
} }
counter++ counter++
@ -245,26 +254,35 @@ func (p *P2PImpl) ConnectToNode(connectionUris []*url.URL, retried bool, fromPee
if counter >= p.maxOutgoingPeerFailures { if counter >= p.maxOutgoingPeerFailures {
if fromPeer != nil { if fromPeer != nil {
blocked := false
var fromPeerId string var fromPeerId string
if fromPeer.Id() != nil { if fromPeer.Id() != nil {
fromPeerId, err = fromPeer.Id().ToString() fromPeerId, err = fromPeer.Id().ToString()
if err != nil { if err != nil {
return err return err
} }
if !p.incomingPeerBlockList.Contains(fromPeerId) {
p.incomingPeerBlockList.Put(fromPeerId, true) p.incomingPeerBlockList.Put(fromPeerId, true)
blocked = true
}
} }
fromPeerIP := fromPeer.GetIP() fromPeerIP := fromPeer.GetIP()
if !p.incomingIPBlocklist.Contains(fromPeerIP) {
p.incomingIPBlocklist.Put(fromPeerIP, true) p.incomingIPBlocklist.Put(fromPeerIP, true)
blocked = true
}
err = fromPeer.End() err = fromPeer.End()
if err != nil { if err != nil {
return err return err
} }
p.logger.Info("blocking peer for sending peer on blocklist", zap.String("node", connectionUri.String()), zap.String("peer", fromPeerId), zap.String("ip", fromPeerIP)) if blocked {
p.logger.Debug("blocking peer for sending peer on blocklist", zap.String("node", connectionUri.String()), zap.String("peer", fromPeerId), zap.String("ip", fromPeerIP))
}
} }
p.outgoingPeerBlocklist.Put(idString, true) p.outgoingPeerBlocklist.Put(idString, true)
p.logger.Info("blocking peer for too many failures", zap.String("node", connectionUri.String())) p.logger.Debug("blocking peer for too many failures", zap.String("node", connectionUri.String()))
} }
return nil return nil