Skip to content
Snippets Groups Projects
Commit 66462228 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'hotfix/UdRefactor' into 'release'

Standardize sub-interfaces in ud/

See merge request !280
parents 892200eb 2432e3ab
Branches
Tags
2 merge requests!510Release,!280Standardize sub-interfaces in ud/
......@@ -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
}
......
......@@ -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
......@@ -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) (
......
......@@ -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 {
......
......@@ -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,7 +124,7 @@ func NewManagerFromBackup(e2e E2E, comms Comms, follower NetworkStatus,
// Initialize manager
m := &Manager{
e2e: e2e,
messenger: messenger,
comms: comms,
}
......@@ -188,9 +188,9 @@ 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,
messenger: messenger,
comms: comms,
}
......@@ -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()
}
......@@ -25,7 +25,7 @@ import (
)
///////////////////////////////////////////////////////////////////////////////
// Mock of the E2E interface within this package //////////////////////////////
// Mock of the udE2e interface within this package //////////////////////////////
///////////////////////////////////////////////////////////////////////////////
type mockE2e struct {
......
......@@ -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
......
......@@ -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
......
......@@ -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) {
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment