Report connections

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

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

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

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

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

@ -28,8 +28,16 @@ public class TrafficStatsHelper {
ctx = context;
}
public static void report(String host, String protocol, long sent, long received) {
String msg = protocol + " " + host + " tx=" + sent + " rx=" + received;
public static void connect(String host, int port, String prefix) {
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)
Log.i(msg);
else

Loading…
Cancel
Save