From 6f9309c8e28d763de43637475a23b5c2ae5e7e39 Mon Sep 17 00:00:00 2001 From: Jake Taylor <jake@elixxir.io> Date: Tue, 13 Apr 2021 12:35:23 -0500 Subject: [PATCH] go fmt --- bindings/callback.go | 7 +++---- interfaces/params/network.go | 12 ++++++------ interfaces/params/rounds.go | 6 +++--- keyExchange/exchange.go | 4 ++-- network/checkedRounds.go | 29 ++++++++++++++-------------- network/rounds/check.go | 10 +++++----- network/rounds/manager.go | 2 +- stoppable/cleanup.go | 2 +- storage/cmix/store_test.go | 1 - storage/e2e/relationship.go | 4 ++-- storage/e2e/relationship_test.go | 2 +- storage/e2e/session.go | 6 +++--- storage/e2e/session_test.go | 6 +++--- storage/e2e/store.go | 4 ++-- storage/rounds/unknownRounds_test.go | 6 +++--- 15 files changed, 49 insertions(+), 52 deletions(-) diff --git a/bindings/callback.go b/bindings/callback.go index 34d26eccc..d0fe898c2 100644 --- a/bindings/callback.go +++ b/bindings/callback.go @@ -97,16 +97,15 @@ type ClientError interface { Report(source, message, trace string) } - -type LogWriter interface{ +type LogWriter interface { Log(string) } -type writerAdapter struct{ +type writerAdapter struct { lw LogWriter } -func (wa *writerAdapter)Write(p []byte) (n int, err error){ +func (wa *writerAdapter) Write(p []byte) (n int, err error) { wa.lw.Log(string(p)) return len(p), nil } diff --git a/interfaces/params/network.go b/interfaces/params/network.go index b84c38a09..24af3d540 100644 --- a/interfaces/params/network.go +++ b/interfaces/params/network.go @@ -35,13 +35,13 @@ type Network struct { func GetDefaultNetwork() Network { n := Network{ - TrackNetworkPeriod: 100 * time.Millisecond, - MaxCheckedRounds: 500, - RegNodesBufferLen: 500, - NetworkHealthTimeout: 30 * time.Second, - E2EParams: GetDefaultE2ESessionParams(), + TrackNetworkPeriod: 100 * time.Millisecond, + MaxCheckedRounds: 500, + RegNodesBufferLen: 500, + NetworkHealthTimeout: 30 * time.Second, + E2EParams: GetDefaultE2ESessionParams(), ParallelNodeRegistrations: 8, - KnownRoundsThreshold: 1500, //5 rounds/sec * 60 sec/min * 5 min + KnownRoundsThreshold: 1500, //5 rounds/sec * 60 sec/min * 5 min } n.Rounds = GetDefaultRounds() n.Messages = GetDefaultMessage() diff --git a/interfaces/params/rounds.go b/interfaces/params/rounds.go index 87fa53fc0..07c4c3c25 100644 --- a/interfaces/params/rounds.go +++ b/interfaces/params/rounds.go @@ -39,9 +39,9 @@ func GetDefaultRounds() Rounds { HistoricalRoundsPeriod: 100 * time.Millisecond, NumMessageRetrievalWorkers: 8, - HistoricalRoundsBufferLen: 1000, - LookupRoundsBufferLen: 2000, - ForceHistoricalRounds: false, + HistoricalRoundsBufferLen: 1000, + LookupRoundsBufferLen: 2000, + ForceHistoricalRounds: false, MaxHistoricalRoundsRetries: 3, } } diff --git a/keyExchange/exchange.go b/keyExchange/exchange.go index d94e8800f..42b7a177e 100644 --- a/keyExchange/exchange.go +++ b/keyExchange/exchange.go @@ -32,7 +32,7 @@ func Start(switchboard *switchboard.Switchboard, sess *storage.Session, net inte // create the trigger stoppable triggerStop := stoppable.NewSingle(keyExchangeTriggerName) - cleanupTrigger := func(){ + cleanupTrigger := func() { switchboard.Unregister(triggerID) } @@ -46,7 +46,7 @@ func Start(switchboard *switchboard.Switchboard, sess *storage.Session, net inte // register the confirm stoppable confirmStop := stoppable.NewSingle(keyExchangeConfirmName) - cleanupConfirm := func(){ + cleanupConfirm := func() { switchboard.Unregister(confirmID) } diff --git a/network/checkedRounds.go b/network/checkedRounds.go index 8ffa9ba39..d104ac958 100644 --- a/network/checkedRounds.go +++ b/network/checkedRounds.go @@ -7,36 +7,35 @@ import ( "gitlab.com/xx_network/primitives/id" ) - type idFingerprint [16]byte -type checkedRounds struct{ +type checkedRounds struct { lookup map[idFingerprint]*checklist } -type checklist struct{ +type checklist struct { m map[id.Round]interface{} l *list.List } -func newCheckedRounds()*checkedRounds{ +func newCheckedRounds() *checkedRounds { return &checkedRounds{ lookup: make(map[idFingerprint]*checklist), } } -func (cr *checkedRounds)Check(identity reception.IdentityUse, rid id.Round)bool{ +func (cr *checkedRounds) Check(identity reception.IdentityUse, rid id.Round) bool { idFp := getIdFingerprint(identity) cl, exists := cr.lookup[idFp] - if !exists{ + if !exists { cl = &checklist{ m: make(map[id.Round]interface{}), l: list.New().Init(), } - cr.lookup[idFp]=cl + cr.lookup[idFp] = cl } - if _, exists := cl.m[rid]; !exists{ + if _, exists := cl.m[rid]; !exists { cl.m[rid] = nil cl.l.PushBack(rid) return true @@ -44,7 +43,7 @@ func (cr *checkedRounds)Check(identity reception.IdentityUse, rid id.Round)bool{ return false } -func (cr *checkedRounds)Prune(identity reception.IdentityUse, earliestAllowed id.Round){ +func (cr *checkedRounds) Prune(identity reception.IdentityUse, earliestAllowed id.Round) { idFp := getIdFingerprint(identity) cl, exists := cr.lookup[idFp] if !exists { @@ -52,19 +51,19 @@ func (cr *checkedRounds)Prune(identity reception.IdentityUse, earliestAllowed id } e := cl.l.Front() - for e!=nil { - if e.Value.(id.Round)<earliestAllowed{ - delete(cl.m,e.Value.(id.Round)) + for e != nil { + if e.Value.(id.Round) < earliestAllowed { + delete(cl.m, e.Value.(id.Round)) lastE := e e = e.Next() cl.l.Remove(lastE) - }else{ + } else { break } } } -func getIdFingerprint(identity reception.IdentityUse)idFingerprint{ +func getIdFingerprint(identity reception.IdentityUse) idFingerprint { h := md5.New() h.Write(identity.EphId[:]) h.Write(identity.Source[:]) @@ -72,4 +71,4 @@ func getIdFingerprint(identity reception.IdentityUse)idFingerprint{ fp := idFingerprint{} copy(fp[:], h.Sum(nil)) return fp -} \ No newline at end of file +} diff --git a/network/rounds/check.go b/network/rounds/check.go index 9deb3ec6c..a22bafd8e 100644 --- a/network/rounds/check.go +++ b/network/rounds/check.go @@ -47,9 +47,9 @@ func serializeRound(roundId id.Round) []byte { return b } -func (m *Manager) GetMessagesFromRound(roundID id.Round, identity reception.IdentityUse){ +func (m *Manager) GetMessagesFromRound(roundID id.Round, identity reception.IdentityUse) { ri, err := m.Instance.GetRound(roundID) - if err !=nil || m.params.ForceHistoricalRounds { + if err != nil || m.params.ForceHistoricalRounds { if m.params.ForceHistoricalRounds { jww.WARN.Printf("Forcing use of historical rounds for round ID %d.", roundID) @@ -59,8 +59,8 @@ func (m *Manager) GetMessagesFromRound(roundID id.Round, identity reception.Iden identity.Source) // If we didn't find it, send to Historical Rounds Retrieval m.historicalRounds <- historicalRoundRequest{ - rid: roundID, - identity: identity, + rid: roundID, + identity: identity, numAttempts: 0, } } else { @@ -74,4 +74,4 @@ func (m *Manager) GetMessagesFromRound(roundID id.Round, identity reception.Iden } } -} \ No newline at end of file +} diff --git a/network/rounds/manager.go b/network/rounds/manager.go index cdc87ea2c..942e86319 100644 --- a/network/rounds/manager.go +++ b/network/rounds/manager.go @@ -58,4 +58,4 @@ func (m *Manager) StartProcessors() stoppable.Stoppable { multi.Add(stopper) } return multi -} \ No newline at end of file +} diff --git a/stoppable/cleanup.go b/stoppable/cleanup.go index 8111abe20..b1e2c4561 100644 --- a/stoppable/cleanup.go +++ b/stoppable/cleanup.go @@ -87,7 +87,7 @@ func (c *Cleanup) Close(timeout time.Duration) error { } }) - if err!=nil{ + if err != nil { jww.ERROR.Printf(err.Error()) } diff --git a/storage/cmix/store_test.go b/storage/cmix/store_test.go index f4dfc3a7a..63329b769 100644 --- a/storage/cmix/store_test.go +++ b/storage/cmix/store_test.go @@ -70,7 +70,6 @@ func TestStore_AddRemove(t *testing.T) { } } - // Happy path Add/Has test func TestStore_AddHas(t *testing.T) { // Uncomment to print keys that Set and Get are called on diff --git a/storage/e2e/relationship.go b/storage/e2e/relationship.go index 6efd7081b..a492a72ed 100644 --- a/storage/e2e/relationship.go +++ b/storage/e2e/relationship.go @@ -303,9 +303,9 @@ func (r *relationship) getNewestRekeyableSession() *Session { // always valid. It isn't clear it can fail though because we are // accessing the data in the same order it would be written (i think) if s.Status() != RekeyEmpty { - if s.IsConfirmed(){ + if s.IsConfirmed() { return s - }else if unconfirmed == nil{ + } else if unconfirmed == nil { unconfirmed = s } } diff --git a/storage/e2e/relationship_test.go b/storage/e2e/relationship_test.go index 49fa51de4..457e4f6dc 100644 --- a/storage/e2e/relationship_test.go +++ b/storage/e2e/relationship_test.go @@ -571,4 +571,4 @@ func Test_relationship_getNewestRekeyableSession(t *testing.T) { } }) } -} \ No newline at end of file +} diff --git a/storage/e2e/session.go b/storage/e2e/session.go index 5f0344378..ad684725a 100644 --- a/storage/e2e/session.go +++ b/storage/e2e/session.go @@ -119,7 +119,7 @@ func newSession(ship *relationship, t RelationshipType, myPrivKey, partnerPubKey relationshipFingerprint: relationshipFingerprint, negotiationStatus: negotiationStatus, partnerSource: trigger, - partner: ship.manager.partner.DeepCopy(), + partner: ship.manager.partner.DeepCopy(), } session.kv = session.generate(ship.kv) @@ -173,8 +173,8 @@ func loadSession(ship *relationship, kv *versioned.KV, } session.relationshipFingerprint = relationshipFingerprint - if !session.partner.Cmp(ship.manager.partner){ - return nil, errors.Errorf("Stored partner (%s) did not match " + + if !session.partner.Cmp(ship.manager.partner) { + return nil, errors.Errorf("Stored partner (%s) did not match "+ "relationship partner (%s)", session.partner, ship.manager.partner) } diff --git a/storage/e2e/session_test.go b/storage/e2e/session_test.go index 800cac541..258cea9ed 100644 --- a/storage/e2e/session_test.go +++ b/storage/e2e/session_test.go @@ -628,8 +628,8 @@ func makeTestSession() (*Session, *context) { e2eParams: params.GetDefaultE2ESessionParams(), relationship: &relationship{ manager: &Manager{ - ctx: ctx, - kv: kv, + ctx: ctx, + kv: kv, partner: &id.ID{}, }, kv: kv, @@ -638,7 +638,7 @@ func makeTestSession() (*Session, *context) { t: Receive, negotiationStatus: Confirmed, rekeyThreshold: 5, - partner: &id.ID{}, + partner: &id.ID{}, } var err error s.keyState, err = newStateVector(s.kv, diff --git a/storage/e2e/store.go b/storage/e2e/store.go index a0a427e0a..e647cacab 100644 --- a/storage/e2e/store.go +++ b/storage/e2e/store.go @@ -260,8 +260,8 @@ func (s *Store) unmarshal(b []byte) error { partnerID, err.Error()) } - if !manager.GetPartnerID().Cmp(partnerID){ - jww.FATAL.Panicf("Loaded a manager with the wrong partner " + + if !manager.GetPartnerID().Cmp(partnerID) { + jww.FATAL.Panicf("Loaded a manager with the wrong partner "+ "ID: \n\t loaded: %s \n\t present: %s", partnerID, manager.GetPartnerID()) } diff --git a/storage/rounds/unknownRounds_test.go b/storage/rounds/unknownRounds_test.go index ffc9bdd46..f437e0839 100644 --- a/storage/rounds/unknownRounds_test.go +++ b/storage/rounds/unknownRounds_test.go @@ -27,7 +27,7 @@ func TestNewUnknownRoundsStore(t *testing.T) { params: DefaultUnknownRoundsParams(), } - store := NewUnknownRounds(kv, DefaultUnknownRoundsParams()) + store := NewUnknownRounds(kv, DefaultUnknownRoundsParams()) // Compare manually created object with NewUnknownRoundsStore if !reflect.DeepEqual(expectedStore, store) { @@ -60,7 +60,7 @@ func TestNewUnknownRoundsStore(t *testing.T) { // Full test func TestUnknownRoundsStore_Iterate(t *testing.T) { kv := versioned.NewKV(make(ekv.Memstore)) - store := NewUnknownRounds(kv, DefaultUnknownRoundsParams()) + store := NewUnknownRounds(kv, DefaultUnknownRoundsParams()) // Return true only for rounds that are even mockChecker := func(rid id.Round) bool { @@ -116,7 +116,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) { // Iterate over map until all rounds have checks incremented over // maxCheck for i := 0; i < defaultMaxCheck+1; i++ { - _ = store.Iterate(mockChecker,[]id.Round{}) + _ = store.Iterate(mockChecker, []id.Round{}) } -- GitLab