|
7 | 7 | "matching-service/processes"
|
8 | 8 | "matching-service/utils"
|
9 | 9 | "net/http"
|
| 10 | + "strings" |
10 | 11 | "sync"
|
11 | 12 |
|
12 | 13 | "github.com/gorilla/websocket"
|
@@ -99,7 +100,13 @@ func readMatchRequest(ws *websocket.Conn) (models.MatchRequest, error) {
|
99 | 100 | if err := ws.ReadJSON(&matchRequest); err != nil {
|
100 | 101 | return matchRequest, err
|
101 | 102 | }
|
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) |
103 | 110 | return matchRequest, nil
|
104 | 111 | }
|
105 | 112 |
|
@@ -137,7 +144,6 @@ func waitForResult(ws *websocket.Conn, ctx, timeoutCtx, matchCtx context.Context
|
137 | 144 | return
|
138 | 145 | }
|
139 | 146 | log.Println("Match found for user: " + result.User)
|
140 |
| - |
141 | 147 | // Notify the users about the match
|
142 | 148 | notifyMatch(result.User, result.MatchedUser, result)
|
143 | 149 |
|
@@ -185,7 +191,7 @@ func notifyMatch(username, matchedUsername string, result models.MatchFound) {
|
185 | 191 |
|
186 | 192 | if cancelFunc, exists := matchContexts[matchedUsername]; exists {
|
187 | 193 | delete(matchContexts, matchedUsername)
|
188 |
| - cancelFunc() |
| 194 | + defer cancelFunc() // TODO: CancelFunction here is not causing the matchCtx to be done |
189 | 195 | }
|
190 | 196 |
|
191 | 197 | // Remove users from the activeConnections map
|
|
0 commit comments