Do not ban client if it's the same peer

This commit is contained in:
DataHoarder 2023-04-23 17:21:10 +02:00
parent d267716c25
commit 34fc5cedf5
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -117,15 +117,17 @@ func (c *Client) BanError() error {
return c.banError
}
func (c *Client) SetError(err error) {
c.banErrorLock.Lock()
c.banErrorLock.Unlock()
if c.banError == nil {
c.banError = err
}
}
func (c *Client) Ban(duration time.Duration, err error) {
func() {
c.banErrorLock.Lock()
c.banErrorLock.Unlock()
if c.banError == nil {
c.banError = err
}
}()
c.SetError(err)
c.Owner.Ban(c.AddressPort.Addr(), duration, err)
c.Owner.RemoveFromPeerList(c.AddressPort.Addr())
c.Close()
@ -377,6 +379,8 @@ func (c *Client) OnConnection() {
}
return false, nil
}(); ok {
c.HandshakeComplete.Store(true)
c.SetError(errors.New("already connected"))
//same peer
log.Printf("[P2PClient] Connected to other same peer: %s (%d) is also %s (%d)", c.AddressPort, c.PeerId.Load(), otherClient.AddressPort, otherClient.PeerId.Load())
c.Close()