diff --git a/auth/state.go b/auth/state.go index 2b9daff5abf5feb64638f7cc1883df2d8a1f8416..a0f106952ac2d777717e6211f5a0401fa8aca53b 100644 --- a/auth/state.go +++ b/auth/state.go @@ -64,7 +64,7 @@ type state struct { // are treated as ephemeral. To do so in auth, pass in an ephemeral e2e (made // with a memory only versioned.KV) as well as a memory only versioned.KV for // NewState and use GetDefaultTemporaryParams() for the parameters -func NewState(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, +func NewState(kv versioned.KV, net cmix.Client, e2e e2e.Handler, rng *fastRNG.StreamGenerator, event event.Reporter, authParams Params, sessParams session.Params, callbacks Callbacks, backupTrigger func(reason string)) (State, error) { @@ -80,7 +80,7 @@ func NewState(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, // be found. Bases its reception identity and keys off of what is found in e2e. // Does not modify the kv prefix for backwards compatibility. // Otherwise, acts the same as NewState -func NewStateLegacy(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, +func NewStateLegacy(kv versioned.KV, net cmix.Client, e2e e2e.Handler, rng *fastRNG.StreamGenerator, event event.Reporter, authParams Params, sessParams session.Params, callbacks Callbacks, backupTrigger func(reason string)) (State, error) { diff --git a/auth/state_test.go b/auth/state_test.go index a67179b5c242bb54c49787a8fbb4a3ad18b71efd..080cd682e9452e8b2777122db3044804acf89b8c 100644 --- a/auth/state_test.go +++ b/auth/state_test.go @@ -194,7 +194,7 @@ loop: } } -func makeTestStore(t *testing.T) (*store.Store, *versioned.KV, []*cyclic.Int) { +func makeTestStore(t *testing.T) (*store.Store, versioned.KV, []*cyclic.Int) { kv := versioned.NewKV(ekv.MakeMemstore()) grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(0)) privKeys := make([]*cyclic.Int, 10) diff --git a/auth/store/previousNegotiations.go b/auth/store/previousNegotiations.go index a0d3bc2fff082c5d405436d64c12dac422197162..5941d4d545fff7528a564214fbe58de115f7b351 100644 --- a/auth/store/previousNegotiations.go +++ b/auth/store/previousNegotiations.go @@ -180,7 +180,7 @@ func unmarshalPreviousNegotiations(b []byte) (map[id.ID]bool, // saveNegotiationFingerprints saves the list of sentByFingerprints for the given // partner to storage. func saveNegotiationFingerprints( - partner *id.ID, kv *versioned.KV, fingerprints ...[]byte) error { + partner *id.ID, kv versioned.KV, fingerprints ...[]byte) error { obj := &versioned.Object{ Version: currentNegotiationFingerprintsVersion, @@ -193,7 +193,7 @@ func saveNegotiationFingerprints( // loadNegotiationFingerprints loads the list of sentByFingerprints for the given // partner from storage. -func loadNegotiationFingerprints(partner *id.ID, kv *versioned.KV) ([][]byte, error) { +func loadNegotiationFingerprints(partner *id.ID, kv versioned.KV) ([][]byte, error) { fpKey := makeNegotiationFingerprintsKey(partner) obj, err := kv.Get(fpKey, currentNegotiationFingerprintsVersion) if err != nil { @@ -269,7 +269,7 @@ func unmarshalPreviousNegotiationsV0(buf []byte) map[id.ID]struct{} { // upgradePreviousNegotiationsV0 upgrades the negotiations Partners key from V0 // to V1 -func upgradePreviousNegotiationsV0(kv *versioned.KV) error { +func upgradePreviousNegotiationsV0(kv versioned.KV) error { obj, err := kv.Get(negotiationPartnersKey, 0) if !kv.Exists(err) { return nil diff --git a/auth/store/receivedRequest.go b/auth/store/receivedRequest.go index bc3bf8d7433f499dfbfb37a2cf38f3d3423d6d27..3bd07fdb3fdcc58571877812678f652dd9b782d4 100644 --- a/auth/store/receivedRequest.go +++ b/auth/store/receivedRequest.go @@ -21,7 +21,7 @@ import ( ) type ReceivedRequest struct { - kv *versioned.KV + kv versioned.KV // contact of partner partner contact.Contact @@ -36,7 +36,7 @@ type ReceivedRequest struct { mux sync.Mutex } -func newReceivedRequest(kv *versioned.KV, c contact.Contact, +func newReceivedRequest(kv versioned.KV, c contact.Contact, key *sidh.PublicKey, round rounds.Round) *ReceivedRequest { if err := util.StoreContact(kv, c); err != nil { @@ -63,7 +63,7 @@ func newReceivedRequest(kv *versioned.KV, c contact.Contact, } } -func loadReceivedRequest(kv *versioned.KV, partner *id.ID) ( +func loadReceivedRequest(kv versioned.KV, partner *id.ID) ( *ReceivedRequest, error) { c, err := util.LoadContact(kv, partner) diff --git a/auth/store/sentRequest.go b/auth/store/sentRequest.go index b8e95e44f7a0817caf1a3a693392238a46fbe648..18d9841dc70d78de081dc8433a8c5f545c20a64a 100644 --- a/auth/store/sentRequest.go +++ b/auth/store/sentRequest.go @@ -27,7 +27,7 @@ import ( const currentSentRequestVersion = 1 type SentRequest struct { - kv *versioned.KV + kv versioned.KV partner *id.ID partnerHistoricalPubKey *cyclic.Int @@ -51,7 +51,7 @@ type sentRequestDisk struct { Reset bool } -func newSentRequest(kv *versioned.KV, partner *id.ID, partnerHistoricalPubKey, +func newSentRequest(kv versioned.KV, partner *id.ID, partnerHistoricalPubKey, myPrivKey, myPubKey *cyclic.Int, sidHPrivA *sidh.PrivateKey, sidHPubA *sidh.PublicKey, fp format.Fingerprint, reset bool) (*SentRequest, error) { @@ -70,7 +70,7 @@ func newSentRequest(kv *versioned.KV, partner *id.ID, partnerHistoricalPubKey, return sr, sr.save() } -func loadSentRequest(kv *versioned.KV, partner *id.ID, grp *cyclic.Group) (*SentRequest, error) { +func loadSentRequest(kv versioned.KV, partner *id.ID, grp *cyclic.Group) (*SentRequest, error) { srKey := makeSentRequestKey(partner) obj, err := kv.Get(srKey, currentSentRequestVersion) @@ -283,7 +283,7 @@ func makeSentRequestKeyV0(partner *id.ID) string { // upgradeSentRequestKeyV0 upgrads the srKey from version 0 to 1 by // changing the version number. -func upgradeSentRequestKeyV0(kv *versioned.KV, partner *id.ID) error { +func upgradeSentRequestKeyV0(kv versioned.KV, partner *id.ID) error { oldKey := makeSentRequestKeyV0(partner) obj, err := kv.Get(oldKey, 0) if err != nil { diff --git a/auth/store/store.go b/auth/store/store.go index 1109987ef74a1fa841cec7261dc4099b0cffceb6..cca5b47abbc85b324658f27d60a312150440d93c 100644 --- a/auth/store/store.go +++ b/auth/store/store.go @@ -29,7 +29,7 @@ const requestMapKey = "map" const requestMapVersion = 0 type Store struct { - kv *versioned.KV + kv versioned.KV grp *cyclic.Group receivedByID map[id.ID]*ReceivedRequest sentByID map[id.ID]*SentRequest @@ -44,7 +44,7 @@ type Store struct { // NewOrLoadStore loads an extant new store. All passed in private keys are added as // sentByFingerprints so they can be used to trigger receivedByID. // If no store can be found, it creates a new one -func NewOrLoadStore(kv *versioned.KV, grp *cyclic.Group, srh SentRequestHandler) (*Store, error) { +func NewOrLoadStore(kv versioned.KV, grp *cyclic.Group, srh SentRequestHandler) (*Store, error) { kv, err := kv.Prefix(storePrefix) if err != nil { return nil, err @@ -155,7 +155,7 @@ func (s *Store) save() error { // NewStore creates a new store. All passed in private keys are added as // sentByFingerprints so they can be used to trigger receivedByID. -func newStore(kv *versioned.KV, grp *cyclic.Group, srh SentRequestHandler) ( +func newStore(kv versioned.KV, grp *cyclic.Group, srh SentRequestHandler) ( *Store, error) { s := &Store{ kv: kv, diff --git a/auth/store/store_test.go b/auth/store/store_test.go index 5c09170ce03aa335418a53f55c77fcc22d913e25..b4538ee8785dd81035164d26015e5578039659b3 100644 --- a/auth/store/store_test.go +++ b/auth/store/store_test.go @@ -868,7 +868,7 @@ func TestStore_DeleteAllRequests(t *testing.T) { } -func makeTestStore(t *testing.T) (*Store, *versioned.KV) { +func makeTestStore(t *testing.T) (*Store, versioned.KV) { kv := versioned.NewKV(ekv.MakeMemstore()) grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(0)) diff --git a/backup/backup.go b/backup/backup.go index 2d8b55e8a3ba388892aad7bcd8b274182c6fddce..51e9a96c2ba9102194985f43e23bcbe28564b3e4 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -49,7 +49,7 @@ type Backup struct { e2e E2e session Session ud UserDiscovery - kv *versioned.KV + kv versioned.KV rng *fastRNG.StreamGenerator mux sync.RWMutex @@ -92,7 +92,7 @@ type UpdateBackupFn func(encryptedBackup []byte) // password. func InitializeBackup(backupPassphrase string, updateBackupCb UpdateBackupFn, container *xxdk.Container, e2e E2e, session Session, ud UserDiscovery, - kv *versioned.KV, rng *fastRNG.StreamGenerator) (*Backup, error) { + kv versioned.KV, rng *fastRNG.StreamGenerator) (*Backup, error) { b := &Backup{ updateBackupCb: updateBackupCb, @@ -137,7 +137,7 @@ func InitializeBackup(backupPassphrase string, updateBackupCb UpdateBackupFn, // a new callback. Call this to resume backups that have already been // initialized. Returns an error if backups have not already been initialized. func ResumeBackup(updateBackupCb UpdateBackupFn, container *xxdk.Container, - e2e E2e, session Session, ud UserDiscovery, kv *versioned.KV, + e2e E2e, session Session, ud UserDiscovery, kv versioned.KV, rng *fastRNG.StreamGenerator) (*Backup, error) { _, _, _, err := loadBackup(kv) if err != nil { diff --git a/backup/jsonStorage.go b/backup/jsonStorage.go index ac887bce8fc46dbbec86492ee15c8d76d9fdd972..3403ecb46a3d36a9f2d7a523bfaf173d8121c9a0 100644 --- a/backup/jsonStorage.go +++ b/backup/jsonStorage.go @@ -17,7 +17,7 @@ const ( jsonStorageKey = "JsonStorage" ) -func storeJson(json string, kv *versioned.KV) error { +func storeJson(json string, kv versioned.KV) error { obj := &versioned.Object{ Version: jsonStorageVersion, Timestamp: netTime.Now(), @@ -27,7 +27,7 @@ func storeJson(json string, kv *versioned.KV) error { return kv.Set(jsonStorageKey, obj) } -func loadJson(kv *versioned.KV) string { +func loadJson(kv versioned.KV) string { obj, err := kv.Get(jsonStorageKey, jsonStorageVersion) if err != nil { return "" diff --git a/backup/keyStorage.go b/backup/keyStorage.go index d6b5afd8c01f7be0a56fa0d629ec2e791ff8ecf7..8d96e5b85538902def0b4d6625c1907494727894 100644 --- a/backup/keyStorage.go +++ b/backup/keyStorage.go @@ -30,7 +30,7 @@ const ( ) // saveBackup saves the key, salt, and params to storage. -func saveBackup(key, salt []byte, params backup.Params, kv *versioned.KV) error { +func saveBackup(key, salt []byte, params backup.Params, kv versioned.KV) error { obj := &versioned.Object{ Version: cryptoStorageVersion, @@ -42,7 +42,7 @@ func saveBackup(key, salt []byte, params backup.Params, kv *versioned.KV) error } // loadBackup loads the key, salt, and params from storage. -func loadBackup(kv *versioned.KV) (key, salt []byte, params backup.Params, err error) { +func loadBackup(kv versioned.KV) (key, salt []byte, params backup.Params, err error) { obj, err := kv.Get(cryptoStorageKey, cryptoStorageVersion) if err != nil { return @@ -52,7 +52,7 @@ func loadBackup(kv *versioned.KV) (key, salt []byte, params backup.Params, err e } // deleteBackup deletes the key, salt, and params from storage. -func deleteBackup(kv *versioned.KV) error { +func deleteBackup(kv versioned.KV) error { return kv.Delete(cryptoStorageKey, cryptoStorageVersion) } diff --git a/channels/commandStore.go b/channels/commandStore.go index 13d7da3acde4ad6382c13c06dbd0575748bbffdf..05e7b4d2ff31cbd913d82256b2982f2328e50692 100644 --- a/channels/commandStore.go +++ b/channels/commandStore.go @@ -30,12 +30,12 @@ const ( // CommandStore stores message information about channel commands in storage. // Each message type CommandStore struct { - kv *versioned.KV + kv versioned.KV } // NewCommandStore initialises a new message CommandStore object with a prefixed // KV. -func NewCommandStore(kv *versioned.KV) *CommandStore { +func NewCommandStore(kv versioned.KV) *CommandStore { kv, err := kv.Prefix(commandStorePrefix) if err != nil { jww.FATAL.Panicf("[CH] Failed to add prefix %s to KV: %+v", commandStorePrefix, err) diff --git a/channels/eventModel.go b/channels/eventModel.go index 04e927bc29896b92957c9bdda35f23264226be39..9beb46c53f5ebee0b6db1a848f171cb37fda6cb0 100644 --- a/channels/eventModel.go +++ b/channels/eventModel.go @@ -335,7 +335,7 @@ func (rmh *ReceiveMessageHandler) CheckSpace(user, admin, muted bool) error { // initEvents initializes the event model and registers default message type // handlers. -func initEvents(model EventModel, maxMessageLength int, kv *versioned.KV, +func initEvents(model EventModel, maxMessageLength int, kv versioned.KV, rng *fastRNG.StreamGenerator) *events { e := &events{ model: model, diff --git a/channels/identityStore.go b/channels/identityStore.go index 2a98eb93903ce85eb79683f570fc3f742a38c50d..5a5decb68102fe319a53e19c2730ba8e4fae7810 100644 --- a/channels/identityStore.go +++ b/channels/identityStore.go @@ -11,7 +11,7 @@ const ( identityStoreStorageVersion = 0 ) -func storeIdentity(kv *versioned.KV, ident cryptoChannel.PrivateIdentity) error { +func storeIdentity(kv versioned.KV, ident cryptoChannel.PrivateIdentity) error { data := ident.Marshal() obj := &versioned.Object{ Version: identityStoreStorageVersion, @@ -22,7 +22,7 @@ func storeIdentity(kv *versioned.KV, ident cryptoChannel.PrivateIdentity) error return kv.Set(identityStoreStorageKey, obj) } -func loadIdentity(kv *versioned.KV) (cryptoChannel.PrivateIdentity, error) { +func loadIdentity(kv versioned.KV) (cryptoChannel.PrivateIdentity, error) { obj, err := kv.Get(identityStoreStorageKey, identityStoreStorageVersion) if err != nil { return cryptoChannel.PrivateIdentity{}, err diff --git a/channels/joinedChannel.go b/channels/joinedChannel.go index e9f4952551ae37c4f1f8e9ec7373be5bc6beda82..09733d70c5d1857cfcf481775ec11f98de0b3625 100644 --- a/channels/joinedChannel.go +++ b/channels/joinedChannel.go @@ -188,7 +188,7 @@ type joinedChannelDisk struct { } // Store writes the given channel to a unique storage location within the EKV. -func (jc *joinedChannel) Store(kv *versioned.KV) error { +func (jc *joinedChannel) Store(kv versioned.KV) error { jcd := joinedChannelDisk{jc.broadcast.Get()} data, err := json.Marshal(&jcd) if err != nil { @@ -227,7 +227,7 @@ func (m *manager) loadJoinedChannel(channelID *id.ID) (*joinedChannel, error) { } // delete removes the channel from the kv. -func (jc *joinedChannel) delete(kv *versioned.KV) error { +func (jc *joinedChannel) delete(kv versioned.KV) error { return kv.Delete(makeJoinedChannelKey(jc.broadcast.Get().ReceptionID), joinedChannelVersion) } diff --git a/channels/lease.go b/channels/lease.go index 36c9ecf0ecf7fba067d87566eb600099e5af911b..c10f162c6c50d22895031880f8c90e46577efc70 100644 --- a/channels/lease.go +++ b/channels/lease.go @@ -99,7 +99,7 @@ type ActionLeaseList struct { rb *replayBlocker store *CommandStore - kv *versioned.KV + kv versioned.KV rng *fastRNG.StreamGenerator } @@ -152,7 +152,7 @@ type leaseMessage struct { // NewOrLoadActionLeaseList loads an existing ActionLeaseList from storage, if // it exists. Otherwise, it initialises a new empty ActionLeaseList. func NewOrLoadActionLeaseList(triggerFn triggerActionEventFunc, - store *CommandStore, kv *versioned.KV, rng *fastRNG.StreamGenerator) ( + store *CommandStore, kv versioned.KV, rng *fastRNG.StreamGenerator) ( *ActionLeaseList, error) { all := NewActionLeaseList(triggerFn, store, kv, rng) @@ -171,7 +171,7 @@ func NewOrLoadActionLeaseList(triggerFn triggerActionEventFunc, // NewActionLeaseList initialises a new empty ActionLeaseList. func NewActionLeaseList(triggerFn triggerActionEventFunc, store *CommandStore, - kv *versioned.KV, rng *fastRNG.StreamGenerator) *ActionLeaseList { + kv versioned.KV, rng *fastRNG.StreamGenerator) *ActionLeaseList { all := &ActionLeaseList{ leases: list.New(), messagesByChannel: make(map[id.ID]map[commandFingerprintKey]*leaseMessage), diff --git a/channels/manager.go b/channels/manager.go index e6a8aeefd8de73b1b2e395a5694779a8e0bd9a45..4d370d79742f1f82701eefa51033a057d419d063 100644 --- a/channels/manager.go +++ b/channels/manager.go @@ -46,7 +46,7 @@ type manager struct { mux sync.RWMutex // External references - kv *versioned.KV + kv versioned.KV net Client rng *fastRNG.StreamGenerator @@ -96,7 +96,7 @@ type EventModelBuilder func(path string) (EventModel, error) type AddServiceFn func(sp xxdk.Service) error // NewManagerBuilder creates a new channel Manager using an EventModelBuilder. -func NewManagerBuilder(identity cryptoChannel.PrivateIdentity, kv *versioned.KV, +func NewManagerBuilder(identity cryptoChannel.PrivateIdentity, kv versioned.KV, net Client, rng *fastRNG.StreamGenerator, modelBuilder EventModelBuilder, addService AddServiceFn) (Manager, error) { model, err := modelBuilder(getStorageTag(identity.PubKey)) @@ -110,7 +110,7 @@ func NewManagerBuilder(identity cryptoChannel.PrivateIdentity, kv *versioned.KV, // NewManager creates a new channel Manager from a [cryptoChannel.PrivateIdentity]. It // prefixes the KV with a tag derived from the public key that can be retried // for reloading using [Manager.GetStorageTag]. -func NewManager(identity cryptoChannel.PrivateIdentity, kv *versioned.KV, +func NewManager(identity cryptoChannel.PrivateIdentity, kv versioned.KV, net Client, rng *fastRNG.StreamGenerator, model EventModel, addService AddServiceFn) (Manager, error) { @@ -141,7 +141,7 @@ func NewManager(identity cryptoChannel.PrivateIdentity, kv *versioned.KV, // LoadManager restores a channel Manager from disk stored at the given storage // tag. -func LoadManager(storageTag string, kv *versioned.KV, net Client, +func LoadManager(storageTag string, kv versioned.KV, net Client, rng *fastRNG.StreamGenerator, model EventModel) ( Manager, error) { jww.INFO.Printf("[CH] LoadManager for tag %s", storageTag) @@ -166,7 +166,7 @@ func LoadManager(storageTag string, kv *versioned.KV, net Client, // LoadManagerBuilder restores a channel Manager from disk stored at the given storage // tag. -func LoadManagerBuilder(storageTag string, kv *versioned.KV, net Client, +func LoadManagerBuilder(storageTag string, kv versioned.KV, net Client, rng *fastRNG.StreamGenerator, modelBuilder EventModelBuilder) (Manager, error) { model, err := modelBuilder(storageTag) if err != nil { @@ -176,7 +176,7 @@ func LoadManagerBuilder(storageTag string, kv *versioned.KV, net Client, return LoadManager(storageTag, kv, net, rng, model) } -func setupManager(identity cryptoChannel.PrivateIdentity, kv *versioned.KV, +func setupManager(identity cryptoChannel.PrivateIdentity, kv versioned.KV, net Client, rng *fastRNG.StreamGenerator, model EventModel) *manager { m := manager{ me: identity, diff --git a/channels/mutedUsers.go b/channels/mutedUsers.go index 70e59a262bf259336623485764100960d6d571e1..1572489034cc7cecbe49dbf85895cad4612f1997 100644 --- a/channels/mutedUsers.go +++ b/channels/mutedUsers.go @@ -43,12 +43,12 @@ type mutedUserManager struct { list map[id.ID]map[mutedUserKey]struct{} mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // newOrLoadMutedUserManager loads an existing mutedUserManager from storage, if // it exists. Otherwise, it initialises a new empty mutedUserManager. -func newOrLoadMutedUserManager(kv *versioned.KV) (*mutedUserManager, error) { +func newOrLoadMutedUserManager(kv versioned.KV) (*mutedUserManager, error) { mum := newMutedUserManager(kv) err := mum.load() @@ -60,7 +60,7 @@ func newOrLoadMutedUserManager(kv *versioned.KV) (*mutedUserManager, error) { } // newMutedUserManager initializes a new and empty mutedUserManager. -func newMutedUserManager(kv *versioned.KV) *mutedUserManager { +func newMutedUserManager(kv versioned.KV) *mutedUserManager { return &mutedUserManager{ list: make(map[id.ID]map[mutedUserKey]struct{}), kv: kv, diff --git a/channels/nickname.go b/channels/nickname.go index 9595a91f2acc1a4bbf202eafa0dac49ddce0e220..a0460e99a7e8d510c7b9b0682fdc4146bbd81826 100644 --- a/channels/nickname.go +++ b/channels/nickname.go @@ -19,12 +19,12 @@ const ( type nicknameManager struct { byChannel map[id.ID]string mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // LoadOrNewNicknameManager returns the stored nickname manager if there is one // or returns a new one. -func LoadOrNewNicknameManager(kv *versioned.KV) *nicknameManager { +func LoadOrNewNicknameManager(kv versioned.KV) *nicknameManager { nm := &nicknameManager{ byChannel: make(map[id.ID]string), kv: kv, diff --git a/channels/privateKey.go b/channels/privateKey.go index 7c74aa9803b36c3d8f675894b6e0663e33190594..1bad5683a5d0f45def0ebb8b37120a2cd8886dcb 100644 --- a/channels/privateKey.go +++ b/channels/privateKey.go @@ -150,7 +150,7 @@ const ( // // The private key can retrieved from storage via loadChannelPrivateKey. func saveChannelPrivateKey( - channelID *id.ID, pk rsa.PrivateKey, kv *versioned.KV) error { + channelID *id.ID, pk rsa.PrivateKey, kv versioned.KV) error { return kv.Set(makeChannelPrivateKeyStoreKey(channelID), &versioned.Object{ Version: channelPrivateKeyStoreVersion, @@ -165,7 +165,7 @@ func saveChannelPrivateKey( // // The private key is saved to storage via saveChannelPrivateKey. func loadChannelPrivateKey( - channelID *id.ID, kv *versioned.KV) (rsa.PrivateKey, error) { + channelID *id.ID, kv versioned.KV) (rsa.PrivateKey, error) { obj, err := kv.Get( makeChannelPrivateKeyStoreKey(channelID), channelPrivateKeyStoreVersion) if err != nil { @@ -177,7 +177,7 @@ func loadChannelPrivateKey( // deleteChannelPrivateKey deletes the private key from storage for the given // channel ID. -func deleteChannelPrivateKey(channelID *id.ID, kv *versioned.KV) error { +func deleteChannelPrivateKey(channelID *id.ID, kv versioned.KV) error { return kv.Delete( makeChannelPrivateKeyStoreKey(channelID), channelPrivateKeyStoreVersion) } diff --git a/channels/replayBlocker.go b/channels/replayBlocker.go index 5fce82ca8d367d736533b5bc889c5cb7a988f3a0..b44bd4f97f0fb33a31551806970d65617daab0d7 100644 --- a/channels/replayBlocker.go +++ b/channels/replayBlocker.go @@ -40,7 +40,7 @@ type replayBlocker struct { replay triggerLeaseReplay store *CommandStore - kv *versioned.KV + kv versioned.KV mux sync.Mutex } @@ -75,7 +75,7 @@ type commandMessage struct { // newOrLoadReplayBlocker loads an existing replayBlocker from storage, if it // exists. Otherwise, it initialises a new empty replayBlocker. func newOrLoadReplayBlocker(replay triggerLeaseReplay, store *CommandStore, - kv *versioned.KV) (*replayBlocker, error) { + kv versioned.KV) (*replayBlocker, error) { rb := newReplayBlocker(replay, store, kv) err := rb.load() @@ -88,7 +88,7 @@ func newOrLoadReplayBlocker(replay triggerLeaseReplay, store *CommandStore, // newReplayBlocker initialises a new empty replayBlocker. func newReplayBlocker(replay triggerLeaseReplay, store *CommandStore, - kv *versioned.KV) *replayBlocker { + kv versioned.KV) *replayBlocker { kv, err := kv.Prefix(replayBlockerStoragePrefix) if err != nil { jww.FATAL.Panicf("[CH] Failed to add prefix %s to KV: %+v", replayBlockerStoragePrefix, err) diff --git a/channels/sendTracker.go b/channels/sendTracker.go index 7a8a502f2c45dc6e71823379bdbf626b8be50ac3..052a237239f28e6e80d96c6304085ab6ccd701a5 100644 --- a/channels/sendTracker.go +++ b/channels/sendTracker.go @@ -68,7 +68,7 @@ type sendTracker struct { net Client rngSrc *fastRNG.StreamGenerator - kv *versioned.KV + kv versioned.KV mux sync.RWMutex } @@ -80,7 +80,7 @@ type messageReceiveFunc func( // loadSendTracker loads a sent tracker, restoring from disk. It will register a // function with the cmix client, delayed on when the network goes healthy, // which will attempt to discover the status of all rounds that are outstanding. -func loadSendTracker(net Client, kv *versioned.KV, trigger triggerEventFunc, +func loadSendTracker(net Client, kv versioned.KV, trigger triggerEventFunc, adminTrigger triggerAdminEventFunc, updateStatus UpdateFromUuidFunc, rngSource *fastRNG.StreamGenerator) *sendTracker { st := &sendTracker{ diff --git a/cmix/cmixMessageBuffer.go b/cmix/cmixMessageBuffer.go index a3590a69ff8062a553ea896221cb352a635fb257..cd9d54af2191bea0d40dc0881f0b2be34bcaf235 100644 --- a/cmix/cmixMessageBuffer.go +++ b/cmix/cmixMessageBuffer.go @@ -43,7 +43,7 @@ func (sm storedMessage) Marshal() []byte { // SaveMessage saves the message as a versioned object at the specified key // in the key value store. func (cmh *cmixMessageHandler) SaveMessage( - kv *versioned.KV, m interface{}, key string) error { + kv versioned.KV, m interface{}, key string) error { sm := m.(storedMessage) // Create versioned object @@ -60,7 +60,7 @@ func (cmh *cmixMessageHandler) SaveMessage( // LoadMessage returns the message with the specified key from the key value // store. An empty message and error are returned if the message could not be // retrieved. -func (cmh *cmixMessageHandler) LoadMessage(kv *versioned.KV, key string) ( +func (cmh *cmixMessageHandler) LoadMessage(kv versioned.KV, key string) ( interface{}, error) { // Load the versioned object @@ -80,7 +80,7 @@ func (cmh *cmixMessageHandler) LoadMessage(kv *versioned.KV, key string) ( // DeleteMessage deletes the message with the specified key from the key value // store. -func (cmh *cmixMessageHandler) DeleteMessage(kv *versioned.KV, key string) error { +func (cmh *cmixMessageHandler) DeleteMessage(kv versioned.KV, key string) error { return kv.Delete(key, currentCmixMessageVersion) } @@ -109,7 +109,7 @@ type CmixMessageBuffer struct { mb *utility.MessageBuffer } -func NewOrLoadCmixMessageBuffer(kv *versioned.KV, key string) ( +func NewOrLoadCmixMessageBuffer(kv versioned.KV, key string) ( *CmixMessageBuffer, error) { cmb, err := LoadCmixMessageBuffer(kv, key) @@ -125,7 +125,7 @@ func NewOrLoadCmixMessageBuffer(kv *versioned.KV, key string) ( return cmb, nil } -func LoadCmixMessageBuffer(kv *versioned.KV, key string) (*CmixMessageBuffer, error) { +func LoadCmixMessageBuffer(kv versioned.KV, key string) (*CmixMessageBuffer, error) { mb, err := utility.LoadMessageBuffer(kv, &cmixMessageHandler{}, key) if err != nil { return nil, err diff --git a/cmix/critical.go b/cmix/critical.go index c20a36fe4ba1d4464c9487c396dd81aa3efe8946..b40bf26a3e0f1a2ddb1308ed0ded885f93e6f299 100644 --- a/cmix/critical.go +++ b/cmix/critical.go @@ -48,7 +48,7 @@ type critical struct { send criticalSender } -func newCritical(kv *versioned.KV, hm health.Monitor, +func newCritical(kv versioned.KV, hm health.Monitor, roundEvents roundEventRegistrar, send criticalSender) *critical { cm, err := NewOrLoadCmixMessageBuffer(kv, criticalRawMessagesKey) if err != nil { diff --git a/cmix/gateway/certChecker.go b/cmix/gateway/certChecker.go index bd12350e57363d5a4866309ab90f255794378c95..6d23c0b410d42df6051f763af8fa4727b5925407 100644 --- a/cmix/gateway/certChecker.go +++ b/cmix/gateway/certChecker.go @@ -12,6 +12,8 @@ import ( "crypto" "crypto/sha256" "fmt" + "time" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" @@ -20,7 +22,6 @@ import ( "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/primitives/id" - "time" ) const ( @@ -37,12 +38,12 @@ type CertCheckerCommInterface interface { // certChecker stores verified certificates and handles verification checking type certChecker struct { - kv *versioned.KV + kv versioned.KV comms CertCheckerCommInterface } // newCertChecker initializes a certChecker object -func newCertChecker(comms CertCheckerCommInterface, kv *versioned.KV) *certChecker { +func newCertChecker(comms CertCheckerCommInterface, kv versioned.KV) *certChecker { checkerKv, err := kv.Prefix(certCheckerPrefix) if err != nil { jww.FATAL.Panicf("Failed to add prefix %s to KV: %+v", certCheckerPrefix, err) diff --git a/cmix/gateway/hostPool.go b/cmix/gateway/hostPool.go index 87b492c9068dd924e2e685b5a19a9bac4d1a1e37..71fa1860e1e63ba777864af371f9118fac2ab391 100644 --- a/cmix/gateway/hostPool.go +++ b/cmix/gateway/hostPool.go @@ -8,6 +8,12 @@ package gateway import ( + "math" + "strconv" + "sync" + "sync/atomic" + "testing" + "github.com/golang-collections/collections/set" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" @@ -19,11 +25,6 @@ import ( "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/ndf" - "math" - "strconv" - "sync" - "sync/atomic" - "testing" ) type hostPool struct { @@ -56,7 +57,7 @@ type hostPool struct { manager HostManager filterMux sync.Mutex filter Filter - kv *versioned.KV + kv versioned.KV addChan chan commNetwork.NodeGateway /* Computed parameters*/ @@ -309,7 +310,7 @@ func (hp *hostPool) getFilter() Filter { // getHostList returns the host list from storage. // it will trip the list if it is too long and // extend it if it is too short -func getHostPreparedList(kv *versioned.KV, poolSize int) ([]*id.ID, error) { +func getHostPreparedList(kv versioned.KV, poolSize int) ([]*id.ID, error) { obj, err := kv.Get(hostListKey, hostListVersion) if err != nil { return make([]*id.ID, poolSize), errors.Errorf(getStorageErr, err) diff --git a/cmix/gateway/storeHostList.go b/cmix/gateway/storeHostList.go index 3d0c69f2f4af4a768b3d13f62e88c5ff5c2c530c..65d0e25b8ada0f846ddb69174b436a8570a58b33 100644 --- a/cmix/gateway/storeHostList.go +++ b/cmix/gateway/storeHostList.go @@ -9,6 +9,7 @@ package gateway import ( "bytes" + "github.com/pkg/errors" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/id" @@ -29,7 +30,7 @@ const ( unmarshallLenErr = "malformed data: length of data %d incorrect" ) -func saveHostList(kv *versioned.KV, list []*id.ID) error { +func saveHostList(kv versioned.KV, list []*id.ID) error { obj := &versioned.Object{ Version: hostListVersion, Data: marshalHostList(list), @@ -40,7 +41,7 @@ func saveHostList(kv *versioned.KV, list []*id.ID) error { } // getHostList returns the host list from storage. -func getHostList(kv *versioned.KV) ([]*id.ID, error) { +func getHostList(kv versioned.KV) ([]*id.ID, error) { obj, err := kv.Get(hostListKey, hostListVersion) if err != nil { return nil, errors.Errorf(getStorageErr, err) diff --git a/cmix/identity/receptionID/identity.go b/cmix/identity/receptionID/identity.go index 586cbe9b945c3e30e549209365c3a32c9be8ae86..8af1cd318f910ca132b6a012bc9fd66f7da5e033 100644 --- a/cmix/identity/receptionID/identity.go +++ b/cmix/identity/receptionID/identity.go @@ -55,7 +55,7 @@ type Identity struct { ProcessNext *Identity } -func loadIdentity(kv *versioned.KV) (Identity, error) { +func loadIdentity(kv versioned.KV) (Identity, error) { obj, err := kv.Get(identityStorageKey, identityStorageVersion) if err != nil { return Identity{}, errors.WithMessage(err, "Failed to load Identity") @@ -70,7 +70,7 @@ func loadIdentity(kv *versioned.KV) (Identity, error) { return r, nil } -func (i Identity) store(kv *versioned.KV) error { +func (i Identity) store(kv versioned.KV) error { // Marshal the registration regStr, err := json.Marshal(&i) if err != nil { @@ -93,7 +93,7 @@ func (i Identity) store(kv *versioned.KV) error { return nil } -func (i Identity) delete(kv *versioned.KV) error { +func (i Identity) delete(kv versioned.KV) error { return kv.Delete(identityStorageKey, identityStorageVersion) } diff --git a/cmix/identity/receptionID/registration.go b/cmix/identity/receptionID/registration.go index 16c512e922fb546e015f4d49ff8eb3091e7847ac..312d5221006a4c2a30bbd13c3b7196c6f6a22fb6 100644 --- a/cmix/identity/receptionID/registration.go +++ b/cmix/identity/receptionID/registration.go @@ -14,6 +14,7 @@ import ( "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + // "gitlab.com/xx_network/primitives/netTime" "strconv" "time" @@ -24,10 +25,10 @@ type registration struct { UR *store.UnknownRounds ER *store.EarliestRound CR *store.CheckedRounds - kv *versioned.KV + kv versioned.KV } -func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) { +func newRegistration(reg Identity, kv versioned.KV) (*registration, error) { // Round the times to remove the monotonic clocks for future saving reg.StartValid = reg.StartValid.Round(0) reg.EndValid = reg.EndValid.Round(0) @@ -74,7 +75,7 @@ func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) { } func loadRegistration(EphId ephemeral.Id, Source *id.ID, startValid time.Time, - kv *versioned.KV) (*registration, error) { + kv versioned.KV) (*registration, error) { kv, err := kv.Prefix(regPrefix(EphId, Source, startValid)) if err != nil { diff --git a/cmix/identity/receptionID/store.go b/cmix/identity/receptionID/store.go index b61f0ccb1e49c3fa95af7efb14c221db20afb28e..eea99ab0f1617afe84ef733cde7cd03eabc2ca01 100644 --- a/cmix/identity/receptionID/store.go +++ b/cmix/identity/receptionID/store.go @@ -36,7 +36,7 @@ type Store struct { active []*registration present map[idHash]struct{} - kv *versioned.KV + kv versioned.KV mux sync.Mutex } @@ -59,7 +59,7 @@ func makeIdHash(ephID ephemeral.Id, source *id.ID) idHash { } // NewOrLoadStore creates a new reception store that starts empty. -func NewOrLoadStore(kv *versioned.KV) *Store { +func NewOrLoadStore(kv versioned.KV) *Store { s, err := loadStore(kv) if err != nil { @@ -87,7 +87,7 @@ func NewOrLoadStore(kv *versioned.KV) *Store { return s } -func loadStore(kv *versioned.KV) (*Store, error) { +func loadStore(kv versioned.KV) (*Store, error) { kv, err := kv.Prefix(receptionPrefix) if err != nil { return nil, err diff --git a/cmix/identity/receptionID/store/checkedRounds.go b/cmix/identity/receptionID/store/checkedRounds.go index adbe9ee43a059666a6bee54ee43e259fab0f3cb8..3e6629b371782768e8061b8d3c69bafa2022cd17 100644 --- a/cmix/identity/receptionID/store/checkedRounds.go +++ b/cmix/identity/receptionID/store/checkedRounds.go @@ -10,6 +10,7 @@ package store import ( "container/list" "encoding/binary" + "github.com/pkg/errors" "gitlab.com/elixxir/client/v4/storage/utility" "gitlab.com/elixxir/client/v4/storage/versioned" @@ -36,7 +37,7 @@ type CheckedRounds struct { } // NewCheckedRounds returns a new CheckedRounds with an initialized map. -func NewCheckedRounds(maxRounds int, kv *versioned.KV) (*CheckedRounds, error) { +func NewCheckedRounds(maxRounds int, kv versioned.KV) (*CheckedRounds, error) { // Calculate the number of blocks of size itemsPerBlock are needed to store // numRoundsToKeep number of round IDs numBlocks := maxRounds / itemsPerBlock @@ -67,7 +68,7 @@ func newCheckedRounds(maxRounds int, store *utility.BlockStore) *CheckedRounds { } // LoadCheckedRounds restores the list from storage. -func LoadCheckedRounds(maxRounds int, kv *versioned.KV) (*CheckedRounds, error) { +func LoadCheckedRounds(maxRounds int, kv versioned.KV) (*CheckedRounds, error) { // get rounds from storage store, rounds, err := utility.LoadBlockStore(kv) if err != nil { diff --git a/cmix/identity/receptionID/store/earliestRound.go b/cmix/identity/receptionID/store/earliestRound.go index dd57f681a3a37382afd2a18ca6bf259d2950e118..5ad3bbee960176091382ed9c18eccf2d8195a17d 100644 --- a/cmix/identity/receptionID/store/earliestRound.go +++ b/cmix/identity/receptionID/store/earliestRound.go @@ -3,17 +3,18 @@ // // // Use of this source code is governed by a license that can be found in the // // LICENSE file. // -//////////////////////////////////////////////////////////////////////////////// +///////////////////////A///////////////////////////////////////////////////////// package store import ( "encoding/json" + "sync" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "sync" ) const ( @@ -23,12 +24,12 @@ const ( type EarliestRound struct { stored bool - kv *versioned.KV + kv versioned.KV rid id.Round mux sync.Mutex } -func NewEarliestRound(stored bool, kv *versioned.KV) *EarliestRound { +func NewEarliestRound(stored bool, kv versioned.KV) *EarliestRound { ur := &EarliestRound{ stored: stored, kv: kv, @@ -39,7 +40,7 @@ func NewEarliestRound(stored bool, kv *versioned.KV) *EarliestRound { return ur } -func LoadEarliestRound(kv *versioned.KV) *EarliestRound { +func LoadEarliestRound(kv versioned.KV) *EarliestRound { ur := &EarliestRound{ stored: true, kv: kv, diff --git a/cmix/identity/receptionID/store/unknownRounds.go b/cmix/identity/receptionID/store/unknownRounds.go index c7a3fa5ac75134e390aa9efaf8c39e8a016025ec..1a733a6693d02dc68c80dc25465705dd538fe547 100644 --- a/cmix/identity/receptionID/store/unknownRounds.go +++ b/cmix/identity/receptionID/store/unknownRounds.go @@ -9,13 +9,14 @@ package store import ( "encoding/json" + "sync" + "sync/atomic" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "sync" - "sync/atomic" ) const ( @@ -98,13 +99,13 @@ type UnknownRounds struct { params UnknownRoundsParams // Key Value store to save data to disk - kv *versioned.KV + kv versioned.KV mux sync.Mutex } // NewUnknownRounds builds and returns a new UnknownRounds object. -func NewUnknownRounds(kv *versioned.KV, +func NewUnknownRounds(kv versioned.KV, params UnknownRoundsParams) *UnknownRounds { urs, err := newUnknownRounds(kv, params) @@ -119,7 +120,7 @@ func NewUnknownRounds(kv *versioned.KV, return urs } -func newUnknownRounds(kv *versioned.KV, params UnknownRoundsParams) (*UnknownRounds, error) { +func newUnknownRounds(kv versioned.KV, params UnknownRoundsParams) (*UnknownRounds, error) { kv, err := kv.Prefix(unknownRoundPrefix) if err != nil { return nil, errors.Errorf("failed to add prefix %s to KV: %+v", unknownRoundPrefix, err) @@ -136,7 +137,7 @@ func newUnknownRounds(kv *versioned.KV, params UnknownRoundsParams) (*UnknownRou // LoadUnknownRounds loads the data for a UnknownRounds from disk into an // object. -func LoadUnknownRounds(kv *versioned.KV, +func LoadUnknownRounds(kv versioned.KV, params UnknownRoundsParams) *UnknownRounds { kv, err := kv.Prefix(unknownRoundPrefix) if err != nil { diff --git a/cmix/message/handler.go b/cmix/message/handler.go index 23bfde1d30d14f0cb2cbd6c974c6edf13aee824c..4bff5d6446cd071452fd0d99d5878b85742a9e09 100644 --- a/cmix/message/handler.go +++ b/cmix/message/handler.go @@ -64,7 +64,7 @@ type handler struct { FallthroughManager } -func NewHandler(param Params, kv *versioned.KV, events event.Reporter, +func NewHandler(param Params, kv versioned.KV, events event.Reporter, standardID *id.ID) Handler { garbled, err := NewOrLoadMeteredCmixMessageBuffer(kv, inProcessKey) diff --git a/cmix/message/meteredCmixMessageBuffer.go b/cmix/message/meteredCmixMessageBuffer.go index f58d67563e4d17c081590f63a3a295b79435cbc1..2e72cd9d9ed2e6a1235236aeb0215bb0cca1c297 100644 --- a/cmix/message/meteredCmixMessageBuffer.go +++ b/cmix/message/meteredCmixMessageBuffer.go @@ -36,7 +36,7 @@ type meteredCmixMessage struct { // SaveMessage saves the message as a versioned object at the specified key in // the key value store. -func (*meteredCmixMessageHandler) SaveMessage(kv *versioned.KV, m interface{}, +func (*meteredCmixMessageHandler) SaveMessage(kv versioned.KV, m interface{}, key string) error { msg := m.(meteredCmixMessage) @@ -59,7 +59,7 @@ func (*meteredCmixMessageHandler) SaveMessage(kv *versioned.KV, m interface{}, // LoadMessage returns the message with the specified key from the key value // store. An empty message and error are returned if the message could not be // retrieved. -func (*meteredCmixMessageHandler) LoadMessage(kv *versioned.KV, key string) ( +func (*meteredCmixMessageHandler) LoadMessage(kv versioned.KV, key string) ( interface{}, error) { // Load the versioned object vo, err := kv.Get(key, utility.CurrentMessageBufferVersion) @@ -80,7 +80,7 @@ func (*meteredCmixMessageHandler) LoadMessage(kv *versioned.KV, key string) ( // DeleteMessage deletes the message with the specified key from the key value // store. -func (*meteredCmixMessageHandler) DeleteMessage(kv *versioned.KV, key string) error { +func (*meteredCmixMessageHandler) DeleteMessage(kv versioned.KV, key string) error { return kv.Delete(key, utility.CurrentMessageBufferVersion) } @@ -102,11 +102,11 @@ func (*meteredCmixMessageHandler) HashMessage(m interface{}) utility.MessageHash // messages. type MeteredCmixMessageBuffer struct { mb *utility.MessageBuffer - kv *versioned.KV + kv versioned.KV key string } -func NewMeteredCmixMessageBuffer(kv *versioned.KV, key string) ( +func NewMeteredCmixMessageBuffer(kv versioned.KV, key string) ( *MeteredCmixMessageBuffer, error) { mb, err := utility.NewMessageBuffer(kv, &meteredCmixMessageHandler{}, key) if err != nil { @@ -116,7 +116,7 @@ func NewMeteredCmixMessageBuffer(kv *versioned.KV, key string) ( return &MeteredCmixMessageBuffer{mb: mb, kv: kv, key: key}, nil } -func LoadMeteredCmixMessageBuffer(kv *versioned.KV, key string) ( +func LoadMeteredCmixMessageBuffer(kv versioned.KV, key string) ( *MeteredCmixMessageBuffer, error) { mb, err := utility.LoadMessageBuffer(kv, &meteredCmixMessageHandler{}, key) if err != nil { @@ -126,7 +126,7 @@ func LoadMeteredCmixMessageBuffer(kv *versioned.KV, key string) ( return &MeteredCmixMessageBuffer{mb: mb, kv: kv, key: key}, nil } -func NewOrLoadMeteredCmixMessageBuffer(kv *versioned.KV, key string) ( +func NewOrLoadMeteredCmixMessageBuffer(kv versioned.KV, key string) ( *MeteredCmixMessageBuffer, error) { mb, err := utility.LoadMessageBuffer(kv, &meteredCmixMessageHandler{}, key) if err != nil { diff --git a/cmix/nodes/interfaces.go b/cmix/nodes/interfaces.go index 11c3c14757cc0a40b29726c88c898eac8616df92..ae397b6e47aa80e4064ba825023064747194f4ec 100644 --- a/cmix/nodes/interfaces.go +++ b/cmix/nodes/interfaces.go @@ -87,7 +87,7 @@ type session interface { GetTransmissionID() *id.ID IsPrecanned() bool GetCmixGroup() *cyclic.Group - GetKV() *versioned.KV + GetKV() versioned.KV GetTransmissionRSA() rsa.PrivateKey GetRegistrationTimestamp() time.Time GetTransmissionSalt() []byte diff --git a/cmix/nodes/registrar.go b/cmix/nodes/registrar.go index 3d59fefce505a7fe0fb11f919f01776d3b108bd2..187c3f859d37f417e3e82ff85cb5ba34f7df4304 100644 --- a/cmix/nodes/registrar.go +++ b/cmix/nodes/registrar.go @@ -9,6 +9,11 @@ package nodes import ( "bytes" + "strconv" + "sync" + "sync/atomic" + "time" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/cmix/gateway" @@ -21,10 +26,6 @@ import ( "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/ndf" - "strconv" - "sync" - "sync/atomic" - "time" ) const InputChanLen = 1000 @@ -42,7 +43,7 @@ var delayTable = [5]time.Duration{ // registrar is an implementation of the Registrar interface. type registrar struct { nodes map[id.ID]*key - kv *versioned.KV + kv versioned.KV mux sync.RWMutex session session diff --git a/cmix/nodes/storeKey.go b/cmix/nodes/storeKey.go index b6de84269464e20cf66a95833a3eede010a548f1..a38de9c44635bd959535894377c130f41bca84c7 100644 --- a/cmix/nodes/storeKey.go +++ b/cmix/nodes/storeKey.go @@ -20,14 +20,14 @@ import ( const currentKeyVersion = 0 type key struct { - kv *versioned.KV + kv versioned.KV k *cyclic.Int keyId []byte validUntil uint64 storeKey string } -func newKey(kv *versioned.KV, k *cyclic.Int, id *id.ID, validUntil uint64, +func newKey(kv versioned.KV, k *cyclic.Int, id *id.ID, validUntil uint64, keyId []byte) *key { nk := &key{ kv: kv, @@ -50,7 +50,7 @@ func (k *key) get() *cyclic.Int { } // loadKey loads the key for the given node ID from the versioned keystore. -func loadKey(kv *versioned.KV, id *id.ID) (*key, error) { +func loadKey(kv versioned.KV, id *id.ID) (*key, error) { k := &key{} key := keyKey(id) @@ -88,7 +88,7 @@ func (k *key) save() error { } // delete deletes the key from the versioned keystore. -func (k *key) delete(kv *versioned.KV, id *id.ID) { +func (k *key) delete(kv versioned.KV, id *id.ID) { key := keyKey(id) if err := kv.Delete(key, currentKeyVersion); err != nil { jww.FATAL.Panicf("Failed to delete key %s: %s", k, err) diff --git a/cmix/nodes/utils_test.go b/cmix/nodes/utils_test.go index ae6ebd80324fe6c44cfe32c03155a83f262dcd50..00fd104df0ad5227647eefba4f1045f14ee23866 100644 --- a/cmix/nodes/utils_test.go +++ b/cmix/nodes/utils_test.go @@ -172,7 +172,7 @@ func (m mockSession) GetCmixGroup() *cyclic.Group { return nil } -func (m mockSession) GetKV() *versioned.KV { +func (m mockSession) GetKV() versioned.KV { return nil } diff --git a/cmix/pickup/store/store.go b/cmix/pickup/store/store.go index 61fcd0d8cc176fce349adc51a7c79db6b9150959..8a2e17b9e9bdad8ca86eb16c843cc30ae6867e57 100644 --- a/cmix/pickup/store/store.go +++ b/cmix/pickup/store/store.go @@ -26,11 +26,11 @@ import ( type UncheckedRoundStore struct { list map[roundIdentity]UncheckedRound mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // NewUncheckedStore is a constructor for a UncheckedRoundStore. -func NewUncheckedStore(kv *versioned.KV) (*UncheckedRoundStore, error) { +func NewUncheckedStore(kv versioned.KV) (*UncheckedRoundStore, error) { kv, err := kv.Prefix(uncheckedRoundPrefix) if err != nil { return nil, err @@ -45,7 +45,7 @@ func NewUncheckedStore(kv *versioned.KV) (*UncheckedRoundStore, error) { } // NewOrLoadUncheckedStore is a constructor for a UncheckedRoundStore. -func NewOrLoadUncheckedStore(kv *versioned.KV) *UncheckedRoundStore { +func NewOrLoadUncheckedStore(kv versioned.KV) *UncheckedRoundStore { kv, err := kv.Prefix(uncheckedRoundPrefix) if err != nil { jww.FATAL.Panicf("Failed to add prefix %s to KV: %+v", uncheckedRoundPrefix, err) @@ -69,7 +69,7 @@ func NewOrLoadUncheckedStore(kv *versioned.KV) *UncheckedRoundStore { } // LoadUncheckedStore loads a deserializes a UncheckedRoundStore from memory. -func LoadUncheckedStore(kv *versioned.KV) (*UncheckedRoundStore, error) { +func LoadUncheckedStore(kv versioned.KV) (*UncheckedRoundStore, error) { kv, err := kv.Prefix(uncheckedRoundPrefix) if err != nil { return nil, err diff --git a/cmix/pickup/store/uncheckedRounds.go b/cmix/pickup/store/uncheckedRounds.go index b4f77054c2b3578ca3040d48868d6a621f812982..6d56e04dde354e1cc8f6d974eddc82139d1db023 100644 --- a/cmix/pickup/store/uncheckedRounds.go +++ b/cmix/pickup/store/uncheckedRounds.go @@ -10,6 +10,8 @@ package store import ( "bytes" "encoding/binary" + "time" + "github.com/golang/protobuf/proto" "github.com/pkg/errors" "gitlab.com/elixxir/client/v4/storage/versioned" @@ -17,7 +19,6 @@ import ( "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/netTime" - "time" ) const ( @@ -61,7 +62,7 @@ type UncheckedRound struct { } // marshal serializes UncheckedRound r into a byte slice. -func (r UncheckedRound) marshal(kv *versioned.KV) ([]byte, error) { +func (r UncheckedRound) marshal(kv versioned.KV) ([]byte, error) { buf := bytes.NewBuffer(nil) // Store teh round info if r.Info != nil && !r.storageUpToDate { @@ -104,7 +105,7 @@ func (r UncheckedRound) marshal(kv *versioned.KV) ([]byte, error) { } // unmarshal deserializes round data from buff into UncheckedRound r. -func (r *UncheckedRound) unmarshal(kv *versioned.KV, buff *bytes.Buffer) error { +func (r *UncheckedRound) unmarshal(kv versioned.KV, buff *bytes.Buffer) error { // Deserialize the roundInfo r.Id = id.Round(binary.LittleEndian.Uint64(buff.Next(uint64Size))) @@ -135,7 +136,7 @@ func (r *UncheckedRound) unmarshal(kv *versioned.KV, buff *bytes.Buffer) error { return nil } -func storeRoundInfo(kv *versioned.KV, info *pb.RoundInfo, recipient *id.ID, +func storeRoundInfo(kv versioned.KV, info *pb.RoundInfo, recipient *id.ID, ephID ephemeral.Id) error { now := netTime.Now() @@ -155,7 +156,7 @@ func storeRoundInfo(kv *versioned.KV, info *pb.RoundInfo, recipient *id.ID, roundKey(id.Round(info.ID), recipient, ephID), &obj) } -func loadRoundInfo(kv *versioned.KV, id id.Round, recipient *id.ID, +func loadRoundInfo(kv versioned.KV, id id.Round, recipient *id.ID, ephID ephemeral.Id) (*pb.RoundInfo, error) { vo, err := kv.Get(roundKey(id, recipient, ephID), roundInfoVersion) @@ -171,7 +172,7 @@ func loadRoundInfo(kv *versioned.KV, id id.Round, recipient *id.ID, return ri, nil } -func deleteRoundInfo(kv *versioned.KV, id id.Round, recipient *id.ID, +func deleteRoundInfo(kv versioned.KV, id id.Round, recipient *id.ID, ephID ephemeral.Id) error { return kv.Delete(roundKey(id, recipient, ephID), roundInfoVersion) } diff --git a/cmix/rounds/roundStorage.go b/cmix/rounds/roundStorage.go index 91f8ac99e810d23f98bf687b59a7a6a084a15566..3ad31addb73774a5fdb98985496402a009555b8f 100644 --- a/cmix/rounds/roundStorage.go +++ b/cmix/rounds/roundStorage.go @@ -17,7 +17,7 @@ import ( const currentRoundVersion = 0 // StoreRound stores the round using the key. -func StoreRound(kv *versioned.KV, round Round, key string) error { +func StoreRound(kv versioned.KV, round Round, key string) error { now := netTime.Now() marshaled, err := proto.Marshal(round.Raw) @@ -36,7 +36,7 @@ func StoreRound(kv *versioned.KV, round Round, key string) error { } // LoadRound stores the round using the key. -func LoadRound(kv *versioned.KV, key string) (Round, error) { +func LoadRound(kv versioned.KV, key string) (Round, error) { vo, err := kv.Get(key, currentRoundVersion) if err != nil { return Round{}, err @@ -51,6 +51,6 @@ func LoadRound(kv *versioned.KV, key string) (Round, error) { return MakeRound(ri), nil } -func DeleteRound(kv *versioned.KV, key string) error { +func DeleteRound(kv versioned.KV, key string) error { return kv.Delete(key, currentRoundVersion) } diff --git a/dm/client.go b/dm/client.go index 9672b1eb13c7a3d59a55209d75302dd5fda62d3b..2789c75a0669ce5f9410d1dc5018259f613035f3 100644 --- a/dm/client.go +++ b/dm/client.go @@ -108,7 +108,7 @@ func (dc *dmClient) register(apiReceiver EventModel, return nil } -func NewNicknameManager(id *id.ID, ekv *versioned.KV) NickNameManager { +func NewNicknameManager(id *id.ID, ekv versioned.KV) NickNameManager { return &nickMgr{ ekv: ekv, storeKey: fmt.Sprintf(nickStoreKey, id.String()), @@ -118,7 +118,7 @@ func NewNicknameManager(id *id.ID, ekv *versioned.KV) NickNameManager { type nickMgr struct { storeKey string - ekv *versioned.KV + ekv versioned.KV nick string sync.Mutex } diff --git a/dm/sendTracker.go b/dm/sendTracker.go index afc06c28a359f0f518afb8a88f40b83fe2f67273..22dd5600f5a021d0ea92c6396874c97c34637d42 100644 --- a/dm/sendTracker.go +++ b/dm/sendTracker.go @@ -85,14 +85,14 @@ type sendTracker struct { net cMixClient - kv *versioned.KV + kv versioned.KV rngSrc *fastRNG.StreamGenerator } // NewSendTracker returns an uninitialized SendTracker object. The DM // Client will call Init to initialize it. -func NewSendTracker(kv *versioned.KV) SendTracker { +func NewSendTracker(kv versioned.KV) SendTracker { return &sendTracker{kv: kv} } diff --git a/e2e/critical.go b/e2e/critical.go index 4122fbaf763b11b37a9856ecb8d5a043184d46a9..e027b9a1b954054fdb69761f6e127f3497705e24 100644 --- a/e2e/critical.go +++ b/e2e/critical.go @@ -48,7 +48,7 @@ type critical struct { healthcb func(f func(bool)) uint64 } -func newCritical(kv *versioned.KV, hm func(f func(bool)) uint64, +func newCritical(kv versioned.KV, hm func(f func(bool)) uint64, send criticalSender) *critical { cm, err := NewOrLoadE2eMessageBuffer(kv, e2eCriticalMessagesKey) if err != nil { diff --git a/e2e/e2eMessageBuffer.go b/e2e/e2eMessageBuffer.go index af33b779c84234228e8dfa276bceb52c5a8e6035..0427753d91aab7965977980dc69d24de5ad0c129 100644 --- a/e2e/e2eMessageBuffer.go +++ b/e2e/e2eMessageBuffer.go @@ -33,7 +33,7 @@ type e2eMessage struct { // SaveMessage saves the e2eMessage as a versioned object at the specified key // in the key value store. -func (emh *e2eMessageHandler) SaveMessage(kv *versioned.KV, m interface{}, +func (emh *e2eMessageHandler) SaveMessage(kv versioned.KV, m interface{}, key string) error { msg := m.(e2eMessage) @@ -57,7 +57,7 @@ func (emh *e2eMessageHandler) SaveMessage(kv *versioned.KV, m interface{}, // LoadMessage returns the e2eMessage with the specified key from the key value // store. An empty message and error are returned if the message could not be // retrieved. -func (emh *e2eMessageHandler) LoadMessage(kv *versioned.KV, key string) ( +func (emh *e2eMessageHandler) LoadMessage(kv versioned.KV, key string) ( interface{}, error) { // Load the versioned object vo, err := kv.Get(key, currentE2EMessageVersion) @@ -77,7 +77,7 @@ func (emh *e2eMessageHandler) LoadMessage(kv *versioned.KV, key string) ( // DeleteMessage deletes the message with the specified key from the key value // store. -func (emh *e2eMessageHandler) DeleteMessage(kv *versioned.KV, +func (emh *e2eMessageHandler) DeleteMessage(kv versioned.KV, key string) error { return kv.Delete(key, currentE2EMessageVersion) } @@ -106,7 +106,7 @@ type E2eMessageBuffer struct { mb *utility.MessageBuffer } -func NewOrLoadE2eMessageBuffer(kv *versioned.KV, key string) ( +func NewOrLoadE2eMessageBuffer(kv versioned.KV, key string) ( *E2eMessageBuffer, error) { mb, err := LoadE2eMessageBuffer(kv, key) if err == nil { @@ -119,7 +119,7 @@ func NewOrLoadE2eMessageBuffer(kv *versioned.KV, key string) ( return &E2eMessageBuffer{mb: mbInt}, nil } -func LoadE2eMessageBuffer(kv *versioned.KV, key string) ( +func LoadE2eMessageBuffer(kv versioned.KV, key string) ( *E2eMessageBuffer, error) { mb, err := utility.LoadMessageBuffer(kv, &e2eMessageHandler{}, key) if err != nil { diff --git a/e2e/manager.go b/e2e/manager.go index 5978aebfc6ebbaa348888d5efad2feb54487f85d..13f1d9ea309360b87ac1c7e15ced325bb46aa477 100644 --- a/e2e/manager.go +++ b/e2e/manager.go @@ -45,7 +45,7 @@ type manager struct { grp *cyclic.Group crit *critical rekeyParams rekey.Params - kv *versioned.KV + kv versioned.KV // Generic Callbacks for all E2E operations; by default this is nil and // ignored until set via RegisterCallbacks @@ -63,7 +63,7 @@ const e2eRekeyParamsVer = 0 // Init Creates stores. After calling, use load // Passes the ID public key which is used for the relationship // uses the passed ID to modify the kv prefix for a unique storage path -func Init(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, +func Init(kv versioned.KV, myID *id.ID, privKey *cyclic.Int, grp *cyclic.Group, rekeyParams rekey.Params) error { jww.INFO.Printf("Initializing new e2e.Handler for %s", myID.String()) kv, err := kv.Prefix(makeE2ePrefix(myID)) @@ -74,7 +74,7 @@ func Init(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, return initE2E(kv, myID, privKey, grp, rekeyParams) } -func initE2E(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, +func initE2E(kv versioned.KV, myID *id.ID, privKey *cyclic.Int, grp *cyclic.Group, rekeyParams rekey.Params) error { rekeyParamsData, err := json.Marshal(rekeyParams) if err != nil { @@ -96,7 +96,7 @@ func initE2E(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, // You can use a memkv for an ephemeral e2e id // Can be initialized with a nil cmix.Client, but will crash on start - use when // prebuilding e2e identity to be used later -func Load(kv *versioned.KV, net cmix.Client, myID *id.ID, +func Load(kv versioned.KV, net cmix.Client, myID *id.ID, grp *cyclic.Group, rng *fastRNG.StreamGenerator, events event.Reporter) (Handler, error) { kv, err := kv.Prefix(makeE2ePrefix(myID)) @@ -114,7 +114,7 @@ func Load(kv *versioned.KV, net cmix.Client, myID *id.ID, // You can use a memkv for an ephemeral e2e id // Can be initialized with a nil cmix.Client, but will crash on start - use when // prebuilding e2e identity to be used later -func LoadLegacy(kv *versioned.KV, net cmix.Client, myID *id.ID, +func LoadLegacy(kv versioned.KV, net cmix.Client, myID *id.ID, grp *cyclic.Group, rng *fastRNG.StreamGenerator, events event.Reporter, params rekey.Params) (Handler, error) { @@ -158,7 +158,7 @@ func LoadLegacy(kv *versioned.KV, net cmix.Client, myID *id.ID, } -func loadE2E(kv *versioned.KV, net cmix.Client, myDefaultID *id.ID, +func loadE2E(kv versioned.KV, net cmix.Client, myDefaultID *id.ID, grp *cyclic.Group, rng *fastRNG.StreamGenerator, events event.Reporter) (Handler, error) { diff --git a/e2e/parse/conversation/partner.go b/e2e/parse/conversation/partner.go index 9336dfba889d79f04163ce17d6c1f5877c9dd70c..01485bfec6695a41d0ad8e77386826c2fb6fad42 100644 --- a/e2e/parse/conversation/partner.go +++ b/e2e/parse/conversation/partner.go @@ -9,13 +9,14 @@ package conversation import ( "encoding/json" + "math" + "sync" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "math" - "sync" ) const ( @@ -33,7 +34,7 @@ type Conversation struct { // Private and non-stored data partner *id.ID - kv *versioned.KV + kv versioned.KV mux sync.Mutex } @@ -47,7 +48,7 @@ type conversationDisk struct { // LoadOrMakeConversation returns the Conversation with the given ID, if it can // be found in KV. Otherwise, a new conversation with the given ID is generated, // saved to KV, and returned. -func LoadOrMakeConversation(kv *versioned.KV, partner *id.ID) *Conversation { +func LoadOrMakeConversation(kv versioned.KV, partner *id.ID) *Conversation { c, err := loadConversation(kv, partner) if err != nil && kv.Exists(err) { jww.FATAL.Panicf("Failed to load conversation from storage: %+v", err) @@ -127,7 +128,7 @@ func (c *Conversation) GetNextSendID() (uint64, uint32) { } // loadConversation returns the Conversation with the given ID from KV storage. -func loadConversation(kv *versioned.KV, partner *id.ID) (*Conversation, error) { +func loadConversation(kv versioned.KV, partner *id.ID) (*Conversation, error) { key := makeConversationKey(partner) obj, err := kv.Get(key, currentConversationVersion) diff --git a/e2e/parse/conversation/partner_test.go b/e2e/parse/conversation/partner_test.go index 68460b5e2165c3d3afbae223186508082dbecb64..e9368961d0586f0fc50ed2aa1063229232d4258d 100644 --- a/e2e/parse/conversation/partner_test.go +++ b/e2e/parse/conversation/partner_test.go @@ -8,12 +8,13 @@ package conversation import ( - "gitlab.com/elixxir/client/v4/storage/versioned" - "gitlab.com/elixxir/ekv" - "gitlab.com/xx_network/primitives/id" "math/rand" "reflect" "testing" + + "gitlab.com/elixxir/client/v4/storage/versioned" + "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/primitives/id" ) // Tests happy path of LoadOrMakeConversation when making a new Conversation. @@ -221,7 +222,7 @@ func TestConversation_marshal_unmarshal(t *testing.T) { } } -func makeRandomConv(kv *versioned.KV, partner *id.ID) *Conversation { +func makeRandomConv(kv versioned.KV, partner *id.ID) *Conversation { c := LoadOrMakeConversation(kv, partner) c.lastReceivedID = rand.Uint32() c.numReceivedRevolutions = rand.Uint32() diff --git a/e2e/parse/conversation/ring.go b/e2e/parse/conversation/ring.go index 74705e4dc98f3a360f1aad1afb29464adc7c4e53..3a7a815ec82a8818fe3af511ec658c583b9050d3 100644 --- a/e2e/parse/conversation/ring.go +++ b/e2e/parse/conversation/ring.go @@ -10,12 +10,13 @@ package conversation import ( "bytes" "encoding/binary" - "github.com/pkg/errors" - "gitlab.com/elixxir/client/v4/storage/versioned" - "gitlab.com/xx_network/primitives/netTime" "math" "sync" "time" + + "github.com/pkg/errors" + "gitlab.com/elixxir/client/v4/storage/versioned" + "gitlab.com/xx_network/primitives/netTime" ) // Storage keys and versions. @@ -43,11 +44,11 @@ type Buff struct { lookup map[truncatedMessageID]*Message oldest, newest uint32 mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // NewBuff initializes a new ring buffer with size n. -func NewBuff(kv *versioned.KV, n int) (*Buff, error) { +func NewBuff(kv versioned.KV, n int) (*Buff, error) { kv, err := kv.Prefix(ringBuffPrefix) if err != nil { return nil, err @@ -173,7 +174,7 @@ func (b *Buff) handleMessageOverwrite() { // LoadBuff loads the ring buffer from storage. It loads all messages from // storage and repopulates the buffer. -func LoadBuff(kv *versioned.KV) (*Buff, error) { +func LoadBuff(kv versioned.KV) (*Buff, error) { kv, err := kv.Prefix(ringBuffPrefix) if err != nil { return nil, err @@ -304,7 +305,7 @@ func (b *Buff) saveMessage(msg *Message) error { } // loadMessage loads a message given truncatedMessageID from storage. -func loadMessage(tmID truncatedMessageID, kv *versioned.KV) (*Message, error) { +func loadMessage(tmID truncatedMessageID, kv versioned.KV) (*Message, error) { // Load message from storage vo, err := kv.Get(makeMessageKey(tmID), messageVersion) if err != nil { diff --git a/e2e/parse/conversation/store.go b/e2e/parse/conversation/store.go index 48e5daffcb0e8919b79e2510fbdf4104dc9bd290..a6dd7d22703a1580e2e4fa4f4d5ad41c275a2bdb 100644 --- a/e2e/parse/conversation/store.go +++ b/e2e/parse/conversation/store.go @@ -19,12 +19,12 @@ const conversationKeyPrefix = "conversation" type Store struct { loadedConversations map[id.ID]*Conversation - kv *versioned.KV + kv versioned.KV mux sync.RWMutex } // NewStore returns a new conversation Store made off of the KV. -func NewStore(kv *versioned.KV) *Store { +func NewStore(kv versioned.KV) *Store { kv, err := kv.Prefix(conversationKeyPrefix) if err != nil { jww.FATAL.Panicf("Failed to add prefix %s to KV", conversationKeyPrefix) diff --git a/e2e/parse/partition.go b/e2e/parse/partition.go index 64667c15a99f7336ec715bb40b830805c1d2c6c8..bb44609c9ca4f402a975f3df7ab67a8d9ddbdd18 100644 --- a/e2e/parse/partition.go +++ b/e2e/parse/partition.go @@ -33,7 +33,7 @@ type Partitioner struct { partition *partition.Store } -func NewPartitioner(kv *versioned.KV, messageSize int) *Partitioner { +func NewPartitioner(kv versioned.KV, messageSize int) *Partitioner { p := Partitioner{ baseMessageSize: messageSize, firstContentsSize: messageSize - firstHeaderLen, diff --git a/e2e/parse/partition/multiPartMessage.go b/e2e/parse/partition/multiPartMessage.go index 99eaaa86a61824b06147f8c5501a414a06aca76e..96840192f297aa5acb1ba879fdc4ec372bca6f0c 100644 --- a/e2e/parse/partition/multiPartMessage.go +++ b/e2e/parse/partition/multiPartMessage.go @@ -9,6 +9,10 @@ package partition import ( "encoding/json" + "strconv" + "sync" + "time" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/catalog" @@ -17,9 +21,6 @@ import ( "gitlab.com/elixxir/crypto/e2e" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "strconv" - "sync" - "time" ) const ( @@ -43,14 +44,14 @@ type multiPartMessage struct { KeyResidue e2e.KeyResidue parts [][]byte - kv *versioned.KV + kv versioned.KV mux sync.Mutex } // loadOrCreateMultiPartMessage loads an extant multipart message store or // creates a new one and saves it if one does not exist. func loadOrCreateMultiPartMessage(sender *id.ID, messageID uint64, - kv *versioned.KV) *multiPartMessage { + kv versioned.KV) *multiPartMessage { kv, err := kv.Prefix(versioned.MakePartnerPrefix(sender)) if err != nil { jww.FATAL.Panicf("Failed to add prefix %s to KV: %+v", diff --git a/e2e/parse/partition/part.go b/e2e/parse/partition/part.go index 0a2932f12d70f79ac5ec42b0e597d0c25f48329a..215c4019b50a3fdb599a0a981d27aef45ba17d80 100644 --- a/e2e/parse/partition/part.go +++ b/e2e/parse/partition/part.go @@ -15,7 +15,7 @@ import ( const currentMultiPartMessagePartVersion = 0 -func loadPart(kv *versioned.KV, partNum uint8) ([]byte, error) { +func loadPart(kv versioned.KV, partNum uint8) ([]byte, error) { key := makeMultiPartMessagePartKey(partNum) obj, err := kv.Get(key, currentMultiPartMessageVersion) @@ -26,7 +26,7 @@ func loadPart(kv *versioned.KV, partNum uint8) ([]byte, error) { return obj.Data, nil } -func savePart(kv *versioned.KV, partNum uint8, part []byte) error { +func savePart(kv versioned.KV, partNum uint8, part []byte) error { key := makeMultiPartMessagePartKey(partNum) obj := versioned.Object{ @@ -37,7 +37,7 @@ func savePart(kv *versioned.KV, partNum uint8, part []byte) error { return kv.Set(key, &obj) } -func deletePart(kv *versioned.KV, partNum uint8) error { +func deletePart(kv versioned.KV, partNum uint8) error { key := makeMultiPartMessagePartKey(partNum) return kv.Delete(key, currentMultiPartMessageVersion) } diff --git a/e2e/parse/partition/store.go b/e2e/parse/partition/store.go index 5183ebcc7777557b48562f8867f2721a2a69ee92..19a9626520d2bfd186b5c1af9cb9797effebf8ae 100644 --- a/e2e/parse/partition/store.go +++ b/e2e/parse/partition/store.go @@ -34,11 +34,11 @@ const activePartitionVersion = 0 type Store struct { multiParts map[multiPartID]*multiPartMessage activeParts map[*multiPartMessage]bool - kv *versioned.KV + kv versioned.KV mux sync.Mutex } -func NewOrLoad(kv *versioned.KV) *Store { +func NewOrLoad(kv versioned.KV) *Store { kv, err := kv.Prefix(packagePrefix) if err != nil { jww.FATAL.Panicf("Failed to add prefix %s to KV: %+v", packagePrefix, err) diff --git a/e2e/ratchet/partner/manager.go b/e2e/ratchet/partner/manager.go index 531eba920185a3533cbc7396e93c2f4f53b306b1..f55b2645c6a2cca7d632ceb065bfcac61b75056a 100644 --- a/e2e/ratchet/partner/manager.go +++ b/e2e/ratchet/partner/manager.go @@ -32,7 +32,7 @@ const relationshipFpLength = 15 // Implements the partner.Manager interface type manager struct { - kv *versioned.KV + kv versioned.KV myID *id.ID partner *id.ID @@ -52,7 +52,7 @@ type manager struct { } // NewManager creates the relationship and its first Send and Receive sessions. -func NewManager(kv *versioned.KV, myID, partnerID *id.ID, myPrivKey, +func NewManager(kv versioned.KV, myID, partnerID *id.ID, myPrivKey, partnerPubKey *cyclic.Int, mySIDHPrivKey *sidh.PrivateKey, partnerSIDHPubKey *sidh.PublicKey, sendParams, receiveParams session.Params, cyHandler session.CypherHandler, @@ -114,7 +114,7 @@ func (c ConnectionFp) String() string { } // LoadManager loads a relationship and all buffers and sessions from disk -func LoadManager(kv *versioned.KV, myID, partnerID *id.ID, +func LoadManager(kv versioned.KV, myID, partnerID *id.ID, cyHandler session.CypherHandler, grp *cyclic.Group, rng *fastRNG.StreamGenerator) (Manager, error) { diff --git a/e2e/ratchet/partner/relationship.go b/e2e/ratchet/partner/relationship.go index 66356a8f56762cc34e04f5a83f3407cc59265a5f..3a533136209b33873e75e85d7ae7344c08871f90 100644 --- a/e2e/ratchet/partner/relationship.go +++ b/e2e/ratchet/partner/relationship.go @@ -31,7 +31,7 @@ const relationshipFingerprintKey = "relationshipFingerprint" type relationship struct { t session.RelationshipType - kv *versioned.KV + kv versioned.KV sessions []*session.Session sessionByID map[session.SessionID]*session.Session @@ -60,7 +60,7 @@ type ServiceHandler interface { // Should be refactored to create an empty relationship, with a second call // adding the session // todo - doscstring -func NewRelationship(kv *versioned.KV, t session.RelationshipType, +func NewRelationship(kv versioned.KV, t session.RelationshipType, myID, partnerID *id.ID, myOriginPrivateKey, partnerOriginPublicKey *cyclic.Int, originMySIDHPrivKey *sidh.PrivateKey, originPartnerSIDHPubKey *sidh.PublicKey, initialParams session.Params, @@ -118,7 +118,7 @@ func NewRelationship(kv *versioned.KV, t session.RelationshipType, } // todo - doscstring -func LoadRelationship(kv *versioned.KV, t session.RelationshipType, myID, +func LoadRelationship(kv versioned.KV, t session.RelationshipType, myID, partnerID *id.ID, cyHandler session.CypherHandler, grp *cyclic.Group, rng *fastRNG.StreamGenerator) (*relationship, error) { diff --git a/e2e/ratchet/partner/relationshipFingerprint.go b/e2e/ratchet/partner/relationshipFingerprint.go index 396e65f6b8d13c2ebf63f4142615b9382bae08d0..dd651545cc2bfbe1a1fc2cfd74a2f2d667ddda69 100644 --- a/e2e/ratchet/partner/relationshipFingerprint.go +++ b/e2e/ratchet/partner/relationshipFingerprint.go @@ -37,7 +37,7 @@ func makeRelationshipFingerprint(t session2.RelationshipType, grp *cyclic.Group, return nil } -func storeRelationshipFingerprint(fp []byte, kv *versioned.KV) error { +func storeRelationshipFingerprint(fp []byte, kv versioned.KV) error { now := netTime.Now() obj := versioned.Object{ Version: currentRelationshipVersion, @@ -48,7 +48,7 @@ func storeRelationshipFingerprint(fp []byte, kv *versioned.KV) error { return kv.Set(relationshipFingerprintKey, &obj) } -func loadRelationshipFingerprint(kv *versioned.KV) []byte { +func loadRelationshipFingerprint(kv versioned.KV) []byte { obj, err := kv.Get(relationshipFingerprintKey, currentRelationshipVersion) if err != nil { @@ -59,7 +59,7 @@ func loadRelationshipFingerprint(kv *versioned.KV) []byte { return obj.Data } -func deleteRelationshipFingerprint(kv *versioned.KV) error { +func deleteRelationshipFingerprint(kv versioned.KV) error { return kv.Delete(relationshipFingerprintKey, currentRelationshipVersion) } diff --git a/e2e/ratchet/partner/relationship_test.go b/e2e/ratchet/partner/relationship_test.go index 4698751fd46206db13b776c1c5eb98de6937abe9..2fc5f85fbca0bca703ffe238e79aaaccc161883c 100644 --- a/e2e/ratchet/partner/relationship_test.go +++ b/e2e/ratchet/partner/relationship_test.go @@ -843,7 +843,7 @@ func TestSessionBuff_TriggerNegotiation(t *testing.T) { } } -func makeTestRelationshipManager(t *testing.T) (*manager, *versioned.KV) { +func makeTestRelationshipManager(t *testing.T) (*manager, versioned.KV) { grp := cyclic.NewGroup( large.NewIntFromString("E2EE983D031DC1DB6F1A7A67DF0E9A8E5561DB8E8D49413394C049B"+ "7A8ACCEDC298708F121951D9CF920EC5D146727AA4AE535B0922C688B55B3DD2AE"+ diff --git a/e2e/ratchet/partner/session/session.go b/e2e/ratchet/partner/session/session.go index 039ff42772589383247380cfb3cee29442234158..93674a4cadcd4be0be166dfbd923dfb12f5f5680 100644 --- a/e2e/ratchet/partner/session/session.go +++ b/e2e/ratchet/partner/session/session.go @@ -36,7 +36,7 @@ const sessionKey = "session" type Session struct { //prefixed kv - kv *versioned.KV + kv versioned.KV //params e2eParams Params @@ -125,7 +125,7 @@ type SessionDisk struct { /*CONSTRUCTORS*/ // NewSession - Generator which creates all keys and structures -func NewSession(kv *versioned.KV, t RelationshipType, partner *id.ID, myPrivKey, +func NewSession(kv versioned.KV, t RelationshipType, partner *id.ID, myPrivKey, partnerPubKey, baseKey *cyclic.Int, mySIDHPrivKey *sidh.PrivateKey, partnerSIDHPubKey *sidh.PublicKey, trigger SessionID, relationshipFingerprint []byte, negotiationStatus Negotiation, @@ -189,7 +189,7 @@ func NewSession(kv *versioned.KV, t RelationshipType, partner *id.ID, myPrivKey, } // LoadSession and state vector from kv and populate runtime fields -func LoadSession(kv *versioned.KV, sessionID SessionID, +func LoadSession(kv versioned.KV, sessionID SessionID, relationshipFingerprint []byte, cyHandler CypherHandler, grp *cyclic.Group, rng *fastRNG.StreamGenerator) (*Session, error) { diff --git a/e2e/ratchet/partner/session/testUtils.go b/e2e/ratchet/partner/session/testUtils.go index 533ec1709e06f7d81a87598641230d81ec16315c..8cf07dd4c96fd1a5fc3408aab9ee5b272d615814 100644 --- a/e2e/ratchet/partner/session/testUtils.go +++ b/e2e/ratchet/partner/session/testUtils.go @@ -47,7 +47,7 @@ func getGroup() *cyclic.Group { } -func CreateTestSession(numKeys, keysAvailable, rekeyThreshold uint32, status Negotiation, t *testing.T) (*Session, *versioned.KV) { +func CreateTestSession(numKeys, keysAvailable, rekeyThreshold uint32, status Negotiation, t *testing.T) (*Session, versioned.KV) { if t == nil { panic("Cannot run this outside tests") } @@ -68,7 +68,7 @@ func CreateTestSession(numKeys, keysAvailable, rekeyThreshold uint32, status Neg } // Make a default test session with some things populated -func makeTestSession() (*Session, *versioned.KV) { +func makeTestSession() (*Session, versioned.KV) { grp := getGroup() rng := csprng.NewSystemRNG() partnerPrivKey := dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, diff --git a/e2e/ratchet/partner/utils_test.go b/e2e/ratchet/partner/utils_test.go index 4d485f183bd180312a323d1fb65c6d8fb8139874..6af81d3f80b3440bebba4d1dfee588ff15b50a2e 100644 --- a/e2e/ratchet/partner/utils_test.go +++ b/e2e/ratchet/partner/utils_test.go @@ -54,7 +54,7 @@ func getGroup() *cyclic.Group { } // newTestManager returns a new relationship for testing. -func newTestManager(t *testing.T) (manager, *versioned.KV) { +func newTestManager(t *testing.T) (manager, versioned.KV) { if t == nil { panic("Cannot run this outside tests") } diff --git a/e2e/ratchet/ratchet.go b/e2e/ratchet/ratchet.go index fa960f14d6b3ba0c31e780c83524c0e5cbb64de1..573eab3f0d8a0bf78ec0ac0f1395de03268856ca 100644 --- a/e2e/ratchet/ratchet.go +++ b/e2e/ratchet/ratchet.go @@ -49,14 +49,14 @@ type Ratchet struct { sInterface Services servicesMux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // New creates a new store for the passed user ID and private key. // The store can then be accessed by calling LoadStore. // Does not create at a unique prefix, if multiple Ratchets are needed, make // sure to add an uint prefix to the KV before instantiation. -func New(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int, +func New(kv versioned.KV, myID *id.ID, privKey *cyclic.Int, grp *cyclic.Group) error { // Generate public key diff --git a/e2e/ratchet/storage.go b/e2e/ratchet/storage.go index 4534779e5203f8a414f5a9b8c0f1931ccaa7a130..5de0a8e2f0cafbf7653f11f0bacb7f26a9593e72 100644 --- a/e2e/ratchet/storage.go +++ b/e2e/ratchet/storage.go @@ -29,7 +29,7 @@ const ( ) // Load loads an extant ratchet from disk -func Load(kv *versioned.KV, myID *id.ID, grp *cyclic.Group, +func Load(kv versioned.KV, myID *id.ID, grp *cyclic.Group, cyHandler session.CypherHandler, services Services, rng *fastRNG.StreamGenerator) ( *Ratchet, error) { kv, err := kv.Prefix(packagePrefix) diff --git a/e2e/ratchet/utils_test.go b/e2e/ratchet/utils_test.go index 6a2b8ec6b298d2045131c5bf589c37346a74c06a..2737ad470a6e122a49f7b487025068f0900d2cef 100644 --- a/e2e/ratchet/utils_test.go +++ b/e2e/ratchet/utils_test.go @@ -31,7 +31,7 @@ import ( ) // Constructor for a mock ratchet -func makeTestRatchet() (*Ratchet, *versioned.KV, error) { +func makeTestRatchet() (*Ratchet, versioned.KV, error) { grp := cyclic.NewGroup(large.NewInt(107), large.NewInt(2)) privKey := grp.NewInt(57) kv := versioned.NewKV(ekv.MakeMemstore()) diff --git a/fileTransfer/connect/utils_test.go b/fileTransfer/connect/utils_test.go index dad4999cda72c07bb0b6f19072b1a51d38d3b879..d391139938dea99137ab42adb8d53ca5cfd2654f 100644 --- a/fileTransfer/connect/utils_test.go +++ b/fileTransfer/connect/utils_test.go @@ -317,7 +317,7 @@ func (m *mockConnection) RegisterListener(mt catalog.MessageType, //////////////////////////////////////////////////////////////////////////////// type mockStorage struct { - kv *versioned.KV + kv versioned.KV cmixGroup *cyclic.Group } @@ -337,7 +337,7 @@ func (m *mockStorage) GetClientVersion() version.Version { panic("implement func (m *mockStorage) Get(string) (*versioned.Object, error) { panic("implement me") } func (m *mockStorage) Set(string, *versioned.Object) error { panic("implement me") } func (m *mockStorage) Delete(string) error { panic("implement me") } -func (m *mockStorage) GetKV() *versioned.KV { return m.kv } +func (m *mockStorage) GetKV() versioned.KV { return m.kv } func (m *mockStorage) GetCmixGroup() *cyclic.Group { return m.cmixGroup } func (m *mockStorage) GetE2EGroup() *cyclic.Group { panic("implement me") } func (m *mockStorage) ForwardRegistrationStatus(storage.RegistrationStatus) error { diff --git a/fileTransfer/e2e/utils_test.go b/fileTransfer/e2e/utils_test.go index ceb87f3409fed45138984193a73edb285e7369e0..134bdb7cc8966d6940149c07c87439715048cf6e 100644 --- a/fileTransfer/e2e/utils_test.go +++ b/fileTransfer/e2e/utils_test.go @@ -342,7 +342,7 @@ func (m *mockE2e) DeletePartnerCallbacks(*id.ID) { panic("implement //////////////////////////////////////////////////////////////////////////////// type mockStorage struct { - kv *versioned.KV + kv versioned.KV cmixGroup *cyclic.Group } @@ -362,7 +362,7 @@ func (m *mockStorage) GetClientVersion() version.Version { panic("implement func (m *mockStorage) Get(string) (*versioned.Object, error) { panic("implement me") } func (m *mockStorage) Set(string, *versioned.Object) error { panic("implement me") } func (m *mockStorage) Delete(string) error { panic("implement me") } -func (m *mockStorage) GetKV() *versioned.KV { return m.kv } +func (m *mockStorage) GetKV() versioned.KV { return m.kv } func (m *mockStorage) GetCmixGroup() *cyclic.Group { return m.cmixGroup } func (m *mockStorage) GetE2EGroup() *cyclic.Group { panic("implement me") } func (m *mockStorage) ForwardRegistrationStatus(storage.RegistrationStatus) error { diff --git a/fileTransfer/groupChat/utils_test.go b/fileTransfer/groupChat/utils_test.go index bf2d3c83816326e15e35f823b9234e1db0ec999e..dd18a7630485692b6607eb84cc0a1cd1cfcc3c3e 100644 --- a/fileTransfer/groupChat/utils_test.go +++ b/fileTransfer/groupChat/utils_test.go @@ -279,7 +279,7 @@ func (m *mockGC) AddService(tag string, p groupChat.Processor) error { //////////////////////////////////////////////////////////////////////////////// type mockStorage struct { - kv *versioned.KV + kv versioned.KV cmixGroup *cyclic.Group } @@ -299,7 +299,7 @@ func (m *mockStorage) GetClientVersion() version.Version { panic("implement func (m *mockStorage) Get(string) (*versioned.Object, error) { panic("implement me") } func (m *mockStorage) Set(string, *versioned.Object) error { panic("implement me") } func (m *mockStorage) Delete(string) error { panic("implement me") } -func (m *mockStorage) GetKV() *versioned.KV { return m.kv } +func (m *mockStorage) GetKV() versioned.KV { return m.kv } func (m *mockStorage) GetCmixGroup() *cyclic.Group { return m.cmixGroup } func (m *mockStorage) GetE2EGroup() *cyclic.Group { panic("implement me") } func (m *mockStorage) ForwardRegistrationStatus(storage.RegistrationStatus) error { diff --git a/fileTransfer/manager.go b/fileTransfer/manager.go index dc65222b3730a23e0364ef77510925b32d505886..28f0876c8f45ffd03ec4720a696b8be2f93debc0 100644 --- a/fileTransfer/manager.go +++ b/fileTransfer/manager.go @@ -128,7 +128,7 @@ type manager struct { myID *id.ID cmix Cmix cmixGroup *cyclic.Group - kv *versioned.KV + kv versioned.KV rng *fastRNG.StreamGenerator } @@ -162,7 +162,7 @@ type Cmix interface { // Storage interface matches a subset of the storage.Session methods used by the // manager for easier testing. type Storage interface { - GetKV() *versioned.KV + GetKV() versioned.KV GetCmixGroup() *cyclic.Group } diff --git a/fileTransfer/store/cypher/manager.go b/fileTransfer/store/cypher/manager.go index 9de789a6cafea005b4a9cde7b1509e6d33900b86..4c77361ea036c1b938fd3e2bf04a203161f0031f 100644 --- a/fileTransfer/store/cypher/manager.go +++ b/fileTransfer/store/cypher/manager.go @@ -51,12 +51,12 @@ type Manager struct { // (has its own storage backend) fpVector *utility.StateVector - kv *versioned.KV + kv versioned.KV } // NewManager returns a new cypher Manager initialised with the given number of // fingerprints. -func NewManager(key *ftCrypto.TransferKey, numFps uint16, kv *versioned.KV) ( +func NewManager(key *ftCrypto.TransferKey, numFps uint16, kv versioned.KV) ( *Manager, error) { kv, err := kv.Prefix(cypherManagerPrefix) @@ -121,7 +121,7 @@ func (m *Manager) GetUnusedCyphers() []Cypher { //////////////////////////////////////////////////////////////////////////////// // LoadManager loads the Manager from storage. -func LoadManager(kv *versioned.KV) (*Manager, error) { +func LoadManager(kv versioned.KV) (*Manager, error) { kv, err := kv.Prefix(cypherManagerPrefix) if err != nil { return nil, err @@ -163,7 +163,7 @@ func (m *Manager) Delete() error { } // saveKey saves the transfer key to storage. -func saveKey(key *ftCrypto.TransferKey, kv *versioned.KV) error { +func saveKey(key *ftCrypto.TransferKey, kv versioned.KV) error { obj := &versioned.Object{ Version: cypherManagerKeyStoreVersion, Timestamp: netTime.Now(), @@ -174,7 +174,7 @@ func saveKey(key *ftCrypto.TransferKey, kv *versioned.KV) error { } // loadKey loads the transfer key from storage. -func loadKey(kv *versioned.KV) (*ftCrypto.TransferKey, error) { +func loadKey(kv versioned.KV) (*ftCrypto.TransferKey, error) { obj, err := kv.Get(cypherManagerKeyStoreKey, cypherManagerKeyStoreVersion) if err != nil { return nil, err diff --git a/fileTransfer/store/cypher/manager_test.go b/fileTransfer/store/cypher/manager_test.go index ad0f68b2f40cbf8d5a2254216f474aef12feca86..ddab2942fa713a8a882f3607417afffc927db7ae 100644 --- a/fileTransfer/store/cypher/manager_test.go +++ b/fileTransfer/store/cypher/manager_test.go @@ -9,14 +9,15 @@ package cypher import ( "fmt" + "reflect" + "testing" + "github.com/stretchr/testify/require" "gitlab.com/elixxir/client/v4/storage/utility" "gitlab.com/elixxir/client/v4/storage/versioned" ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/crypto/csprng" - "reflect" - "testing" ) // Tests that NewManager returns a new Manager that matches the expected @@ -160,7 +161,7 @@ func Test_saveKey_loadKey(t *testing.T) { } // newTestManager creates a new Manager for testing. -func newTestManager(numFps uint16, t *testing.T) (*Manager, *versioned.KV) { +func newTestManager(numFps uint16, t *testing.T) (*Manager, versioned.KV) { key, err := ftCrypto.NewTransferKey(csprng.NewSystemRNG()) if err != nil { t.Errorf("Failed to generate transfer key: %+v", err) diff --git a/fileTransfer/store/received.go b/fileTransfer/store/received.go index 02b0431b01ad0134b2df4d80304dd04d2d838cc8..b252f90818f5a95fea68b60bc909a4f3a0d047a2 100644 --- a/fileTransfer/store/received.go +++ b/fileTransfer/store/received.go @@ -42,13 +42,13 @@ type Received struct { transfers map[ftCrypto.TransferID]*ReceivedTransfer mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // NewOrLoadReceived attempts to load a Received from storage. Or if none exist, // then a new Received is returned. Also returns a list of all transfers that // have unreceived file parts so their fingerprints can be re-added. -func NewOrLoadReceived(kv *versioned.KV) (*Received, []*ReceivedTransfer, error) { +func NewOrLoadReceived(kv versioned.KV) (*Received, []*ReceivedTransfer, error) { kv, err := kv.Prefix(receivedTransfersStorePrefix) if err != nil { return nil, nil, err diff --git a/fileTransfer/store/receivedTransfer.go b/fileTransfer/store/receivedTransfer.go index 8d6033771d629fe19626edb8dc396d72a1dc70db..868e3deee2157a6d293515a9974957aef8061d26 100644 --- a/fileTransfer/store/receivedTransfer.go +++ b/fileTransfer/store/receivedTransfer.go @@ -11,6 +11,9 @@ import ( "bytes" "encoding/base64" "encoding/json" + "strconv" + "sync" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/fileTransfer/store/cypher" @@ -18,8 +21,6 @@ import ( "gitlab.com/elixxir/client/v4/storage/versioned" ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" "gitlab.com/xx_network/primitives/netTime" - "strconv" - "sync" ) // Storage keys and versions. @@ -90,14 +91,14 @@ type ReceivedTransfer struct { lastCallbackFingerprint string mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // newReceivedTransfer generates a ReceivedTransfer with the specified transfer // key, transfer ID, and a number of parts. func newReceivedTransfer(key *ftCrypto.TransferKey, tid *ftCrypto.TransferID, fileName string, transferMAC []byte, fileSize uint32, numParts, - numFps uint16, kv *versioned.KV) (*ReceivedTransfer, error) { + numFps uint16, kv versioned.KV) (*ReceivedTransfer, error) { kv, err := kv.Prefix(makeReceivedTransferPrefix(tid)) if err != nil { return nil, err @@ -246,7 +247,7 @@ func generateReceivedFp(completed bool, received, total uint16, err error) strin // loadReceivedTransfer loads the ReceivedTransfer with the given transfer ID // from storage. -func loadReceivedTransfer(tid *ftCrypto.TransferID, kv *versioned.KV) ( +func loadReceivedTransfer(tid *ftCrypto.TransferID, kv versioned.KV) ( *ReceivedTransfer, error) { kv, err := kv.Prefix(makeReceivedTransferPrefix(tid)) if err != nil { @@ -384,7 +385,7 @@ func unmarshalReceivedTransfer(data []byte) (fileName string, } // savePart saves the given part to storage keying on its part number. -func savePart(part []byte, partNum int, kv *versioned.KV) error { +func savePart(part []byte, partNum int, kv versioned.KV) error { obj := &versioned.Object{ Version: receivedPartStoreVersion, Timestamp: netTime.Now(), @@ -395,7 +396,7 @@ func savePart(part []byte, partNum int, kv *versioned.KV) error { } // loadPart loads the part with the given part number from storage. -func loadPart(partNum int, kv *versioned.KV) ([]byte, error) { +func loadPart(partNum int, kv versioned.KV) ([]byte, error) { obj, err := kv.Get(makeReceivedPartKey(partNum), receivedPartStoreVersion) if err != nil { return nil, err diff --git a/fileTransfer/store/receivedTransfer_test.go b/fileTransfer/store/receivedTransfer_test.go index 13b5ca71fd140a2b2e6876d62674bedafc2c3c3f..92baa70be594141a743c1b82dc68a75a17ade1ea 100644 --- a/fileTransfer/store/receivedTransfer_test.go +++ b/fileTransfer/store/receivedTransfer_test.go @@ -10,6 +10,9 @@ package store import ( "bytes" "fmt" + "reflect" + "testing" + "github.com/stretchr/testify/require" "gitlab.com/elixxir/client/v4/fileTransfer/store/cypher" "gitlab.com/elixxir/client/v4/storage/utility" @@ -17,8 +20,6 @@ import ( ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/crypto/csprng" - "reflect" - "testing" ) // Tests that newReceivedTransfer returns a new ReceivedTransfer with the @@ -333,7 +334,7 @@ func TestReceivedTransfer_save(t *testing.T) { // newTestReceivedTransfer creates a new ReceivedTransfer for testing. func newTestReceivedTransfer(numParts uint16, t *testing.T) ( rt *ReceivedTransfer, file []byte, key *ftCrypto.TransferKey, - numFps uint16, kv *versioned.KV) { + numFps uint16, kv versioned.KV) { kv = versioned.NewKV(ekv.MakeMemstore()) keyTmp, _ := ftCrypto.NewTransferKey(csprng.NewSystemRNG()) tid, _ := ftCrypto.NewTransferID(csprng.NewSystemRNG()) diff --git a/fileTransfer/store/sent.go b/fileTransfer/store/sent.go index 8f449da79bfb92b0f37cd4a3e1f7f16e3435578d..f3f7d3395b6d3dc630e643e0d2a4ff6148f492d0 100644 --- a/fileTransfer/store/sent.go +++ b/fileTransfer/store/sent.go @@ -9,13 +9,14 @@ package store import ( "encoding/json" + "sync" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "sync" ) // Storage keys and versions. @@ -43,13 +44,13 @@ type Sent struct { transfers map[ftCrypto.TransferID]*SentTransfer mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // NewOrLoadSent attempts to load Sent from storage. Or if none exist, then a // new Sent is returned. If running transfers were loaded from storage, a list // of unsent parts is returned. -func NewOrLoadSent(kv *versioned.KV) (*Sent, []Part, error) { +func NewOrLoadSent(kv versioned.KV) (*Sent, []Part, error) { kv, err := kv.Prefix(sentTransfersStorePrefix) if err != nil { return nil, nil, err diff --git a/fileTransfer/store/sentTransfer.go b/fileTransfer/store/sentTransfer.go index d023c939e36bf495c6fedd3b77585f911e25415c..b398b769067256e67d2b35dbe91ba597e68bd177 100644 --- a/fileTransfer/store/sentTransfer.go +++ b/fileTransfer/store/sentTransfer.go @@ -10,6 +10,9 @@ package store import ( "encoding/base64" "encoding/json" + "strconv" + "sync" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/fileTransfer/store/cypher" @@ -18,8 +21,6 @@ import ( ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "strconv" - "sync" ) // Storage keys and versions. @@ -89,14 +90,14 @@ type SentTransfer struct { lastCallbackFingerprint string mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // newSentTransfer generates a new SentTransfer with the specified transfer key, // transfer ID, and parts. func newSentTransfer(recipient *id.ID, key *ftCrypto.TransferKey, tid *ftCrypto.TransferID, fileName string, fileSize uint32, parts [][]byte, - numFps uint16, kv *versioned.KV) (*SentTransfer, error) { + numFps uint16, kv versioned.KV) (*SentTransfer, error) { kv, err := kv.Prefix(makeSentTransferPrefix(tid)) if err != nil { return nil, err @@ -258,7 +259,7 @@ func generateSentFp(completed bool, arrived, total uint16, err error) string { // loadSentTransfer loads the SentTransfer with the given transfer ID from // storage. -func loadSentTransfer(tid *ftCrypto.TransferID, kv *versioned.KV) ( +func loadSentTransfer(tid *ftCrypto.TransferID, kv versioned.KV) ( *SentTransfer, error) { kv, err := kv.Prefix(makeSentTransferPrefix(tid)) if err != nil { diff --git a/fileTransfer/store/sentTransfer_test.go b/fileTransfer/store/sentTransfer_test.go index 178b6a909572e356d0646901792c07af111b58e5..43251aa97ed7b1b24d6a3957a58a05198d28bd6b 100644 --- a/fileTransfer/store/sentTransfer_test.go +++ b/fileTransfer/store/sentTransfer_test.go @@ -452,7 +452,7 @@ const numPrimeBytes = 512 // newTestSentTransfer creates a new SentTransfer for testing. func newTestSentTransfer(numParts uint16, t *testing.T) (st *SentTransfer, - parts [][]byte, key *ftCrypto.TransferKey, numFps uint16, kv *versioned.KV) { + parts [][]byte, key *ftCrypto.TransferKey, numFps uint16, kv versioned.KV) { kv = versioned.NewKV(ekv.MakeMemstore()) recipient := id.NewIdFromString("recipient", id.User, t) keyTmp, _ := ftCrypto.NewTransferKey(csprng.NewSystemRNG()) diff --git a/fileTransfer/utils_test.go b/fileTransfer/utils_test.go index 9c1c2f700871dcfe366fb8b79c4274efb2427654..a726a7c616bc918c1b61bb9a2e6461d54287cf80 100644 --- a/fileTransfer/utils_test.go +++ b/fileTransfer/utils_test.go @@ -291,7 +291,7 @@ func (m *mockCmix) ChangeNumberOfNodeRegistrations(toRun int, timeout time.Durat //////////////////////////////////////////////////////////////////////////////// type mockStorage struct { - kv *versioned.KV + kv versioned.KV cmixGroup *cyclic.Group } @@ -311,7 +311,7 @@ func (m *mockStorage) GetClientVersion() version.Version { panic("implement func (m *mockStorage) Get(string) (*versioned.Object, error) { panic("implement me") } func (m *mockStorage) Set(string, *versioned.Object) error { panic("implement me") } func (m *mockStorage) Delete(string) error { panic("implement me") } -func (m *mockStorage) GetKV() *versioned.KV { return m.kv } +func (m *mockStorage) GetKV() versioned.KV { return m.kv } func (m *mockStorage) GetCmixGroup() *cyclic.Group { return m.cmixGroup } func (m *mockStorage) GetE2EGroup() *cyclic.Group { panic("implement me") } func (m *mockStorage) ForwardRegistrationStatus(storage.RegistrationStatus) error { diff --git a/groupChat/groupStore/group.go b/groupChat/groupStore/group.go index ed8c3d0292a7374cae42318460759639e901881a..4d551f7fa6967b671f40fa89b252cdeaf7dab176 100644 --- a/groupChat/groupStore/group.go +++ b/groupChat/groupStore/group.go @@ -11,14 +11,15 @@ import ( "bytes" "encoding/binary" "fmt" + "strings" + "time" + "github.com/pkg/errors" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/group" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "strings" - "time" ) // Storage values. @@ -98,7 +99,7 @@ func (g Group) DeepCopy() Group { } // store saves an individual Group to storage keying on the group ID. -func (g Group) store(kv *versioned.KV) error { +func (g Group) store(kv versioned.KV) error { obj := &versioned.Object{ Version: groupStoreVersion, Timestamp: netTime.Now(), @@ -109,7 +110,7 @@ func (g Group) store(kv *versioned.KV) error { } // loadGroup returns the group with the corresponding ID from storage. -func loadGroup(groupID *id.ID, kv *versioned.KV) (Group, error) { +func loadGroup(groupID *id.ID, kv versioned.KV) (Group, error) { obj, err := kv.Get(groupStoreKey(groupID), groupStoreVersion) if err != nil { return Group{}, errors.Errorf(kvGetGroupErr, groupID, err) @@ -119,7 +120,7 @@ func loadGroup(groupID *id.ID, kv *versioned.KV) (Group, error) { } // removeGroup deletes the given group from storage. -func removeGroup(groupID *id.ID, kv *versioned.KV) error { +func removeGroup(groupID *id.ID, kv versioned.KV) error { return kv.Delete(groupStoreKey(groupID), groupStoreVersion) } diff --git a/groupChat/groupStore/store.go b/groupChat/groupStore/store.go index 8305b29fa49d8abf8fc00f2a209b95a2c313763c..25923f0946b5e18dfbf59961ff9bdb1183ddf9ff 100644 --- a/groupChat/groupStore/store.go +++ b/groupChat/groupStore/store.go @@ -9,6 +9,9 @@ package groupStore import ( "bytes" + "sync" + "testing" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" @@ -16,8 +19,6 @@ import ( "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "sync" - "testing" ) // Storage values. @@ -48,12 +49,12 @@ const MaxGroupChats = 64 type Store struct { list map[id.ID]Group user group.Member - kv *versioned.KV + kv versioned.KV mux sync.RWMutex } // NewStore constructs a new Store object for the user and saves it to storage. -func NewStore(kv *versioned.KV, user group.Member) (*Store, error) { +func NewStore(kv versioned.KV, user group.Member) (*Store, error) { kv, err := kv.Prefix(groupStoragePrefix) if err != nil { return nil, err @@ -69,7 +70,7 @@ func NewStore(kv *versioned.KV, user group.Member) (*Store, error) { // NewOrLoadStore loads the group store from storage or makes a new one if it // does not exist. -func NewOrLoadStore(kv *versioned.KV, user group.Member) (*Store, error) { +func NewOrLoadStore(kv versioned.KV, user group.Member) (*Store, error) { prefixKv, err := kv.Prefix(groupStoragePrefix) if err != nil { return nil, err @@ -87,7 +88,7 @@ func NewOrLoadStore(kv *versioned.KV, user group.Member) (*Store, error) { // LoadStore loads all the Groups from storage into memory and return them in // a Store object. -func LoadStore(kv *versioned.KV, user group.Member) (*Store, error) { +func LoadStore(kv versioned.KV, user group.Member) (*Store, error) { kv, err := kv.Prefix(groupStoragePrefix) if err != nil { return nil, err @@ -103,7 +104,7 @@ func LoadStore(kv *versioned.KV, user group.Member) (*Store, error) { } // loadStore builds the list of group IDs and loads the groups from storage. -func loadStore(data []byte, kv *versioned.KV, user group.Member) (*Store, error) { +func loadStore(data []byte, kv versioned.KV, user group.Member) (*Store, error) { // Deserialize list of group IDs groupIDs := deserializeGroupIdList(data) diff --git a/groupChat/messenger_test.go b/groupChat/messenger_test.go index f65e7aba27c744427a5ae21b474fb064a22e98fd..7fd78bb97984a2a774636a2c1f13697f7491b10b 100644 --- a/groupChat/messenger_test.go +++ b/groupChat/messenger_test.go @@ -32,7 +32,7 @@ type mockE2e struct { storage storage.Session } -func newMockE2e(t testing.TB, kv *versioned.KV) groupE2e { +func newMockE2e(t testing.TB, kv versioned.KV) groupE2e { receptionId := id.NewIdFromString("test", id.User, t) mockCmix := newTestNetworkManager(0) prng := rand.New(rand.NewSource(42)) diff --git a/groupChat/session_test.go b/groupChat/session_test.go index b3a5ce529ff5e1023990c33a9460fb44f0c15d34..5d8e485a38619862135f8d81e6400b8db2a5c8f1 100644 --- a/groupChat/session_test.go +++ b/groupChat/session_test.go @@ -22,10 +22,10 @@ import ( // mockSession is a storage.Session implementation for testing. type mockSession struct { - kv *versioned.KV + kv versioned.KV } -func newMockSesion(kv *versioned.KV) storage.Session { +func newMockSesion(kv versioned.KV) storage.Session { return mockSession{kv: kv} } @@ -33,7 +33,7 @@ func (m mockSession) GetE2EGroup() *cyclic.Group { return getGroup() } -func (m mockSession) GetKV() *versioned.KV { +func (m mockSession) GetKV() versioned.KV { if m.kv != nil { return m.kv } diff --git a/storage/clientVersion/store.go b/storage/clientVersion/store.go index bf8cd1666729115fa102935c207e4eb3ff35b180..edc0e4da0bce5999a4a45419b17c80a9573e8f43 100644 --- a/storage/clientVersion/store.go +++ b/storage/clientVersion/store.go @@ -8,12 +8,13 @@ package clientVersion import ( + "sync" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/elixxir/primitives/version" "gitlab.com/xx_network/primitives/netTime" - "sync" ) const ( @@ -25,12 +26,12 @@ const ( // Store stores the version of the client's storage. type Store struct { version version.Version - kv *versioned.KV + kv versioned.KV sync.RWMutex } // NewStore returns a new clientVersion store. -func NewStore(newVersion version.Version, kv *versioned.KV) (*Store, error) { +func NewStore(newVersion version.Version, kv versioned.KV) (*Store, error) { kv, err := kv.Prefix(prefix) if err != nil { return nil, err @@ -44,7 +45,7 @@ func NewStore(newVersion version.Version, kv *versioned.KV) (*Store, error) { } // LoadStore loads the clientVersion storage object. -func LoadStore(kv *versioned.KV) (*Store, error) { +func LoadStore(kv versioned.KV) (*Store, error) { kv, err := kv.Prefix(prefix) if err != nil { return nil, err diff --git a/storage/session.go b/storage/session.go index df641ad2906a9279cfd061ee0c658221f876e71f..99b67b655e1a4e9215ea9db14adaf1aa7d141c0c 100644 --- a/storage/session.go +++ b/storage/session.go @@ -46,7 +46,7 @@ type Session interface { Get(key string) (*versioned.Object, error) Set(key string, object *versioned.Object) error Delete(key string) error - GetKV() *versioned.KV + GetKV() versioned.KV GetCmixGroup() *cyclic.Group GetE2EGroup() *cyclic.Group ForwardRegistrationStatus(regStatus RegistrationStatus) error @@ -74,7 +74,7 @@ type Session interface { } type session struct { - kv *versioned.KV + kv versioned.KV // memoized data mux sync.RWMutex @@ -207,7 +207,7 @@ func (s *session) Delete(key string) error { } // GetKV returns the Session versioned.KV. -func (s *session) GetKV() *versioned.KV { +func (s *session) GetKV() versioned.KV { return s.kv } diff --git a/storage/user/cryptographic.go b/storage/user/cryptographic.go index 90d26c1310fc311e28fd0d64a61aed8e7a54e157..ade79f20e359fb2d39ce63d7f4676c126476422d 100644 --- a/storage/user/cryptographic.go +++ b/storage/user/cryptographic.go @@ -11,6 +11,7 @@ import ( "bytes" "encoding/gob" "encoding/json" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/utility" @@ -64,7 +65,7 @@ func newCryptographicIdentity(transmissionID, receptionID *id.ID, transmissionSalt, receptionSalt []byte, transmissionRsa, receptionRsa rsa.PrivateKey, isPrecanned bool, e2eDhPrivateKey, e2eDhPublicKey *cyclic.Int, - kv *versioned.KV) *CryptographicIdentity { + kv versioned.KV) *CryptographicIdentity { ci := &CryptographicIdentity{ transmissionID: transmissionID, @@ -87,7 +88,7 @@ func newCryptographicIdentity(transmissionID, receptionID *id.ID, } // loadOriginalCryptographicIdentity attempts to load the originalCryptographicIdentityVersion CryptographicIdentity -func loadOriginalCryptographicIdentity(kv *versioned.KV) (*CryptographicIdentity, error) { +func loadOriginalCryptographicIdentity(kv versioned.KV) (*CryptographicIdentity, error) { result := &CryptographicIdentity{} obj, err := kv.Get(cryptographicIdentityKey, originalCryptographicIdentityVersion) if err != nil { @@ -116,7 +117,7 @@ func loadOriginalCryptographicIdentity(kv *versioned.KV) (*CryptographicIdentity return result, nil } -func loadCryptographicIdentity(kv *versioned.KV) (*CryptographicIdentity, error) { +func loadCryptographicIdentity(kv versioned.KV) (*CryptographicIdentity, error) { result := &CryptographicIdentity{} obj, err := kv.Get(cryptographicIdentityKey, currentCryptographicIdentityVersion) @@ -165,7 +166,7 @@ func loadCryptographicIdentity(kv *versioned.KV) (*CryptographicIdentity, error) // loadLegacyDHKeys attempts to load DH Keys from legacy storage. It // prints a warning to the log as users should be using ReceptionIdentity // instead of PortableUserInfo -func loadLegacyDHKeys(kv *versioned.KV) (pub, priv *cyclic.Int) { +func loadLegacyDHKeys(kv versioned.KV) (pub, priv *cyclic.Int) { // Legacy package prefixes and keys, see e2e/ratchet/storage.go packagePrefix := "e2eSession" pubKeyKey := "DhPubKey" @@ -192,7 +193,7 @@ func loadLegacyDHKeys(kv *versioned.KV) (pub, priv *cyclic.Int) { return pubKey, privKey } -func (ci *CryptographicIdentity) save(kv *versioned.KV) error { +func (ci *CryptographicIdentity) save(kv versioned.KV) error { dhPriv, err := ci.e2eDhPrivateKey.MarshalJSON() if err != nil { return err diff --git a/storage/user/user.go b/storage/user/user.go index d26e29781c9d9f1851c0c30024fd4f4cf54c7484..235905983f209930bbf68ac132efe8dcdf83d745 100644 --- a/storage/user/user.go +++ b/storage/user/user.go @@ -8,13 +8,14 @@ package user import ( + "sync" + "time" + "github.com/pkg/errors" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/rsa" "gitlab.com/xx_network/primitives/id" - "sync" - "time" ) type User struct { @@ -29,11 +30,11 @@ type User struct { username string usernameMux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // builds a new user. -func NewUser(kv *versioned.KV, transmissionID, receptionID *id.ID, transmissionSalt, +func NewUser(kv versioned.KV, transmissionID, receptionID *id.ID, transmissionSalt, receptionSalt []byte, transmissionRsa, receptionRsa rsa.PrivateKey, isPrecanned bool, e2eDhPrivateKey, e2eDhPublicKey *cyclic.Int) (*User, error) { @@ -43,7 +44,7 @@ func NewUser(kv *versioned.KV, transmissionID, receptionID *id.ID, transmissionS return &User{CryptographicIdentity: ci, kv: kv}, nil } -func LoadUser(kv *versioned.KV) (*User, error) { +func LoadUser(kv versioned.KV) (*User, error) { ci, err := loadCryptographicIdentity(kv) if err != nil { return nil, errors.WithMessage(err, "Failed to load user "+ diff --git a/storage/utility/NDF.go b/storage/utility/NDF.go index d53cf49118c349a5e57b5487c660f7070310d3ff..7830e9c146f67d3ee97a8213a3d512f16660bd8e 100644 --- a/storage/utility/NDF.go +++ b/storage/utility/NDF.go @@ -18,7 +18,7 @@ import ( const currentNDFVersion = 0 -func LoadNDF(kv *versioned.KV, key string) (*ndf.NetworkDefinition, error) { +func LoadNDF(kv versioned.KV, key string) (*ndf.NetworkDefinition, error) { vo, err := kv.Get(key, currentNDFVersion) if err != nil { return nil, err @@ -32,7 +32,7 @@ func LoadNDF(kv *versioned.KV, key string) (*ndf.NetworkDefinition, error) { return netDef, err } -func SaveNDF(kv *versioned.KV, key string, ndf *ndf.NetworkDefinition) error { +func SaveNDF(kv versioned.KV, key string, ndf *ndf.NetworkDefinition) error { marshaled, err := ndf.Marshal() if err != nil { return err diff --git a/storage/utility/NDF_js.go b/storage/utility/NDF_js.go index 05d5eb885575fad7bb96f7e561d42660f7b2f494..93ae38d8fc55b019125676c4e1c0d800ec084540 100644 --- a/storage/utility/NDF_js.go +++ b/storage/utility/NDF_js.go @@ -18,7 +18,7 @@ const NdfStorageKeyNamePrefix = "ndfStorageKey/" var localStorage = js.Global().Get("localStorage") -func LoadNDF(_ *versioned.KV, key string) (*ndf.NetworkDefinition, error) { +func LoadNDF(_ versioned.KV, key string) (*ndf.NetworkDefinition, error) { keyValue := localStorage.Call("getItem", NdfStorageKeyNamePrefix+key) if keyValue.IsNull() { return nil, os.ErrNotExist @@ -27,7 +27,7 @@ func LoadNDF(_ *versioned.KV, key string) (*ndf.NetworkDefinition, error) { return ndf.Unmarshal([]byte(keyValue.String())) } -func SaveNDF(_ *versioned.KV, key string, ndf *ndf.NetworkDefinition) error { +func SaveNDF(_ versioned.KV, key string, ndf *ndf.NetworkDefinition) error { marshaled, err := ndf.Marshal() if err != nil { return err diff --git a/storage/utility/blockStore.go b/storage/utility/blockStore.go index 3683e5178bbc3ec94a2b641325a519ea2b510c26..9665917af61fcb6f3234f7504462d8200a3bce60 100644 --- a/storage/utility/blockStore.go +++ b/storage/utility/blockStore.go @@ -11,11 +11,12 @@ import ( "bytes" "encoding/binary" "encoding/json" + "strconv" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/netTime" - "strconv" ) // Sizes in bytes @@ -57,11 +58,11 @@ type BlockStore struct { blockSize int // The maximum number of items allowed in a block firstSaved int // The index of the oldest block in the list lastSaved int // The index of the newest block in the list - kv *versioned.KV + kv versioned.KV } // NewBlockStore returns a new BlockStore and saves it to storage. -func NewBlockStore(numBlocks, blockSize int, kv *versioned.KV) (*BlockStore, error) { +func NewBlockStore(numBlocks, blockSize int, kv versioned.KV) (*BlockStore, error) { bs := &BlockStore{ block: make([][]byte, 0, blockSize), numBlocks: numBlocks, @@ -76,7 +77,7 @@ func NewBlockStore(numBlocks, blockSize int, kv *versioned.KV) (*BlockStore, err // LoadBlockStore returns the BlockStore from storage and a concatenation of all // blocks in storage. -func LoadBlockStore(kv *versioned.KV) (*BlockStore, [][]byte, error) { +func LoadBlockStore(kv versioned.KV) (*BlockStore, [][]byte, error) { bs := &BlockStore{kv: kv} // get BlockStore parameters from storage diff --git a/storage/utility/bucket.go b/storage/utility/bucket.go index 93eba68d609c609bdeb6a793c5a03b178721a1d1..05b1da34d3230d86fab5c2e5d87e91234c0a09fb 100644 --- a/storage/utility/bucket.go +++ b/storage/utility/bucket.go @@ -9,11 +9,12 @@ package utility import ( "encoding/json" + "time" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/rateLimiting" - "time" ) const ( @@ -25,7 +26,7 @@ const ( // BucketStore stores a leaky bucket into storage. The bucket // is saved in a JSON-able format. type BucketStore struct { - kv *versioned.KV + kv versioned.KV } // bucketDisk is a JSON-able structure used to store @@ -37,7 +38,7 @@ type bucketDisk struct { // NewStoredBucket creates a new, empty Bucket and saves it to storage. func NewStoredBucket(capacity, leaked uint32, leakDuration time.Duration, - kv *versioned.KV) *rateLimiting.Bucket { + kv versioned.KV) *rateLimiting.Bucket { kv, err := kv.Prefix(bucketStorePrefix) if err != nil { jww.FATAL.Panicf("Failed to prefix KV with %s: %+v", bucketStorePrefix, err) @@ -86,7 +87,7 @@ func (s *BucketStore) save(inBucket uint32, timestamp int64) { // LoadBucket is a storage operation which loads a bucket from storage. func LoadBucket(capacity, leaked uint32, leakDuration time.Duration, - kv *versioned.KV) (*rateLimiting.Bucket, error) { + kv versioned.KV) (*rateLimiting.Bucket, error) { kv, err := kv.Prefix(bucketStorePrefix) if err != nil { jww.FATAL.Panicf("Failed to prefix KV with %s: %+v", bucketStorePrefix, err) diff --git a/storage/utility/bucketParams.go b/storage/utility/bucketParams.go index af2821107f51319edb4d75254ed8ea64d5c8e417..e518f45ed4e161471fa766bd465940d984b99972 100644 --- a/storage/utility/bucketParams.go +++ b/storage/utility/bucketParams.go @@ -10,13 +10,14 @@ package utility import ( "bytes" "encoding/binary" + "sync" + "time" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/rateLimiting" - "sync" - "time" ) const ( @@ -30,12 +31,12 @@ const ( type BucketParamStore struct { params *rateLimiting.MapParams mux sync.RWMutex - kv *versioned.KV + kv versioned.KV } // NewBucketParamsStore is the constructor for a BucketParamStore. func NewBucketParamsStore(capacity, leakedTokens uint32, - leakDuration time.Duration, kv *versioned.KV) (*BucketParamStore, error) { + leakDuration time.Duration, kv versioned.KV) (*BucketParamStore, error) { kv, err := kv.Prefix(bucketParamsPrefix) if err != nil { @@ -83,7 +84,7 @@ func (s *BucketParamStore) UpdateParams(capacity, leakedTokens uint32, // LoadBucketParamsStore loads the bucket params data from storage and constructs // a BucketParamStore. -func LoadBucketParamsStore(kv *versioned.KV) (*BucketParamStore, error) { +func LoadBucketParamsStore(kv versioned.KV) (*BucketParamStore, error) { kv, err := kv.Prefix(bucketParamsPrefix) if err != nil { diff --git a/storage/utility/contact.go b/storage/utility/contact.go index f67443f208a02494c98423b07aebeec1b65e79d8..f7fefe1b7aa56c9b4b64892326b33b0c8bb7e9e3 100644 --- a/storage/utility/contact.go +++ b/storage/utility/contact.go @@ -22,11 +22,12 @@ const currentContactVersion = 0 // contact ID as the key. // // Parameters: -// * kv - the key value store to write the contact. -// * c - the contact object to store. +// - kv - the key value store to write the contact. +// - c - the contact object to store. +// // Returns: -// * error if the write fails to succeed for any reason. -func StoreContact(kv *versioned.KV, c contact.Contact) error { +// - error if the write fails to succeed for any reason. +func StoreContact(kv versioned.KV, c contact.Contact) error { now := netTime.Now() obj := versioned.Object{ @@ -41,13 +42,14 @@ func StoreContact(kv *versioned.KV, c contact.Contact) error { // LoadContact reads a contact from a versioned.KV vie their contact ID. // // Parameters: -// * kv - the key value store to read the contact -// * cid - the contacts unique *id.ID to load +// - kv - the key value store to read the contact +// - cid - the contacts unique *id.ID to load +// // Returns: -// * contact.Contact object populated with the user info, or empty on error. -// * version number of the contact loaded. -// * error if an error occurs, or nil otherwise -func LoadContact(kv *versioned.KV, cid *id.ID) (contact.Contact, error) { +// - contact.Contact object populated with the user info, or empty on error. +// - version number of the contact loaded. +// - error if an error occurs, or nil otherwise +func LoadContact(kv versioned.KV, cid *id.ID) (contact.Contact, error) { vo, err := kv.Get(makeContactKey(cid), currentContactVersion) if err != nil { return contact.Contact{}, err @@ -61,9 +63,10 @@ func LoadContact(kv *versioned.KV, cid *id.ID) (contact.Contact, error) { // Parameters: // - kv - the key value store to delete from // - cid - the contacts unique *id.ID to delete +// // Returns: // - error if an error occurs or nil otherwise -func DeleteContact(kv *versioned.KV, cid *id.ID) error { +func DeleteContact(kv versioned.KV, cid *id.ID) error { return kv.Delete(makeContactKey(cid), currentContactVersion) } diff --git a/storage/utility/dh.go b/storage/utility/dh.go index a3f05b2d74779d33482b10d07f68de42fb2ba051..403e8f1335c2191fc2f25318b2ac8c4078e941cb 100644 --- a/storage/utility/dh.go +++ b/storage/utility/dh.go @@ -15,7 +15,7 @@ import ( const currentCyclicVersion = 0 -func StoreCyclicKey(kv *versioned.KV, cy *cyclic.Int, key string) error { +func StoreCyclicKey(kv versioned.KV, cy *cyclic.Int, key string) error { now := netTime.Now() data, err := cy.GobEncode() @@ -32,7 +32,7 @@ func StoreCyclicKey(kv *versioned.KV, cy *cyclic.Int, key string) error { return kv.Set(key, &obj) } -func LoadCyclicKey(kv *versioned.KV, key string) (*cyclic.Int, error) { +func LoadCyclicKey(kv versioned.KV, key string) (*cyclic.Int, error) { vo, err := kv.Get(key, currentCyclicVersion) if err != nil { return nil, err @@ -44,6 +44,6 @@ func LoadCyclicKey(kv *versioned.KV, key string) (*cyclic.Int, error) { } // DeleteCyclicKey deletes a given cyclic key from storage -func DeleteCyclicKey(kv *versioned.KV, key string) error { +func DeleteCyclicKey(kv versioned.KV, key string) error { return kv.Delete(key, currentCyclicVersion) } diff --git a/storage/utility/encryptionSalt.go b/storage/utility/encryptionSalt.go index e34d0f6dedda2d99b76af761cc9e68f1c747cbbd..c0c7c0accaabae59169e0cb60e3cee7477cba3b0 100644 --- a/storage/utility/encryptionSalt.go +++ b/storage/utility/encryptionSalt.go @@ -1,10 +1,11 @@ package utility import ( + "io" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/netTime" - "io" ) // Storage constats @@ -21,7 +22,7 @@ const saltSize = 32 // NewOrLoadSalt will attempt to find a stored salt if one exists. // If one does not exist in storage, a new one will be generated. The newly // generated salt will be stored. -func NewOrLoadSalt(kv *versioned.KV, stream io.Reader) ([]byte, error) { +func NewOrLoadSalt(kv versioned.KV, stream io.Reader) ([]byte, error) { kv, err := kv.Prefix(saltPrefix) if err != nil { return nil, err @@ -37,7 +38,7 @@ func NewOrLoadSalt(kv *versioned.KV, stream io.Reader) ([]byte, error) { // loadSalt is a helper function which attempts to load a stored salt from // memory. -func loadSalt(kv *versioned.KV) ([]byte, error) { +func loadSalt(kv versioned.KV) ([]byte, error) { obj, err := kv.Get(saltKey, saltVersion) if err != nil { return nil, err @@ -48,7 +49,7 @@ func loadSalt(kv *versioned.KV) ([]byte, error) { // newSalt generates a new random salt. This salt is stored and returned // to the caller. -func newSalt(kv *versioned.KV, stream io.Reader) ([]byte, error) { +func newSalt(kv versioned.KV, stream io.Reader) ([]byte, error) { // Generate a new salt salt := make([]byte, saltSize) _, err := stream.Read(salt) diff --git a/storage/utility/group.go b/storage/utility/group.go index 19a157509007549e00e5c1a38d4ec306ecbe8631..1aeca4ee2c07ebf0f65a3bbf47f1fa6ba898f20e 100644 --- a/storage/utility/group.go +++ b/storage/utility/group.go @@ -15,7 +15,7 @@ import ( const currentGroupVersion = 0 -func StoreGroup(kv *versioned.KV, grp *cyclic.Group, key string) error { +func StoreGroup(kv versioned.KV, grp *cyclic.Group, key string) error { now := netTime.Now() data, err := grp.GobEncode() @@ -32,7 +32,7 @@ func StoreGroup(kv *versioned.KV, grp *cyclic.Group, key string) error { return kv.Set(key, &obj) } -func LoadGroup(kv *versioned.KV, key string) (*cyclic.Group, error) { +func LoadGroup(kv versioned.KV, key string) (*cyclic.Group, error) { vo, err := kv.Get(key, currentGroupVersion) if err != nil { return nil, err diff --git a/storage/utility/id.go b/storage/utility/id.go index 5e2168c7be17bc057a4bfc7d2b9e62f4d48bd6f3..0e1c2a8829269a9bb146535b3c3863d2833e8ce9 100644 --- a/storage/utility/id.go +++ b/storage/utility/id.go @@ -15,7 +15,7 @@ import ( const currentIDVersion = 0 -func StoreID(kv *versioned.KV, sid *id.ID, key string) error { +func StoreID(kv versioned.KV, sid *id.ID, key string) error { now := netTime.Now() data, err := sid.MarshalJSON() @@ -32,7 +32,7 @@ func StoreID(kv *versioned.KV, sid *id.ID, key string) error { return kv.Set(key, &obj) } -func LoadID(kv *versioned.KV, key string) (*id.ID, error) { +func LoadID(kv versioned.KV, key string) (*id.ID, error) { vo, err := kv.Get(key, currentIDVersion) if err != nil { return nil, err @@ -44,6 +44,6 @@ func LoadID(kv *versioned.KV, key string) (*id.ID, error) { } // DeleteCID deletes a given cyclic key from storage -func DeleteCID(kv *versioned.KV, key string) error { +func DeleteCID(kv versioned.KV, key string) error { return kv.Delete(key, currentIDVersion) } diff --git a/storage/utility/knownRounds.go b/storage/utility/knownRounds.go index d75d094c1e99e7e73781abf3eae89e799a30d8d1..4fe4547cf77df54465db53e471bf92afa46edb6c 100644 --- a/storage/utility/knownRounds.go +++ b/storage/utility/knownRounds.go @@ -19,7 +19,7 @@ const currentKnownRoundsVersion = 0 // the values can be recovered if something happens to the buffer in memory. type KnownRounds struct { rounds *knownRounds.KnownRounds - kv *versioned.KV + kv versioned.KV key string mux sync.RWMutex } @@ -27,7 +27,7 @@ type KnownRounds struct { // NewKnownRounds creates a new empty KnownRounds and saves it to the passed // in key value store at the specified key. An error is returned on an // unsuccessful save. -func NewKnownRounds(kv *versioned.KV, key string, known *knownRounds.KnownRounds) (*KnownRounds, error) { +func NewKnownRounds(kv versioned.KV, key string, known *knownRounds.KnownRounds) (*KnownRounds, error) { // Create new empty struct kr := &KnownRounds{ rounds: known, @@ -44,7 +44,7 @@ func NewKnownRounds(kv *versioned.KV, key string, known *knownRounds.KnownRounds // LoadKnownRounds loads and existing KnownRounds from the key value store // into memory at the given key. Returns an error if it cannot be loaded. -func LoadKnownRounds(kv *versioned.KV, key string, size int) (*KnownRounds, error) { +func LoadKnownRounds(kv versioned.KV, key string, size int) (*KnownRounds, error) { // Create new empty struct kr := &KnownRounds{ rounds: knownRounds.NewKnownRound(size), diff --git a/storage/utility/messageBuffer.go b/storage/utility/messageBuffer.go index 501a969c4c5c5429936ed0201e1b29f9632c8f74..b4c7f598a4e34c8486280842a99a1deb5295c362 100644 --- a/storage/utility/messageBuffer.go +++ b/storage/utility/messageBuffer.go @@ -37,15 +37,15 @@ const CurrentMessageBufferVersion = 0 type MessageHandler interface { // SaveMessage saves the message as a versioned object at the specified key // in the key value store. - SaveMessage(kv *versioned.KV, m interface{}, key string) error + SaveMessage(kv versioned.KV, m interface{}, key string) error // LoadMessage returns the message with the specified key from the key value // store. - LoadMessage(kv *versioned.KV, key string) (interface{}, error) + LoadMessage(kv versioned.KV, key string) (interface{}, error) // DeleteMessage deletes the message with the specified key from the key // value store. - DeleteMessage(kv *versioned.KV, key string) error + DeleteMessage(kv versioned.KV, key string) error // HashMessage generates a hash of the message. HashMessage(m interface{}) MessageHash @@ -60,7 +60,7 @@ type MessageHandler interface { type MessageBuffer struct { messages map[MessageHash]struct{} processingMessages map[MessageHash]struct{} - kv *versioned.KV + kv versioned.KV handler MessageHandler key string mux sync.RWMutex @@ -69,7 +69,7 @@ type MessageBuffer struct { // NewMessageBuffer creates a new empty buffer and saves it to the passed in key // value store at the specified key. An error is returned on an unsuccessful // save. -func NewMessageBuffer(kv *versioned.KV, handler MessageHandler, +func NewMessageBuffer(kv versioned.KV, handler MessageHandler, key string) (*MessageBuffer, error) { // Create new empty buffer mb := &MessageBuffer{ @@ -89,7 +89,7 @@ func NewMessageBuffer(kv *versioned.KV, handler MessageHandler, // LoadMessageBuffer loads an existing message buffer from the key value store // into memory at the given key. Returns an error if buffer cannot be loaded. -func LoadMessageBuffer(kv *versioned.KV, handler MessageHandler, +func LoadMessageBuffer(kv versioned.KV, handler MessageHandler, key string) (*MessageBuffer, error) { // Create new empty buffer mb := &MessageBuffer{ diff --git a/storage/utility/messageBuffer_test.go b/storage/utility/messageBuffer_test.go index 97fbe0c8035628c1854ee34db5e7fb70fad78054..02ac0e2f64bb9549e7c7cad8c501d6ab6062fcdf 100644 --- a/storage/utility/messageBuffer_test.go +++ b/storage/utility/messageBuffer_test.go @@ -24,13 +24,13 @@ type testHandler struct { messages map[string][]byte } -func (th *testHandler) SaveMessage(kv *versioned.KV, m interface{}, key string) error { +func (th *testHandler) SaveMessage(kv versioned.KV, m interface{}, key string) error { mBytes := m.([]byte) th.messages[key] = mBytes return nil } -func (th *testHandler) LoadMessage(kv *versioned.KV, key string) (interface{}, error) { +func (th *testHandler) LoadMessage(kv versioned.KV, key string) (interface{}, error) { m, ok := th.messages[key] if !ok { return nil, os.ErrNotExist @@ -38,7 +38,7 @@ func (th *testHandler) LoadMessage(kv *versioned.KV, key string) (interface{}, e return m, nil } -func (th *testHandler) DeleteMessage(kv *versioned.KV, key string) error { +func (th *testHandler) DeleteMessage(kv versioned.KV, key string) error { _, ok := th.messages[key] if !ok { return os.ErrNotExist diff --git a/storage/utility/multiStateVector.go b/storage/utility/multiStateVector.go index 8653625c236623cc3c3d0bb21914acc8d7dd682f..511117567b3689a2fc4f8b838ca1c31802c1ac97 100644 --- a/storage/utility/multiStateVector.go +++ b/storage/utility/multiStateVector.go @@ -10,11 +10,12 @@ package utility import ( "bytes" "encoding/binary" + "math" + "sync" + "github.com/pkg/errors" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/netTime" - "math" - "sync" ) // Storage key and version. @@ -96,14 +97,14 @@ type MultiStateVector struct { stateUseCount []uint16 key string // Unique string used to save/load object from storage - kv *versioned.KV + kv versioned.KV mux sync.RWMutex } // NewMultiStateVector generates a new MultiStateVector with the specified // number of keys and bits pr state per keys. The max number of states in 64. func NewMultiStateVector(numKeys uint16, numStates uint8, stateMap [][]bool, - key string, kv *versioned.KV) (*MultiStateVector, error) { + key string, kv versioned.KV) (*MultiStateVector, error) { // Return an error if the number of states is out of range if numStates < minNumStates { @@ -464,7 +465,7 @@ func shiftBitsIn(bits uint64, keyNum uint16, bitSize uint8) uint64 { // LoadMultiStateVector loads a MultiStateVector with the specified key from the // given versioned storage. -func LoadMultiStateVector(stateMap [][]bool, key string, kv *versioned.KV) ( +func LoadMultiStateVector(stateMap [][]bool, key string, kv versioned.KV) ( *MultiStateVector, error) { msv := &MultiStateVector{ stateMap: stateMap, diff --git a/storage/utility/multiStateVector_test.go b/storage/utility/multiStateVector_test.go index b8d69f3a8ed691cc8175c8454353b78dc21560f1..0e1c3f20e0b03219389355055251a89439bdb6e0 100644 --- a/storage/utility/multiStateVector_test.go +++ b/storage/utility/multiStateVector_test.go @@ -1025,7 +1025,7 @@ func Test_makeMultiStateVectorKey(t *testing.T) { // newTestFilledMSV produces a new MultiStateVector and sets each key to a // random state. func newTestFilledMSV(numKeys uint16, numStates uint8, stateMap [][]bool, - key string, t *testing.T) (*MultiStateVector, *versioned.KV) { + key string, t *testing.T) (*MultiStateVector, versioned.KV) { kv := versioned.NewKV(ekv.MakeMemstore()) msv, err := NewMultiStateVector(numKeys, numStates, stateMap, key, kv) diff --git a/storage/utility/sidh.go b/storage/utility/sidh.go index e82157e14e71e25e8335da5159c055326e757cc3..6e55b5b5e5f36a6160f6c0d0039ff779b7a2536e 100644 --- a/storage/utility/sidh.go +++ b/storage/utility/sidh.go @@ -10,13 +10,14 @@ package utility import ( "encoding/base64" "fmt" + "io" + "github.com/cloudflare/circl/dh/sidh" jww "github.com/spf13/jwalterweatherman" sidhinterface "gitlab.com/elixxir/client/v4/interfaces/sidh" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "io" ) const currentSIDHVersion = 0 @@ -80,7 +81,7 @@ const currentSIDHPubKeyVersion = 0 // StoreSIDHPubKeyA is a helper to store the requestor public key (which is // always of type A) -func StoreSIDHPublicKey(kv *versioned.KV, sidH *sidh.PublicKey, key string) error { +func StoreSIDHPublicKey(kv versioned.KV, sidH *sidh.PublicKey, key string) error { now := netTime.Now() sidHBytes := make([]byte, sidH.Size()+1) @@ -97,7 +98,7 @@ func StoreSIDHPublicKey(kv *versioned.KV, sidH *sidh.PublicKey, key string) erro } // LoadSIDHPubKeyA loads a public key from storage. -func LoadSIDHPublicKey(kv *versioned.KV, key string) (*sidh.PublicKey, error) { +func LoadSIDHPublicKey(kv versioned.KV, key string) (*sidh.PublicKey, error) { vo, err := kv.Get(key, currentSIDHPubKeyVersion) if err != nil { return nil, err @@ -109,7 +110,7 @@ func LoadSIDHPublicKey(kv *versioned.KV, key string) (*sidh.PublicKey, error) { } // DeleteSIDHPubKey removes the key from the store -func DeleteSIDHPublicKey(kv *versioned.KV, key string) error { +func DeleteSIDHPublicKey(kv versioned.KV, key string) error { return kv.Delete(key, currentSIDHPubKeyVersion) } @@ -125,7 +126,7 @@ const currentSIDHPrivKeyVersion = 0 // StoreSIDHPrivateKeyA is a helper to store the requestor public key (which is // always of type A) -func StoreSIDHPrivateKey(kv *versioned.KV, sidH *sidh.PrivateKey, key string) error { +func StoreSIDHPrivateKey(kv versioned.KV, sidH *sidh.PrivateKey, key string) error { now := netTime.Now() sidHBytes := make([]byte, sidH.Size()+1) @@ -142,7 +143,7 @@ func StoreSIDHPrivateKey(kv *versioned.KV, sidH *sidh.PrivateKey, key string) er } // LoadSIDHPrivateKeyA loads a public key from storage. -func LoadSIDHPrivateKey(kv *versioned.KV, key string) (*sidh.PrivateKey, error) { +func LoadSIDHPrivateKey(kv versioned.KV, key string) (*sidh.PrivateKey, error) { vo, err := kv.Get(key, currentSIDHPrivKeyVersion) if err != nil { return nil, err @@ -154,7 +155,7 @@ func LoadSIDHPrivateKey(kv *versioned.KV, key string) (*sidh.PrivateKey, error) } // DeleteSIDHPrivateKey removes the key from the store -func DeleteSIDHPrivateKey(kv *versioned.KV, key string) error { +func DeleteSIDHPrivateKey(kv versioned.KV, key string) error { return kv.Delete(key, currentSIDHPrivKeyVersion) } diff --git a/storage/utility/stateVector.go b/storage/utility/stateVector.go index e23c776bb931d31d9321772ff0536209e0da19e6..f69e3a3c83e219763a23223bb05a4a7f2f1b2835 100644 --- a/storage/utility/stateVector.go +++ b/storage/utility/stateVector.go @@ -10,12 +10,13 @@ package utility import ( "encoding/json" "fmt" + "sync" + "testing" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/xx_network/primitives/netTime" - "sync" - "testing" ) // Storage key and version. @@ -48,12 +49,12 @@ type StateVector struct { numAvailable uint32 // Number of unused keys key string // Unique string used to save/load object from storage - kv *versioned.KV + kv versioned.KV mux sync.RWMutex } // NewStateVector generates a new StateVector with the specified number of keys. -func NewStateVector(kv *versioned.KV, key string, numKeys uint32) ( +func NewStateVector(kv versioned.KV, key string, numKeys uint32) ( *StateVector, error) { // Calculate the number of 64-bit blocks needed to store numKeys @@ -352,7 +353,7 @@ type stateVectorDisk struct { // LoadStateVector loads a StateVector with the specified key from the given // versioned storage. -func LoadStateVector(kv *versioned.KV, key string) (*StateVector, error) { +func LoadStateVector(kv versioned.KV, key string) (*StateVector, error) { sv := &StateVector{ key: makeStateVectorKey(key), kv: kv, @@ -498,7 +499,7 @@ func (sv *StateVector) SetNumAvailableTEST(numAvailable uint32, x interface{}) { } // SetKvTEST sets the kv. This should only be used for testing. -func (sv *StateVector) SetKvTEST(kv *versioned.KV, x interface{}) { +func (sv *StateVector) SetKvTEST(kv versioned.KV, x interface{}) { switch x.(type) { case *testing.T, *testing.M, *testing.B, *testing.PB: break diff --git a/storage/versioned/kv.go b/storage/versioned/kv.go index 85f7a92f76fe2c0c07f7405c4517f6081313f836..b99dad64530f129661a8b947e9c9dd058f6821f4 100644 --- a/storage/versioned/kv.go +++ b/storage/versioned/kv.go @@ -9,11 +9,12 @@ package versioned import ( "fmt" + "strings" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" - "strings" ) // PrefixSeparator is the separator added when prefixing a KV (see [KV.Prefix]). @@ -29,6 +30,45 @@ const ( DuplicatePrefixErr = "prefix has already been added, cannot overwrite" ) +type KV interface { + // Get returns the object stored at the specified version. + Get(key string, version uint64) (*Object, error) + + // GetAndUpgrade gets and upgrades data stored in the key/value store. + // Make sure to inspect the version returned in the versioned object. + GetAndUpgrade(key string, ut UpgradeTable) (*Object, error) + + // Delete removes a given key from the data store. + Delete(key string, version uint64) error + + // Set upserts new data into the storage + // When calling this, you are responsible for prefixing the + // key with the correct type optionally unique id! Call + // MakeKeyWithPrefix() to do so. + // The [Object] should contain the versioning if you are + // maintaining such a functionality. + Set(key string, object *Object) error + + // GetPrefix returns the full Prefix of the KV + GetPrefix() string + + // HasPrefix returns whether this prefix exists in the KV + HasPrefix(prefix string) bool + + // Prefix returns a new KV with the new prefix appending + Prefix(prefix string) (KV, error) + + // IsMemStore returns true if the underlying KV is memory based + IsMemStore() bool + + // GetFullKey returns the key with all prefixes appended + GetFullKey(key string, version uint64) string + + // Exists returns if the error indicates a KV error showing + // the key exists. + Exists(err error) bool +} + // MakePartnerPrefix creates a string prefix // to denote who a conversation or relationship is with func MakePartnerPrefix(id *id.ID) string { @@ -39,12 +79,17 @@ func MakePartnerPrefix(id *id.ID) string { type Upgrade func(oldObject *Object) (*Object, error) +type UpgradeTable struct { + CurrentVersion uint64 + Table []Upgrade +} + type root struct { data ekv.KeyValue } -// KV stores versioned data and Upgrade functions -type KV struct { +// kv stores versioned data and Upgrade functions +type kv struct { r *root prefix string prefixMap map[string]int @@ -52,22 +97,22 @@ type KV struct { } // Create a versioned key/value store backed by something implementing KeyValue -func NewKV(data ekv.KeyValue) *KV { - newKV := KV{ +func NewKV(data ekv.KeyValue) KV { + newkv := kv{ prefixMap: make(map[string]int, 0), } root := root{} root.data = data - newKV.r = &root + newkv.r = &root - return &newKV + return &newkv } // Get gets and upgrades data stored in the key/value store // Make sure to inspect the version returned in the versioned object -func (v *KV) Get(key string, version uint64) (*Object, error) { +func (v *kv) Get(key string, version uint64) (*Object, error) { key = v.makeKey(key, version) jww.TRACE.Printf("get %p with key %v", v.r.data, key) // get raw data @@ -79,14 +124,9 @@ func (v *KV) Get(key string, version uint64) (*Object, error) { return &result, nil } -type UpgradeTable struct { - CurrentVersion uint64 - Table []Upgrade -} - // GetAndUpgrade gets and upgrades data stored in the key/value store. // Make sure to inspect the version returned in the versioned object. -func (v *KV) GetAndUpgrade(key string, ut UpgradeTable) (*Object, error) { +func (v *kv) GetAndUpgrade(key string, ut UpgradeTable) (*Object, error) { version := ut.CurrentVersion baseKey := key key = v.makeKey(baseKey, version) @@ -138,7 +178,7 @@ func (v *KV) GetAndUpgrade(key string, ut UpgradeTable) (*Object, error) { } // Delete removes a given key from the data store. -func (v *KV) Delete(key string, version uint64) error { +func (v *kv) Delete(key string, version uint64) error { key = v.makeKey(key, version) jww.TRACE.Printf("delete %p with key %v", v.r.data, key) return v.r.data.Delete(key) @@ -149,25 +189,25 @@ func (v *KV) Delete(key string, version uint64) error { // type optionally unique id! Call MakeKeyWithPrefix() to do so. // The [Object] should contain the versioning if you are maintaining such // a functionality. -func (v *KV) Set(key string, object *Object) error { +func (v *kv) Set(key string, object *Object) error { key = v.makeKey(key, object.Version) jww.TRACE.Printf("Set %p with key %v", v.r.data, key) return v.r.data.Set(key, object) } -// GetPrefix returns the prefix of the KV. -func (v *KV) GetPrefix() string { +// GetPrefix returns the prefix of the kv. +func (v *kv) GetPrefix() string { return v.prefix } -// HasPrefix returns whether this prefix exists in the KV. -func (v *KV) HasPrefix(prefix string) bool { +// HasPrefix returns whether this prefix exists in the kv. +func (v *kv) HasPrefix(prefix string) bool { _, exists := v.prefixMap[prefix] return exists } -// Prefix returns a new KV with the new prefix appending. -func (v *KV) Prefix(prefix string) (*KV, error) { +// Prefix returns a new kv with the new prefix appending. +func (v *kv) Prefix(prefix string) (KV, error) { //// Reject invalid prefixes if strings.Contains(prefix, PrefixSeparator) { return nil, errors.Errorf(PrefixContainingSeparatorErr) @@ -180,7 +220,7 @@ func (v *KV) Prefix(prefix string) (*KV, error) { v.offset++ - kvPrefix := KV{ + kvPrefix := kv{ r: v.r, prefix: v.prefix + prefix + PrefixSeparator, prefixMap: v.prefixMap, @@ -191,22 +231,22 @@ func (v *KV) Prefix(prefix string) (*KV, error) { return &kvPrefix, nil } -func (v *KV) IsMemStore() bool { +func (v *kv) IsMemStore() bool { _, success := v.r.data.(*ekv.Memstore) return success } // Returns the key with all prefixes appended -func (v *KV) GetFullKey(key string, version uint64) string { +func (v *kv) GetFullKey(key string, version uint64) string { return v.makeKey(key, version) } -func (v *KV) makeKey(key string, version uint64) string { +func (v *kv) makeKey(key string, version uint64) string { return fmt.Sprintf("%s%s_%d", v.prefix, key, version) } // Exists returns false if the error indicates the element doesn't // exist. -func (v *KV) Exists(err error) bool { +func (v *kv) Exists(err error) bool { return ekv.Exists(err) } diff --git a/ud/channelIDTracking.go b/ud/channelIDTracking.go index 9dc19646ee85ecd23323e29cec4257b9b8446de6..03173f68ebef5b3a820f3900cb1cf3fa70bb136c 100644 --- a/ud/channelIDTracking.go +++ b/ud/channelIDTracking.go @@ -30,7 +30,7 @@ var ErrChannelLeaseSignature = errors.New("failure to validate lease signature") // loadRegistrationDisk loads a registrationDisk from the kv // and returns the registrationDisk. -func loadRegistrationDisk(kv *versioned.KV) (registrationDisk, error) { +func loadRegistrationDisk(kv versioned.KV) (registrationDisk, error) { obj, err := kv.Get(registrationDiskKey, registrationDiskVersion) if err != nil { return registrationDisk{}, err @@ -40,7 +40,7 @@ func loadRegistrationDisk(kv *versioned.KV) (registrationDisk, error) { // saveRegistrationDisk saves the given saveRegistrationDisk to // the given kv. -func saveRegistrationDisk(kv *versioned.KV, reg registrationDisk) error { +func saveRegistrationDisk(kv versioned.KV, reg registrationDisk) error { regBytes, err := reg.Marshall() if err != nil { return err @@ -150,7 +150,7 @@ func (r registrationDisk) GetLeaseSignature() ([]byte, time.Time) { // repetitive scheduling of new lease registrations when the // current lease expires. type clientIDTracker struct { - kv *versioned.KV + kv versioned.KV username string @@ -168,7 +168,7 @@ type clientIDTracker struct { var _ channels.NameService = (*clientIDTracker)(nil) // newclientIDTracker creates a new clientIDTracker. -func newclientIDTracker(comms channelLeaseComms, host *connect.Host, username string, kv *versioned.KV, +func newclientIDTracker(comms channelLeaseComms, host *connect.Host, username string, kv versioned.KV, receptionIdentity xxdk.ReceptionIdentity, udPubKey ed25519.PublicKey, rngSource *fastRNG.StreamGenerator) *clientIDTracker { reg, err := loadRegistrationDisk(kv) diff --git a/ud/manager.go b/ud/manager.go index eed144156e47eb6aab3f84dce58ba651e0189cdd..a87fff9a4b14c8beffce1a9004e81bf0a34e7fc6 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -177,7 +177,7 @@ func NewManagerFromBackup(user udE2e, comms Comms, } // InitStoreFromBackup initializes the UD storage from the backup subsystem. -func InitStoreFromBackup(kv *versioned.KV, +func InitStoreFromBackup(kv versioned.KV, username, email, phone fact.Fact) error { // Initialize our store udStore, err := store.NewOrLoadStore(kv) @@ -232,7 +232,7 @@ func (m *Manager) getCmix() udCmix { // getKv returns a versioned.KV used for IsRegistered and setRegistered. // This is separated from store operations as store's kv // has a different prefix which breaks backwards compatibility. -func (m *Manager) getKv() *versioned.KV { +func (m *Manager) getKv() versioned.KV { return m.user.GetStorage().GetKV() } diff --git a/ud/mockE2e_test.go b/ud/mockE2e_test.go index f7be833c24797770ac984c2cd9b688d17da44978..763d8c05189f729da5f5fdbb1ca0289b8b9c9b9b 100644 --- a/ud/mockE2e_test.go +++ b/ud/mockE2e_test.go @@ -39,7 +39,7 @@ type mockE2e struct { grp *cyclic.Group events event.Reporter rng *fastRNG.StreamGenerator - kv *versioned.KV + kv versioned.KV network cmix.Client mockStore mockStorage t testing.TB diff --git a/ud/mockStore_test.go b/ud/mockStore_test.go index f2fb390adcd7dfb3a3ec672c9fb0cb7bbf47f441..229358d43eb3890c3665ad1e764b77eb2451eb97 100644 --- a/ud/mockStore_test.go +++ b/ud/mockStore_test.go @@ -22,7 +22,7 @@ import ( type mockStorage struct{} -func (m mockStorage) GetKV() *versioned.KV { +func (m mockStorage) GetKV() versioned.KV { return versioned.NewKV(ekv.MakeMemstore()) } diff --git a/ud/registered.go b/ud/registered.go index 648577c01d2616ae801502d1dc83bc8c2bea798b..6d766a477d20655fe9b4558f0a713f354eae01c5 100644 --- a/ud/registered.go +++ b/ud/registered.go @@ -20,7 +20,7 @@ const isRegisteredVersion = 0 // IsRegistered loads from storage if the user is registered with user // discovery. -func IsRegistered(kv *versioned.KV) bool { +func IsRegistered(kv versioned.KV) bool { _, err := kv.Get(isRegisteredKey, isRegisteredVersion) if err != nil { return false @@ -30,7 +30,7 @@ func IsRegistered(kv *versioned.KV) bool { } // setRegistered sets the user to registered -func setRegistered(kv *versioned.KV) error { +func setRegistered(kv versioned.KV) error { data := make([]byte, 4) binary.BigEndian.PutUint32(data, 1) obj := &versioned.Object{ diff --git a/ud/store/store.go b/ud/store/store.go index f0a3e5c365f5c901e1030a985c9415a6c03e6c1d..4b1a0b3c6daddfcd4894b0a2bd64bc76df581024 100644 --- a/ud/store/store.go +++ b/ud/store/store.go @@ -11,11 +11,12 @@ package ud import ( "encoding/json" + "sync" + "github.com/pkg/errors" "gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/primitives/netTime" - "sync" ) // Storage constants @@ -43,12 +44,12 @@ type Store struct { // Stores facts that have been added by UDB but unconfirmed facts. // Maps confirmID to fact unconfirmedFacts map[string]fact.Fact - kv *versioned.KV + kv versioned.KV mux sync.RWMutex } // newStore creates a new, empty Store object. -func newStore(kv *versioned.KV) (*Store, error) { +func newStore(kv versioned.KV) (*Store, error) { kv, err := kv.Prefix(prefix) if err != nil { return nil, err @@ -129,7 +130,7 @@ func (s *Store) saveUnconfirmedFacts() error { ///////////////////////////////////////////////////////////////// // NewOrLoadStore loads the Store object from the provided versioned.KV. -func NewOrLoadStore(kv *versioned.KV) (*Store, error) { +func NewOrLoadStore(kv versioned.KV) (*Store, error) { storeKv, err := kv.Prefix(prefix) if err != nil { diff --git a/xxdk/e2e.go b/xxdk/e2e.go index 7a08af68aa8fce0d2d45c2d8d32bb4d72f077037..db1abc6728f4e71fe55823fde35fd5196e9cbdd5 100644 --- a/xxdk/e2e.go +++ b/xxdk/e2e.go @@ -114,7 +114,7 @@ func loginLegacy(net *Cmix, callbacks AuthCallbacks, // login creates a new xxdk.E2e backed by the given versioned.KV. func login(net *Cmix, callbacks AuthCallbacks, identity ReceptionIdentity, - kv *versioned.KV, params E2EParams) (m *E2e, err error) { + kv versioned.KV, params E2EParams) (m *E2e, err error) { // Verify the passed-in ReceptionIdentity matches its properties privatePem, err := identity.GetRSAPrivateKey()