First commit

pull/1/head
knaccc 5 years ago
parent 7fb6e5f2c8
commit a912eb5a1a

4
.gitignore vendored

@ -0,0 +1,4 @@
out/
target/
.idea/
*.swp

@ -0,0 +1,41 @@
# Embedded I2P Java Router with SAM interface
This project will build a native launcher. The launcher will include the I2P router, a SAM listener and a minimal JVM.
## Prerequisites
This project requires the JAR files and base configuration dir from an existing I2P installation.
To install I2P on Ubuntu so that these files are available to you, type:
```
sudo apt-add-repository ppa:i2p-maintainers/i2p
sudo apt-get update
sudo apt-get install i2p
```
Then copy the following 4 JAR files from the I2P installation to the import/lib directory in your clone of this GitHub project:
`for i in i2p.jar mstreaming.jar router.jar sam.jar streaming.jar; do cp /usr/share/i2p/lib/$i import/lib/; done`
You will need OpenJDK 11 installed:
`sudo apt install openjdk-11-jdk-headless`
## Building the launcher
`bin/build-launcher.sh`
This will convert the imported JARs to modules, compile the Java source code in this project, and then use the jlink tool
to build a platform-specific launcher executable.
## Running the launcher
`target/router/bin/router`
## Check that the I2P router is running and that it is listening for SAM connections
`fuser 7656/tcp`
## Todo
Need to determine the most minimal base configuration directory contents, and include it as part of this project.

@ -0,0 +1,15 @@
#!/bin/bash
basedir=`dirname $0`/..
# convert the jar files from an existing I2P built into modules suitable for use with jlink
basedir/bin/convert-jars-to-modules.sh
# compile the Main class that starts the I2P router and SAM listener
javac --module-path lib -d target/classes $(find src -name '*.java')
# package as a modular jar
jar --create --file target/org.getmonero.i2p.embedded.jar --main-class org.getmonero.i2p.embedded.Main -C target/classes .
# create an OS specific launcher which will bundle together the code and a minimal JVM
jlink --module-path target/modules:target/org.getmonero.i2p.embedded.jar --add-modules org.getmonero.i2p.embedded --launcher router=org.getmonero.i2p.embedded --output target/router --strip-debug --compress 2 --no-header-files --no-man-pages

@ -0,0 +1,21 @@
#!/bin/bash
basedir=`dirname $0`/..
jarPaths=`find $basedir/import/lib -name '*.jar'`
mkdir -p $basedir/target/modules
rm -f $basedir/target/modules/*
for jarPath in $jarPaths; do
moduleName=$(basename "${jarPath%.*}")
echo "*** Determining dependencies for " $moduleName
jdeps --module-path $basedir/import/lib --add-modules=ALL-MODULE-PATH --generate-module-info $basedir/target/module-info $jarPath
done
for jarPath in $jarPaths; do
moduleName=$(basename "${jarPath%.*}")
echo "*** Creating new modular jar for " $moduleName
javac --module-path $basedir/import/lib --patch-module $moduleName=$jarPath $basedir/target/module-info/$moduleName/module-info.java
cp $jarPath $basedir/target/modules/
jar uf $basedir/target/modules/${moduleName}.jar -C $basedir/target/module-info/$moduleName module-info.class
done

@ -0,0 +1,7 @@
module org.getmonero.i2p.embedded {
requires i2p;
requires mstreaming;
requires streaming;
requires router;
requires sam;
}

@ -0,0 +1,64 @@
package org.getmonero.i2p.embedded;
import java.io.File;
import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.app.ClientAppManager;
import net.i2p.app.ClientAppManagerImpl;
import net.i2p.router.Router;
import net.i2p.sam.SAMBridge;
public class Main {
public static void main(String[] args) {
Properties p = new Properties();
// add your configuration settings, directories, etc.
// where to find the I2P installation files
p.put("i2p.dir.base", "/usr/share/i2p");
// where to find the I2P data files
p.put("i2p.dir.config", System.getProperty("user.home") + File.separator + ".i2p");
// bandwidth limits in K bytes per second
p.put("i2np.inboundKBytesPerSecond","50");
p.put("i2np.outboundKBytesPerSecond","50");
p.put("router.sharePercentage","80");
Router r = new Router(p);
new Thread() {
@Override
public void run() {
// don't call exit() when the router stops
r.setKillVMOnEnd(false);
r.runRouter();
}
}.start();
new Thread() {
@Override
public void run() {
try {
String[] args = new String[]{"sam.keys", "127.0.0.1", "7656", "i2cp.tcp.host=127.0.0.1", "i2cp.tcp.port=7654"};
I2PAppContext context = r.getContext();
ClientAppManager mgr = new ClientAppManagerImpl(context);
SAMBridge samBridge = new SAMBridge(context, mgr, args);
samBridge.startup();
}
catch (Exception e) {
e.printStackTrace();
}
}
}.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("I2P router will shut down gracefully");
r.shutdownGracefully();
}
});
}
}
Loading…
Cancel
Save