Skip to content

Commit 021eade

Browse files
committed
Add port into logging
1 parent 6becc5c commit 021eade

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

apps/matching-service/handlers/websocket.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"matching-service/processes"
88
"matching-service/utils"
99
"net/http"
10+
"strings"
1011
"sync"
1112

1213
"github.com/gorilla/websocket"
@@ -99,7 +100,13 @@ func readMatchRequest(ws *websocket.Conn) (models.MatchRequest, error) {
99100
if err := ws.ReadJSON(&matchRequest); err != nil {
100101
return matchRequest, err
101102
}
102-
log.Printf("Received match request: %v", matchRequest)
103+
// Get the remote address (client's IP and port)
104+
clientAddr := ws.RemoteAddr().String()
105+
106+
// Extract the port (after the last ':')
107+
clientPort := clientAddr[strings.LastIndex(clientAddr, ":")+1:]
108+
109+
log.Printf("Received match request: %v from client port: %s", matchRequest, clientPort)
103110
return matchRequest, nil
104111
}
105112

@@ -137,7 +144,6 @@ func waitForResult(ws *websocket.Conn, ctx, timeoutCtx, matchCtx context.Context
137144
return
138145
}
139146
log.Println("Match found for user: " + result.User)
140-
141147
// Notify the users about the match
142148
notifyMatch(result.User, result.MatchedUser, result)
143149

@@ -185,7 +191,7 @@ func notifyMatch(username, matchedUsername string, result models.MatchFound) {
185191

186192
if cancelFunc, exists := matchContexts[matchedUsername]; exists {
187193
delete(matchContexts, matchedUsername)
188-
cancelFunc()
194+
defer cancelFunc() // TODO: CancelFunction here is not causing the matchCtx to be done
189195
}
190196

191197
// Remove users from the activeConnections map

0 commit comments

Comments
 (0)