Open gregoiregentil opened 1 year ago
A solution would consist of storing port key and remotePort in C from NatSessionManager.createSession. Because remotePort is the only information missing. I'm still confused: the port I'm getting from getpeername, is it the key port? Couldn't it be the remotePort and then get entirely rid of NATSession?
Thank you for this code. It's short so it's readable.
First, in NatSession, I would recommend to rename remoteAddress to remoteIP for consistency.
Secondly, this line is not "very good": https://github.com/DrBrad/JTun2Socks/blob/master/app/src/main/java/jtun2socks/shadowrouter/org/jtun2socks/VPN/Proxy.java#L90
I think that it would be better to use session.remoteAddress. I have a C-implementation of proxy.java and I initially did getsockname for java "socket.getInetAddress().getAddress()" but it was giving me 10.8.0.2. I had to use getpeername.
To continue my point, remoteAddress is not used in proxy.java because you are putting the IP address into the source IP header. So you are duplicating information and remoteAddress is not used. Not a bug but it was confusing a little bit.
Now, as I'm doing a C-implementation of proxy.java, it's very difficult to go back from JNI to JAVA to get the NatSessionManager.getSession((short) socket.getPort()) because the class is started by a service (I could explain this more but that's not the point of the issue). My point is that if remotePort was hidden somewhere else in the socket, it could be retrieved from C without JAVA and without even the NATSession.
So, how could I hide the remotePort to retrieve it without java? Couldn't it be put where the port key is put?