26
26
import tech .httptoolkit .android .TagKt ;
27
27
import tech .httptoolkit .android .vpn .socket .DataConst ;
28
28
import tech .httptoolkit .android .vpn .socket .ICloseSession ;
29
- import tech .httptoolkit .android .vpn .socket .SocketNIODataService ;
30
29
import tech .httptoolkit .android .vpn .socket .SocketProtector ;
31
30
import tech .httptoolkit .android .vpn .util .PacketUtil ;
32
31
33
32
import java .io .IOException ;
34
33
import java .net .InetSocketAddress ;
35
34
import java .net .SocketAddress ;
36
- import java .net .SocketException ;
37
35
import java .nio .ByteBuffer ;
38
- import java .nio .channels .ClosedChannelException ;
39
36
import java .nio .channels .DatagramChannel ;
40
37
import java .nio .channels .SocketChannel ;
41
38
import java .nio .channels .spi .AbstractSelectableChannel ;
@@ -59,8 +56,13 @@ public class SessionManager implements ICloseSession {
59
56
*/
60
57
public void keepSessionAlive (Session session ) {
61
58
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
+ );
64
66
table .put (key , session );
65
67
}
66
68
}
@@ -77,8 +79,8 @@ public int addClientData(ByteBuffer buffer, Session session) {
77
79
return session .setSendingData (buffer );
78
80
}
79
81
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 );
82
84
83
85
return getSessionByKey (key );
84
86
}
@@ -99,8 +101,8 @@ public Session getSessionByKey(String key) {
99
101
* @param srcIp Source IP Address
100
102
* @param srcPort Source Port
101
103
*/
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 );
104
106
Session session = table .remove (key );
105
107
106
108
if (session != null ){
@@ -117,21 +119,21 @@ public void closeSession(int ip, int port, int srcIp, int srcPort){
117
119
}
118
120
119
121
public void closeSession (@ NonNull Session session ){
120
- closeSession (session .getDestIp (),
122
+ closeSession (session .getProtocol (), session . getDestIp (),
121
123
session .getDestPort (), session .getSourceIp (),
122
124
session .getSourcePort ());
123
125
}
124
126
125
127
@ NotNull
126
128
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 );
128
130
129
131
// For TCP, we freak out if you try to create an already existing session.
130
132
// With UDP though, it's totally fine:
131
133
Session existingSession = table .get (keys );
132
134
if (existingSession != null ) return existingSession ;
133
135
134
- Session session = new Session (srcIp , srcPort , ip , port , this );
136
+ Session session = new Session (SessionProtocol . UDP , srcIp , srcPort , ip , port , this );
135
137
136
138
DatagramChannel channel ;
137
139
@@ -160,7 +162,7 @@ public Session createNewUDPSession(int ip, int port, int srcIp, int srcPort) thr
160
162
161
163
@ NotNull
162
164
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 );
164
166
165
167
Session existingSession = table .get (key );
166
168
@@ -169,7 +171,7 @@ public Session createNewTCPSession(int ip, int port, int srcIp, int srcPort) thr
169
171
// We return the initialized session, which will be reacked to indicate rejection.
170
172
if (existingSession != null ) return existingSession ;
171
173
172
- Session session = new Session (srcIp , srcPort , ip , port , this );
174
+ Session session = new Session (SessionProtocol . TCP , srcIp , srcPort , ip , port , this );
173
175
174
176
SocketChannel channel ;
175
177
channel = SocketChannel .open ();
0 commit comments