@@ -126,11 +126,10 @@ public void closeSession(@NonNull Session session){
126126 public Session createNewUDPSession (int ip , int port , int srcIp , int srcPort ) throws IOException {
127127 String keys = Session .getSessionKey (ip , port , srcIp , srcPort );
128128
129- if (table .containsKey (keys )) {
130- // For TCP, we freak out if you try to create an already existing session.
131- // With UDP though, it's totally fine:
132- return table .get (keys );
133- }
129+ // For TCP, we freak out if you try to create an already existing session.
130+ // With UDP though, it's totally fine:
131+ Session existingSession = table .get (keys );
132+ if (existingSession != null ) return existingSession ;
134133
135134 Session session = new Session (srcIp , srcPort , ip , port , this );
136135
@@ -162,12 +161,13 @@ public Session createNewUDPSession(int ip, int port, int srcIp, int srcPort) thr
162161 @ NotNull
163162 public Session createNewTCPSession (int ip , int port , int srcIp , int srcPort ) throws IOException {
164163 String key = Session .getSessionKey (ip , port , srcIp , srcPort );
165- if (table .containsKey (key )) {
166- // This can happen if we receive two SYN packets somehow. That shouldn't happen, especially
167- // given that our connection is local & should be 100% reliable, but it does. We probably
168- // should RST, for now we just throw here (and so drop the packet entirely).
169- throw new IllegalArgumentException ("Can't create duplicate session" );
170- }
164+
165+ Session existingSession = table .get (key );
166+
167+ // This can happen if we receive two SYN packets somehow. That shouldn't happen,
168+ // given that our connection is local & should be 100% reliable, but it can.
169+ // We return the initialized session, which will be reacked to indicate rejection.
170+ if (existingSession != null ) return existingSession ;
171171
172172 Session session = new Session (srcIp , srcPort , ip , port , this );
173173
0 commit comments