From f68a86a4987471c0f1b5230843743292dc7aaae4 Mon Sep 17 00:00:00 2001 From: knaccc Date: Sun, 20 Jan 2019 16:19:38 +0000 Subject: [PATCH] Tunnel control now lets you easily create client and server tunnels --- README.md | 18 +++++++++---- .../getmonero/i2p/embedded/TunnelControl.java | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fe9c7ea..a363f8b 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Zero dependency, small footprint, cross-platform I2P Java Router with SAM interface +# Zero dependency, small footprint, cross-platform I2P Java Router with simple tunnel controller and SAM interface This project will run under Linux, and build native launchers for Linux, MacOS and Windows. The launchers will include the I2P router, a SAM listener and a minimal JVM. @@ -67,25 +67,33 @@ Press Ctrl-C to gracefully shut down the router (or send the SIGINT signal to th ## Tunnel control -Listen for i2p connections and forward them to the specified host and port. Returns a newly created destination public key. +### Listen for i2p connections and forward them to the specified host and port. Returns a newly created destination public key. `dist/linux/router/bin/tunnel-control.sh server.create ` -Close the tunnel listening for connections on the specified port. Returns "OK". +### Close the tunnel listening for connections on the specified port. Returns "OK". `dist/linux/router/bin/tunnel-control.sh server.destroy ` -Create a tunnel that listens for connections on localhost and forwards connections over I2P to the specified destination public key. Returns a newly created localhost port number. +### Create a tunnel that listens for connections on localhost and forwards connections over I2P to the specified destination public key. Returns a newly created localhost port number. `dist/linux/router/bin/tunnel-control.sh client.create ` -Close the tunnel listening for connections on the specified port. Returns "OK". +### Close the tunnel listening for connections on the specified port. Returns "OK". `dist/linux/router/bin/tunnel-control.sh client.destroy ` +### Create a socks tunnel, listening on the specified port + +`dist/linux/router/bin/tunnel-control.sh socks.create ` + +### Destroy the socks tunnel listening on the specified port + +`dist/linux/router/bin/tunnel-control.sh socks.destroy ` + ## Watch the I2P log for messages diff --git a/src/org/getmonero/i2p/embedded/TunnelControl.java b/src/org/getmonero/i2p/embedded/TunnelControl.java index 7de35ce..aa7d581 100644 --- a/src/org/getmonero/i2p/embedded/TunnelControl.java +++ b/src/org/getmonero/i2p/embedded/TunnelControl.java @@ -17,6 +17,7 @@ public class TunnelControl implements Runnable { private Map clientTunnels = new HashMap<>(); private Map serverTunnels = new HashMap<>(); + private Map socksTunnels = new HashMap<>(); private int clientPortSeq = 30000; private int serverSeq = 0; private String tunnelConfigDirPrefix; @@ -100,6 +101,31 @@ public class TunnelControl implements Runnable { }.start(); out.println("OK"); } + if(args[0].equals("socks.create")) { + int port = Integer.parseInt(args[1]); + new Thread() { + @Override + public void run() { + // sockstunnel port + var t = new I2PTunnel(new String[]{"-die", "-nocli", "-e", "sockstunnel " + port}); + socksTunnels.put(port, t); + } + }.start(); + out.println("OK"); + } + if(args[0].equals("socks.destroy")) { + int port = Integer.parseInt(args[1]); + new Thread() { + @Override + public void run() { + var t = socksTunnels.get(port); + socksTunnels.remove(port); + t.runClose(new String[]{"forced", "all"}, t); + } + }.start(); + out.println("OK"); + } + } catch (Exception e) { e.printStackTrace();