From 757fb816651ef66481134343c6956af2f98264f4 Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Tue, 7 Jun 2022 09:47:03 -0700 Subject: [PATCH] added a closer to auth and made it called in connect on its closer --- auth/interface.go | 4 ++++ auth/state.go | 15 +++++++++++++++ connect/connect.go | 13 +++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/auth/interface.go b/auth/interface.go index 92ad54b77..e01e55766 100644 --- a/auth/interface.go +++ b/auth/interface.go @@ -16,6 +16,7 @@ import ( "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "io" ) type State interface { @@ -94,6 +95,9 @@ type State interface { // VerifyOwnership checks if the received ownership proof is valid VerifyOwnership(received, verified contact.Contact, e2e e2e.Handler) bool + + //Closer stops listening to auth + io.Closer } // Callbacks is the interface for auth callback methods. diff --git a/auth/state.go b/auth/state.go index 751f60312..0cd1a33ea 100644 --- a/auth/state.go +++ b/auth/state.go @@ -119,3 +119,18 @@ func (s *state) CallAllReceivedRequests() { func makeStorePrefix(partner *id.ID) string { return "authStore:" + base64.StdEncoding.EncodeToString(partner.Marshal()) } + +func (s *state) Close() error { + s.net.DeleteService(s.e2e.GetReceptionID(), message.Service{ + Identifier: s.e2e.GetReceptionID()[:], + Tag: s.params.RequestTag, + Metadata: nil, + }, nil) + + s.net.AddService(s.e2e.GetReceptionID(), message.Service{ + Identifier: s.e2e.GetReceptionID()[:], + Tag: s.params.ResetRequestTag, + Metadata: nil, + }, nil) + return nil +} diff --git a/connect/connect.go b/connect/connect.go index aef59baad..074718429 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -211,6 +211,7 @@ func StartServer(cb Callback, myId *id.ID, privKey *cyclic.Int, // handler provides an implementation for the Connection interface. type handler struct { + auth auth.State partner partner.Manager e2e clientE2e.Handler params Params @@ -220,8 +221,9 @@ type handler struct { // after an E2E partnership has already been confirmed with the given // partner.Manager. func BuildConnection(partner partner.Manager, e2eHandler clientE2e.Handler, - p Params) Connection { + auth auth.State, p Params) Connection { return &handler{ + auth: auth, partner: partner, params: p, e2e: e2eHandler, @@ -230,7 +232,10 @@ func BuildConnection(partner partner.Manager, e2eHandler clientE2e.Handler, // Close deletes this Connection's partner.Manager and releases resources. func (h *handler) Close() error { - return h.e2e.DeletePartner(h.partner.PartnerId()) + if err := h.e2e.DeletePartner(h.partner.PartnerId()); err != nil { + return err + } + return h.auth.Close() } // GetPartner returns the partner.Manager for this Connection. @@ -309,7 +314,7 @@ func (a authCallback) Confirm(requestor contact.Contact, // Return the new Connection object if a.confrimCallback != nil { a.confrimCallback(BuildConnection(newPartner, a.connectionE2e, - a.connectionParams)) + a.authState, a.connectionParams)) } } @@ -341,7 +346,7 @@ func (a authCallback) Request(requestor contact.Contact, // Return the new Connection object a.requestCallback(BuildConnection(newPartner, a.connectionE2e, - a.connectionParams)) + a.authState, a.connectionParams)) } // Reset will be called when an auth Reset operation occurs. -- GitLab