From 18d219f9813add9c190be3e7633152068c08e29e Mon Sep 17 00:00:00 2001 From: Jake Taylor <jake@elixxir.io> Date: Wed, 3 Mar 2021 13:41:58 -0600 Subject: [PATCH] go fmt --- api/processies.go | 22 ++++++------ api/results.go | 2 +- auth/callback.go | 6 ++-- auth/confirm.go | 16 ++++----- auth/request.go | 16 ++++----- bindings/client.go | 10 +++--- bindings/contact.go | 6 ++-- bindings/list.go | 10 +++--- cmd/root.go | 6 ++-- globals/version_vars.go | 22 ++++++------ interfaces/message/encryptionType.go | 6 ++-- interfaces/message/receiveMessage.go | 2 +- keyExchange/rekey.go | 4 +-- network/follow.go | 9 +++-- network/manager.go | 2 +- network/message/critical.go | 26 +++++++------- network/message/garbled.go | 4 +-- network/message/handler.go | 6 ++-- network/message/sendCmix.go | 43 +++++++++++------------ network/message/sendCmix_test.go | 10 +++--- network/message/sendUnsafe.go | 3 +- network/polltracker.go | 17 +++++---- network/rounds/check.go | 10 +++--- network/rounds/historical.go | 4 +-- network/rounds/manager.go | 2 +- network/rounds/processingRounds.go | 6 ++-- network/rounds/processingRounds_test.go | 2 +- network/rounds/retrieve.go | 2 +- storage/e2e/negotiation.go | 2 +- storage/e2e/relationship.go | 6 ++-- storage/e2e/relationship_test.go | 17 +++++---- storage/e2e/session.go | 4 +-- storage/reception/IdentityUse.go | 2 +- storage/reception/registration.go | 16 ++++----- storage/reception/registration_test.go | 2 +- storage/reception/unknownRound.go | 24 ++++++------- storage/utility/cmixMessageBuffer.go | 12 +++---- storage/utility/cmixMessageBuffer_test.go | 2 +- ud/confirmFact_test.go | 4 +-- ud/manager.go | 3 +- ud/registered.go | 16 ++++----- ud/remove_test.go | 8 ++--- 42 files changed, 190 insertions(+), 202 deletions(-) diff --git a/api/processies.go b/api/processies.go index 13409bd38..ad4a71499 100644 --- a/api/processies.go +++ b/api/processies.go @@ -7,29 +7,29 @@ import ( // a service process starts itself in a new thread, returning from the // originator a stopable to control it -type ServiceProcess func()stoppable.Stoppable +type ServiceProcess func() stoppable.Stoppable -type serviceProcessiesList struct{ +type serviceProcessiesList struct { serviceProcessies []ServiceProcess - multiStopable *stoppable.Multi - mux sync.Mutex + multiStopable *stoppable.Multi + mux sync.Mutex } // newServiceProcessiesList creates a new processies list which will add its // processies to the passed mux -func newServiceProcessiesList(m *stoppable.Multi)*serviceProcessiesList{ +func newServiceProcessiesList(m *stoppable.Multi) *serviceProcessiesList { return &serviceProcessiesList{ serviceProcessies: make([]ServiceProcess, 0), - multiStopable: m, + multiStopable: m, } } // Add adds the service process to the list and adds it to the multi-stopable -func (spl serviceProcessiesList)Add(sp ServiceProcess){ +func (spl serviceProcessiesList) Add(sp ServiceProcess) { spl.mux.Lock() defer spl.mux.Unlock() - spl.serviceProcessies = append(spl.serviceProcessies,sp) + spl.serviceProcessies = append(spl.serviceProcessies, sp) // starts the process and adds it to the stopable // there can be a race condition between the execution of the process and // the stopable. @@ -37,14 +37,12 @@ func (spl serviceProcessiesList)Add(sp ServiceProcess){ } // Runs all processies, to be used after a stop. Must use a new stopable -func (spl serviceProcessiesList)run(m *stoppable.Multi){ +func (spl serviceProcessiesList) run(m *stoppable.Multi) { spl.mux.Lock() defer spl.mux.Unlock() spl.multiStopable = m - for _, sp := range spl.serviceProcessies{ + for _, sp := range spl.serviceProcessies { spl.multiStopable.Add(sp()) } } - - diff --git a/api/results.go b/api/results.go index e339a4837..2c87dd27a 100644 --- a/api/results.go +++ b/api/results.go @@ -29,7 +29,7 @@ const ( Succeeded ) -func (rr RoundResult) String() string { +func (rr RoundResult) String() string { switch rr { case TimeOut: return "TimeOut" diff --git a/auth/callback.go b/auth/callback.go index f90b430f1..a304905f4 100644 --- a/auth/callback.go +++ b/auth/callback.go @@ -58,7 +58,7 @@ func (m *Manager) StartProcessies() stoppable.Stoppable { // if it is specific, that means the original request was sent // by this users and a confirmation has been received case auth.Specific: - jww.INFO.Printf("Received AutConfirm from %s," + + jww.INFO.Printf("Received AutConfirm from %s,"+ " msgDigest: %s", sr.GetPartner(), cmixMsg.Digest()) m.handleConfirm(cmixMsg, sr, grp) } @@ -115,7 +115,7 @@ func (m *Manager) handleRequest(cmixMsg format.Message, return } - jww.INFO.Printf("Received AuthRequest from %s," + + jww.INFO.Printf("Received AuthRequest from %s,"+ " msgDigest: %s", partnerID, cmixMsg.Digest()) /*do state edge checks*/ @@ -148,7 +148,7 @@ func (m *Manager) handleRequest(cmixMsg format.Message, // if we sent a request, then automatically confirm // then exit, nothing else needed case auth.Sent: - jww.INFO.Printf("Received AuthRequest from %s," + + jww.INFO.Printf("Received AuthRequest from %s,"+ " msgDigest: %s which has been requested, auto-confirming", partnerID, cmixMsg.Digest()) // do the confirmation diff --git a/auth/confirm.go b/auth/confirm.go index 092be519f..d1b88bf99 100644 --- a/auth/confirm.go +++ b/auth/confirm.go @@ -132,10 +132,10 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, if err != nil { // if the send fails just set it to failed, it will but automatically // retried - jww.INFO.Printf("Auth Confirm with %s (msgDigest: %s) failed " + - "to transmit: %+v", partner.ID, cmixMsg.Digest(), err) + jww.INFO.Printf("Auth Confirm with %s (msgDigest: %s) failed "+ + "to transmit: %+v", partner.ID, cmixMsg.Digest(), err) storage.GetCriticalRawMessages().Failed(cmixMsg, partner.ID) - return errors.WithMessage(err,"Auth Confirm Failed to transmit") + return errors.WithMessage(err, "Auth Confirm Failed to transmit") } jww.INFO.Printf("Confirm Request with %s (msgDigest: %s) sent on round %d", @@ -150,12 +150,12 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, success, numFailed, _ := utility.TrackResults(sendResults, 1) if !success { - if numFailed > 0{ - jww.INFO.Printf("Auth Confirm with %s (msgDigest: %s) failed " + + if numFailed > 0 { + jww.INFO.Printf("Auth Confirm with %s (msgDigest: %s) failed "+ "delivery due to round failure, will retry on reconnect", partner.ID, cmixMsg.Digest()) - }else{ - jww.INFO.Printf("Auth Confirm with %s (msgDigest: %s) failed " + + } else { + jww.INFO.Printf("Auth Confirm with %s (msgDigest: %s) failed "+ "delivery due to timeout, will retry on reconnect", partner.ID, cmixMsg.Digest()) } @@ -163,7 +163,7 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, "handled on reconnect") storage.GetCriticalRawMessages().Failed(cmixMsg, partner.ID) } else { - jww.INFO.Printf("Auth Confirm with %s (msgDigest: %s) delivered " + + jww.INFO.Printf("Auth Confirm with %s (msgDigest: %s) delivered "+ "sucesfully", partner.ID, cmixMsg.Digest()) storage.GetCriticalRawMessages().Succeeded(cmixMsg, partner.ID) } diff --git a/auth/request.go b/auth/request.go index 7b9662497..8e9c1c58e 100644 --- a/auth/request.go +++ b/auth/request.go @@ -153,10 +153,10 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader, if err != nil { // if the send fails just set it to failed, it will but automatically // retried - jww.INFO.Printf("Auth Request with %s (msgDigest: %s) failed " + - "to transmit: %+v", partner.ID, cmixMsg.Digest(), err) + jww.INFO.Printf("Auth Request with %s (msgDigest: %s) failed "+ + "to transmit: %+v", partner.ID, cmixMsg.Digest(), err) storage.GetCriticalRawMessages().Failed(cmixMsg, partner.ID) - return errors.WithMessage(err,"Auth Request Failed to transmit") + return errors.WithMessage(err, "Auth Request Failed to transmit") } jww.INFO.Printf("Auth Request with %s (msgDigest: %s) sent on round %d", @@ -171,18 +171,18 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader, success, numFailed, _ := utility.TrackResults(sendResults, 1) if !success { - if numFailed > 0{ - jww.INFO.Printf("Auth Request with %s (msgDigest: %s) failed " + + if numFailed > 0 { + jww.INFO.Printf("Auth Request with %s (msgDigest: %s) failed "+ "delivery due to round failure, will retry on reconnect", partner.ID, cmixMsg.Digest()) - }else{ - jww.INFO.Printf("Auth Request with %s (msgDigest: %s) failed " + + } else { + jww.INFO.Printf("Auth Request with %s (msgDigest: %s) failed "+ "delivery due to timeout, will retry on reconnect", partner.ID, cmixMsg.Digest()) } storage.GetCriticalRawMessages().Failed(cmixMsg, partner.ID) } else { - jww.INFO.Printf("Auth Request with %s (msgDigest: %s) delivered " + + jww.INFO.Printf("Auth Request with %s (msgDigest: %s) delivered "+ "sucesfully", partner.ID, cmixMsg.Digest()) storage.GetCriticalRawMessages().Succeeded(cmixMsg, partner.ID) } diff --git a/bindings/client.go b/bindings/client.go index 866721af2..431c86083 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -310,15 +310,15 @@ func (c *Client) WaitForRoundCompletion(marshaledSendReport []byte, sr, err := UnmarshalSendReport(marshaledSendReport) if err != nil { - return errors.New(fmt.Sprintf("Failed to "+ + return errors.New(fmt.Sprintf("Failed to "+ "WaitForRoundCompletion callback due to bad Send Report: %+v", err)) } - f := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]api.RoundResult){ + f := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]api.RoundResult) { results := make([]byte, len(sr.rl.list)) - for i, r := range sr.rl.list{ - if result, exists := rounds[r]; exists{ + for i, r := range sr.rl.list { + if result, exists := rounds[r]; exists { results[i] = byte(result) } } @@ -326,7 +326,7 @@ func (c *Client) WaitForRoundCompletion(marshaledSendReport []byte, mdc.EventCallback(sr.mid.Marshal(), allRoundsSucceeded, timedOut, results) } - timeout := time.Duration(timeoutMS)*time.Millisecond + timeout := time.Duration(timeoutMS) * time.Millisecond return c.api.GetRoundResults(sr.rl.list, timeout, f) } diff --git a/bindings/contact.go b/bindings/contact.go index 4fab63d38..daa45aa35 100644 --- a/bindings/contact.go +++ b/bindings/contact.go @@ -21,12 +21,12 @@ import ( // semicolons. If it is not well formed, it will be rejected. Phone numbers // must have the two letter country codes appended. For the complete set of // validation, see /elixxir/primitives/fact/fact.go -func NewFact(factType int, factStr string)(*Fact, error){ +func NewFact(factType int, factStr string) (*Fact, error) { f, err := fact.NewFact(fact.FactType(factType), factStr) - if err!=nil{ + if err != nil { return nil, err } - return &Fact{f:&f}, nil + return &Fact{f: &f}, nil } type Fact struct { diff --git a/bindings/list.go b/bindings/list.go index fda887f93..3fc313826 100644 --- a/bindings/list.go +++ b/bindings/list.go @@ -78,16 +78,16 @@ func (cl *ContactList) Get(i int) (*Contact, error) { " list len") } - return &Contact{c:&cl.list[i]}, nil + return &Contact{c: &cl.list[i]}, nil } /*FactList*/ -func NewFactList()*FactList{ - return &FactList{ c: &contact.Contact{ +func NewFactList() *FactList { + return &FactList{c: &contact.Contact{ ID: nil, DhPubKey: nil, OwnershipProof: nil, - Facts: make([]fact.Fact,0), + Facts: make([]fact.Fact, 0), }} } @@ -105,7 +105,7 @@ func (fl *FactList) Get(i int) Fact { func (fl *FactList) Add(factData string, factType int) error { f, err := fact.NewFact(fact.FactType(factType), factData) - if err!=nil{ + if err != nil { return err } fl.c.Facts = append(fl.c.Facts, f) diff --git a/cmd/root.go b/cmd/root.go index 619016095..ff55ffab8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -560,15 +560,15 @@ func initLog(threshold uint, logPath string) { jww.SetLogOutput(logOutput) } - if threshold>1{ + if threshold > 1 { jww.INFO.Printf("log level set to: TRACE") jww.SetStdoutThreshold(jww.LevelTrace) jww.SetLogThreshold(jww.LevelTrace) - }else if threshold == 1{ + } else if threshold == 1 { jww.INFO.Printf("log level set to: DEBUG") jww.SetStdoutThreshold(jww.LevelDebug) jww.SetLogThreshold(jww.LevelDebug) - }else{ + } else { jww.INFO.Printf("log level set to: TRACE") jww.SetStdoutThreshold(jww.LevelInfo) jww.SetLogThreshold(jww.LevelInfo) diff --git a/globals/version_vars.go b/globals/version_vars.go index 7e5cc9710..96811389c 100644 --- a/globals/version_vars.go +++ b/globals/version_vars.go @@ -1,9 +1,9 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated by robots at -// 2021-02-15 13:16:40.214748 -0600 CST m=+0.021065952 +// 2021-02-23 13:45:01.90479 -0600 CST m=+0.028659802 package globals -const GITVERSION = `e5e78f6b fixed the useage of the excluded list in send cMix` +const GITVERSION = `52999989 added better logging on send` const SEMVER = "1.4.0" const DEPENDENCIES = `module gitlab.com/elixxir/client @@ -24,16 +24,16 @@ 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.20210215180544-d672a6bfd53a - gitlab.com/elixxir/crypto v0.0.7-0.20210210215733-951b4e717763 - gitlab.com/elixxir/ekv v0.1.4 - gitlab.com/elixxir/primitives v0.0.3-0.20210210215643-bf48247248e5 - gitlab.com/xx_network/comms v0.0.4-0.20210210215624-622913c0a215 - gitlab.com/xx_network/crypto v0.0.5-0.20210210215543-446333e9022e - gitlab.com/xx_network/primitives v0.0.4-0.20210215191517-2f56b21d6ed7 - golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad + gitlab.com/elixxir/comms v0.0.4-0.20210223192051-a47bfe7991e8 + gitlab.com/elixxir/crypto v0.0.7-0.20210216174551-f806f79610eb + gitlab.com/elixxir/ekv v0.1.5-0.20210223193853-5f54e289198f + gitlab.com/elixxir/primitives v0.0.3-0.20210223180234-8e5d82635c20 + gitlab.com/xx_network/comms v0.0.4-0.20210216174438-0790d1f1f225 + gitlab.com/xx_network/crypto v0.0.5-0.20210216174356-e81e1ddf8fb7 + gitlab.com/xx_network/primitives v0.0.4-0.20210219231511-983054dbee36 + golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect - golang.org/x/sys v0.0.0-20210105210732-16f7687f5001 // indirect + golang.org/x/sys v0.0.0-20210223095934-7937bea0104d // indirect google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect google.golang.org/grpc v1.34.0 // indirect google.golang.org/protobuf v1.25.0 diff --git a/interfaces/message/encryptionType.go b/interfaces/message/encryptionType.go index 364937728..cdd86c06a 100644 --- a/interfaces/message/encryptionType.go +++ b/interfaces/message/encryptionType.go @@ -14,8 +14,8 @@ const ( E2E EncryptionType = 1 ) -func (et EncryptionType)String()string{ - switch et{ +func (et EncryptionType) String() string { + switch et { case None: return "None" case E2E: @@ -23,4 +23,4 @@ func (et EncryptionType)String()string{ default: return "Unknown" } -} \ No newline at end of file +} diff --git a/interfaces/message/receiveMessage.go b/interfaces/message/receiveMessage.go index f5373e716..fad6fb750 100644 --- a/interfaces/message/receiveMessage.go +++ b/interfaces/message/receiveMessage.go @@ -19,7 +19,7 @@ type Receive struct { Payload []byte MessageType Type Sender *id.ID - RecipientID *id.ID + RecipientID *id.ID EphemeralID ephemeral.Id Timestamp time.Time Encryption EncryptionType diff --git a/keyExchange/rekey.go b/keyExchange/rekey.go index 14aec2bc5..f37e2e679 100644 --- a/keyExchange/rekey.go +++ b/keyExchange/rekey.go @@ -40,7 +40,7 @@ func trigger(instance *network.Instance, sendE2E interfaces.SendE2E, sess *storage.Session, manager *e2e.Manager, session *e2e.Session, sendTimeout time.Duration) { var negotiatingSession *e2e.Session - jww.INFO.Printf("Negotation triggered for session %s with " + + jww.INFO.Printf("Negotation triggered for session %s with "+ "status: %s", session, session.NegotiationStatus()) switch session.NegotiationStatus() { // If the passed session is triggering a negotiation on a new session to @@ -65,7 +65,7 @@ func trigger(instance *network.Instance, sendE2E interfaces.SendE2E, // if sending the negotiation fails, revert the state of the session to // unconfirmed so it will be triggered in the future if err != nil { - jww.ERROR.Printf("Failed to do Key Negotiation with " + + jww.ERROR.Printf("Failed to do Key Negotiation with "+ "session %s: %s", session, err) } } diff --git a/network/follow.go b/network/follow.go index ea8113104..cb0b4c9be 100644 --- a/network/follow.go +++ b/network/follow.go @@ -37,7 +37,7 @@ import ( "time" ) -const debugTrackPeriod = 1*time.Minute +const debugTrackPeriod = 1 * time.Minute const maxChecked = 100000 //comms interface makes testing easier @@ -61,7 +61,7 @@ func (m *manager) followNetwork(quitCh <-chan struct{}) { done = true case <-ticker.C: m.follow(rng, m.Comms) - case <- TrackTicker.C: + case <-TrackTicker.C: jww.INFO.Println(m.tracker.Report()) m.tracker = newPollTracker() } @@ -71,7 +71,6 @@ func (m *manager) followNetwork(quitCh <-chan struct{}) { // executes each iteration of the follower func (m *manager) follow(rng csprng.Source, comms followNetworkComms) { - //get the identity we will poll for identity, err := m.Session.Reception().GetIdentity(rng) if err != nil { @@ -235,7 +234,7 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) { deletionStart := identity.UR.Get() earliestTrackedRound := id.Round(pollResp.EarliestRound) updated := identity.UR.Set(earliestTrackedRound) - if updated-deletionStart>maxChecked{ + if updated-deletionStart > maxChecked { deletionStart = updated } @@ -247,7 +246,7 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) { identity.UR.Set(earliestRemaining) //delete any old rounds from processing - for i:=deletionStart;i<=earliestRemaining;i++{ + for i := deletionStart; i <= earliestRemaining; i++ { m.round.DeleteProcessingRoundDelete(i, identity.EphId, identity.Source) } } diff --git a/network/manager.go b/network/manager.go index b2d43c8e6..7df9c58d9 100644 --- a/network/manager.go +++ b/network/manager.go @@ -87,7 +87,7 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, NodeRegistration: make(chan network.NodeGateway, params.RegNodesBufferLen), Instance: instance, TransmissionID: session.User().GetCryptographicIdentity().GetTransmissionID(), - ReceptionID: session.User().GetCryptographicIdentity().GetReceptionID(), + ReceptionID: session.User().GetCryptographicIdentity().GetReceptionID(), } //create sub managers diff --git a/network/message/critical.go b/network/message/critical.go index 800c93ef7..0ebaed5d3 100644 --- a/network/message/critical.go +++ b/network/message/critical.go @@ -57,7 +57,7 @@ func (m *Manager) criticalMessages() { //if the message fail to send, notify the buffer so it can be handled //in the future and exit if err != nil { - jww.ERROR.Printf("Failed to send critical message to %s " + + jww.ERROR.Printf("Failed to send critical message to %s "+ " on notification of healthy network: %+v", msg.Recipient, err) critMsgs.Failed(msg) @@ -72,15 +72,15 @@ func (m *Manager) criticalMessages() { } success, numTimeOut, numRoundFail := utility.TrackResults(sendResults, len(rounds)) if !success { - jww.ERROR.Printf("critical message send to %s failed " + - "to transmit transmit %v/%v paritions on rounds %d: %v " + + jww.ERROR.Printf("critical message send to %s failed "+ + "to transmit transmit %v/%v paritions on rounds %d: %v "+ "round failures, %v timeouts", msg.Recipient, numRoundFail+numTimeOut, len(rounds), rounds, numRoundFail, numTimeOut) critMsgs.Failed(msg) return } - jww.INFO.Printf("Sucesfull resend of critical message " + + jww.INFO.Printf("Sucesfull resend of critical message "+ "to %s on rounds %d", msg.Recipient, rounds) critMsgs.Succeeded(msg) }(msg, param) @@ -92,7 +92,7 @@ func (m *Manager) criticalMessages() { for msg, rid, has := critRawMsgs.Next(); has; msg, rid, has = critRawMsgs.Next() { localRid := rid.DeepCopy() go func(msg format.Message, rid *id.ID) { - jww.INFO.Printf("Resending critical raw message to %s " + + jww.INFO.Printf("Resending critical raw message to %s "+ "(msgDigest: %s)", rid, msg.Digest()) //send the message round, _, err := m.SendCMIX(msg, rid, param) @@ -114,13 +114,13 @@ func (m *Manager) criticalMessages() { success, numTimeOut, _ := utility.TrackResults(sendResults, 1) if !success { - if numTimeOut>0{ - jww.ERROR.Printf("critical raw message resend to %s " + - "(msgDigest: %s) on round %d failed to transmit due to " + + if numTimeOut > 0 { + jww.ERROR.Printf("critical raw message resend to %s "+ + "(msgDigest: %s) on round %d failed to transmit due to "+ "timeout", rid, msg.Digest(), round) - }else{ - jww.ERROR.Printf("critical raw message resend to %s " + - "(msgDigest: %s) on round %d failed to transmit due to " + + } else { + jww.ERROR.Printf("critical raw message resend to %s "+ + "(msgDigest: %s) on round %d failed to transmit due to "+ "send failure", rid, msg.Digest(), round) } @@ -128,11 +128,11 @@ func (m *Manager) criticalMessages() { return } - jww.INFO.Printf("Sucesfull resend of critical raw message " + + jww.INFO.Printf("Sucesfull resend of critical raw message "+ "to %s (msgDigest: %s) on round %d", rid, msg.Digest(), round) critRawMsgs.Succeeded(msg, rid) }(msg, localRid) } -} \ No newline at end of file +} diff --git a/network/message/garbled.go b/network/message/garbled.go index b8b10bf2b..70bab27f4 100644 --- a/network/message/garbled.go +++ b/network/message/garbled.go @@ -8,10 +8,10 @@ package message import ( + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/primitives/format" "time" - jww "github.com/spf13/jwalterweatherman" ) // Messages can arrive in the network out of order. When message handling fails @@ -61,7 +61,7 @@ func (m *Manager) handleGarbledMessages() { //remove from the buffer if decryption is successful garbledMsgs.Remove(grbldMsg) - jww.INFO.Printf("Garbled message decoded as E2E from " + + jww.INFO.Printf("Garbled message decoded as E2E from "+ "%s, msgDigest: %s", sender, grbldMsg.Digest()) //handle the successfully decrypted message diff --git a/network/message/handler.go b/network/message/handler.go index 39125d468..95606c8a7 100644 --- a/network/message/handler.go +++ b/network/message/handler.go @@ -53,12 +53,12 @@ func (m *Manager) handleMessage(ecrMsg format.Message, identity reception.Identi jww.FATAL.Panicf("Could not check IdentityFingerprint: %+v", err) } if !forMe { - if jww.GetLogThreshold()==jww.LevelTrace{ + if jww.GetLogThreshold() == jww.LevelTrace { expectedFP, _ := fingerprint2.IdentityFP(ecrMsg.GetContents(), identity.Source) - jww.TRACE.Printf("Message for %d (%s) failed identity " + + jww.TRACE.Printf("Message for %d (%s) failed identity "+ "check: %v (expected) vs %v (received)", identity.EphId, - identity.Source, expectedFP, ecrMsg.GetIdentityFP(), ) + identity.Source, expectedFP, ecrMsg.GetIdentityFP()) } return diff --git a/network/message/sendCmix.go b/network/message/sendCmix.go index a6ebbb79a..1cabc5797 100644 --- a/network/message/sendCmix.go +++ b/network/message/sendCmix.go @@ -55,25 +55,24 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins timeStart := time.Now() attempted := set.New() - jww.INFO.Printf("Looking for round to send cMix message to %s " + + jww.INFO.Printf("Looking for round to send cMix message to %s "+ "(msgDigest: %s)", recipient, msg.Digest()) for numRoundTries := uint(0); numRoundTries < param.RoundTries; numRoundTries++ { elapsed := time.Now().Sub(timeStart) if elapsed > param.Timeout { - jww.INFO.Printf("No rounds to send to %s (msgDigest: %s) " + + jww.INFO.Printf("No rounds to send to %s (msgDigest: %s) "+ "were found before timeout %s", recipient, msg.Digest(), param.Timeout) return 0, ephemeral.Id{}, errors.New("Sending cmix message timed out") } - if numRoundTries>0{ - jww.INFO.Printf("Attempt %d to find round to send message " + + if numRoundTries > 0 { + jww.INFO.Printf("Attempt %d to find round to send message "+ "to %s (msgDigest: %s)", numRoundTries+1, recipient, msg.Digest()) } - remainingTime := param.Timeout - elapsed //find the best round to send to, excluding attempted rounds bestRound, _ := instance.GetWaitingRounds().GetUpcomingRealtime(remainingTime, attempted) @@ -90,10 +89,10 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins bestRound.ID, recipient, msg.Digest()) if now.After(roundCutoffTime) { - jww.WARN.Printf("Round %d for sending to %s (msgDigest: %s) " + - "received which has already started realtime: \n\t started: " + + jww.WARN.Printf("Round %d for sending to %s (msgDigest: %s) "+ + "received which has already started realtime: \n\t started: "+ "%s \n\t now: %s", bestRound.ID, recipient, msg.Digest(), - roundCutoffTime, now) + roundCutoffTime, now) attempted.Insert(bestRound) continue } @@ -103,7 +102,7 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins uint(bestRound.AddressSpaceSize), int64(bestRound.Timestamps[states.QUEUED])) if err != nil { - jww.FATAL.Panicf("Failed to generate ephemeral ID when " + + jww.FATAL.Panicf("Failed to generate ephemeral ID when "+ "sending to %s (msgDigest: %s): %+v", err, recipient, msg.Digest()) } @@ -111,7 +110,7 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins stream := rng.GetStream() ephIdFilled, err := ephID.Fill(uint(bestRound.AddressSpaceSize), stream) if err != nil { - jww.FATAL.Panicf("Failed to obfuscate the ephemeralID when " + + jww.FATAL.Panicf("Failed to obfuscate the ephemeralID when "+ "sending to %s (msgDigest: %s): %+v", recipient, msg.Digest(), err) } @@ -123,7 +122,7 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins ifp, err := fingerprint.IdentityFP(msg.GetContents(), recipient) if err != nil { jww.FATAL.Panicf("failed to generate the Identity "+ - "fingerprint due to unrecoverable error when sending to %s " + + "fingerprint due to unrecoverable error when sending to %s "+ "(msgDigest: %s): %+v", recipient, msg.Digest(), err) } @@ -132,7 +131,7 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins //build the topology idList, err := id.NewIDListFromBytes(bestRound.Topology) if err != nil { - jww.ERROR.Printf("Failed to use topology for round %d when " + + jww.ERROR.Printf("Failed to use topology for round %d when "+ "sending to %s (msgDigest: %s): %+v", bestRound.ID, recipient, msg.Digest(), err) continue @@ -142,7 +141,7 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins //keying relationships roundKeys, missingKeys := session.Cmix().GetRoundKeys(topology) if len(missingKeys) > 0 { - jww.WARN.Printf("Failed to send on round %d to %s " + + jww.WARN.Printf("Failed to send on round %d to %s "+ "(msgDigest: %s) due to missing relationships with nodes: %s", bestRound.ID, recipient, msg.Digest(), missingKeys) go handleMissingNodeKeys(instance, nodeRegistration, missingKeys) @@ -156,7 +155,7 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins transmitGateway, ok := comms.GetHost(firstGateway) if !ok { - jww.ERROR.Printf("Failed to get host for gateway %s when " + + jww.ERROR.Printf("Failed to get host for gateway %s when "+ "sending to %s (msgDigest: %s)", transmitGateway, recipient, msg.Digest()) time.Sleep(param.RetryDelay) @@ -170,7 +169,7 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins stream.Close() if err != nil { - jww.ERROR.Printf("Failed to generate salt when sending to " + + jww.ERROR.Printf("Failed to generate salt when sending to "+ "%s (msgDigest: %s): %+v", recipient, msg.Digest(), err) return 0, ephemeral.Id{}, errors.WithMessage(err, "Failed to generate salt, this should never happen") @@ -199,7 +198,7 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins //add the round on to the list of attempted so it is not tried again attempted.Insert(bestRound) - jww.INFO.Printf("Sending to EphID %d (%s) on round %d, " + + jww.INFO.Printf("Sending to EphID %d (%s) on round %d, "+ "(msgDigest: %s, ecrMsgDigest: %s) via gateway %s", ephID.Int64(), recipient, bestRound.ID, msg.Digest(), encMsg.Digest(), transmitGateway.GetId()) @@ -210,21 +209,21 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins if err != nil { if strings.Contains(err.Error(), "try a different round.") { - jww.WARN.Printf("Failed to send to %s (msgDigest: %s) " + + jww.WARN.Printf("Failed to send to %s (msgDigest: %s) "+ "due to round error with rougn %d, retrying: %+v", recipient, msg.Digest(), bestRound.ID, err) continue } - jww.ERROR.Printf("Failed to send to EphID %d (%s) on " + + jww.ERROR.Printf("Failed to send to EphID %d (%s) on "+ "round %d, bailing: %+v", ephID.Int64(), recipient, bestRound.ID, err) - return 0, ephemeral.Id{}, errors.WithMessage(err, "Failed to put cmix message") + return 0, ephemeral.Id{}, errors.WithMessage(err, "Failed to put cmix message") } else if gwSlotResp.Accepted { - jww.INFO.Printf("Successfully sent to EphID %v (source: %s) " + + jww.INFO.Printf("Successfully sent to EphID %v (source: %s) "+ "in round %d", ephID.Int64(), recipient, bestRound.ID) return id.Round(bestRound.ID), ephID, nil - } else{ - jww.FATAL.Panicf("Gateway %s returned no error, but failed " + + } else { + jww.FATAL.Panicf("Gateway %s returned no error, but failed "+ "to accept message when sending to EphID %d (%s) on round %d", transmitGateway.GetId(), ephID.Int64(), recipient, bestRound.ID) } diff --git a/network/message/sendCmix_test.go b/network/message/sendCmix_test.go index 395d6b3a0..7ea83223a 100644 --- a/network/message/sendCmix_test.go +++ b/network/message/sendCmix_test.go @@ -72,11 +72,11 @@ func Test_attemptSendCmix(t *testing.T) { sess1.Cmix().Add(nid3, grp.NewInt(3)) timestamps := []uint64{ - uint64(now.Add(-30*time.Second).UnixNano()), //PENDING - uint64(now.Add(-25*time.Second).UnixNano()), //PRECOMPUTING - uint64(now.Add(-5*time.Second).UnixNano()), //STANDBY - uint64(now.Add(5*time.Second).UnixNano()), //QUEUED - 0} //REALTIME + uint64(now.Add(-30 * time.Second).UnixNano()), //PENDING + uint64(now.Add(-25 * time.Second).UnixNano()), //PRECOMPUTING + uint64(now.Add(-5 * time.Second).UnixNano()), //STANDBY + uint64(now.Add(5 * time.Second).UnixNano()), //QUEUED + 0} //REALTIME inst.GetWaitingRounds().Insert(&mixmessages.RoundInfo{ ID: 3, diff --git a/network/message/sendUnsafe.go b/network/message/sendUnsafe.go index 51529b826..d039b1872 100644 --- a/network/message/sendUnsafe.go +++ b/network/message/sendUnsafe.go @@ -52,7 +52,6 @@ func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round, jww.INFO.Printf("Unsafe sending %d messages to %s", len(partitions), msg.Recipient) - for i, p := range partitions { myID := m.Session.User().GetCryptographicIdentity() msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen()) @@ -82,7 +81,7 @@ func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round, numFail, len(partitions), msg.Recipient) return nil, errors.Errorf("Failed to send %v/%v sub payloads:"+ " %s", numFail, len(partitions), errRtn) - }else{ + } else { jww.INFO.Printf("Sucesfully Unsafe sent %d/%d to %s", len(partitions)-numFail, len(partitions), msg.Recipient) } diff --git a/network/polltracker.go b/network/polltracker.go index 7653ac340..497539e94 100644 --- a/network/polltracker.go +++ b/network/polltracker.go @@ -8,32 +8,32 @@ import ( type pollTracker map[id.ID]map[int64]uint -func newPollTracker()*pollTracker{ +func newPollTracker() *pollTracker { pt := make(pollTracker) return &pt } //tracks a single poll -func (pt *pollTracker)Track(ephID ephemeral.Id, source *id.ID){ - if _, exists := (*pt)[*source]; !exists{ +func (pt *pollTracker) Track(ephID ephemeral.Id, source *id.ID) { + if _, exists := (*pt)[*source]; !exists { (*pt)[*source] = make(map[int64]uint) (*pt)[*source][ephID.Int64()] = 0 - }else if _, exists := (*pt)[*source][ephID.Int64()]; !exists{ + } else if _, exists := (*pt)[*source][ephID.Int64()]; !exists { (*pt)[*source][ephID.Int64()] = 0 - }else{ + } else { (*pt)[*source][ephID.Int64()] = (*pt)[*source][ephID.Int64()] + 1 } } //reports all resent polls -func (pt *pollTracker)Report()string{ +func (pt *pollTracker) Report() string { report := "" numReports := uint(0) - for source := range *pt{ + for source := range *pt { numSubReports := uint(0) subReport := "" - for ephID, reports := range (*pt)[source]{ + for ephID, reports := range (*pt)[source] { numSubReports += reports subReport += fmt.Sprintf("\n\t\tEphID %d polled %d times", ephID, reports) } @@ -43,4 +43,3 @@ func (pt *pollTracker)Report()string{ return fmt.Sprintf("\nPolled the network %d times", numReports) + report } - diff --git a/network/rounds/check.go b/network/rounds/check.go index 0329cd8e2..38e121304 100644 --- a/network/rounds/check.go +++ b/network/rounds/check.go @@ -31,13 +31,13 @@ func (m *Manager) Checker(roundID id.Round, filters []*RemoteFilter, identity re if !notProcessing { // if is already processing, ignore return false - }else if completed{ + } else if completed { return true } //if the number of times the round has been checked has hit the max, drop it if count == m.params.MaxAttemptsCheckingARound { - jww.ERROR.Printf("Looking up Round %v for %d (%s) failed " + + jww.ERROR.Printf("Looking up Round %v for %d (%s) failed "+ "the maximum number of times (%v), stopping retrval attempt", roundID, identity.EphId, identity.Source, m.params.MaxAttemptsCheckingARound) @@ -61,7 +61,7 @@ func (m *Manager) Checker(roundID id.Round, filters []*RemoteFilter, identity re //if it is not present, set the round as checked //that means no messages are available for the user in the round if !hasRound { - jww.DEBUG.Printf("No messages found for %d (%s) in round %d, " + + jww.DEBUG.Printf("No messages found for %d (%s) in round %d, "+ "will not check again", identity.EphId.Int64(), identity.Source, roundID) m.p.Done(roundID, identity.EphId, identity.Source) return true @@ -74,7 +74,7 @@ func (m *Manager) Checker(roundID id.Round, filters []*RemoteFilter, identity re jww.WARN.Printf("Forcing use of historical rounds for round ID %d.", roundID) } - jww.INFO.Printf("Messages found in round %d for %d (%s), looking " + + jww.INFO.Printf("Messages found in round %d for %d (%s), looking "+ "up messages via historical lookup", roundID, identity.EphId.Int64(), identity.Source) // If we didn't find it, send to Historical Rounds Retrieval @@ -83,7 +83,7 @@ func (m *Manager) Checker(roundID id.Round, filters []*RemoteFilter, identity re identity: identity, } } else { - jww.INFO.Printf("Messages found in round %d for %d (%s), looking " + + jww.INFO.Printf("Messages found in round %d for %d (%s), looking "+ "up messages via in ram lookup", roundID, identity.EphId.Int64(), identity.Source) // If found, send to Message Retrieval Workers diff --git a/network/rounds/historical.go b/network/rounds/historical.go index 3d4460a0d..1a0f5c100 100644 --- a/network/rounds/historical.go +++ b/network/rounds/historical.go @@ -73,7 +73,7 @@ func (m *Manager) processHistoricalRounds(comm historicalRoundsComms, quitCh <-c } // get new round to lookup and force a lookup if case r := <-m.historicalRounds: - jww.DEBUG.Printf("Recieved and quing round %d for " + + jww.DEBUG.Printf("Recieved and quing round %d for "+ "historical rounds lookup", r.rid) roundRequests = append(roundRequests, r) if len(roundRequests) > int(m.params.MaxHistoricalRounds) { @@ -104,7 +104,7 @@ func (m *Manager) processHistoricalRounds(comm historicalRoundsComms, quitCh <-c Rounds: rounds, } - jww.DEBUG.Printf("Requesting Historical rounds %v from " + + jww.DEBUG.Printf("Requesting Historical rounds %v from "+ "gateway %s", rounds, gwHost.GetId()) response, err := comm.RequestHistoricalRounds(gwHost, hr) diff --git a/network/rounds/manager.go b/network/rounds/manager.go index 96cc9d716..c2a3a37b2 100644 --- a/network/rounds/manager.go +++ b/network/rounds/manager.go @@ -62,7 +62,7 @@ func (m *Manager) StartProcessors() stoppable.Stoppable { return multi } -func (m *Manager) DeleteProcessingRoundDelete(round id.Round, eph ephemeral.Id, source *id.ID) { +func (m *Manager) DeleteProcessingRoundDelete(round id.Round, eph ephemeral.Id, source *id.ID) { m.p.Delete(round, eph, source) } diff --git a/network/rounds/processingRounds.go b/network/rounds/processingRounds.go index 0ac44fa57..21687c896 100644 --- a/network/rounds/processingRounds.go +++ b/network/rounds/processingRounds.go @@ -20,7 +20,7 @@ import ( type status struct { failCount uint processing bool - done bool + done bool } // processing struct with a lock so it can be managed with concurrent threads. @@ -31,7 +31,7 @@ type processing struct { type hashID [16]byte -func makeHashID(round id.Round, eph ephemeral.Id, source *id.ID)hashID{ +func makeHashID(round id.Round, eph ephemeral.Id, source *id.ID) hashID { h := md5.New() ridbytes := make([]byte, 8) binary.BigEndian.PutUint64(ridbytes, uint64(round)) @@ -64,7 +64,7 @@ func (pr *processing) Process(round id.Round, eph ephemeral.Id, source *id.ID) ( if rs, ok := pr.rounds[hid]; ok { if rs.processing { return false, false, rs.failCount - } else if rs.done{ + } else if rs.done { return false, true, 0 } rs.processing = true diff --git a/network/rounds/processingRounds_test.go b/network/rounds/processingRounds_test.go index d69d85906..94f819dd0 100644 --- a/network/rounds/processingRounds_test.go +++ b/network/rounds/processingRounds_test.go @@ -119,7 +119,7 @@ func TestProcessing_Done(t *testing.T) { hid := makeHashID(rid, ephID, source) pr.rounds[hid] = &status{0, true, false} pr.Done(rid, ephID, source) - if s, _ := pr.rounds[hid]; !s.done{ + if s, _ := pr.rounds[hid]; !s.done { t.Errorf("Done() failed to flag round ID %d.", rid) } } diff --git a/network/rounds/retrieve.go b/network/rounds/retrieve.go index 152fe8791..ff68f8704 100644 --- a/network/rounds/retrieve.go +++ b/network/rounds/retrieve.go @@ -67,7 +67,7 @@ func (m *Manager) getMessagesFromGateway(roundInfo *pb.RoundInfo, "to request from") } - jww.INFO.Printf("Getting messages for RoundID %v for EphID %d " + + jww.INFO.Printf("Getting messages for RoundID %v for EphID %d "+ "via Gateway: %s", rid, identity.EphId, gwHost.GetId()) // send the request diff --git a/storage/e2e/negotiation.go b/storage/e2e/negotiation.go index 1a6174dd7..783f6a04a 100644 --- a/storage/e2e/negotiation.go +++ b/storage/e2e/negotiation.go @@ -43,4 +43,4 @@ func (c Negotiation) String() string { default: return fmt.Sprintf("Unknown Negotiation %v", uint8(c)) } -} \ No newline at end of file +} diff --git a/storage/e2e/relationship.go b/storage/e2e/relationship.go index 8a3c34ece..8af504600 100644 --- a/storage/e2e/relationship.go +++ b/storage/e2e/relationship.go @@ -244,10 +244,10 @@ func (r *relationship) getSessionForSending() *Session { } jww.INFO.Printf("Details about %v sessions which are invalid:", len(sessions)) - for i, s := range sessions{ - if s==nil{ + for i, s := range sessions { + if s == nil { jww.INFO.Printf("\tSession %v is nil", i) - }else{ + } else { jww.INFO.Printf("\tSession %v: status: %v, confimred: %v", i, s.Status(), s.IsConfirmed()) } } diff --git a/storage/e2e/relationship_test.go b/storage/e2e/relationship_test.go index af1272297..df9e7be0e 100644 --- a/storage/e2e/relationship_test.go +++ b/storage/e2e/relationship_test.go @@ -268,8 +268,8 @@ func TestRelationship_GetSessionForSending(t *testing.T) { if sending.GetID() != sb.sessions[0].GetID() { t.Error("got an unexpected session") } - if sending.Status()!=RekeyNeeded || sending.IsConfirmed(){ - t.Errorf("returned session is expected to be 'RekeyNedded' " + + if sending.Status() != RekeyNeeded || sending.IsConfirmed() { + t.Errorf("returned session is expected to be 'RekeyNedded' "+ "'Unconfirmed', it is: %s, confirmed: %v", sending.Status(), sending.IsConfirmed()) } @@ -289,8 +289,8 @@ func TestRelationship_GetSessionForSending(t *testing.T) { t.Error("got an unexpected session") } - if sending.Status()!=Active || sending.IsConfirmed(){ - t.Errorf("returned session is expected to be 'Active' " + + if sending.Status() != Active || sending.IsConfirmed() { + t.Errorf("returned session is expected to be 'Active' "+ "'Unconfirmed', it is: %s, confirmed: %v", sending.Status(), sending.IsConfirmed()) } @@ -309,13 +309,12 @@ func TestRelationship_GetSessionForSending(t *testing.T) { if sending.GetID() != sb.sessions[0].GetID() { t.Error("got an unexpected session") } - if sending.Status()!=RekeyNeeded || !sending.IsConfirmed(){ - t.Errorf("returned session is expected to be 'RekeyNeeded' " + + if sending.Status() != RekeyNeeded || !sending.IsConfirmed() { + t.Errorf("returned session is expected to be 'RekeyNeeded' "+ "'Confirmed', it is: %s, confirmed: %v", sending.Status(), sending.IsConfirmed()) } - // Fourth case: confirmed active confirmedActive, _ := makeTestSession() sb.AddSession(confirmedActive.myPrivKey, confirmedActive.partnerPubKey, @@ -330,8 +329,8 @@ func TestRelationship_GetSessionForSending(t *testing.T) { if sending.GetID() != sb.sessions[0].GetID() { t.Errorf("got an unexpected session of state: %s", sending.Status()) } - if sending.Status()!=Active || !sending.IsConfirmed(){ - t.Errorf("returned session is expected to be 'Active' " + + if sending.Status() != Active || !sending.IsConfirmed() { + t.Errorf("returned session is expected to be 'Active' "+ "'Confirmed', it is: %s, confirmed: %v", sending.Status(), sending.IsConfirmed()) } diff --git a/storage/e2e/session.go b/storage/e2e/session.go index f339a4a68..2be837e61 100644 --- a/storage/e2e/session.go +++ b/storage/e2e/session.go @@ -101,7 +101,7 @@ func newSession(ship *relationship, t RelationshipType, myPrivKey, partnerPubKey baseKey *cyclic.Int, trigger SessionID, relationshipFingerprint []byte, negotiationStatus Negotiation, e2eParams params.E2ESessionParams) *Session { - if e2eParams.MinKeys<10{ + if e2eParams.MinKeys < 10 { jww.FATAL.Panicf("Cannot create a session with a minnimum number " + "of keys less than 10") } @@ -552,7 +552,7 @@ func (s *Session) generate(kv *versioned.KV) *versioned.KV { s.baseKey.Bytes(), h).Int64() + int64(p.MinKeys)) // start rekeying when 75% of keys have been used - s.rekeyThreshold = (numKeys*3)/4 + s.rekeyThreshold = (numKeys * 3) / 4 // the total number of keys should be the number of rekeys plus the // number of keys to use diff --git a/storage/reception/IdentityUse.go b/storage/reception/IdentityUse.go index 829425ea5..37432d9d1 100644 --- a/storage/reception/IdentityUse.go +++ b/storage/reception/IdentityUse.go @@ -45,4 +45,4 @@ func (iu IdentityUse) setSamplingPeriod(rng io.Reader) (IdentityUse, error) { iu.StartRequest = iu.StartValid.Add(-time.Duration(periodOffset)) iu.EndRequest = iu.EndValid.Add(iu.RequestMask - time.Duration(periodOffset)) return iu, nil -} \ No newline at end of file +} diff --git a/storage/reception/registration.go b/storage/reception/registration.go index a0c835cc4..2365cdea6 100644 --- a/storage/reception/registration.go +++ b/storage/reception/registration.go @@ -14,7 +14,7 @@ const knownRoundsStorageKey = "krStorage" type registration struct { Identity ur *UnknownRound - kv *versioned.KV + kv *versioned.KV } func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) { @@ -35,9 +35,9 @@ func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) { kv = kv.Prefix(regPrefix(reg.EphId, reg.Source, reg.StartValid)) r := ®istration{ - Identity: reg, - ur: NewUnknownRound(!reg.Ephemeral, kv), - kv: kv, + Identity: reg, + ur: NewUnknownRound(!reg.Ephemeral, kv), + kv: kv, } // If this is not ephemeral, then store everything @@ -50,8 +50,6 @@ func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) { } } - - return r, nil } @@ -69,9 +67,9 @@ func loadRegistration(EphId ephemeral.Id, Source *id.ID, startValid time.Time, ur := LoadUnknownRound(kv) r := ®istration{ - Identity: reg, - ur: ur, - kv: kv, + Identity: reg, + ur: ur, + kv: kv, } return r, nil diff --git a/storage/reception/registration_test.go b/storage/reception/registration_test.go index 4705be0c6..20d03c159 100644 --- a/storage/reception/registration_test.go +++ b/storage/reception/registration_test.go @@ -80,7 +80,7 @@ func TestNewRegistration_Persistent(t *testing.T) { LoadUnknownRound(reg.kv) if _, err = reg.kv.Get(identityStorageKey); err != nil { - t.Errorf("Persistent identity did not store the identity when " + + t.Errorf("Persistent identity did not store the identity when "+ "it should: %+v.", err) } } diff --git a/storage/reception/unknownRound.go b/storage/reception/unknownRound.go index 49762bd41..7912b9d5c 100644 --- a/storage/reception/unknownRound.go +++ b/storage/reception/unknownRound.go @@ -12,14 +12,14 @@ import ( const unknownRoundStorageKey = "unknownRoundStorage" const unknownRoundStorageVersion = 0 -type UnknownRound struct{ +type UnknownRound struct { stored bool - kv *versioned.KV - rid id.Round - mux sync.Mutex + kv *versioned.KV + rid id.Round + mux sync.Mutex } -func NewUnknownRound(stored bool, kv *versioned.KV)*UnknownRound{ +func NewUnknownRound(stored bool, kv *versioned.KV) *UnknownRound { ur := &UnknownRound{ stored: stored, kv: kv, @@ -29,7 +29,7 @@ func NewUnknownRound(stored bool, kv *versioned.KV)*UnknownRound{ return ur } -func LoadUnknownRound(kv *versioned.KV)*UnknownRound{ +func LoadUnknownRound(kv *versioned.KV) *UnknownRound { ur := &UnknownRound{ stored: true, kv: kv, @@ -41,7 +41,6 @@ func LoadUnknownRound(kv *versioned.KV)*UnknownRound{ jww.FATAL.Panicf("Failed to get the unknown round: %+v", err) } - err = json.Unmarshal(obj.Data, &ur.rid) if err != nil { jww.FATAL.Panicf("Failed to unmarshal the unknown round: %+v", err) @@ -49,7 +48,7 @@ func LoadUnknownRound(kv *versioned.KV)*UnknownRound{ return ur } -func (ur *UnknownRound)save() { +func (ur *UnknownRound) save() { if ur.stored { urStr, err := json.Marshal(&ur.rid) if err != nil { @@ -71,18 +70,17 @@ func (ur *UnknownRound)save() { } } - -func (ur *UnknownRound)Set(rid id.Round)id.Round{ +func (ur *UnknownRound) Set(rid id.Round) id.Round { ur.mux.Lock() defer ur.mux.Unlock() - if rid>ur.rid{ + if rid > ur.rid { ur.rid = rid ur.save() } return ur.rid } -func (ur *UnknownRound)Get()id.Round { +func (ur *UnknownRound) Get() id.Round { ur.mux.Lock() defer ur.mux.Unlock() return ur.rid @@ -92,7 +90,7 @@ func (ur *UnknownRound) delete() { ur.mux.Lock() defer ur.mux.Unlock() err := ur.kv.Delete(unknownRoundStorageKey) - if err!=nil{ + if err != nil { jww.FATAL.Panicf("Failed to delete unknownRound storage: %+v", err) } } diff --git a/storage/utility/cmixMessageBuffer.go b/storage/utility/cmixMessageBuffer.go index 7611e87c2..ce53a60f5 100644 --- a/storage/utility/cmixMessageBuffer.go +++ b/storage/utility/cmixMessageBuffer.go @@ -22,15 +22,15 @@ const currentCmixMessageVersion = 0 type cmixMessageHandler struct{} -type storedMessage struct{ +type storedMessage struct { Msg []byte Recipient []byte } -func (sm storedMessage)Marshal()[]byte{ +func (sm storedMessage) Marshal() []byte { data, err := json.Marshal(&sm) - if err!=nil{ + if err != nil { jww.FATAL.Panicf("Failed to marshal stored message: %s", err) } @@ -64,7 +64,7 @@ func (cmh *cmixMessageHandler) LoadMessage(kv *versioned.KV, key string) (interf } sm := storedMessage{} - if err = json.Unmarshal(vo.Data, &sm); err!=nil{ + if err = json.Unmarshal(vo.Data, &sm); err != nil { return nil, errors.Wrap(err, "Failed to unmarshal stored message") } @@ -133,8 +133,8 @@ func (cmb *CmixMessageBuffer) Next() (format.Message, *id.ID, bool) { sm := m.(storedMessage) msg := format.Unmarshal(sm.Msg) recpient, err := id.Unmarshal(sm.Recipient) - if err!=nil{ - jww.FATAL.Panicf("Could nto get an id for stored cmix " + + if err != nil { + jww.FATAL.Panicf("Could nto get an id for stored cmix "+ "message buffer: %+v", err) } return msg, recpient, true diff --git a/storage/utility/cmixMessageBuffer_test.go b/storage/utility/cmixMessageBuffer_test.go index 149da6663..9e42103dd 100644 --- a/storage/utility/cmixMessageBuffer_test.go +++ b/storage/utility/cmixMessageBuffer_test.go @@ -122,7 +122,7 @@ func TestCmixMessageBuffer_Smoke(t *testing.T) { 1, len(cmb.mb.messages)) } - msg, rid, exists = cmb.Next() + msg, rid, exists = cmb.Next() if !exists { t.Error("Next() did not find any messages in buffer.") } diff --git a/ud/confirmFact_test.go b/ud/confirmFact_test.go index 5645898e8..2e060c098 100644 --- a/ud/confirmFact_test.go +++ b/ud/confirmFact_test.go @@ -30,8 +30,8 @@ func TestManager_confirmFact(t *testing.T) { // Set up manager m := &Manager{ - host: host, - registered:&isReg, + host: host, + registered: &isReg, } c := &testComm{} diff --git a/ud/manager.go b/ud/manager.go index 661754bd8..d38c5aa5b 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -41,8 +41,7 @@ type Manager struct { // internal structures host *connect.Host single SingleInterface - myID *id.ID - + myID *id.ID registered *uint32 } diff --git a/ud/registered.go b/ud/registered.go index e1134f0d9..6c1065177 100644 --- a/ud/registered.go +++ b/ud/registered.go @@ -14,13 +14,13 @@ const isRegisteredVersion = 0 // loadRegistered loads from storage if the client is registered with user // discovery. -func (m *Manager) loadRegistered() { +func (m *Manager) loadRegistered() { var isReg = uint32(0) obj, err := m.storage.Get(isRegisteredKey) if err != nil { - jww.INFO.Printf("Failed to load is registered; " + + jww.INFO.Printf("Failed to load is registered; "+ "assuming un-registered: %s", err) - }else{ + } else { isReg = binary.BigEndian.Uint32(obj.Data) } @@ -28,13 +28,13 @@ func (m *Manager) loadRegistered() { } // IsRegistered returns if the client is registered with user discovery -func (m *Manager) IsRegistered()bool { - return atomic.LoadUint32(m.registered)==1 +func (m *Manager) IsRegistered() bool { + return atomic.LoadUint32(m.registered) == 1 } // IsRegistered returns if the client is registered with user discovery -func (m *Manager) setRegistered()error { - if !atomic.CompareAndSwapUint32(m.registered,0,1){ +func (m *Manager) setRegistered() error { + if !atomic.CompareAndSwapUint32(m.registered, 0, 1) { return errors.New("cannot register with User Discovery when " + "already registered") } @@ -49,7 +49,7 @@ func (m *Manager) setRegistered()error { } if err := m.storage.Set(isRegisteredKey, obj); err != nil { - jww.FATAL.Panicf("Failed to store that the client is " + + jww.FATAL.Panicf("Failed to store that the client is "+ "registered: %+v", err) } return nil diff --git a/ud/remove_test.go b/ud/remove_test.go index c8c46b901..bfe30a77d 100644 --- a/ud/remove_test.go +++ b/ud/remove_test.go @@ -32,11 +32,11 @@ func TestRemoveFact(t *testing.T) { isReg := uint32(1) m := Manager{ - comms: nil, - host: h, - privKey: cpk, + comms: nil, + host: h, + privKey: cpk, registered: &isReg, - myID: &id.ID{}, + myID: &id.ID{}, } f := fact.Fact{ -- GitLab