mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Discard non-STUN if no associated candidate
If a inbound message is not associated with a valid remote STUN candidate discard it Resolves #20
This commit is contained in:
@@ -654,12 +654,16 @@ func (a *Agent) handleInbound(m *stun.Message, local *Candidate, remote net.Addr
|
||||
}
|
||||
}
|
||||
|
||||
// noSTUNSeen processes non STUN traffic from a remote candidate
|
||||
func (a *Agent) noSTUNSeen(local *Candidate, remote net.Addr) {
|
||||
// noSTUNSeen processes non STUN traffic from a remote candidate,
|
||||
// and returns true if it is an actual remote candidate
|
||||
func (a *Agent) noSTUNSeen(local *Candidate, remote net.Addr) bool {
|
||||
remoteCandidate := a.findRemoteCandidate(local.NetworkType, remote)
|
||||
if remoteCandidate != nil {
|
||||
remoteCandidate.seen(false)
|
||||
if remoteCandidate == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
remoteCandidate.seen(false)
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *Agent) getBestPair() (*candidatePair, error) {
|
||||
|
||||
+11
-7
@@ -188,13 +188,17 @@ func (c *Candidate) recvLoop() {
|
||||
}
|
||||
|
||||
continue
|
||||
} else {
|
||||
err = c.agent.run(func(agent *Agent) {
|
||||
agent.noSTUNSeen(c, srcAddr)
|
||||
})
|
||||
if err != nil {
|
||||
log.Warnf("Failed to handle message: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
isValidRemoteCandidate := make(chan bool, 1)
|
||||
err = c.agent.run(func(agent *Agent) {
|
||||
isValidRemoteCandidate <- agent.noSTUNSeen(c, srcAddr)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Warnf("Failed to handle message: %v", err)
|
||||
} else if !<-isValidRemoteCandidate {
|
||||
log.Warnf("Discarded message from %s, not a valid remote candidate", c.addr())
|
||||
}
|
||||
|
||||
// NOTE This will return packetio.ErrFull if the buffer ever manages to fill up.
|
||||
|
||||
Reference in New Issue
Block a user