(packet *Packet)
| 314 | } |
| 315 | |
| 316 | func (c *ForwardCtx) handleNewConnection(packet *Packet) { |
| 317 | newConnectionPacket, err := c.unmarshalNewConnection(packet.Payload) |
| 318 | if err != nil { |
| 319 | c.logger.Error("Error unmarshalling new connection payload", err) |
| 320 | return |
| 321 | } |
| 322 | pipeReader, pipeWriter := io.Pipe() |
| 323 | connection := Connection{ |
| 324 | state: CONNECTION_STATE_WAITINIT, |
| 325 | id: packet.ConnectionId, |
| 326 | details: newConnectionPacket, |
| 327 | bufferReader: pipeReader, |
| 328 | bufferWriter: pipeWriter, |
| 329 | ctx: c, |
| 330 | logger: c.logger, |
| 331 | } |
| 332 | connection.stateCond = sync.NewCond(&connection.lock) |
| 333 | c.connMapMu.Lock() |
| 334 | if _, ok := c.connMap[packet.ConnectionId]; ok { |
| 335 | c.logger.Warning("Remote tried to open connection with re-used connectionId") |
| 336 | // Cannot send reject here, might interfere with other connection ? |
| 337 | c.connMapMu.Unlock() |
| 338 | return |
| 339 | } |
| 340 | if packet.ConnectionId <= c.connectionId { |
| 341 | c.logger.Warning("Suspicious connection, id <= prev") |
| 342 | // Can't send reject here either |
| 343 | c.connMapMu.Unlock() |
| 344 | return |
| 345 | } |
| 346 | if packet.ConnectionId != c.connectionId+1 { |
| 347 | c.logger.Warning("Suspicious connection, id not prev + 1") |
| 348 | } |
| 349 | |
| 350 | c.connectionId = packet.ConnectionId |
| 351 | c.connMap[packet.ConnectionId] = &connection |
| 352 | c.waitGroup.Add(1) |
| 353 | c.connMapMu.Unlock() |
| 354 | |
| 355 | if c.stopped { |
| 356 | c.logger.Warning("Client tried opening a connection after stopping") |
| 357 | _ = connection.Reject() |
| 358 | return |
| 359 | } |
| 360 | |
| 361 | c.connectionChannel <- &connection |
| 362 | } |
| 363 | |
| 364 | func (c *ForwardCtx) handleBackend() { |
| 365 | for { |
no test coverage detected