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

Fix grace period use

parent 48e1227b
No related branches found
No related tags found
Loading
...@@ -141,15 +141,16 @@ func generateIdentities(protoIds []ephemeral.ProtoIdentity, ourId *id.ID, ...@@ -141,15 +141,16 @@ 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) // This does not actually modify anything.... time is not a pointer and even if it were this returns the new value???
eid.Start.Add(-validityGracePeriod) // 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), // What is this vs end? should it be modified??
Ephemeral: false, Ephemeral: false,
} }
...@@ -211,6 +212,6 @@ func calculateTickerTime(baseIDs []ephemeral.ProtoIdentity, now time.Time) time. ...@@ -211,6 +212,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].End != 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