-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ca0d49
commit 6a7fa4c
Showing
21 changed files
with
203 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package spao_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/scionproto/scion/pkg/drkey" | ||
"github.com/scionproto/scion/pkg/spao" | ||
"github.com/scionproto/scion/private/drkey/drkeyutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTimestamp(t *testing.T) { | ||
testCases := map[string]struct { | ||
currentTime time.Time | ||
epoch drkey.Epoch | ||
assertErr assert.ErrorAssertionFunc | ||
}{ | ||
"valid": { | ||
currentTime: time.Now().UTC(), | ||
epoch: getEpoch(time.Now()), | ||
assertErr: assert.NoError, | ||
}, | ||
"invalid": { | ||
currentTime: time.Now().UTC(), | ||
epoch: getEpoch(time.Now().UTC().Add(-4 * 24 * time.Hour)), | ||
assertErr: assert.Error, | ||
}, | ||
} | ||
for name, tc := range testCases { | ||
name, tc := name, tc | ||
t.Run(name, func(t *testing.T) { | ||
|
||
rt, err := spao.RelativeTimestamp(tc.epoch, tc.currentTime) | ||
tc.assertErr(t, err) | ||
if err != nil { | ||
return | ||
} | ||
recoveredTime := spao.AbsoluteTimestamp(tc.epoch, rt) | ||
assert.EqualValues(t, tc.currentTime, recoveredTime) | ||
}) | ||
} | ||
} | ||
|
||
func getEpoch(t time.Time) drkey.Epoch { | ||
epochDuration := drkeyutil.LoadEpochDuration() | ||
duration := int64(epochDuration / time.Second) | ||
idx := t.Unix() / duration | ||
begin := uint32(idx * duration) | ||
end := begin + uint32(duration) | ||
return drkey.NewEpoch(begin, end) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package drkeyutil | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/scionproto/scion/pkg/private/util" | ||
) | ||
|
||
const ( | ||
// DefaultEpochDuration is the default duration for the drkey SecretValue and derived keys | ||
DefaultEpochDuration = 24 * time.Hour | ||
DefaultPrefetchEntries = 10000 | ||
EnvVarEpochDuration = "SCION_TESTING_DRKEY_EPOCH_DURATION" | ||
// DefaultAcceptanceWindowOffset is the time width for accepting incoming packets. The | ||
// acceptance widown is then compute as: | ||
// aw := [T-a, T+a) | ||
// where aw:= acceptance window, T := time instant and a := acceptanceWindowOffset | ||
// | ||
// Picking the value equal or shorter than half of the drkey Grace Period ensures | ||
// that we accept packets for active keys only. | ||
DefaultAcceptanceWindowOffset = 2*time.Second + 500*time.Millisecond | ||
EnvVarAccpetanceWindow = "SCION_TESTING_ACCEPTANCE_WINDOW" | ||
) | ||
|
||
func LoadEpochDuration() time.Duration { | ||
s := os.Getenv(EnvVarEpochDuration) | ||
if s == "" { | ||
return DefaultEpochDuration | ||
} | ||
duration, err := util.ParseDuration(s) | ||
if err != nil { | ||
return DefaultEpochDuration | ||
} | ||
return duration | ||
} | ||
|
||
func LoadAcceptanceWindow() time.Duration { | ||
s := os.Getenv(EnvVarAccpetanceWindow) | ||
if s == "" { | ||
return DefaultAcceptanceWindowOffset | ||
} | ||
duration, err := util.ParseDuration(s) | ||
if err != nil { | ||
return DefaultAcceptanceWindowOffset | ||
} | ||
return duration | ||
} |
Oops, something went wrong.