final InetSocketAddress localAddress = (InetSocketAddress) controlConnection.getLocalSocketAddress();
final ConnectionListener connectionListener = new ConnectionListener(localAddress.getAddress(),
localAddress.getPort());
logger.debug("Starting hole puncher"); //$NON-NLS-1$
final SourceConnectionAuthenticator authentification = new SourceConnectionAuthenticator(token.getToken());
final HolePuncher hp = new HolePuncher(connectionListener, localAddress, socketQueue);
this.startHolePunching(addresses, authentification, hp);
boolean interrupted = false;
try {
while (result == null) {
try {
result = socketQueue.take();
} catch (final InterruptedException e) {
interrupted = true;
// fall through and retry
logger.info("InterruptedException (fall through and retry)");
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
connectionListener.shutdown();
hp.shutdownNow();
// received dummy socket for indicating time limit exceeded
if (!result.isConnected()) {
throw new IOException("Could not get socket to: " + targetId);
}
logger.info("Returning socket: {}", result);