mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
Update server.go
This commit is contained in:
parent
a9ab53d751
commit
1505c608c6
1 changed files with 31 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue