Application layer keepalives to detect dead TCP connections.

DuplexOutgoingSession flushes its output stream if it's idle for a
transport-defined interval, causing an empty frame to be sent. The TCP
and Tor plugins use a socket timeout equal to twice the idle interval to
detect dead connections.

See bugs #27, #46 and #60.
This commit is contained in:
akwizgran
2014-12-13 12:00:40 +00:00
parent 3a70aa7653
commit d4fa656dbb
19 changed files with 95 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
package org.briarproject.messaging;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
@@ -54,6 +55,7 @@ import org.briarproject.api.messaging.TransportUpdate;
*/
class DuplexOutgoingSession implements MessagingSession, EventListener {
private static final int MAX_IDLE_TIME = 30 * 1000; // Milliseconds
private static final Logger LOG =
Logger.getLogger(DuplexOutgoingSession.class.getName());
@@ -108,7 +110,12 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
while(!interrupted) {
// Flush the stream if it's going to be idle
if(writerTasks.isEmpty()) out.flush();
ThrowingRunnable<IOException> task = writerTasks.take();
ThrowingRunnable<IOException> task = writerTasks.poll(
MAX_IDLE_TIME, MILLISECONDS);
if(task == null) {
LOG.info("Idle timeout");
continue; // Flush and wait again
}
if(task == CLOSE) break;
task.run();
}