prysm-pulse/beacon-chain/sync/deadlines.go
Nishant Das 28733f2c9e
Add Separate Network Config (#5454)
* clean up config
* add discv5 config
* add gaz
* Merge branch 'master' into configCleanup
* Merge refs/heads/master into configCleanup
* Merge refs/heads/master into configCleanup
* Merge refs/heads/master into configCleanup
* Merge refs/heads/master into configCleanup
* Merge refs/heads/master into configCleanup
* Merge refs/heads/master into configCleanup
2020-04-16 22:21:44 +00:00

33 lines
1.1 KiB
Go

package sync
import (
"time"
"github.com/libp2p/go-libp2p-core/network"
"github.com/prysmaticlabs/prysm/shared/params"
)
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).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")
}
}