Skip to content

Commit 043acfa

Browse files
committed
Reduce unnecessary repetitive logging
This was sort of useful when debugging low-level session handling, but it's incredibly noisy with real traffic, to the point that it affects performance on device substantially when during dev & testing. Better to focus logging on the major events: conn setup, teardown & errors.
1 parent 6a8c1de commit 043acfa

File tree

6 files changed

+10
-48
lines changed

6 files changed

+10
-48
lines changed

app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ class ProxyVpnService : VpnService(), IProtectSocket {
192192
}
193193

194194
private fun stopVpn() {
195+
Log.i(TAG, "VPN stopping..")
196+
195197
if (vpnRunnable != null) {
196198
app!!.trackEvent("VPN", "vpn-stopped")
197199
app!!.resumeEvents()

app/src/main/java/tech/httptoolkit/android/vpn/ClientPacketWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public ClientPacketWriter(FileOutputStream clientWriter) {
5151

5252
public void write(byte[] data) {
5353
if (data.length > 30000) throw new Error("Packet too large");
54-
Log.i(TAG, "Putting " + data.length + " bytes on the write queue");
5554
packetQueue.addLast(data);
5655
}
5756

app/src/main/java/tech/httptoolkit/android/vpn/SessionHandler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ private void handleUDPPacket(ByteBuffer clientPacketData, IPv4Header ipHeader) t
115115
int len = manager.addClientData(clientPacketData, session);
116116
session.setDataForSendingReady(true);
117117

118-
Log.i(TAG, "Subscribe UDP to OP_WRITE");
119118
// Ping the NIO thread to write this, when the session is next writable
120119
session.subscribeKey(SelectionKey.OP_WRITE);
121120
nioService.refreshSelect(session);
122-
Log.d(TAG,"added UDP data for bg worker to send: "+len);
123121
}
124122

125123
manager.keepSessionAlive(session);
@@ -140,7 +138,7 @@ private void handleTCPPacket(ByteBuffer clientPacketData, IPv4Header ipHeader) t
140138
String key = Session.getSessionKey(destinationIP, destinationPort, sourceIP, sourcePort);
141139
Session session = manager.getSessionByKey(key);
142140

143-
if(session == null) {
141+
if (session == null) {
144142
Log.w(TAG, "Ack for unknown session: " + key);
145143
if (tcpheader.isFIN()) {
146144
sendLastAck(ipHeader, tcpheader);
@@ -286,9 +284,6 @@ private void pushDataToDestination(Session session, TCPHeader tcp){
286284
// Ping the NIO thread to write this, when the session is next writable
287285
session.subscribeKey(SelectionKey.OP_WRITE);
288286
nioService.refreshSelect(session);
289-
290-
Log.d(TAG,"set data ready for sending to dest, bg will do it. data size: "
291-
+ session.getSendingDataSize());
292287
}
293288

294289
/**
@@ -300,7 +295,6 @@ private void pushDataToDestination(Session session, TCPHeader tcp){
300295
*/
301296
private void sendAck(IPv4Header ipheader, TCPHeader tcpheader, int acceptedDataLength, Session session){
302297
long acknumber = session.getRecSequence() + acceptedDataLength;
303-
Log.d(TAG,"sent ack, ack# "+session.getRecSequence()+" + "+acceptedDataLength+" = "+acknumber);
304298
session.setRecSequence(acknumber);
305299
byte[] data = TCPPacketFactory.createResponseAckData(ipheader, tcpheader, acknumber);
306300

app/src/main/java/tech/httptoolkit/android/vpn/socket/SocketChannelReader.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public SocketChannelReader(ClientPacketWriter writer) {
4545
public void read(Session session) {
4646
AbstractSelectableChannel channel = session.getChannel();
4747

48-
Log.d(TAG, "Reading from session " + session);
49-
5048
if(channel instanceof SocketChannel) {
5149
readTCP(session);
5250
} else if(channel instanceof DatagramChannel){
@@ -58,7 +56,7 @@ public void read(Session session) {
5856
// Resubscribe to reads, so that we're triggered again if more data arrives later.
5957
session.subscribeKey(SelectionKey.OP_READ);
6058

61-
if(session.isAbortingConnection()) {
59+
if (session.isAbortingConnection()) {
6260
Log.d(TAG,"removing aborted connection -> "+ session);
6361
session.cancelKey();
6462
if (channel instanceof SocketChannel){
@@ -85,7 +83,7 @@ public void read(Session session) {
8583
}
8684

8785
private void readTCP(@NonNull Session session) {
88-
if(session.isAbortingConnection()){
86+
if (session.isAbortingConnection()) {
8987
return;
9088
}
9189

@@ -191,16 +189,15 @@ private void readUDP(Session session){
191189

192190
try {
193191
do{
194-
if(session.isAbortingConnection()){
192+
if (session.isAbortingConnection()) {
195193
break;
196194
}
195+
197196
len = channel.read(buffer);
198-
if(len > 0){
199-
Date date = new Date();
200-
long responseTime = date.getTime() - session.connectionStartTime;
201-
197+
if (len > 0) {
202198
buffer.limit(len);
203199
buffer.flip();
200+
204201
//create UDP packet
205202
byte[] data = new byte[len];
206203
System.arraycopy(buffer.array(),0, data, 0, len);
@@ -213,25 +210,11 @@ private void readUDP(Session session){
213210
Log.d(TAG,"SDR: sent " + len + " bytes to UDP client, packetData.length: "
214211
+ packetData.length);
215212
buffer.clear();
216-
217-
try {
218-
final ByteBuffer stream = ByteBuffer.wrap(packetData);
219-
IPv4Header ip = IPPacketFactory.createIPv4Header(stream);
220-
UDPHeader udp = UDPPacketFactory.createUDPHeader(stream);
221-
String str = PacketUtil.getUDPoutput(ip, udp);
222-
Log.d(TAG,"++++++ SD: packet sending to client ++++++++");
223-
Log.d(TAG,"got response time: " + responseTime);
224-
Log.d(TAG,str);
225-
Log.d(TAG,"++++++ SD: end sending packet to client ++++");
226-
} catch (PacketHeaderException e) {
227-
e.printStackTrace();
228-
}
229213
}
230214
} while(len > 0);
231215
}catch(NotYetConnectedException ex){
232216
Log.e(TAG,"failed to read from unconnected UDP socket");
233217
} catch (IOException e) {
234-
e.printStackTrace();
235218
Log.e(TAG,"Failed to read from UDP socket, aborting connection");
236219
session.setAbortingConnection(true);
237220
}

app/src/main/java/tech/httptoolkit/android/vpn/socket/SocketChannelWriter.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void write(@NonNull Session session) {
4747
throw new IllegalArgumentException("Unexpected channel type: " + channel);
4848
}
4949

50-
if(session.isAbortingConnection()){
50+
if (session.isAbortingConnection()) {
5151
Log.d(TAG,"removing aborted connection -> " + session);
5252
session.cancelKey();
5353

@@ -76,11 +76,7 @@ public void write(@NonNull Session session) {
7676
}
7777

7878
private void writeUDP(Session session) {
79-
String name = PacketUtil.intToIPAddress(session.getDestIp())+":"+session.getDestPort()+
80-
"-"+PacketUtil.intToIPAddress(session.getSourceIp())+":"+session.getSourcePort();
81-
8279
try {
83-
Log.d(TAG,"writing data to remote UDP: "+name);
8480
writePendingData(session);
8581
Date dt = new Date();
8682
session.connectionStartTime = dt.getTime();
@@ -95,11 +91,7 @@ private void writeUDP(Session session) {
9591
}
9692

9793
private void writeTCP(Session session) {
98-
String name = PacketUtil.intToIPAddress(session.getDestIp())+":"+session.getDestPort()+
99-
"-"+PacketUtil.intToIPAddress(session.getSourceIp())+":"+session.getSourcePort();
100-
10194
try {
102-
Log.d(TAG,"writing TCP data to: " + name);
10395
writePendingData(session);
10496
} catch (NotYetConnectedException ex) {
10597
Log.e(TAG,"failed to write to unconnected socket: " + ex.getMessage());
@@ -127,8 +119,6 @@ private void writePendingData(Session session) throws IOException {
127119
buffer.put(data);
128120
buffer.flip();
129121

130-
Log.d(TAG, "Write " + buffer.remaining() + " bytes from " + session + " to " + channel);
131-
132122
while (buffer.hasRemaining()) {
133123
int bytesWritten = channel instanceof SocketChannel
134124
? ((SocketChannel) channel).write(buffer)

app/src/main/java/tech/httptoolkit/android/vpn/socket/SocketNIODataService.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package tech.httptoolkit.android.vpn.socket;
22

3-
import android.annotation.SuppressLint;
43
import android.util.Log;
54

65
import tech.httptoolkit.android.vpn.ClientPacketWriter;
@@ -20,13 +19,8 @@
2019
import java.nio.channels.UnsupportedAddressTypeException;
2120
import java.nio.channels.spi.AbstractSelectableChannel;
2221
import java.util.Iterator;
23-
import java.util.concurrent.BlockingQueue;
24-
import java.util.concurrent.LinkedBlockingQueue;
25-
import java.util.concurrent.ThreadPoolExecutor;
26-
import java.util.concurrent.TimeUnit;
2722
import java.util.concurrent.locks.Lock;
2823
import java.util.concurrent.locks.ReentrantLock;
29-
import java.util.function.Consumer;
3024

3125
import tech.httptoolkit.android.TagKt;
3226

0 commit comments

Comments
 (0)