Update server.go

This commit is contained in:
Ragnar 2025-01-06 02:00:11 +01:00 committed by GitHub
parent a9ab53d751
commit 1505c608c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -831,7 +831,38 @@ running:
}
}
// checkConnectionQuality performs a latency check on the connection
func (srv *Server) checkConnectionQuality(c *conn) error {
start := time.Now()
// Send ping and wait for pong
select {
case c.cont <- nil: // Simulate ping
select {
case err := <-c.cont: // Wait for pong
if err != nil {
return err
}
// Check if latency is acceptable (less than 1 second)
if time.Since(start) > time.Second {
return fmt.Errorf("connection latency too high: %v", time.Since(start))
}
case <-time.After(time.Second):
return fmt.Errorf("connection quality check timeout")
}
case <-time.After(time.Second):
return fmt.Errorf("connection quality check failed")
}
return nil
}
func (srv *Server) postHandshakeChecks(peers map[enode.ID]*Peer, inboundCount int, c *conn) error {
// First check connection quality
if err := srv.checkConnectionQuality(c); err != nil {
return fmt.Errorf("connection quality check failed: %v", err)
}
switch {
case !c.is(trustedConn) && len(peers) >= srv.MaxPeers:
return DiscTooManyPeers