using clientId in the public interface of admin instead of an internal

interface agentConnection.
This commit is contained in:
Erik Brakkee 2024-08-24 22:44:02 +02:00
parent 95204a9f5b
commit f3963288e3
3 changed files with 8 additions and 3 deletions

View File

@ -222,10 +222,15 @@ func (admin *Admin) RemoveAgent(publicId models.RendezVousId) error {
return nil return nil
} }
func (admin *Admin) RemoveClient(client *clientConnection) error { func (admin *Admin) RemoveClient(clientId models.ClientId) error {
admin.mutex.Lock() admin.mutex.Lock()
defer admin.mutex.Unlock() 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, log.Printf("Removing client: '%s' created at %s\n", client.Info.Guid,
client.Info.StartTime.Format(time.DateTime)) client.Info.StartTime.Format(time.DateTime))
// try to explicitly close connection to the agent. // try to explicitly close connection to the agent.

View File

@ -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 // removing the client will close all connections, we test this by writing to the connections
// after removing the client. // after removing the client.
err = s.admin.RemoveClient(clientConn) err = s.admin.RemoveClient(clientConn.Info.ClientId)
s.Nil(err) s.Nil(err)
buf := make([]byte, 10) buf := make([]byte, 10)
_, err = clientConn.clientConnection.Write(buf) _, err = clientConn.clientConnection.Write(buf)

View File

@ -120,7 +120,7 @@ func (converge *MatchMaker) Connect(wsProxyMode bool,
client, err := converge.admin.AddClient(publicId, conn) client, err := converge.admin.AddClient(publicId, conn)
cleanUpFunc := func() { cleanUpFunc := func() {
if client != nil { if client != nil {
converge.admin.RemoveClient(client) converge.admin.RemoveClient(client.Info.ClientId)
} }
converge.logStatus() converge.logStatus()
} }