Skip to content
Snippets Groups Projects
Commit 7539cc75 authored by Jonah Husson's avatar Jonah Husson
Browse files

Merge branch 'hotfix/tracker' into 'release'

Fix grace period use

See merge request !17
parents 48e1227b dab666dd
No related branches found
No related tags found
2 merge requests!23Release,!17Fix grace period use
...@@ -141,15 +141,13 @@ func generateIdentities(protoIds []ephemeral.ProtoIdentity, ourId *id.ID, ...@@ -141,15 +141,13 @@ func generateIdentities(protoIds []ephemeral.ProtoIdentity, ourId *id.ID,
// Add identities for every ephemeral ID // Add identities for every ephemeral ID
for i, eid := range protoIds { for i, eid := range protoIds {
// Expand the grace period for both start and end // Expand the grace period for both start and end
eid.End.Add(validityGracePeriod)
eid.Start.Add(-validityGracePeriod)
identities[i] = reception.Identity{ identities[i] = reception.Identity{
EphId: eid.Id, EphId: eid.Id,
Source: ourId, Source: ourId,
AddressSize: addressSize, AddressSize: addressSize,
End: eid.End, End: eid.End,
StartValid: eid.Start, StartValid: eid.Start.Add(-validityGracePeriod),
EndValid: eid.End, EndValid: eid.End.Add(validityGracePeriod),
Ephemeral: false, Ephemeral: false,
} }
...@@ -211,6 +209,6 @@ func calculateTickerTime(baseIDs []ephemeral.ProtoIdentity, now time.Time) time. ...@@ -211,6 +209,6 @@ func calculateTickerTime(baseIDs []ephemeral.ProtoIdentity, now time.Time) time.
// Factor out the grace period previously expanded upon // Factor out the grace period previously expanded upon
// Calculate and return that duration // Calculate and return that duration
gracePeriod := lastIdentity.End.Add(-2 * validityGracePeriod) gracePeriod := lastIdentity.End.Add(-1 * validityGracePeriod)
return gracePeriod.Sub(now) return gracePeriod.Sub(now)
} }
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
"gitlab.com/xx_network/comms/signature" "gitlab.com/xx_network/comms/signature"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"gitlab.com/xx_network/primitives/utils" "gitlab.com/xx_network/primitives/utils"
"testing" "testing"
...@@ -122,3 +123,18 @@ func setupInstance(instance interfaces.NetworkManager) error { ...@@ -122,3 +123,18 @@ func setupInstance(instance interfaces.NetworkManager) error {
return nil return nil
} }
func TestGenerateIdentities(t *testing.T) {
eid, s, e, err := ephemeral.GetId(id.NewIdFromString("zezima", id.Node, t), 16, time.Now().UnixNano())
if err != nil {
t.Errorf("Failed to get eid: %+v", err)
}
protoIds := []ephemeral.ProtoIdentity{{eid, s, e}}
generated := generateIdentities(protoIds, id.NewIdFromString("escaline", id.Node, t), 16)
if generated[0].EndValid != protoIds[0].End.Add(5*time.Minute) {
t.Errorf("End was not modified. Orig %+v, Generated %+v", protoIds[0].End, generated[0].End)
}
if generated[0].StartValid != protoIds[0].Start.Add(-5*time.Minute) {
t.Errorf("End was not modified. Orig %+v, Generated %+v", protoIds[0].End, generated[0].End)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment