Skip to content
Snippets Groups Projects
Commit 2432e3ab authored by Josh Brooks's avatar Josh Brooks
Browse files

E2e -> messenger refactor

parent 02e461dd
Branches
Tags
2 merge requests!510Release,!280Standardize sub-interfaces in ud/
...@@ -22,7 +22,7 @@ func (m *Manager) SendRegisterFact(f fact.Fact) (string, error) { ...@@ -22,7 +22,7 @@ func (m *Manager) SendRegisterFact(f fact.Fact) (string, error) {
jww.INFO.Printf("ud.SendRegisterFact(%s)", f.Stringify()) jww.INFO.Printf("ud.SendRegisterFact(%s)", f.Stringify())
m.factMux.Lock() m.factMux.Lock()
defer m.factMux.Unlock() 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. // addFact is the helper function for SendRegisterFact.
...@@ -45,7 +45,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID, ...@@ -45,7 +45,7 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID,
fHash := factID.Fingerprint(f) fHash := factID.Fingerprint(f)
// Sign our inFact for putting into the request // Sign our inFact for putting into the request
privKey, err := m.e2e.GetReceptionIdentity().GetRSAPrivatePem() privKey, err := m.messenger.GetReceptionIdentity().GetRSAPrivatePem()
if err != nil { if err != nil {
return "", err return "", err
} }
......
...@@ -65,8 +65,8 @@ func TestManager_Lookup(t *testing.T) { ...@@ -65,8 +65,8 @@ func TestManager_Lookup(t *testing.T) {
defer mockListener.Stop() defer mockListener.Stop()
r := m.e2e.GetE2E().GetGroup().NewInt(1) r := m.messenger.GetE2E().GetGroup().NewInt(1)
m.e2e.GetE2E().GetGroup().Random(r) m.messenger.GetE2E().GetGroup().Random(r)
s := "" s := ""
jsonable, err := r.MarshalJSON() jsonable, err := r.MarshalJSON()
if err != nil { if err != nil {
......
...@@ -27,9 +27,9 @@ const ( ...@@ -27,9 +27,9 @@ const (
// Manager is the control structure for the contacting the user discovery service. // Manager is the control structure for the contacting the user discovery service.
type Manager struct { 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. // to retrieve the client's E2E information.
e2e udE2e messenger udE2e
// store is an instantiation of this package's storage object. // store is an instantiation of this package's storage object.
// It contains the facts that are in some state of being registered // It contains the facts that are in some state of being registered
...@@ -58,7 +58,7 @@ type Manager struct { ...@@ -58,7 +58,7 @@ type Manager struct {
// It requires that an updated // It requires that an updated
// NDF is available and will error if one is not. // NDF is available and will error if one is not.
// registrationValidationSignature may be set to nil // registrationValidationSignature may be set to nil
func NewManager(e2e udE2e, comms Comms, follower udNetworkStatus, func NewManager(messenger udE2e, comms Comms, follower udNetworkStatus,
username string, registrationValidationSignature []byte) (*Manager, error) { username string, registrationValidationSignature []byte) (*Manager, error) {
jww.INFO.Println("ud.NewManager()") jww.INFO.Println("ud.NewManager()")
...@@ -69,7 +69,7 @@ func NewManager(e2e udE2e, comms Comms, follower udNetworkStatus, ...@@ -69,7 +69,7 @@ func NewManager(e2e udE2e, comms Comms, follower udNetworkStatus,
// Initialize manager // Initialize manager
m := &Manager{ m := &Manager{
e2e: e2e, messenger: messenger,
comms: comms, comms: comms,
registrationValidationSignature: registrationValidationSignature, registrationValidationSignature: registrationValidationSignature,
} }
...@@ -113,7 +113,7 @@ func NewManager(e2e udE2e, comms Comms, follower udNetworkStatus, ...@@ -113,7 +113,7 @@ func NewManager(e2e udE2e, comms Comms, follower udNetworkStatus,
// NewManagerFromBackup builds a new user discover manager from a backup. // NewManagerFromBackup builds a new user discover manager from a backup.
// It will construct a manager that is already registered and restore // It will construct a manager that is already registered and restore
// already registered facts into store. // already registered facts into store.
func NewManagerFromBackup(e2e udE2e, comms Comms, follower udNetworkStatus, func NewManagerFromBackup(messenger udE2e, comms Comms, follower udNetworkStatus,
email, phone fact.Fact) (*Manager, error) { email, phone fact.Fact) (*Manager, error) {
jww.INFO.Println("ud.NewManagerFromBackup()") jww.INFO.Println("ud.NewManagerFromBackup()")
if follower() != xxdk.Running { if follower() != xxdk.Running {
...@@ -124,7 +124,7 @@ func NewManagerFromBackup(e2e udE2e, comms Comms, follower udNetworkStatus, ...@@ -124,7 +124,7 @@ func NewManagerFromBackup(e2e udE2e, comms Comms, follower udNetworkStatus,
// Initialize manager // Initialize manager
m := &Manager{ m := &Manager{
e2e: e2e, messenger: messenger,
comms: comms, comms: comms,
} }
...@@ -188,9 +188,9 @@ func InitStoreFromBackup(kv *versioned.KV, ...@@ -188,9 +188,9 @@ func InitStoreFromBackup(kv *versioned.KV,
// LoadManager loads the state of the Manager // LoadManager loads the state of the Manager
// from disk. This is meant to be called after any the first // from disk. This is meant to be called after any the first
// instantiation of the manager by NewUserDiscovery. // instantiation of the manager by NewUserDiscovery.
func LoadManager(e2e udE2e, comms Comms) (*Manager, error) { func LoadManager(messenger udE2e, comms Comms) (*Manager, error) {
m := &Manager{ m := &Manager{
e2e: e2e, messenger: messenger,
comms: comms, comms: comms,
} }
...@@ -222,7 +222,7 @@ func (m *Manager) GetStringifiedFacts() []string { ...@@ -222,7 +222,7 @@ func (m *Manager) GetStringifiedFacts() []string {
// GetContact returns the contact for UD as retrieved from the NDF. // GetContact returns the contact for UD as retrieved from the NDF.
func (m *Manager) GetContact() (contact.Contact, error) { func (m *Manager) GetContact() (contact.Contact, error) {
grp, err := m.e2e.GetReceptionIdentity().GetGroup() grp, err := m.messenger.GetReceptionIdentity().GetGroup()
if err != nil { if err != nil {
return contact.Contact{}, err return contact.Contact{}, err
} }
...@@ -319,24 +319,24 @@ func (m *Manager) getOrAddUdHost() (*connect.Host, error) { ...@@ -319,24 +319,24 @@ func (m *Manager) getOrAddUdHost() (*connect.Host, error) {
// getCmix retrieve a sub-interface of cmix.Client. // getCmix retrieve a sub-interface of cmix.Client.
// It allows the Manager to retrieve network state. // It allows the Manager to retrieve network state.
func (m *Manager) getCmix() udCmix { func (m *Manager) getCmix() udCmix {
return m.e2e.GetCmix() return m.messenger.GetCmix()
} }
// getKv returns a versioned.KV used for isRegistered and setRegistered. // getKv returns a versioned.KV used for isRegistered and setRegistered.
// This is separated from store operations as store's kv // This is separated from store operations as store's kv
// has a different prefix which breaks backwards compatibility. // has a different prefix which breaks backwards compatibility.
func (m *Manager) getKv() *versioned.KV { func (m *Manager) getKv() *versioned.KV {
return m.e2e.GetStorage().GetKV() return m.messenger.GetStorage().GetKV()
} }
// getEventReporter returns an event.Reporter. This allows // getEventReporter returns an event.Reporter. This allows
// the Manager to report events to the other levels of the client. // the Manager to report events to the other levels of the client.
func (m *Manager) getEventReporter() event.Reporter { func (m *Manager) getEventReporter() event.Reporter {
return m.e2e.GetEventReporter() return m.messenger.GetEventReporter()
} }
// getRng returns a fastRNG.StreamGenerator. This RNG is for // getRng returns a fastRNG.StreamGenerator. This RNG is for
// generating signatures for adding/removing facts. // generating signatures for adding/removing facts.
func (m *Manager) getRng() *fastRNG.StreamGenerator { func (m *Manager) getRng() *fastRNG.StreamGenerator {
return m.e2e.GetRng() return m.messenger.GetRng()
} }
...@@ -18,7 +18,7 @@ func (m *Manager) register(username string, rng csprng.Source, ...@@ -18,7 +18,7 @@ func (m *Manager) register(username string, rng csprng.Source,
comm registerUserComms, udHost *connect.Host) error { comm registerUserComms, udHost *connect.Host) error {
var err error var err error
identity := m.e2e.GetReceptionIdentity() identity := m.messenger.GetReceptionIdentity()
privKey, err := identity.GetRSAPrivatePem() privKey, err := identity.GetRSAPrivatePem()
if err != nil { if err != nil {
return err return err
...@@ -43,7 +43,7 @@ func (m *Manager) register(username string, rng csprng.Source, ...@@ -43,7 +43,7 @@ func (m *Manager) register(username string, rng csprng.Source,
Salt: identity.Salt, Salt: identity.Salt,
}, },
UID: identity.ID.Marshal(), UID: identity.ID.Marshal(),
Timestamp: m.e2e.GetTransmissionIdentity().RegistrationTimestamp, Timestamp: m.messenger.GetTransmissionIdentity().RegistrationTimestamp,
} }
// Sign the identity data and add to user registration message // Sign the identity data and add to user registration message
......
...@@ -43,7 +43,7 @@ func TestManager_register(t *testing.T) { ...@@ -43,7 +43,7 @@ func TestManager_register(t *testing.T) {
isCorrect("testUser", c.msg, m, t) isCorrect("testUser", c.msg, m, t)
// Verify the signed identity data // Verify the signed identity data
pubKeyPem := m.e2e.GetReceptionIdentity().RSAPrivatePem pubKeyPem := m.messenger.GetReceptionIdentity().RSAPrivatePem
privKey, err := rsa.LoadPrivateKeyFromPem(pubKeyPem) privKey, err := rsa.LoadPrivateKeyFromPem(pubKeyPem)
if err != nil { if err != nil {
t.Fatalf("Failed to load public key: %+v", err) t.Fatalf("Failed to load public key: %+v", err)
...@@ -72,7 +72,7 @@ func isCorrect(username string, msg *pb.UDBUserRegistration, m *Manager, t *test ...@@ -72,7 +72,7 @@ func isCorrect(username string, msg *pb.UDBUserRegistration, m *Manager, t *test
m.registrationValidationSignature, msg.PermissioningSignature) m.registrationValidationSignature, msg.PermissioningSignature)
} }
identity := m.e2e.GetReceptionIdentity() identity := m.messenger.GetReceptionIdentity()
privKey, err := rsa.LoadPrivateKeyFromPem(identity.RSAPrivatePem) privKey, err := rsa.LoadPrivateKeyFromPem(identity.RSAPrivatePem)
if err != nil { if err != nil {
t.Fatalf("Failed to load private key: %v", err) t.Fatalf("Failed to load private key: %v", err)
...@@ -97,7 +97,7 @@ func isCorrect(username string, msg *pb.UDBUserRegistration, m *Manager, t *test ...@@ -97,7 +97,7 @@ func isCorrect(username string, msg *pb.UDBUserRegistration, m *Manager, t *test
t.Fatalf("%v", err) t.Fatalf("%v", err)
} }
grp := m.e2e.GetE2E().GetGroup() grp := m.messenger.GetE2E().GetGroup()
dhKeyPub := grp.ExpG(dhKeyPriv, grp.NewInt(1)) dhKeyPub := grp.ExpG(dhKeyPriv, grp.NewInt(1))
if !bytes.Equal(dhKeyPub.Bytes(), msg.IdentityRegistration.DhPubKey) { if !bytes.Equal(dhKeyPub.Bytes(), msg.IdentityRegistration.DhPubKey) {
......
...@@ -45,7 +45,7 @@ func (m *Manager) removeFact(f fact.Fact, ...@@ -45,7 +45,7 @@ func (m *Manager) removeFact(f fact.Fact,
fHash := factID.Fingerprint(f) fHash := factID.Fingerprint(f)
// Sign our inFact for putting into the request // Sign our inFact for putting into the request
identity := m.e2e.GetReceptionIdentity() identity := m.messenger.GetReceptionIdentity()
privKey, err := identity.GetRSAPrivatePem() privKey, err := identity.GetRSAPrivatePem()
if err != nil { if err != nil {
return err return err
...@@ -89,7 +89,7 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error { ...@@ -89,7 +89,7 @@ func (m *Manager) PermanentDeleteAccount(f fact.Fact) error {
return err return err
} }
identity := m.e2e.GetReceptionIdentity() identity := m.messenger.GetReceptionIdentity()
privKey, err := identity.GetRSAPrivatePem() privKey, err := identity.GetRSAPrivatePem()
if err != nil { if err != nil {
return err return err
......
...@@ -71,7 +71,7 @@ func TestManager_Search(t *testing.T) { ...@@ -71,7 +71,7 @@ func TestManager_Search(t *testing.T) {
CmixParams: cmix.GetDefaultCMIXParams(), 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) udContact, callback, factList, p)
if err != nil { if err != nil {
t.Fatalf("Search() returned an error: %+v", err) t.Fatalf("Search() returned an error: %+v", err)
......
...@@ -58,7 +58,7 @@ func newTestManager(t *testing.T) (*Manager, *testNetworkManager) { ...@@ -58,7 +58,7 @@ func newTestManager(t *testing.T) (*Manager, *testNetworkManager) {
// Create our Manager object // Create our Manager object
tnm := newTestNetworkManager(t) tnm := newTestNetworkManager(t)
m := &Manager{ m := &Manager{
e2e: mockE2e{ messenger: mockE2e{
grp: getGroup(), grp: getGroup(),
events: event.NewEventManager(), events: event.NewEventManager(),
rng: rngGen, rng: rngGen,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment