Skip to content
Snippets Groups Projects
Commit 2a893f33 authored by Josh Brooks's avatar Josh Brooks
Browse files

Respond to MR comments: Add functionality to dataStructures, fix tests

parent e08a127d
Branches
Tags
1 merge request!58Revert "Modify waiting lock"
......@@ -33,6 +33,19 @@ func NewRound(ri *pb.RoundInfo, pubkey *rsa.PublicKey) *Round {
}
}
// Constructor of an already verified round object
// Intended for use by round creator.
func NewVerifiedRound(ri *pb.RoundInfo, pubkey *rsa.PublicKey) *Round {
jww.WARN.Print("NewVerifiedRound is intended for use by round creator")
// Set validation to done on creation
validationDefault := uint32(1)
return &Round{
info: ri,
needsValidation: &validationDefault,
pubkey: pubkey,
}
}
// Get returns the round info object. If we have not
// validated the signature before, we then verify.
// Later calls will not need validation
......
......@@ -40,7 +40,7 @@ func (d *Data) UpsertRound(r *Round) error {
return d.rounds.UpsertById(int(r.info.ID), r)
}
// Get a given round id from the ring buffer
// Get a given round id from the ring buffer as a roundInfo
func (d *Data) GetRound(id int) (*mixmessages.RoundInfo, error) {
val, err := d.rounds.GetById(id)
if err != nil {
......@@ -48,7 +48,20 @@ func (d *Data) GetRound(id int) (*mixmessages.RoundInfo, error) {
}
var rtn *mixmessages.RoundInfo
if val != nil {
rtn = val.(*Round).info
rtn = val.(*Round).Get()
}
return rtn, nil
}
// Get a given round id from the ring buffer as a round object
func (d *Data) GetWrappedRound(id int) (*Round, error) {
val, err := d.rounds.GetById(id)
if err != nil {
return nil, errors.Wrapf(err, "Failed to get update with id %d", id)
}
var rtn *Round
if val != nil {
rtn = val.(*Round)
}
return rtn, nil
}
......
......@@ -42,6 +42,7 @@ func TestData_GetRound(t *testing.T) {
ID: 0,
UpdateID: 0,
}
testutils.SignRoundInfo(ri, t)
pubKey, err := testutils.LoadPublicKeyTesting(t)
if err != nil {
......@@ -65,6 +66,7 @@ func TestData_ComparisonFunc(t *testing.T) {
ID: 2,
UpdateID: 3,
}
testutils.SignRoundInfo(roundInfoOne, t)
pubKey, err := testutils.LoadPublicKeyTesting(t)
if err != nil {
......@@ -79,6 +81,8 @@ func TestData_ComparisonFunc(t *testing.T) {
ID: 2,
UpdateID: 4,
}
testutils.SignRoundInfo(roundInfoTwo, t)
roundTwo := NewRound(roundInfoTwo, pubKey)
_ = d.UpsertRound(roundTwo)
r, err := d.GetRound(2)
......
......@@ -135,8 +135,11 @@ func (r *RoundEvents) TriggerRoundEvent(rnd *Round) {
return
}
for _, event := range callbacks[rnd.info.State] {
// Retrieve and validate the round info
event.signal <- rnd.Get()
roundInfo := rnd.Get()
// Send round info to every event in the list
for _, event := range callbacks[rnd.info.State] {
event.signal <- roundInfo
}
}
......@@ -155,6 +155,7 @@ func TestInstance_GetRound(t *testing.T) {
// Construct a mock round object
ri := &mixmessages.RoundInfo{ID: uint64(1)}
testutils.SignRoundInfo(ri, t)
pubKey, err := testutils.LoadPublicKeyTesting(t)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment