Report connections

pull/206/head
M66B 3 years ago
parent ca2d0f7d60
commit 1c8e16f794

@ -636,7 +636,7 @@ public class Protocol {
} }
socket = null; socket = null;
if (traceInput != null && traceOutput != null) if (traceInput != null && traceOutput != null)
eu.faircode.email.TrafficStatsHelper.report(host, "IMAP", eu.faircode.email.TrafficStatsHelper.report(host, prefix,
traceOutput.getSent(), traceInput.getReceived()); traceOutput.getSent(), traceInput.getReceived());
} }
} }

@ -807,7 +807,7 @@ class Protocol {
if (socket != null) if (socket != null)
socket.close(); socket.close();
if (traceInput != null && traceOutput != null) if (traceInput != null && traceOutput != null)
eu.faircode.email.TrafficStatsHelper.report(host, "POP3", eu.faircode.email.TrafficStatsHelper.report(host, prefix,
traceOutput.getSent(), traceInput.getReceived()); traceOutput.getSent(), traceInput.getReceived());
} catch (IOException ex) { } catch (IOException ex) {
// ignore it // ignore it

@ -1473,7 +1473,7 @@ public class SMTPTransport extends Transport {
serverInput = null; serverInput = null;
lineInputStream = null; lineInputStream = null;
if (traceInput != null && traceOutput != null) if (traceInput != null && traceOutput != null)
eu.faircode.email.TrafficStatsHelper.report(host, "SMTP", eu.faircode.email.TrafficStatsHelper.report(host, name,
traceOutput.getSent(), traceInput.getReceived()); traceOutput.getSent(), traceInput.getReceived());
if (super.isConnected()) // only notify if already connected if (super.isConnected()) // only notify if already connected
super.close(); super.close();

@ -347,6 +347,7 @@ public class SocketFetcher {
socket.connect(new InetSocketAddress(iaddr, port), cto); socket.connect(new InetSocketAddress(iaddr, port), cto);
else else
socket.connect(new InetSocketAddress(iaddr, port)); socket.connect(new InetSocketAddress(iaddr, port));
eu.faircode.email.TrafficStatsHelper.connect(host, port, prefix);
eu.faircode.email.Log.i("Socket connected" + eu.faircode.email.Log.i("Socket connected" +
" local=" + socket.getLocalSocketAddress() + " local=" + socket.getLocalSocketAddress() +
" remote=" + socket.getRemoteSocketAddress()); " remote=" + socket.getRemoteSocketAddress());

@ -28,8 +28,16 @@ public class TrafficStatsHelper {
ctx = context; ctx = context;
} }
public static void report(String host, String protocol, long sent, long received) { public static void connect(String host, int port, String prefix) {
String msg = protocol + " " + host + " tx=" + sent + " rx=" + received; String msg = "Connected " + prefix + " " + host + ":" + port;
if (ctx == null)
Log.i(msg);
else
EntityLog.log(ctx, EntityLog.Type.Statistics, msg);
}
public static void report(String host, String prefix, long sent, long received) {
String msg = "Disconnected " + prefix + " " + host + " tx=" + sent + " rx=" + received;
if (ctx == null) if (ctx == null)
Log.i(msg); Log.i(msg);
else else

Loading…
Cancel
Save