Changeset a5e568f
- Timestamp:
- Mar 26, 2019 3:34:15 PM (22 months ago)
- Branches:
- master
- Children:
- 62f7b2c
- Parents:
- 64039ee
- Location:
- apps
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java
r64039ee ra5e568f 56 56 */ 57 57 public static I2PSocketManager createManager() { 58 return createManager(getHost(), getPort(), (Properties) System.getProperties().clone()); 58 return createManager(getHost(), getPort(), (Properties) System.getProperties().clone(), 59 IncomingConnectionFilter.ALLOW); 60 } 61 62 /** 63 * Create a socket manager using a brand new destination connected to the 64 * I2CP router on the local machine on the default port (7654) with the 65 * specified incoming connection filter. 66 * 67 * Blocks for a long time while the router builds tunnels. 68 * The nonblocking createDisconnectedManager() is preferred. 69 * 70 * @since 0.9.40 71 * @param filter The filter for incoming connections 72 * @return the newly created socket manager, or null if there were errors 73 */ 74 public static I2PSocketManager createManager(IncomingConnectionFilter filter) { 75 return createManager(getHost(), getPort(), (Properties) System.getProperties().clone(), filter); 59 76 } 60 77 … … 70 87 */ 71 88 public static I2PSocketManager createManager(Properties opts) { 72 return createManager(getHost(), getPort(), opts); 89 return createManager(getHost(), getPort(), opts, IncomingConnectionFilter.ALLOW); 90 } 91 92 /** 93 * Create a socket manager using a brand new destination connected to the 94 * I2CP router on the local machine on the default port (7654). 95 * 96 * Blocks for a long time while the router builds tunnels. 97 * The nonblocking createDisconnectedManager() is preferred. 98 * 99 * @since 0.9.40 100 * @param opts Streaming and I2CP options, may be null 101 * @param filter The filter to use for incoming connections 102 * @return the newly created socket manager, or null if there were errors 103 */ 104 public static I2PSocketManager createManager(Properties opts, IncomingConnectionFilter filter) { 105 return createManager(getHost(), getPort(), opts, filter); 73 106 } 74 107 … … 85 118 */ 86 119 public static I2PSocketManager createManager(String host, int port) { 87 return createManager(host, port, (Properties) System.getProperties().clone()); 88 } 89 120 return createManager(host, port, (Properties) System.getProperties().clone(), 121 IncomingConnectionFilter.ALLOW); 122 } 123 124 /** 125 * Create a socket manager using a brand new destination connected to the 126 * I2CP router on the specified host and port with the specified connection filter 127 * 128 * Blocks for a long time while the router builds tunnels. 129 * The nonblocking createDisconnectedManager() is preferred. 130 * 131 * @param host I2CP host null to use default, ignored if in router context 132 * @param port I2CP port <= 0 to use default, ignored if in router context 133 * @param filter The filter to use for incoming connections 134 * @return the newly created socket manager, or null if there were errors 135 */ 136 public static I2PSocketManager createManager(String host, int port, IncomingConnectionFilter filter) { 137 return createManager(host, port, (Properties) System.getProperties().clone(), filter); 138 } 139 90 140 /** 91 141 * Create a socket manager using a brand new destination connected to the … … 101 151 */ 102 152 public static I2PSocketManager createManager(String i2cpHost, int i2cpPort, Properties opts) { 153 return createManager(i2cpHost, i2cpPort, opts, IncomingConnectionFilter.ALLOW); 154 } 155 156 /** 157 * Create a socket manager using a brand new destination connected to the 158 * I2CP router on the given machine reachable through the given port with 159 * the specified connection filter 160 * 161 * Blocks for a long time while the router builds tunnels. 162 * The nonblocking createDisconnectedManager() is preferred. 163 * 164 * @since 0.9.40 165 * @param i2cpHost I2CP host null to use default, ignored if in router context 166 * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context 167 * @param opts Streaming and I2CP options, may be null 168 * @param filter The filter to use for incoming connections 169 * @return the newly created socket manager, or null if there were errors 170 */ 171 public static I2PSocketManager createManager(String i2cpHost, int i2cpPort, Properties opts, 172 IncomingConnectionFilter filter) { 103 173 I2PClient client = I2PClientFactory.createClient(); 104 174 ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024); … … 106 176 client.createDestination(keyStream, getSigType(opts)); 107 177 ByteArrayInputStream in = new ByteArrayInputStream(keyStream.toByteArray()); 108 return createManager(in, i2cpHost, i2cpPort, opts );178 return createManager(in, i2cpHost, i2cpPort, opts, filter); 109 179 } catch (IOException ioe) { 110 180 getLog().error("Error creating the destination for socket manager", ioe); … … 128 198 */ 129 199 public static I2PSocketManager createManager(InputStream myPrivateKeyStream) { 130 return createManager(myPrivateKeyStream, getHost(), getPort(), (Properties) System.getProperties().clone()); 200 return createManager(myPrivateKeyStream, IncomingConnectionFilter.ALLOW); 201 } 202 203 /** 204 * Create a socket manager using the destination loaded from the given private key 205 * stream and connected to the default I2CP host and port with the specified connection filter 206 * 207 * Blocks for a long time while the router builds tunnels. 208 * The nonblocking createDisconnectedManager() is preferred. 209 * 210 * @since 0.9.40 211 * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile} 212 * or null for a transient destination. Caller must close. 213 * @param filter The filter to use for incoming connections 214 * @return the newly created socket manager, or null if there were errors 215 */ 216 public static I2PSocketManager createManager(InputStream myPrivateKeyStream, 217 IncomingConnectionFilter filter) { 218 return createManager(myPrivateKeyStream, getHost(), getPort(), 219 (Properties) System.getProperties().clone(), 220 filter); 221 131 222 } 132 223 … … 144 235 */ 145 236 public static I2PSocketManager createManager(InputStream myPrivateKeyStream, Properties opts) { 146 return createManager(myPrivateKeyStream, getHost(), getPort(), opts); 237 return createManager(myPrivateKeyStream, opts, IncomingConnectionFilter.ALLOW); 238 } 239 240 /** 241 * Create a socket manager using the destination loaded from the given private key 242 * stream and connected to the default I2CP host and port. 243 * 244 * Blocks for a long time while the router builds tunnels. 245 * The nonblocking createDisconnectedManager() is preferred. 246 * 247 * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile} 248 * or null for a transient destination. Caller must close. 249 * @param opts Streaming and I2CP options, may be null 250 * @param filter The filter to use for incoming connections 251 * @return the newly created socket manager, or null if there were errors 252 */ 253 public static I2PSocketManager createManager(InputStream myPrivateKeyStream, 254 Properties opts, 255 IncomingConnectionFilter filter) { 256 return createManager(myPrivateKeyStream, getHost(), getPort(), opts, filter); 147 257 } 148 258 … … 164 274 public static I2PSocketManager createManager(InputStream myPrivateKeyStream, String i2cpHost, int i2cpPort, 165 275 Properties opts) { 276 return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, IncomingConnectionFilter.ALLOW); 277 } 278 279 /** 280 * Create a socket manager using the destination loaded from the given private key 281 * stream and connected to the I2CP router on the specified machine on the given 282 * port. 283 * 284 * Blocks for a long time while the router builds tunnels. 285 * The nonblocking createDisconnectedManager() is preferred. 286 * 287 * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile} 288 * or null for a transient destination. Caller must close. 289 * @param i2cpHost I2CP host null to use default, ignored if in router context 290 * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context 291 * @param opts Streaming and I2CP options, may be null 292 * @param filter The filter to use for incoming connections 293 * @return the newly created socket manager, or null if there were errors 294 */ 295 public static I2PSocketManager createManager(InputStream myPrivateKeyStream, 296 String i2cpHost, 297 int i2cpPort, 298 Properties opts, 299 IncomingConnectionFilter filter) { 166 300 try { 167 return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, true );301 return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, true, filter); 168 302 } catch (I2PSessionException ise) { 169 303 getLog().error("Error creating session for socket manager", ise); 170 304 return null; 171 305 } 172 } 173 306 } 307 174 308 /** 175 309 * Create a disconnected socket manager using the destination loaded from the given private key … … 192 326 public static I2PSocketManager createDisconnectedManager(InputStream myPrivateKeyStream, String i2cpHost, 193 327 int i2cpPort, Properties opts) throws I2PSessionException { 328 return createDisconnectedManager(myPrivateKeyStream, 329 i2cpHost, 330 i2cpPort, 331 opts, 332 IncomingConnectionFilter.ALLOW); 333 } 334 335 /** 336 * Create a disconnected socket manager using the destination loaded from the given private key 337 * stream, or null for a transient destination. 338 * 339 * Non-blocking. Does not connect to the router or build tunnels. 340 * For servers, caller MUST call getSession().connect() to build tunnels and start listening. 341 * For clients, caller may do that to build tunnels in advance; 342 * otherwise, the first call to connect() will initiate a connection to the router, 343 * with significant delay for tunnel building. 344 * 345 * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile} 346 * or null for a transient destination. Caller must close. 347 * @param i2cpHost I2CP host null to use default, ignored if in router context 348 * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context 349 * @param opts Streaming and I2CP options, may be null 350 * @param filter The filter to use for incoming connections 351 * @return the newly created socket manager, non-null (throws on error) 352 * @since 0.9.40 353 */ 354 public static I2PSocketManager createDisconnectedManager(InputStream myPrivateKeyStream, 355 String i2cpHost, 356 int i2cpPort, 357 Properties opts, 358 IncomingConnectionFilter filter) 359 throws I2PSessionException { 194 360 if (myPrivateKeyStream == null) { 195 361 I2PClient client = I2PClientFactory.createClient(); … … 204 370 myPrivateKeyStream = new ByteArrayInputStream(keyStream.toByteArray()); 205 371 } 206 return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, false );207 } 208 372 return createManager(myPrivateKeyStream, i2cpHost, i2cpPort, opts, false, filter); 373 } 374 209 375 /** 210 376 * Create a socket manager using the destination loaded from the given private key … … 220 386 * @param opts Streaming and I2CP options, may be null 221 387 * @param connect true to connect (blocking) 388 * @param filter The filter to use for incoming connections 222 389 * @return the newly created socket manager, non-null (throws on error) 223 * @since 0.9. 7390 * @since 0.9.40 224 391 */ 225 392 private static I2PSocketManager createManager(InputStream myPrivateKeyStream, String i2cpHost, int i2cpPort, 226 Properties opts, boolean connect) throws I2PSessionException { 393 Properties opts, boolean connect, 394 IncomingConnectionFilter filter) throws I2PSessionException { 227 395 I2PClient client = I2PClientFactory.createClient(); 228 396 if (opts == null) … … 246 414 if (connect) 247 415 session.connect(); 248 I2PSocketManager sockMgr = createManager(session, opts, "manager" );416 I2PSocketManager sockMgr = createManager(session, opts, "manager", filter); 249 417 return sockMgr; 250 418 } 251 419 252 private static I2PSocketManager createManager(I2PSession session, Properties opts, String name) { 420 private static I2PSocketManager createManager(I2PSession session, Properties opts, String name, 421 IncomingConnectionFilter filter) { 253 422 I2PAppContext context = I2PAppContext.getGlobalContext(); 254 423 // As of 0.9.12, ignore this setting, as jwebcache and i2phex set it to the old value. … … 261 430 throw new IllegalArgumentException(classname + " is not an I2PSocketManager"); 262 431 Constructor<?> con = 263 cls.getConstructor(I2PAppContext.class, I2PSession.class, Properties.class, String.class); 264 I2PSocketManager mgr = (I2PSocketManager) con.newInstance(new Object[] {context, session, opts, name}); 432 cls.getConstructor(I2PAppContext.class, 433 I2PSession.class, 434 Properties.class, 435 String.class, 436 IncomingConnectionFilter.class); 437 I2PSocketManager mgr = (I2PSocketManager) con.newInstance( 438 new Object[] {context, session, opts, name, filter}); 265 439 return mgr; 266 440 } catch (Throwable t) { -
apps/streaming/java/src/net/i2p/client/streaming/impl/ConnectionManager.java
r64039ee ra5e568f 22 22 import net.i2p.util.Log; 23 23 import net.i2p.util.SimpleTimer2; 24 import net.i2p.client.streaming.IncomingConnectionFilter; 24 25 25 26 /** … … 39 40 private final ConnectionPacketHandler _conPacketHandler; 40 41 private final TCBShare _tcbShare; 42 private final IncomingConnectionFilter _connectionFilter; 41 43 /** Inbound stream ID (Long) to Connection map */ 42 44 private final ConcurrentHashMap<Long, Connection> _connectionByInboundId; … … 82 84 * Manage all conns for this session 83 85 */ 84 public ConnectionManager(I2PAppContext context, I2PSession session, ConnectionOptions defaultOptions) { 86 public ConnectionManager(I2PAppContext context, 87 I2PSession session, 88 ConnectionOptions defaultOptions, 89 IncomingConnectionFilter connectionFilter) { 85 90 _context = context; 86 91 _session = session; 87 92 _defaultOptions = defaultOptions; 93 _connectionFilter = connectionFilter; 88 94 _log = _context.logManager().getLog(ConnectionManager.class); 89 95 _connectionByInboundId = new ConcurrentHashMap<Long,Connection>(32); … … 656 662 } 657 663 664 if (!_connectionFilter.allowDestination(from)) { 665 return "not allowed by filter"; 666 } 667 658 668 return null; 659 669 } -
apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java
r64039ee ra5e568f 29 29 import net.i2p.client.streaming.I2PSocketManager; 30 30 import net.i2p.client.streaming.I2PSocketOptions; 31 import net.i2p.client.streaming.IncomingConnectionFilter; 31 32 import net.i2p.crypto.SigAlgo; 32 33 import net.i2p.crypto.SigType; … … 192 193 * @param name non-null 193 194 */ 194 public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name) { 195 public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name, 196 IncomingConnectionFilter connectionFilter) { 195 197 _context = context; 196 198 _session = session; … … 201 203 _acceptTimeout = ACCEPT_TIMEOUT_DEFAULT; 202 204 _defaultOptions = new ConnectionOptions(opts); 203 _connectionManager = new ConnectionManager(_context, _session, _defaultOptions );205 _connectionManager = new ConnectionManager(_context, _session, _defaultOptions, connectionFilter); 204 206 _serverSocket = new I2PServerSocketFull(this); 205 207
Note: See TracChangeset
for help on using the changeset viewer.