2019-08-16 20:03:11 +00:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p-core/network"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/roughtime"
|
|
|
|
)
|
|
|
|
|
2019-09-24 14:56:50 +00:00
|
|
|
const defaultReadDuration = ttfbTimeout
|
|
|
|
const defaultWriteDuration = 10 * time.Second // RESP_TIMEOUT
|
|
|
|
|
2019-08-16 20:03:11 +00:00
|
|
|
func setRPCStreamDeadlines(stream network.Stream) {
|
2019-09-24 14:56:50 +00:00
|
|
|
setStreamReadDeadline(stream, defaultReadDuration)
|
|
|
|
setStreamWriteDeadline(stream, defaultWriteDuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setStreamReadDeadline(stream network.Stream, duration time.Duration) {
|
|
|
|
stream.SetReadDeadline(roughtime.Now().Add(duration))
|
|
|
|
}
|
|
|
|
|
|
|
|
func setStreamWriteDeadline(stream network.Stream, duration time.Duration) {
|
|
|
|
stream.SetWriteDeadline(roughtime.Now().Add(duration))
|
2019-08-16 20:03:11 +00:00
|
|
|
}
|