mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user