Skip to content

Commit

Permalink
Merge pull request #50 from compscidr/jason/udp-debug
Browse files Browse the repository at this point in the history
debugging why UDP is getting stuck on android
  • Loading branch information
compscidr authored Dec 2, 2024
2 parents 65b521f + 0630c42 commit e9bb4a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions core/src/main/kotlin/com/jasonernst/kanonproxy/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.nio.ByteBuffer
import java.nio.channels.ByteChannel
import java.nio.channels.CancelledKeyException
import java.nio.channels.ClosedSelectorException
import java.nio.channels.DatagramChannel
import java.nio.channels.SelectionKey
import java.nio.channels.Selector
import java.nio.channels.SocketChannel
Expand Down Expand Up @@ -211,6 +212,9 @@ abstract class Session(
}
}
if (it.isConnectable) {
if (it.channel() is DatagramChannel) {
logger.warn("IN CONNECTABLE AS DATAGRAM CHANNEL")
}
val socketChannel = it.channel() as SocketChannel
// logger.debug("Tcp connectable, trying to finish connection to ${socketChannel.remoteAddress}")
if (socketChannel.isConnectionPending) {
Expand All @@ -226,6 +230,7 @@ abstract class Session(
}
} catch (e: Exception) {
handleExceptionOnRemoteChannel(e)
selector.close()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class AnonymousTcpSession(
try {
logger.debug("TCP connecting to {}:{}", initialIpHeader.destinationAddress, initialTransportHeader.destinationPort)
channel.socket().keepAlive = true
channel.socket().keepAlive = true
channel.socket().soTimeout = 0
channel.configureBlocking(false)
connectTime = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jasonernst.kanonproxy.udp

import com.jasonernst.kanonproxy.ChangeRequest
import com.jasonernst.kanonproxy.Session
import com.jasonernst.kanonproxy.SessionManager
import com.jasonernst.kanonproxy.VpnProtector
Expand Down Expand Up @@ -53,12 +54,16 @@ class UdpSession(
try {
logger.debug("UDP connecting to {}:{}", initialIpHeader.destinationAddress, initialTransportHeader.destinationPort)
protector.protectUDPSocket(channel.socket())
channel.socket().soTimeout = 0
channel.configureBlocking(false)
channel.register(selector, OP_READ)
channel.connect(InetSocketAddress(initialIpHeader.destinationAddress, initialTransportHeader.destinationPort.toInt()))
logger.debug("UDP Connected")
synchronized(changeRequests) {
changeRequests.add(ChangeRequest(channel, ChangeRequest.REGISTER, OP_READ))
}
startIncomingHandling()
} catch (e: Exception) {
logger.error("ERROR ON UDP CONNECT $e")
handleExceptionOnRemoteChannel(e)
}
}
Expand Down

0 comments on commit e9bb4a4

Please sign in to comment.