From f3963288e32d81f5c4678d040433592e1a47e3ef Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sat, 24 Aug 2024 22:44:02 +0200 Subject: [PATCH] using clientId in the public interface of admin instead of an internal interface agentConnection. --- pkg/server/admin/admin.go | 7 ++++++- pkg/server/admin/admin_test.go | 2 +- pkg/server/matchmaker/matchmaker.go | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/server/admin/admin.go b/pkg/server/admin/admin.go index 542c172..0a3931d 100644 --- a/pkg/server/admin/admin.go +++ b/pkg/server/admin/admin.go @@ -222,10 +222,15 @@ func (admin *Admin) RemoveAgent(publicId models.RendezVousId) error { return nil } -func (admin *Admin) RemoveClient(client *clientConnection) error { +func (admin *Admin) RemoveClient(clientId models.ClientId) error { admin.mutex.Lock() defer admin.mutex.Unlock() + client := admin.clients[clientId] + if client == nil { + return fmt.Errorf("RemoveClient: client with id '%v' not found", string(clientId)) + } + log.Printf("Removing client: '%s' created at %s\n", client.Info.Guid, client.Info.StartTime.Format(time.DateTime)) // try to explicitly close connection to the agent. diff --git a/pkg/server/admin/admin_test.go b/pkg/server/admin/admin_test.go index c4f9d96..5d84ee1 100644 --- a/pkg/server/admin/admin_test.go +++ b/pkg/server/admin/admin_test.go @@ -182,7 +182,7 @@ func (s *AdminTestSuite) Test_connectClient() error { // removing the client will close all connections, we test this by writing to the connections // after removing the client. - err = s.admin.RemoveClient(clientConn) + err = s.admin.RemoveClient(clientConn.Info.ClientId) s.Nil(err) buf := make([]byte, 10) _, err = clientConn.clientConnection.Write(buf) diff --git a/pkg/server/matchmaker/matchmaker.go b/pkg/server/matchmaker/matchmaker.go index e933c1d..1e457b8 100644 --- a/pkg/server/matchmaker/matchmaker.go +++ b/pkg/server/matchmaker/matchmaker.go @@ -120,7 +120,7 @@ func (converge *MatchMaker) Connect(wsProxyMode bool, client, err := converge.admin.AddClient(publicId, conn) cleanUpFunc := func() { if client != nil { - converge.admin.RemoveClient(client) + converge.admin.RemoveClient(client.Info.ClientId) } converge.logStatus() }