mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 04:35:57 +00:00
Log transfer stats
This commit is contained in:
parent
6bc8576636
commit
f1cae5839e
7 changed files with 67 additions and 5 deletions
|
@ -635,6 +635,9 @@ public class Protocol {
|
||||||
// ignore it
|
// ignore it
|
||||||
}
|
}
|
||||||
socket = null;
|
socket = null;
|
||||||
|
if (traceInput != null && traceOutput != null)
|
||||||
|
eu.faircode.email.TrafficStatsHelper.report(host, "IMAP",
|
||||||
|
traceOutput.getSent(), traceInput.getReceived());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -806,6 +806,9 @@ class Protocol {
|
||||||
try {
|
try {
|
||||||
if (socket != null)
|
if (socket != null)
|
||||||
socket.close();
|
socket.close();
|
||||||
|
if (traceInput != null && traceOutput != null)
|
||||||
|
eu.faircode.email.TrafficStatsHelper.report(host, "POP3",
|
||||||
|
traceOutput.getSent(), traceInput.getReceived());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
// ignore it
|
// ignore it
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -1472,6 +1472,9 @@ public class SMTPTransport extends Transport {
|
||||||
serverOutput = null;
|
serverOutput = null;
|
||||||
serverInput = null;
|
serverInput = null;
|
||||||
lineInputStream = null;
|
lineInputStream = null;
|
||||||
|
if (traceInput != null && traceOutput != null)
|
||||||
|
eu.faircode.email.TrafficStatsHelper.report(host, "SMTP",
|
||||||
|
traceOutput.getSent(), traceInput.getReceived());
|
||||||
if (super.isConnected()) // only notify if already connected
|
if (super.isConnected()) // only notify if already connected
|
||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ public class TraceInputStream extends FilterInputStream {
|
||||||
private boolean quote = false;
|
private boolean quote = false;
|
||||||
private OutputStream traceOut;
|
private OutputStream traceOut;
|
||||||
|
|
||||||
|
private long pos = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an input stream filter built on top of the specified
|
* Creates an input stream filter built on top of the specified
|
||||||
* input stream.
|
* input stream.
|
||||||
|
@ -82,6 +84,7 @@ public class TraceInputStream extends FilterInputStream {
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
int b = in.read();
|
int b = in.read();
|
||||||
|
pos++;
|
||||||
if (trace && b != -1) {
|
if (trace && b != -1) {
|
||||||
if (quote)
|
if (quote)
|
||||||
writeByte(b);
|
writeByte(b);
|
||||||
|
@ -100,6 +103,7 @@ public class TraceInputStream extends FilterInputStream {
|
||||||
@Override
|
@Override
|
||||||
public int read(byte b[], int off, int len) throws IOException {
|
public int read(byte b[], int off, int len) throws IOException {
|
||||||
int count = in.read(b, off, len);
|
int count = in.read(b, off, len);
|
||||||
|
pos += count;
|
||||||
if (trace && count != -1) {
|
if (trace && count != -1) {
|
||||||
if (quote) {
|
if (quote) {
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
|
@ -137,4 +141,8 @@ public class TraceInputStream extends FilterInputStream {
|
||||||
traceOut.write(b);
|
traceOut.write(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getReceived() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,8 @@ public class TraceOutputStream extends FilterOutputStream {
|
||||||
private boolean quote = false;
|
private boolean quote = false;
|
||||||
private OutputStream traceOut;
|
private OutputStream traceOut;
|
||||||
|
|
||||||
private int pos = 0;
|
private long pos = 0;
|
||||||
|
private long base = 0;
|
||||||
private int last = 0;
|
private int last = 0;
|
||||||
private int total = 0;
|
private int total = 0;
|
||||||
private IReport reporter = null;
|
private IReport reporter = null;
|
||||||
|
@ -153,15 +154,20 @@ public class TraceOutputStream extends FilterOutputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getSent() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
void report() {
|
void report() {
|
||||||
if (reporter != null && pos - last > 1024) {
|
int p = (int) (pos - base);
|
||||||
last = pos;
|
if (reporter != null && p - last > 1024) {
|
||||||
reporter.report(pos, total);
|
last = p;
|
||||||
|
reporter.report(p, total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReporter(int total, IReport reporter) {
|
public void setReporter(int total, IReport reporter) {
|
||||||
this.pos = 0;
|
this.base = pos;
|
||||||
this.last = 0;
|
this.last = 0;
|
||||||
this.total = total;
|
this.total = total;
|
||||||
this.reporter = reporter;
|
this.reporter = reporter;
|
||||||
|
|
|
@ -190,6 +190,7 @@ public class ApplicationEx extends Application
|
||||||
if (Helper.hasWebView(this))
|
if (Helper.hasWebView(this))
|
||||||
CookieManager.getInstance().setAcceptCookie(false);
|
CookieManager.getInstance().setAcceptCookie(false);
|
||||||
|
|
||||||
|
TrafficStatsHelper.init(this);
|
||||||
EncryptionHelper.init(this);
|
EncryptionHelper.init(this);
|
||||||
MessageHelper.setSystemProperties(this);
|
MessageHelper.setSystemProperties(this);
|
||||||
|
|
||||||
|
|
38
app/src/main/java/eu/faircode/email/TrafficStatsHelper.java
Normal file
38
app/src/main/java/eu/faircode/email/TrafficStatsHelper.java
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of FairEmail.
|
||||||
|
|
||||||
|
FairEmail is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
FairEmail is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
public class TrafficStatsHelper {
|
||||||
|
private static Context ctx;
|
||||||
|
|
||||||
|
static void init(Context context) {
|
||||||
|
ctx = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void report(String host, String protocol, long sent, long received) {
|
||||||
|
String msg = protocol + " " + host + " tx=" + sent + " rx=" + received;
|
||||||
|
if (ctx == null)
|
||||||
|
Log.i(msg);
|
||||||
|
else
|
||||||
|
EntityLog.log(ctx, EntityLog.Type.Statistics, msg);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue