ClientId is now a string instead of an int.

This commit is contained in:
Erik Brakkee 2024-08-07 21:00:41 +02:00
parent 68804761bf
commit 86535683fa
6 changed files with 9 additions and 11 deletions

View File

@ -93,7 +93,7 @@ func main() {
state.Agents = append(state.Agents, agent) state.Agents = append(state.Agents, agent)
client := models.Client{ client := models.Client{
PublicId: "c1", PublicId: "c1",
ClientId: 3, ClientId: "3",
StartTime: time.Now().In(japan), StartTime: time.Now().In(japan),
SessionType: "sftp", SessionType: "sftp",
} }

View File

@ -3,7 +3,6 @@ package comms
import ( import (
"converge/pkg/support/websocketutil" "converge/pkg/support/websocketutil"
"net" "net"
"strconv"
) )
type AgentListener struct { type AgentListener struct {
@ -42,7 +41,7 @@ func (listener AgentListener) Accept() (net.Conn, error) {
conn.Close() conn.Close()
return nil, err return nil, err
} }
return NewLocalAddrHackConn(conn, strconv.Itoa(clientInfo.ClientId)), nil return NewLocalAddrHackConn(conn, clientInfo.ClientId), nil
} }
func (listener AgentListener) Close() error { func (listener AgentListener) Close() error {

View File

@ -25,7 +25,7 @@ type AgentInfo struct {
} }
type ClientInfo struct { type ClientInfo struct {
ClientId int ClientId string
} }
type SessionInfo struct { type SessionInfo struct {

View File

@ -6,7 +6,7 @@ import (
type Client struct { type Client struct {
PublicId string PublicId string
ClientId int ClientId string
StartTime time.Time StartTime time.Time
SessionType string SessionType string
} }

View File

@ -46,7 +46,7 @@ func NewClient(publicId string, clientConn iowrappers2.ReadWriteAddrCloser,
return &ClientConnection{ return &ClientConnection{
Client: models.Client{ Client: models.Client{
PublicId: publicId, PublicId: publicId,
ClientId: clientIdGenerator.IncrementAndGet(), ClientId: strconv.Itoa(clientIdGenerator.IncrementAndGet()),
StartTime: time.Now(), StartTime: time.Now(),
}, },
agent: agentConn, agent: agentConn,
@ -107,7 +107,7 @@ func (admin *Admin) logStatus() {
lines = append(lines, fmt.Sprintf(format, "CLIENT", "AGENT", "ACTIVE_SINCE", "REMOTE_ADDRESS", "SESSION_TYPE")) lines = append(lines, fmt.Sprintf(format, "CLIENT", "AGENT", "ACTIVE_SINCE", "REMOTE_ADDRESS", "SESSION_TYPE"))
for _, client := range admin.clients { for _, client := range admin.clients {
lines = append(lines, fmt.Sprintf(format, lines = append(lines, fmt.Sprintf(format,
strconv.Itoa(client.ClientId), client.ClientId,
client.PublicId, client.PublicId,
client.StartTime.Format(time.DateTime), client.StartTime.Format(time.DateTime),
client.client.RemoteAddr(), client.client.RemoteAddr(),
@ -248,7 +248,7 @@ func (admin *Admin) RemoveClient(client *ClientConnection) error {
admin.mutex.Lock() admin.mutex.Lock()
defer admin.mutex.Unlock() defer admin.mutex.Unlock()
log.Printf("Removing client: '%d' created at %s\n", client.ClientId, log.Printf("Removing client: '%s' created at %s\n", client.ClientId,
client.StartTime.Format(time.DateTime)) client.StartTime.Format(time.DateTime))
// try to explicitly close connection to the agent. // try to explicitly close connection to the agent.
_ = client.agent.Close() _ = client.agent.Close()
@ -293,7 +293,7 @@ func (admin *Admin) Register(publicId string, conn io.ReadWriteCloser) error {
for _, client := range admin.clients { for _, client := range admin.clients {
// a bit hacky. There should be at most one client that has an unset session // a bit hacky. There should be at most one client that has an unset session
// Very unlikely for multiple sessions to start at the same point in time. // Very unlikely for multiple sessions to start at the same point in time.
if strconv.Itoa(client.ClientId) == session.ClientId { if client.ClientId == session.ClientId {
client.SessionType = session.SessionType client.SessionType = session.SessionType
break break
} }

View File

@ -2,7 +2,6 @@ package templates
import ( import (
"converge/pkg/models" "converge/pkg/models"
"strconv"
"time" "time"
_ "time/tzdata" _ "time/tzdata"
) )
@ -75,7 +74,7 @@ templ State(state *models.State, location *time.Location) {
</thead> </thead>
for _, client := range state.Clients { for _, client := range state.Clients {
<tr> <tr>
<td>{strconv.Itoa(client.ClientId)}</td> <td>{client.ClientId}</td>
<td>{client.StartTime.In(location).Format(time.DateTime)}</td> <td>{client.StartTime.In(location).Format(time.DateTime)}</td>
<td>{client.SessionType}</td> <td>{client.SessionType}</td>
<td>{client.PublicId}</td> <td>{client.PublicId}</td>