Skip to content
Snippets Groups Projects
Commit 5fcffca3 authored by Jono Wenger's avatar Jono Wenger
Browse files

Fix code formatting of storage/reception/

parent ce273f56
No related branches found
No related tags found
No related merge requests found
...@@ -14,12 +14,11 @@ import ( ...@@ -14,12 +14,11 @@ import (
type IdentityUse struct { type IdentityUse struct {
Identity Identity
//randomly generated time to poll between // Randomly generated time to poll between
StartRequest time.Time //timestamp to request the start of bloom filters StartRequest time.Time // Timestamp to request the start of bloom filters
EndRequest time.Time //timestamp to request the End of bloom filters EndRequest time.Time // Timestamp to request the End of bloom filters
// denotes if the identity is fake, in which case we do not process // Denotes if the identity is fake, in which case we do not process messages
// messages
Fake bool Fake bool
// rounds data // rounds data
...@@ -27,14 +26,14 @@ type IdentityUse struct{ ...@@ -27,14 +26,14 @@ type IdentityUse struct{
} }
// setSamplingPeriod add the Request mask as a random buffer around the sampling // setSamplingPeriod add the Request mask as a random buffer around the sampling
// time to obfuscate it // time to obfuscate it.
func (iu IdentityUse) setSamplingPeriod(rng io.Reader) (IdentityUse, error) { func (iu IdentityUse) setSamplingPeriod(rng io.Reader) (IdentityUse, error) {
//generate the seed // Generate the seed
seed := make([]byte, 32) seed := make([]byte, 32)
if _, err := rng.Read(seed); err != nil { if _, err := rng.Read(seed); err != nil {
return IdentityUse{}, errors.WithMessage(err, "Failed to "+ return IdentityUse{}, errors.WithMessage(err, "Failed to "+
"choose id due to rng failure") "choose ID due to rng failure")
} }
h, err := hash.NewCMixHash() h, err := hash.NewCMixHash()
...@@ -42,13 +41,11 @@ func (iu IdentityUse)setSamplingPeriod(rng io.Reader)(IdentityUse, error){ ...@@ -42,13 +41,11 @@ func (iu IdentityUse)setSamplingPeriod(rng io.Reader)(IdentityUse, error){
return IdentityUse{}, err return IdentityUse{}, err
} }
//calculate the period offset // Calculate the period offset
periodOffset := periodOffset := randomness.RandInInterval(
randomness.RandInInterval(big.NewInt(iu.RequestMask.Nanoseconds()), big.NewInt(iu.RequestMask.Nanoseconds()), seed, h).Int64()
seed,h).Int64()
iu.StartRequest = iu.StartValid.Add(-time.Duration(periodOffset)) iu.StartRequest = iu.StartValid.Add(-time.Duration(periodOffset))
iu.EndRequest = iu.EndValid.Add(iu.RequestMask - iu.EndRequest = iu.EndValid.Add(iu.RequestMask - time.Duration(periodOffset))
time.Duration(periodOffset))
return iu, nil return iu, nil
} }
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
// generateFakeIdentity generates a fake identity of the given size with the // generateFakeIdentity generates a fake identity of the given size with the
// given random number generator // given random number generator
func generateFakeIdentity(rng io.Reader, idSize uint, now time.Time) (IdentityUse, error) { func generateFakeIdentity(rng io.Reader, idSize uint, now time.Time) (IdentityUse, error) {
//randomly generate an identity // Randomly generate an identity
randIDbytes := make([]byte, id.ArrIDLen-1) randIDbytes := make([]byte, id.ArrIDLen-1)
if _, err := rng.Read(randIDbytes); err != nil { if _, err := rng.Read(randIDbytes); err != nil {
return IdentityUse{}, errors.WithMessage(err, "failed to "+ return IdentityUse{}, errors.WithMessage(err, "failed to "+
...@@ -22,12 +22,12 @@ func generateFakeIdentity(rng io.Reader, idSize uint, now time.Time)(IdentityUse ...@@ -22,12 +22,12 @@ func generateFakeIdentity(rng io.Reader, idSize uint, now time.Time)(IdentityUse
copy(randID[:id.ArrIDLen-1], randIDbytes) copy(randID[:id.ArrIDLen-1], randIDbytes)
randID.SetType(id.User) randID.SetType(id.User)
//generate the current ephemeral ID from the random identity // Generate the current ephemeral ID from the random identity
ephID, start, end, err := ephemeral.GetId(randID, idSize, ephID, start, end, err := ephemeral.GetId(randID, idSize,
now.UnixNano()) now.UnixNano())
if err != nil { if err != nil {
return IdentityUse{}, errors.WithMessage(err, "failed to "+ return IdentityUse{}, errors.WithMessage(err, "failed to "+
"generate an ephemral ID for random identity when none is " + "generate an ephemeral ID for random identity when none is "+
"available") "available")
} }
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"time" "time"
) )
//tests Generate Fake identity is consistant and returns a correct result // Tests Generate Fake identity is consistent and returns a correct result.
func TestGenerateFakeIdentity(t *testing.T) { func TestGenerateFakeIdentity(t *testing.T) {
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewSource(42))
......
...@@ -14,23 +14,22 @@ const identityStorageKey = "IdentityStorage" ...@@ -14,23 +14,22 @@ const identityStorageKey = "IdentityStorage"
const identityStorageVersion = 0 const identityStorageVersion = 0
type Identity struct { type Identity struct {
//identity // Identity
EphId ephemeral.Id EphId ephemeral.Id
Source *id.ID Source *id.ID
//usage variables // Usage variables
End time.Time // timestamp when active polling will stop End time.Time // Timestamp when active polling will stop
ExtraChecks uint // number of extra checks executed as active ExtraChecks uint // Number of extra checks executed as active after the
// after the id exits active // ID exits active
//polling parameters // Polling parameters
StartValid time.Time // timestamp when the ephID begins being valid StartValid time.Time // Timestamp when the ephID begins being valid
EndValid time.Time // timestamp when the ephID stops being valid EndValid time.Time // Timestamp when the ephID stops being valid
RequestMask time.Duration // amount of extra time requested for the poll RequestMask time.Duration // Amount of extra time requested for the poll in
// in order to mask the exact valid time for // order to mask the exact valid time for the ID
// the id
//makes the identity not store on disk // Makes the identity not store on disk
Ephemeral bool Ephemeral bool
} }
...@@ -49,7 +48,7 @@ func loadIdentity(kv *versioned.KV) (Identity, error) { ...@@ -49,7 +48,7 @@ func loadIdentity(kv *versioned.KV) (Identity, error) {
} }
func (i Identity) store(kv *versioned.KV) error { func (i Identity) store(kv *versioned.KV) error {
//marshal the registration // Marshal the registration
regStr, err := json.Marshal(&i) regStr, err := json.Marshal(&i)
if err != nil { if err != nil {
return errors.WithMessage(err, "Failed to marshal Identity") return errors.WithMessage(err, "Failed to marshal Identity")
...@@ -62,7 +61,7 @@ func (i Identity) store(kv *versioned.KV) error { ...@@ -62,7 +61,7 @@ func (i Identity) store(kv *versioned.KV) error {
Data: regStr, Data: regStr,
} }
//store the data // Store the data
err = kv.Set(identityStorageKey, obj) err = kv.Set(identityStorageKey, obj)
if err != nil { if err != nil {
return errors.WithMessage(err, "Failed to store Identity") return errors.WithMessage(err, "Failed to store Identity")
...@@ -92,5 +91,4 @@ func (i Identity) Equal(b Identity) bool { ...@@ -92,5 +91,4 @@ func (i Identity) Equal(b Identity) bool {
i.EndValid.Equal(b.EndValid) && i.EndValid.Equal(b.EndValid) &&
i.RequestMask == b.RequestMask && i.RequestMask == b.RequestMask &&
i.Ephemeral == b.Ephemeral i.Ephemeral == b.Ephemeral
} }
...@@ -12,7 +12,7 @@ func TestIdentityUse_SetSamplingPeriod(t *testing.T) { ...@@ -12,7 +12,7 @@ func TestIdentityUse_SetSamplingPeriod(t *testing.T) {
const numTests = 1000 const numTests = 1000
for i := 0; i < numTests; i++ { for i := 0; i < numTests; i++ {
//generate an identity use // Generate an identity use
start := randate() start := randate()
end := start.Add(time.Duration(rand.Uint64() % uint64(92*time.Hour))) end := start.Add(time.Duration(rand.Uint64() % uint64(92*time.Hour)))
mask := time.Duration(rand.Uint64() % uint64(92*time.Hour)) mask := time.Duration(rand.Uint64() % uint64(92*time.Hour))
...@@ -24,7 +24,7 @@ func TestIdentityUse_SetSamplingPeriod(t *testing.T) { ...@@ -24,7 +24,7 @@ func TestIdentityUse_SetSamplingPeriod(t *testing.T) {
}, },
} }
//generate the sampling period // Generate the sampling period
var err error var err error
iu, err = iu.setSamplingPeriod(rng) iu, err = iu.setSamplingPeriod(rng)
if err != nil { if err != nil {
...@@ -32,7 +32,7 @@ func TestIdentityUse_SetSamplingPeriod(t *testing.T) { ...@@ -32,7 +32,7 @@ func TestIdentityUse_SetSamplingPeriod(t *testing.T) {
"period on interation %v: %+v", i, err) "period on interation %v: %+v", i, err)
} }
//test that the range between the periods is correct // Test that the range between the periods is correct
resultRange := iu.EndRequest.Sub(iu.StartRequest) resultRange := iu.EndRequest.Sub(iu.StartRequest)
expectedRange := iu.EndValid.Sub(iu.StartValid) + iu.RequestMask expectedRange := iu.EndValid.Sub(iu.StartValid) + iu.RequestMask
...@@ -41,21 +41,20 @@ func TestIdentityUse_SetSamplingPeriod(t *testing.T) { ...@@ -41,21 +41,20 @@ func TestIdentityUse_SetSamplingPeriod(t *testing.T) {
"size: Expecterd: %s, Received: %s", expectedRange, resultRange) "size: Expecterd: %s, Received: %s", expectedRange, resultRange)
} }
//test the sampling range does not exceed a reasonable lower bound // Test the sampling range does not exceed a reasonable lower bound
lowerBound := iu.StartValid.Add(-iu.RequestMask) lowerBound := iu.StartValid.Add(-iu.RequestMask)
if !iu.StartRequest.After(lowerBound) { if !iu.StartRequest.After(lowerBound) {
t.Errorf("Start request exceeds the reasonable lower "+ t.Errorf("Start request exceeds the reasonable lower "+
"bound: \n\t Bound: %s\n\t Start: %s", lowerBound, iu.StartValid) "bound: \n\t Bound: %s\n\t Start: %s", lowerBound, iu.StartValid)
} }
//test the sampling range does not exceed a reasonable upper bound // Test the sampling range does not exceed a reasonable upper bound
upperBound := iu.EndValid.Add(iu.RequestMask - time.Millisecond) upperBound := iu.EndValid.Add(iu.RequestMask - time.Millisecond)
if iu.EndRequest.After(upperBound) { if iu.EndRequest.After(upperBound) {
t.Errorf("End request exceeds the reasonable upper bound") t.Errorf("End request exceeds the reasonable upper bound")
} }
} }
} }
func randate() time.Time { func randate() time.Time {
......
...@@ -90,12 +90,12 @@ func TestIdentity_CalculateKrSize(t *testing.T) { ...@@ -90,12 +90,12 @@ func TestIdentity_CalculateKrSize(t *testing.T) {
for _, d := range deltas { for _, d := range deltas {
expected := int(d.Seconds()+1) * maxRoundsPerSecond expected := int(d.Seconds()+1) * maxRoundsPerSecond
now := time.Now() now := time.Now()
id := Identity{ i := Identity{
StartValid: now, StartValid: now,
EndValid: now.Add(d), EndValid: now.Add(d),
} }
krSize := id.calculateKrSize() krSize := i.calculateKrSize()
if krSize != expected { if krSize != expected {
t.Errorf("kr size not correct! expected: %v, recieved: %v", t.Errorf("kr size not correct! expected: %v, recieved: %v",
expected, krSize) expected, krSize)
......
...@@ -9,13 +9,11 @@ import ( ...@@ -9,13 +9,11 @@ import (
"gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/id/ephemeral"
"strconv" "strconv"
"time" "time"
) )
const maxRoundsPerSecond = 100 const maxRoundsPerSecond = 100
const knownRoundsStorageKey = "krStorage" const knownRoundsStorageKey = "krStorage"
type registration struct { type registration struct {
Identity Identity
knownRounds *knownRounds.KnownRounds knownRounds *knownRounds.KnownRounds
...@@ -24,38 +22,38 @@ type registration struct{ ...@@ -24,38 +22,38 @@ type registration struct{
} }
func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) { func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) {
//round the times to remove the monotic clocks for future saving // Round the times to remove the monotonic clocks for future saving
reg.StartValid = reg.StartValid.Round(0) reg.StartValid = reg.StartValid.Round(0)
reg.EndValid = reg.EndValid.Round(0) reg.EndValid = reg.EndValid.Round(0)
reg.End = reg.End.Round(0) reg.End = reg.End.Round(0)
now := time.Now() now := time.Now()
//do edge checks to determine if the identity is valid // Do edge checks to determine if the identity is valid
if now.After(reg.End) && reg.ExtraChecks < 1 { if now.After(reg.End) && reg.ExtraChecks < 1 {
return nil, errors.New("Cannot create a registration for an " + return nil, errors.New("Cannot create a registration for an " +
"identity which has expired") "identity which has expired")
} }
//set the prefix // Set the prefix
kv = kv.Prefix(regPrefix(reg.EphId, reg.Source, reg.StartValid)) kv = kv.Prefix(regPrefix(reg.EphId, reg.Source, reg.StartValid))
r := &registration{ r := &registration{
Identity: reg, Identity: reg,
knownRounds: knownRounds.NewKnownRound(reg.calculateKrSize()), knownRounds: knownRounds.NewKnownRound(reg.calculateKrSize()),
kv: kv, kv: kv,
} }
//if this isn't ephemeral, store everything // If this is not ephemeral, then store everything
if !reg.Ephemeral { if !reg.Ephemeral {
//store known rounds // Store known rounds
var err error var err error
r.knownRoundsStorage, err = utility.NewKnownRounds(kv, knownRoundsStorageKey, r.knownRounds) r.knownRoundsStorage, err = utility.NewKnownRounds(kv, knownRoundsStorageKey, r.knownRounds)
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "failed to store known rounds") return nil, errors.WithMessage(err, "failed to store known rounds")
} }
//store the registration
// Store the registration
if err = reg.store(kv); err != nil { if err = reg.store(kv); err != nil {
return nil, errors.WithMessage(err, "failed to store registration") return nil, errors.WithMessage(err, "failed to store registration")
} }
...@@ -64,19 +62,21 @@ func newRegistration(reg Identity, kv *versioned.KV)(*registration, error){ ...@@ -64,19 +62,21 @@ func newRegistration(reg Identity, kv *versioned.KV)(*registration, error){
return r, nil return r, nil
} }
func loadRegistration(EphId ephemeral.Id, Source *id.ID, startvalid time.Time, kv *versioned.KV)(*registration, error){ func loadRegistration(EphId ephemeral.Id, Source *id.ID, startValid time.Time,
kv = kv.Prefix(regPrefix(EphId, Source, startvalid)) kv *versioned.KV) (*registration, error) {
kv = kv.Prefix(regPrefix(EphId, Source, startValid))
reg, err := loadIdentity(kv) reg, err := loadIdentity(kv)
if err != nil { if err != nil {
return nil, errors.WithMessagef(err, "Failed to load identity "+ return nil, errors.WithMessagef(err, "Failed to load identity "+
"for %s", regPrefix(EphId, Source, startvalid)) "for %s", regPrefix(EphId, Source, startValid))
} }
kr, err := utility.LoadKnownRounds(kv, knownRoundsStorageKey, reg.calculateKrSize()) kr, err := utility.LoadKnownRounds(kv, knownRoundsStorageKey, reg.calculateKrSize())
if err != nil { if err != nil {
return nil, errors.WithMessagef(err, "Failed to load known "+ return nil, errors.WithMessagef(err, "Failed to load known "+
"rounds for %s", regPrefix(EphId, Source, startvalid)) "rounds for %s", regPrefix(EphId, Source, startValid))
} }
r := &registration{ r := &registration{
...@@ -88,7 +88,6 @@ func loadRegistration(EphId ephemeral.Id, Source *id.ID, startvalid time.Time, ...@@ -88,7 +88,6 @@ func loadRegistration(EphId ephemeral.Id, Source *id.ID, startvalid time.Time,
return r, nil return r, nil
} }
func (r *registration) Delete() error { func (r *registration) Delete() error {
if !r.Ephemeral { if !r.Ephemeral {
if err := r.knownRoundsStorage.Delete(); err != nil { if err := r.knownRoundsStorage.Delete(); err != nil {
...@@ -100,6 +99,7 @@ func (r *registration)Delete()error{ ...@@ -100,6 +99,7 @@ func (r *registration)Delete()error{
"registration public data %s", r) "registration public data %s", r)
} }
} }
return nil return nil
} }
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
) )
func TestNewRegistration_Failed(t *testing.T) { func TestNewRegistration_Failed(t *testing.T) {
//generate an identity for use // Generate an identity for use
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewSource(42))
timestamp := time.Date(2009, 11, 17, 20, timestamp := time.Date(2009, 11, 17, 20,
...@@ -32,7 +32,7 @@ func TestNewRegistration_Failed(t *testing.T) { ...@@ -32,7 +32,7 @@ func TestNewRegistration_Failed(t *testing.T) {
} }
func TestNewRegistration_Ephemeral(t *testing.T) { func TestNewRegistration_Ephemeral(t *testing.T) {
//generate an identity for use // Generate an identity for use
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewSource(42))
timestamp := time.Date(2009, 11, 17, 20, timestamp := time.Date(2009, 11, 17, 20,
...@@ -62,13 +62,12 @@ func TestNewRegistration_Ephemeral(t *testing.T) { ...@@ -62,13 +62,12 @@ func TestNewRegistration_Ephemeral(t *testing.T) {
t.Errorf("Ephemenral identity has a known rounds storage") t.Errorf("Ephemenral identity has a known rounds storage")
} }
//check if the known rounds is stored, it should not be // Check if the known rounds is stored, it should not be
if _, err = utility.LoadKnownRounds(reg.kv, knownRoundsStorageKey, id.calculateKrSize()); err == nil { if _, err = utility.LoadKnownRounds(reg.kv, knownRoundsStorageKey, id.calculateKrSize()); err == nil {
t.Errorf("Ephemeral identity stored the known rounds when it " + t.Errorf("Ephemeral identity stored the known rounds when it " +
"shouldnt") "shouldnt")
} }
if _, err = reg.kv.Get(identityStorageKey); err == nil { if _, err = reg.kv.Get(identityStorageKey); err == nil {
t.Errorf("Ephemeral identity stored the idenity when it " + t.Errorf("Ephemeral identity stored the idenity when it " +
"shouldnt") "shouldnt")
...@@ -76,7 +75,7 @@ func TestNewRegistration_Ephemeral(t *testing.T) { ...@@ -76,7 +75,7 @@ func TestNewRegistration_Ephemeral(t *testing.T) {
} }
func TestNewRegistration_Persistent(t *testing.T) { func TestNewRegistration_Persistent(t *testing.T) {
//generate an identity for use // Generate an identity for use
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewSource(42))
timestamp := time.Date(2009, 11, 17, 20, timestamp := time.Date(2009, 11, 17, 20,
...@@ -106,7 +105,7 @@ func TestNewRegistration_Persistent(t *testing.T) { ...@@ -106,7 +105,7 @@ func TestNewRegistration_Persistent(t *testing.T) {
t.Errorf("Persistent identity does not have a known rounds storage") t.Errorf("Persistent identity does not have a known rounds storage")
} }
//check if the known rounds is stored, it should not be // Check if the known rounds is stored, it should not be
if _, err = utility.LoadKnownRounds(reg.kv, knownRoundsStorageKey, id.calculateKrSize()); err != nil { if _, err = utility.LoadKnownRounds(reg.kv, knownRoundsStorageKey, id.calculateKrSize()); err != nil {
t.Errorf("Persistent identity did not store known rounds when "+ t.Errorf("Persistent identity did not store known rounds when "+
"it should: %+v", err) "it should: %+v", err)
...@@ -119,7 +118,7 @@ func TestNewRegistration_Persistent(t *testing.T) { ...@@ -119,7 +118,7 @@ func TestNewRegistration_Persistent(t *testing.T) {
} }
func TestLoadRegistration(t *testing.T) { func TestLoadRegistration(t *testing.T) {
//generate an identity for use // Generate an identity for use
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewSource(42))
timestamp := time.Date(2009, 11, 17, 20, timestamp := time.Date(2009, 11, 17, 20,
......
...@@ -25,7 +25,7 @@ const receptionIDSizeStorageVersion = 0 ...@@ -25,7 +25,7 @@ const receptionIDSizeStorageVersion = 0
const defaultIDSize = 12 const defaultIDSize = 12
type Store struct { type Store struct {
// identities which are being actively checked // Identities which are being actively checked
active []*registration active []*registration
idSize int idSize int
...@@ -40,7 +40,7 @@ type storedReference struct { ...@@ -40,7 +40,7 @@ type storedReference struct {
StartValid time.Time StartValid time.Time
} }
//creates a new reception store. It starts empty // NewStore creates a new reception store that starts empty.
func NewStore(kv *versioned.KV) *Store { func NewStore(kv *versioned.KV) *Store {
kv = kv.Prefix(receptionPrefix) kv = kv.Prefix(receptionPrefix)
s := &Store{ s := &Store{
...@@ -49,12 +49,12 @@ func NewStore(kv *versioned.KV)*Store{ ...@@ -49,12 +49,12 @@ func NewStore(kv *versioned.KV)*Store{
kv: kv, kv: kv,
} }
//store the empty list // Store the empty list
if err := s.save(); err != nil { if err := s.save(); err != nil {
jww.FATAL.Panicf("Failed to save new reception store: %+v", err) jww.FATAL.Panicf("Failed to save new reception store: %+v", err)
} }
//update the size so queries can be made // Update the size so queries can be made
s.UpdateIDSize(defaultIDSize) s.UpdateIDSize(defaultIDSize)
return s return s
...@@ -89,15 +89,15 @@ func LoadStore(kv *versioned.KV)*Store{ ...@@ -89,15 +89,15 @@ func LoadStore(kv *versioned.KV)*Store{
} }
} }
//load the ephmemeral ID length // Load the ephemeral ID length
vo, err = kv.Get(receptionIDSizeStorageKey) vo, err = kv.Get(receptionIDSizeStorageKey)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to get the reception id size: %+v", jww.FATAL.Panicf("Failed to get the reception ID size: %+v",
err) err)
} }
if s.idSize, err = strconv.Atoi(string(vo.Data)); err != nil { if s.idSize, err = strconv.Atoi(string(vo.Data)); err != nil {
jww.FATAL.Panicf("Failed to unmarshal the reception id size: %+v", jww.FATAL.Panicf("Failed to unmarshal the reception ID size: %+v",
err) err)
} }
...@@ -146,15 +146,15 @@ func (s *Store)GetIdentity(rng io.Reader)(IdentityUse, error){ ...@@ -146,15 +146,15 @@ func (s *Store)GetIdentity(rng io.Reader)(IdentityUse, error){
now := time.Now() now := time.Now()
//remove any now expired identities // Remove any now expired identities
s.prune(now) s.prune(now)
var identity IdentityUse var identity IdentityUse
var err error var err error
// if the list is empty, we return a randomly generated identity to poll // If the list is empty, then we return a randomly generated identity to
// with so we can continue tracking the network and to further obfuscate // poll with so we can continue tracking the network and to further
// network identities // obfuscate network identities.
if len(s.active) == 0 { if len(s.active) == 0 {
identity, err = generateFakeIdentity(rng, uint(s.idSize), now) identity, err = generateFakeIdentity(rng, uint(s.idSize), now)
if err != nil { if err != nil {
...@@ -164,14 +164,14 @@ func (s *Store)GetIdentity(rng io.Reader)(IdentityUse, error){ ...@@ -164,14 +164,14 @@ func (s *Store)GetIdentity(rng io.Reader)(IdentityUse, error){
} else { } else {
identity, err = s.selectIdentity(rng, now) identity, err = s.selectIdentity(rng, now)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to select an id: %+v", err) jww.FATAL.Panicf("Failed to select an ID: %+v", err)
} }
} }
//calculate the sampling period // Calculate the sampling period
identity, err = identity.setSamplingPeriod(rng) identity, err = identity.setSamplingPeriod(rng)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to caluclate the sampling period: " + jww.FATAL.Panicf("Failed to calculate the sampling period: "+
"%+v", err) "%+v", err)
} }
...@@ -226,7 +226,8 @@ func (s *Store)UpdateIDSize(idSize uint){ ...@@ -226,7 +226,8 @@ func (s *Store)UpdateIDSize(idSize uint){
s.mux.Lock() s.mux.Lock()
defer s.mux.Unlock() defer s.mux.Unlock()
s.idSize = int(idSize) s.idSize = int(idSize)
//store the id size
// Store the ID size
obj := &versioned.Object{ obj := &versioned.Object{
Version: receptionIDSizeStorageVersion, Version: receptionIDSizeStorageVersion,
Timestamp: time.Now(), Timestamp: time.Now(),
...@@ -242,7 +243,7 @@ func (s *Store)UpdateIDSize(idSize uint){ ...@@ -242,7 +243,7 @@ func (s *Store)UpdateIDSize(idSize uint){
func (s *Store) prune(now time.Time) { func (s *Store) prune(now time.Time) {
lengthBefore := len(s.active) lengthBefore := len(s.active)
//prune the list // Prune the list
for i := 0; i < len(s.active); i++ { for i := 0; i < len(s.active); i++ {
inQuestion := s.active[i] inQuestion := s.active[i]
if now.After(inQuestion.End) && inQuestion.ExtraChecks == 0 { if now.After(inQuestion.End) && inQuestion.ExtraChecks == 0 {
...@@ -257,7 +258,7 @@ func (s *Store)prune(now time.Time) { ...@@ -257,7 +258,7 @@ func (s *Store)prune(now time.Time) {
} }
} }
//save the list if it changed // Save the list if it changed
if lengthBefore != len(s.active) { if lengthBefore != len(s.active) {
if err := s.save(); err != nil { if err := s.save(); err != nil {
jww.FATAL.Panicf("Failed to store reception storage") jww.FATAL.Panicf("Failed to store reception storage")
...@@ -267,17 +268,16 @@ func (s *Store)prune(now time.Time) { ...@@ -267,17 +268,16 @@ func (s *Store)prune(now time.Time) {
func (s *Store) selectIdentity(rng io.Reader, now time.Time) (IdentityUse, error) { func (s *Store) selectIdentity(rng io.Reader, now time.Time) (IdentityUse, error) {
//choose a member from the list // Choose a member from the list
var selected *registration var selected *registration
if len(s.active) == 1 { if len(s.active) == 1 {
selected = s.active[0] selected = s.active[0]
} else { } else {
seed := make([]byte, 32) seed := make([]byte, 32)
if _, err := rng.Read(seed); err != nil { if _, err := rng.Read(seed); err != nil {
return IdentityUse{}, errors.WithMessage(err, "Failed to "+ return IdentityUse{}, errors.WithMessage(err, "Failed to "+
"choose id due to rng failure") "choose ID due to rng failure")
} }
h, err := hash.NewCMixHash() h, err := hash.NewCMixHash()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment