(buf []byte, srcAddr net.Addr)
| 320 | } |
| 321 | |
| 322 | func (c *candidateBase) handleInboundPacket(buf []byte, srcAddr net.Addr) { |
| 323 | agent := c.agent() |
| 324 | |
| 325 | if stun.IsMessage(buf) { |
| 326 | msg := &stun.Message{ |
| 327 | Raw: make([]byte, len(buf)), |
| 328 | } |
| 329 | |
| 330 | // Explicitly copy raw buffer so Message can own the memory. |
| 331 | copy(msg.Raw, buf) |
| 332 | |
| 333 | if err := msg.Decode(); err != nil { |
| 334 | agent.log.Warnf("Failed to handle decode ICE from %s to %s: %v", c.addr(), srcAddr, err) |
| 335 | |
| 336 | return |
| 337 | } |
| 338 | |
| 339 | if err := agent.loop.Run(c, func(_ context.Context) { |
| 340 | // nolint: contextcheck |
| 341 | agent.handleInbound(msg, c, srcAddr) |
| 342 | }); err != nil { |
| 343 | agent.log.Warnf("Failed to handle message: %v", err) |
| 344 | } |
| 345 | |
| 346 | return |
| 347 | } |
| 348 | |
| 349 | if !c.validateSTUNTrafficCache(srcAddr) { |
| 350 | remoteCandidate, valid := agent.validateNonSTUNTraffic(c, srcAddr) //nolint:contextcheck |
| 351 | if !valid { |
| 352 | agent.log.Warnf("Discarded message from %s, not a valid remote candidate", c.addr()) |
| 353 | |
| 354 | return |
| 355 | } |
| 356 | c.addRemoteCandidateCache(remoteCandidate, srcAddr) |
| 357 | } |
| 358 | |
| 359 | // Note: This will return packetio.ErrFull if the buffer ever manages to fill up. |
| 360 | n, err := agent.buf.Write(buf) |
| 361 | if err != nil { |
| 362 | agent.log.Warnf("Failed to write packet: %s", err) |
| 363 | |
| 364 | return |
| 365 | } |
| 366 | |
| 367 | // Add received application bytes to the currently selected candidate pair. |
| 368 | if n > 0 { |
| 369 | if sp := agent.getSelectedPair(); sp != nil { |
| 370 | sp.UpdatePacketReceived(n) |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // close stops the recvLoop. |
| 376 | func (c *candidateBase) close() error { |
no test coverage detected