MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / handleControlStream

Function handleControlStream

lambda/main.go:264–300  ·  view source on GitHub ↗
(stream quic.Stream, done chan<- error)

Source from the content-addressed store, hash-verified

262}
263
264func handleControlStream(stream quic.Stream, done chan<- error) {
265 defer stream.Close()
266 shared.LogNetwork("Control stream established")
267
268 for {
269 opcode, nonce, err := shared.ReadControlMessage(stream)
270 if err != nil {
271 // EOF is expected when client disconnects - treat as normal shutdown
272 if err == io.EOF || errors.Is(err, io.EOF) {
273 shared.LogNetwork("Control stream EOF - client disconnected normally")
274 done <- nil
275 return
276 }
277 shared.LogError("Failed to read control message", err)
278 // Signal completion on control stream error
279 done <- err
280 return
281 }
282
283 switch opcode {
284 case shared.OpPing:
285 // Respond with pong
286 if err := shared.WritePong(stream, nonce); err != nil {
287 shared.LogError("Failed to send pong", err)
288 return
289 }
290
291 case shared.OpShutdown:
292 shared.LogNetwork("Received shutdown signal, exiting immediately")
293 done <- nil
294 return
295
296 default:
297 shared.LogErrorf("Unknown control opcode: %02x", opcode)
298 }
299 }
300}
301
302func handleSOCKS5Stream(stream quic.Stream) {
303 defer stream.Close()

Callers 1

handleQUICConnectionFunction · 0.85

Calls 5

LogNetworkFunction · 0.92
ReadControlMessageFunction · 0.92
LogErrorFunction · 0.92
WritePongFunction · 0.92
LogErrorfFunction · 0.92

Tested by

no test coverage detected