From 5e23460b74a0f954dfcac561276257f22db0dfce Mon Sep 17 00:00:00 2001
From: joshemb <josh@elixxir.io>
Date: Mon, 25 Jul 2022 15:35:09 -0700
Subject: [PATCH] Refactor messenger to user

---
 connectAuthClient/main.go   | 10 +++++-----
 connectClient/main.go       | 10 +++++-----
 e2eClient/main.go           | 12 ++++++------
 restConnectClient/main.go   | 12 ++++++------
 restSingleUseClient/main.go | 12 ++++++------
 restSingleUseServer/main.go | 10 +++++-----
 6 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/connectAuthClient/main.go b/connectAuthClient/main.go
index 2d59533..82672c7 100644
--- a/connectAuthClient/main.go
+++ b/connectAuthClient/main.go
@@ -95,7 +95,7 @@ func main() {
 	// `xxdk.DefaultAuthCallbacks` is fine here
 	params := xxdk.GetDefaultE2EParams()
 	jww.INFO.Printf("Using E2E parameters: %+v", params)
-	messenger, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
+	user, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
 		identity, params)
 	if err != nil {
 		jww.FATAL.Panicf("Unable to Login: %+v", err)
@@ -105,7 +105,7 @@ func main() {
 
 	// Set networkFollowerTimeout to a value of your choice (seconds)
 	networkFollowerTimeout := 5 * time.Second
-	err = messenger.StartNetworkFollower(networkFollowerTimeout)
+	err = user.StartNetworkFollower(networkFollowerTimeout)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to start network follower: %+v", err)
 	}
@@ -131,7 +131,7 @@ func main() {
 	connected := make(chan bool, 10)
 	// Provide a callback that will be signalled when network
 	// health status changes
-	messenger.GetCmix().AddHealthCallback(
+	user.GetCmix().AddHealthCallback(
 		func(isConnected bool) {
 			connected <- isConnected
 		})
@@ -157,7 +157,7 @@ func main() {
 	jww.INFO.Printf("Recipient contact: %+v", recipientContact)
 
 	// Create the connection
-	handler, err := connect.ConnectWithAuthentication(recipientContact, messenger, params)
+	handler, err := connect.ConnectWithAuthentication(recipientContact, user, params)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to create connection object: %+v", err)
 	}
@@ -195,7 +195,7 @@ func main() {
 	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 	<-c
 
-	err = messenger.StopNetworkFollower()
+	err = user.StopNetworkFollower()
 	if err != nil {
 		jww.ERROR.Printf("Failed to stop network follower: %+v", err)
 	} else {
diff --git a/connectClient/main.go b/connectClient/main.go
index 7147b0f..8ff58e7 100644
--- a/connectClient/main.go
+++ b/connectClient/main.go
@@ -97,7 +97,7 @@ func main() {
 	// `xxdk.DefaultAuthCallbacks` is fine here
 	params := xxdk.GetDefaultE2EParams()
 	jww.INFO.Printf("Using E2E parameters: %+v", params)
-	messenger, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
+	user, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
 		identity, params)
 	if err != nil {
 		jww.FATAL.Panicf("Unable to Login: %+v", err)
@@ -107,7 +107,7 @@ func main() {
 
 	// Set networkFollowerTimeout to a value of your choice (seconds)
 	networkFollowerTimeout := 5 * time.Second
-	err = messenger.StartNetworkFollower(networkFollowerTimeout)
+	err = user.StartNetworkFollower(networkFollowerTimeout)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to start network follower: %+v", err)
 	}
@@ -133,7 +133,7 @@ func main() {
 	connected := make(chan bool, 10)
 	// Provide a callback that will be signalled when network
 	// health status changes
-	messenger.GetCmix().AddHealthCallback(
+	user.GetCmix().AddHealthCallback(
 		func(isConnected bool) {
 			connected <- isConnected
 		})
@@ -159,7 +159,7 @@ func main() {
 	jww.INFO.Printf("Recipient contact: %+v", recipientContact)
 
 	// Create the connection
-	handler, err := connect.Connect(recipientContact, messenger, params)
+	handler, err := connect.Connect(recipientContact, user, params)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to create connection object: %+v", err)
 	}
@@ -197,7 +197,7 @@ func main() {
 	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 	<-c
 
-	err = messenger.StopNetworkFollower()
+	err = user.StopNetworkFollower()
 	if err != nil {
 		jww.ERROR.Printf("Failed to stop network follower: %+v", err)
 	} else {
diff --git a/e2eClient/main.go b/e2eClient/main.go
index fdff064..19e8d65 100644
--- a/e2eClient/main.go
+++ b/e2eClient/main.go
@@ -98,17 +98,17 @@ func main() {
 	params := xxdk.GetDefaultE2EParams()
 	jww.INFO.Printf("Using E2E parameters: %+v", params)
 	confirmChan := make(chan contact.Contact, 5)
-	messenger, err := xxdk.Login(net, &auth{confirmChan: confirmChan}, identity, params)
+	user, err := xxdk.Login(net, &auth{confirmChan: confirmChan}, identity, params)
 	if err != nil {
 		jww.FATAL.Panicf("Unable to Login: %+v", err)
 	}
-	e2eClient := messenger.GetE2E()
+	e2eClient := user.GetE2E()
 
 	// Start network threads------------------------------------------------------------
 
 	// Set networkFollowerTimeout to a value of your choice (seconds)
 	networkFollowerTimeout := 5 * time.Second
-	err = messenger.StartNetworkFollower(networkFollowerTimeout)
+	err = user.StartNetworkFollower(networkFollowerTimeout)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to start network follower: %+v", err)
 	}
@@ -133,7 +133,7 @@ func main() {
 	// Create a tracker channel to be notified of network changes
 	connected := make(chan bool, 10)
 	// Provide a callback that will be signalled when network health status changes
-	messenger.GetCmix().AddHealthCallback(
+	user.GetCmix().AddHealthCallback(
 		func(isConnected bool) {
 			connected <- isConnected
 		})
@@ -171,7 +171,7 @@ func main() {
 		// Check that the partner exists, if not send a request
 		_, err = e2eClient.GetPartner(recipientContact.ID)
 		if err != nil {
-			_, err = messenger.GetAuth().Request(recipientContact, fact.FactList{})
+			_, err = user.GetAuth().Request(recipientContact, fact.FactList{})
 			if err != nil {
 				jww.FATAL.Panicf("Failed to send contact request to %s: %+v", recipientContact.ID.String(), err)
 			}
@@ -205,7 +205,7 @@ func main() {
 	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 	<-c
 
-	err = messenger.StopNetworkFollower()
+	err = user.StopNetworkFollower()
 	if err != nil {
 		jww.ERROR.Printf("Failed to stop network follower: %+v", err)
 	} else {
diff --git a/restConnectClient/main.go b/restConnectClient/main.go
index e0365a2..1074599 100644
--- a/restConnectClient/main.go
+++ b/restConnectClient/main.go
@@ -113,7 +113,7 @@ func main() {
 	// xxdk.DefaultAuthCallbacks is fine here
 	params := xxdk.GetDefaultE2EParams()
 	jww.INFO.Printf("Using E2E parameters: %+v", params)
-	messenger, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
+	user, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
 		identity, params)
 	if err != nil {
 		jww.FATAL.Panicf("Unable to Login: %+v", err)
@@ -123,7 +123,7 @@ func main() {
 
 	// Set networkFollowerTimeout to a value of your choice (seconds)
 	networkFollowerTimeout := 5 * time.Second
-	err = messenger.StartNetworkFollower(networkFollowerTimeout)
+	err = user.StartNetworkFollower(networkFollowerTimeout)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to start network follower: %+v", err)
 	}
@@ -149,7 +149,7 @@ func main() {
 	connected := make(chan bool, 10)
 	// Provide a callback that will be signalled when network health status
 	// changes
-	messenger.GetCmix().AddHealthCallback(
+	user.GetCmix().AddHealthCallback(
 		func(isConnected bool) {
 			connected <- isConnected
 		})
@@ -176,7 +176,7 @@ func main() {
 
 	// Establish connection with the server------------------------------------
 
-	handler, err := connect.Connect(serverContact, messenger, params)
+	handler, err := connect.Connect(serverContact, user, params)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to create connection object: %+v", err)
 	}
@@ -185,7 +185,7 @@ func main() {
 
 	// Construct request-------------------------------------------------------
 
-	stream := messenger.GetRng().GetStream()
+	stream := user.GetRng().GetStream()
 	defer stream.Close()
 
 	grp, err := identity.GetGroup()
@@ -241,7 +241,7 @@ func main() {
 	jww.DEBUG.Printf("Waiting for SIGTERM signal to close process")
 	<-c
 
-	err = messenger.StopNetworkFollower()
+	err = user.StopNetworkFollower()
 	if err != nil {
 		jww.ERROR.Printf("Failed to stop network follower: %+v", err)
 	} else {
diff --git a/restSingleUseClient/main.go b/restSingleUseClient/main.go
index ad2e29c..3ac42ed 100644
--- a/restSingleUseClient/main.go
+++ b/restSingleUseClient/main.go
@@ -110,7 +110,7 @@ func main() {
 	// xxdk.DefaultAuthCallbacks is fine here
 	params := xxdk.GetDefaultE2EParams()
 	jww.INFO.Printf("Using E2E parameters: %+v", params)
-	messenger, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
+	user, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
 		identity, params)
 	if err != nil {
 		jww.FATAL.Panicf("Unable to Login: %+v", err)
@@ -120,7 +120,7 @@ func main() {
 
 	// Set networkFollowerTimeout to a value of your choice (seconds)
 	networkFollowerTimeout := 5 * time.Second
-	err = messenger.StartNetworkFollower(networkFollowerTimeout)
+	err = user.StartNetworkFollower(networkFollowerTimeout)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to start network follower: %+v", err)
 	}
@@ -146,7 +146,7 @@ func main() {
 	connected := make(chan bool, 10)
 	// Provide a callback that will be signalled when network health status
 	// changes
-	messenger.GetCmix().AddHealthCallback(
+	user.GetCmix().AddHealthCallback(
 		func(isConnected bool) {
 			connected <- isConnected
 		})
@@ -173,7 +173,7 @@ func main() {
 
 	// Construct request-------------------------------------------------------
 
-	stream := messenger.GetRng().GetStream()
+	stream := user.GetRng().GetStream()
 	defer stream.Close()
 
 	grp, err := identity.GetGroup()
@@ -182,7 +182,7 @@ func main() {
 	}
 
 	request := restSingle.Request{
-		Net:    messenger.GetCmix(),
+		Net:    user.GetCmix(),
 		Rng:    stream,
 		E2eGrp: grp,
 	}
@@ -230,7 +230,7 @@ func main() {
 	jww.DEBUG.Printf("Waiting for SIGTERM signal to close process")
 	<-c
 
-	err = messenger.StopNetworkFollower()
+	err = user.StopNetworkFollower()
 	if err != nil {
 		jww.ERROR.Printf("Failed to stop network follower: %+v", err)
 	} else {
diff --git a/restSingleUseServer/main.go b/restSingleUseServer/main.go
index 0ba74c3..c86903d 100644
--- a/restSingleUseServer/main.go
+++ b/restSingleUseServer/main.go
@@ -101,7 +101,7 @@ func main() {
 	// xxdk.DefaultAuthCallbacks is fine here
 	params := xxdk.GetDefaultE2EParams()
 	jww.INFO.Printf("Using E2E parameters: %+v", params)
-	messenger, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
+	user, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
 		identity, params)
 	if err != nil {
 		jww.FATAL.Panicf("Unable to Login: %+v", err)
@@ -126,7 +126,7 @@ func main() {
 	}
 	// Initialize the server
 	restlikeServer := single.NewServer(identity.ID, dhKeyPrivateKey,
-		grp, messenger.GetCmix())
+		grp, user.GetCmix())
 	jww.INFO.Printf("Initialized restlike single use server")
 
 	// Implement restlike endpoint---------------------------------------------
@@ -142,7 +142,7 @@ func main() {
 
 	// Set networkFollowerTimeout to a value of your choice (seconds)
 	networkFollowerTimeout := 5 * time.Second
-	err = messenger.StartNetworkFollower(networkFollowerTimeout)
+	err = user.StartNetworkFollower(networkFollowerTimeout)
 	if err != nil {
 		jww.FATAL.Panicf("Failed to start network follower: %+v", err)
 	}
@@ -168,7 +168,7 @@ func main() {
 	connected := make(chan bool, 10)
 	// Provide a callback that will be signalled when network
 	// health status changes
-	messenger.GetCmix().AddHealthCallback(
+	user.GetCmix().AddHealthCallback(
 		func(isConnected bool) {
 			connected <- isConnected
 		})
@@ -183,7 +183,7 @@ func main() {
 	jww.DEBUG.Printf("Waiting for SIGTERM signal to close process")
 	<-c
 
-	err = messenger.StopNetworkFollower()
+	err = user.StopNetworkFollower()
 	if err != nil {
 		jww.ERROR.Printf("Failed to stop network follower: %+v", err)
 	} else {
-- 
GitLab