mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
36c82b26e4
* minor improvements * Update beacon-chain/sync/deadlines.go * go fmt
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package sync
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/libp2p/go-libp2p-core/network"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var defaultReadDuration = ttfbTimeout
|
|
var defaultWriteDuration = params.BeaconNetworkConfig().RespTimeout // RESP_TIMEOUT
|
|
|
|
func setRPCStreamDeadlines(stream network.Stream) {
|
|
setStreamReadDeadline(stream, defaultReadDuration)
|
|
setStreamWriteDeadline(stream, defaultWriteDuration)
|
|
}
|
|
|
|
func setStreamReadDeadline(stream network.Stream, duration time.Duration) {
|
|
// libp2p uses the system clock time for determining the deadline so we use
|
|
// time.Now() instead of the synchronized roughtime.Now().
|
|
if err := stream.SetReadDeadline(time.Now().Add(duration)); err != nil {
|
|
log.WithError(err).WithFields(logrus.Fields{
|
|
"peer": stream.Conn().RemotePeer(),
|
|
"protocol": stream.Protocol(),
|
|
"direction": stream.Stat().Direction,
|
|
}).Debug("Failed to set stream deadline")
|
|
}
|
|
}
|
|
|
|
func setStreamWriteDeadline(stream network.Stream, duration time.Duration) {
|
|
// libp2p uses the system clock time for determining the deadline so we use
|
|
// time.Now() instead of the synchronized roughtime.Now().
|
|
if err := stream.SetWriteDeadline(time.Now().Add(duration)); err != nil {
|
|
log.WithError(err).WithFields(logrus.Fields{
|
|
"peer": stream.Conn().RemotePeer(),
|
|
"protocol": stream.Protocol(),
|
|
"direction": stream.Stat().Direction,
|
|
}).Debug("Failed to set stream deadline")
|
|
}
|
|
}
|