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:
Sean DuBois
2019-04-15 15:37:10 -07:00
parent df66c58d56
commit 7fa75afc59
2 changed files with 19 additions and 11 deletions
+8 -4
View File
@@ -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
View File
@@ -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.