diff --git a/cmd/root.go b/cmd/root.go index 84f456cbccd2999f98ff3e46ff78ef714029084a..a88efa9fe5517b40e7a0f05beb51fe3ce5ef5dca 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -191,10 +191,10 @@ var rootCmd = &cobra.Command{ wg := &sync.WaitGroup{} sendCnt := int(viper.GetUint("sendCount")) wg.Add(sendCnt) - go func(){ + go func() { //sendDelay := time.Duration(viper.GetUint("sendDelay")) for i := 0; i < sendCnt; i++ { - go func(){ + go func() { defer wg.Done() fmt.Printf("Sending to %s: %s\n", recipientID, msgBody) var roundIDs []id.Round @@ -220,7 +220,7 @@ var rootCmd = &cobra.Command{ // Have the client report back the round results err = errors.New("derp") - for j:=0;j<5&&err!=nil;j++{ + for j := 0; j < 5 && err != nil; j++ { err = client.GetRoundResults(roundIDs, roundTimeout, f) } diff --git a/cmd/single.go b/cmd/single.go index edb84044cbb2faa4d725424059386ea1207c6250..6600cbfbbf9b9358d79163c555096127609379d2 100644 --- a/cmd/single.go +++ b/cmd/single.go @@ -89,8 +89,7 @@ var singleCmd = &cobra.Command{ jww.FATAL.Panicf("Could not add single use process: %+v", err) } - - for numReg, total := 1,100; numReg < total; { + for numReg, total := 1, 100; numReg < total; { time.Sleep(1 * time.Second) numReg, total, err = client.GetNodeRegistrationStatus() if err != nil { @@ -100,7 +99,6 @@ var singleCmd = &cobra.Command{ numReg, total) } - timeout := viper.GetDuration("timeout") // If the send flag is set, then send a message diff --git a/keyExchange/trigger.go b/keyExchange/trigger.go index 68878349408043aa439fe45608e10141246d9cc6..0bdcbcc6e6ca80a28b58f53bbf32f22a2b0d0d41 100644 --- a/keyExchange/trigger.go +++ b/keyExchange/trigger.go @@ -120,8 +120,6 @@ func handleTrigger(sess *storage.Session, net interfaces.NetworkManager, MessageType: message.KeyExchangeConfirm, } - - //send the message under the key exchange e2eParams := params.GetDefaultE2E() diff --git a/network/message/sendManyCmix.go b/network/message/sendManyCmix.go index 04719d10de62efb7a4045135b1b898704fa1d77b..3c212f745846c2b60747517d3759a0d019e5528d 100644 --- a/network/message/sendManyCmix.go +++ b/network/message/sendManyCmix.go @@ -148,7 +148,7 @@ func sendManyCmixHelper(sender *gateway.Sender, msgs map[id.ID]format.Message, err := handlePutMessageError(firstGateway, instance, session, nodeRegistration, recipientString, bestRound, err) return result, errors.WithMessagef(err, - "SendManyCMIX %s", unrecoverableError) + "SendManyCMIX %s", unrecoverableError) } return result, err diff --git a/network/roundTracking.go b/network/roundTracking.go index 602d8c55dbb72cdc5cddf1034e6290bf00512e75..b0cf1bf9cfc61fccad3bb02f7aed7488c29bbbbe 100644 --- a/network/roundTracking.go +++ b/network/roundTracking.go @@ -63,7 +63,7 @@ func (rt *RoundTracker) denote(rid id.Round, state RoundState) { // this ensures a lower state will not overwrite a higher state. // eg. Unchecked does not overwrite MessageAvailable if storedState, exists := rt.state[rid]; exists && storedState > state { - jww.TRACE.Printf("did not denote round %d because " + + jww.TRACE.Printf("did not denote round %d because "+ "stored state of %s (%d) > passed state %s (%d)", rid, storedState, storedState, state, state) return diff --git a/network/rounds/check.go b/network/rounds/check.go index 1f262197825923d255f1ec2492c006bb07a40613..3b9eb2d2849400d2fea2227373839cbc0def44e6 100644 --- a/network/rounds/check.go +++ b/network/rounds/check.go @@ -64,7 +64,7 @@ func (m *Manager) GetMessagesFromRound(roundID id.Round, identity reception.Iden "up messages via historical lookup", roundID, identity.EphId.Int64(), identity.Source) //store the round as an unretreived round - err = m.Session.UncheckedRounds().AddRound(roundID,nil, + err = m.Session.UncheckedRounds().AddRound(roundID, nil, identity.Source, identity.EphId) if err != nil { jww.FATAL.Panicf("Failed to denote Unchecked Round for round %d", roundID) @@ -80,7 +80,7 @@ func (m *Manager) GetMessagesFromRound(roundID id.Round, identity reception.Iden "up messages via in ram lookup", roundID, identity.EphId.Int64(), identity.Source) //store the round as an unretreived round - err = m.Session.UncheckedRounds().AddRound(roundID,ri, + err = m.Session.UncheckedRounds().AddRound(roundID, ri, identity.Source, identity.EphId) if err != nil { jww.FATAL.Panicf("Failed to denote Unchecked Round for round %d", roundID) diff --git a/network/rounds/retrieve.go b/network/rounds/retrieve.go index 646b9be11f978c538926ec18223f2d651968b86c..67809eb876ec94b3774ae530918f3ca23f487972 100644 --- a/network/rounds/retrieve.go +++ b/network/rounds/retrieve.go @@ -157,9 +157,9 @@ func (m *Manager) getMessagesFromGateway(roundID id.Round, // If the gateway doesnt have the round, return an error msgResp, err := comms.RequestMessages(host, msgReq) - if err!=nil{ + if err != nil { //you need to default to a retryable errors because otherwise we cannot enumerate all errors - return nil, errors.WithMessage(err, gateway.RetryableError) + return nil, errors.WithMessage(err, gateway.RetryableError) } if !msgResp.GetHasRound() { diff --git a/network/rounds/unchecked.go b/network/rounds/unchecked.go index 81c333392532f75376ff5665f29a3a08428ebd99..0618a95c75d07faa2bdc030348bb0c27b68fca84 100644 --- a/network/rounds/unchecked.go +++ b/network/rounds/unchecked.go @@ -49,32 +49,32 @@ func (m *Manager) processUncheckedRounds(checkInterval time.Duration, backoffTab return case <-ticker.C: - iterator := func(rid id.Round, rnd rounds.UncheckedRound){ + iterator := func(rid id.Round, rnd rounds.UncheckedRound) { jww.DEBUG.Printf("checking if %d due for a message lookup", rid) // If this round is due for a round check, send the round over // to the retrieval thread. If not due, check next round. - if !isRoundCheckDue(rnd.NumChecks, rnd.LastCheck, backoffTable){ + if !isRoundCheckDue(rnd.NumChecks, rnd.LastCheck, backoffTable) { return } jww.INFO.Printf("Round %d due for a message lookup, retrying...", rid) //check if it needs to be processed by historical Rounds - if rnd.Info==nil{ + if rnd.Info == nil { jww.INFO.Printf("Messages in round %d for %d (%s) loaded from unchecked rounds, looking "+ "up messages via historical lookup", rnd.Id, rnd.EpdId.Int64(), rnd.Source) // If we didn't find it, send to Historical Rounds Retrieval m.historicalRounds <- historicalRoundRequest{ - rid: rnd.Id, - identity: reception.IdentityUse{ - Identity: reception.Identity{ - EphId: rnd.EpdId, - Source: rnd.Source, - }, - }, + rid: rnd.Id, + identity: reception.IdentityUse{ + Identity: reception.Identity{ + EphId: rnd.EpdId, + Source: rnd.Source, + }, + }, numAttempts: 0, } return - }else{ + } else { // Construct roundLookup object to send rl := roundLookup{ diff --git a/storage/e2e/stateVector.go b/storage/e2e/stateVector.go index c01b1a2ecab7cbb03f7455eee7e758bdf1210684..fea42c68cec3475ba27d1e6a16f884c7b8b73463 100644 --- a/storage/e2e/stateVector.go +++ b/storage/e2e/stateVector.go @@ -213,12 +213,12 @@ func (sv *stateVector) Delete() error { func (sv *stateVector) nextAvailable() { //plus one so we start at the next one - pos := sv.firstAvailable+1 - block := pos/64 + pos := sv.firstAvailable + 1 + block := pos / 64 for block < uint32(len(sv.vect)) && (sv.vect[block]>>(pos%64))&1 == 1 { pos++ - block = pos/64 + block = pos / 64 } sv.firstAvailable = pos diff --git a/storage/e2e/stateVector_test.go b/storage/e2e/stateVector_test.go index 271c982d01652c7ca556db06dd3983da9e9c268d..e67d251c3c07c4f6ef3014080dee93a88a7846e4 100644 --- a/storage/e2e/stateVector_test.go +++ b/storage/e2e/stateVector_test.go @@ -111,7 +111,6 @@ func TestStateVector_Next(t *testing.T) { } } - // Shows that Next mutates vector state as expected // Shows that Next can find key indexes all throughout the bitfield // A bug was found when the next avalible was in the first index of a word, this tests that case @@ -132,7 +131,7 @@ func TestStateVector_Next_EdgeCase(t *testing.T) { sv.nextAvailable() // firstAvailable should now be beyond the end of the bitfield - if sv.firstAvailable !=64 { + if sv.firstAvailable != 64 { t.Errorf("Next avalivle skiped the first of the next word, should be 64, is %d", sv.firstAvailable) } } diff --git a/storage/rounds/checkedRounds.go b/storage/rounds/checkedRounds.go index dcfd1e6678926285859d90a0f53efcf40f691b77..df17faa3ad38c7ea84d67e44aee01feb92230925 100644 --- a/storage/rounds/checkedRounds.go +++ b/storage/rounds/checkedRounds.go @@ -52,10 +52,9 @@ func newCheckedRounds(maxRounds int, store *utility.BlockStore) *CheckedRounds { return &CheckedRounds{ m: make(map[id.Round]interface{}), l: list.New(), - recent: make([]id.Round,0,maxRounds), + recent: make([]id.Round, 0, maxRounds), store: store, maxRounds: maxRounds, - } } diff --git a/storage/utility/e2eMessageBuffer_test.go b/storage/utility/e2eMessageBuffer_test.go index 0fcef8fc65eb74560cce387fa250e111b79d1562..6eda44ba0cdca36ed43e9332739b968e92ed6ea9 100644 --- a/storage/utility/e2eMessageBuffer_test.go +++ b/storage/utility/e2eMessageBuffer_test.go @@ -128,7 +128,7 @@ func TestE2EMessageHandler_Smoke(t *testing.T) { t.Errorf("Unexpected length of buffer.\n\texpected: %d\n\trecieved: %d", 0, len(cmb.mb.messages)) } - cmb.Failed(msg,params.E2E{}) + cmb.Failed(msg, params.E2E{}) if len(cmb.mb.messages) != 1 { t.Errorf("Unexpected length of buffer.\n\texpected: %d\n\trecieved: %d", @@ -177,14 +177,14 @@ func makeTestE2EMessages(n int, t *testing.T) ([]e2eMessage, []message.Send) { } func TestE2EParamMarshalUnmarshal(t *testing.T) { - msg := e2eMessage{ + msg := &e2eMessage{ Recipient: id.DummyUser[:], - Payload: []byte{1,2,3,4,5,6,7,8,9}, + Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, MessageType: 42, - Params: params.E2E{ + Params: params.E2E{ Type: 1, RetryCount: 7, - CMIX: params.CMIX{ + CMIX: params.CMIX{ RoundTries: 6, Timeout: 99, RetryDelay: -4, @@ -192,26 +192,28 @@ func TestE2EParamMarshalUnmarshal(t *testing.T) { }, } + fmt.Printf("msg1: %#v\n", msg) + b, err := json.Marshal(&msg) - if err!=nil{ + if err != nil { t.Errorf("Failed to Marshal E2eMessage") } - fmt.Printf("%s\n", string(b)) + fmt.Printf("json: %s\n", string(b)) msg2 := &e2eMessage{} - err = json.Unmarshal(b,&msg2) + err = json.Unmarshal(b, &msg2) - if err!=nil{ + if err != nil { t.Errorf("Failed to Unmarshal E2eMessage") } - fmt.Printf("%#v\n", msg2) + fmt.Printf("msg2: %#v\n", msg2) - if !reflect.DeepEqual(msg,msg2){ + if !reflect.DeepEqual(msg, msg2) { t.Errorf("Unmarshaled message is not the same") } -} \ No newline at end of file +}