Skip to content
Snippets Groups Projects
Select Git revision
  • 3e9db936bd1ebf7c42d4c308520002b9b8a157a8
  • release default protected
  • master protected
  • NationalTreasure/NotificationUpgrade
  • XX-4441
  • xx-4417/gw-poll-earliest-client-round
  • tls-websockets
  • hotfix/drain
  • hotfix/matcher
  • projects/crust_RELEASE
  • XX-4055/ChannelIdentityTracking
  • XX-4066/CrustUpgrade_MASTER
  • Ace/Huawei
  • hotfix/accumulate-notifs
  • XX-3564/TlsCipherSuite
  • hotfix/groupNotification
  • Anne/License-Update
  • hotfix/trustoldgatewaysonly
  • hotfix/notifications
  • notls
  • url-repo-rename
  • v0.0.4
  • v0.0.3
  • v0.0.2
  • v0.0.1
25 results

group_test.go

Blame
  • IdentityUse.go 1.72 KiB
    package reception
    
    import (
    	"github.com/pkg/errors"
    	"gitlab.com/elixxir/crypto/hash"
    	"gitlab.com/elixxir/primitives/knownRounds"
    	"gitlab.com/xx_network/crypto/randomness"
    	"gitlab.com/xx_network/primitives/id"
    	"io"
    	"math/big"
    	"time"
    )
    
    type IdentityUse struct{
    	Identity
    
    	//randomly generated time to poll between
    	StartRequest time.Time	//timestamp to request the start 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
    	// messages
    	Fake bool
    
    	//rounds data
    	KR KnownRounds
    }
    
    // setSamplingPeriod add the Request mask as a random buffer around the sampling
    // time to obfuscate it
    func (iu IdentityUse)setSamplingPeriod(rng io.Reader)(IdentityUse, error){
    
    	//generate the seed
    	seed := make([]byte,32)
    	if _, err := rng.Read(seed);err!=nil{
    		return IdentityUse{}, errors.WithMessage(err, "Failed to " +
    			"choose id due to rng failure")
    	}
    
    	h, err := hash.NewCMixHash()
    	if err!=nil{
    		return IdentityUse{}, err
    	}
    
    	//calculate the period offset
    	periodOffset :=
    		randomness.RandInInterval(big.NewInt(iu.RequestMask.Nanoseconds()),
    			seed,h).Int64()
    	iu.StartRequest = iu.StartValid.Add(-time.Duration(periodOffset))
    	iu.EndRequest = iu.EndValid.Add(iu.RequestMask -
    		time.Duration(periodOffset))
    	return iu, nil
    }
    
    type KnownRounds interface{
    	Checked(rid id.Round) bool
    	Check(rid id.Round)
    	Forward(rid id.Round)
    	RangeUnchecked(newestRid id.Round, roundCheck func(id id.Round) bool)
    	RangeUncheckedMasked(mask *knownRounds.KnownRounds,
    		roundCheck knownRounds.RoundCheckFunc, maxChecked int)
    	RangeUncheckedMaskedRange(mask *knownRounds.KnownRounds,
    		roundCheck knownRounds.RoundCheckFunc, start, end id.Round, maxChecked int)
    }