mirror of
https://github.com/h44z/wg-portal.git
synced 2026-03-24 00:56:26 +00:00
fix: configurable handshake validity interval and improved defaults (#645)
* fix: support configurable rekey timeout interval for peer connectivity tracking (#641) * change default check-time to 180s
This commit is contained in:
@@ -9,11 +9,16 @@ func TestPeerStatus_IsConnected(t *testing.T) {
|
||||
now := time.Now()
|
||||
past := now.Add(-3 * time.Minute)
|
||||
recent := now.Add(-1 * time.Minute)
|
||||
defaultTimeout := 125 * time.Second // rekey interval of 120s + 5 seconds grace period
|
||||
past126 := now.Add(-1*defaultTimeout - 1*time.Second)
|
||||
past125 := now.Add(-1 * defaultTimeout)
|
||||
past124 := now.Add(-1*defaultTimeout + 1*time.Second)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
status PeerStatus
|
||||
want bool
|
||||
name string
|
||||
status PeerStatus
|
||||
timeout time.Duration
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "Pingable and recent handshake",
|
||||
@@ -21,7 +26,8 @@ func TestPeerStatus_IsConnected(t *testing.T) {
|
||||
IsPingable: true,
|
||||
LastHandshake: &recent,
|
||||
},
|
||||
want: true,
|
||||
timeout: defaultTimeout,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Not pingable but recent handshake",
|
||||
@@ -29,7 +35,8 @@ func TestPeerStatus_IsConnected(t *testing.T) {
|
||||
IsPingable: false,
|
||||
LastHandshake: &recent,
|
||||
},
|
||||
want: true,
|
||||
timeout: defaultTimeout,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Pingable but old handshake",
|
||||
@@ -37,15 +44,44 @@ func TestPeerStatus_IsConnected(t *testing.T) {
|
||||
IsPingable: true,
|
||||
LastHandshake: &past,
|
||||
},
|
||||
want: true,
|
||||
timeout: defaultTimeout,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Not pingable and old handshake",
|
||||
name: "Not pingable and ok handshake (-124s)",
|
||||
status: PeerStatus{
|
||||
IsPingable: false,
|
||||
LastHandshake: &past124,
|
||||
},
|
||||
timeout: defaultTimeout,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Not pingable and old handshake (-125s)",
|
||||
status: PeerStatus{
|
||||
IsPingable: false,
|
||||
LastHandshake: &past125,
|
||||
},
|
||||
timeout: defaultTimeout,
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "Not pingable and old handshake (-126s)",
|
||||
status: PeerStatus{
|
||||
IsPingable: false,
|
||||
LastHandshake: &past126,
|
||||
},
|
||||
timeout: defaultTimeout,
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "Not pingable and old handshake (very old)",
|
||||
status: PeerStatus{
|
||||
IsPingable: false,
|
||||
LastHandshake: &past,
|
||||
},
|
||||
want: false,
|
||||
timeout: defaultTimeout,
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "Pingable and no handshake",
|
||||
@@ -53,7 +89,8 @@ func TestPeerStatus_IsConnected(t *testing.T) {
|
||||
IsPingable: true,
|
||||
LastHandshake: nil,
|
||||
},
|
||||
want: true,
|
||||
timeout: defaultTimeout,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Not pingable and no handshake",
|
||||
@@ -61,12 +98,13 @@ func TestPeerStatus_IsConnected(t *testing.T) {
|
||||
IsPingable: false,
|
||||
LastHandshake: nil,
|
||||
},
|
||||
want: false,
|
||||
timeout: defaultTimeout,
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.status.CalcConnected()
|
||||
tt.status.CalcConnected(tt.timeout)
|
||||
if got := tt.status.IsConnected; got != tt.want {
|
||||
t.Errorf("IsConnected = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user