Commit a62d5f31 authored by akwizgran's avatar akwizgran

Socket timeout should always be longer than keepalive interval.

parent b6a2e78c
......@@ -18,7 +18,7 @@ interface Constants {
String EXTRA_ALARM_TYPE = "org.briarproject.snooze.EXTRA_ALARM_TYPE";
int SOCKET_TIMEOUT_MS = 2 * 60 * 1000;
int SOCKET_TIMEOUT_MS = 60 * 1000;
int CONNECT_TIMEOUT_MS = 30 * 1000;
......
......@@ -34,7 +34,7 @@ class Logger implements FileLogger.LogLoadedCallback {
this.appContext = appContext;
this.tag = tag;
handler = new Handler(appContext.getMainLooper());
fileLogger = new FileLogger(new File(appContext.getFilesDir(), tag + ".onMessageLogged"), this);
fileLogger = new FileLogger(new File(appContext.getFilesDir(), tag + ".log"), this);
fileLogger.start();
logInitialMessages();
}
......
......@@ -20,14 +20,14 @@ class NetworkClient extends Thread {
private static final String LOCK_TAG = NetworkClient.class.getName();
private final String host;
private final int port, keepaliveIntervalSecs;
private final int port, keepaliveIntervalMs;
private final Logger log;
private final PowerManager.WakeLock wakeLock;
NetworkClient(String host, int port, int keepaliveIntervalMs, Context appContext) {
this.host = host;
this.port = port;
keepaliveIntervalSecs = (keepaliveIntervalMs / 1000);
this.keepaliveIntervalMs = keepaliveIntervalMs;
log = ((SnoozeApplication) appContext).getLogger();
PowerManager pm = (PowerManager) appContext.getSystemService(POWER_SERVICE);
wakeLock = pm.newWakeLock(PARTIAL_WAKE_LOCK, LOCK_TAG);
......@@ -41,14 +41,14 @@ class NetworkClient extends Thread {
while (!isInterrupted()) {
Socket s = new Socket();
try {
s.setSoTimeout(SOCKET_TIMEOUT_MS);
log.log("Connecting to " + host + ":" + port);
s.setSoTimeout(SOCKET_TIMEOUT_MS + keepaliveIntervalMs);
s.connect(new InetSocketAddress(host, port), CONNECT_TIMEOUT_MS);
log.log("Requesting keepalives every " + (keepaliveIntervalMs / 1000) + " seconds");
DataOutputStream out = new DataOutputStream(s.getOutputStream());
InputStream in = s.getInputStream();
log.log("Requesting keepalives every " + keepaliveIntervalSecs + " seconds");
out.writeShort(keepaliveIntervalSecs);
out.writeShort(keepaliveIntervalMs / 1000);
out.flush();
InputStream in = s.getInputStream();
for (int read = 0; read != -1 && !isInterrupted(); read = in.read(buf)) {
wakeLock.acquire();
log.log("Read " + read + " bytes");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment