Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions app/src/main/java/xyz/hexene/localvpn/LRUCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@

import java.util.LinkedHashMap;

public class LRUCache<K, V> extends LinkedHashMap<K, V>
{
public class LRUCache<K, V> extends LinkedHashMap<K, V> {
private int maxSize;
private CleanupCallback callback;
private CleanupCallback<K, V> callback;

public LRUCache(int maxSize, CleanupCallback callback)
{
public LRUCache(int maxSize, CleanupCallback<K, V> callback) {
super(maxSize + 1, 1, true);

this.maxSize = maxSize;
this.callback = callback;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/xyz/hexene/localvpn/Packet.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private enum TransportProtocol
UDP(17),
Other(0xFF);

private int protocolNumber;
private final int protocolNumber;

TransportProtocol(int protocolNumber)
{
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/xyz/hexene/localvpn/TCPOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ public class TCPOutput implements Runnable
{
private static final String TAG = TCPOutput.class.getSimpleName();

private LocalVPNService vpnService;
private android.net.VpnService vpnService;
private ConcurrentLinkedQueue<Packet> inputQueue;
private ConcurrentLinkedQueue<ByteBuffer> outputQueue;
private Selector selector;

private Random random = new Random();
public TCPOutput(ConcurrentLinkedQueue<Packet> inputQueue, ConcurrentLinkedQueue<ByteBuffer> outputQueue,
Selector selector, LocalVPNService vpnService)
{
public TCPOutput(
ConcurrentLinkedQueue<Packet> inputQueue,
ConcurrentLinkedQueue<ByteBuffer> outputQueue,
Selector selector,
android.net.VpnService vpnService) {
this.inputQueue = inputQueue;
this.outputQueue = outputQueue;
this.selector = selector;
Expand Down Expand Up @@ -266,7 +268,7 @@ private void sendRST(TCB tcb, int prevPayloadSize, ByteBuffer buffer)

private void closeCleanly(TCB tcb, ByteBuffer buffer)
{
ByteBufferPool.release(buffer);
// ByteBufferPool.release(buffer); // Commented out to prevent double-free corruption
TCB.closeTCB(tcb);
}
}
12 changes: 9 additions & 3 deletions app/src/main/java/xyz/hexene/localvpn/UDPInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ public void run()
receiveBuffer.position(HEADER_SIZE);

DatagramChannel inputChannel = (DatagramChannel) key.channel();
// XXX: We should handle any IOExceptions here immediately,
// but that probably won't happen with UDP
int readBytes = inputChannel.read(receiveBuffer);
int readBytes;
try {
readBytes = inputChannel.read(receiveBuffer);
} catch (IOException e) {
Log.e(TAG, "UDP read error", e);
key.cancel();
ByteBufferPool.release(receiveBuffer);
continue; // Prevent thread death, skip to next packet
}

Packet referencePacket = (Packet) key.attachment();
referencePacket.updateUDPBuffer(receiveBuffer, readBytes);
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/xyz/hexene/localvpn/UDPOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class UDPOutput implements Runnable
{
private static final String TAG = UDPOutput.class.getSimpleName();

private LocalVPNService vpnService;
private android.net.VpnService vpnService;
private ConcurrentLinkedQueue<Packet> inputQueue;
private Selector selector;

Expand All @@ -48,8 +48,7 @@ public void cleanup(Map.Entry<String, DatagramChannel> eldest)
}
});

public UDPOutput(ConcurrentLinkedQueue<Packet> inputQueue, Selector selector, LocalVPNService vpnService)
{
public UDPOutput(ConcurrentLinkedQueue<Packet> inputQueue, Selector selector, android.net.VpnService vpnService) {
this.inputQueue = inputQueue;
this.selector = selector;
this.vpnService = vpnService;
Expand Down