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
2 merge requests!23Release,!17Fix grace period use
......@@ -141,15 +141,16 @@ func generateIdentities(protoIds []ephemeral.ProtoIdentity, ourId *id.ID,
// Add identities for every ephemeral ID
for i, eid := range protoIds {
// Expand the grace period for both start and end
eid.End.Add(validityGracePeriod)
eid.Start.Add(-validityGracePeriod)
// This does not actually modify anything.... time is not a pointer and even if it were this returns the new value???
// eid.End.Add(validityGracePeriod)
// eid.Start.Add(-validityGracePeriod)
identities[i] = reception.Identity{
EphId: eid.Id,
Source: ourId,
AddressSize: addressSize,
End: eid.End,
StartValid: eid.Start,
EndValid: eid.End,
StartValid: eid.Start.Add(-validityGracePeriod),
EndValid: eid.End.Add(validityGracePeriod), // What is this vs end? should it be modified??
Ephemeral: false,
}
......@@ -211,6 +212,6 @@ func calculateTickerTime(baseIDs []ephemeral.ProtoIdentity, now time.Time) time.
// Factor out the grace period previously expanded upon
// Calculate and return that duration
gracePeriod := lastIdentity.End.Add(-2 * validityGracePeriod)
gracePeriod := lastIdentity.End.Add(-1 * validityGracePeriod)
return gracePeriod.Sub(now)
}
......@@ -17,6 +17,7 @@ import (
"gitlab.com/xx_network/comms/signature"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime"
"gitlab.com/xx_network/primitives/utils"
"testing"
......@@ -122,3 +123,18 @@ func setupInstance(instance interfaces.NetworkManager) error {
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