2626import tech .httptoolkit .android .TagKt ;
2727import tech .httptoolkit .android .vpn .socket .DataConst ;
2828import tech .httptoolkit .android .vpn .socket .ICloseSession ;
29- import tech .httptoolkit .android .vpn .socket .SocketNIODataService ;
3029import tech .httptoolkit .android .vpn .socket .SocketProtector ;
3130import tech .httptoolkit .android .vpn .util .PacketUtil ;
3231
3332import java .io .IOException ;
3433import java .net .InetSocketAddress ;
3534import java .net .SocketAddress ;
36- import java .net .SocketException ;
3735import java .nio .ByteBuffer ;
38- import java .nio .channels .ClosedChannelException ;
3936import java .nio .channels .DatagramChannel ;
4037import java .nio .channels .SocketChannel ;
4138import java .nio .channels .spi .AbstractSelectableChannel ;
@@ -59,8 +56,13 @@ public class SessionManager implements ICloseSession {
5956 */
6057 public void keepSessionAlive (Session session ) {
6158 if (session != null ){
62- String key = Session .getSessionKey (session .getDestIp (), session .getDestPort (),
63- session .getSourceIp (), session .getSourcePort ());
59+ String key = Session .getSessionKey (
60+ session .getProtocol (),
61+ session .getDestIp (),
62+ session .getDestPort (),
63+ session .getSourceIp (),
64+ session .getSourcePort ()
65+ );
6466 table .put (key , session );
6567 }
6668 }
@@ -77,8 +79,8 @@ public int addClientData(ByteBuffer buffer, Session session) {
7779 return session .setSendingData (buffer );
7880 }
7981
80- public Session getSession (int ip , int port , int srcIp , int srcPort ) {
81- String key = Session .getSessionKey (ip , port , srcIp , srcPort );
82+ public Session getSession (SessionProtocol protocol , int ip , int port , int srcIp , int srcPort ) {
83+ String key = Session .getSessionKey (protocol , ip , port , srcIp , srcPort );
8284
8385 return getSessionByKey (key );
8486 }
@@ -99,8 +101,8 @@ public Session getSessionByKey(String key) {
99101 * @param srcIp Source IP Address
100102 * @param srcPort Source Port
101103 */
102- public void closeSession (int ip , int port , int srcIp , int srcPort ){
103- String key = Session .getSessionKey (ip , port , srcIp , srcPort );
104+ public void closeSession (SessionProtocol protocol , int ip , int port , int srcIp , int srcPort ){
105+ String key = Session .getSessionKey (protocol , ip , port , srcIp , srcPort );
104106 Session session = table .remove (key );
105107
106108 if (session != null ){
@@ -117,21 +119,21 @@ public void closeSession(int ip, int port, int srcIp, int srcPort){
117119 }
118120
119121 public void closeSession (@ NonNull Session session ){
120- closeSession (session .getDestIp (),
122+ closeSession (session .getProtocol (), session . getDestIp (),
121123 session .getDestPort (), session .getSourceIp (),
122124 session .getSourcePort ());
123125 }
124126
125127 @ NotNull
126128 public Session createNewUDPSession (int ip , int port , int srcIp , int srcPort ) throws IOException {
127- String keys = Session .getSessionKey (ip , port , srcIp , srcPort );
129+ String keys = Session .getSessionKey (SessionProtocol . UDP , ip , port , srcIp , srcPort );
128130
129131 // For TCP, we freak out if you try to create an already existing session.
130132 // With UDP though, it's totally fine:
131133 Session existingSession = table .get (keys );
132134 if (existingSession != null ) return existingSession ;
133135
134- Session session = new Session (srcIp , srcPort , ip , port , this );
136+ Session session = new Session (SessionProtocol . UDP , srcIp , srcPort , ip , port , this );
135137
136138 DatagramChannel channel ;
137139
@@ -160,7 +162,7 @@ public Session createNewUDPSession(int ip, int port, int srcIp, int srcPort) thr
160162
161163 @ NotNull
162164 public Session createNewTCPSession (int ip , int port , int srcIp , int srcPort ) throws IOException {
163- String key = Session .getSessionKey (ip , port , srcIp , srcPort );
165+ String key = Session .getSessionKey (SessionProtocol . TCP , ip , port , srcIp , srcPort );
164166
165167 Session existingSession = table .get (key );
166168
@@ -169,7 +171,7 @@ public Session createNewTCPSession(int ip, int port, int srcIp, int srcPort) thr
169171 // We return the initialized session, which will be reacked to indicate rejection.
170172 if (existingSession != null ) return existingSession ;
171173
172- Session session = new Session (srcIp , srcPort , ip , port , this );
174+ Session session = new Session (SessionProtocol . TCP , srcIp , srcPort , ip , port , this );
173175
174176 SocketChannel channel ;
175177 channel = SocketChannel .open ();
0 commit comments