diff --git a/.travis.yml b/.travis.yml index 8a0a83b3..25fe76f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: java +dist: trusty jdk: - oraclejdk8 install: true diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java index 93a6292f..8673c7b3 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java @@ -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 @@ -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);