From eaccae5f8a830bba8ba7a2a1f963709f6cff311e Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Sat, 29 Feb 2020 14:14:29 -0800 Subject: [PATCH] added the ability to get round updates --- network/dataStructures/roundUpdates.go | 30 +++++++++++++++++++++----- network/instance.go | 4 ++-- network/securedNdf_test.go | 3 --- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/network/dataStructures/roundUpdates.go b/network/dataStructures/roundUpdates.go index ea688366..67143cb4 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 55cbe90f..75deecda 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 20972f9a..89c3d20a 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 -- GitLab