mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
d5ddd012bc
* Enforce error handling and checking type assertions * Reference issue #5404 in the TODO message * doc description * Merge branch 'master' into errcheck * fix tests and address @nisdas feedbacK * gaz * fix docker image
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
package sync
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/libp2p/go-libp2p-core/network"
|
|
)
|
|
|
|
const defaultReadDuration = ttfbTimeout
|
|
const defaultWriteDuration = 10 * time.Second // 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).Error("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).Error("Failed to set stream deadline")
|
|
}
|
|
}
|