diff --git a/bindings/group.go b/bindings/group.go index 729aac8781d24258e61a077b01ee4eb5a43baec6..a1f32b34e9c613bbb4357f6c2705ee930a7d3c01 100644 --- a/bindings/group.go +++ b/bindings/group.go @@ -64,10 +64,10 @@ func NewGroupManager(client *Client, requestFunc GroupRequestFunc, // MakeGroup creates a new group and sends a group request to all members in the // group. The ID of the new group, the rounds the requests were sent on, and the // status of the send are contained in NewGroupReport. -func (g *GroupChat) MakeGroup(membership *IdList, name, message []byte)*NewGroupReport { +func (g *GroupChat) MakeGroup(membership *IdList, name, message []byte) *NewGroupReport { grp, rounds, status, err := g.m.MakeGroup(membership.list, name, message) errStr := "" - if err !=nil{ + if err != nil { errStr = err.Error() } return &NewGroupReport{&Group{grp}, rounds, status, errStr} @@ -83,14 +83,14 @@ func (g *GroupChat) ResendRequest(groupIdBytes []byte) (*NewGroupReport, error) } grp, exists := g.m.GetGroup(groupID) - if !exists{ - return nil,errors.Errorf("Failed to find group %s", groupID) + if !exists { + return nil, errors.Errorf("Failed to find group %s", groupID) } rounds, status, err := g.m.ResendRequest(groupID) errStr := "" - if err !=nil{ + if err != nil { errStr = err.Error() } return &NewGroupReport{&Group{grp}, rounds, status, errStr}, nil @@ -166,11 +166,11 @@ type NewGroupReport struct { group *Group rounds []id.Round status gc.RequestStatus - err string + err string } type GroupReportDisk struct { - List []id.Round + List []id.Round GrpId []byte Status int } @@ -201,10 +201,9 @@ func (ngr *NewGroupReport) GetError() string { return ngr.err } - func (ngr *NewGroupReport) Marshal() ([]byte, error) { grpReportDisk := GroupReportDisk{ - List: ngr.rounds, + List: ngr.rounds, GrpId: ngr.group.GetID()[:], Status: ngr.GetStatus(), } diff --git a/bindings/ndf_test.go b/bindings/ndf_test.go index d05bc5614e41a400e2a3df3bc819d4f091afb088..3f7c68f26079621e63fe864587da5072ad04b22b 100644 --- a/bindings/ndf_test.go +++ b/bindings/ndf_test.go @@ -17,37 +17,38 @@ import ( ) var testCert = `-----BEGIN CERTIFICATE----- -MIIFtj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PoXI9Hnyxa +8wIDAQABozgwNjAVBgNVHREEDjAMggplbGl4eGlyLmlvMB0GA1UdDgQWBBQimFud +gCzDVFD3Xz68zOAebDN6YDANBgkqhkiG9w0BAQsFAAOCAgEAccsH9JIyFZdytGxC +/6qjSHPgV23ZGmW7alg+GyEATBIAN187Du4Lj6cLbox5nqLdZgYzizVop32JQAHv +N1QPKjViOOkLaJprSUuRULa5kJ5fe+XfMoyhISI4mtJXXbMwl/PbOaDSdeDjl0ZO +auQggWslyv8ZOkfcbC6goEtAxljNZ01zY1ofSKUj+fBw9Lmomql6GAt7NuubANs4 +9mSjXwD27EZf3Aqaaju7gX1APW2O03/q4hDqhrGW14sN0gFt751ddPuPr5COGzCS +c3Xg2HqMpXx//FU4qHrZYzwv8SuGSshlCxGJpWku9LVwci1Kxi4LyZgTm6/xY4kB +5fsZf6C2yAZnkIJ8bEYr0Up4KzG1lNskU69uMv+d7W2+4Ie3Evf3HdYad/WeUskG +tc6LKY6B2NX3RMVkQt0ftsDaWsktnR8VBXVZSBVYVEQu318rKvYRdOwZJn339obI +jyMZC/3D721e5Anj/EqHpc3I9Yn3jRKw1xc8kpNLg/JIAibub8JYyDvT1gO4xjBO ++6EWOBFgDAsf7bSP2xQn1pQFWcA/sY1MnRsWeENmKNrkLXffP+8l1tEcijN+KCSF +ek1mr+qBwSaNV9TA+RXVhvqd3DEKPPJ1WhfxP1K81RdUESvHOV/4kdwnSahDyao0 +EnretBzQkeKeBwoB2u6NTiOmUjk= -----END CERTIFICATE----- ` @@ -55,7 +56,9 @@ pipz4Cfpkoc1Gc8xx91iBsWYBpqu4p7SXDU= // Ensure validity by unmarshalling NDF and checking the scheduling's cert. func TestDownloadSignedNdfWithUrl(t *testing.T) { // Download and verify the cert with the specified URL - content, err := DownloadAndVerifySignedNdfWithUrl("https://elixxir-bins.s3.us-west-1.amazonaws.com/ndf/default.json", testCert) + content, err := DownloadAndVerifySignedNdfWithUrl( + "https://elixxir-bins.s3.us-west-1.amazonaws.com/ndf/default.json", + testCert) if err != nil { t.Errorf("Failed to download signed NDF: %v", err) } diff --git a/go.mod b/go.mod index 27a55715ff942c4cbdc2bd6fcd82ce1694ebcbd7..a2b6fb5b3d2ea0c02683aca204d1a5a8185c9143 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,11 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.7.1 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 - gitlab.com/elixxir/comms v0.0.4-0.20211101174956-590ba1b47887 - gitlab.com/elixxir/crypto v0.0.7-0.20211118181958-04390d5356fa + gitlab.com/elixxir/comms v0.0.4-0.20211202201624-2921e9475e8d + gitlab.com/elixxir/crypto v0.0.7-0.20211202201519-0fbe24cb7f1c gitlab.com/elixxir/ekv v0.1.5 gitlab.com/elixxir/primitives v0.0.3-0.20211111194525-20889b10db75 - gitlab.com/xx_network/comms v0.0.4-0.20211014163953-e774276b83ae + gitlab.com/xx_network/comms v0.0.4-0.20211202195810-9dfc0b6cdb28 gitlab.com/xx_network/crypto v0.0.5-0.20211014163843-57b345890686 gitlab.com/xx_network/primitives v0.0.4-0.20211014163031-53405cf191fb golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 diff --git a/go.sum b/go.sum index 3fec2e96ed182103a775e254ff4bafa318b1d2f3..794015cf2309875b28e1457336536ddeaa635431 100644 --- a/go.sum +++ b/go.sum @@ -253,25 +253,23 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0BJIk1HIzBVMjWNjIUfstrsXC2VqLYPcA= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= -gitlab.com/elixxir/comms v0.0.4-0.20211101174956-590ba1b47887 h1:SOQaoEvc6RqImz86jSjsj7wIW3ZhgxXc38GzvRkKdOw= -gitlab.com/elixxir/comms v0.0.4-0.20211101174956-590ba1b47887/go.mod h1:rQpTeFVSn08ocbQeEw5AbMhGWXHfXmQ0y1/ZprAIVVU= +gitlab.com/elixxir/comms v0.0.4-0.20211202201624-2921e9475e8d h1:GeDe5T0RWeKAnwhS0wRASEWEYtwEtQNOKFfrR//p6pE= +gitlab.com/elixxir/comms v0.0.4-0.20211202201624-2921e9475e8d/go.mod h1:Duc4bfizNRWQlmOIQY198Nm+SPDBWroF4AHCEpQXFUw= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= -gitlab.com/elixxir/crypto v0.0.7-0.20211022013957-3a7899285c4c/go.mod h1:teuTEXyqsqo4N/J1sshcTg9xYOt+wNTurop7pkZOiCg= -gitlab.com/elixxir/crypto v0.0.7-0.20211118181958-04390d5356fa h1:XwoFEIRO4QXpKzeBZehebO/9kU/C3xew/MS5yDyvu1o= -gitlab.com/elixxir/crypto v0.0.7-0.20211118181958-04390d5356fa/go.mod h1:teuTEXyqsqo4N/J1sshcTg9xYOt+wNTurop7pkZOiCg= +gitlab.com/elixxir/crypto v0.0.7-0.20211202201519-0fbe24cb7f1c h1:0rYVebZGkSiMf9vfg0RyUVgJJ36QdnLhdo+9c8wAhrQ= +gitlab.com/elixxir/crypto v0.0.7-0.20211202201519-0fbe24cb7f1c/go.mod h1:58ZxWaMzTmgP6gWkiGSXVL8qIw5cnVAdlgIpbZ/olMU= gitlab.com/elixxir/ekv v0.1.5 h1:R8M1PA5zRU1HVnTyrtwybdABh7gUJSCvt1JZwUSeTzk= gitlab.com/elixxir/ekv v0.1.5/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= gitlab.com/elixxir/primitives v0.0.0-20200804170709-a1896d262cd9/go.mod h1:p0VelQda72OzoUckr1O+vPW0AiFe0nyKQ6gYcmFSuF8= gitlab.com/elixxir/primitives v0.0.0-20200804182913-788f47bded40/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc= gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE= -gitlab.com/elixxir/primitives v0.0.3-0.20211014164029-06022665b576/go.mod h1:zZy8AlOISFm5IG4G4sylypnz7xNBfZ5mpXiibqJT8+8= gitlab.com/elixxir/primitives v0.0.3-0.20211111194525-20889b10db75 h1:LQ9EmPJvm7T6WxwNltjnYKLF0QSYCrS+hyteb8Dfttk= gitlab.com/elixxir/primitives v0.0.3-0.20211111194525-20889b10db75/go.mod h1:zZy8AlOISFm5IG4G4sylypnz7xNBfZ5mpXiibqJT8+8= gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw= -gitlab.com/xx_network/comms v0.0.4-0.20211014163953-e774276b83ae h1:jmZWmSm8eH40SX5B5uOw2XaYoHYqVn8daTfa6B80AOs= -gitlab.com/xx_network/comms v0.0.4-0.20211014163953-e774276b83ae/go.mod h1:wR9Vx0KZLrIs0g2Efcp0UwFPStjcDRWkg/DJLVQI2vw= +gitlab.com/xx_network/comms v0.0.4-0.20211202195810-9dfc0b6cdb28 h1:CEZJfCiV6F6GQnWiYqoEjlzL2KpLipRy/ccV2smgf0E= +gitlab.com/xx_network/comms v0.0.4-0.20211202195810-9dfc0b6cdb28/go.mod h1:wR9Vx0KZLrIs0g2Efcp0UwFPStjcDRWkg/DJLVQI2vw= gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE= gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk= gitlab.com/xx_network/crypto v0.0.5-0.20211014163843-57b345890686 h1:mEjKISxi9LrguYgz6evroFwsfxH78/hYmr32yws+WV0= diff --git a/interfaces/preimage/generate.go b/interfaces/preimage/generate.go index 476e6b7157c8953ac82a572e119f725c0a081475..84798d696a8b2311e6e89b01f64c885eb6c2d5b8 100644 --- a/interfaces/preimage/generate.go +++ b/interfaces/preimage/generate.go @@ -7,7 +7,7 @@ import ( func Generate(data []byte, t string) []byte { - if t==Default{ + if t == Default { return data } // Hash fingerprints diff --git a/network/gateway/hostpool_test.go b/network/gateway/hostpool_test.go index 919d3faedbada3445219de4886fc84ba2362cdeb..5e93ba8df80ded94f70034bdc6ba3540ac6d1644 100644 --- a/network/gateway/hostpool_test.go +++ b/network/gateway/hostpool_test.go @@ -9,6 +9,7 @@ package gateway import ( "fmt" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/crypto/fastRNG" @@ -16,10 +17,17 @@ import ( "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/ndf" + "os" "reflect" "testing" ) +func TestMain(m *testing.M) { + jww.SetStdoutThreshold(jww.LevelTrace) + connect.TestingOnlyDisableTLS = true + os.Exit(m.Run()) +} + // Unit test func TestNewHostPool(t *testing.T) { manager := newMockManager() diff --git a/network/manager.go b/network/manager.go index bb69e30a5154ec09e4d029d6c797171d088e01fb..c968102e2f5b04269c123c5d1b624ae7a865678a 100644 --- a/network/manager.go +++ b/network/manager.go @@ -99,10 +99,10 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, earliest := uint64(0) // create manager object m := manager{ - param: params, - tracker: &tracker, - addrSpace: ephemeral.NewAddressSpace(), - events: events, + param: params, + tracker: &tracker, + addrSpace: ephemeral.NewAddressSpace(), + events: events, earliestRound: &earliest, } @@ -258,19 +258,18 @@ func (m *manager) GetVerboseRounds() string { return m.verboseRounds.String() } - -func (m *manager) SetFakeEarliestRound(rnd id.Round) { +func (m *manager) SetFakeEarliestRound(rnd id.Round) { atomic.StoreUint64(m.earliestRound, uint64(rnd)) } // GetFakeEarliestRound generates a random earliest round for a fake identity. -func (m *manager) GetFakeEarliestRound() id.Round { +func (m *manager) GetFakeEarliestRound() id.Round { b, err := csprng.Generate(8, rand.Reader) if err != nil { jww.FATAL.Panicf("Could not get random number: %v", err) } - rangeVal := binary.LittleEndian.Uint64(b) % 800 + rangeVal := binary.LittleEndian.Uint64(b) % 800 earliestKnown := atomic.LoadUint64(m.earliestRound) diff --git a/network/message/garbled_test.go b/network/message/garbled_test.go index b651c02e041f68467799d02d7892e4916f032042..45a0a98fc672a2df88e0076116237c7a6ff0c0c5 100644 --- a/network/message/garbled_test.go +++ b/network/message/garbled_test.go @@ -2,6 +2,7 @@ package message import ( "encoding/binary" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/network/gateway" @@ -13,13 +14,21 @@ import ( "gitlab.com/elixxir/comms/client" "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/primitives/format" + "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/netTime" "math/rand" + "os" "testing" "time" ) +func TestMain(m *testing.M) { + jww.SetStdoutThreshold(jww.LevelTrace) + connect.TestingOnlyDisableTLS = true + os.Exit(m.Run()) +} + type TestListener struct { ch chan bool } diff --git a/network/rounds/remoteFilters_test.go b/network/rounds/remoteFilters_test.go index 924f7f970d9dd3c9f8d915b4f3f1f3524417de11..a04d7f51c7f580402744fef7a5b1f128d5f23332 100644 --- a/network/rounds/remoteFilters_test.go +++ b/network/rounds/remoteFilters_test.go @@ -8,17 +8,26 @@ package rounds import ( + jww "github.com/spf13/jwalterweatherman" bloom "gitlab.com/elixxir/bloomfilter" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/storage/reception" "gitlab.com/elixxir/comms/mixmessages" + "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "os" "reflect" "testing" "time" ) +func TestMain(m *testing.M) { + jww.SetStdoutThreshold(jww.LevelTrace) + connect.TestingOnlyDisableTLS = true + os.Exit(m.Run()) +} + // Unit test NewRemoteFilter func TestNewRemoteFilter(t *testing.T) { bloomFilter := &mixmessages.ClientBloom{ diff --git a/registration/permissioning_test.go b/registration/permissioning_test.go index 56083a5dd302c22872d1e172c67124bb56199093..616ab9393b868bf4da25e69976a3d316adc23d84 100644 --- a/registration/permissioning_test.go +++ b/registration/permissioning_test.go @@ -8,12 +8,21 @@ package registration import ( + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/comms/client" + "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/ndf" + "os" "testing" ) +func TestMain(m *testing.M) { + jww.SetStdoutThreshold(jww.LevelTrace) + connect.TestingOnlyDisableTLS = true + os.Exit(m.Run()) +} + // Init should create a valid Registration communications struct func TestInit(t *testing.T) { // Create dummy comms and ndf diff --git a/storage/fileTransfer/sentTransfer.go b/storage/fileTransfer/sentTransfer.go index 3a8de11e29cecd668971e0d48b41b339f4e0d6d9..fface05f00f2184840abc0120b5ea1599f55ff99 100644 --- a/storage/fileTransfer/sentTransfer.go +++ b/storage/fileTransfer/sentTransfer.go @@ -447,9 +447,7 @@ func (st *SentTransfer) SetInProgress(rid id.Round, partNums ...uint16) (error, _, exists := st.inProgressTransfers.getPartNums(rid) // Set parts as in-progress in status vector - for _, partNum := range partNums { - st.inProgressStatus.Use(uint32(partNum)) - } + st.inProgressStatus.UseMany(uint16SliceToUint32Slice(partNums)...) return st.inProgressTransfers.addPartNums(rid, partNums...), exists } @@ -473,10 +471,8 @@ func (st *SentTransfer) UnsetInProgress(rid id.Round) ([]uint16, error) { // Get the list of part numbers to be removed from list partNums, _ := st.inProgressTransfers.getPartNums(rid) - // Unsets parts as in-progress in status vector - for _, partNum := range partNums { - st.inProgressStatus.Unuse(uint32(partNum)) - } + // Unset parts as in-progress in status vector + st.inProgressStatus.UnuseMany(uint16SliceToUint32Slice(partNums)...) return partNums, st.inProgressTransfers.deletePartNums(rid) } @@ -500,10 +496,8 @@ func (st *SentTransfer) FinishTransfer(rid id.Round) error { return errors.Errorf(deleteInProgressPartsErr, rid, err) } - // Unsets parts as in-progress in status vector - for _, partNum := range partNums { - st.inProgressStatus.Unuse(uint32(partNum)) - } + // Unset parts as in-progress in status vector + st.inProgressStatus.UnuseMany(uint16SliceToUint32Slice(partNums)...) // Add the parts to the finished list err = st.finishedTransfers.addPartNums(rid, partNums...) @@ -512,9 +506,7 @@ func (st *SentTransfer) FinishTransfer(rid id.Round) error { } // Set parts as finished in status vector - for _, partNum := range partNums { - st.finishedStatus.Use(uint32(partNum)) - } + st.finishedStatus.UseMany(uint16SliceToUint32Slice(partNums)...) // If all parts have been moved to the finished list, then set the status // to stopping @@ -745,3 +737,12 @@ func unmarshalSentTransfer(b []byte) (recipient *id.ID, func makeSentTransferPrefix(tid ftCrypto.TransferID) string { return sentTransferPrefix + tid.String() } + +// uint16SliceToUint32Slice converts a slice of uint16 to a slice of uint32. +func uint16SliceToUint32Slice(slice []uint16) []uint32 { + newSlice := make([]uint32, len(slice)) + for i, val := range slice { + newSlice[i] = uint32(val) + } + return newSlice +} diff --git a/storage/fileTransfer/sentTransfer_test.go b/storage/fileTransfer/sentTransfer_test.go index de3e97a9428a24e8ada2a818c63b76284985e0f5..10a76c2a6e442d15ec8200cedc60616e39178b7d 100644 --- a/storage/fileTransfer/sentTransfer_test.go +++ b/storage/fileTransfer/sentTransfer_test.go @@ -19,6 +19,7 @@ import ( "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" + "math/rand" "reflect" "strconv" "strings" @@ -1461,6 +1462,27 @@ func Test_makeSentTransferPrefix_Consistency(t *testing.T) { } } +// Tests that each of the elements in the uint32 slice returned by +// uint16SliceToUint32Slice matches the elements in the original uint16 slice. +func Test_uint16SliceToUint32Slice(t *testing.T) { + prng := rand.New(rand.NewSource(42)) + uint16Slice := make([]uint16, 100) + + for i := range uint16Slice { + uint16Slice[i] = uint16(prng.Uint32()) + } + + uint32Slice := uint16SliceToUint32Slice(uint16Slice) + + // Check that each element is correct + for i, expected := range uint16Slice { + if uint32(expected) != uint32Slice[i] { + t.Errorf("Element #%d is incorrect.\nexpected: %d\nreceived: %d", + i, uint32(expected), uint32Slice[i]) + } + } +} + // newRandomSentTransfer generates a new SentTransfer with random data. func newRandomSentTransfer(numParts, numFps uint16, kv *versioned.KV, t *testing.T) (ftCrypto.TransferID, *SentTransfer) { diff --git a/storage/utility/stateVector.go b/storage/utility/stateVector.go index 19ee95c14da03d798ed7c3b5ab1f9c3840a50d4c..4e4f9d3cfec0c7cc4688b461ded54f2c4d21e5da 100644 --- a/storage/utility/stateVector.go +++ b/storage/utility/stateVector.go @@ -26,12 +26,14 @@ const ( // Error messages. const ( - saveUsedKeyErr = "Failed to save %s after marking key %d as used: %+v" - saveUnusedKeyErr = "Failed to save %s after marking key %d as unused: %+v" - saveNextErr = "failed to save %s after getting next available key: %+v" - noKeysErr = "all keys used" - loadUnmarshalErr = "failed to unmarshal from storage: %+v" - testInterfaceErr = "%s can only be used for testing." + saveUsedKeyErr = "Failed to save %s after marking key %d as used: %+v" + saveUsedKeysErr = "Failed to save %s after marking keys %d as used: %+v" + saveUnusedKeyErr = "Failed to save %s after marking key %d as unused: %+v" + saveUnusedKeysErr = "Failed to save %s after marking keys %d as unused: %+v" + saveNextErr = "failed to save %s after getting next available key: %+v" + noKeysErr = "all keys used" + loadUnmarshalErr = "failed to unmarshal from storage: %+v" + testInterfaceErr = "%s can only be used for testing." ) // StateVector stores a list of a set number of items and their binary state. @@ -83,6 +85,23 @@ func (sv *StateVector) Use(keyNum uint32) { } } +// UseMany marks all of the keys as used (sets them to 1). Saves only after all +// of the keys are set. +func (sv *StateVector) UseMany(keyNums ...uint32) { + sv.mux.Lock() + defer sv.mux.Unlock() + + // Mark the keys as used + for _, keyNum := range keyNums { + sv.use(keyNum) + } + + // Save changes to storage + if err := sv.save(); err != nil { + jww.FATAL.Printf(saveUsedKeysErr, sv, keyNums, err) + } +} + // use marks the key as used (sets it to 1). It is not thread-safe and does not // save to storage. func (sv *StateVector) use(keyNum uint32) { @@ -120,6 +139,23 @@ func (sv *StateVector) Unuse(keyNum uint32) { } } +// UnuseMany marks all the key as unused (sets them to 0). Saves only after all +// of the keys are set. +func (sv *StateVector) UnuseMany(keyNums ...uint32) { + sv.mux.Lock() + defer sv.mux.Unlock() + + // Mark all of the keys as unused + for _, keyNum := range keyNums { + sv.unuse(keyNum) + } + + // Save changes to storage + if err := sv.save(); err != nil { + jww.FATAL.Printf(saveUnusedKeysErr, sv, keyNums, err) + } +} + // unuse marks the key as unused (sets it to 0). It is not thread-safe and does // not save to storage. func (sv *StateVector) unuse(keyNum uint32) { diff --git a/storage/utility/stateVector_test.go b/storage/utility/stateVector_test.go index 3c92a23b88c945c91ac7c8c00eda0ceadf364a39..2d537ef61f2d2a7c810d3e609362cb8551f6a17e 100644 --- a/storage/utility/stateVector_test.go +++ b/storage/utility/stateVector_test.go @@ -90,6 +90,41 @@ func TestStateVector_Use(t *testing.T) { } } +// Tests that StateVector.UseMany sets the correct keys to used at once and does +// not modify others keys and that numAvailable is correctly set. +func TestStateVector_UseMany(t *testing.T) { + sv := newTestStateVector("StateVectorUse", 138, t) + + // Set some keys to used + usedKeys := []uint32{0, 2, 3, 4, 6, 39, 62, 70, 98, 100} + usedKeysMap := make(map[uint32]bool, len(usedKeys)) + for _, keyNum := range usedKeys { + usedKeysMap[keyNum] = true + } + + // Use all keys + sv.UseMany(usedKeys...) + + // Check all keys for their expected states + for i := uint32(0); i < sv.numKeys; i++ { + if usedKeysMap[i] { + if !sv.Used(i) { + t.Errorf("Key #%d should have been marked used.", i) + } + } else if sv.Used(i) { + t.Errorf("Key #%d should have been marked unused.", i) + } + } + + // Make sure numAvailable is not modified when the key is already used + sv.Use(usedKeys[0]) + if sv.numAvailable != sv.numKeys-uint32(len(usedKeys)) { + t.Errorf("numAvailable incorrect.\nexpected: %d\nreceived: %d", + sv.numKeys-uint32(len(usedKeys)), sv.numAvailable) + } + +} + // Tests that StateVector.Unuse sets the correct keys to unused and does not // modify others keys and that numAvailable is correctly set. func TestStateVector_Unuse(t *testing.T) { @@ -140,6 +175,44 @@ func TestStateVector_Unuse(t *testing.T) { } } +// Tests that StateVector.Unuse sets the correct keys to unused at the same time +// and does not modify others keys and that numAvailable is correctly set. +func TestStateVector_UnuseMany(t *testing.T) { + sv := newTestStateVector("StateVectorUse", 138, t) + + // Set all the keys to used + for keyNum := uint32(0); keyNum < sv.numKeys; keyNum++ { + sv.Use(keyNum) + } + + // Set some keys to unused + unusedKeys := []uint32{0, 2, 3, 4, 6, 39, 62, 70, 98, 100} + unusedKeysMap := make(map[uint32]bool, len(unusedKeys)) + for _, keyNum := range unusedKeys { + unusedKeysMap[keyNum] = true + } + + sv.UnuseMany(unusedKeys...) + + // Check all keys for their expected states + for i := uint32(0); i < sv.numKeys; i++ { + if unusedKeysMap[i] { + if sv.Used(i) { + t.Errorf("Key #%d should have been marked unused.", i) + } + } else if !sv.Used(i) { + t.Errorf("Key #%d should have been marked used.", i) + } + } + + // Make sure numAvailable is not modified when the key is already used + sv.Unuse(unusedKeys[0]) + if sv.numAvailable != uint32(len(unusedKeys)) { + t.Errorf("numAvailable incorrect.\nexpected: %d\nreceived: %d", + uint32(len(unusedKeys)), sv.numAvailable) + } +} + // Tests StateVector.Used by creating a vector with known used and unused keys // and making sure it returns the expected state for all keys in the vector. func TestStateVector_Used(t *testing.T) { diff --git a/ud/addFact_test.go b/ud/addFact_test.go index eebb92a1d867c3873897ad56eac60d1b415ec5f2..ba6db2dc18596d476676666e7a4eaed4da0feabc 100644 --- a/ud/addFact_test.go +++ b/ud/addFact_test.go @@ -1,6 +1,7 @@ package ud import ( + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/comms/client" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/primitives/fact" @@ -8,9 +9,16 @@ import ( "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/primitives/id" + "os" "testing" ) +func TestMain(m *testing.M) { + jww.SetStdoutThreshold(jww.LevelTrace) + connect.TestingOnlyDisableTLS = true + os.Exit(m.Run()) +} + type testAFC struct{} // Dummy implementation of SendRegisterFact so that we don't need to run our own