11package keepalive
22
33import (
4+ "time"
5+
46 "github.com/cloudstruct/go-ouroboros-network/protocol"
57)
68
@@ -9,7 +11,10 @@ const (
911 PROTOCOL_ID uint16 = 8
1012
1113 // Time between keep-alive probes, in seconds
12- KEEP_ALIVE_PERIOD = 60
14+ DEFAULT_KEEP_ALIVE_PERIOD = 60
15+
16+ // Timeout for keep-alive responses, in seconds
17+ DEFAULT_KEEP_ALIVE_TIMEOUT = 10
1318)
1419
1520var (
@@ -55,6 +60,8 @@ type Config struct {
5560 KeepAliveFunc KeepAliveFunc
5661 KeepAliveResponseFunc KeepAliveResponseFunc
5762 DoneFunc DoneFunc
63+ Timeout time.Duration
64+ Period time.Duration
5865}
5966
6067// Callback function types
@@ -73,7 +80,10 @@ func New(protoOptions protocol.ProtocolOptions, cfg *Config) *KeepAlive {
7380type KeepAliveOptionFunc func (* Config )
7481
7582func NewConfig (options ... KeepAliveOptionFunc ) Config {
76- c := Config {}
83+ c := Config {
84+ Period : DEFAULT_KEEP_ALIVE_PERIOD * time .Second ,
85+ Timeout : DEFAULT_KEEP_ALIVE_TIMEOUT * time .Second ,
86+ }
7787 // Apply provided options functions
7888 for _ , option := range options {
7989 option (& c )
@@ -98,3 +108,15 @@ func WithDoneFunc(doneFunc DoneFunc) KeepAliveOptionFunc {
98108 c .DoneFunc = doneFunc
99109 }
100110}
111+
112+ func WithTimeout (timeout time.Duration ) KeepAliveOptionFunc {
113+ return func (c * Config ) {
114+ c .Timeout = timeout
115+ }
116+ }
117+
118+ func WithPeriod (period time.Duration ) KeepAliveOptionFunc {
119+ return func (c * Config ) {
120+ c .Period = period
121+ }
122+ }
0 commit comments