Improve nomination

This implements a basic validation schema using a checklist. We try
every pair at least maxTries, and mark it as failed if we don't get a
success response after that many requests. Once we get a success
response, we check if it belongs to the best candidate available so far,
if it does we nominate it, otherwise we continue.

Also, after a given timeout, if no candidate has been nominated, we
simply choose the best valid candidate we got so far (if no candidate is
valid, we mark the connection as failed).

Finally, the nomination request also has a maximum of maxTries, we mark
the connection as failed if after that many attempt we fail to get a
success response.
This commit is contained in:
Hugo Arregui
2019-05-14 16:20:17 -03:00
committed by Sean DuBois
parent a58a281d3a
commit bf57064619
5 changed files with 311 additions and 90 deletions

View File

@@ -35,11 +35,11 @@ func TestPairSearch(t *testing.T) {
t.Fatalf("Error constructing ice.Agent")
}
if len(a.validPairs) != 0 {
if len(a.checklist) != 0 {
t.Fatalf("TestPairSearch is only a valid test if a.validPairs is empty on construction")
}
cp := a.getBestValidPair()
cp := a.getBestAvailableCandidatePair()
if cp != nil {
t.Fatalf("No Candidate pairs should exist")
@@ -110,8 +110,14 @@ func TestPairPriority(t *testing.T) {
}
for _, remote := range []Candidate{relayRemote, srflxRemote, prflxRemote, hostRemote} {
a.addValidPair(hostLocal, remote)
bestPair := a.getBestValidPair()
p := a.findPair(hostLocal, remote)
if p == nil {
p = a.addPair(hostLocal, remote)
}
p.state = candidatePairStateValid
bestPair := a.getBestValidCandidatePair()
if bestPair.String() != (&candidatePair{remote: remote, local: hostLocal}).String() {
t.Fatalf("Unexpected bestPair %s (expected remote: %s)", bestPair, remote)
}