Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/#26 remove gathering timeout #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: java
dist: trusty
jdk:
- oraclejdk8
install: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,53 +101,17 @@ private void gatherCandidates() {
.forEach(agent::addCandidateHarvester)
);

CompletableFuture gatheringFuture = CompletableFuture.runAsync(() -> {
try {
component = agent.createComponent(mediaStream, Transport.UDP, MINIMUM_PORT + (int) (Math.random() * 999.0), MINIMUM_PORT, MINIMUM_PORT + 1000);
} catch (IOException e) {
throw new RuntimeException(e);
}
});

Executor.executeDelayed(5000, () -> {
if(! gatheringFuture.isDone()) {
gatheringFuture.cancel(true);
}
});

try {
gatheringFuture.join();
} catch(CompletionException e) {
//Completed exceptionally
log.error(getLogPrefix() + "Error while creating stream component/gathering candidates", e);
new Thread(this::onConnectionLost).start();
return;
} catch(CancellationException e) {
//was cancelled due to timeout
log.error(getLogPrefix() + "Gathering candidates timed out", e);
new Thread(this::onConnectionLost).start();
return;
component = agent.createComponent(mediaStream, Transport.UDP, MINIMUM_PORT + (int) (Math.random() * 999.0), MINIMUM_PORT, MINIMUM_PORT + 1000);
} catch (IOException e) {
throw new RuntimeException(e);
}


int previousConnectivityAttempts = getConnectivityAttempsInThePast(FORCE_SRFLX_RELAY_INTERVAL);
CandidatesMessage localCandidatesMessage = CandidateUtil.packCandidates(IceAdapter.id, peer.getRemoteId(), agent, component, previousConnectivityAttempts < FORCE_SRFLX_COUNT && IceAdapter.ALLOW_HOST, previousConnectivityAttempts < FORCE_RELAY_COUNT && IceAdapter.ALLOW_REFLEXIVE, IceAdapter.ALLOW_RELAY);
log.debug(getLogPrefix() + "Sending own candidates to {}", peer.getRemoteId());
setState(AWAITING_CANDIDATES);
RPCService.onIceMsg(localCandidatesMessage);

//TODO: is this a good fix for awaiting candidates loop????
//Make sure to abort the connection process and reinitiate when we haven't received an answer to our offer in 6 seconds, candidate packet was probably lost
final int currentacei = ++awaitingCandidatesEventId;
Executor.executeDelayed(6000, () -> {
if(peer.isClosing()) {
log.warn(getLogPrefix() + "Peer {} not connected anymore, aborting reinitiation of ICE", peer.getRemoteId());
return;
}
if (iceState == AWAITING_CANDIDATES && currentacei == awaitingCandidatesEventId) {
onConnectionLost();
}
});
}

//How often have we been waiting for a response to local candidates/offer
Expand Down Expand Up @@ -205,28 +169,22 @@ private void startIce() {

//Wait for termination/completion of the agent
long iceStartTime = System.currentTimeMillis();
while (agent.getState() != IceProcessingState.COMPLETED) {//TODO include more?, maybe stop on COMPLETED, is that to early?
while (!agent.getState().isOver()) {
try {
Thread.sleep(20);
} catch (InterruptedException e) {
log.error(getLogPrefix() + "Interrupted while waiting for ICE", e);
}
}

if (agent.getState() == IceProcessingState.FAILED) {//TODO null pointer due to no agent?
onConnectionLost();
return;
}

log.debug(getLogPrefix() + "ICE connectivity " + agent.getState().toString());

if(System.currentTimeMillis() - iceStartTime > 15_000) {
log.error(getLogPrefix() + "ABORTING ICE DUE TO TIMEOUT");
onConnectionLost();
return;
}
if(agent.getState() == IceProcessingState.FAILED || agent.getState() == IceProcessingState.TERMINATED)
{
onConnectionLost();
return;
}

log.debug(getLogPrefix() + "ICE terminated");

//We are connected
connected = true;
RPCService.onConnected(IceAdapter.id, peer.getRemoteId(), true);
Expand Down