diff --git a/network/dataStructures/roundUpdates.go b/network/dataStructures/roundUpdates.go index ea688366af0cb1de5b0fb0858f468fabaf1e0aa0..67143cb4df2ea89731dbfdc5d1aaee6baa129464 100644 --- a/network/dataStructures/roundUpdates.go +++ b/network/dataStructures/roundUpdates.go @@ -2,7 +2,7 @@ package dataStructures import ( "github.com/pkg/errors" - "gitlab.com/elixxir/comms/mixmessages" + pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/primitives/ring" ) @@ -15,7 +15,8 @@ type Updates struct { } // Add a round to the ring buffer -func (u *Updates) AddRound(info *mixmessages.RoundInfo) error { +func (u *Updates) AddRound(info *pb.RoundInfo) error { + // comparison should ensure that updates are not overwritten in the event of a duplicate comp := func(current interface{}, new interface{}) bool { if current == nil { @@ -29,7 +30,7 @@ func (u *Updates) AddRound(info *mixmessages.RoundInfo) error { if val == nil { return -1 } - return int(val.(*mixmessages.RoundInfo).UpdateID) + return int(val.(*pb.RoundInfo).UpdateID) } if u.updates == nil { @@ -40,12 +41,31 @@ func (u *Updates) AddRound(info *mixmessages.RoundInfo) error { } // Get a given update ID from the ring buffer -func (u *Updates) GetUpdate(id int) (*mixmessages.RoundInfo, error) { +func (u *Updates) GetUpdate(id int) (*pb.RoundInfo, error) { + val, err := u.updates.GetById(id) if err != nil { return nil, errors.Wrapf(err, "Failed to get update with id %d", id) } - return val.(*mixmessages.RoundInfo), nil + return val.(*pb.RoundInfo), nil } +//gets all updates after a given ID +func (u *Updates)GetUpdates(id int)([]*pb.RoundInfo, error){ + interfaceList, err := u.updates.GetNewerById(id) + + if err!=nil{ + return nil, err + } + + infoList := make([]*pb.RoundInfo,len(interfaceList)) + + for i, face := range interfaceList{ + infoList[i] = face.(*pb.RoundInfo) + } + + return infoList, nil +} + + diff --git a/network/instance.go b/network/instance.go index 55cbe90fc2dd8f3fe6a58e0f328e7d5d61ad5c25..75deecda890787e1eb214c6626fb58f4bf269d18 100644 --- a/network/instance.go +++ b/network/instance.go @@ -102,7 +102,7 @@ func (i *Instance)GetRoundUpdate(updateID int)(*pb.RoundInfo, error){ return i.roundUpdates.GetUpdate(updateID) } -func (i *Instance)GetRoundUpdates(id id.Round)([]*pb.RoundInfo, error){ - return nil, nil +func (i *Instance)GetRoundUpdates(id int)([]*pb.RoundInfo, error){ + return i.roundUpdates.GetUpdates(id) } diff --git a/network/securedNdf_test.go b/network/securedNdf_test.go index 20972f9acb1eb104802d1ca1b3695fa2caa7dba4..89c3d20a27f5a1fc59d5efda51fd5d31c6cec418 100644 --- a/network/securedNdf_test.go +++ b/network/securedNdf_test.go @@ -9,6 +9,3 @@ func TestNewSecuredNdf(t *testing.T) { } } -func TestSecuredNdf_CompareHash(t *testing.T) { - -} \ No newline at end of file