feature: increase key usage after successful peer registration (#93)

This commit is contained in:
Mikhail Bragin
2021-08-22 11:29:25 +02:00
committed by GitHub
parent 90ef1e939b
commit 6869b48905
3 changed files with 34 additions and 14 deletions
+10
View File
@@ -35,6 +35,8 @@ type SetupKey struct {
Revoked bool
// UsedTimes indicates how many times the key was used
UsedTimes int
// LastUsed last time the key was used for peer registration
LastUsed time.Time
}
//Copy copies SetupKey to a new object
@@ -51,6 +53,14 @@ func (key *SetupKey) Copy() *SetupKey {
}
}
//IncrementUsage makes a copy of a key, increments the UsedTimes by 1 and sets LastUsed to now
func (key *SetupKey) IncrementUsage() *SetupKey {
c := key.Copy()
c.UsedTimes = c.UsedTimes + 1
c.LastUsed = time.Now()
return c
}
// IsValid is true if the key was not revoked, is not expired and used not more than it was supposed to
func (key *SetupKey) IsValid() bool {
expired := time.Now().After(key.ExpiresAt)