storj/storagenode/contact/network.go
Clement Sam 59b37db670 storagenode: overhaul QUIC check implementation
The current implementation blocks the the startup until one or none
of the trusted satellites is able to reach the node via QUIC.
This can cause delayed startup. Also, the quic check is done
once during startup, and if there is a misconfiguration later,
snos would have to restart to node.

In this change, we reuse the contact service which pings the satellite
periodically for node checkin. During checkin the satellite tries
pinging the node back via both TCP and QUIC and reports both statuses.
WIth this, we are able to get a periodic update of the QUIC status
without restarting the node.

Also adds the time the node was last pinged via QUIC to the tooltip
on the QUIC status tab.

Resolves https://github.com/storj/storj/issues/4398

Change-Id: I18aa2a8e8d44e8187f8f2eb51f398fa6073882a4
2022-11-09 03:15:57 +00:00

76 lines
1.6 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package contact
import (
"sync"
"time"
)
const (
// NetworkStatusOk represents node successfully pinged.
NetworkStatusOk = "OK"
// NetworkStatusMisconfigured means satellite could not ping
// back node due to misconfiguration on the node host.
NetworkStatusMisconfigured = "Misconfigured"
// NetworkStatusDisabled means QUIC is disabled by config.
NetworkStatusDisabled = "Disabled"
// NetworkStatusRefreshing means QUIC check is in progress.
NetworkStatusRefreshing = "Refreshing"
)
// QUICStats contains information regarding QUIC status of the node.
type QUICStats struct {
status string
enabled bool
mu sync.Mutex
lastPinged time.Time
}
// NewQUICStats returns a new QUICStats.
func NewQUICStats(enabled bool) *QUICStats {
stats := &QUICStats{
enabled: enabled,
status: NetworkStatusRefreshing,
}
if !enabled {
stats.status = NetworkStatusDisabled
}
return stats
}
// SetStatus sets the QUIC status during PingMe request.
func (q *QUICStats) SetStatus(pingSuccess bool) {
q.mu.Lock()
defer q.mu.Unlock()
q.lastPinged = time.Now()
if pingSuccess {
q.status = NetworkStatusOk
return
}
q.status = NetworkStatusMisconfigured
}
// Status returns the quic status gathered in a PingMe request.
func (q *QUICStats) Status() string {
q.mu.Lock()
defer q.mu.Unlock()
if !q.enabled {
return NetworkStatusDisabled
}
return q.status
}
// WhenLastPinged returns last time someone pinged this node via QUIC.
func (q *QUICStats) WhenLastPinged() (when time.Time) {
q.mu.Lock()
defer q.mu.Unlock()
return q.lastPinged
}