@@ -40,8 +40,8 @@ const (
40
40
retryReadWriteMessageAttempts = 5
41
41
reconnectInterval = 10 * time .Second
42
42
43
- pingInterval = 30 * time .Second
44
- connectionHealthTickerDuration = 1 * time .Minute
43
+ pingIntervalDefault = 30 * time .Second
44
+ connectionHealthTickerDurationDefault = 1 * time .Minute
45
45
)
46
46
47
47
type Block struct {
@@ -77,8 +77,9 @@ type Peer struct {
77
77
retryReadWriteMessageInterval time.Duration
78
78
nrWriteHandlers int
79
79
isUnhealthyCh chan struct {}
80
-
81
- ctx context.Context
80
+ pingInterval time.Duration
81
+ connectionHealthThreshold time.Duration
82
+ ctx context.Context
82
83
83
84
cancelReadHandler context.CancelFunc
84
85
cancelWriteHandler context.CancelFunc
@@ -114,6 +115,8 @@ func NewPeer(logger *slog.Logger, address string, peerHandler PeerHandlerI, netw
114
115
maximumMessageSize : defaultMaximumMessageSize ,
115
116
batchDelay : defaultBatchDelayMilliseconds * time .Millisecond ,
116
117
retryReadWriteMessageInterval : retryReadWriteMessageIntervalDefault ,
118
+ pingInterval : pingIntervalDefault ,
119
+ connectionHealthThreshold : connectionHealthTickerDurationDefault ,
117
120
writerWg : & sync.WaitGroup {},
118
121
readerWg : & sync.WaitGroup {},
119
122
reconnectingWg : & sync.WaitGroup {},
@@ -790,11 +793,11 @@ func (p *Peer) versionMessage(address string) *wire.MsgVersion {
790
793
func (p * Peer ) startMonitorPingPong () {
791
794
p .healthMonitorWg .Add (1 )
792
795
793
- pingTicker := time .NewTicker (pingInterval )
796
+ pingTicker := time .NewTicker (p . pingInterval )
794
797
795
798
go func () {
796
799
// if no ping/pong signal is received for certain amount of time, mark peer as unhealthy
797
- monitorConnectionTicker := time .NewTicker (connectionHealthTickerDuration )
800
+ monitorConnectionTicker := time .NewTicker (p . connectionHealthThreshold )
798
801
799
802
defer func () {
800
803
p .healthMonitorWg .Done ()
@@ -812,7 +815,7 @@ func (p *Peer) startMonitorPingPong() {
812
815
p .writeChan <- wire .NewMsgPing (nonce )
813
816
case <- p .pingPongAlive :
814
817
// if ping/pong signal is received reset the ticker
815
- monitorConnectionTicker .Reset (connectionHealthTickerDuration )
818
+ monitorConnectionTicker .Reset (p . connectionHealthThreshold )
816
819
p .setHealthy ()
817
820
case <- monitorConnectionTicker .C :
818
821
0 commit comments