Skip to content
Snippets Groups Projects
Commit 1a8e02eb authored by Jonah Husson's avatar Jonah Husson
Browse files

Add a New func to datastructures

parent ef8ffb34
No related branches found
No related tags found
No related merge requests found
...@@ -5,14 +5,20 @@ go 1.13 ...@@ -5,14 +5,20 @@ go 1.13
require ( require (
github.com/golang/protobuf v1.3.4 github.com/golang/protobuf v1.3.4
github.com/google/go-cmp v0.4.0 // indirect github.com/google/go-cmp v0.4.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
gitlab.com/elixxir/crypto v0.0.0-20200229000841-b1ee7117a1d0 github.com/stretchr/testify v1.5.1 // indirect
gitlab.com/elixxir/primitives v0.0.0-20200306214728-35300c4b5152 gitlab.com/elixxir/crypto v0.0.0-20200206203107-b8926242da23
gitlab.com/elixxir/primitives v0.0.0-20200226191544-59ff3303abb3
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect
golang.org/x/net v0.0.0-20200301022130-244492dfa37a golang.org/x/net v0.0.0-20200301022130-244492dfa37a
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
golang.org/x/text v0.3.2 // indirect golang.org/x/text v0.3.2 // indirect
google.golang.org/genproto v0.0.0-20200306153348-d950eab6f860 // indirect google.golang.org/genproto v0.0.0-20200306153348-d950eab6f860 // indirect
google.golang.org/grpc v1.27.1 google.golang.org/grpc v1.27.1
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
) )
replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1 replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1
...@@ -48,16 +48,15 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy ...@@ -48,16 +48,15 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
gitlab.com/elixxir/crypto v0.0.0-20200229000841-b1ee7117a1d0 h1:2oq/Y1pA3bwCdlRjhFjoOtb2somDY+wYz2vuiOQkVVA= gitlab.com/elixxir/crypto v0.0.0-20200206203107-b8926242da23 h1:J9MKdOxLGzDZoLy2Q0CAxPlPjSH+k4NG3JhgvatAZjo=
gitlab.com/elixxir/crypto v0.0.0-20200229000841-b1ee7117a1d0/go.mod h1:QPClJr3F90ejz6iHaCZuhexytd6PP97dDnt93iRCTDo= gitlab.com/elixxir/crypto v0.0.0-20200206203107-b8926242da23/go.mod h1:wWulHuSqxiGhvasduZrtyTTqy+7y5ebe440GdORhzig=
gitlab.com/elixxir/primitives v0.0.0-20200218211222-4193179f359c/go.mod h1:REJMcwIcyxh74VSHqy4S9yYiaEsQYObOPglRExDpk14= gitlab.com/elixxir/primitives v0.0.0-20200131183153-e93c6b75019f/go.mod h1:REJMcwIcyxh74VSHqy4S9yYiaEsQYObOPglRExDpk14=
gitlab.com/elixxir/primitives v0.0.0-20200306214728-35300c4b5152 h1:RqT4XSphs+73DWvdKaWlTI8qY6eUdkG9LfTli+qukjU= gitlab.com/elixxir/primitives v0.0.0-20200226191544-59ff3303abb3 h1:572R0Ap/rYmC6XNNQeoZfvfqXyuiRENidgUzdpCbFHw=
gitlab.com/elixxir/primitives v0.0.0-20200306214728-35300c4b5152/go.mod h1:vx+QS3daQGu4WrHMU6IOuddbpJQnEOhbDyhYdHm/nNQ= gitlab.com/elixxir/primitives v0.0.0-20200226191544-59ff3303abb3/go.mod h1:REJMcwIcyxh74VSHqy4S9yYiaEsQYObOPglRExDpk14=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg=
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
...@@ -78,7 +77,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h ...@@ -78,7 +77,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
......
...@@ -20,6 +20,20 @@ type Data struct { ...@@ -20,6 +20,20 @@ type Data struct {
rounds *ring.Buff rounds *ring.Buff
} }
func NewData() *Data {
// We want data using the round ID as its primary
idFunc := func(val interface{}) int {
if val == nil {
return -1
}
return int(val.(*mixmessages.RoundInfo).ID)
}
return &Data{
rounds: ring.NewBuff(RoundInfoBufLen, idFunc),
}
}
// Upsert a round into the ring bugger // Upsert a round into the ring bugger
func (d *Data) UpsertRound(r *mixmessages.RoundInfo) error { func (d *Data) UpsertRound(r *mixmessages.RoundInfo) error {
// comparison here should ensure that either the current round is nil or has a lower update id than the new round // comparison here should ensure that either the current round is nil or has a lower update id than the new round
...@@ -33,18 +47,6 @@ func (d *Data) UpsertRound(r *mixmessages.RoundInfo) error { ...@@ -33,18 +47,6 @@ func (d *Data) UpsertRound(r *mixmessages.RoundInfo) error {
return false return false
} }
// We want data using the round ID as its primary
id := func(val interface{}) int {
if val == nil {
return -1
}
return int(val.(*mixmessages.RoundInfo).ID)
}
if d.rounds == nil {
d.rounds = ring.NewBuff(RoundInfoBufLen, id)
}
//find the round location //find the round location
//check the new state is newer then the current //check the new state is newer then the current
//replace the round info object //replace the round info object
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
) )
func TestData_UpsertRound(t *testing.T) { func TestData_UpsertRound(t *testing.T) {
d := Data{} d := NewData()
err := d.UpsertRound(&mixmessages.RoundInfo{ err := d.UpsertRound(&mixmessages.RoundInfo{
ID: 0, ID: 0,
UpdateID: 0, UpdateID: 0,
...@@ -23,7 +23,7 @@ func TestData_UpsertRound(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestData_UpsertRound(t *testing.T) {
} }
func TestData_GetRound(t *testing.T) { func TestData_GetRound(t *testing.T) {
d := Data{} d := NewData()
_ = d.UpsertRound(&mixmessages.RoundInfo{ _ = d.UpsertRound(&mixmessages.RoundInfo{
ID: 0, ID: 0,
UpdateID: 3, UpdateID: 3,
...@@ -35,7 +35,7 @@ func TestData_GetRound(t *testing.T) { ...@@ -35,7 +35,7 @@ func TestData_GetRound(t *testing.T) {
} }
func TestData_ComparisonFunc(t *testing.T) { func TestData_ComparisonFunc(t *testing.T) {
d := Data{} d := NewData()
_ = d.UpsertRound(&mixmessages.RoundInfo{ _ = d.UpsertRound(&mixmessages.RoundInfo{
ID: 2, ID: 2,
UpdateID: 3, UpdateID: 3,
......
...@@ -22,6 +22,19 @@ type Updates struct { ...@@ -22,6 +22,19 @@ type Updates struct {
updates *ring.Buff updates *ring.Buff
} }
func NewUpdates() *Updates {
// we want each updateId stored in this structure
idFunc := func(val interface{}) int {
if val == nil {
return -1
}
return int(val.(*pb.RoundInfo).UpdateID)
}
return &Updates{
updates: ring.NewBuff(RoundUpdatesBufLen, idFunc),
}
}
// Add a round to the ring buffer // Add a round to the ring buffer
func (u *Updates) AddRound(info *pb.RoundInfo) error { func (u *Updates) AddRound(info *pb.RoundInfo) error {
...@@ -33,18 +46,6 @@ func (u *Updates) AddRound(info *pb.RoundInfo) error { ...@@ -33,18 +46,6 @@ func (u *Updates) AddRound(info *pb.RoundInfo) error {
return false return false
} }
// we want each updateId stored in this structure
id := func(val interface{}) int {
if val == nil {
return -1
}
return int(val.(*pb.RoundInfo).UpdateID)
}
if u.updates == nil {
u.updates = ring.NewBuff(RoundUpdatesBufLen, id)
}
return u.updates.UpsertById(info, comp) return u.updates.UpsertById(info, comp)
} }
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
) )
func TestUpdates_AddRound(t *testing.T) { func TestUpdates_AddRound(t *testing.T) {
u := Updates{} u := NewUpdates()
err := u.AddRound(&mixmessages.RoundInfo{ err := u.AddRound(&mixmessages.RoundInfo{
ID: 0, ID: 0,
UpdateID: 0, UpdateID: 0,
...@@ -23,7 +23,7 @@ func TestUpdates_AddRound(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestUpdates_AddRound(t *testing.T) {
} }
func TestUpdates_GetUpdate(t *testing.T) { func TestUpdates_GetUpdate(t *testing.T) {
u := Updates{} u := NewUpdates()
_ = u.AddRound(&mixmessages.RoundInfo{ _ = u.AddRound(&mixmessages.RoundInfo{
ID: 0, ID: 0,
UpdateID: 3, UpdateID: 3,
...@@ -35,7 +35,7 @@ func TestUpdates_GetUpdate(t *testing.T) { ...@@ -35,7 +35,7 @@ func TestUpdates_GetUpdate(t *testing.T) {
} }
func TestUpdates_GetUpdates(t *testing.T) { func TestUpdates_GetUpdates(t *testing.T) {
u := Updates{} u := NewUpdates()
_ = u.AddRound(&mixmessages.RoundInfo{ _ = u.AddRound(&mixmessages.RoundInfo{
ID: 0, ID: 0,
UpdateID: 3, UpdateID: 3,
......
...@@ -72,8 +72,8 @@ func NewInstance(c *connect.ProtoComms, partial, full *ndf.NetworkDefinition) (* ...@@ -72,8 +72,8 @@ func NewInstance(c *connect.ProtoComms, partial, full *ndf.NetworkDefinition) (*
comm: c, comm: c,
partial: partialNdf, partial: partialNdf,
full: fullNdf, full: fullNdf,
roundUpdates: &ds.Updates{}, roundUpdates: ds.NewUpdates(),
roundData: &ds.Data{}, roundData: ds.NewData(),
cmixGroup: ds.NewGroup(), cmixGroup: ds.NewGroup(),
e2eGroup: ds.NewGroup(), e2eGroup: ds.NewGroup(),
}, nil }, nil
......
...@@ -67,7 +67,7 @@ func TestInstance_GetPartialNdf(t *testing.T) { ...@@ -67,7 +67,7 @@ func TestInstance_GetPartialNdf(t *testing.T) {
func TestInstance_GetRound(t *testing.T) { func TestInstance_GetRound(t *testing.T) {
i := Instance{ i := Instance{
roundData: &ds.Data{}, roundData: ds.NewData(),
} }
_ = i.roundData.UpsertRound(&mixmessages.RoundInfo{ID: uint64(1)}) _ = i.roundData.UpsertRound(&mixmessages.RoundInfo{ID: uint64(1)})
r, err := i.GetRound(id.Round(1)) r, err := i.GetRound(id.Round(1))
...@@ -78,7 +78,7 @@ func TestInstance_GetRound(t *testing.T) { ...@@ -78,7 +78,7 @@ func TestInstance_GetRound(t *testing.T) {
func TestInstance_GetRoundUpdate(t *testing.T) { func TestInstance_GetRoundUpdate(t *testing.T) {
i := Instance{ i := Instance{
roundUpdates: &ds.Updates{}, roundUpdates: ds.NewUpdates(),
} }
_ = i.roundUpdates.AddRound(&mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)}) _ = i.roundUpdates.AddRound(&mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)})
r, err := i.GetRoundUpdate(1) r, err := i.GetRoundUpdate(1)
...@@ -89,7 +89,7 @@ func TestInstance_GetRoundUpdate(t *testing.T) { ...@@ -89,7 +89,7 @@ func TestInstance_GetRoundUpdate(t *testing.T) {
func TestInstance_GetRoundUpdates(t *testing.T) { func TestInstance_GetRoundUpdates(t *testing.T) {
i := Instance{ i := Instance{
roundUpdates: &ds.Updates{}, roundUpdates: ds.NewUpdates(),
} }
_ = i.roundUpdates.AddRound(&mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)}) _ = i.roundUpdates.AddRound(&mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)})
_ = i.roundUpdates.AddRound(&mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(2)}) _ = i.roundUpdates.AddRound(&mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(2)})
...@@ -184,7 +184,7 @@ func TestInstance_UpdatePartialNdf(t *testing.T) { ...@@ -184,7 +184,7 @@ func TestInstance_UpdatePartialNdf(t *testing.T) {
func TestInstance_GetLastRoundID(t *testing.T) { func TestInstance_GetLastRoundID(t *testing.T) {
i := Instance{ i := Instance{
roundData: &ds.Data{}, roundData: ds.NewData(),
} }
_ = i.roundData.UpsertRound(&mixmessages.RoundInfo{ID: uint64(1)}) _ = i.roundData.UpsertRound(&mixmessages.RoundInfo{ID: uint64(1)})
i.GetLastRoundID() i.GetLastRoundID()
...@@ -192,7 +192,7 @@ func TestInstance_GetLastRoundID(t *testing.T) { ...@@ -192,7 +192,7 @@ func TestInstance_GetLastRoundID(t *testing.T) {
func TestInstance_GetLastUpdateID(t *testing.T) { func TestInstance_GetLastUpdateID(t *testing.T) {
i := Instance{ i := Instance{
roundUpdates: &ds.Updates{}, roundUpdates: ds.NewUpdates(),
} }
_ = i.roundUpdates.AddRound(&mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)}) _ = i.roundUpdates.AddRound(&mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)})
i.GetLastUpdateID() i.GetLastUpdateID()
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
package network package network
import ( import (
"fmt"
"github.com/pkg/errors" "github.com/pkg/errors"
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
ds "gitlab.com/elixxir/comms/network/dataStructures" ds "gitlab.com/elixxir/comms/network/dataStructures"
...@@ -39,7 +38,6 @@ func NewSecuredNdf(definition *ndf.NetworkDefinition) (*SecuredNdf, error) { ...@@ -39,7 +38,6 @@ func NewSecuredNdf(definition *ndf.NetworkDefinition) (*SecuredNdf, error) {
func (sndf *SecuredNdf) update(m *pb.NDF, key *rsa.PublicKey) error { func (sndf *SecuredNdf) update(m *pb.NDF, key *rsa.PublicKey) error {
err := signature.Verify(m, key) err := signature.Verify(m, key)
if err != nil { if err != nil {
fmt.Printf("err: %+v", err)
return errors.WithMessage(err, "Could not validate NDF") return errors.WithMessage(err, "Could not validate NDF")
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package network package network
import ( import (
"fmt"
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
ds "gitlab.com/elixxir/comms/network/dataStructures" ds "gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/comms/testutils" "gitlab.com/elixxir/comms/testutils"
...@@ -51,6 +52,7 @@ func TestSecuredNdf_update(t *testing.T) { ...@@ -51,6 +52,7 @@ func TestSecuredNdf_update(t *testing.T) {
t.Errorf("Could not generate rsa key: %s", err) t.Errorf("Could not generate rsa key: %s", err)
} }
badPub := badPriv.GetPublic() badPub := badPriv.GetPublic()
fmt.Println(badPub)
f := pb.NDF{} f := pb.NDF{}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment