diff --git a/api/version_vars.go b/api/version_vars.go index 9ef72f196cc77927fd45ecad2a70d4a28d5ce7ae..c96f6402a0c5c0e998a03e8dd5fe5c8609fbac7b 100644 --- a/api/version_vars.go +++ b/api/version_vars.go @@ -1,16 +1,16 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated by robots at -// 2022-02-15 12:19:19.667352 -0600 CST m=+0.033427370 +// 2022-02-23 12:55:40.971513 -0600 CST m=+0.038316967 package api -const GITVERSION = `d8832766 made splitSends default to false` +const GITVERSION = `80d6fb9f Merge branch 'hotfix/RenableHistorical' into 'release'` const SEMVER = "4.0.0" const DEPENDENCIES = `module gitlab.com/elixxir/client go 1.17 require ( - github.com/cloudflare/circl v1.0.1-0.20211008185751-59b49bc148ce + github.com/cloudflare/circl v1.1.0 github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 github.com/golang/protobuf v1.5.2 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 @@ -19,13 +19,13 @@ 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.20220214214811-4a1bd320aa45 - gitlab.com/elixxir/crypto v0.0.7-0.20220211185439-4a6d9f41f8ab + gitlab.com/elixxir/comms v0.0.4-0.20220222221859-c12e29bde218 + gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b gitlab.com/elixxir/ekv v0.1.6 - gitlab.com/elixxir/primitives v0.0.3-0.20220211185255-f9bc3df21e1d - gitlab.com/xx_network/comms v0.0.4-0.20220211184526-00dc9cfe8e2e - gitlab.com/xx_network/crypto v0.0.5-0.20220211184244-5803ecaafd59 - gitlab.com/xx_network/primitives v0.0.4-0.20220211183913-d6f5fd114a2a + gitlab.com/elixxir/primitives v0.0.3-0.20220222212109-d412a6e46623 + gitlab.com/xx_network/comms v0.0.4-0.20220222212058-5a37737af57e + gitlab.com/xx_network/crypto v0.0.5-0.20220222212031-750f7e8a01f4 + gitlab.com/xx_network/primitives v0.0.4-0.20220222211843-901fa4a2d72b golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 google.golang.org/grpc v1.42.0 @@ -53,8 +53,8 @@ require ( github.com/ttacon/libphonenumber v1.2.1 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect github.com/zeebo/blake3 v0.1.1 // indirect - gitlab.com/xx_network/ring v0.0.3-0.20210527191221-ce3f170aabd5 // indirect - golang.org/x/sys v0.0.0-20210902050250-f475640dd07b // indirect + gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93 // indirect + golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect golang.org/x/text v0.3.6 // indirect google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect gopkg.in/ini.v1 v1.62.0 // indirect diff --git a/go.mod b/go.mod index 4769d0460b352b0fc653bf0c4122bfb2849ddf15..b36a47399ea8875063ca4320e64780636b98b7fd 100644 --- a/go.mod +++ b/go.mod @@ -12,11 +12,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.20220222212253-41a1a0067369 + gitlab.com/elixxir/comms v0.0.4-0.20220222221859-c12e29bde218 gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b gitlab.com/elixxir/ekv v0.1.6 gitlab.com/elixxir/primitives v0.0.3-0.20220222212109-d412a6e46623 - gitlab.com/xx_network/comms v0.0.4-0.20220222212058-5a37737af57e + gitlab.com/xx_network/comms v0.0.4-0.20220223204319-1a310472e098 gitlab.com/xx_network/crypto v0.0.5-0.20220222212031-750f7e8a01f4 gitlab.com/xx_network/primitives v0.0.4-0.20220222211843-901fa4a2d72b golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed diff --git a/go.sum b/go.sum index 8700a8af76b5e4d4b56fd8dc25cbcd794c31005d..a71a1e695479964b0590ca37e184f1fab871bb61 100644 --- a/go.sum +++ b/go.sum @@ -272,11 +272,10 @@ 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.20220222212253-41a1a0067369 h1:Bk5T3unbs3cjEqzxCirb1IlcTOMAEVQLltgsrVs1/cw= -gitlab.com/elixxir/comms v0.0.4-0.20220222212253-41a1a0067369/go.mod h1:AligJKSltFDPe/rqE2EZBfWCMSrae0zUo7scsXoyMPE= +gitlab.com/elixxir/comms v0.0.4-0.20220222221859-c12e29bde218 h1:apk5zGDMwi6DGvSd4fMCiyQALU8lB3mm+lPfaGWxwIw= +gitlab.com/elixxir/comms v0.0.4-0.20220222221859-c12e29bde218/go.mod h1:qAcXtUsEvaTE9H/cUWHOQg5DbJFapv7BLnvpFZOK7io= 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.20220222212142-d3303373ee78/go.mod h1:bPD4FmnnaDFLxn+d4YDWZhVnevWXArKwOMMza4MU5uQ= gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b h1:m80Ub5mshPbMzYjRC0nXuI8vtm6e5crISczRsP2YUJ4= gitlab.com/elixxir/crypto v0.0.7-0.20220222221347-95c7ae58da6b/go.mod h1:tD6XjtQh87T2nKZL5I/pYPck5M2wLpkZ1Oz7H/LqO10= gitlab.com/elixxir/ekv v0.1.6 h1:M2hUSNhH/ChxDd+s8xBqSEKgoPtmE6hOEBqQ73KbN6A= @@ -288,8 +287,9 @@ gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2Y gitlab.com/elixxir/primitives v0.0.3-0.20220222212109-d412a6e46623 h1:NzJ06KdJd3fVJee0QvGhNr3CO+Ki8Ea1PeakZsm+rZM= gitlab.com/elixxir/primitives v0.0.3-0.20220222212109-d412a6e46623/go.mod h1:MtFIyJUQn9P7djzVlBpEYkPNnnWFTjZvw89swoXY+QM= gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw= -gitlab.com/xx_network/comms v0.0.4-0.20220222212058-5a37737af57e h1:PrQoTQoA6be4J+Lr/AclebS5Gz0Zm/TYC5b44qWa1PU= gitlab.com/xx_network/comms v0.0.4-0.20220222212058-5a37737af57e/go.mod h1:isHnwem0v4rTcwwHP455FhVlFyPcHkHiVz+N3s/uCSI= +gitlab.com/xx_network/comms v0.0.4-0.20220223204319-1a310472e098 h1:wGXXG3m65GpzmWmumLak5dn6Sm75iAF7qlx5uz81+Pg= +gitlab.com/xx_network/comms v0.0.4-0.20220223204319-1a310472e098/go.mod h1:isHnwem0v4rTcwwHP455FhVlFyPcHkHiVz+N3s/uCSI= 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.20220222212031-750f7e8a01f4 h1:95dZDMn/hpLNwsgZO9eyQgGKaSDyh6F6+WygqZIciww= diff --git a/interfaces/params/CMIX.go b/interfaces/params/CMIX.go index db2bfa655906d3b07d98ca54ea1f1539cd2fb9ed..b7351ce00a4fe641159f8225f71a4e19f02650b5 100644 --- a/interfaces/params/CMIX.go +++ b/interfaces/params/CMIX.go @@ -39,7 +39,7 @@ func GetDefaultCMIX() CMIX { Timeout: 25 * time.Second, RetryDelay: 1 * time.Second, SendTimeout: 3 * time.Second, - DebugTag: "External", + DebugTag: "External", } } diff --git a/interfaces/params/rounds.go b/interfaces/params/rounds.go index 75e4270987ab2b5d8ea1c4edb6e49efb9f32a863..4cfdbb233326f3e85d35497f85a2b3cd50c899ac 100644 --- a/interfaces/params/rounds.go +++ b/interfaces/params/rounds.go @@ -60,7 +60,7 @@ func GetDefaultRounds() Rounds { MaxHistoricalRoundsRetries: 3, UncheckRoundPeriod: 20 * time.Second, ForceMessagePickupRetry: false, - SendTimeout: 1 * time.Second, - RealtimeOnly: false, + SendTimeout: 3 * time.Second, + RealtimeOnly: false, } } diff --git a/network/gateway/hostPool.go b/network/gateway/hostPool.go index 43ae1481b9dcb01f732b12e6d6234fbc29acf5ff..eed695bb9a56ebc4ef8ef4e43289e19376593b3f 100644 --- a/network/gateway/hostPool.go +++ b/network/gateway/hostPool.go @@ -91,11 +91,12 @@ func DefaultPoolParams() PoolParams { HostParams: connect.GetDefaultHostParams(), } p.HostParams.MaxRetries = 1 + p.HostParams.MaxSendRetries = 1 p.HostParams.AuthEnabled = false p.HostParams.EnableCoolOff = false p.HostParams.NumSendsBeforeCoolOff = 1 p.HostParams.CoolOffTimeout = 5 * time.Minute - p.HostParams.SendTimeout = 2000 * time.Millisecond + p.HostParams.SendTimeout = 1 * time.Second p.HostParams.PingTimeout = 1 * time.Second return p } @@ -462,7 +463,7 @@ func (h *HostPool) checkReplace(hostId *id.ID, hostErr error) (bool, error) { } h.hostMux.Unlock() } - return doReplace, err + return doReplace && err == nil, err } // Select a viable HostPool candidate from the NDF diff --git a/network/gateway/sender.go b/network/gateway/sender.go index b3b029f369bd91ada4f023f5fd77bb336e682177..dae588f4f355130749f7c16057afd0b301b0b6ca 100644 --- a/network/gateway/sender.go +++ b/network/gateway/sender.go @@ -51,27 +51,26 @@ func (s *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error return nil, errors.Errorf(stoppable.ErrMsg, stop.Name(), "SendToAny") } else if err == nil { return result, nil - } else if strings.Contains(err.Error(), RetryableError) { - // Retry of the proxy could not communicate - jww.INFO.Printf("Unable to SendToAny via %s: non-fatal error received, retrying: %s", - proxies[proxy].GetId().String(), err) - } else if strings.Contains(err.Error(), "unable to connect to target host") || - strings.Contains(err.Error(), "unable to find target host") { - // Retry of the proxy could not communicate - jww.WARN.Printf("Unable to SendToAny via %s: %s,"+ - " proxy could not contact requested host", - proxies[proxy].GetId(), err) - continue - } else if replaced, checkReplaceErr := s.checkReplace(proxies[proxy].GetId(), err); replaced { - if checkReplaceErr != nil { + } else { + // Now we must check whether the Host should be replaced + replaced, checkReplaceErr := s.checkReplace(proxies[proxy].GetId(), err) + if replaced { jww.WARN.Printf("Unable to SendToAny, replaced a proxy %s with error %s", - proxies[proxy].GetId().String(), checkReplaceErr) + proxies[proxy].GetId().String(), err.Error()) } else { - jww.WARN.Printf("Unable to SendToAny, replaced a proxy %s", - proxies[proxy].GetId().String()) + if checkReplaceErr != nil { + jww.WARN.Printf("Unable to SendToAny via %s: %s. Unable to replace host: %+v", + proxies[proxy].GetId().String(), err.Error(), checkReplaceErr) + } else { + jww.WARN.Printf("Unable to SendToAny via %s: %s. Did not replace host.", + proxies[proxy].GetId().String(), err.Error()) + } + } + + // End for non-retryable errors + if !strings.Contains(err.Error(), RetryableError) { + return nil, errors.WithMessage(err, "Received error with SendToAny") } - } else { - return nil, errors.WithMessage(err, "Received error with SendToAny") } } @@ -107,34 +106,26 @@ func (s *Sender) SendToPreferred(targets []*id.ID, sendFunc sendToPreferredFunc, return nil, errors.Errorf(stoppable.ErrMsg, stop.Name(), "SendToPreferred") } else if err == nil { return result, nil - } else if strings.Contains(err.Error(), RetryableError) { - // Retry of the proxy could not communicate - jww.INFO.Printf("Unable to to SendToPreferred first pass %s via %s: non-fatal error received, retrying: %s", - targets[i], targetHosts[i].GetId(), err) - } else if strings.Contains(err.Error(), "unable to connect to target host") || - strings.Contains(err.Error(), "unable to find target host") { - // Retry of the proxy could not communicate - jww.WARN.Printf("Unable to SendToPreferred first pass %s via %s: %s, "+ - "proxy could not contact requested host", - targets[i], targetHosts[i].GetId(), err) - continue - } else if replaced, checkReplaceErr := s.checkReplace(targetHosts[i].GetId(), err); replaced { - if checkReplaceErr != nil { - jww.WARN.Printf("Unable to SendToPreferred first pass %s via %s, "+ - "proxy failed, was replaced with error: %s", - targets[i], targetHosts[i].GetId(), checkReplaceErr) + } else { + // Now we must check whether the Host should be replaced + replaced, checkReplaceErr := s.checkReplace(targetHosts[i].GetId(), err) + if replaced { + jww.WARN.Printf("Unable to SendToPreferred first pass via %s, replaced a proxy %s with error %s", + targets[i], targetHosts[i].GetId(), err.Error()) } else { - jww.WARN.Printf("Unable to SendToPreferred first pass %s via %s, "+ - "proxy failed, was replaced", - targets[i], targetHosts[i].GetId()) + if checkReplaceErr != nil { + jww.WARN.Printf("Unable to SendToPreferred first pass %s via %s: %s. Unable to replace host: %+v", + targets[i], targetHosts[i].GetId(), err.Error(), checkReplaceErr) + } else { + jww.WARN.Printf("Unable to SendToPreferred first pass %s via %s: %s. Did not replace host.", + targets[i], targetHosts[i].GetId(), err.Error()) + } + } + + // End for non-retryable errors + if !strings.Contains(err.Error(), RetryableError) { + return nil, errors.WithMessage(err, "Received error with SendToPreferred") } - jww.WARN.Printf("Unable to SendToPreferred first pass %s via %s: %s, proxy failed, was replaced", - targets[i], targetHosts[i].GetId(), checkReplaceErr) - continue - } else { - jww.WARN.Printf("Unable to SendToPreferred first pass %s via %s: %s, comm returned an error", - targets[i], targetHosts[i].GetId(), err) - return result, err } } @@ -182,29 +173,30 @@ func (s *Sender) SendToPreferred(targets []*id.ID, sendFunc sendToPreferredFunc, // Retry of the proxy could not communicate jww.INFO.Printf("Unable to SendToPreferred second pass %s via %s: non-fatal error received, retrying: %s", target, proxy, err) - } else if strings.Contains(err.Error(), "unable to connect to target host") || - strings.Contains(err.Error(), "unable to find target host") { - // Retry of the proxy could not communicate - jww.WARN.Printf("Unable to SendToPreferred second pass %s via %s: %s,"+ - " proxy could not contact requested host", - target, proxy, err) continue - } else if replaced, checkReplaceErr := s.checkReplace(proxy.GetId(), err); replaced { - if checkReplaceErr != nil { - jww.WARN.Printf("Unable to SendToPreferred second pass %s via %s,"+ - "proxy failed, was replaced with error: %s", target, proxy.GetId(), - checkReplaceErr) + } else if err == nil { + return result, nil + } else { + // Now we must check whether the Host should be replaced + replaced, checkReplaceErr := s.checkReplace(proxy.GetId(), err) + badProxies[proxy.String()] = nil + if replaced { + jww.WARN.Printf("Unable to SendToPreferred second pass via %s, replaced a proxy %s with error %s", + target, proxy.GetId(), err.Error()) } else { - jww.WARN.Printf("Unable to SendToPreferred second pass %s via %s, "+ - "proxy failed, was replaced", target, proxy.GetId()) + if checkReplaceErr != nil { + jww.WARN.Printf("Unable to SendToPreferred second pass %s via %s: %s. Unable to replace host: %+v", + target, proxy.GetId(), err.Error(), checkReplaceErr) + } else { + jww.WARN.Printf("Unable to SendToPreferred second pass %s via %s: %s. Did not replace host.", + target, proxy.GetId(), err.Error()) + } } - badProxies[proxy.String()] = nil - continue - } else { - jww.WARN.Printf("Unable to SendToPreferred second pass %s via %s: %s, comm returned an error", - target, proxy.GetId(), err) - return result, err + // End for non-retryable errors + if !strings.Contains(err.Error(), RetryableError) { + return nil, errors.WithMessage(err, "Received error with SendToPreferred") + } } } } diff --git a/network/rounds/check.go b/network/rounds/check.go index 295a63f0abdb607660c0e6bc6865e7d026d608f6..afcd20f1d52a0f1b089adb82b28606f576ebf1ec 100644 --- a/network/rounds/check.go +++ b/network/rounds/check.go @@ -56,11 +56,6 @@ func serializeRound(roundId id.Round) []byte { func (m *Manager) GetMessagesFromRound(roundID id.Round, identity reception.IdentityUse) { ri, err := m.Instance.GetRound(roundID) if err != nil || m.params.ForceHistoricalRounds { - if m.params.RealtimeOnly { - jww.WARN.Printf("Skipping round %d because it is not in ram and we are realtime only mode", - roundID) - return - } if m.params.ForceHistoricalRounds { jww.WARN.Printf("Forcing use of historical rounds for round ID %d.", roundID) diff --git a/single/reception.go b/single/reception.go index b4aa68f8341da6dba735639883239fcc1d0a97da..01faada1fa07ada31f779ec25f2eecc973f95f9b 100644 --- a/single/reception.go +++ b/single/reception.go @@ -114,9 +114,8 @@ func (m *Manager) processTransmission(msg format.Message, c := NewContact(payload.GetRID(transmitMsg.GetPubKey(grp)), transmitMsg.GetPubKey(grp), dhKey, payload.GetTagFP(), payload.GetMaxParts()) - jww.INFO.Printf("Generated by singe use receiver reception id for single use: %s, "+ - "ephId: %v, pubkey: %x", - c.partner, "unknown:", transmitMsg.GetPubKey(grp).Bytes()) + jww.INFO.Printf("Generated by singe use receiver reception id for single use. EphId %s, PubKey: %x", + c.partner, transmitMsg.GetPubKey(grp).Bytes()) return payload.GetContents(), c, nil } diff --git a/storage/auth/previousNegotiations.go b/storage/auth/previousNegotiations.go index 6a538f51825098f8602a741ea2617825eab4245a..d15bab6bd33a75985ae4b021427f58e59a3ff353 100644 --- a/storage/auth/previousNegotiations.go +++ b/storage/auth/previousNegotiations.go @@ -22,6 +22,7 @@ import ( "gitlab.com/elixxir/crypto/e2e/auth" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" + "strings" ) const ( @@ -157,11 +158,15 @@ func (s *Store) savePreviousNegotiations() error { return s.kv.Set(negotiationPartnersKey, negotiationPartnersVersion, obj) } -// loadPreviousNegotiations loads the list of previousNegotiations partners from -// storage. -func (s *Store) loadPreviousNegotiations() (map[id.ID]struct{}, error) { +// newOrLoadPreviousNegotiations loads the list of previousNegotiations partners +// from storage. +func (s *Store) newOrLoadPreviousNegotiations() (map[id.ID]struct{}, error) { obj, err := s.kv.Get(negotiationPartnersKey, negotiationPartnersVersion) if err != nil { + if strings.Contains(err.Error(), "object not found") || + strings.Contains(err.Error(), "no such file or directory") { + return make(map[id.ID]struct{}), nil + } return nil, err } diff --git a/storage/auth/previousNegotiations_test.go b/storage/auth/previousNegotiations_test.go index 94351aac983f8b58439177a927c05bc9df6ee616..8d096fc21d054110d0fd048151a8873d90291b4d 100644 --- a/storage/auth/previousNegotiations_test.go +++ b/storage/auth/previousNegotiations_test.go @@ -229,9 +229,9 @@ func TestStore_deletePreviousNegotiationPartner(t *testing.T) { } // Check previousNegotiations in storage - previousNegotiations, err := s.loadPreviousNegotiations() + previousNegotiations, err := s.newOrLoadPreviousNegotiations() if err != nil { - t.Errorf("loadPreviousNegotiations returned an error (%d): %+v", + t.Errorf("newOrLoadPreviousNegotiations returned an error (%d): %+v", i, err) } _, exists = previousNegotiations[*v.partner] @@ -260,8 +260,8 @@ func TestStore_deletePreviousNegotiationPartner(t *testing.T) { } // Tests that Store.previousNegotiations can be saved and loaded from storage -// via Store.savePreviousNegotiations andStore.loadPreviousNegotiations. -func TestStore_savePreviousNegotiations_loadPreviousNegotiations(t *testing.T) { +// via Store.savePreviousNegotiations andStore.newOrLoadPreviousNegotiations. +func TestStore_savePreviousNegotiations_newOrLoadPreviousNegotiations(t *testing.T) { s := &Store{ kv: versioned.NewKV(make(ekv.Memstore)), previousNegotiations: make(map[id.ID]struct{}), @@ -280,9 +280,9 @@ func TestStore_savePreviousNegotiations_loadPreviousNegotiations(t *testing.T) { i, err) } - s.previousNegotiations, err = s.loadPreviousNegotiations() + s.previousNegotiations, err = s.newOrLoadPreviousNegotiations() if err != nil { - t.Errorf("loadPreviousNegotiations returned an error (%d): %+v", + t.Errorf("newOrLoadPreviousNegotiations returned an error (%d): %+v", i, err) } @@ -293,6 +293,26 @@ func TestStore_savePreviousNegotiations_loadPreviousNegotiations(t *testing.T) { } } +// Tests that Store.newOrLoadPreviousNegotiations returns blank negotiations if +// they do not exist. +func TestStore_newOrLoadPreviousNegotiations_noNegotiations(t *testing.T) { + s := &Store{ + kv: versioned.NewKV(make(ekv.Memstore)), + previousNegotiations: make(map[id.ID]struct{}), + } + expected := make(map[id.ID]struct{}) + + blankNegotations, err := s.newOrLoadPreviousNegotiations() + if err != nil { + t.Errorf("newOrLoadPreviousNegotiations returned an error: %+v", err) + } + + if !reflect.DeepEqual(expected, blankNegotations) { + t.Errorf("Loaded previousNegotiations does not match expected."+ + "\nexpected: %v\nreceived: %v", expected, blankNegotations) + } +} + // Tests that a list of partner IDs that is marshalled and unmarshalled via // marshalPreviousNegotiations and unmarshalPreviousNegotiations matches the // original list diff --git a/storage/auth/store.go b/storage/auth/store.go index 83a306d9bbb50f43cf15b4091c8b275feff414d1..069b828dbd663aa7e2fb658612041d70d5888b81 100644 --- a/storage/auth/store.go +++ b/storage/auth/store.go @@ -155,7 +155,7 @@ func LoadStore(kv *versioned.KV, grp *cyclic.Group, privKeys []*cyclic.Int) (*St } // Load previous negotiations from storage - s.previousNegotiations, err = s.loadPreviousNegotiations() + s.previousNegotiations, err = s.newOrLoadPreviousNegotiations() if err != nil { return nil, errors.Errorf("failed to load list of previouse "+ "negotation partner IDs: %+v", err) diff --git a/storage/session.go b/storage/session.go index 1fc0aec0e43ffa46d95ce07db69936e381a4e0db..2ad3042ed7c76758227a42f751f146ae15cc58b4 100644 --- a/storage/session.go +++ b/storage/session.go @@ -282,7 +282,7 @@ func Load(baseDir, password string, currentVersion version.Version, "Failed to load bucket store") } - s.ud, err = ud.LoadStore(s.kv) + s.ud, err = ud.NewOrLoadStore(s.kv) if err != nil { return nil, errors.WithMessage(err, "Failed to load ud store") } diff --git a/storage/ud/store.go b/storage/ud/store.go index 33f62113e8218b378df3e6afd2f72ea972a2a6e0..64325e317bef67ef2d192ab64e70ba32da2d5365 100644 --- a/storage/ud/store.go +++ b/storage/ud/store.go @@ -8,6 +8,7 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/primitives/netTime" + "strings" ) // Storage constants @@ -101,17 +102,23 @@ func (s *Store) saveUnconfirmedFacts() error { // LOAD FUNCTIONS ///////////////////////////////////////////////////////////////// -// LoadStore loads the Store object from the provided versioned.KV. -func LoadStore(kv *versioned.KV) (*Store, error) { - kv = kv.Prefix(prefix) +// NewOrLoadStore loads the Store object from the provided versioned.KV. +func NewOrLoadStore(kv *versioned.KV) (*Store, error) { s := &Store{ confirmedFacts: make(map[fact.Fact]struct{}, 0), unconfirmedFacts: make(map[string]fact.Fact, 0), - kv: kv, + kv: kv.Prefix(prefix), } - return s, s.load() + if err := s.load(); err != nil { + if strings.Contains(err.Error(), "object not found") || + strings.Contains(err.Error(), "no such file or directory") { + return s, s.save() + } + } + + return s, nil } @@ -143,6 +150,9 @@ func (s *Store) loadConfirmedFacts() error { // Place the map in memory s.confirmedFacts, err = s.unmarshalConfirmedFacts(obj.Data) + if err != nil { + return err + } return nil } @@ -158,6 +168,9 @@ func (s *Store) loadUnconfirmedFacts() error { // Place the map in memory s.unconfirmedFacts, err = s.unmarshalUnconfirmedFacts(obj.Data) + if err != nil { + return err + } return nil } diff --git a/storage/ud/store_test.go b/storage/ud/store_test.go index 135348eed9bfa97db73931db19d81fc1a69b3cff..977aba8ef641029199bf186d4e9a1af2fc692131 100644 --- a/storage/ud/store_test.go +++ b/storage/ud/store_test.go @@ -4,11 +4,13 @@ import ( "bytes" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" + "gitlab.com/elixxir/primitives/fact" "reflect" "testing" ) -func TestLoadStore(t *testing.T) { +// Test it loads a Store from storage if it exists. +func TestNewOrLoadStore_LoadStore(t *testing.T) { kv := versioned.NewKV(make(ekv.Memstore)) expectedStore, err := NewStore(kv) @@ -16,13 +18,37 @@ func TestLoadStore(t *testing.T) { t.Errorf("NewStore() produced an error: %v", err) } - receivedStore, err := LoadStore(kv) + receivedStore, err := NewOrLoadStore(kv) if err != nil { - t.Fatalf("LoadStore() produced an error: %v", err) + t.Fatalf("NewOrLoadStore() produced an error: %v", err) } if !reflect.DeepEqual(expectedStore, receivedStore) { - t.Errorf("LoadStore() returned incorrect Store."+ + t.Errorf("NewOrLoadStore() returned incorrect Store."+ + "\nexpected: %#v\nreceived: %#v", expectedStore, + receivedStore) + + } + +} + +// Test that it creates a new store if an old one is not in storage. +func TestNewOrLoadStore_NewStore(t *testing.T) { + kv := versioned.NewKV(make(ekv.Memstore)) + + receivedStore, err := NewOrLoadStore(kv) + if err != nil { + t.Fatalf("NewOrLoadStore() produced an error: %v", err) + } + + expectedStore := &Store{ + confirmedFacts: make(map[fact.Fact]struct{}, 0), + unconfirmedFacts: make(map[string]fact.Fact, 0), + kv: kv.Prefix(prefix), + } + + if !reflect.DeepEqual(expectedStore, receivedStore) { + t.Errorf("NewOrLoadStore() returned incorrect Store."+ "\nexpected: %#v\nreceived: %#v", expectedStore, receivedStore)