From d374c03a4833c23ab172da5b90a1d1f14ec36df2 Mon Sep 17 00:00:00 2001
From: josh <josh@elixxir.io>
Date: Thu, 12 May 2022 15:57:36 -0700
Subject: [PATCH] Fix bug where request callback (server-side) was not
 confirming the connection

---
 connect/authenticated_test.go |  1 +
 connect/connect.go            | 17 ++++++++++++++---
 connect/utils_test.go         |  1 +
 3 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 connect/authenticated_test.go
 create mode 100644 connect/utils_test.go

diff --git a/connect/authenticated_test.go b/connect/authenticated_test.go
new file mode 100644
index 000000000..9c5ea44a3
--- /dev/null
+++ b/connect/authenticated_test.go
@@ -0,0 +1 @@
+package connect
diff --git a/connect/connect.go b/connect/connect.go
index 985b80fb6..ff6bf3133 100644
--- a/connect/connect.go
+++ b/connect/connect.go
@@ -7,6 +7,7 @@
 package connect
 
 import (
+	"fmt"
 	"github.com/pkg/errors"
 	jww "github.com/spf13/jwalterweatherman"
 	"gitlab.com/elixxir/client/auth"
@@ -169,8 +170,9 @@ func StartServer(cb Callback, myId *id.ID, privKey *cyclic.Int,
 	callback := getAuthCallback(cb, e2eHandler, p)
 
 	// Build auth object for E2E negotiation
-	_, err = auth.NewState(kv, net, e2eHandler,
+	authState, err := auth.NewState(kv, net, e2eHandler,
 		rng, p.Event, p.Auth, callback, nil)
+	callback.authState = authState
 	return err
 }
 
@@ -208,6 +210,7 @@ func (h *handler) GetPartner() partner.Manager {
 func (h *handler) SendE2E(mt catalog.MessageType, payload []byte,
 	params clientE2e.Params) (
 	[]id.Round, e2e.MessageID, time.Time, error) {
+	fmt.Printf("sending e2e\n")
 	return h.e2e.SendE2E(mt, h.partner.PartnerId(), payload, params)
 }
 
@@ -235,13 +238,14 @@ type authCallback struct {
 	// Used for building new Connection objects
 	connectionE2e    clientE2e.Handler
 	connectionParams Params
+	authState        auth.State
 }
 
 // getAuthCallback returns a callback interface to be passed into the creation
 // of an auth.State object.
 func getAuthCallback(cb Callback, e2e clientE2e.Handler,
-	params Params) authCallback {
-	return authCallback{
+	params Params) *authCallback {
+	return &authCallback{
 		connectionCallback: cb,
 		connectionE2e:      e2e,
 		connectionParams:   params,
@@ -272,6 +276,13 @@ func (a authCallback) Confirm(requestor contact.Contact,
 // Request will be called when an auth Request message is processed.
 func (a authCallback) Request(requestor contact.Contact,
 	receptionID receptionID.EphemeralIdentity, round rounds.Round) {
+	_, err := a.authState.Confirm(requestor)
+	if err != nil {
+		jww.ERROR.Printf("Unable to build connection with "+
+			"partner %s: %+v", requestor.ID, err)
+		// Send a nil connection to avoid hold-ups down the line
+		a.connectionCallback(nil)
+	}
 }
 
 // Reset will be called when an auth Reset operation occurs.
diff --git a/connect/utils_test.go b/connect/utils_test.go
new file mode 100644
index 000000000..9c5ea44a3
--- /dev/null
+++ b/connect/utils_test.go
@@ -0,0 +1 @@
+package connect
-- 
GitLab