diff --git a/ud/addFact.go b/ud/addFact.go index ba9fef240d7b26dc56d4eb89b41c23676a026ce1..116975372d5bc01cb8c69fcd4cf6d061f0f300ae 100644 --- a/ud/addFact.go +++ b/ud/addFact.go @@ -22,7 +22,7 @@ func (m *Manager) SendRegisterFact(f fact.Fact) (string, error) { jww.INFO.Printf("ud.SendRegisterFact(%s)", f.Stringify()) m.factMux.Lock() defer m.factMux.Unlock() - return m.addFact(f, m.e2e.GetReceptionIdentity().ID, m.comms) + return m.addFact(f, m.messenger.GetReceptionIdentity().ID, m.comms) } // addFact is the helper function for SendRegisterFact. @@ -45,7 +45,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID, fHash := factID.Fingerprint(f) // Sign our inFact for putting into the request - privKey, err := m.e2e.GetReceptionIdentity().GetRSAPrivatePem() + privKey, err := m.messenger.GetReceptionIdentity().GetRSAPrivatePem() if err != nil { return "", err } diff --git a/ud/interfaces.go b/ud/interfaces.go index 42b0c570f5ff522bcb2b8204ad867b4b08fd9b4a..addd3a5303c42f7d6e3ce5ddd075e6a43e14ed6d 100644 --- a/ud/interfaces.go +++ b/ud/interfaces.go @@ -10,17 +10,21 @@ import ( "gitlab.com/elixxir/crypto/fastRNG" ) -// CMix is a sub-interface of the cmix.Client. It contains the methods +////////////////////////////////////////////////////////////////////////////////////// +// UD sub-interfaces +///////////////////////////////////////////////////////////////////////////////////// + +// udCmix is a sub-interface of the cmix.Client. It contains the methods // relevant to what is used in this package. -type CMix interface { - // CMix is passed down into the single use package, - // and thus has to adhere to the sub-interface defined in that package +type udCmix interface { + // Cmix within the single package is what udCmix must adhere to when passing + // arguments through to methods in the single package. single.Cmix } -// E2E is a sub-interface of the xxdk.E2e. It contains the methods +// udE2e is a sub-interface of the xxdk.E2e. It contains the methods // relevant to what is used in this package. -type E2E interface { +type udE2e interface { GetReceptionIdentity() xxdk.ReceptionIdentity GetCmix() cmix.Client GetE2E() e2e.Handler @@ -30,6 +34,6 @@ type E2E interface { GetTransmissionIdentity() xxdk.TransmissionIdentity } -// NetworkStatus is an interface for the xxdk.Cmix's +// udNetworkStatus is an interface for the xxdk.Cmix's // NetworkFollowerStatus method. -type NetworkStatus func() xxdk.Status +type udNetworkStatus func() xxdk.Status diff --git a/ud/lookup.go b/ud/lookup.go index bdcf557b8ebffd2bd21b75e7ed7ba20d58dedd54..6f23a8ccd91ac4eb7c76f1c3a71787717695e0b3 100644 --- a/ud/lookup.go +++ b/ud/lookup.go @@ -22,21 +22,21 @@ type lookupCallback func(contact.Contact, error) // Lookup returns the public key of the passed ID as known by the user discovery // system or returns by the timeout. -func Lookup(services CMix, +func Lookup(net udCmix, rng csprng.Source, grp *cyclic.Group, udContact contact.Contact, callback lookupCallback, uid *id.ID, p single.RequestParams) ([]id.Round, receptionID.EphemeralIdentity, error) { jww.INFO.Printf("ud.Lookup(%s, %s)", uid, p.Timeout) - return lookup(services, rng, uid, grp, udContact, callback, p) + return lookup(net, rng, uid, grp, udContact, callback, p) } // BatchLookup performs a Lookup operation on a list of user IDs. // The lookup performs a callback on each lookup on the returned contact object // constructed from the response. func BatchLookup(udContact contact.Contact, - services CMix, callback lookupCallback, + net udCmix, callback lookupCallback, rng csprng.Source, uids []*id.ID, grp *cyclic.Group, p single.RequestParams) { @@ -44,7 +44,7 @@ func BatchLookup(udContact contact.Contact, for _, uid := range uids { go func(localUid *id.ID) { - _, _, err := lookup(services, rng, localUid, grp, + _, _, err := lookup(net, rng, localUid, grp, udContact, callback, p) if err != nil { jww.WARN.Printf("Failed batch lookup on user %s: %v", @@ -59,7 +59,7 @@ func BatchLookup(udContact contact.Contact, // lookup is a helper function which sends a lookup request to the user discovery // service. It will construct a contact object off of the returned public key. // The callback will be called on that contact object. -func lookup(net CMix, rng csprng.Source, uid *id.ID, +func lookup(net udCmix, rng csprng.Source, uid *id.ID, grp *cyclic.Group, udContact contact.Contact, callback lookupCallback, p single.RequestParams) ( diff --git a/ud/lookup_test.go b/ud/lookup_test.go index da300b7b4e778913d8c66b84a497d344e368c795..662ac8552c4bb2409944fddcc61f27f4b3288371 100644 --- a/ud/lookup_test.go +++ b/ud/lookup_test.go @@ -65,8 +65,8 @@ func TestManager_Lookup(t *testing.T) { defer mockListener.Stop() - r := m.e2e.GetE2E().GetGroup().NewInt(1) - m.e2e.GetE2E().GetGroup().Random(r) + r := m.messenger.GetE2E().GetGroup().NewInt(1) + m.messenger.GetE2E().GetGroup().Random(r) s := "" jsonable, err := r.MarshalJSON() if err != nil { diff --git a/ud/manager.go b/ud/manager.go index 026583cb43bbd2b000ca49a1b693b92e6bb2dfe4..c9d408f0656a850b864deb2b4eaed065984d0013 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -27,9 +27,9 @@ const ( // Manager is the control structure for the contacting the user discovery service. type Manager struct { - // e2e is a sub-interface of the e2e.Handler. It allows the Manager + // messenger is a sub-interface of the e2e.Handler. It allows the Manager // to retrieve the client's E2E information. - e2e E2E + messenger udE2e // store is an instantiation of this package's storage object. // It contains the facts that are in some state of being registered @@ -58,7 +58,7 @@ type Manager struct { // It requires that an updated // NDF is available and will error if one is not. // registrationValidationSignature may be set to nil -func NewManager(e2e E2E, comms Comms, follower NetworkStatus, +func NewManager(messenger udE2e, comms Comms, follower udNetworkStatus, username string, registrationValidationSignature []byte) (*Manager, error) { jww.INFO.Println("ud.NewManager()") @@ -69,7 +69,7 @@ func NewManager(e2e E2E, comms Comms, follower NetworkStatus, // Initialize manager m := &Manager{ - e2e: e2e, + messenger: messenger, comms: comms, registrationValidationSignature: registrationValidationSignature, } @@ -113,7 +113,7 @@ func NewManager(e2e E2E, comms Comms, follower NetworkStatus, // NewManagerFromBackup builds a new user discover manager from a backup. // It will construct a manager that is already registered and restore // already registered facts into store. -func NewManagerFromBackup(e2e E2E, comms Comms, follower NetworkStatus, +func NewManagerFromBackup(messenger udE2e, comms Comms, follower udNetworkStatus, email, phone fact.Fact) (*Manager, error) { jww.INFO.Println("ud.NewManagerFromBackup()") if follower() != xxdk.Running { @@ -124,8 +124,8 @@ func NewManagerFromBackup(e2e E2E, comms Comms, follower NetworkStatus, // Initialize manager m := &Manager{ - e2e: e2e, - comms: comms, + messenger: messenger, + comms: comms, } // Initialize our store @@ -188,10 +188,10 @@ func InitStoreFromBackup(kv *versioned.KV, // LoadManager loads the state of the Manager // from disk. This is meant to be called after any the first // instantiation of the manager by NewUserDiscovery. -func LoadManager(e2e E2E, comms Comms) (*Manager, error) { +func LoadManager(messenger udE2e, comms Comms) (*Manager, error) { m := &Manager{ - e2e: e2e, - comms: comms, + messenger: messenger, + comms: comms, } if !m.isRegistered() { @@ -222,7 +222,7 @@ func (m *Manager) GetStringifiedFacts() []string { // GetContact returns the contact for UD as retrieved from the NDF. func (m *Manager) GetContact() (contact.Contact, error) { - grp, err := m.e2e.GetReceptionIdentity().GetGroup() + grp, err := m.messenger.GetReceptionIdentity().GetGroup() if err != nil { return contact.Contact{}, err } @@ -318,25 +318,25 @@ func (m *Manager) getOrAddUdHost() (*connect.Host, error) { // getCmix retrieve a sub-interface of cmix.Client. // It allows the Manager to retrieve network state. -func (m *Manager) getCmix() CMix { - return m.e2e.GetCmix() +func (m *Manager) getCmix() udCmix { + return m.messenger.GetCmix() } // 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 { - return m.e2e.GetStorage().GetKV() + return m.messenger.GetStorage().GetKV() } // getEventReporter returns an event.Reporter. This allows // the Manager to report events to the other levels of the client. func (m *Manager) getEventReporter() event.Reporter { - return m.e2e.GetEventReporter() + return m.messenger.GetEventReporter() } // getRng returns a fastRNG.StreamGenerator. This RNG is for // generating signatures for adding/removing facts. func (m *Manager) getRng() *fastRNG.StreamGenerator { - return m.e2e.GetRng() + return m.messenger.GetRng() } diff --git a/ud/mockE2e_test.go b/ud/mockE2e_test.go index 103d7e1362eeebfdec403a741044f6610918cff0..3be9c745ab0e44bfe413029872e3c9d28d007df6 100644 --- a/ud/mockE2e_test.go +++ b/ud/mockE2e_test.go @@ -25,7 +25,7 @@ import ( ) /////////////////////////////////////////////////////////////////////////////// -// Mock of the E2E interface within this package ////////////////////////////// +// Mock of the udE2e interface within this package ////////////////////////////// /////////////////////////////////////////////////////////////////////////////// type mockE2e struct { diff --git a/ud/networkManager_test.go b/ud/networkManager_test.go index 8aaec9115ab25ee3870dbff16afe3aa62670bbe8..3af69d9efaab5db21c45ea17f46c21313bb4e197 100644 --- a/ud/networkManager_test.go +++ b/ud/networkManager_test.go @@ -18,7 +18,7 @@ import ( "time" ) -// testNetworkManager is a mock implementation of the CMix interface. +// testNetworkManager is a mock implementation of the udCmix interface. type testNetworkManager struct { requestProcess message.Processor instance *network.Instance diff --git a/ud/register.go b/ud/register.go index 07c7fcdb942b2f96726af26a5e1deeac92fc2278..bac71c0ceb312f382ebedf53c2a3ac5909a9eb72 100644 --- a/ud/register.go +++ b/ud/register.go @@ -18,7 +18,7 @@ func (m *Manager) register(username string, rng csprng.Source, comm registerUserComms, udHost *connect.Host) error { var err error - identity := m.e2e.GetReceptionIdentity() + identity := m.messenger.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return err @@ -43,7 +43,7 @@ func (m *Manager) register(username string, rng csprng.Source, Salt: identity.Salt, }, UID: identity.ID.Marshal(), - Timestamp: m.e2e.GetTransmissionIdentity().RegistrationTimestamp, + Timestamp: m.messenger.GetTransmissionIdentity().RegistrationTimestamp, } // Sign the identity data and add to user registration message diff --git a/ud/register_test.go b/ud/register_test.go index d23aacc40f1b7bb89a1fb2f9606dc414ec909f72..fc1d4be40a5c949384f43f2a212c30d6ccf4c19a 100644 --- a/ud/register_test.go +++ b/ud/register_test.go @@ -43,7 +43,7 @@ func TestManager_register(t *testing.T) { isCorrect("testUser", c.msg, m, t) // Verify the signed identity data - pubKeyPem := m.e2e.GetReceptionIdentity().RSAPrivatePem + pubKeyPem := m.messenger.GetReceptionIdentity().RSAPrivatePem privKey, err := rsa.LoadPrivateKeyFromPem(pubKeyPem) if err != nil { t.Fatalf("Failed to load public key: %+v", err) @@ -72,7 +72,7 @@ func isCorrect(username string, msg *pb.UDBUserRegistration, m *Manager, t *test m.registrationValidationSignature, msg.PermissioningSignature) } - identity := m.e2e.GetReceptionIdentity() + identity := m.messenger.GetReceptionIdentity() privKey, err := rsa.LoadPrivateKeyFromPem(identity.RSAPrivatePem) if err != nil { t.Fatalf("Failed to load private key: %v", err) @@ -97,7 +97,7 @@ func isCorrect(username string, msg *pb.UDBUserRegistration, m *Manager, t *test t.Fatalf("%v", err) } - grp := m.e2e.GetE2E().GetGroup() + grp := m.messenger.GetE2E().GetGroup() dhKeyPub := grp.ExpG(dhKeyPriv, grp.NewInt(1)) if !bytes.Equal(dhKeyPub.Bytes(), msg.IdentityRegistration.DhPubKey) { diff --git a/ud/remove.go b/ud/remove.go index bdaf1e66e682035df6c2d35fccbc864d25622c8a..0e462019a535bfab624bf7857bab0a4cc2b300d9 100644 --- a/ud/remove.go +++ b/ud/remove.go @@ -45,7 +45,7 @@ func (m *Manager) removeFact(f fact.Fact, fHash := factID.Fingerprint(f) // Sign our inFact for putting into the request - identity := m.e2e.GetReceptionIdentity() + identity := m.messenger.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return err @@ -89,7 +89,7 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error { return err } - identity := m.e2e.GetReceptionIdentity() + identity := m.messenger.GetReceptionIdentity() privKey, err := identity.GetRSAPrivatePem() if err != nil { return err diff --git a/ud/search.go b/ud/search.go index 7061f4cc3a5c0b1c463b665a06f7cc9b3d70bdaf..473ba7a7fabfb754669726c92063fda1cec52658 100644 --- a/ud/search.go +++ b/ud/search.go @@ -28,7 +28,7 @@ type searchCallback func([]contact.Contact, error) // used to search for multiple users at once; that can have a privacy reduction. // Instead, it is intended to be used to search for a user where multiple pieces // of information is known. -func Search(services CMix, events event.Reporter, +func Search(net udCmix, events event.Reporter, rng csprng.Source, grp *cyclic.Group, udContact contact.Contact, callback searchCallback, list fact.FactList, @@ -48,7 +48,7 @@ func Search(services CMix, events event.Reporter, response := searchResponse{ cb: callback, - services: services, + services: net, events: events, grp: grp, factMap: factMap, @@ -56,7 +56,7 @@ func Search(services CMix, events event.Reporter, rndId, ephId, err := single.TransmitRequest(udContact, SearchTag, requestMarshaled, - response, params, services, rng, grp) + response, params, net, rng, grp) if err != nil { return []id.Round{}, receptionID.EphemeralIdentity{}, errors.WithMessage(err, "Failed to transmit search request.") @@ -72,7 +72,7 @@ func Search(services CMix, events event.Reporter, type searchResponse struct { cb searchCallback - services CMix + services udCmix events event.Reporter grp *cyclic.Group factMap map[string]fact.Fact diff --git a/ud/search_test.go b/ud/search_test.go index cb9f77bbd8b175fccb56c82093cbe8c536ac60f5..9276aece3c7b46ad6dbf0c18659e6c6846d72b4c 100644 --- a/ud/search_test.go +++ b/ud/search_test.go @@ -71,7 +71,7 @@ func TestManager_Search(t *testing.T) { CmixParams: cmix.GetDefaultCMIXParams(), } - _, _, err = Search(m.getCmix(), m.getEventReporter(), prng, m.e2e.GetE2E().GetGroup(), + _, _, err = Search(m.getCmix(), m.getEventReporter(), prng, m.messenger.GetE2E().GetGroup(), udContact, callback, factList, p) if err != nil { t.Fatalf("Search() returned an error: %+v", err) diff --git a/ud/utils_test.go b/ud/utils_test.go index 8c3016a8680085cddf9bdd732a182a3624edef1a..084cc16de02b1e4db40a9cf83cb965140cb8e434 100644 --- a/ud/utils_test.go +++ b/ud/utils_test.go @@ -58,7 +58,7 @@ func newTestManager(t *testing.T) (*Manager, *testNetworkManager) { // Create our Manager object tnm := newTestNetworkManager(t) m := &Manager{ - e2e: mockE2e{ + messenger: mockE2e{ grp: getGroup(), events: event.NewEventManager(), rng: rngGen,