forked from I2P_Developers/i2p.i2p
Compare commits
95 Commits
i2p_0_4_2_
...
i2p_0_5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d9efa17de | ||
|
|
b125b04c8d | ||
|
|
0539f1d794 | ||
|
|
a4b6709f02 | ||
|
|
f2db143a6f | ||
|
|
b615f54d41 | ||
|
|
db2328e03e | ||
|
|
e2071935ad | ||
|
|
1c40ff773f | ||
|
|
37a3645663 | ||
|
|
eb8accd1e0 | ||
|
|
3af97894b4 | ||
|
|
15a0dcf4d8 | ||
|
|
aa3a44c42a | ||
|
|
40f4b47b87 | ||
|
|
dca09d96b3 | ||
|
|
dd10747460 | ||
|
|
77176162af | ||
|
|
8b9ee4dfd7 | ||
|
|
6e8e77b9ec | ||
|
|
7ef9ce8cc6 | ||
|
|
9646ac2911 | ||
|
|
566a713baa | ||
|
|
36f7e98e90 | ||
|
|
4da755816a | ||
|
|
3ef0258faf | ||
|
|
293ceaee93 | ||
|
|
7b58d0fa0f | ||
|
|
bd68c1e056 | ||
|
|
200162d973 | ||
|
|
4b37a53f1c | ||
|
|
2d41de7ae0 | ||
|
|
bc5bc62c18 | ||
|
|
a0d680024e | ||
|
|
45013feea7 | ||
|
|
2abbe992dd | ||
|
|
d7081b3eeb | ||
|
|
a2f5289bd9 | ||
|
|
b366a4b942 | ||
|
|
27e92653fe | ||
|
|
80120b7b7d | ||
|
|
af8a618826 | ||
|
|
af0e554562 | ||
|
|
382cbb18db | ||
|
|
252b523155 | ||
|
|
4303b3b716 | ||
|
|
87715dc21a | ||
|
|
8552494fc1 | ||
|
|
1c2290b613 | ||
|
|
5f6060b801 | ||
|
|
b39958604d | ||
|
|
22ca1491bc | ||
|
|
690d7e30cf | ||
|
|
4fac2f1094 | ||
|
|
eb0935d577 | ||
|
|
425fedf55b | ||
|
|
a33de09ae6 | ||
|
|
5018e56103 | ||
|
|
de2c975ac2 | ||
|
|
d86e2c0f59 | ||
|
|
14023163b3 | ||
|
|
d85dc8213e | ||
|
|
f6a34055ac | ||
|
|
3beb0d9c12 | ||
|
|
60968fe6f1 | ||
|
|
517c3101c7 | ||
|
|
998f03ba68 | ||
|
|
f3b0e0cfc7 | ||
|
|
a65e6c888c | ||
|
|
cd939d3379 | ||
|
|
29e5aeff5c | ||
|
|
0e5cf81fca | ||
|
|
61f217c610 | ||
|
|
ccb1f491c7 | ||
|
|
49fdac9b4e | ||
|
|
6b6a9490f6 | ||
|
|
2c783e9876 | ||
|
|
ecd971c0e5 | ||
|
|
c48875a6fb | ||
|
|
a245ccb8b7 | ||
|
|
75a18debcb | ||
|
|
1a15d3bb55 | ||
|
|
ffdcae47e3 | ||
|
|
34a2bc8590 | ||
|
|
8ae4d00ccb | ||
|
|
9ed6d5e7fb | ||
|
|
c9243b241c | ||
|
|
9c364a64e3 | ||
|
|
b34306205c | ||
|
|
77f778dbf9 | ||
|
|
23fa4e4161 | ||
|
|
5b6fd0b829 | ||
|
|
8fa8d7739f | ||
|
|
dc552c7a29 | ||
|
|
cf84f453d3 |
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="../jetty/jettylib/javax.servlet.jar"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>addressbook</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -188,7 +188,7 @@ public class AddressBook {
|
||||
String otherKey = (String) otherIter.next();
|
||||
String otherValue = (String) other.addresses.get(otherKey);
|
||||
|
||||
if (otherValue.length() >= 516) {
|
||||
if (otherKey.endsWith(".i2p") && otherValue.length() >= 516) {
|
||||
if (this.addresses.containsKey(otherKey)) {
|
||||
if (!this.addresses.get(otherKey).equals(otherValue)
|
||||
&& log != null) {
|
||||
|
||||
@@ -65,7 +65,8 @@ public class Daemon {
|
||||
master.merge((AddressBook) iter.next(), log);
|
||||
}
|
||||
master.write(new File(routerLocation));
|
||||
master.write(published);
|
||||
if (published != null)
|
||||
master.write(published);
|
||||
subscriptions.write();
|
||||
}
|
||||
|
||||
@@ -82,7 +83,9 @@ public class Daemon {
|
||||
.get("master_addressbook"));
|
||||
File routerFile = new File(home, (String) settings
|
||||
.get("router_addressbook"));
|
||||
File published = new File(home, (String) settings
|
||||
File published = null;
|
||||
if ("true".equals(settings.get("should_publish")))
|
||||
published = new File(home, (String) settings
|
||||
.get("published_addressbook"));
|
||||
File subscriptionFile = new File(home, (String) settings
|
||||
.get("subscriptions"));
|
||||
@@ -95,8 +98,7 @@ public class Daemon {
|
||||
AddressBook router = new AddressBook(routerFile);
|
||||
|
||||
List defaultSubs = new LinkedList();
|
||||
defaultSubs.add("http://dev.i2p/i2p/hosts.txt");
|
||||
defaultSubs.add("http://duck.i2p/hosts.txt");
|
||||
defaultSubs.add("http://i2p/NF2RLVUxVulR3IqK0sGJR0dHQcGXAzwa6rEO4WAWYXOHw-DoZhKnlbf1nzHXwMEJoex5nFTyiNMqxJMWlY54cvU~UenZdkyQQeUSBZXyuSweflUXFqKN-y8xIoK2w9Ylq1k8IcrAFDsITyOzjUKoOPfVq34rKNDo7fYyis4kT5bAHy~2N1EVMs34pi2RFabATIOBk38Qhab57Umpa6yEoE~rbyR~suDRvD7gjBvBiIKFqhFueXsR2uSrPB-yzwAGofTXuklofK3DdKspciclTVzqbDjsk5UXfu2nTrC1agkhLyqlOfjhyqC~t1IXm-Vs2o7911k7KKLGjB4lmH508YJ7G9fLAUyjuB-wwwhejoWqvg7oWvqo4oIok8LG6ECR71C3dzCvIjY2QcrhoaazA9G4zcGMm6NKND-H4XY6tUWhpB~5GefB3YczOqMbHq4wi0O9MzBFrOJEOs3X4hwboKWANf7DT5PZKJZ5KorQPsYRSq0E3wSOsFCSsdVCKUGsAAAA/i2p/hosts.txt");
|
||||
|
||||
SubscriptionList subscriptions = new SubscriptionList(subscriptionFile,
|
||||
etagsFile, lastModifiedFile, defaultSubs);
|
||||
@@ -128,9 +130,10 @@ public class Daemon {
|
||||
Map defaultSettings = new HashMap();
|
||||
defaultSettings.put("proxy_host", "localhost");
|
||||
defaultSettings.put("proxy_port", "4444");
|
||||
defaultSettings.put("master_addressbook", "myhosts.txt");
|
||||
defaultSettings.put("router_addressbook", "../userhosts.txt");
|
||||
defaultSettings.put("master_addressbook", "../userhosts.txt");
|
||||
defaultSettings.put("router_addressbook", "../hosts.txt");
|
||||
defaultSettings.put("published_addressbook", "../eepsite/docroot/hosts.txt");
|
||||
defaultSettings.put("should_publish", "false");
|
||||
defaultSettings.put("log", "log.txt");
|
||||
defaultSettings.put("subscriptions", "subscriptions.txt");
|
||||
defaultSettings.put("etags", "etags");
|
||||
|
||||
106
apps/fortuna/build.xml
Normal file
106
apps/fortuna/build.xml
Normal file
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project basedir="." default="all" name="fortuna">
|
||||
|
||||
<property name="cvs.base.dir" value="java/gnu-crypto" />
|
||||
<property name="cvs.etc.dir" value="${cvs.base.dir}/etc" />
|
||||
<property name="cvs.lib.dir" value="${cvs.base.dir}/lib" />
|
||||
<property name="cvs.object.dir" value="${cvs.base.dir}/classes" />
|
||||
<property name="cvs.base.crypto.object.dir" value="${cvs.object.dir}/gnu/crypto" />
|
||||
<property name="cvs.cipher.object.dir" value="${cvs.base.crypto.object.dir}/cipher" />
|
||||
<property name="cvs.hash.object.dir" value="${cvs.base.crypto.object.dir}/hash" />
|
||||
<property name="cvs.prng.object.dir" value="${cvs.base.crypto.object.dir}/prng" />
|
||||
|
||||
<patternset id="fortuna.files">
|
||||
<include name="${cvs.base.crypto.object.dir}/Registry.class"/>
|
||||
<include name="${cvs.prng.object.dir}/Fortuna*.class"/>
|
||||
<include name="${cvs.prng.object.dir}/BasePRNG.class"/>
|
||||
<include name="${cvs.prng.object.dir}/RandomEventListener.class"/>
|
||||
<include name="${cvs.prng.object.dir}/IRandom.class"/>
|
||||
<include name="${cvs.cipher.object.dir}/CipherFactory.class"/>
|
||||
<include name="${cvs.cipher.object.dir}/IBlockCipher.class"/>
|
||||
<include name="${cvs.hash.object.dir}/HashFactory.class"/>
|
||||
<include name="${cvs.hash.object.dir}/IMessageDigest.class"/>
|
||||
</patternset>
|
||||
|
||||
<target name="all" depends="build,jar"
|
||||
description="Create and test the custom Fortuna library" />
|
||||
|
||||
<target name="build" depends="-init,checkout"
|
||||
description="Build the source and tests">
|
||||
<ant dir="${cvs.base.dir}" target="jar" />
|
||||
</target>
|
||||
|
||||
<target name="builddep" />
|
||||
|
||||
<target name="checkout" depends="-init" unless="cvs.source.available"
|
||||
description="Check out GNU Crypto sources from CVS HEAD">
|
||||
<cvs cvsRoot=":ext:anoncvs@savannah.gnu.org:/cvsroot/gnu-crypto"
|
||||
cvsRsh="ssh"
|
||||
dest="java"
|
||||
package="gnu-crypto" />
|
||||
</target>
|
||||
|
||||
<target name="clean"
|
||||
description="Remove generated tests and object files">
|
||||
<ant dir="${cvs.base.dir}" target="clean" />
|
||||
</target>
|
||||
|
||||
<target name="cleandep" />
|
||||
|
||||
<target name="compile" />
|
||||
|
||||
<target name="distclean" depends="clean"
|
||||
description="Remove all generated files">
|
||||
<delete dir="build" />
|
||||
<delete dir="jartemp" />
|
||||
<!--
|
||||
Annoyingly the GNU Crypto distclean task called here doesn't clean
|
||||
*all* derived files from java/gnu-crypto/lib like it should.....
|
||||
-->
|
||||
<ant dir="${cvs.base.dir}" target="distclean" />
|
||||
<!--
|
||||
.....and so we mop up the rest ourselves.
|
||||
-->
|
||||
<delete dir="${cvs.lib.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="-init">
|
||||
<available property="cvs.source.available" file="${cvs.base.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="build"
|
||||
description="Create the custom Fortuna jar library">
|
||||
<delete dir="build" />
|
||||
<delete dir="jartemp" />
|
||||
<mkdir dir="build" />
|
||||
<mkdir dir="jartemp/${cvs.object.dir}" />
|
||||
<copy todir="jartemp">
|
||||
<fileset dir=".">
|
||||
<patternset refid="fortuna.files" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<jar basedir="jartemp/${cvs.object.dir}" jarfile="build/fortuna.jar">
|
||||
<manifest>
|
||||
<section name="fortuna">
|
||||
<attribute name="Implementation-Title" value="I2P Custom GNU Crypto Fortuna Library" />
|
||||
<attribute name="Implementation-Version" value="CVS HEAD" />
|
||||
<attribute name="Implementation-Vendor" value="Free Software Foundation" />
|
||||
<attribute name="Implementation-Vendor-Id" value="FSF" />
|
||||
<attribute name="Implementation-URL" value="http://www.gnu.org/software/gnu-crypto" />
|
||||
</section>
|
||||
</manifest>
|
||||
</jar>
|
||||
<delete dir="jartemp" />
|
||||
</target>
|
||||
|
||||
<target name="test" depends="jar"
|
||||
description="Perform crypto tests on custom Fortuna jar library" />
|
||||
<!--
|
||||
Add this when Fortuna tests are added to GNU Crypto, else write some
|
||||
-->
|
||||
|
||||
<target name="update" depends="checkout"
|
||||
description="Update GNU Crypto sources to latest CVS HEAD">
|
||||
<cvs command="update -d" cvsRsh="ssh" dest="java/gnu-crypto" />
|
||||
</target>
|
||||
</project>
|
||||
@@ -39,12 +39,13 @@
|
||||
<pathelement location="../../jetty/jettylib/jasper-compiler.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jasper-runtime.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../../jetty/jettylib/commons-logging.jar" />
|
||||
<pathelement location="../../jetty/jettylib/commons-el.jar" />
|
||||
<pathelement location="../../jetty/jettylib/ant.jar" />
|
||||
<pathelement location="build/i2ptunnel.jar" />
|
||||
</classpath>
|
||||
<arg value="-d" />
|
||||
<arg value="../jsp/WEB-INF/classes" />
|
||||
<arg value="-v9" />
|
||||
<arg value="-p" />
|
||||
<arg value="net.i2p.i2ptunnel.jsp" />
|
||||
<arg value="-webinc" />
|
||||
@@ -52,10 +53,12 @@
|
||||
<arg value="-webapp" />
|
||||
<arg value="../jsp/" />
|
||||
</java>
|
||||
<javac destdir="../jsp/WEB-INF/classes/" srcdir="../jsp/WEB-INF/classes" includes="*.java">
|
||||
<javac destdir="../jsp/WEB-INF/classes/" srcdir="../jsp/WEB-INF/classes" includes="**/*.java">
|
||||
<classpath>
|
||||
<pathelement location="../../jetty/jettylib/jasper-runtime.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../../jetty/jettylib/commons-logging.jar" />
|
||||
<pathelement location="../../jetty/jettylib/commons-el.jar" />
|
||||
<pathelement location="build/i2ptunnel.jar" />
|
||||
</classpath>
|
||||
</javac>
|
||||
|
||||
@@ -183,7 +183,8 @@ public class I2PTunnel implements Logging, EventDispatcher {
|
||||
void addSession(I2PSession session) {
|
||||
if (session == null) return;
|
||||
synchronized (_sessions) {
|
||||
_sessions.add(session);
|
||||
if (!_sessions.contains(session))
|
||||
_sessions.add(session);
|
||||
}
|
||||
}
|
||||
void removeSession(I2PSession session) {
|
||||
|
||||
@@ -211,7 +211,18 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
|
||||
String request = line.substring(pos + 1);
|
||||
if (request.startsWith("/") && getTunnel().getClientOptions().getProperty("i2ptunnel.noproxy") != null) {
|
||||
request = "http://i2p" + request;
|
||||
} else if (request.startsWith("/eepproxy/")) {
|
||||
// /eepproxy/foo.i2p/bar/baz.html HTTP/1.0
|
||||
String subRequest = request.substring("/eepproxy/".length());
|
||||
int protopos = subRequest.indexOf(" ");
|
||||
String uri = subRequest.substring(0, protopos);
|
||||
if (uri.indexOf("/") == -1) {
|
||||
uri = uri + "/";
|
||||
}
|
||||
// "http://" + "foo.i2p/bar/baz.html" + " HTTP/1.0"
|
||||
request = "http://" + uri + subRequest.substring(protopos);
|
||||
}
|
||||
|
||||
pos = request.indexOf("//");
|
||||
if (pos == -1) {
|
||||
method = null;
|
||||
|
||||
@@ -102,6 +102,7 @@ public class TunnelController implements Logging {
|
||||
|
||||
public void startTunnelBackground() {
|
||||
if (_running) return;
|
||||
_starting = true;
|
||||
new I2PThread(new Runnable() { public void run() { startTunnel(); } }).start();
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ public class TunnelControllerGroup {
|
||||
List msgs = new ArrayList();
|
||||
for (int i = 0; i < _controllers.size(); i++) {
|
||||
TunnelController controller = (TunnelController)_controllers.get(i);
|
||||
controller.startTunnel();
|
||||
controller.startTunnelBackground();
|
||||
msgs.addAll(controller.clearMessages());
|
||||
}
|
||||
|
||||
|
||||
@@ -186,6 +186,9 @@ class WebEditPageFormGenerator {
|
||||
buf.append("<form action=\"edit.jsp\">");
|
||||
if (id != null)
|
||||
buf.append("<input type=\"hidden\" name=\"num\" value=\"").append(id).append("\" />");
|
||||
long nonce = new Random().nextLong();
|
||||
System.setProperty(WebEditPageHelper.class.getName() + ".nonce", nonce+"");
|
||||
buf.append("<input type=\"hidden\" name=\"nonce\" value=\"").append(nonce).append("\" />");
|
||||
|
||||
buf.append("<b>Name:</b> <input type=\"text\" name=\"name\" size=\"20\" ");
|
||||
if ( (controller != null) && (controller.getName() != null) )
|
||||
@@ -253,9 +256,10 @@ class WebEditPageFormGenerator {
|
||||
int tunnelDepth = 2;
|
||||
int numTunnels = 2;
|
||||
int connectDelay = 0;
|
||||
int maxWindowSize = -1;
|
||||
Properties opts = getOptions(controller);
|
||||
if (opts != null) {
|
||||
String depth = opts.getProperty("tunnels.depthInbound");
|
||||
String depth = opts.getProperty("inbound.length");
|
||||
if (depth != null) {
|
||||
try {
|
||||
tunnelDepth = Integer.parseInt(depth);
|
||||
@@ -263,7 +267,7 @@ class WebEditPageFormGenerator {
|
||||
tunnelDepth = 2;
|
||||
}
|
||||
}
|
||||
String num = opts.getProperty("tunnels.numInbound");
|
||||
String num = opts.getProperty("inbound.quantity");
|
||||
if (num != null) {
|
||||
try {
|
||||
numTunnels = Integer.parseInt(num);
|
||||
@@ -279,6 +283,14 @@ class WebEditPageFormGenerator {
|
||||
connectDelay = 0;
|
||||
}
|
||||
}
|
||||
String max = opts.getProperty("i2p.streaming.maxWindowSize");
|
||||
if (max != null) {
|
||||
try {
|
||||
maxWindowSize = Integer.parseInt(max);
|
||||
} catch (NumberFormatException nfe) {
|
||||
maxWindowSize = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.append("<b>Tunnel depth:</b> ");
|
||||
@@ -325,6 +337,14 @@ class WebEditPageFormGenerator {
|
||||
buf.append("checked=\"true\" ");
|
||||
buf.append("/> (useful for brief request/response connections)<br />\n");
|
||||
|
||||
buf.append("<b>Communication profile:</b>");
|
||||
buf.append("<select name=\"profile\">");
|
||||
if (maxWindowSize <= 0)
|
||||
buf.append("<option value=\"interactive\">Interactive</option><option value=\"bulk\" selected=\"true\">Bulk</option>");
|
||||
else
|
||||
buf.append("<option value=\"interactive\" selected=\"true\">Interactive</option><option value=\"bulk\">Bulk</option>");
|
||||
buf.append("</select><br />\n");
|
||||
|
||||
buf.append("<b>I2CP host:</b> ");
|
||||
buf.append("<input type=\"text\" name=\"clientHost\" size=\"20\" value=\"");
|
||||
if ( (controller != null) && (controller.getI2CPHost() != null) )
|
||||
@@ -347,9 +367,14 @@ class WebEditPageFormGenerator {
|
||||
for (Iterator iter = opts.keySet().iterator(); iter.hasNext(); ) {
|
||||
String key = (String)iter.next();
|
||||
String val = opts.getProperty(key);
|
||||
if ("tunnels.depthInbound".equals(key)) continue;
|
||||
if ("tunnels.numInbound".equals(key)) continue;
|
||||
if ("inbound.length".equals(key)) continue;
|
||||
if ("outbound.length".equals(key)) continue;
|
||||
if ("inbound.quantity".equals(key)) continue;
|
||||
if ("outbound.quantity".equals(key)) continue;
|
||||
if ("inbound.nickname".equals(key)) continue;
|
||||
if ("outbound.nickname".equals(key)) continue;
|
||||
if ("i2p.streaming.connectDelay".equals(key)) continue;
|
||||
if ("i2p.streaming.maxWindowSize".equals(key)) continue;
|
||||
if (i != 0) buf.append(' ');
|
||||
buf.append(key).append('=').append(val);
|
||||
i++;
|
||||
|
||||
@@ -40,9 +40,11 @@ public class WebEditPageHelper {
|
||||
private String _targetPort;
|
||||
private String _spoofedHost;
|
||||
private String _privKeyFile;
|
||||
private String _profile;
|
||||
private boolean _startOnLoad;
|
||||
private boolean _privKeyGenerate;
|
||||
private boolean _removeConfirmed;
|
||||
private long _nonce;
|
||||
|
||||
public WebEditPageHelper() {
|
||||
_action = null;
|
||||
@@ -52,6 +54,14 @@ public class WebEditPageHelper {
|
||||
_log = I2PAppContext.getGlobalContext().logManager().getLog(WebEditPageHelper.class);
|
||||
}
|
||||
|
||||
public void setNonce(String nonce) {
|
||||
if (nonce != null) {
|
||||
try {
|
||||
_nonce = Long.parseLong(nonce);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for form submit - either "Save" or Remove"
|
||||
*/
|
||||
@@ -173,6 +183,9 @@ public class WebEditPageHelper {
|
||||
public void setConnectDelay(String moo) {
|
||||
_connectDelay = true;
|
||||
}
|
||||
public void setProfile(String profile) {
|
||||
_profile = profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form and display any resulting messages
|
||||
@@ -224,6 +237,9 @@ public class WebEditPageHelper {
|
||||
private String processAction() {
|
||||
if ( (_action == null) || (_action.trim().length() <= 0) )
|
||||
return "";
|
||||
String expected = System.getProperty(getClass().getName() + ".nonce");
|
||||
if ( (expected == null) || (!expected.equals(Long.toString(_nonce))) )
|
||||
return "<b>Invalid nonce, are you being spoofed?</b>";
|
||||
if ("Save".equals(_action))
|
||||
return save();
|
||||
else if ("Remove".equals(_action))
|
||||
@@ -272,14 +288,26 @@ public class WebEditPageHelper {
|
||||
if (c == cur) continue;
|
||||
if ("httpclient".equals(c.getType()) || "client".equals(c.getType())) {
|
||||
Properties cOpt = c.getConfig("");
|
||||
if (_tunnelCount != null)
|
||||
cOpt.setProperty("option.tunnels.numInbound", _tunnelCount);
|
||||
if (_tunnelDepth != null)
|
||||
cOpt.setProperty("option.tunnels.depthInbound", _tunnelDepth);
|
||||
if (_tunnelCount != null) {
|
||||
cOpt.setProperty("option.inbound.quantity", _tunnelCount);
|
||||
cOpt.setProperty("option.outbound.quantity", _tunnelCount);
|
||||
}
|
||||
if (_tunnelDepth != null) {
|
||||
cOpt.setProperty("option.inbound.length", _tunnelDepth);
|
||||
cOpt.setProperty("option.outbound.length", _tunnelDepth);
|
||||
}
|
||||
if (_connectDelay)
|
||||
cOpt.setProperty("option.i2p.streaming.connectDelay", "1000");
|
||||
else
|
||||
cOpt.setProperty("option.i2p.streaming.connectDelay", "0");
|
||||
if ("interactive".equals(_profile))
|
||||
cOpt.setProperty("option.i2p.streaming.maxWindowSize", "1");
|
||||
else
|
||||
cOpt.remove("option.i2p.streaming.maxWindowSize");
|
||||
if (_name != null) {
|
||||
cOpt.setProperty("option.inbound.nickname", _name);
|
||||
cOpt.setProperty("option.outbound.nickname", _name);
|
||||
}
|
||||
c.setConfig(cOpt, "");
|
||||
}
|
||||
}
|
||||
@@ -339,7 +367,6 @@ public class WebEditPageHelper {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -363,23 +390,40 @@ public class WebEditPageHelper {
|
||||
continue;
|
||||
String key = pair.substring(0, eq);
|
||||
String val = pair.substring(eq+1);
|
||||
if ("tunnels.numInbound".equals(key)) continue;
|
||||
if ("tunnels.depthInbound".equals(key)) continue;
|
||||
if ("inbound.length".equals(key)) continue;
|
||||
if ("outbound.length".equals(key)) continue;
|
||||
if ("inbound.quantity".equals(key)) continue;
|
||||
if ("outbound.quantity".equals(key)) continue;
|
||||
if ("inbound.nickname".equals(key)) continue;
|
||||
if ("outbound.nickname".equals(key)) continue;
|
||||
if ("i2p.streaming.connectDelay".equals(key)) continue;
|
||||
if ("i2p.streaming.maxWindowSize".equals(key)) continue;
|
||||
config.setProperty("option." + key, val);
|
||||
}
|
||||
}
|
||||
|
||||
config.setProperty("startOnLoad", _startOnLoad + "");
|
||||
|
||||
if (_tunnelCount != null)
|
||||
config.setProperty("option.tunnels.numInbound", _tunnelCount);
|
||||
if (_tunnelDepth != null)
|
||||
config.setProperty("option.tunnels.depthInbound", _tunnelDepth);
|
||||
if (_tunnelCount != null) {
|
||||
config.setProperty("option.inbound.quantity", _tunnelCount);
|
||||
config.setProperty("option.outbound.quantity", _tunnelCount);
|
||||
}
|
||||
if (_tunnelDepth != null) {
|
||||
config.setProperty("option.inbound.length", _tunnelDepth);
|
||||
config.setProperty("option.outbound.length", _tunnelDepth);
|
||||
}
|
||||
if (_connectDelay)
|
||||
config.setProperty("option.i2p.streaming.connectDelay", "1000");
|
||||
else
|
||||
config.setProperty("option.i2p.streaming.connectDelay", "0");
|
||||
if (_name != null) {
|
||||
config.setProperty("option.inbound.nickname", _name);
|
||||
config.setProperty("option.outbound.nickname", _name);
|
||||
}
|
||||
if ("interactive".equals(_profile))
|
||||
config.setProperty("option.i2p.streaming.maxWindowSize", "1");
|
||||
else
|
||||
config.remove("option.i2p.streaming.maxWindowSize");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,14 +14,17 @@ import net.i2p.util.Log;
|
||||
*
|
||||
*/
|
||||
public class WebStatusPageHelper {
|
||||
private I2PAppContext _context;
|
||||
private Log _log;
|
||||
private String _action;
|
||||
private int _controllerNum;
|
||||
private long _nonce;
|
||||
|
||||
public WebStatusPageHelper() {
|
||||
_context = I2PAppContext.getGlobalContext();
|
||||
_action = null;
|
||||
_controllerNum = -1;
|
||||
_log = I2PAppContext.getGlobalContext().logManager().getLog(WebStatusPageHelper.class);
|
||||
_log = _context.logManager().getLog(WebStatusPageHelper.class);
|
||||
}
|
||||
|
||||
public void setAction(String action) {
|
||||
@@ -36,6 +39,14 @@ public class WebStatusPageHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setNonce(long nonce) { _nonce = nonce; }
|
||||
public void setNonce(String nonce) {
|
||||
if (nonce != null) {
|
||||
try {
|
||||
_nonce = Long.parseLong(nonce);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
|
||||
public String getActionResults() {
|
||||
try {
|
||||
@@ -51,28 +62,44 @@ public class WebStatusPageHelper {
|
||||
if (group == null)
|
||||
return "<b>I2PTunnel instances not yet started - please be patient</b>\n";
|
||||
|
||||
long nonce = _context.random().nextLong();
|
||||
StringBuffer buf = new StringBuffer(4*1024);
|
||||
buf.append("<ul>");
|
||||
List tunnels = group.getControllers();
|
||||
for (int i = 0; i < tunnels.size(); i++) {
|
||||
buf.append("<li>\n");
|
||||
getSummary(buf, i, (TunnelController)tunnels.get(i));
|
||||
getSummary(buf, i, (TunnelController)tunnels.get(i), nonce);
|
||||
buf.append("</li>\n");
|
||||
}
|
||||
buf.append("</ul>");
|
||||
|
||||
buf.append("<hr /><form action=\"index.jsp\" method=\"GET\">\n");
|
||||
buf.append("<input type=\"hidden\" name=\"nonce\" value=\"").append(nonce).append("\" />\n");
|
||||
buf.append("<input type=\"submit\" name=\"action\" value=\"Stop all\" />\n");
|
||||
buf.append("<input type=\"submit\" name=\"action\" value=\"Start all\" />\n");
|
||||
buf.append("<input type=\"submit\" name=\"action\" value=\"Restart all\" />\n");
|
||||
buf.append("<input type=\"submit\" name=\"action\" value=\"Reload config\" />\n");
|
||||
buf.append("</form>\n");
|
||||
|
||||
System.setProperty(getClass().getName() + ".nonce", nonce+"");
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private void getSummary(StringBuffer buf, int num, TunnelController controller) {
|
||||
private void getSummary(StringBuffer buf, int num, TunnelController controller, long nonce) {
|
||||
buf.append("<b>").append(controller.getName()).append("</b>: ");
|
||||
if (controller.getIsRunning()) {
|
||||
buf.append("<i>running</i> ");
|
||||
buf.append("<a href=\"index.jsp?num=").append(num).append("&action=stop\">stop</a> ");
|
||||
buf.append("<a href=\"index.jsp?num=").append(num);
|
||||
buf.append("&nonce=").append(nonce);
|
||||
buf.append("&action=stop\">stop</a> ");
|
||||
} else if (controller.getIsStarting()) {
|
||||
buf.append("<i>startup in progress (please be patient)</i>");
|
||||
} else {
|
||||
buf.append("<i>not running</i> ");
|
||||
buf.append("<a href=\"index.jsp?num=").append(num).append("&action=start\">start</a> ");
|
||||
buf.append("<a href=\"index.jsp?num=").append(num);
|
||||
buf.append("&nonce=").append(nonce);
|
||||
buf.append("&action=start\">start</a> ");
|
||||
}
|
||||
buf.append("<a href=\"edit.jsp?num=").append(num).append("\">edit</a> ");
|
||||
buf.append("<br />\n");
|
||||
@@ -82,6 +109,9 @@ public class WebStatusPageHelper {
|
||||
private String processAction() {
|
||||
if ( (_action == null) || (_action.trim().length() <= 0) )
|
||||
return getMessages();
|
||||
String expected = System.getProperty(getClass().getName() + ".nonce");
|
||||
if ( (expected == null) || (!expected.equals(Long.toString(_nonce))) )
|
||||
return "<b>Invalid nonce, are you being spoofed?</b>";
|
||||
if ("Stop all".equals(_action))
|
||||
return stopAll();
|
||||
else if ("Start all".equals(_action))
|
||||
@@ -139,7 +169,7 @@ public class WebStatusPageHelper {
|
||||
List controllers = group.getControllers();
|
||||
if (_controllerNum >= controllers.size()) return "Invalid tunnel";
|
||||
TunnelController controller = (TunnelController)controllers.get(_controllerNum);
|
||||
controller.startTunnel();
|
||||
controller.startTunnelBackground();
|
||||
return getMessages(controller.clearMessages());
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,6 @@
|
||||
<b><jsp:getProperty name="helper" property="actionResults" /></b>
|
||||
|
||||
<jsp:getProperty name="helper" property="summaryList" />
|
||||
<hr />
|
||||
<form action="index.jsp" method="GET">
|
||||
<input type="submit" name="action" value="Stop all" />
|
||||
<input type="submit" name="action" value="Start all" />
|
||||
<input type="submit" name="action" value="Restart all" />
|
||||
<input type="submit" name="action" value="Reload config" />
|
||||
</form>
|
||||
|
||||
<form action="edit.jsp">
|
||||
<b>Add new:</b>
|
||||
|
||||
@@ -3,18 +3,38 @@
|
||||
|
||||
<target name="all" depends="build" />
|
||||
<target name="fetchJettylib" >
|
||||
<available property="jetty.available" file="jettylib" />
|
||||
<available property="jetty.available" file="jetty-5.1.2.zip" />
|
||||
<ant target="doFetchJettylib" />
|
||||
</target>
|
||||
<target name="doFetchJettylib" unless="jetty.available" >
|
||||
<echo message="The libraries contained within the fetched file are from Jetty's 4.2.21 " />
|
||||
<echo message="distribution (http://jetty.mortbay.org/) which we have copied to our website since" />
|
||||
<echo message="theirs doesn't have direct HTTP access to the libs. These are not " />
|
||||
<echo message="The libraries contained within the fetched file are from Jetty's 5.1.2" />
|
||||
<echo message="distribution (http://jetty.mortbay.org/). These are not " />
|
||||
<echo message="necessary for using I2P, but are used by some applications on top of I2P," />
|
||||
<echo message="such as the routerconsole." />
|
||||
<get src="http://dev.i2p.net/jettylib.tar.bz2" verbose="true" dest="jettylib.tar.bz2" />
|
||||
<untar src="jettylib.tar.bz2" compression="bzip2" dest="." />
|
||||
<delete file="jettylib.tar.bz2" />
|
||||
<get src="http://mesh.dl.sourceforge.net/sourceforge/jetty/jetty-5.1.2.zip" verbose="true" dest="jetty-5.1.2.zip" />
|
||||
<ant target="doExtract" />
|
||||
</target>
|
||||
<target name="doExtract">
|
||||
<unzip src="jetty-5.1.2.zip" dest="." />
|
||||
<mkdir dir="jettylib" />
|
||||
<copy todir="jettylib">
|
||||
<fileset dir="jetty-5.1.2/lib">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="jettylib">
|
||||
<fileset dir="jetty-5.1.2/ext">
|
||||
<include name="ant.jar" />
|
||||
<include name="commons-el.jar" />
|
||||
<include name="commons-logging.jar" />
|
||||
<include name="jasper-compiler.jar" />
|
||||
<include name="jasper-runtime.jar" />
|
||||
<include name="javax.servlet.jar" />
|
||||
<include name="org.mortbay.jetty.jar" />
|
||||
<include name="xercesImpl.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<delete dir="jetty-5.1.2" />
|
||||
</target>
|
||||
<target name="build" depends="fetchJettylib" />
|
||||
<target name="builddep" />
|
||||
|
||||
@@ -32,7 +32,7 @@ class I2PSocketImpl implements I2PSocket {
|
||||
private Object remoteIDWaiter = new Object();
|
||||
private I2PInputStream in;
|
||||
private I2POutputStream out;
|
||||
private SocketErrorListener _socketErrorListener;
|
||||
private I2PSocket.SocketErrorListener _socketErrorListener;
|
||||
private boolean outgoing;
|
||||
private long _socketId;
|
||||
private static long __socketId = 0;
|
||||
@@ -284,7 +284,7 @@ class I2PSocketImpl implements I2PSocket {
|
||||
in.setReadTimeout(ms);
|
||||
}
|
||||
|
||||
public void setSocketErrorListener(SocketErrorListener lsnr) {
|
||||
public void setSocketErrorListener(I2PSocket.SocketErrorListener lsnr) {
|
||||
_socketErrorListener = lsnr;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListener {
|
||||
_listeners.clear();
|
||||
}
|
||||
for (int i = 0; i < listeners.size(); i++) {
|
||||
DisconnectListener lsnr = (DisconnectListener)listeners.get(i);
|
||||
I2PSocketManager.DisconnectListener lsnr = (I2PSocketManager.DisconnectListener)listeners.get(i);
|
||||
lsnr.sessionDisconnected();
|
||||
}
|
||||
}
|
||||
@@ -720,12 +720,12 @@ class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListener {
|
||||
public String getName() { return _name; }
|
||||
public void setName(String name) { _name = name; }
|
||||
|
||||
public void addDisconnectListener(DisconnectListener lsnr) {
|
||||
public void addDisconnectListener(I2PSocketManager.DisconnectListener lsnr) {
|
||||
synchronized (_listeners) {
|
||||
_listeners.add(lsnr);
|
||||
}
|
||||
}
|
||||
public void removeDisconnectListener(DisconnectListener lsnr) {
|
||||
public void removeDisconnectListener(I2PSocketManager.DisconnectListener lsnr) {
|
||||
synchronized (_listeners) {
|
||||
_listeners.remove(lsnr);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,18 @@ class I2PSocketOptionsImpl implements I2PSocketOptions {
|
||||
init(opts);
|
||||
}
|
||||
|
||||
public void setProperties(Properties opts) {
|
||||
if (opts == null) return;
|
||||
if (opts.containsKey(PROP_BUFFER_SIZE))
|
||||
_maxBufferSize = getInt(opts, PROP_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
|
||||
if (opts.containsKey(PROP_CONNECT_TIMEOUT))
|
||||
_connectTimeout = getInt(opts, PROP_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
|
||||
if (opts.containsKey(PROP_READ_TIMEOUT))
|
||||
_readTimeout = getInt(opts, PROP_READ_TIMEOUT, -1);
|
||||
if (opts.containsKey(PROP_WRITE_TIMEOUT))
|
||||
_writeTimeout = getInt(opts, PROP_WRITE_TIMEOUT, DEFAULT_WRITE_TIMEOUT);
|
||||
}
|
||||
|
||||
protected void init(Properties opts) {
|
||||
_maxBufferSize = getInt(opts, PROP_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
|
||||
_connectTimeout = getInt(opts, PROP_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
|
||||
|
||||
@@ -115,6 +115,7 @@ public class StreamSinkServer {
|
||||
}
|
||||
public void run() {
|
||||
if (_fos == null) return;
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
InputStream in = _sock.getInputStream();
|
||||
byte buf[] = new byte[4096];
|
||||
@@ -126,7 +127,8 @@ public class StreamSinkServer {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("read and wrote " + read);
|
||||
}
|
||||
_log.error("Got EOF from client socket [written=" + written + "]");
|
||||
long lifetime = System.currentTimeMillis() - start;
|
||||
_log.error("Got EOF from client socket [written=" + written + " lifetime=" + lifetime + "]");
|
||||
} catch (IOException ioe) {
|
||||
_log.error("Error writing the sink", ioe);
|
||||
} finally {
|
||||
|
||||
236
apps/pants/build.xml
Normal file
236
apps/pants/build.xml
Normal file
@@ -0,0 +1,236 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Ports + Ant = Pants, a simple Ant-based package manager
|
||||
|
||||
free (adj.): unencumbered; not under the control of others
|
||||
|
||||
Written by smeghead in 2005 and released into the public domain with no
|
||||
warranty of any kind, either expressed or implied. It probably won't make
|
||||
your computer catch on fire, or eat your children, but it might. Use at your
|
||||
own risk.
|
||||
-->
|
||||
|
||||
<project basedir="." default="help" name="pants-interface">
|
||||
|
||||
<!-- .......................... Global Properties .......................... -->
|
||||
|
||||
|
||||
|
||||
<!-- ........................... Internal Tasks ............................ -->
|
||||
|
||||
<target name="-fetchCvs" unless="cvs.source.available" if="using.cvs">
|
||||
<cvs compressionlevel="${cvs.compression.level}"
|
||||
date="${cvs.date}"
|
||||
dest="./distfiles/cvs-src/${pbuild}"
|
||||
failonerror="true"
|
||||
package="${cvs.package}"
|
||||
passfile="${cvs.passfile}"
|
||||
port="${cvs.port}"
|
||||
cvsRoot="${cvs.root}"
|
||||
cvsRsh="${cvs.rsh}"
|
||||
tag="${cvs.tag}"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="-fetchPackage" unless="using.cvs">
|
||||
<get src="${package.url}"
|
||||
verbose="true"
|
||||
dest="./distfiles"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="-init">
|
||||
<!--
|
||||
TODO: Create dist/ and working/ folders for each pbuild subdir in case
|
||||
they've been wiped.
|
||||
-->
|
||||
<loadproperties srcfile="world" />
|
||||
<taskdef name="mergetypedproperties"
|
||||
classname="net.i2p.pants.MergeTypedPropertiesTask"
|
||||
classpath="./lib/pants.jar"
|
||||
/>
|
||||
<mergetypedproperties input="./pbuilds/${pbuild}/pbuild.properties"
|
||||
output="./pbuilds/${pbuild}/merged-properties.temp"
|
||||
booleanList="version.latest.find.regex.canonicaleq, version.latest.find.regex.caseinsensitive, version.latest.find.regex.comments, version.latest.find.regex.dotall, version.latest.find.regex.multiline, version.latest.find.regex.unicodecase, version.latest.find.regex.unixlines"
|
||||
stringList="cvs.compression.level, cvs.date, cvs.package, cvs.passfile, cvs.port, cvs.root, cvs.rsh, cvs.tag, package.url, version.latest, version.latest.find.url, version.latest.find.regex"
|
||||
/>
|
||||
<loadproperties srcfile="./pbuilds/${pbuild}/merged-properties.temp" />
|
||||
<delete file="./pbuilds/${pbuild}/merged-properties.temp" />
|
||||
<!--
|
||||
If '-Dpbuild={name}' isn't specified, the 'build', 'fetch', 'update'
|
||||
and 'version' commands should default to 'world' behavior.
|
||||
-->
|
||||
<antcall target="-setWorld" />
|
||||
<condition property="using.cvs">
|
||||
<or>
|
||||
<equals arg1="CVS" arg2="${version.using.${pbuild}}" />
|
||||
<equals arg1="cvs" arg2="${version.using.${pbuild}}" />
|
||||
</or>
|
||||
</condition>
|
||||
<!--
|
||||
If 'version.recommended' isn't defined in pbuild.properties, default
|
||||
to latest available version.
|
||||
-->
|
||||
</target>
|
||||
|
||||
<target name="-setWorld" unless="pbuild">
|
||||
<property name="pbuild" value="world" />
|
||||
</target>
|
||||
|
||||
<target name="-unpackTarBz2">
|
||||
<untar src="${pbuild.package}"
|
||||
compression="bzip2"
|
||||
dest="./${pbuild}/working"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="-unpackTarGzip">
|
||||
<untar src="${pbuild.package}"
|
||||
compression="gzip"
|
||||
dest="./${pbuild}/working"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="-unpackZip">
|
||||
<unzip src="${pbuild.package}" dest="./${pbuild}/working" />
|
||||
</target>
|
||||
|
||||
<target name="-updateCvs" if="using.cvs">
|
||||
<cvs command="update -d"
|
||||
compressionlevel="${compression.level}"
|
||||
date="${cvs.date}"
|
||||
dest="./distfiles/cvs-src"
|
||||
failonerror="true"
|
||||
package="${cvs.package}"
|
||||
passfile="${cvs.passfile}"
|
||||
port="${cvs.port}"
|
||||
cvsRoot="${cvs.root}"
|
||||
cvsRsh="${cvs.rsh}"
|
||||
tag="${cvs.tag}"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="-updateConfirm" if="confirm.update" unless="no.prompts">
|
||||
<input validargs="y,Y,n,N"
|
||||
defaultvalue="n"
|
||||
addproperty="confirm.update.answer">
|
||||
You currently have the recommended version installed. A newer
|
||||
version will be installed if you continue and this may break some
|
||||
applications which depend on this package. Are you sure you want
|
||||
to update? [y/N]
|
||||
</input>
|
||||
<condition property="abort.update">
|
||||
<or>
|
||||
<equals arg1="n" arg2="${confirm.update.answer}" />
|
||||
<equals arg1="N" arg2="${confirm.update.answer}" />
|
||||
</or>
|
||||
</condition>
|
||||
<fail if="abort.update">Update aborted.</fail>
|
||||
</target>
|
||||
|
||||
<target name="-versionLatest">
|
||||
<get src="${version.latest.find.url}"
|
||||
dest="version.latest.in.temp"
|
||||
verbose="true"
|
||||
/>
|
||||
<taskdef name="match"
|
||||
classname="net.i2p.pants.MatchTask"
|
||||
classpath="./lib/pants.jar"
|
||||
/>
|
||||
<match input="version.latest.in.temp"
|
||||
output="version.latest.parsed.temp"
|
||||
regex="${version.latest.find.regex}"
|
||||
canonicaleq="${version.latest.find.regex.canonicaleq}"
|
||||
caseinsensitive="${version.latest.find.regex.caseinsensitive}"
|
||||
comments="${version.latest.find.regex.comments}"
|
||||
dotall="${version.latest.find.regex.dotall}"
|
||||
multiline="${version.latest.find.regex.multiline}"
|
||||
unicodecase="${version.latest.find.regex.unicodecase}"
|
||||
unixlines="${version.latest.find.regex.unixlines}"
|
||||
/>
|
||||
<loadproperties srcFile="version.latest.parsed.temp" />
|
||||
<delete file="version.latest.in.temp" />
|
||||
<delete file="version.latest.parsed.temp" />
|
||||
<property name="version.latest" value="${group.1}" />
|
||||
</target>
|
||||
|
||||
<target name="-versionRecommended">
|
||||
<property name="version.recommended" value="x" />
|
||||
</target>
|
||||
|
||||
<target name="-versionUsing">
|
||||
<property name="version.using" value="x" />
|
||||
</target>
|
||||
|
||||
<!-- .......................... Public Interface ........................... -->
|
||||
|
||||
<target name="build" depends="-init,fetch"
|
||||
description="Build a pbuild and its dependencies">
|
||||
<ant antfile="pbuild.xml" dir="./pbuilds/${pbuild}" target="clean" />
|
||||
<ant antfile="pbuild.xml" dir="./pbuilds/${pbuild}" target="build" />
|
||||
<!--
|
||||
Perform a 'clean' on the target first (but not 'distclean')
|
||||
-->
|
||||
</target>
|
||||
|
||||
<target name="fetch" depends="-init"
|
||||
description="Get package only">
|
||||
<antcall target="-fetchPackage" />
|
||||
<antcall target="-fetchCvs" />
|
||||
<copydir dest="./pbuilds/${pbuild}/working"
|
||||
src="./distfiles/cvs-src/${pbuild}"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="help"
|
||||
description="Display usage synopsis">
|
||||
<echo>
|
||||
Pants usage:
|
||||
|
||||
ant [--usejikes] [-Dpbuild={name}] [-Dpbuild.version={version}]
|
||||
[-D{property}={value}] [-Dno.prompts=true] build | fetch |
|
||||
help | install | uninstall | update | version
|
||||
|
||||
build Build a pbuild and its dependencies
|
||||
fetch Get package only
|
||||
help Display usage synopsis
|
||||
install Fetch, build and install a pbuild
|
||||
uninstall Uninstall a pbuild
|
||||
update Update pbuild(s) to the latest version(s)
|
||||
version Display pbuild version information
|
||||
</echo>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Install recommended version by default unless 'version' property is set.
|
||||
Do not install if package is already installed.
|
||||
-->
|
||||
<target name="install" depends="-init, build"
|
||||
description="Install a pbuild">
|
||||
<ant antfile="pbuild.xml" dir="./pbuilds/${pbuild}" target="dist" />
|
||||
<ant antfile="pbuild.xml" dir="./pbuilds/${pbuild}"
|
||||
target="distclean"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="uninstall" depends="-init"
|
||||
description="Uninstall a pbuild" />
|
||||
|
||||
<target name="update" depends="-init"
|
||||
description="Update pbuild(s) to the latest version(s)">
|
||||
<condition property="${confirm.update}">
|
||||
<equals arg1="${version.using}" arg2="${version.recommended}" />
|
||||
</condition>
|
||||
<antcall target="-updateConfirm" />
|
||||
</target>
|
||||
|
||||
<target name="version"
|
||||
depends="-init, -versionRecommended, -versionUsing, -versionLatest"
|
||||
description="Display pbuild version information">
|
||||
<echo message="Latest version: ${version.recommended}" />
|
||||
<echo message="Latest version: ${version.using}" />
|
||||
<echo message="Latest version: ${version.latest}" />
|
||||
</target>
|
||||
|
||||
</project>
|
||||
45
apps/pants/pants/build.xml
Normal file
45
apps/pants/pants/build.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project basedir="." default="build" name="build-pants">
|
||||
|
||||
<target name="build"
|
||||
description="Build the source">
|
||||
<mkdir dir="./java/build"/>
|
||||
<javac srcdir="./java/src" source="1.3" target="1.3" deprecation="on" destdir="./java/build" />
|
||||
</target>
|
||||
|
||||
<target name="clean"
|
||||
description="Remove all object files">
|
||||
<delete dir="./java/build" />
|
||||
<delete dir="./java/jartemp" />
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="build, jar"
|
||||
description="Create the jar and copy it to ../lib">
|
||||
<copy todir="../lib" file="./java/build/pants.jar" />
|
||||
</target>
|
||||
|
||||
<target name="distclean" depends="clean"
|
||||
description="Remove the jar and all object files" >
|
||||
<delete file="../lib/pants.jar" />
|
||||
</target>
|
||||
|
||||
<target name="jar">
|
||||
<delete dir="./java/jartemp" />
|
||||
<mkdir dir="./java/jartemp" />
|
||||
<copy todir="./java/jartemp">
|
||||
<fileset dir="./java/build" includes="**/*.class" />
|
||||
</copy>
|
||||
<jar basedir="./java/jartemp" jarfile="./java/build/pants.jar">
|
||||
<manifest>
|
||||
<section name="net.i2p.pants">
|
||||
<attribute name="Implementation-Title" value="Pants" />
|
||||
<attribute name="Implementation-Version" value="0.0.1" />
|
||||
<attribute name="Implementation-Vendor" value="I2P" />
|
||||
<attribute name="Implementation-Vendor-Id" value="I2P" />
|
||||
<attribute name="Implementation-URL" value="http://www.i2p.net" />
|
||||
</section>
|
||||
</manifest>
|
||||
</jar>
|
||||
<delete dir="./java/jartemp" />
|
||||
</target>
|
||||
</project>
|
||||
212
apps/pants/pants/java/src/net/i2p/pants/MatchTask.java
Normal file
212
apps/pants/pants/java/src/net/i2p/pants/MatchTask.java
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Ports + Ant = Pants, a simple Ant-based package manager
|
||||
*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
*
|
||||
* Written by smeghead in 2005 and released into the public domain with no
|
||||
* warranty of any kind, either expressed or implied. It probably won't make
|
||||
* your computer catch on fire, or eat your children, but it might. Use at your
|
||||
* own risk.
|
||||
*/
|
||||
|
||||
package net.i2p.pants;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Task;
|
||||
|
||||
/**
|
||||
* <p>Custom Ant task for matching the contents of a file against a given
|
||||
* regular expression and writing any matching groups to a file in
|
||||
* <code>java.util.Properties</code> format.
|
||||
* </p>
|
||||
* <p>Each key in the properties file is named after the number corresponding to
|
||||
* its matching group and its value is the contents of the matching group.
|
||||
* </p>
|
||||
* <p>Regular expressions passed to this task must conform to the specification
|
||||
* used by Sun's <code>java.util.regex</code> package and thus are mostly
|
||||
* compatible with Perl 5 regular expressions.
|
||||
* </p>
|
||||
* <p>When calling the <code>match</code> task, the attributes
|
||||
* <code>input</code>, <code>output</code>, and <code>regex</code> are required.
|
||||
* </p>
|
||||
* <p>Optional boolean attributes may be used to toggle various modes for the
|
||||
* regular expression engine (all are set to <code>false</code> by default):
|
||||
* </p>
|
||||
* <table>
|
||||
* <tr><td><code>canonicaleq</code></td><td>Enable canonical equivalence</td></tr>
|
||||
* <tr><td><code>caseinsensitive</code></td><td>Enable case-insensitive matching</td></tr>
|
||||
* <tr><td><code>comments</code></td><td>Permit whitespace and comments in pattern</td></tr>
|
||||
* <tr><td><code>dotall</code></td><td>Enable dotall mode</td></tr>
|
||||
* <tr><td><code>multiline</code></td><td>Enable multi-line mode</td></tr>
|
||||
* <tr><td><code>unicodecase</code></td><td>Enable Unicode-aware case folding</td></tr>
|
||||
* <tr><td><code>unixlines</code></td><td>Enable Unix lines mode</td></tr>
|
||||
* </table>
|
||||
* <p>There is one additional optional boolean attribute,
|
||||
* <code>failOnNoMatch</code>. If this attribute is <code>true</code> it causes
|
||||
* the <code>match</code> task to throw a
|
||||
* <code>org.apache.tools.ant.BuildException</code> and fail if no matches for
|
||||
* the regular expression are found. The default value is <code>false</code>,
|
||||
* meaning a failed match will simply result in a warning message to
|
||||
* <code>STDERR</code> and an empty (0 byte) <code>output</code> file being
|
||||
* created.
|
||||
* </p>
|
||||
* <p>
|
||||
* <h4>Example</h4>
|
||||
* </p>
|
||||
* <p>Contents of input file <code>letter.txt</code>:
|
||||
* <pre>
|
||||
* Dear Alice,
|
||||
*
|
||||
* How's about you and me gettin' together for some anonymous foo action?
|
||||
*
|
||||
* Kisses,
|
||||
* Bob
|
||||
* </pre>
|
||||
* </p>
|
||||
* <p>Ant <code>match</code> task and a <code>taskdef</code> defining it:
|
||||
* <pre>
|
||||
* <taskdef name="match" classname="net.i2p.pants.MatchTask" classpath="../../lib/pants.jar" />
|
||||
* <match input="letter.txt"
|
||||
* output="matches.txt"
|
||||
* regex="about (\S*?) and (\S*?) .+anonymous (\S*?)"
|
||||
* />
|
||||
* </pre>
|
||||
* </p>
|
||||
* <p>Contents of properties file <code>matches.txt</code> written by this task:
|
||||
* <pre>
|
||||
* group.0=about you and me gettin' together for some anonymous foo
|
||||
* group.1=you
|
||||
* group.2=me
|
||||
* group.3=foo
|
||||
* </pre>
|
||||
* </p>
|
||||
* <p>These values can be loaded from <code>matches.txt</code> into Ant
|
||||
* properties like so:
|
||||
* <pre>
|
||||
* <loadproperties srcFile="matches.txt" />
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @author smeghead
|
||||
*/
|
||||
public class MatchTask extends Task {
|
||||
|
||||
private boolean _failOnNoMatch;
|
||||
private String _inputFile;
|
||||
private String _outputFile;
|
||||
private String _regex;
|
||||
private int _regexFlags;
|
||||
|
||||
public void execute() throws BuildException {
|
||||
int charRead = 0;
|
||||
FileReader fileReader = null;
|
||||
FileWriter fileWriter = null;
|
||||
Matcher matcher = null;
|
||||
Pattern pattern = null;
|
||||
PrintWriter printWriter = null;
|
||||
StringBuffer text = new StringBuffer();
|
||||
|
||||
if (_inputFile == null)
|
||||
throw new BuildException("Error: 'match' task requires 'input' attribute");
|
||||
|
||||
if (_outputFile == null)
|
||||
throw new BuildException("Error: 'match' task requires 'output' attribute");
|
||||
|
||||
if (_regex == null)
|
||||
throw new BuildException("Error: 'match' task requires 'regex' attribute");
|
||||
|
||||
pattern = Pattern.compile(_regex, _regexFlags);
|
||||
|
||||
try {
|
||||
fileReader = new FileReader(_inputFile);
|
||||
|
||||
while ((charRead = fileReader.read()) != -1)
|
||||
text.append((char) charRead);
|
||||
|
||||
fileReader.close();
|
||||
matcher = pattern.matcher(text);
|
||||
|
||||
if (matcher.find()) {
|
||||
printWriter = new PrintWriter(new FileWriter(_outputFile));
|
||||
|
||||
for (int i = 0; i <= matcher.groupCount(); i++)
|
||||
printWriter.println("group." + Integer.toString(i) + "=" + matcher.group(i));
|
||||
|
||||
printWriter.flush();
|
||||
printWriter.close();
|
||||
} else {
|
||||
if (_failOnNoMatch) {
|
||||
throw new BuildException("Error: No matches found in " + _inputFile);
|
||||
} else {
|
||||
System.err.println("Warning: No matches found in " + _inputFile);
|
||||
// Create 0 byte output file.
|
||||
fileWriter = new FileWriter(_outputFile);
|
||||
fileWriter.close();
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
throw new BuildException("File " + _inputFile + " not found", fnfe);
|
||||
} catch (IOException ioe) {
|
||||
throw new BuildException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCanonicalEq(boolean enableCanonicalEq) {
|
||||
if (enableCanonicalEq)
|
||||
_regexFlags |= Pattern.CANON_EQ;
|
||||
}
|
||||
|
||||
public void setCaseInsensitive(boolean enableCaseInsensitive) {
|
||||
if (enableCaseInsensitive)
|
||||
_regexFlags |= Pattern.CASE_INSENSITIVE;
|
||||
}
|
||||
|
||||
public void setComments(boolean enableComments) {
|
||||
if (enableComments)
|
||||
_regexFlags |= Pattern.COMMENTS;
|
||||
}
|
||||
|
||||
public void setDotall(boolean enableDotall) {
|
||||
if (enableDotall)
|
||||
_regexFlags |= Pattern.DOTALL;
|
||||
}
|
||||
|
||||
public void setFailOnNoMatch(boolean failOnNoMatch) {
|
||||
_failOnNoMatch = failOnNoMatch;
|
||||
}
|
||||
|
||||
public void setInput(String inputFile) {
|
||||
_inputFile = inputFile;
|
||||
}
|
||||
|
||||
public void setMultiLine(boolean enableMultiLine) {
|
||||
if (enableMultiLine)
|
||||
_regexFlags |= Pattern.MULTILINE;
|
||||
}
|
||||
|
||||
public void setOutput(String outputFile) {
|
||||
_outputFile = outputFile;
|
||||
}
|
||||
|
||||
public void setRegex(String regex) {
|
||||
_regex = regex;
|
||||
}
|
||||
|
||||
public void setUnicodeCase(boolean enableUnicodeCase) {
|
||||
if (enableUnicodeCase)
|
||||
_regexFlags |= Pattern.UNICODE_CASE;
|
||||
}
|
||||
|
||||
public void setUnixLines(boolean enableUnixLines) {
|
||||
if (enableUnixLines)
|
||||
_regexFlags |= Pattern.UNIX_LINES;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Ports + Ant = Pants, a simple Ant-based package manager
|
||||
*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
*
|
||||
* Written by smeghead in 2005 and released into the public domain with no
|
||||
* warranty of any kind, either expressed or implied. It probably won't make
|
||||
* your computer catch on fire, or eat your children, but it might. Use at your
|
||||
* own risk.
|
||||
*/
|
||||
|
||||
package net.i2p.pants;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Task;
|
||||
|
||||
/**
|
||||
* <p>Custom Ant task for loading properties from a
|
||||
* <code>java.util.Properties</code> file then merging them with lists of
|
||||
* expected properties. When an expected property is found in the properties
|
||||
* file it is set to the value given for it in the file. If an expected property
|
||||
* from a list isn't found in the properties file its value will be set to "" or
|
||||
* "false", depending on the property's data type.
|
||||
* </p>
|
||||
* <p>A property's data type is determined by membership in one of two lists
|
||||
* which can be passed into an instance of this class: a string-typed list and a
|
||||
* boolean-typed list. Values for string-typed properties may be any valid
|
||||
* string accepted by <code>java.util.Properties</code>, and values for
|
||||
* boolean-typed properties must be either "false" or "true".
|
||||
* </p>
|
||||
* <p>Lists holding more than one property must be comma-delimited.
|
||||
* </p>
|
||||
* <p>The output of this class is a temporary <code>java.util.Properties</code>
|
||||
* file which is suitable for reading by the standard Ant
|
||||
* <code>loadproperties</code> task.
|
||||
* </p>
|
||||
* <p>Note that if any properties in the given lists have already been defined
|
||||
* before the <code>mergetypedproperties</code> task is called, their values
|
||||
* cannot be changed since Ant properties are immutable.
|
||||
* </p>
|
||||
* <h4>Example</h4>
|
||||
* </p>
|
||||
* <p>Contents of a properties file <code>my.properties</code>:
|
||||
* <pre>
|
||||
* some.property.exists=true
|
||||
* hasValue=false
|
||||
* some.property=this is a value
|
||||
* property0=bork bork
|
||||
* propertyX=this property wasn't passed in a list
|
||||
* </pre>
|
||||
* </p>
|
||||
* <p>Ant <code>mergetypedproperties</code> task and a <code>taskdef</code>
|
||||
* defining it:
|
||||
* <pre>
|
||||
* <taskdef name="mergetypedproperties" classname="net.i2p.pants.MergeTypedPropertiesTask" classpath="../../lib/pants.jar" />
|
||||
* <mergetypedproperties input="my.properties"
|
||||
* output="merged-properties.temp"
|
||||
* booleanList="some.property.exists,is.valid,hasValue"
|
||||
* stringList="some.property,another.property,property0"
|
||||
* />
|
||||
* </pre>
|
||||
* </p>
|
||||
* <p>Contents of properties file <code>merged-properties.temp</code> written by this task:
|
||||
* <pre>
|
||||
* some.property.exists=true
|
||||
* is.valid=false
|
||||
* hasValue=false
|
||||
* some.property=this is a value
|
||||
* another.property=
|
||||
* property0=bork bork
|
||||
* propertyX=this property wasn't passed in a list
|
||||
* </pre>
|
||||
* </p>
|
||||
* <p>If you don't want this task's output to include properties which weren't
|
||||
* in the lists of expected properties, you can set the attribute
|
||||
* <code>onlyExpected</code> to <code>true</code>. In the example, this would
|
||||
* result in the file <code>merged-properties.temp</code> containing only the
|
||||
* following properties:
|
||||
* <pre>
|
||||
* some.property.exists=true
|
||||
* is.valid=false
|
||||
* hasValue=false
|
||||
* some.property=this is a value
|
||||
* another.property=
|
||||
* property0=bork bork
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @author smeghead
|
||||
*/
|
||||
public class MergeTypedPropertiesTask extends Task {
|
||||
|
||||
private String _booleanList = "";
|
||||
private String _inputFile;
|
||||
private boolean _onlyExpected;
|
||||
private String _outputFile;
|
||||
private Properties _propertiesIn = new Properties();
|
||||
private Properties _propertiesOut = new Properties();
|
||||
private String _stringList = "";
|
||||
|
||||
public void execute() throws BuildException {
|
||||
StringTokenizer strtokBoolean = new StringTokenizer(_booleanList, ",");
|
||||
StringTokenizer strtokString = new StringTokenizer(_stringList, ",");
|
||||
String property = "";
|
||||
|
||||
if (_inputFile == null)
|
||||
throw new BuildException("Error: 'mergetypedproperties' task requires 'input' attribute");
|
||||
|
||||
if (_outputFile == null)
|
||||
throw new BuildException("Error: 'mergetypedproperties' task requires 'output' attribute");
|
||||
|
||||
// Add some type-checking on the list elements
|
||||
|
||||
try {
|
||||
_propertiesIn.load(new FileInputStream(_inputFile));
|
||||
|
||||
while (strtokBoolean.hasMoreTokens())
|
||||
_propertiesOut.setProperty(strtokBoolean.nextToken().trim(), "false");
|
||||
|
||||
while (strtokString.hasMoreTokens())
|
||||
_propertiesOut.setProperty(strtokString.nextToken().trim(), "");
|
||||
|
||||
for (Enumeration enum = _propertiesIn.elements(); enum.hasMoreElements(); ) {
|
||||
property = (String) enum.nextElement();
|
||||
|
||||
if (_onlyExpected && !_propertiesOut.containsKey(property))
|
||||
continue;
|
||||
else
|
||||
_propertiesOut.setProperty(property, _propertiesIn.getProperty(property));
|
||||
}
|
||||
|
||||
_propertiesOut.store(new FileOutputStream(_inputFile), "This is a temporary file. It is safe to delete it.");
|
||||
} catch (IOException ioe) {
|
||||
throw new BuildException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBooleanList(String booleanList) {
|
||||
_booleanList = booleanList;
|
||||
}
|
||||
|
||||
public void setInput(String inputFile) {
|
||||
_inputFile = inputFile;
|
||||
}
|
||||
|
||||
public void setOnlyExpected(boolean onlyExpected) {
|
||||
_onlyExpected = onlyExpected;
|
||||
}
|
||||
|
||||
public void setOutput(String outputFile) {
|
||||
_outputFile = outputFile;
|
||||
}
|
||||
|
||||
public void setStringList(String stringList) {
|
||||
_stringList = stringList;
|
||||
}
|
||||
}
|
||||
116
apps/pants/pants/resources/README
Normal file
116
apps/pants/pants/resources/README
Normal file
@@ -0,0 +1,116 @@
|
||||
What is Pants?
|
||||
--------------
|
||||
|
||||
Pants is an Apache Ant-based package manager for the management of 3rd party
|
||||
dependencies in Java development projects. It's loosely modeled after
|
||||
FreeBSD's Ports and Gentoo Linux's Portage, with two major differences:
|
||||
|
||||
* Pants isn't intended for system-wide package management. It's tailored for
|
||||
per-project 3rd party package management. You will typically have one
|
||||
Pants repository per project and each repository will be located somewhere
|
||||
under your project's root directory. If you're familiar with Ports or
|
||||
Portage, a Pants repository is roughly analogous to /usr/ports or
|
||||
/usr/portage.
|
||||
|
||||
* Pants is extremely portable. It goes anywhere Apache Ant goes.
|
||||
|
||||
Pants takes a modular approach to the standard Ant buildfile, breaking it
|
||||
into 3 files for functionality and convenience:
|
||||
|
||||
1. The Pants public interface, pants/build.xml, provides a single consistent
|
||||
way to access and manipulate dependency packages and relieves some of the
|
||||
developer's burden by providing implementations for some frequently-used
|
||||
and complex Ant operations.
|
||||
|
||||
2. pbuild.xml is a specially-structured and slimmed-down Ant buildfile in
|
||||
which you implement custom handling for a package your project depends
|
||||
on. This is known as the "pbuild" and is roughly analogous to a FreeBSD
|
||||
port or a Gentoo ebuild. A fairly explanatory template for pbuilds,
|
||||
pbuild.template.xml, is provided.
|
||||
|
||||
3. pbuild.properties contains those properties for a specific pbuild which
|
||||
are most likely to change over time. It uses the java.util.Properties
|
||||
format which is more human-friendly for hand-editing than Ant/XML. A
|
||||
fairly explanatory template, pbuild.template.properties, is provided.
|
||||
|
||||
There is one more file that completes the Pants system: the metadata file
|
||||
pants/world is a database for keeping track of all packages managed by Pants
|
||||
for your project.
|
||||
|
||||
Pants automatically handles versioning for your project's dependency
|
||||
packages and keeps track of their recommended versions, currently used
|
||||
versions, and latest available versions. This makes it extremely simple for
|
||||
project developers to switch back and forth between different versions of a
|
||||
dependency, and makes it just as easy to update a dependency. You can even
|
||||
update all your project's Pants-managed packages with a single command.
|
||||
|
||||
Pbuilds are designed to automatically handle the downloading, building,
|
||||
repackaging and deployment of source archives, binary archives, and CVS
|
||||
sources, all in a manner that's completely transparent to the project
|
||||
developer. Pbuilds currently support tar + gzip, tar + bzip2, and zip
|
||||
archives.
|
||||
|
||||
Because it is based on Ant, Pants integrates very well with Ant buildfiles
|
||||
and will fit easily into your project's Ant build framework. However, its
|
||||
interface is simple enough to be called just as easily by more traditional
|
||||
build systems such as GNU Make.
|
||||
|
||||
|
||||
Why Should I Use Pants?
|
||||
-----------------------
|
||||
|
||||
There are many applications for Pants, but a few use cases should best serve
|
||||
to illustrate its usefulness:
|
||||
|
||||
1. You have a project that you ship with several 3rd party libraries but the
|
||||
versions you're using are stale. With a single command, Pants can
|
||||
automatically discover the latest release versions for all of these, then
|
||||
download, build, and place the fresh libraries where your project's main
|
||||
build system expects them to be at build time.
|
||||
|
||||
2. You want to test multiple versions of a 3rd party library against your
|
||||
project. Pants only requires you to issue a single command to switch
|
||||
library versions, so can spend more time testing and less time hunting
|
||||
packages down, unpackaging them, symlinking, etc.
|
||||
|
||||
3. Pants is public domain. You can ship it with your project if you need to
|
||||
without having to worry about petty intellectual property or licensing
|
||||
issues.
|
||||
|
||||
|
||||
Minimum Requirements
|
||||
--------------------
|
||||
|
||||
* Apache Ant 1.6.2 or higher is recommended
|
||||
|
||||
* Any Java runtime and operating system that will run Ant
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Not finished yet.
|
||||
|
||||
|
||||
Why the Silly Name?
|
||||
-------------------
|
||||
|
||||
Ports + Ant = Pants. Any other explanation is purely a product of your
|
||||
twisted imagination.
|
||||
|
||||
|
||||
Miscellaneous Pocket Fluff
|
||||
--------------------------
|
||||
|
||||
Author: smeghead <smeghead@i2pmail.org> <smeghead@mail.i2p>
|
||||
|
||||
License: No license necessary. This work is released into the public domain.
|
||||
|
||||
Price: Free! But if you really appreciate Pants, or you're just a sicko,
|
||||
please send me a picture of your worst or most unusual pair of
|
||||
pants so I can add it to the Whirling Hall of Pants on pants.i2p,
|
||||
the official Pants eepsite (that's an anonymous website on I2P--see
|
||||
http://www.i2p.net for more information).
|
||||
|
||||
|
||||
$Id$
|
||||
110
apps/pants/pants/resources/pbuild.template.properties
Normal file
110
apps/pants/pants/resources/pbuild.template.properties
Normal file
@@ -0,0 +1,110 @@
|
||||
# The properties defined in this file can be overridden on the command line by
|
||||
# passing them in as parameters like so:
|
||||
#
|
||||
# ant -Dpbuild=myapp -Dversion.recommended=2.0.5 install
|
||||
#
|
||||
# *** DO NOT DEFINE A PROPERTY BUT LEAVE ITS VALUE BLANK. PANTS WILL BREAK! ***
|
||||
|
||||
|
||||
# Recommended Package Version
|
||||
#
|
||||
# Set this property's value to the package version you want Pants to use for the
|
||||
# pbuild by default. The version string specified must match the version
|
||||
# substring from the package's filename if the filename contains a version
|
||||
# number.
|
||||
#
|
||||
# Comment out this property to force use of the latest available version.
|
||||
#
|
||||
# If the pbuild is CVS-based rather than package-based, this property must be
|
||||
# set to 'CVS'.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# version.recommended=2.0.4
|
||||
|
||||
|
||||
# Latest Package Version
|
||||
#
|
||||
# There are currently two ways to inform Pants of the latest version number for
|
||||
# your package.
|
||||
#
|
||||
# Method 1: Manually modify the property 'version.latest' to reflect the latest
|
||||
# version number.
|
||||
#
|
||||
# Method 2: Provide a URL for a page on the package's website and a regular
|
||||
# expression with which to parse it in order to extract the version
|
||||
# number of the latest available package. For this you must define the
|
||||
# properties 'version.latest.find.url', 'version.latest.find.regex',
|
||||
# and any regular expression engine mode flags needed. The pattern
|
||||
# defined must have exactly one capturing group to encapsulate the
|
||||
# version string, otherwise the operation will fail.
|
||||
#
|
||||
# You may use both methods, in which case the version number specified by Method
|
||||
# 1 will be used as the fallback value if Method 2 for some reason is
|
||||
# unsuccessful.
|
||||
#
|
||||
# If neither method is enabled here or they fail to return a valid value to
|
||||
# Pants, the 'ant update' operation for this pbuild may exit ungracefully unless
|
||||
# the pbuild is CVS-based (none of the version.latest.* properties are used by
|
||||
# CVS-based pbuilds).
|
||||
#
|
||||
# The following is a list of boolean properties for optional mode flags used by
|
||||
# the regular expression engine. Set a value of "true" for any you wish to use.
|
||||
#
|
||||
# version.latest.find.regex.canonicaleq - Enable canonical equivalence
|
||||
# version.latest.find.regex.caseinsensitive - Enable case-insensitive matching
|
||||
# version.latest.find.regex.comments - Permit whitespace and comments
|
||||
# version.latest.find.regex.dotall - Enable dotall mode
|
||||
# version.latest.find.regex.multiline - Enable multi-line mode
|
||||
# version.latest.find.regex.unicodecase - Enable Unicode-aware case folding
|
||||
# version.latest.find.regex.unixlines - Enable Unix lines mode
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# version.latest=5.1.2
|
||||
# version.latest.find.url=http://sourceforge.net/projects/jetty/
|
||||
# version.latest.find.regex=Stable.+?Jetty-(.+?)</A>
|
||||
|
||||
|
||||
# Package URL
|
||||
#
|
||||
# Specify the URL pointing to the pbuild's package from here. The token
|
||||
# '${pbuild.version}' if used will automatically be expanded to the appropriate
|
||||
# version string.
|
||||
#
|
||||
# The package URL property is not used by CVS-based pbuilds.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# package.url=ftp://borkbork.se/bork-${pbuild.version}.tar.bz2
|
||||
# package.url=http://bork.borkbork.se/bork-${pbuild.version}-src.tar.gz
|
||||
|
||||
|
||||
# CVS Repository
|
||||
#
|
||||
# The values expected for CVS properties here are the same as those expected by
|
||||
# their corresponding Apache Ant 'Cvs' task attributes. For details see:
|
||||
#
|
||||
# http://ant.apache.org/manual/CoreTasks/cvs.html
|
||||
#
|
||||
# Not all of the 'Cvs' task's attributes have corresponding Pants properties.
|
||||
# The following is a list of all valid CVS properties for Pants (and their
|
||||
# default values if applicable):
|
||||
#
|
||||
# cvs.compression.level
|
||||
# cvs.date
|
||||
# cvs.package
|
||||
# cvs.passfile=~/.cvspass
|
||||
# cvs.port=2401
|
||||
# cvs.root
|
||||
# cvs.rsh
|
||||
# cvs.tag
|
||||
#
|
||||
# Of these, only the 'cvs.root' property is required for CVS-based pbuilds.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# cvs.root=:pserver:anoncvs@borkbork.se:/cvsroot/bork
|
||||
# cvs.rsh=ssh
|
||||
# cvs.package=borkbork
|
||||
|
||||
69
apps/pants/pants/resources/pbuild.template.xml
Normal file
69
apps/pants/pants/resources/pbuild.template.xml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
This is a template for Pants pbuilds. Pbuilds use standard Apache Ant syntax.
|
||||
For each target in the Public Interface section you must provide either an
|
||||
implementation or a stub. You may also add your own custom tasks and
|
||||
properties to this file. Be careful that none of your custom properties'
|
||||
names clash with the properties defined in pants/build.xml.
|
||||
-->
|
||||
|
||||
<project basedir="." default="build" name="name-of-pbuild-here">
|
||||
|
||||
<!-- ....................... Begin Public Interface ........................ -->
|
||||
|
||||
<!--
|
||||
When this target is called, the pbuild's sources and/or binaries have
|
||||
already been extracted/copied by Pants into the pbuild's working/
|
||||
subdirectory. This target must prepare those sources and/or binaries in
|
||||
the working/ subdirectory into deployable form, for example by building
|
||||
all necessary classes and jar files.
|
||||
|
||||
This target must not create or modify any files outside the pbuild's
|
||||
working/ subdirectory. (An automatic sandboxing mechanism should be added
|
||||
to Pants at some point.) It is however acceptable for a task called by
|
||||
'builddep' to modify files outside of this pbuild's working/ directory.
|
||||
-->
|
||||
<target name="build" depends="builddep" />
|
||||
|
||||
<!--
|
||||
Use this to call targets from other pbuilds, Ant buildfiles, Makefiles,
|
||||
etc. which perform tasks this pbuild's 'build' target depends on. If other
|
||||
pbuilds are called here, they must be called through the Pants interface
|
||||
or else it may leave Pants in an inconsistent state.
|
||||
|
||||
Most pbuilds probably won't need to implement this target.
|
||||
-->
|
||||
<target name="builddep" />
|
||||
|
||||
<!--
|
||||
This target must undo the actions performed by the 'build' target.
|
||||
-->
|
||||
<target name="clean" depends="depclean" />
|
||||
|
||||
<!--
|
||||
If the 'builddep' target is implemented, this target must be implemented
|
||||
to undo its actions.
|
||||
-->
|
||||
<target name="depclean" />
|
||||
|
||||
<!--
|
||||
This target must copy all deployable files generated by the 'build' target
|
||||
into the pbuild's dist/ subdirectory (for use by other pbuilds or Ant
|
||||
processes) or to their final deployment locations outside the pants/
|
||||
directory hierarchy. Note that the latter may require the user to gain
|
||||
superuser/admin privileges.
|
||||
-->
|
||||
<target name="dist" depends="build" />
|
||||
|
||||
<!--
|
||||
This target must remove all files from the pbuild's dist/ subdirectory
|
||||
and final deployment locations, reversing the actions of the 'dist'
|
||||
target. Note that removal of files from their final deployment locations
|
||||
may require the user to gain superuser/admin privileges.
|
||||
-->
|
||||
<target name="distclean" depends="clean" />
|
||||
|
||||
<!-- ........................ End Public Interface ......................... -->
|
||||
|
||||
</project>
|
||||
112
apps/pants/pbuilds/fortuna/pbuild.properties
Normal file
112
apps/pants/pbuilds/fortuna/pbuild.properties
Normal file
@@ -0,0 +1,112 @@
|
||||
# The properties defined in this file can be overridden on the command line by
|
||||
# passing them in as parameters like so:
|
||||
#
|
||||
# ant -Dpbuild=myapp -Dversion.recommended=2.0.5 install
|
||||
#
|
||||
# *** DO NOT DEFINE A PROPERTY BUT LEAVE ITS VALUE BLANK. PANTS WILL BREAK! ***
|
||||
|
||||
|
||||
# Recommended Package Version
|
||||
#
|
||||
# Set this property's value to the package version you want Pants to use for the
|
||||
# pbuild by default. The version string specified must match the version
|
||||
# substring from the package's filename if the filename contains a version
|
||||
# number.
|
||||
#
|
||||
# Comment out this property to force use of the latest available version.
|
||||
#
|
||||
# If the pbuild is CVS-based rather than package-based, this property must be
|
||||
# set to 'CVS'.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# version.recommended=2.0.4
|
||||
version.recommended=CVS
|
||||
|
||||
# Latest Package Version
|
||||
#
|
||||
# There are currently two ways to inform Pants of the latest version number for
|
||||
# your package.
|
||||
#
|
||||
# Method 1: Manually modify the property 'version.latest' to reflect the latest
|
||||
# version number.
|
||||
#
|
||||
# Method 2: Provide a URL for a page on the package's website and a regular
|
||||
# expression with which to parse it in order to extract the version
|
||||
# number of the latest available package. For this you must define the
|
||||
# properties 'version.latest.find.url', 'version.latest.find.regex',
|
||||
# and any regular expression engine mode flags needed. The pattern
|
||||
# defined must have exactly one capturing group to encapsulate the
|
||||
# version string, otherwise the operation will fail.
|
||||
#
|
||||
# You may use both methods, in which case the version number specified by Method
|
||||
# 1 will be used as the fallback value if Method 2 for some reason is
|
||||
# unsuccessful.
|
||||
#
|
||||
# If neither method is enabled here or they fail to return a valid value to
|
||||
# Pants, the 'ant update' operation for this pbuild may exit ungracefully unless
|
||||
# the pbuild is CVS-based (none of the version.latest.* properties are used by
|
||||
# CVS-based pbuilds).
|
||||
#
|
||||
# The following is a list of boolean properties for optional mode flags used by
|
||||
# the regular expression engine. Set a value of "true" for any you wish to use.
|
||||
#
|
||||
# version.latest.find.regex.canonicaleq - Enable canonical equivalence
|
||||
# version.latest.find.regex.caseinsensitive - Enable case-insensitive matching
|
||||
# version.latest.find.regex.comments - Permit whitespace and comments
|
||||
# version.latest.find.regex.dotall - Enable dotall mode
|
||||
# version.latest.find.regex.multiline - Enable multi-line mode
|
||||
# version.latest.find.regex.unicodecase - Enable Unicode-aware case folding
|
||||
# version.latest.find.regex.unixlines - Enable Unix lines mode
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# version.latest=5.1.2
|
||||
# version.latest.find.url=http://sourceforge.net/projects/jetty/
|
||||
# version.latest.find.regex=Stable.+?Jetty-(.+?)</A>
|
||||
|
||||
|
||||
# Package URL
|
||||
#
|
||||
# Specify the URL pointing to the pbuild's package from here. The token
|
||||
# '${pbuild.version}' if used will automatically be expanded to the appropriate
|
||||
# version string.
|
||||
#
|
||||
# The package URL property is not used by CVS-based pbuilds.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# package.url=ftp://borkbork.se/bork-${pbuild.version}.tar.bz2
|
||||
# package.url=http://bork.borkbork.se/bork-${pbuild.version}-src.tar.gz
|
||||
|
||||
|
||||
# CVS Repository
|
||||
#
|
||||
# The values expected for CVS properties here are the same as those expected by
|
||||
# their corresponding Apache Ant 'Cvs' task attributes. For details see:
|
||||
#
|
||||
# http://ant.apache.org/manual/CoreTasks/cvs.html
|
||||
#
|
||||
# Not all of the 'Cvs' task's attributes have corresponding Pants properties.
|
||||
# The following is a list of all valid CVS properties for Pants (and their
|
||||
# default values if applicable):
|
||||
#
|
||||
# cvs.compression.level
|
||||
# cvs.date
|
||||
# cvs.package
|
||||
# cvs.passfile=~/.cvspass
|
||||
# cvs.port=2401
|
||||
# cvs.root
|
||||
# cvs.rsh
|
||||
# cvs.tag
|
||||
#
|
||||
# Of these, only the 'cvs.root' property is required for CVS-based pbuilds.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# cvs.root=:pserver:anoncvs@borkbork.se:/cvsroot/bork
|
||||
# cvs.rsh=ssh
|
||||
# cvs.package=borkbork
|
||||
cvs.root=:ext:anoncvs@savannah.gnu.org:/cvsroot/gnu-crypto
|
||||
cvs.rsh=ssh
|
||||
cvs.package=gnu-crypto
|
||||
127
apps/pants/pbuilds/fortuna/pbuild.xml
Normal file
127
apps/pants/pbuilds/fortuna/pbuild.xml
Normal file
@@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project basedir="." default="build" name="fortuna-pbuild">
|
||||
|
||||
<property name="gnucrypt.base.dir" value="./working/gnu-crypto" />
|
||||
<property name="gnucrypt.etc.dir" value="${gnucrypt.base.dir}/etc" />
|
||||
<property name="gnucrypt.lib.dir" value="${gnucrypt.base.dir}/lib" />
|
||||
<property name="gnucrypt.object.dir" value="${gnucrypt.base.dir}/classes" />
|
||||
<property name="gnucrypt.base.crypto.object.dir" value="${gnucrypt.object.dir}/gnu/crypto" />
|
||||
<property name="gnucrypt.cipher.object.dir" value="${gnucrypt.base.crypto.object.dir}/cipher" />
|
||||
<property name="gnucrypt.hash.object.dir" value="${gnucrypt.base.crypto.object.dir}/hash" />
|
||||
<property name="gnucrypt.prng.object.dir" value="${gnucrypt.base.crypto.object.dir}/prng" />
|
||||
|
||||
<patternset id="fortuna.files">
|
||||
<include name="${gnucrypt.base.crypto.object.dir}/Registry.class" />
|
||||
<include name="${gnucrypt.prng.object.dir}/Fortuna*.class" />
|
||||
<include name="${gnucrypt.prng.object.dir}/BasePRNG.class" />
|
||||
<include name="${gnucrypt.prng.object.dir}/RandomEventListener.class" />
|
||||
<include name="${gnucrypt.prng.object.dir}/IRandom.class" />
|
||||
<include name="${gnucrypt.cipher.object.dir}/CipherFactory.class" />
|
||||
<include name="${gnucrypt.cipher.object.dir}/IBlockCipher.class" />
|
||||
<include name="${gnucrypt.hash.object.dir}/HashFactory.class" />
|
||||
<include name="${gnucrypt.hash.object.dir}/IMessageDigest.class" />
|
||||
</patternset>
|
||||
|
||||
<!--
|
||||
Add this when Fortuna tests are added to GNU Crypto, else write some
|
||||
-->
|
||||
<target name="-test" />
|
||||
|
||||
<!-- ....................... Begin Public Interface ........................ -->
|
||||
|
||||
<!--
|
||||
When this target is called, the pbuild's sources and/or binaries have
|
||||
already been extracted/copied by Pants into the pbuild's working/
|
||||
subdirectory. This target must prepare those sources and/or binaries in
|
||||
the working/ subdirectory into deployable form, for example by building
|
||||
all necessary classes and jar files.
|
||||
|
||||
This target must not create or modify any files outside the pbuild's
|
||||
working/ subdirectory. (An automatic sandboxing mechanism should be added
|
||||
to Pants at some point.) It is however acceptable for a task called by
|
||||
'builddep' to modify files outside of this pbuild's working/ directory.
|
||||
-->
|
||||
<target name="build" depends="builddep">
|
||||
<delete dir="./working/build" />
|
||||
<delete dir="./working/jartemp" />
|
||||
<mkdir dir="./working/build" />
|
||||
<mkdir dir="./working/jartemp/${gnucrypt.object.dir}" />
|
||||
<copy todir="./working/jartemp">
|
||||
<fileset dir=".">
|
||||
<patternset refid="fortuna.files" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<jar basedir="./working/jartemp/${gnucrypt.object.dir}" jarfile="./working/build/fortuna.jar">
|
||||
<manifest>
|
||||
<section name="fortuna">
|
||||
<attribute name="Implementation-Title" value="I2P Custom GNU Crypto Fortuna Library" />
|
||||
<attribute name="Implementation-Version" value="CVS HEAD" />
|
||||
<attribute name="Implementation-Vendor" value="Free Software Foundation" />
|
||||
<attribute name="Implementation-Vendor-Id" value="FSF" />
|
||||
<attribute name="Implementation-URL" value="http://www.gnu.org/software/gnu-crypto" />
|
||||
</section>
|
||||
</manifest>
|
||||
</jar>
|
||||
<delete dir="./working/jartemp" />
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Use this to call targets from other pbuilds, Ant buildfiles, Makefiles,
|
||||
etc. which perform tasks this pbuild's 'build' target depends on. If other
|
||||
pbuilds are called here, they must be called through the Pants interface
|
||||
or else it may leave Pants in an inconsistent state.
|
||||
|
||||
Most pbuilds probably won't need to implement this target.
|
||||
-->
|
||||
<target name="builddep">
|
||||
<ant dir="${gnucrypt.base.dir}" target="jar" />
|
||||
</target>
|
||||
|
||||
<!--
|
||||
This target must undo the actions performed by the 'build' target.
|
||||
-->
|
||||
<target name="clean" depends="depclean">
|
||||
<delete dir="./working/jartemp" />
|
||||
</target>
|
||||
|
||||
<!--
|
||||
If the 'builddep' target is implemented, this target must be implemented
|
||||
to undo its actions.
|
||||
-->
|
||||
<target name="depclean">
|
||||
<!--
|
||||
Annoyingly the GNU Crypto distclean task called here doesn't clean
|
||||
*all* derived files from java/gnu-crypto/lib like it should (because
|
||||
a couple of lines are commented out).....
|
||||
-->
|
||||
<ant dir="${gnucrypt.base.dir}" target="distclean" />
|
||||
<!--
|
||||
.....and so we mop up the rest ourselves.
|
||||
-->
|
||||
<delete dir="${gnucrypt.lib.dir}" />
|
||||
</target>
|
||||
|
||||
<!--
|
||||
This target must copy all deployable files generated by the 'build' target
|
||||
into the pbuild's dist/ subdirectory (for use by other pbuilds or Ant
|
||||
processes) or to their final deployment locations outside the pants/
|
||||
directory hierarchy. Note that the latter may require the user to gain
|
||||
superuser/admin privileges.
|
||||
-->
|
||||
<target name="dist" depends="build">
|
||||
<copy todir="./dist/fortuna.jar" file="./working/build/fortuna.jar" />
|
||||
</target>
|
||||
|
||||
<!--
|
||||
This target must remove all files from the pbuild's dist/ subdirectory
|
||||
and final deployment locations, reversing the actions of the 'dist'
|
||||
target. Note that removal of files from their final deployment locations
|
||||
may require the user to gain superuser/admin privileges.
|
||||
-->
|
||||
<target name="distclean" depends="clean">
|
||||
<delete file="./dist/fortuna.jar" />
|
||||
</target>
|
||||
|
||||
<!-- ........................ End Public Interface ......................... -->
|
||||
|
||||
</project>
|
||||
112
apps/pants/pbuilds/jetty/pbuild.properties
Normal file
112
apps/pants/pbuilds/jetty/pbuild.properties
Normal file
@@ -0,0 +1,112 @@
|
||||
# The properties defined in this file can be overridden on the command line by
|
||||
# passing them in as parameters like so:
|
||||
#
|
||||
# ant -Dpbuild=myapp -Dversion.recommended=2.0.5 install
|
||||
#
|
||||
# *** DO NOT DEFINE A PROPERTY BUT LEAVE ITS VALUE BLANK. PANTS WILL BREAK! ***
|
||||
|
||||
|
||||
# Recommended Package Version
|
||||
#
|
||||
# Set this property's value to the package version you want Pants to use for the
|
||||
# pbuild by default. The version string specified must match the version
|
||||
# substring from the package's filename if the filename contains a version
|
||||
# number.
|
||||
#
|
||||
# Comment out this property to force use of the latest available version.
|
||||
#
|
||||
# If the pbuild is CVS-based rather than package-based, this property must be
|
||||
# set to 'CVS'.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# version.recommended=2.0.4
|
||||
version.recommended=5.1.2
|
||||
|
||||
# Latest Package Version
|
||||
#
|
||||
# There are currently two ways to inform Pants of the latest version number for
|
||||
# your package.
|
||||
#
|
||||
# Method 1: Manually modify the property 'version.latest' to reflect the latest
|
||||
# version number.
|
||||
#
|
||||
# Method 2: Provide a URL for a page on the package's website and a regular
|
||||
# expression with which to parse it in order to extract the version
|
||||
# number of the latest available package. For this you must define the
|
||||
# properties 'version.latest.find.url', 'version.latest.find.regex',
|
||||
# and any regular expression engine mode flags needed. The pattern
|
||||
# defined must have exactly one capturing group to encapsulate the
|
||||
# version string, otherwise the operation will fail.
|
||||
#
|
||||
# You may use both methods, in which case the version number specified by Method
|
||||
# 1 will be used as the fallback value if Method 2 for some reason is
|
||||
# unsuccessful.
|
||||
#
|
||||
# If neither method is enabled here or they fail to return a valid value to
|
||||
# Pants, the 'ant update' operation for this pbuild may exit ungracefully unless
|
||||
# the pbuild is CVS-based (none of the version.latest.* properties are used by
|
||||
# CVS-based pbuilds).
|
||||
#
|
||||
# The following is a list of boolean properties for optional mode flags used by
|
||||
# the regular expression engine. Set a value of "true" for any you wish to use.
|
||||
#
|
||||
# version.latest.find.regex.canonicaleq - Enable canonical equivalence
|
||||
# version.latest.find.regex.caseinsensitive - Enable case-insensitive matching
|
||||
# version.latest.find.regex.comments - Permit whitespace and comments
|
||||
# version.latest.find.regex.dotall - Enable dotall mode
|
||||
# version.latest.find.regex.multiline - Enable multi-line mode
|
||||
# version.latest.find.regex.unicodecase - Enable Unicode-aware case folding
|
||||
# version.latest.find.regex.unixlines - Enable Unix lines mode
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# version.latest=5.1.2
|
||||
# version.latest.find.url=http://sourceforge.net/projects/jetty/
|
||||
# version.latest.find.regex=Stable.+?Jetty-(.+?)</A>
|
||||
version.latest=5.1.2
|
||||
version.latest.find.url=http://sourceforge.net/projects/jetty/
|
||||
version.latest.find.regex=Stable.+?Jetty-(.+?)</A>
|
||||
|
||||
# Package URL
|
||||
#
|
||||
# Specify the URL pointing to the pbuild's package from here. The token
|
||||
# '${pbuild.version}' if used will automatically be expanded to the appropriate
|
||||
# version string.
|
||||
#
|
||||
# The package URL property is not used by CVS-based pbuilds.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# package.url=ftp://borkbork.se/bork-${pbuild.version}.tar.bz2
|
||||
# package.url=http://bork.borkbork.se/bork-${pbuild.version}-src.tar.gz
|
||||
package.url=http://mesh.dl.sourceforge.net/sourceforge/jetty/jetty-${pbuild.version}.zip
|
||||
|
||||
# CVS Repository
|
||||
#
|
||||
# The values expected for CVS properties here are the same as those expected by
|
||||
# their corresponding Apache Ant 'Cvs' task attributes. For details see:
|
||||
#
|
||||
# http://ant.apache.org/manual/CoreTasks/cvs.html
|
||||
#
|
||||
# Not all of the 'Cvs' task's attributes have corresponding Pants properties.
|
||||
# The following is a list of all valid CVS properties for Pants (and their
|
||||
# default values if applicable):
|
||||
#
|
||||
# cvs.compression.level
|
||||
# cvs.date
|
||||
# cvs.package
|
||||
# cvs.passfile=~/.cvspass
|
||||
# cvs.port=2401
|
||||
# cvs.root
|
||||
# cvs.rsh
|
||||
# cvs.tag
|
||||
#
|
||||
# Of these, only the 'cvs.root' property is required for CVS-based pbuilds.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# cvs.root=:pserver:anoncvs@borkbork.se:/cvsroot/bork
|
||||
# cvs.rsh=ssh
|
||||
# cvs.package=borkbork
|
||||
|
||||
89
apps/pants/pbuilds/jetty/pbuild.xml
Normal file
89
apps/pants/pbuilds/jetty/pbuild.xml
Normal file
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project basedir="." default="all" name="jetty">
|
||||
|
||||
<!-- make this generic, place variables in properties file -->
|
||||
|
||||
<target name="all" depends="build"
|
||||
description="Run the build target" />
|
||||
|
||||
<target name="assignProperties" if="group.0">
|
||||
<property name="latest.jetty.version" value="${group.1}" />
|
||||
<available property="jetty.package.available" file="jetty-${latest.jetty.version}.zip" />
|
||||
<available property="jetty.package.unpacked.available" file="jettypkg/jetty-${latest.jetty.version}" />
|
||||
<echo message="Properties assigned" />
|
||||
</target>
|
||||
|
||||
<target name="build" depends="init, unpackJettyPackage" if="latest.jetty.version"
|
||||
description="Download latest Jetty package and copy needed libs to jettylib/">
|
||||
<property name="unpack.dir" value="jettypkg/jetty-${latest.jetty.version}" />
|
||||
<copy todir="jettylib" overwrite="true" file="${unpack.dir}/ext/ant.jar" />
|
||||
<copy todir="jettylib" overwrite="true" file="${unpack.dir}/ext/jasper-compiler.jar" />
|
||||
<copy todir="jettylib" overwrite="true" file="${unpack.dir}/ext/jasper-runtime.jar" />
|
||||
<copy todir="jettylib" overwrite="true" file="${unpack.dir}/ext/xercesImpl.jar" />
|
||||
<copy todir="jettylib" overwrite="true" file="${unpack.dir}/ext/xml-apis.jar" />
|
||||
<copy todir="jettylib" overwrite="true" file="${unpack.dir}/extra/lib/org.mortbay.jetty-jdk1.2.jar" />
|
||||
<copy todir="jettylib" overwrite="true" file="${unpack.dir}/lib/javax.servlet.jar" />
|
||||
<copy todir="jettylib" overwrite="true" file="${unpack.dir}/lib/org.mortbay.jetty.jar" />
|
||||
<copy todir="jettylib" overwrite="true">
|
||||
<fileset dir="${unpack.dir}/ext" includes="xmlParserAPIs*.jar" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="builddep"
|
||||
description="Build the custom helper Ant task for this buildfile">
|
||||
<mkdir dir="java/build"/>
|
||||
<javac srcdir="./java/src" source="1.3" target="1.3" deprecation="on" destdir="./java/build" />
|
||||
</target>
|
||||
|
||||
<target name="clean"
|
||||
description="Remove temp files and zip only; jettypkg/ requires manual deletion">
|
||||
<echo message="Not actually deleting the Jetty package directory since it's so large" />
|
||||
<delete>
|
||||
<fileset dir="." includes="*.zip jettytemp.html parsed.temp" />
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="cleandep"
|
||||
description="Remove custom helper Ant task">
|
||||
<delete dir="java/build" />
|
||||
</target>
|
||||
|
||||
<target name="compile" />
|
||||
|
||||
<target name="distclean" depends="clean"
|
||||
description="Remove temp files, zip and jettylib/ contents" >
|
||||
<delete>
|
||||
<fileset dir="jettylib" includes="*.jar"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="fetchJettyPackage" if="latest.jetty.version" unless="jetty.package.available">
|
||||
<echo message="The Jetty libs are not necessary for using I2P, but are used by some" />
|
||||
<echo message="applications on top of I2P such as the routerconsole." />
|
||||
<get src="http://mesh.dl.sourceforge.net/sourceforge/jetty/jetty-${latest.jetty.version}.zip" verbose="true" dest="jetty-${latest.jetty.version}.zip" />
|
||||
</target>
|
||||
|
||||
<target name="init" depends="builddep">
|
||||
<echo message="Checking SourceForge for latest Jetty version....." />
|
||||
<get src="http://sourceforge.net/projects/jetty/" dest="jettytemp.html" verbose="true" />
|
||||
<taskdef name="match" classname="net.i2p.pants.MatchTask" classpath="../../lib/pants.jar" />
|
||||
<match input="jettytemp.html"
|
||||
output="parsed.temp"
|
||||
regex="Stable.+?Jetty-(.+?)</A>"
|
||||
/>
|
||||
<loadproperties srcFile="parsed.temp" />
|
||||
<antcall target="assignProperties" />
|
||||
</target>
|
||||
|
||||
<target name="jar" />
|
||||
|
||||
<target name="showlatest" depends="init"
|
||||
description="Display latest version number for Jetty">
|
||||
<echo message="Latest Jetty version: ${latest.jetty.version}" />
|
||||
</target>
|
||||
|
||||
<target name="unpackJettyPackage" depends="fetchJettyPackage" if="latest.jetty.version" unless="jetty.package.unpacked.available">
|
||||
<mkdir dir="jettypkg" />
|
||||
<unzip src="jetty-${latest.jetty.version}.zip" dest="jettypkg" />
|
||||
</target>
|
||||
</project>
|
||||
2
apps/pants/world
Normal file
2
apps/pants/world
Normal file
@@ -0,0 +1,2 @@
|
||||
version.using.fortuna=CVS
|
||||
version.using.jetty=5.1.2
|
||||
@@ -20,7 +20,7 @@
|
||||
<classpath>
|
||||
<pathelement location="../../../core/java/build/i2p.jar" />
|
||||
<pathelement location="../../../router/java/build/router.jar" />
|
||||
<pathelement location="../../jetty/jettylib/org.mortbay.jetty-jdk1.2.jar" />
|
||||
<pathelement location="../../jetty/jettylib/org.mortbay.jetty.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../../systray/java/build/systray.jar" />
|
||||
<pathelement location="../../systray/java/lib/systray4j.jar" />
|
||||
@@ -48,20 +48,24 @@
|
||||
<mkdir dir="../jsp/WEB-INF/" />
|
||||
<mkdir dir="../jsp/WEB-INF/classes" />
|
||||
<!-- there are various jspc ant tasks, but they all seem a bit flakey -->
|
||||
<java classname="org.apache.jasper.JspC" fork="true" >
|
||||
<java classname="org.apache.jasper.JspC" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="../../jetty/jettylib/jasper-compiler.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jasper-runtime.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../../jetty/jettylib/commons-logging.jar" />
|
||||
<pathelement location="../../jetty/jettylib/commons-el.jar" />
|
||||
<pathelement location="../../jetty/jettylib/ant.jar" />
|
||||
<pathelement location="../../systray/java/build/obj" />
|
||||
<pathelement location="../../systray/java/lib/systray4j.jar" /> <!-- some javacs resolve recursively... -->
|
||||
<pathelement location="../../../installer/lib/wrapper/win32/wrapper.jar" /> <!-- we dont care if we're not on win32 -->
|
||||
<pathelement location="../../systray/java/lib/systray4j.jar" />
|
||||
<pathelement location="../../../installer/lib/wrapper/win32/wrapper.jar" />
|
||||
<pathelement location="build/routerconsole.jar" />
|
||||
<pathelement location="../../../router/java/build/router.jar" />
|
||||
<pathelement location="../../../core/java/build/i2p.jar" />
|
||||
</classpath>
|
||||
<arg value="-d" />
|
||||
<arg value="../jsp/WEB-INF/classes" />
|
||||
<arg value="-v9" />
|
||||
<arg value="-v" />
|
||||
<arg value="-p" />
|
||||
<arg value="net.i2p.router.web.jsp" />
|
||||
<arg value="-webinc" />
|
||||
@@ -69,10 +73,13 @@
|
||||
<arg value="-webapp" />
|
||||
<arg value="../jsp/" />
|
||||
</java>
|
||||
<javac destdir="../jsp/WEB-INF/classes/" srcdir="../jsp/WEB-INF/classes" includes="*.java">
|
||||
|
||||
<javac destdir="../jsp/WEB-INF/classes/" srcdir="../jsp/WEB-INF/classes" includes="**/*.java">
|
||||
<classpath>
|
||||
<pathelement location="../../jetty/jettylib/jasper-runtime.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../../jetty/jettylib/commons-logging.jar" />
|
||||
<pathelement location="../../jetty/jettylib/commons-el.jar" />
|
||||
<pathelement location="build/routerconsole.jar" />
|
||||
</classpath>
|
||||
</javac>
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import net.i2p.router.ClientTunnelSettings;
|
||||
|
||||
/**
|
||||
* Handler to deal with form submissions from the client config form and act
|
||||
* upon the values.
|
||||
*
|
||||
*/
|
||||
public class ConfigClientsHandler extends FormHandler {
|
||||
private String _numClients;
|
||||
private String _numTunnels;
|
||||
private String _numHops;
|
||||
private String _numHopsOutbound;
|
||||
private boolean _shouldSave;
|
||||
|
||||
public void ConfigNetHandler() {
|
||||
_shouldSave = false;
|
||||
}
|
||||
|
||||
protected void processForm() {
|
||||
if (_shouldSave) {
|
||||
saveChanges();
|
||||
} else {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
public void setShouldsave(String moo) { _shouldSave = true; }
|
||||
|
||||
public void setClientcount(String num) {
|
||||
_numClients = (num != null ? num.trim(): null);
|
||||
}
|
||||
public void setTunnelcount(String num) {
|
||||
_numTunnels = (num != null ? num.trim() : null);
|
||||
}
|
||||
public void setTunneldepth(String num) {
|
||||
_numHops = (num != null ? num.trim() : null);
|
||||
}
|
||||
public void setTunneldepthoutbound(String num) {
|
||||
_numHopsOutbound = (num != null ? num.trim() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user made changes to the network config and wants to save them, so
|
||||
* lets go ahead and do so.
|
||||
*
|
||||
*/
|
||||
private void saveChanges() {
|
||||
boolean saveRequired = false;
|
||||
|
||||
if ( (_numClients != null) && (_numClients.length() > 0) ) {
|
||||
_context.router().setConfigSetting("router.targetClients", _numClients);
|
||||
addFormNotice("Updating estimated number of clients to " + _numClients);
|
||||
saveRequired = true;
|
||||
}
|
||||
|
||||
if ( (_numTunnels != null) && (_numTunnels.length() > 0) ) {
|
||||
_context.router().setConfigSetting(ClientTunnelSettings.PROP_NUM_INBOUND, _numTunnels);
|
||||
addFormNotice("Updating default number of tunnels per client to " + _numTunnels);
|
||||
saveRequired = true;
|
||||
}
|
||||
|
||||
if ( (_numHops != null) && (_numHops.length() > 0) ) {
|
||||
_context.router().setConfigSetting(ClientTunnelSettings.PROP_DEPTH_INBOUND, _numHops);
|
||||
addFormNotice("Updating default tunnel length to " + _numHops);
|
||||
saveRequired = true;
|
||||
}
|
||||
|
||||
if ( (_numHopsOutbound != null) && (_numHopsOutbound.length() > 0) ) {
|
||||
_context.router().setConfigSetting(ClientTunnelSettings.PROP_DEPTH_OUTBOUND, _numHopsOutbound);
|
||||
addFormNotice("Updating default outbound tunnel length to " + _numHopsOutbound);
|
||||
saveRequired = true;
|
||||
}
|
||||
|
||||
if (saveRequired) {
|
||||
boolean saved = _context.router().saveConfig();
|
||||
if (saved)
|
||||
addFormNotice("Configuration saved successfully");
|
||||
else
|
||||
addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.ClientTunnelSettings;
|
||||
|
||||
public class ConfigClientsHelper {
|
||||
private RouterContext _context;
|
||||
/**
|
||||
* Configure this bean to query a particular router context
|
||||
*
|
||||
* @param contextId begging few characters of the routerHash, or null to pick
|
||||
* the first one we come across.
|
||||
*/
|
||||
public void setContextId(String contextId) {
|
||||
try {
|
||||
_context = ContextHelper.getContext(contextId);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** copied from the package private {@link net.i2p.router.tunnelmanager.TunnelPool} */
|
||||
public final static String TARGET_CLIENTS_PARAM = "router.targetClients";
|
||||
/** copied from the package private {@link net.i2p.router.tunnelmanager.TunnelPool} */
|
||||
public final static int TARGET_CLIENTS_DEFAULT = 3;
|
||||
|
||||
public ConfigClientsHelper() {}
|
||||
|
||||
public String getClientCountSelectBox() {
|
||||
int count = TARGET_CLIENTS_DEFAULT;
|
||||
String val = _context.router().getConfigSetting(TARGET_CLIENTS_PARAM);
|
||||
if (val != null) {
|
||||
try {
|
||||
count = Integer.parseInt(val);
|
||||
} catch (NumberFormatException nfe) {
|
||||
// ignore, use default from above
|
||||
}
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
buf.append("<select name=\"clientcount\">\n");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
buf.append("<option value=\"").append(i).append("\" ");
|
||||
if (count == i)
|
||||
buf.append("selected=\"true\" ");
|
||||
buf.append(">").append(i).append("</option>\n");
|
||||
}
|
||||
if (count >= 5) {
|
||||
buf.append("<option value=\"").append(count);
|
||||
buf.append("\" selected>").append(count);
|
||||
buf.append("</option>\n");
|
||||
}
|
||||
buf.append("</select>\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getTunnelCountSelectBox() {
|
||||
int count = ClientTunnelSettings.DEFAULT_NUM_INBOUND;
|
||||
String val = _context.router().getConfigSetting(ClientTunnelSettings.PROP_NUM_INBOUND);
|
||||
if (val != null) {
|
||||
try {
|
||||
count = Integer.parseInt(val);
|
||||
} catch (NumberFormatException nfe) {
|
||||
// ignore, use default from above
|
||||
}
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
buf.append("<select name=\"tunnelcount\">\n");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buf.append("<option value=\"").append(i).append("\" ");
|
||||
if (count == i)
|
||||
buf.append("selected=\"true\" ");
|
||||
buf.append(">").append(i).append("</option>\n");
|
||||
}
|
||||
if (count >= 4) {
|
||||
buf.append("<option value=\"").append(count);
|
||||
buf.append("\" selected>").append(count);
|
||||
buf.append("</option>\n");
|
||||
}
|
||||
buf.append("</select>\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getTunnelDepthSelectBox() {
|
||||
int count = ClientTunnelSettings.DEFAULT_DEPTH_INBOUND;
|
||||
String val = _context.router().getConfigSetting(ClientTunnelSettings.PROP_DEPTH_INBOUND);
|
||||
if (val != null) {
|
||||
try {
|
||||
count = Integer.parseInt(val);
|
||||
} catch (NumberFormatException nfe) {
|
||||
// ignore, use default from above
|
||||
}
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
buf.append("<select name=\"tunneldepth\">\n");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buf.append("<option value=\"").append(i).append("\" ");
|
||||
if (count == i)
|
||||
buf.append("selected=\"true\" ");
|
||||
buf.append(">").append(i).append("</option>\n");
|
||||
}
|
||||
if (count >= 4) {
|
||||
buf.append("<option value=\"").append(count);
|
||||
buf.append("\" selected>").append(count);
|
||||
buf.append("</option>\n");
|
||||
}
|
||||
buf.append("</select>\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getTunnelDepthOutboundSelectBox() {
|
||||
int count = ClientTunnelSettings.DEFAULT_DEPTH_OUTBOUND;
|
||||
String val = _context.router().getConfigSetting(ClientTunnelSettings.PROP_DEPTH_OUTBOUND);
|
||||
if (val != null) {
|
||||
try {
|
||||
count = Integer.parseInt(val);
|
||||
} catch (NumberFormatException nfe) {
|
||||
// ignore, use default from above
|
||||
}
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
buf.append("<select name=\"tunneldepthoutbound\">\n");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buf.append("<option value=\"").append(i).append("\" ");
|
||||
if (count == i)
|
||||
buf.append("selected=\"true\" ");
|
||||
buf.append(">").append(i).append("</option>\n");
|
||||
}
|
||||
if (count >= 4) {
|
||||
buf.append("<option value=\"").append(count);
|
||||
buf.append("\" selected>").append(count);
|
||||
buf.append("</option>\n");
|
||||
}
|
||||
buf.append("</select>\n");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ public class ConfigNetHandler extends FormHandler {
|
||||
private String _outboundRate;
|
||||
private String _outboundBurst;
|
||||
private String _reseedFrom;
|
||||
private String _sharePct;
|
||||
|
||||
public void ConfigNetHandler() {
|
||||
_guessRequested = false;
|
||||
@@ -85,6 +86,9 @@ public class ConfigNetHandler extends FormHandler {
|
||||
public void setReseedfrom(String url) {
|
||||
_reseedFrom = (url != null ? url.trim() : null);
|
||||
}
|
||||
public void setSharePercentage(String pct) {
|
||||
_sharePct = (pct != null ? pct.trim() : null);
|
||||
}
|
||||
|
||||
private static final String IP_PREFIX = "<h1>Your IP is ";
|
||||
private static final String IP_SUFFIX = " <br></h1>";
|
||||
@@ -229,6 +233,14 @@ public class ConfigNetHandler extends FormHandler {
|
||||
|
||||
updateRates();
|
||||
|
||||
if (_sharePct != null) {
|
||||
String old = _context.router().getConfigSetting(ConfigNetHelper.PROP_SHARE_PERCENTAGE);
|
||||
if ( (old == null) || (!old.equalsIgnoreCase(_sharePct)) ) {
|
||||
_context.router().setConfigSetting(ConfigNetHelper.PROP_SHARE_PERCENTAGE, _sharePct);
|
||||
addFormNotice("Updating bandwidth share percentage");
|
||||
}
|
||||
}
|
||||
|
||||
if (_timeSyncEnabled) {
|
||||
// Time sync enable, means NOT disabled
|
||||
_context.router().setConfigSetting(Timestamper.PROP_DISABLED, "false");
|
||||
|
||||
@@ -62,6 +62,8 @@ public class ConfigNetHelper {
|
||||
public static final String PROP_OUTBOUND_KBPS = "i2np.bandwidth.outboundKBytesPerSecond";
|
||||
public static final String PROP_INBOUND_BURST = "i2np.bandwidth.inboundBurstKBytes";
|
||||
public static final String PROP_OUTBOUND_BURST = "i2np.bandwidth.outboundBurstKBytes";
|
||||
public static final String PROP_SHARE_PERCENTAGE = "router.sharePercentage";
|
||||
public static final int DEFAULT_SHARE_PERCENTAGE = 80;
|
||||
|
||||
public String getInboundRate() {
|
||||
String rate = _context.getProperty(PROP_INBOUND_KBPS);
|
||||
@@ -135,4 +137,26 @@ public class ConfigNetHelper {
|
||||
buf.append("</select>\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getSharePercentageBox() {
|
||||
String pctStr = _context.getProperty(PROP_SHARE_PERCENTAGE);
|
||||
int pct = DEFAULT_SHARE_PERCENTAGE;
|
||||
if (pctStr != null)
|
||||
try { pct = Integer.parseInt(pctStr); } catch (NumberFormatException nfe) {}
|
||||
StringBuffer buf = new StringBuffer(256);
|
||||
buf.append("<select name=\"sharePercentage\">\n");
|
||||
boolean found = false;
|
||||
for (int i = 30; i <= 100; i += 10) {
|
||||
buf.append("<option value=\"").append(i).append("\" ");
|
||||
if (pct == i) {
|
||||
buf.append("selected=\"true\" ");
|
||||
found = true;
|
||||
} else if ( (i == DEFAULT_SHARE_PERCENTAGE) && (!found) ) {
|
||||
buf.append("selected=\"true\" ");
|
||||
}
|
||||
buf.append(">Up to ").append(i).append("%</option>\n");
|
||||
}
|
||||
buf.append("</select>\n");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.router.TunnelPoolSettings;
|
||||
|
||||
/**
|
||||
* Handler to deal with form submissions from the tunnel config form and act
|
||||
* upon the values. Holy crap, this is UUUUGLY
|
||||
*
|
||||
*/
|
||||
public class ConfigTunnelsHandler extends FormHandler {
|
||||
private Log _log;
|
||||
private Map _settings;
|
||||
private boolean _shouldSave;
|
||||
|
||||
public ConfigTunnelsHandler() {
|
||||
_shouldSave = false;
|
||||
}
|
||||
|
||||
protected void processForm() {
|
||||
if (_shouldSave) {
|
||||
saveChanges();
|
||||
} else {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
public void setShouldsave(String moo) {
|
||||
if ( (moo != null) && (moo.equals("Save changes")) )
|
||||
_shouldSave = true;
|
||||
}
|
||||
|
||||
public void setSettings(Map settings) { _settings = new HashMap(settings); }
|
||||
|
||||
/**
|
||||
* The user made changes to the network config and wants to save them, so
|
||||
* lets go ahead and do so.
|
||||
*
|
||||
*/
|
||||
private void saveChanges() {
|
||||
_log = _context.logManager().getLog(ConfigTunnelsHandler.class);
|
||||
boolean saveRequired = false;
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Saving changes, with props = " + _settings);
|
||||
|
||||
int updated = 0;
|
||||
int index = 0;
|
||||
while (true) {
|
||||
Object val = _settings.get("pool." + index);
|
||||
if (val == null) break;
|
||||
Hash client = new Hash();
|
||||
|
||||
String poolName = (val instanceof String ? (String)val : ((String[])val)[0]);
|
||||
|
||||
TunnelPoolSettings in = null;
|
||||
TunnelPoolSettings out = null;
|
||||
if ("exploratory".equals(poolName)) {
|
||||
in = _context.tunnelManager().getInboundSettings();
|
||||
out = _context.tunnelManager().getOutboundSettings();
|
||||
} else {
|
||||
try {
|
||||
client.fromBase64(poolName);
|
||||
} catch (DataFormatException dfe) {
|
||||
addFormError("Internal error (pool name could not resolve - " + poolName + ")");
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
in = _context.tunnelManager().getInboundSettings(client);
|
||||
out = _context.tunnelManager().getOutboundSettings(client);
|
||||
}
|
||||
|
||||
if ( (in == null) || (out == null) ) {
|
||||
addFormError("Internal error (pool settings cound not be fuond for " + poolName + ")");
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
in.setLength(getInt(_settings.get(index + ".depthInbound")));
|
||||
out.setLength(getInt(_settings.get(index + ".depthOutbound")));
|
||||
in.setLengthVariance(getInt(_settings.get(index + ".varianceInbound")));
|
||||
out.setLengthVariance(getInt(_settings.get(index + ".varianceOutbound")));
|
||||
in.setQuantity(getInt(_settings.get(index + ".quantityInbound")));
|
||||
out.setQuantity(getInt(_settings.get(index + ".quantityOutbound")));
|
||||
in.setBackupQuantity(getInt(_settings.get(index + ".backupInbound")));
|
||||
out.setBackupQuantity(getInt(_settings.get(index + ".backupOutbound")));
|
||||
|
||||
if ("exploratory".equals(poolName)) {
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_LENGTH, in.getLength()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_LENGTH, out.getLength()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_LENGTH_VARIANCE, in.getLengthVariance()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_LENGTH_VARIANCE, out.getLengthVariance()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_QUANTITY, in.getQuantity()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_QUANTITY, out.getQuantity()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_BACKUP_QUANTITY, in.getBackupQuantity()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_BACKUP_QUANTITY, out.getBackupQuantity()+"");
|
||||
}
|
||||
|
||||
if ("exploratory".equals(poolName)) {
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
_log.debug("Inbound exploratory settings: " + in);
|
||||
_log.debug("Outbound exploratory settings: " + out);
|
||||
}
|
||||
_context.tunnelManager().setInboundSettings(in);
|
||||
_context.tunnelManager().setOutboundSettings(out);
|
||||
} else {
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
_log.debug("Inbound settings for " + client.toBase64() + ": " + in);
|
||||
_log.debug("Outbound settings for " + client.toBase64() + ": " + out);
|
||||
}
|
||||
_context.tunnelManager().setInboundSettings(client, in);
|
||||
_context.tunnelManager().setOutboundSettings(client, out);
|
||||
}
|
||||
|
||||
updated++;
|
||||
saveRequired = true;
|
||||
index++;
|
||||
}
|
||||
|
||||
if (updated > 0)
|
||||
addFormNotice("Updated settings for " + updated + " pools");
|
||||
|
||||
if (saveRequired) {
|
||||
boolean saved = _context.router().saveConfig();
|
||||
if (saved)
|
||||
addFormNotice("Configuration saved successfully");
|
||||
else
|
||||
addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs");
|
||||
}
|
||||
}
|
||||
private static final int getInt(Object val) {
|
||||
if (val == null) return 0;
|
||||
String str = null;
|
||||
if (val instanceof String)
|
||||
str = (String)val;
|
||||
else
|
||||
str = ((String[])val)[0];
|
||||
|
||||
if (str.trim().length() <= 0) return 0;
|
||||
try { return Integer.parseInt(str); } catch (NumberFormatException nfe) { return 0; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.TunnelPoolSettings;
|
||||
|
||||
public class ConfigTunnelsHelper {
|
||||
private RouterContext _context;
|
||||
/**
|
||||
* Configure this bean to query a particular router context
|
||||
*
|
||||
* @param contextId begging few characters of the routerHash, or null to pick
|
||||
* the first one we come across.
|
||||
*/
|
||||
public void setContextId(String contextId) {
|
||||
try {
|
||||
_context = ContextHelper.getContext(contextId);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigTunnelsHelper() {}
|
||||
|
||||
|
||||
public String getForm() {
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
buf.append("<table border=\"1\">\n");
|
||||
TunnelPoolSettings exploratoryIn = _context.tunnelManager().getInboundSettings();
|
||||
TunnelPoolSettings exploratoryOut = _context.tunnelManager().getOutboundSettings();
|
||||
|
||||
buf.append("<input type=\"hidden\" name=\"pool.0\" value=\"exploratory\" >");
|
||||
renderForm(buf, 0, "exploratory", "Exploratory tunnels", exploratoryIn, exploratoryOut);
|
||||
|
||||
int cur = 1;
|
||||
Set clients = _context.clientManager().listClients();
|
||||
for (Iterator iter = clients.iterator(); iter.hasNext(); ) {
|
||||
Destination dest = (Destination)iter.next();
|
||||
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(dest.calculateHash());
|
||||
TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(dest.calculateHash());
|
||||
|
||||
String name = (in != null ? in.getDestinationNickname() : null);
|
||||
if (name == null)
|
||||
name = (out != null ? out.getDestinationNickname() : null);
|
||||
if (name == null)
|
||||
name = dest.calculateHash().toBase64().substring(0,6);
|
||||
|
||||
String prefix = dest.calculateHash().toBase64().substring(0,4);
|
||||
buf.append("<input type=\"hidden\" name=\"pool.").append(cur).append("\" value=\"");
|
||||
buf.append(dest.calculateHash().toBase64()).append("\" >");
|
||||
renderForm(buf, cur, prefix, "Client tunnels for " + name, in, out);
|
||||
cur++;
|
||||
}
|
||||
|
||||
buf.append("</table>\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private void renderForm(StringBuffer buf, int index, String prefix, String name, TunnelPoolSettings in, TunnelPoolSettings out) {
|
||||
|
||||
buf.append("<tr><td colspan=\"3\"><b><a name=\"").append(prefix).append("\">");
|
||||
buf.append(name).append("</a></b></td></tr>\n");
|
||||
buf.append("<tr><td></td><td><b>Inbound</b></td><td><b>Outbound</b></td></tr>\n");
|
||||
|
||||
// tunnel depth
|
||||
buf.append("<tr><td>Depth</td>\n");
|
||||
buf.append("<td><select name=\"").append(index).append(".depthInbound\">\n");
|
||||
buf.append("<option value=\"0\" ");
|
||||
if (in.getLength() <= 0) buf.append(" selected=\"true\" ");
|
||||
buf.append(">0 hops</option>\n");
|
||||
buf.append("<option value=\"1\" ");
|
||||
if (in.getLength() == 1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">1 hop</option>\n");
|
||||
buf.append("<option value=\"2\" ");
|
||||
if (in.getLength() == 2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">2 hops</option>\n");
|
||||
buf.append("<option value=\"3\" ");
|
||||
if (in.getLength() == 3) buf.append(" selected=\"true\" ");
|
||||
buf.append(">3 hops</option>\n");
|
||||
if (in.getLength() > 3)
|
||||
buf.append("<option value=\"").append(in.getLength()).append("\">").append(in.getLength()).append(" hops</option>\n");
|
||||
buf.append("</td>\n");
|
||||
|
||||
buf.append("<td><select name=\"").append(index).append(".depthOutbound\">\n");
|
||||
buf.append("<option value=\"0\" ");
|
||||
if (out.getLength() <= 0) buf.append(" selected=\"true\" ");
|
||||
buf.append(">0 hops</option>\n");
|
||||
buf.append("<option value=\"1\" ");
|
||||
if (out.getLength() == 1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">1 hop</option>\n");
|
||||
buf.append("<option value=\"2\" ");
|
||||
if (out.getLength() == 2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">2 hops</option>\n");
|
||||
buf.append("<option value=\"3\" ");
|
||||
if (out.getLength() == 3) buf.append(" selected=\"true\" ");
|
||||
buf.append(">3 hops</option>\n");
|
||||
if (out.getLength() > 3)
|
||||
buf.append("<option value=\"").append(out.getLength()).append("\">").append(out.getLength()).append(" hops</option>\n");
|
||||
buf.append("</td>\n");
|
||||
buf.append("</tr>\n");
|
||||
|
||||
// tunnel depth variance
|
||||
buf.append("<tr><td>Variance</td>\n");
|
||||
buf.append("<td><select name=\"").append(index).append(".varianceInbound\">\n");
|
||||
buf.append("<option value=\"0\" ");
|
||||
if (in.getLengthVariance() == 0) buf.append(" selected=\"true\" ");
|
||||
buf.append(">0 hops</option>\n");
|
||||
buf.append("<option value=\"-1\" ");
|
||||
if (in.getLengthVariance() == -1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">+/- 0-1 hops</option>\n");
|
||||
buf.append("<option value=\"-2\" ");
|
||||
if (in.getLengthVariance() == -2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">+/- 0-2 hops</option>\n");
|
||||
buf.append("<option value=\"1\" ");
|
||||
if (in.getLengthVariance() == 1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">+ 0-1 hops</option>\n");
|
||||
buf.append("<option value=\"2\" ");
|
||||
if (in.getLengthVariance() == 2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">+ 0-2 hops</option>\n");
|
||||
if (in.getLengthVariance() < -2)
|
||||
buf.append("<option value=\"").append(in.getLengthVariance()).append("\">+/- 0-").append(in.getLengthVariance()).append(" hops</option>\n");
|
||||
if (in.getLengthVariance() > 2)
|
||||
buf.append("<option value=\"").append(in.getLengthVariance()).append("\">+ 0-").append(in.getLengthVariance()).append(" hops</option>\n");
|
||||
buf.append("</td>\n");
|
||||
|
||||
buf.append("<td><select name=\"").append(index).append(".varianceOutbound\">\n");
|
||||
buf.append("<option value=\"0\" ");
|
||||
if (out.getLengthVariance() == 0) buf.append(" selected=\"true\" ");
|
||||
buf.append(">0 hops</option>\n");
|
||||
buf.append("<option value=\"-1\" ");
|
||||
if (out.getLengthVariance() == -1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">+/- 0-1 hops</option>\n");
|
||||
buf.append("<option value=\"-2\" ");
|
||||
if (out.getLengthVariance() == -2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">+/- 0-2 hops</option>\n");
|
||||
buf.append("<option value=\"1\" ");
|
||||
if (out.getLengthVariance() == 1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">+ 0-1 hops</option>\n");
|
||||
buf.append("<option value=\"2\" ");
|
||||
if (out.getLengthVariance() == 2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">+ 0-2 hops</option>\n");
|
||||
if (out.getLengthVariance() < -2)
|
||||
buf.append("<option value=\"").append(out.getLengthVariance()).append("\">+/- 0-").append(out.getLengthVariance()).append(" hops</option>\n");
|
||||
if (out.getLengthVariance() > 2)
|
||||
buf.append("<option value=\"").append(out.getLengthVariance()).append("\">+ 0-").append(out.getLengthVariance()).append(" hops</option>\n");
|
||||
buf.append("</td>\n");
|
||||
|
||||
// tunnel quantity
|
||||
buf.append("<tr><td>Quantity</td>\n");
|
||||
buf.append("<td><select name=\"").append(index).append(".quantityInbound\">\n");
|
||||
buf.append("<option value=\"1\" ");
|
||||
if (in.getQuantity() <= 1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">1 tunnel</option>\n");
|
||||
buf.append("<option value=\"2\" ");
|
||||
if (in.getQuantity() == 2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">2 tunnels</option>\n");
|
||||
buf.append("<option value=\"3\" ");
|
||||
if (in.getQuantity() == 3) buf.append(" selected=\"true\" ");
|
||||
buf.append(">3 tunnels</option>\n");
|
||||
if (in.getQuantity() > 3)
|
||||
buf.append("<option value=\"").append(in.getQuantity()).append("\">").append(in.getQuantity()).append(" tunnels</option>\n");
|
||||
buf.append("</td>\n");
|
||||
|
||||
buf.append("<td><select name=\"").append(index).append(".quantityOutbound\">\n");
|
||||
buf.append("<option value=\"1\" ");
|
||||
if (out.getQuantity() <= 1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">1 tunnel</option>\n");
|
||||
buf.append("<option value=\"2\" ");
|
||||
if (out.getQuantity() == 2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">2 tunnels</option>\n");
|
||||
buf.append("<option value=\"3\" ");
|
||||
if (out.getQuantity() == 3) buf.append(" selected=\"true\" ");
|
||||
buf.append(">3 tunnels</option>\n");
|
||||
if (out.getQuantity() > 3)
|
||||
buf.append("<option value=\"").append(out.getQuantity()).append("\">").append(out.getQuantity()).append(" tunnels</option>\n");
|
||||
buf.append("</td>\n");
|
||||
buf.append("</tr>\n");
|
||||
|
||||
// tunnel backup quantity
|
||||
buf.append("<tr><td>Backup quantity</td>\n");
|
||||
buf.append("<td><select name=\"").append(index).append(".backupInbound\">\n");
|
||||
buf.append("<option value=\"0\" ");
|
||||
if (in.getBackupQuantity() <= 0) buf.append(" selected=\"true\" ");
|
||||
buf.append(">0 tunnels</option>\n");
|
||||
buf.append("<option value=\"1\" ");
|
||||
if (in.getBackupQuantity() == 1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">1 tunnel</option>\n");
|
||||
buf.append("<option value=\"2\" ");
|
||||
if (in.getBackupQuantity() == 2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">2 tunnels</option>\n");
|
||||
buf.append("<option value=\"3\" ");
|
||||
if (in.getBackupQuantity() == 3) buf.append(" selected=\"true\" ");
|
||||
buf.append(">3 tunnels</option>\n");
|
||||
if (in.getBackupQuantity() > 3)
|
||||
buf.append("<option value=\"").append(in.getBackupQuantity()).append("\">").append(in.getBackupQuantity()).append(" tunnels</option>\n");
|
||||
buf.append("</td>\n");
|
||||
|
||||
buf.append("<td><select name=\"").append(index).append(".backupOutbound\">\n");
|
||||
buf.append("<option value=\"0\" ");
|
||||
if (out.getBackupQuantity() <= 0) buf.append(" selected=\"true\" ");
|
||||
buf.append(">0 tunnel</option>\n");
|
||||
buf.append("<option value=\"1\" ");
|
||||
if (out.getBackupQuantity() == 1) buf.append(" selected=\"true\" ");
|
||||
buf.append(">1 tunnel</option>\n");
|
||||
buf.append("<option value=\"2\" ");
|
||||
if (out.getBackupQuantity() == 2) buf.append(" selected=\"true\" ");
|
||||
buf.append(">2 tunnels</option>\n");
|
||||
buf.append("<option value=\"3\" ");
|
||||
if (out.getBackupQuantity() == 3) buf.append(" selected=\"true\" ");
|
||||
buf.append(">3 tunnels</option>\n");
|
||||
if (out.getBackupQuantity() > 3)
|
||||
buf.append("<option value=\"").append(out.getBackupQuantity()).append("\">").append(out.getBackupQuantity()).append(" tunnels</option>\n");
|
||||
buf.append("</td>\n");
|
||||
buf.append("</tr>\n");
|
||||
|
||||
// custom options
|
||||
buf.append("<tr><td>Inbound options:</td>\n");
|
||||
buf.append("<td colspan=\"2\"><input name=\"").append(index);
|
||||
buf.append(".inboundOptions\" type=\"text\" size=\"40\" ");
|
||||
buf.append("value=\"");
|
||||
Properties props = in.getUnknownOptions();
|
||||
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
|
||||
String prop = (String)iter.next();
|
||||
String val = (String)props.getProperty(prop);
|
||||
buf.append(prop).append("=").append(val).append(" ");
|
||||
}
|
||||
buf.append("\"/></td></tr>\n");
|
||||
buf.append("<tr><td>Outbound options:</td>\n");
|
||||
buf.append("<td colspan=\"2\"><input name=\"").append(index);
|
||||
buf.append(".outboundOptions\" type=\"text\" size=\"40\" ");
|
||||
buf.append("value=\"");
|
||||
props = in.getUnknownOptions();
|
||||
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
|
||||
String prop = (String)iter.next();
|
||||
String val = (String)props.getProperty(prop);
|
||||
buf.append(prop).append("=").append(val).append(" ");
|
||||
}
|
||||
buf.append("\"/></td></tr>\n");
|
||||
buf.append("<tr><td colspan=\"3\"><hr /></td></tr>\n");
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashSet;
|
||||
@@ -98,13 +100,42 @@ public class ReseedHandler {
|
||||
URL url = new URL(seedURL + (seedURL.endsWith("/") ? "" : "/") + "routerInfo-" + peer + ".dat");
|
||||
|
||||
byte data[] = readURL(url);
|
||||
//System.out.println("read: " + (data != null ? data.length : -1));
|
||||
writeSeed(peer, data);
|
||||
}
|
||||
|
||||
private static byte[] readURL(URL url) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
||||
URLConnection con = url.openConnection();
|
||||
InputStream in = con.getInputStream();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(4*1024);
|
||||
String hostname = url.getHost();
|
||||
int port = url.getPort();
|
||||
if (port < 0)
|
||||
port = 80;
|
||||
Socket s = new Socket(hostname, port);
|
||||
OutputStream out = s.getOutputStream();
|
||||
InputStream in = s.getInputStream();
|
||||
String request = getRequest(url);
|
||||
//System.out.println("Sending to " + hostname +":"+ port + ": " + request);
|
||||
out.write(request.getBytes());
|
||||
out.flush();
|
||||
// skip the HTTP response headers
|
||||
// (if we were smart, we'd check for HTTP 200, content-length, etc)
|
||||
int consecutiveNL = 0;
|
||||
while (true) {
|
||||
int cur = in.read();
|
||||
switch (cur) {
|
||||
case -1:
|
||||
return null;
|
||||
case '\n':
|
||||
case '\r':
|
||||
consecutiveNL++;
|
||||
break;
|
||||
default:
|
||||
consecutiveNL = 0;
|
||||
}
|
||||
if (consecutiveNL == 4)
|
||||
break;
|
||||
}
|
||||
// ok, past the headers, grab the goods
|
||||
byte buf[] = new byte[1024];
|
||||
while (true) {
|
||||
int read = in.read(buf);
|
||||
@@ -113,9 +144,24 @@ public class ReseedHandler {
|
||||
baos.write(buf, 0, read);
|
||||
}
|
||||
in.close();
|
||||
s.close();
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
private static String getRequest(URL url) {
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
String path = url.getPath();
|
||||
if ("".equals(path))
|
||||
path = "/";
|
||||
buf.append("GET ").append(path).append(" HTTP/1.0\n");
|
||||
buf.append("Host: ").append(url.getHost());
|
||||
int port = url.getPort();
|
||||
if ( (port > 0) && (port != 80) )
|
||||
buf.append(":").append(port);
|
||||
buf.append("\nConnection: close\n\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static void writeSeed(String name, byte data[]) throws Exception {
|
||||
String dirName = "netDb"; // _context.getProperty("router.networkDatabase.dbDir", "netDb");
|
||||
File netDbDir = new File(dirName);
|
||||
@@ -126,4 +172,9 @@ public class ReseedHandler {
|
||||
fos.write(data);
|
||||
fos.close();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
reseed();
|
||||
//System.out.println("Done reseeding");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.mortbay.http.handler.SecurityHandler;
|
||||
import org.mortbay.http.HashUserRealm;
|
||||
import org.mortbay.http.HttpRequest;
|
||||
import org.mortbay.http.SecurityConstraint;
|
||||
import org.mortbay.http.Authenticator;
|
||||
import org.mortbay.util.MultiException;
|
||||
|
||||
public class RouterConsoleRunner {
|
||||
@@ -64,7 +65,7 @@ public class RouterConsoleRunner {
|
||||
}
|
||||
try {
|
||||
_server.start();
|
||||
} catch (MultiException me) {
|
||||
} catch (Exception me) {
|
||||
me.printStackTrace();
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -4,13 +4,18 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.LeaseSet;
|
||||
import net.i2p.stat.Rate;
|
||||
import net.i2p.stat.RateStat;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.RouterVersion;
|
||||
import net.i2p.router.TunnelPoolSettings;
|
||||
|
||||
/**
|
||||
* Simple helper to query the appropriate router for data necessary to render
|
||||
@@ -333,16 +338,39 @@ public class SummaryHelper {
|
||||
* @return html section summary
|
||||
*/
|
||||
public String getDestinations() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
||||
try {
|
||||
OutputStreamWriter osw = new OutputStreamWriter(baos);
|
||||
_context.clientManager().renderStatusHTML(osw);
|
||||
osw.flush();
|
||||
return new String(baos.toByteArray());
|
||||
} catch (IOException ioe) {
|
||||
_context.logManager().getLog(SummaryHelper.class).error("Error rendering client info", ioe);
|
||||
return "";
|
||||
Set clients = _context.clientManager().listClients();
|
||||
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
buf.append("<u><b>Local destinations</b></u><br />");
|
||||
|
||||
for (Iterator iter = clients.iterator(); iter.hasNext(); ) {
|
||||
Destination client = (Destination)iter.next();
|
||||
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(client.calculateHash());
|
||||
TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(client.calculateHash());
|
||||
String name = (in != null ? in.getDestinationNickname() : null);
|
||||
if (name == null)
|
||||
name = (out != null ? out.getDestinationNickname() : null);
|
||||
if (name == null)
|
||||
name = client.calculateHash().toBase64().substring(0,6);
|
||||
|
||||
buf.append("<b>*</b> ").append(name).append("<br />\n");
|
||||
LeaseSet ls = _context.netDb().lookupLeaseSetLocally(client.calculateHash());
|
||||
if (ls != null) {
|
||||
long timeToExpire = ls.getEarliestLeaseDate() - _context.clock().now();
|
||||
if (timeToExpire < 0) {
|
||||
buf.append("<i>expired ").append(DataHelper.formatDuration(0-timeToExpire));
|
||||
buf.append(" ago</i><br />\n");
|
||||
}
|
||||
} else {
|
||||
buf.append("<i>No leases</i><br />\n");
|
||||
}
|
||||
buf.append("<a href=\"tunnels.jsp#").append(client.calculateHash().toBase64().substring(0,4));
|
||||
buf.append("\">Details</a> ");
|
||||
buf.append("<a href=\"configtunnels.jsp#").append(client.calculateHash().toBase64().substring(0,4));
|
||||
buf.append("\">Config</a><br />\n");
|
||||
}
|
||||
buf.append("<hr />\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
|
||||
public class TunnelHelper {
|
||||
private RouterContext _context;
|
||||
private Writer _out;
|
||||
/**
|
||||
* Configure this bean to query a particular router context
|
||||
*
|
||||
* @param contextId begging few characters of the routerHash, or null to pick
|
||||
* the first one we come across.
|
||||
*/
|
||||
public void setContextId(String contextId) {
|
||||
try {
|
||||
_context = ContextHelper.getContext(contextId);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public TunnelHelper() {}
|
||||
|
||||
public void setWriter(Writer writer) { _out = writer; }
|
||||
|
||||
public String getTunnelSummary() {
|
||||
try {
|
||||
if (_out != null) {
|
||||
_context.tunnelManager().renderStatusHTML(_out);
|
||||
return "";
|
||||
} else {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(32*1024);
|
||||
_context.tunnelManager().renderStatusHTML(new OutputStreamWriter(baos));
|
||||
return new String(baos.toByteArray());
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,14 +39,17 @@
|
||||
|
||||
<b>Bandwidth limiter</b><br />
|
||||
Inbound rate:
|
||||
<input name="inboundrate" type="text" size="2" value="<jsp:getProperty name="nethelper" property="inboundRate" />" /> KBytes per second<br />
|
||||
Inbound burst duration:
|
||||
<input name="inboundrate" type="text" size="2" value="<jsp:getProperty name="nethelper" property="inboundRate" />" /> KBytes per second
|
||||
bursting up to
|
||||
<jsp:getProperty name="nethelper" property="inboundBurstFactorBox" /><br />
|
||||
Outbound rate:
|
||||
<input name="outboundrate" type="text" size="2" value="<jsp:getProperty name="nethelper" property="outboundRate" />" /> KBytes per second<br />
|
||||
Outbound burst duration:
|
||||
<input name="outboundrate" type="text" size="2" value="<jsp:getProperty name="nethelper" property="outboundRate" />" /> KBytes per second
|
||||
bursting up to
|
||||
<jsp:getProperty name="nethelper" property="outboundBurstFactorBox" /><br />
|
||||
<i>A negative rate means there is no limit</i><br />
|
||||
Bandwidth share percentage:
|
||||
<jsp:getProperty name="nethelper" property="sharePercentageBox" /><br />
|
||||
Sharing a higher percentage will improve your anonymity and help the network
|
||||
<hr />
|
||||
Enable internal time synchronization? <input type="checkbox" <jsp:getProperty name="nethelper" property="enableTimeSyncChecked" /> name="enabletimesync" /><br />
|
||||
<i>If disabled, your machine <b>must</b> be NTP synchronized - your clock must always
|
||||
@@ -61,17 +64,7 @@
|
||||
<hr />
|
||||
<b>Advanced network config:</b>
|
||||
<p>
|
||||
There are two other network settings, but no one reads this text so there's no reason
|
||||
to tell you about them. In case you actually do read this, here's the deal: by default,
|
||||
I2P will attempt to guess your IP address by having whomever it talks to tell it what
|
||||
address they think you are. If and only if you have no working TCP connections and you
|
||||
have not overridden the IP address, your router will believe them. If that doesn't sound
|
||||
ok to you, thats fine - go to the <a href="configadvanced.jsp">advanced config</a> page
|
||||
and add "i2np.tcp.hostname=yourHostname", then go to the
|
||||
<a href="configservice.jsp">service</a> page and do a graceful restart. We used to make
|
||||
people enter a hostname/IP address on this page, but too many people got it wrong ;)</p>
|
||||
|
||||
<p>The other advanced network option has to do with reseeding - you should never need to
|
||||
One advanced network option has to do with reseeding - you should never need to
|
||||
reseed your router as long as you can find at least one other peer on the network. However,
|
||||
when you do need to reseed, a link will show up on the left hand side which will
|
||||
fetch all of the routerInfo-* files from http://dev.i2p.net/i2pdb/. That URL is just an
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<%@page contentType="text/html"%>
|
||||
<%@page pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html><head>
|
||||
<title>I2P Router Console - config clients</title>
|
||||
<link rel="stylesheet" href="default.css" type="text/css" />
|
||||
</head><body>
|
||||
|
||||
<%@include file="nav.jsp" %>
|
||||
<%@include file="summary.jsp" %>
|
||||
|
||||
<jsp:useBean class="net.i2p.router.web.ConfigClientsHelper" id="clientshelper" scope="request" />
|
||||
<jsp:setProperty name="clientshelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||
|
||||
<div class="main" id="main">
|
||||
<%@include file="confignav.jsp" %>
|
||||
|
||||
<jsp:useBean class="net.i2p.router.web.ConfigClientsHandler" id="formhandler" scope="request" />
|
||||
<jsp:setProperty name="formhandler" property="*" />
|
||||
<jsp:setProperty name="formhandler" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||
<font color="red"><jsp:getProperty name="formhandler" property="errors" /></font>
|
||||
<i><jsp:getProperty name="formhandler" property="notices" /></i>
|
||||
|
||||
<form action="configclients.jsp" method="POST">
|
||||
<% String prev = System.getProperty("net.i2p.router.web.ConfigClientsHandler.nonce");
|
||||
if (prev != null) System.setProperty("net.i2p.router.web.ConfigClientsHandler.noncePrev", prev);
|
||||
System.setProperty("net.i2p.router.web.ConfigClientsHandler.nonce", new java.util.Random().nextLong()+""); %>
|
||||
<input type="hidden" name="nonce" value="<%=System.getProperty("net.i2p.router.web.ConfigClientsHandler.nonce")%>" />
|
||||
<input type="hidden" name="action" value="blah" />
|
||||
<b>Estimated number of clients/destinations:</b>
|
||||
<jsp:getProperty name="clientshelper" property="clientCountSelectBox" /><br />
|
||||
<b>Default number of inbound tunnels per client:</b>
|
||||
<jsp:getProperty name="clientshelper" property="tunnelCountSelectBox" /><br />
|
||||
<b>Default number of hops per tunnel:</b>
|
||||
<jsp:getProperty name="clientshelper" property="tunnelDepthSelectBox" /><br />
|
||||
<b>Hops per outbound tunnel:</b>
|
||||
<jsp:getProperty name="clientshelper" property="tunnelDepthOutboundSelectBox" /><br />
|
||||
<hr />
|
||||
<input type="submit" name="shouldsave" value="Save changes" /> <input type="reset" value="Cancel" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,8 +2,8 @@
|
||||
%>Network | <% } else { %><a href="config.jsp">Network</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configservice.jsp") != -1) {
|
||||
%>Service | <% } else { %><a href="configservice.jsp">Service</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configclients.jsp") != -1) {
|
||||
%>Clients | <% } else { %><a href="configclients.jsp">Clients</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configtunnels.jsp") != -1) {
|
||||
%>Tunnels | <% } else { %><a href="configtunnels.jsp">Tunnels</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configlogging.jsp") != -1) {
|
||||
%>Logging | <% } else { %><a href="configlogging.jsp">Logging</a> | <% }
|
||||
if (request.getRequestURI().indexOf("configadvanced.jsp") != -1) {
|
||||
|
||||
41
apps/routerconsole/jsp/configtunnels.jsp
Normal file
41
apps/routerconsole/jsp/configtunnels.jsp
Normal file
@@ -0,0 +1,41 @@
|
||||
<%@page contentType="text/html"%>
|
||||
<%@page pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html><head>
|
||||
<title>I2P Router Console - config tunnels</title>
|
||||
<link rel="stylesheet" href="default.css" type="text/css" />
|
||||
</head><body>
|
||||
|
||||
<%@include file="nav.jsp" %>
|
||||
<%@include file="summary.jsp" %>
|
||||
|
||||
<jsp:useBean class="net.i2p.router.web.ConfigTunnelsHelper" id="tunnelshelper" scope="request" />
|
||||
<jsp:setProperty name="tunnelshelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||
|
||||
<div class="main" id="main">
|
||||
<%@include file="confignav.jsp" %>
|
||||
|
||||
<jsp:useBean class="net.i2p.router.web.ConfigTunnelsHandler" id="formhandler" scope="request" />
|
||||
<jsp:setProperty name="formhandler" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||
<jsp:setProperty name="formhandler" property="shouldsave" value="<%=request.getParameter("shouldsave")%>" />
|
||||
<jsp:setProperty name="formhandler" property="action" value="<%=request.getParameter("action")%>" />
|
||||
<jsp:setProperty name="formhandler" property="nonce" value="<%=request.getParameter("nonce")%>" />
|
||||
<jsp:setProperty name="formhandler" property="settings" value="<%=request.getParameterMap()%>" />
|
||||
<font color="red"><jsp:getProperty name="formhandler" property="errors" /></font>
|
||||
<i><jsp:getProperty name="formhandler" property="notices" /></i>
|
||||
|
||||
<form action="configtunnels.jsp" method="POST">
|
||||
<% String prev = System.getProperty("net.i2p.router.web.ConfigTunnelsHandler.nonce");
|
||||
if (prev != null) System.setProperty("net.i2p.router.web.ConfigTunnelsHandler.noncePrev", prev);
|
||||
System.setProperty("net.i2p.router.web.ConfigTunnelsHandler.nonce", new java.util.Random().nextLong()+""); %>
|
||||
<input type="hidden" name="nonce" value="<%=System.getProperty("net.i2p.router.web.ConfigTunnelsHandler.nonce")%>" />
|
||||
<input type="hidden" name="action" value="blah" />
|
||||
<jsp:getProperty name="tunnelshelper" property="form" />
|
||||
<hr />
|
||||
<input type="submit" name="shouldsave" value="Save changes" /> <input type="reset" value="Cancel" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -34,7 +34,11 @@ by their binary code license. This product includes software developed by the A
|
||||
|
||||
<p>Another application you can see on this webpage is <a href="http://www.i2p.net/i2ptunnel">I2PTunnel</a>
|
||||
(your <a href="i2ptunnel/" target="_blank">web interface</a>) - a GPL'ed application written by mihi that
|
||||
lets you tunnel normal TCP/IP traffic over I2P (such as the eepproxy and the irc proxy).</p>
|
||||
lets you tunnel normal TCP/IP traffic over I2P (such as the eepproxy and the irc proxy). There is also a
|
||||
<a href="http://susi.i2p/">susimail</a> web based mail client <a href="susimail/susimail">available</a> on
|
||||
the console, which is a GPL'ed application written by susi23. The addressbook application, written by
|
||||
<a href="http://ragnarok.i2p/">Ragnarok</a> helps maintain your hosts.txt files (see ./addressbook/ for
|
||||
more information).</p>
|
||||
|
||||
<p>The router by default also includes human's public domain <a href="http://www.i2p.net/sam">SAM</a> bridge,
|
||||
which other client applications (such the <a href="http://duck.i2p/i2p-bt/">bittorrent port</a>) can use.
|
||||
|
||||
@@ -15,12 +15,14 @@
|
||||
</div>
|
||||
|
||||
<h4>
|
||||
<a href="tunnels.jsp">Tunnels</a> |
|
||||
<a href="profiles.jsp">Profiles</a> |
|
||||
<a href="netdb.jsp">Network Database</a> |
|
||||
<a href="netdb.jsp">NetDB</a> |
|
||||
<a href="logs.jsp">Logs</a> |
|
||||
<a href="oldconsole.jsp">Old console</a> |
|
||||
<a href="oldconsole.jsp">Internals</a> |
|
||||
<a href="oldstats.jsp">Stats</a> |
|
||||
<a href="i2ptunnel/" target="_blank">I2PTunnel</a>
|
||||
<a href="i2ptunnel/" target="_blank">I2PTunnel</a> |
|
||||
<a href="susimail/susimail" target="_blank">Susimail</a>
|
||||
<jsp:useBean class="net.i2p.router.web.NavHelper" id="navhelper" scope="request" />
|
||||
<jsp:setProperty name="navhelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||
<jsp:getProperty name="navhelper" property="clientAppLinks" />
|
||||
|
||||
21
apps/routerconsole/jsp/tunnels.jsp
Normal file
21
apps/routerconsole/jsp/tunnels.jsp
Normal file
@@ -0,0 +1,21 @@
|
||||
<%@page contentType="text/html"%>
|
||||
<%@page pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html><head>
|
||||
<title>I2P Router Console - tunnel summary</title>
|
||||
<link rel="stylesheet" href="default.css" type="text/css" />
|
||||
</head><body>
|
||||
|
||||
<%@include file="nav.jsp" %>
|
||||
<%@include file="summary.jsp" %>
|
||||
|
||||
<div class="main" id="main">
|
||||
<jsp:useBean class="net.i2p.router.web.TunnelHelper" id="tunnelHelper" scope="request" />
|
||||
<jsp:setProperty name="tunnelHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||
<jsp:setProperty name="tunnelHelper" property="writer" value="<%=out%>" />
|
||||
<jsp:getProperty name="tunnelHelper" property="tunnelSummary" />
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
84
apps/sam/csharp/README
Normal file
84
apps/sam/csharp/README
Normal file
@@ -0,0 +1,84 @@
|
||||
sam-sharp
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
sam-sharp is a .NET SAM client library for I2P written in C#. It aims to be
|
||||
compatible with platforms that implement .NET's base class library API (such
|
||||
as Mono and DotGNU Portable.NET) and to be usable from all languages
|
||||
conforming to the ECMA-standardized Common Language Infrastructure, including
|
||||
C# and VB.NET.
|
||||
|
||||
|
||||
MINIMUM REQUIREMENTS
|
||||
|
||||
* Mono and mcs 1.0 or higher (Linux, Mac OS X, Windows)
|
||||
|
||||
- or -
|
||||
|
||||
MS .NET Framework SDK 1.0 or higher (Windows)
|
||||
|
||||
- or -
|
||||
|
||||
DotGNU Portable .NET, latest version recommended (*BSD, AIX, Cygwin, Linux,
|
||||
Mac OS X, MinGW, Solaris)
|
||||
|
||||
|
||||
OPTIONAL REQUIREMENTS
|
||||
|
||||
* NAnt 0.85 or higher is needed to use sam-sharp.build. Sorry, NAnt does not
|
||||
yet support Portable.NET.
|
||||
|
||||
* NUnit 2.2.1 or later is needed to run the (soon-to-be-added) unit tests. If
|
||||
you have the Mono mcs package installed then you already have NUnit.
|
||||
|
||||
|
||||
DOCUMENTATION
|
||||
|
||||
Pre-generated docs will be submitted to CVS soon. In the meantime you may
|
||||
generate standalone documentation from the embedded XML doc comments by
|
||||
issuing the following commands from sam-sharp's src/ directory:
|
||||
|
||||
Mono:
|
||||
|
||||
mkdir ../doc
|
||||
mcs -doc:../doc/sam-sharp_doc.xml *.cs
|
||||
|
||||
MS .NET:
|
||||
|
||||
mkdir ../doc
|
||||
csc /doc:../doc/sam-sharp_doc.xml *.cs
|
||||
|
||||
DotGNU Portable.NET:
|
||||
|
||||
mkdir ../doc
|
||||
csdoc -o ../doc/sam-sharp_doc.xml *.cs
|
||||
|
||||
The resulting XML doc can be converted to HTML using either Visual Studio .NET
|
||||
(Tools > Build Comment Web Pages) or Portable.NET's csdoc2html tool:
|
||||
|
||||
csdoc2html -o ../doc ../doc/sam-sharp_doc.xml
|
||||
|
||||
|
||||
ACKNOWLEDGMENTS
|
||||
|
||||
sam-sharp is a port of jrandom's public domain Java SAM client library.
|
||||
|
||||
|
||||
LICENSE
|
||||
|
||||
This work is released into the public domain.
|
||||
|
||||
|
||||
AUTHORS
|
||||
|
||||
jrandom (original Java SAM client library)
|
||||
smeghead (C# port of the Java SAM client library)
|
||||
|
||||
|
||||
MAINTAINERS
|
||||
|
||||
smeghead <smeghead@i2pmail.org> <smeghead@mail.i2p>
|
||||
|
||||
|
||||
$Id: README,v 1.1 2005/01/24 17:42:05 smeghead Exp $
|
||||
19
apps/sam/csharp/sam-sharp.build
Normal file
19
apps/sam/csharp/sam-sharp.build
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0"?>
|
||||
<project basedir="." default="bin" name="sam-sharp">
|
||||
|
||||
<target name="bin" description="Builds assemblies from source">
|
||||
<mkdir dir="bin" />
|
||||
<csc target="dll" output="bin/sam-sharp.dll">
|
||||
<sources>
|
||||
<include name="src/**/*.cs" />
|
||||
</sources>
|
||||
</csc>
|
||||
<echo message="Build complete." />
|
||||
</target>
|
||||
|
||||
<target name="clean" description="Deletes all built assemblies">
|
||||
<delete dir="bin" failonerror="false" />
|
||||
<echo message="Clean complete." />
|
||||
</target>
|
||||
|
||||
</project>
|
||||
32
apps/sam/csharp/src/I2P.SAM.Client/AssemblyInfo.cs
Normal file
32
apps/sam/csharp/src/I2P.SAM.Client/AssemblyInfo.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following
|
||||
// attributes.
|
||||
//
|
||||
// change them to the information which is associated with the assembly
|
||||
// you compile.
|
||||
|
||||
[assembly: AssemblyTitle("sam-sharp")]
|
||||
[assembly: AssemblyDescription("Mono/.NET SAM client for I2P")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("sam-sharp")]
|
||||
[assembly: AssemblyCopyright("Released into the Public Domain")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all values by your own or you can build default build and revision
|
||||
// numbers with the '*' character (the default):
|
||||
|
||||
[assembly: AssemblyVersion("0.1")]
|
||||
|
||||
// The following attributes specify the key for the sign of your assembly. See the
|
||||
// .NET Framework documentation for more information about signing.
|
||||
// This is not required, if you don't want signing let these attributes like they're.
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
[assembly: AssemblyKeyFile("")]
|
||||
160
apps/sam/csharp/src/I2P.SAM.Client/SamBaseEventHandler.cs
Normal file
160
apps/sam/csharp/src/I2P.SAM.Client/SamBaseEventHandler.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Threading;
|
||||
|
||||
namespace I2P.SAM.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Optional base class providing basic SAM event handling and helper
|
||||
/// methods.
|
||||
/// </summary>
|
||||
public class SamBaseEventHandler
|
||||
{
|
||||
private object _helloLock = new Object();
|
||||
private string _helloOk;
|
||||
private NameValueCollection _namingReplies = new NameValueCollection();
|
||||
private object _namingReplyLock = new Object();
|
||||
private SamReader _samReader;
|
||||
private object _sessionCreateLock = new Object();
|
||||
private string _sessionCreateOk;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>SamBaseEventHandler</c> instance and registers
|
||||
/// overridable handler methods for all events generated by the given
|
||||
/// <see cref="SamReader">SamReader</see>.
|
||||
/// </summary>
|
||||
public SamBaseEventHandler(SamReader samReader) {
|
||||
_samReader = samReader;
|
||||
_samReader.DestReplyReceived += new DestReplyReceivedHandler(OnDestReplyReceived);
|
||||
_samReader.HelloReplyReceived += new HelloReplyReceivedHandler(OnHelloReplyReceived);
|
||||
_samReader.NamingReplyReceived += new NamingReplyReceivedHandler(OnNamingReplyReceived);
|
||||
_samReader.SessionStatusReceived += new SessionStatusReceivedHandler(OnSessionStatusReceived);
|
||||
_samReader.StreamClosedReceived += new StreamClosedReceivedHandler(OnStreamClosedReceived);
|
||||
_samReader.StreamConnectedReceived += new StreamConnectedReceivedHandler(OnStreamConnectedReceived);
|
||||
_samReader.StreamDataReceived += new StreamDataReceivedHandler(OnStreamDataReceived);
|
||||
_samReader.StreamStatusReceived += new StreamStatusReceivedHandler(OnStreamStatusReceived);
|
||||
_samReader.UnknownMessageReceived += new UnknownMessageReceivedHandler(OnUnknownMessageReceived);
|
||||
}
|
||||
|
||||
public virtual void OnDestReplyReceived(string publicKey, string privateKey) {
|
||||
}
|
||||
|
||||
public virtual void OnHelloReplyReceived(bool ok) {
|
||||
lock (_helloLock) {
|
||||
if (ok)
|
||||
_helloOk = Boolean.TrueString;
|
||||
else
|
||||
_helloOk = Boolean.FalseString;
|
||||
|
||||
Monitor.PulseAll(_helloLock);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnNamingReplyReceived(string name, string result, string valueString, string message) {
|
||||
lock (_namingReplyLock) {
|
||||
if (result.Equals(SamBridgeMessages.NAMING_REPLY_OK))
|
||||
_namingReplies.Add(name, valueString);
|
||||
else
|
||||
_namingReplies.Add(name, result);
|
||||
|
||||
Monitor.PulseAll(_namingReplyLock);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnSessionStatusReceived(string result, string destination, string message) {
|
||||
lock (_sessionCreateLock) {
|
||||
if (result.Equals(SamBridgeMessages.SESSION_STATUS_OK))
|
||||
_sessionCreateOk = Boolean.TrueString;
|
||||
else
|
||||
_sessionCreateOk = Boolean.FalseString;
|
||||
|
||||
Monitor.PulseAll(_sessionCreateLock);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnStreamClosedReceived(string result, int id, string message) {
|
||||
}
|
||||
|
||||
public virtual void OnStreamConnectedReceived(string remoteDestination, int id) {
|
||||
}
|
||||
|
||||
public virtual void OnStreamDataReceived(int id, byte[] data, int offset, int length) {
|
||||
}
|
||||
|
||||
public virtual void OnStreamStatusReceived(string result, int id, string message) {
|
||||
}
|
||||
|
||||
public virtual void OnUnknownMessageReceived(string major, string minor, NameValueCollection parameters) {
|
||||
Console.WriteLine("wrt, [" + major + "] [" + minor + "] [" + parameters + "]");
|
||||
}
|
||||
|
||||
// Helper methods below.
|
||||
|
||||
/// <summary>
|
||||
/// Waits for a SAM connection to be established.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method blocks until the connection is established.
|
||||
/// </remarks>
|
||||
/// <returns><c>true</c> if the handshake was successful.</returns>
|
||||
public virtual bool WaitForHelloReply() {
|
||||
while (true) {
|
||||
lock (_helloLock) {
|
||||
if (_helloOk == null)
|
||||
Monitor.Wait(_helloLock);
|
||||
else
|
||||
return Boolean.Parse(_helloOk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Waits for a SAM naming reply message.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method blocks until all naming replies are received.
|
||||
/// </remarks>
|
||||
/// <param name="name">The name to be looked for, or <c>ME</c>.</param>
|
||||
/// <returns>The matching destination for <c>name</c>, or <c>null</c> if
|
||||
/// the key was not able to be retrieved.</returns>
|
||||
public virtual string WaitForNamingReply(string name) {
|
||||
while (true) {
|
||||
lock (_namingReplyLock) {
|
||||
try {
|
||||
string valueString = _namingReplies[name];
|
||||
_namingReplies.Remove(name);
|
||||
|
||||
if (valueString.Equals(SamBridgeMessages.NAMING_REPLY_INVALID_KEY))
|
||||
return null;
|
||||
else if (valueString.Equals(SamBridgeMessages.NAMING_REPLY_KEY_NOT_FOUND))
|
||||
return null;
|
||||
else
|
||||
return valueString;
|
||||
|
||||
} catch (ArgumentNullException ane) {
|
||||
Monitor.Wait(_namingReplyLock);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Waits for a SAM session to be created.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method blocks until a SAM session is created.
|
||||
/// </remarks>
|
||||
/// <returns><c>true</c> if the SAM session was created successfully.
|
||||
// </returns>
|
||||
public virtual bool WaitForSessionCreateReply() {
|
||||
while (true) {
|
||||
lock (_sessionCreateLock) {
|
||||
if (_sessionCreateOk == null)
|
||||
Monitor.Wait(_sessionCreateLock);
|
||||
else
|
||||
return Boolean.Parse(_sessionCreateOk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
apps/sam/csharp/src/I2P.SAM.Client/SamBridgeMessages.cs
Normal file
26
apps/sam/csharp/src/I2P.SAM.Client/SamBridgeMessages.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace I2P.SAM.Client
|
||||
{
|
||||
public struct SamBridgeMessages
|
||||
{
|
||||
public const string NAMING_REPLY_INVALID_KEY = "INVALID_KEY";
|
||||
public const string NAMING_REPLY_KEY_NOT_FOUND = "KEY_NOT_FOUND";
|
||||
public const string NAMING_REPLY_OK = "OK";
|
||||
|
||||
public const string SESSION_STATUS_DUPLICATE_DEST = "DUPLICATE_DEST";
|
||||
public const string SESSION_STATUS_I2P_ERROR = "I2P_ERROR";
|
||||
public const string SESSION_STATUS_INVALID_KEY = "INVALID_KEY";
|
||||
public const string SESSION_STATUS_OK = "OK";
|
||||
|
||||
public const string STREAM_CLOSED_CANT_REACH_PEER = "CANT_REACH_PEER";
|
||||
public const string STREAM_CLOSED_I2P_ERROR = "I2P_ERROR";
|
||||
public const string STREAM_CLOSED_PEER_NOT_FOUND = "PEER_NOT_FOUND";
|
||||
public const string STREAM_CLOSED_TIMEOUT = "CLOSED";
|
||||
public const string STREAM_CLOSED_OK = "OK";
|
||||
|
||||
public const string STREAM_STATUS_CANT_REACH_PEER = "CANT_REACH_PEER";
|
||||
public const string STREAM_STATUS_I2P_ERROR = "I2P_ERROR";
|
||||
public const string STREAM_STATUS_INVALID_KEY = "INVALID_KEY";
|
||||
public const string STREAM_STATUS_TIMEOUT = "TIMEOUT";
|
||||
public const string STREAM_STATUS_OK = "OK";
|
||||
}
|
||||
}
|
||||
278
apps/sam/csharp/src/I2P.SAM.Client/SamReader.cs
Normal file
278
apps/sam/csharp/src/I2P.SAM.Client/SamReader.cs
Normal file
@@ -0,0 +1,278 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace I2P.SAM.Client
|
||||
{
|
||||
public delegate void DestReplyReceivedHandler(string publicKey, string privateKey);
|
||||
public delegate void HelloReplyReceivedHandler(bool ok);
|
||||
public delegate void NamingReplyReceivedHandler(string name, string result, string valueString, string message);
|
||||
public delegate void SessionStatusReceivedHandler(string result, string destination, string message);
|
||||
public delegate void StreamClosedReceivedHandler(string result, int id, string message);
|
||||
public delegate void StreamConnectedReceivedHandler(string remoteDestination, int id);
|
||||
public delegate void StreamDataReceivedHandler(int id, byte[] data, int offset, int length);
|
||||
public delegate void StreamStatusReceivedHandler(string result, int id, string message);
|
||||
public delegate void UnknownMessageReceivedHandler(string major, string minor, NameValueCollection parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Reads from a socket stream, producing events for any SAM message read.
|
||||
/// </summary>
|
||||
public class SamReader
|
||||
{
|
||||
public event DestReplyReceivedHandler DestReplyReceived;
|
||||
public event HelloReplyReceivedHandler HelloReplyReceived;
|
||||
public event NamingReplyReceivedHandler NamingReplyReceived;
|
||||
public event SessionStatusReceivedHandler SessionStatusReceived;
|
||||
public event StreamClosedReceivedHandler StreamClosedReceived;
|
||||
public event StreamConnectedReceivedHandler StreamConnectedReceived;
|
||||
public event StreamDataReceivedHandler StreamDataReceived;
|
||||
public event StreamStatusReceivedHandler StreamStatusReceived;
|
||||
public event UnknownMessageReceivedHandler UnknownMessageReceived;
|
||||
|
||||
private bool _isLive;
|
||||
private NetworkStream _samStream;
|
||||
private StreamReader _samStreamReader;
|
||||
|
||||
public SamReader(NetworkStream samStream) {
|
||||
_samStream = samStream;
|
||||
}
|
||||
|
||||
public void RunThread() {
|
||||
|
||||
NameValueCollection parameters = new NameValueCollection();
|
||||
|
||||
while (_isLive) {
|
||||
|
||||
string line = null;
|
||||
|
||||
_samStreamReader = new StreamReader(_samStream);
|
||||
|
||||
try {
|
||||
line = _samStreamReader.ReadLine();
|
||||
_samStreamReader.Close();
|
||||
} catch (IOException ioe) {
|
||||
Console.Error.WriteLine("Error reading from SAM: {1}", ioe);
|
||||
} catch (OutOfMemoryException oome) {
|
||||
Console.Error.WriteLine("Out of memory while reading from SAM: {1}", oome);
|
||||
return;
|
||||
}
|
||||
|
||||
if (line == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
string[] tokens = line.Split(new char[1] { ' ' });
|
||||
|
||||
if (tokens.Length < 2) {
|
||||
Console.Error.WriteLine("Invalid SAM line: [" + line + "]");
|
||||
_isLive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
IEnumerator tokensEnumerator = tokens.GetEnumerator();
|
||||
tokensEnumerator.MoveNext();
|
||||
string major = (string) tokensEnumerator.Current;
|
||||
tokensEnumerator.MoveNext();
|
||||
string minor = (string) tokensEnumerator.Current;
|
||||
|
||||
parameters.Clear();
|
||||
|
||||
while (tokensEnumerator.MoveNext()) {
|
||||
|
||||
string pair = (string) tokensEnumerator.Current;
|
||||
int equalsPosition = pair.IndexOf('=');
|
||||
|
||||
if ( (equalsPosition > 0) && (equalsPosition < pair.Length - 1) ) {
|
||||
|
||||
string name = pair.Substring(0, equalsPosition);
|
||||
string valueString = pair.Substring(equalsPosition + 1);
|
||||
|
||||
while ( (valueString[0] == '\"') && (valueString.Length > 0) )
|
||||
valueString = valueString.Substring(1);
|
||||
|
||||
while ( (valueString.Length > 0) && (valueString[valueString.Length - 1] == '\"') )
|
||||
valueString = valueString.Substring(0, valueString.Length - 1);
|
||||
|
||||
parameters.Set(name, valueString);
|
||||
}
|
||||
}
|
||||
|
||||
ProcessEvent(major, minor, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessEvent(string major, string minor, NameValueCollection parameters) {
|
||||
|
||||
switch (major)
|
||||
{
|
||||
case "HELLO" :
|
||||
|
||||
if (minor.Equals("REPLY")) {
|
||||
|
||||
string result = parameters.Get("RESULT");
|
||||
|
||||
if (result.Equals("OK"))
|
||||
HelloReplyReceived(true);
|
||||
else
|
||||
HelloReplyReceived(false);
|
||||
} else {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "SESSION" :
|
||||
|
||||
if (minor.Equals("STATUS")) {
|
||||
|
||||
string result = parameters.Get("RESULT");
|
||||
string destination = parameters.Get("DESTINATION");
|
||||
string message = parameters.Get("MESSAGE");
|
||||
|
||||
SessionStatusReceived(result, destination, message);
|
||||
} else {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "STREAM" :
|
||||
|
||||
ProcessStream(major, minor, parameters);
|
||||
break;
|
||||
|
||||
case "NAMING" :
|
||||
|
||||
if (minor.Equals("REPLY")) {
|
||||
|
||||
string name = parameters.Get("NAME");
|
||||
string result = parameters.Get("RESULT");
|
||||
string valueString = parameters.Get("VALUE");
|
||||
string message = parameters.Get("MESSAGE");
|
||||
|
||||
NamingReplyReceived(name, result, valueString, message);
|
||||
} else {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "DEST" :
|
||||
|
||||
if (minor.Equals("REPLY")) {
|
||||
|
||||
string pub = parameters.Get("PUB");
|
||||
string priv = parameters.Get("PRIV");
|
||||
|
||||
DestReplyReceived(pub, priv);
|
||||
} else {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessStream(string major, string minor, NameValueCollection parameters) {
|
||||
|
||||
/*
|
||||
* Would use another tidy switch() statement here but the Mono
|
||||
* compiler presently gets variable scopes confused within nested
|
||||
* switch() contexts. Nested switch() is broken with Mono/mcs 1.0.5,
|
||||
* 1.1.3, and SVN head.
|
||||
*/
|
||||
if (minor.Equals("STATUS")) {
|
||||
|
||||
string result = parameters.Get("RESULT");
|
||||
string id = parameters.Get("ID");
|
||||
string message = parameters.Get("MESSAGE");
|
||||
|
||||
try {
|
||||
StreamStatusReceived(result, Int32.Parse(id), message);
|
||||
} catch {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
|
||||
} else if (minor.Equals("CONNECTED")) {
|
||||
|
||||
string destination = parameters.Get("DESTINATION");
|
||||
string id = parameters.Get("ID");
|
||||
|
||||
try {
|
||||
StreamConnectedReceived(destination, Int32.Parse(id));
|
||||
} catch {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
|
||||
} else if (minor.Equals("CLOSED")) {
|
||||
|
||||
string result = parameters.Get("RESULT");
|
||||
string id = parameters.Get("ID");
|
||||
string message = parameters.Get("MESSAGE");
|
||||
|
||||
try {
|
||||
StreamClosedReceived(result, Int32.Parse(id), message);
|
||||
} catch {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
|
||||
} else if (minor.Equals("RECEIVED")) {
|
||||
|
||||
string id = parameters.Get("ID");
|
||||
string size = parameters.Get("SIZE");
|
||||
|
||||
if (id != null) {
|
||||
try {
|
||||
|
||||
int idValue = Int32.Parse(id);
|
||||
int sizeValue = Int32.Parse(size);
|
||||
byte[] data = new byte[sizeValue];
|
||||
int bytesRead;
|
||||
|
||||
try {
|
||||
bytesRead = _samStream.Read(data, 0, sizeValue);
|
||||
|
||||
if (bytesRead != sizeValue) {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
_isLive = false;
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
StreamDataReceived(idValue, data, 0, sizeValue);
|
||||
} catch (FormatException fe) {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
} else {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
} else {
|
||||
UnknownMessageReceived(major, minor, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartReading() {
|
||||
_isLive = true;
|
||||
ThreadStart threadStart = new ThreadStart(RunThread);
|
||||
Thread thread = new Thread(threadStart);
|
||||
thread.Name = "SAM Reader";
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
public void StopReading() {
|
||||
_isLive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
[assembly: AssemblyTitle("")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
//
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
//
|
||||
// In order to sign your assembly you must specify a key to use. Refer to the
|
||||
// Microsoft .NET Framework documentation for more information on assembly signing.
|
||||
//
|
||||
// Use the attributes below to control which key is used for signing.
|
||||
//
|
||||
// Notes:
|
||||
// (*) If no key is specified, the assembly is not signed.
|
||||
// (*) KeyName refers to a key that has been installed in the Crypto Service
|
||||
// Provider (CSP) on your machine. KeyFile refers to a file which contains
|
||||
// a key.
|
||||
// (*) If the KeyFile and the KeyName values are both specified, the
|
||||
// following processing occurs:
|
||||
// (1) If the KeyName can be found in the CSP, that key is used.
|
||||
// (2) If the KeyName does not exist and the KeyFile does exist, the key
|
||||
// in the KeyFile is installed into the CSP and used.
|
||||
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
|
||||
// When specifying the KeyFile, the location of the KeyFile should be
|
||||
// relative to the project output directory which is
|
||||
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
|
||||
// located in the project directory, you would specify the AssemblyKeyFile
|
||||
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
|
||||
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
|
||||
// documentation for more information on this.
|
||||
//
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
[assembly: AssemblyKeyFile("")]
|
||||
[assembly: AssemblyKeyName("")]
|
||||
@@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
|
||||
namespace SAM.NET
|
||||
{
|
||||
class SAMTester
|
||||
{
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
new SAMTester();
|
||||
}
|
||||
public SAMTester ()
|
||||
{
|
||||
SAMConnection connection1 = new SAMConnection(IPAddress.Parse("127.0.0.1"),7656);
|
||||
SAMSession session1 = new SAMSession(connection1,SAM.NET.SamSocketType.Stream,"alice");
|
||||
|
||||
SAMConnection connection2 = new SAMConnection(IPAddress.Parse("127.0.0.1"),7656);
|
||||
SAMSession session2 = new SAMSession(connection2,SAM.NET.SamSocketType.Stream,"bob");
|
||||
|
||||
SAMStream stream1 = new SAMStream(connection1,session1,233);
|
||||
stream1.Connect(session2.getKey());
|
||||
|
||||
//Wait till we are connected to destination
|
||||
while (!stream1.isConnected)
|
||||
Thread.Sleep(1000);
|
||||
|
||||
//Send some bytes
|
||||
stream1.Write(Encoding.ASCII.GetBytes(DateTime.Now.ToLongTimeString() + "Hi!!!!!!"));
|
||||
|
||||
//Wait till a stream magically appears on the other side
|
||||
while (session2.getStreams().Count == 0) Thread.Sleep(1000);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
foreach (SAMStream stream in session2.getStreams().Values)
|
||||
{
|
||||
Console.WriteLine("Text received on " + stream.getID() + " at " + DateTime.Now.ToLongTimeString());
|
||||
Console.WriteLine(Encoding.ASCII.GetString(stream.ReadToEnd()));
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
stream1.Close();
|
||||
connection1.Close();
|
||||
connection2.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
[assembly: AssemblyTitle("")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
//
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
//
|
||||
// In order to sign your assembly you must specify a key to use. Refer to the
|
||||
// Microsoft .NET Framework documentation for more information on assembly signing.
|
||||
//
|
||||
// Use the attributes below to control which key is used for signing.
|
||||
//
|
||||
// Notes:
|
||||
// (*) If no key is specified, the assembly is not signed.
|
||||
// (*) KeyName refers to a key that has been installed in the Crypto Service
|
||||
// Provider (CSP) on your machine. KeyFile refers to a file which contains
|
||||
// a key.
|
||||
// (*) If the KeyFile and the KeyName values are both specified, the
|
||||
// following processing occurs:
|
||||
// (1) If the KeyName can be found in the CSP, that key is used.
|
||||
// (2) If the KeyName does not exist and the KeyFile does exist, the key
|
||||
// in the KeyFile is installed into the CSP and used.
|
||||
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
|
||||
// When specifying the KeyFile, the location of the KeyFile should be
|
||||
// relative to the project output directory which is
|
||||
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
|
||||
// located in the project directory, you would specify the AssemblyKeyFile
|
||||
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
|
||||
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
|
||||
// documentation for more information on this.
|
||||
//
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
[assembly: AssemblyKeyFile("")]
|
||||
[assembly: AssemblyKeyName("")]
|
||||
@@ -1,271 +0,0 @@
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Threading;
|
||||
|
||||
namespace SAM.NET
|
||||
{
|
||||
public enum SamSocketType
|
||||
{
|
||||
Stream,
|
||||
Datagram,
|
||||
Raw
|
||||
}
|
||||
|
||||
public class SAMConnection
|
||||
{
|
||||
private const string propertyMinVersion = "1.0";
|
||||
private const string propertyMaxVersion = "1.0";
|
||||
|
||||
private Socket _sock;
|
||||
private NetworkStream _sockStream;
|
||||
private StreamReader _sockStreamIn;
|
||||
private StreamWriter _sockStreamOut;
|
||||
|
||||
public SAMConnection(IPAddress routerIP, int port)
|
||||
{
|
||||
_sock = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
|
||||
IPEndPoint rEP = new IPEndPoint(routerIP,port);
|
||||
_sock.Connect(rEP);
|
||||
_sockStream = new NetworkStream(_sock);
|
||||
_sockStreamIn = new StreamReader(_sockStream);
|
||||
_sockStreamOut = new StreamWriter(_sockStream);
|
||||
try
|
||||
{
|
||||
sendVersion(propertyMinVersion,propertyMinVersion);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_sock.Close();
|
||||
throw (new Exception("No SAM for you :("));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void sendVersion(string min, string max)
|
||||
{
|
||||
_sockStreamOut.WriteLine("HELLO VERSION MIN=" + propertyMinVersion + " MAX=" + propertyMaxVersion);
|
||||
_sockStreamOut.Flush();
|
||||
Hashtable response = SAMUtil.parseKeyValues(_sockStreamIn.ReadLine(),2);
|
||||
if (response["RESULT"].ToString() != "OK") throw (new Exception("Version mismatch"));
|
||||
}
|
||||
|
||||
public StreamWriter getOutputStream()
|
||||
{
|
||||
return _sockStreamOut;
|
||||
}
|
||||
|
||||
public StreamReader getInputStream()
|
||||
{
|
||||
return _sockStreamIn;
|
||||
}
|
||||
|
||||
public NetworkStream getStream()
|
||||
{
|
||||
return _sockStream;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_sock.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Creating a SAMSession object will automatically:
|
||||
* 1) create a sesion on SAM
|
||||
* 1) query for the base64key
|
||||
* 2) start a listening thread to catch all stream commands
|
||||
*/
|
||||
public class SAMSession
|
||||
{
|
||||
private Hashtable _streams;
|
||||
private string _sessionKey;
|
||||
|
||||
public SAMSession (SAMConnection connection, SamSocketType type, string destination)
|
||||
{
|
||||
_streams = new Hashtable();
|
||||
StreamWriter writer = connection.getOutputStream();
|
||||
StreamReader reader = connection.getInputStream();
|
||||
writer.WriteLine("SESSION CREATE STYLE=STREAM DESTINATION=" + destination);
|
||||
writer.Flush();
|
||||
Hashtable response = SAMUtil.parseKeyValues(reader.ReadLine(),2);
|
||||
if (response["RESULT"].ToString() != "OK")
|
||||
{
|
||||
throw (new Exception(response["MESSAGE"].ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteLine("NAMING LOOKUP NAME=ME");
|
||||
writer.Flush();
|
||||
response = SAMUtil.parseKeyValues(reader.ReadLine(),2);
|
||||
_sessionKey = response["VALUE"].ToString();
|
||||
SAMSessionListener listener = new SAMSessionListener(connection,this,_streams);
|
||||
new Thread(new ThreadStart(listener.startListening)).Start();
|
||||
}
|
||||
}
|
||||
public void addStream(SAMStream stream)
|
||||
{
|
||||
_streams.Add(stream.getID(),stream);
|
||||
}
|
||||
public string getKey()
|
||||
{
|
||||
return _sessionKey;
|
||||
}
|
||||
public Hashtable getStreams()
|
||||
{
|
||||
return _streams;
|
||||
}
|
||||
}
|
||||
|
||||
public class SAMSessionListener
|
||||
{
|
||||
private Hashtable _streams;
|
||||
private SAMConnection _connection;
|
||||
private SAMSession _session;
|
||||
private bool stayAlive = true;
|
||||
|
||||
public SAMSessionListener(SAMConnection connection,SAMSession session, Hashtable streams)
|
||||
{
|
||||
_streams = streams;
|
||||
_connection = connection;
|
||||
_session = session;
|
||||
}
|
||||
public void startListening()
|
||||
{
|
||||
StreamReader reader = _connection.getInputStream();
|
||||
while (stayAlive)
|
||||
{
|
||||
string response = reader.ReadLine();
|
||||
if (response.StartsWith("STREAM STATUS"))
|
||||
{
|
||||
Hashtable values = SAMUtil.parseKeyValues(response,2);
|
||||
SAMStream theStream = (SAMStream)_streams[int.Parse(values["ID"].ToString())];
|
||||
if (theStream != null) theStream.ReceivedStatus(values);
|
||||
}
|
||||
if (response.StartsWith("STREAM CONNECTED"))
|
||||
{
|
||||
Hashtable values = SAMUtil.parseKeyValues(response,2);
|
||||
SAMStream theStream = (SAMStream)_streams[int.Parse(values["ID"].ToString())];
|
||||
if (theStream != null) theStream.isConnected = true;
|
||||
}
|
||||
if (response.StartsWith("STREAM RECEIVED"))
|
||||
{
|
||||
Hashtable values = SAMUtil.parseKeyValues(response,2);
|
||||
int streamID = int.Parse(values["ID"].ToString());
|
||||
SAMStream theStream = (SAMStream)_streams[streamID];
|
||||
if (theStream == null) new SAMStream(_connection,_session,streamID);
|
||||
theStream = (SAMStream)_streams[streamID];
|
||||
theStream.ReceivedData(int.Parse(values["SIZE"].ToString()));
|
||||
}
|
||||
if (response.StartsWith("STREAM CLOSE"))
|
||||
{
|
||||
Hashtable values = SAMUtil.parseKeyValues(response,2);
|
||||
SAMStream theStream = (SAMStream)_streams[int.Parse(values["ID"].ToString())];
|
||||
if (theStream != null) theStream.isConnected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SAMStream
|
||||
{
|
||||
private int _ID;
|
||||
private byte[] _data;
|
||||
private int _position=0;
|
||||
private int _size=0;
|
||||
private SAMSession _session;
|
||||
private SAMConnection _connection;
|
||||
public bool isConnected=false;
|
||||
|
||||
public SAMStream (SAMConnection connection,SAMSession session, int ID)
|
||||
{
|
||||
_data = new byte[100000]; //FIXME: change to non-static structure for storing stream data
|
||||
_ID = ID;
|
||||
_connection = connection;
|
||||
_session = session;
|
||||
_session.addStream(this);
|
||||
}
|
||||
|
||||
public void Connect(string destination)
|
||||
{
|
||||
StreamWriter writer = _connection.getOutputStream();
|
||||
writer.WriteLine("STREAM CONNECT ID=" + _ID.ToString() + " DESTINATION=" + destination);
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
public void ReceivedData(int size) //FIXME: WTF is going on when reading the payload here? All zeros and way too many of them.
|
||||
{
|
||||
NetworkStream stream = _connection.getStream();
|
||||
int bytesRead = stream.Read(_data,_size,size);
|
||||
_size = _size + bytes;
|
||||
}
|
||||
|
||||
public void ReceivedStatus(Hashtable response)
|
||||
{
|
||||
if (response["RESULT"].ToString() != "OK")
|
||||
{
|
||||
throw (new Exception(response["RESULT"].ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
isConnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
public int getID() {return _ID;}
|
||||
|
||||
public bool DataAvailable()
|
||||
{
|
||||
return _position != _size;
|
||||
}
|
||||
|
||||
public void Write(byte[] buf)
|
||||
{
|
||||
NetworkStream stream = _connection.getStream();
|
||||
int sent = 0;
|
||||
while (sent < buf.Length)
|
||||
{
|
||||
int toSend = Math.Min(buf.Length - sent,32768);
|
||||
string header = "STREAM SEND ID=" + _ID.ToString() + " SIZE=" + toSend.ToString() + "\n";
|
||||
byte[] headerbytes = Encoding.ASCII.GetBytes(header);
|
||||
stream.Write(headerbytes,0,headerbytes.Length);
|
||||
stream.Write(buf,sent,toSend);
|
||||
sent = sent + toSend;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ReadToEnd()
|
||||
{
|
||||
byte[] ret = new byte[_size - _position];
|
||||
Array.Copy(_data,_position,ret,0,_size - _position);
|
||||
_position = _size;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
StreamWriter writer = _connection.getOutputStream();
|
||||
writer.WriteLine("STREAM CLOSE " + _ID.ToString());
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
public class SAMUtil
|
||||
{
|
||||
public static Hashtable parseKeyValues(string str, int startingWord)
|
||||
{
|
||||
Hashtable hash = new Hashtable();
|
||||
string strTruncated = string.Join(" ",str.Split(' '),startingWord,str.Split(' ').Length - startingWord);
|
||||
string[] sets = strTruncated.Split('=',' ');
|
||||
for (int i=0; i<sets.Length; i=i+2)
|
||||
{
|
||||
hash.Add(sets[i],sets[i+1]);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,11 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
|
||||
_log.debug("New message received: [" + msg + "]");
|
||||
}
|
||||
|
||||
if(msg.equals("")) {
|
||||
_log.debug("Ignoring newline");
|
||||
continue;
|
||||
}
|
||||
|
||||
tok = new StringTokenizer(msg, " ");
|
||||
if (tok.countTokens() < 2) {
|
||||
// This is not a correct message, for sure
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.TreeMap;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.SessionTag;
|
||||
import net.i2p.util.Log;
|
||||
@@ -61,6 +62,8 @@ public class Connection {
|
||||
private ActivityTimer _activityTimer;
|
||||
/** window size when we last saw congestion */
|
||||
private int _lastCongestionSeenAt;
|
||||
private long _lastCongestionTime;
|
||||
private long _lastCongestionHighestUnacked;
|
||||
private boolean _ackSinceCongestion;
|
||||
/** Notify this on connection (or connection failure) */
|
||||
private Object _connectLock;
|
||||
@@ -78,8 +81,8 @@ public class Connection {
|
||||
/** wait up to 5 minutes after disconnection so we can ack/close packets */
|
||||
public static int DISCONNECT_TIMEOUT = 5*60*1000;
|
||||
|
||||
/** lets be sane- no more than 32 packets in the air in each dir */
|
||||
public static final int MAX_WINDOW_SIZE = 32;
|
||||
/** lets be sane- no more than 64 packets in the air in each dir */
|
||||
public static final int MAX_WINDOW_SIZE = 64;
|
||||
|
||||
public Connection(I2PAppContext ctx, ConnectionManager manager, SchedulerChooser chooser, PacketQueue queue, ConnectionPacketHandler handler) {
|
||||
this(ctx, manager, chooser, queue, handler, null);
|
||||
@@ -89,7 +92,7 @@ public class Connection {
|
||||
_log = ctx.logManager().getLog(Connection.class);
|
||||
_receiver = new ConnectionDataReceiver(ctx, this);
|
||||
_inputStream = new MessageInputStream(ctx);
|
||||
_outputStream = new MessageOutputStream(ctx, _receiver);
|
||||
_outputStream = new MessageOutputStream(ctx, _receiver, (opts == null ? Packet.MAX_PAYLOAD_SIZE : opts.getMaxMessageSize()));
|
||||
_chooser = chooser;
|
||||
_outboundPackets = new TreeMap();
|
||||
_outboundQueue = queue;
|
||||
@@ -104,7 +107,9 @@ public class Connection {
|
||||
_unackedPacketsReceived = 0;
|
||||
_congestionWindowEnd = 0;
|
||||
_highestAckedThrough = -1;
|
||||
_lastCongestionSeenAt = MAX_WINDOW_SIZE;
|
||||
_lastCongestionSeenAt = MAX_WINDOW_SIZE*2; // lets allow it to grow
|
||||
_lastCongestionTime = -1;
|
||||
_lastCongestionHighestUnacked = -1;
|
||||
_connectionManager = manager;
|
||||
_resetReceived = false;
|
||||
_connected = true;
|
||||
@@ -599,6 +604,8 @@ public class Connection {
|
||||
// dont set the size to (winSize >> 4). only set the
|
||||
if (_ackSinceCongestion) {
|
||||
_lastCongestionSeenAt = _options.getWindowSize();
|
||||
_lastCongestionTime = _context.clock().now();
|
||||
_lastCongestionHighestUnacked = _lastSendId;
|
||||
_ackSinceCongestion = false;
|
||||
}
|
||||
}
|
||||
@@ -761,6 +768,21 @@ public class Connection {
|
||||
buf.append(" ").append(nacks[i]);
|
||||
buf.append("]");
|
||||
}
|
||||
|
||||
if (getResetSent())
|
||||
buf.append(" reset sent");
|
||||
if (getResetReceived())
|
||||
buf.append(" reset received");
|
||||
if (getCloseSentOn() > 0) {
|
||||
buf.append(" close sent ");
|
||||
long timeSinceClose = _context.clock().now() - getCloseSentOn();
|
||||
buf.append(DataHelper.formatDuration(timeSinceClose));
|
||||
buf.append(" ago");
|
||||
}
|
||||
if (getCloseReceivedOn() > 0)
|
||||
buf.append(" close received");
|
||||
buf.append(" acked packets ").append(getAckedPackets());
|
||||
|
||||
buf.append("]");
|
||||
return buf.toString();
|
||||
}
|
||||
@@ -813,14 +835,24 @@ public class Connection {
|
||||
_packet.setReceiveStreamId(_receiveStreamId);
|
||||
_packet.setSendStreamId(_sendStreamId);
|
||||
|
||||
// shrink the window
|
||||
int newWindowSize = getOptions().getWindowSize();
|
||||
congestionOccurred();
|
||||
_context.statManager().addRateData("stream.con.windowSizeAtCongestion", newWindowSize, _packet.getLifetime());
|
||||
newWindowSize /= 2;
|
||||
if (newWindowSize <= 0)
|
||||
newWindowSize = 1;
|
||||
getOptions().setWindowSize(newWindowSize);
|
||||
|
||||
if (_ackSinceCongestion) {
|
||||
// only shrink the window once per window
|
||||
if (_packet.getSequenceNum() > _lastCongestionHighestUnacked) {
|
||||
congestionOccurred();
|
||||
_context.statManager().addRateData("stream.con.windowSizeAtCongestion", newWindowSize, _packet.getLifetime());
|
||||
newWindowSize /= 2;
|
||||
if (newWindowSize <= 0)
|
||||
newWindowSize = 1;
|
||||
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Congestion resending packet " + _packet.getSequenceNum() + ": new windowSize " + newWindowSize
|
||||
+ ") for " + Connection.this.toString());
|
||||
|
||||
getOptions().setWindowSize(newWindowSize);
|
||||
}
|
||||
}
|
||||
|
||||
int numSends = _packet.getNumSends() + 1;
|
||||
|
||||
@@ -831,7 +863,7 @@ public class Connection {
|
||||
|
||||
// in case things really suck, the other side may have lost thier
|
||||
// session tags (e.g. they restarted), so jump back to ElGamal.
|
||||
int failTagsAt = _options.getMaxResends() - 1;
|
||||
int failTagsAt = _options.getMaxResends() - 2;
|
||||
if ( (newWindowSize == 1) && (numSends == failTagsAt) ) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Optimistically failing tags at resend " + numSends);
|
||||
|
||||
@@ -146,7 +146,6 @@ class ConnectionDataReceiver implements MessageOutputStream.DataReceiver {
|
||||
|
||||
con.getInputStream().updateAcks(packet);
|
||||
packet.setOptionalDelay(con.getOptions().getChoke());
|
||||
packet.setOptionalMaxSize(con.getOptions().getMaxMessageSize());
|
||||
packet.setResendDelay(con.getOptions().getResendDelay());
|
||||
|
||||
if (con.getOptions().getProfile() == ConnectionOptions.PROFILE_INTERACTIVE)
|
||||
@@ -159,6 +158,7 @@ class ConnectionDataReceiver implements MessageOutputStream.DataReceiver {
|
||||
if ( (!ackOnly) && (packet.getSequenceNum() <= 0) ) {
|
||||
packet.setFlag(Packet.FLAG_SYNCHRONIZE);
|
||||
packet.setOptionalFrom(con.getSession().getMyDestination());
|
||||
packet.setOptionalMaxSize(con.getOptions().getMaxMessageSize());
|
||||
}
|
||||
|
||||
// don't set the closed flag if this is a plain ACK and there are outstanding
|
||||
|
||||
@@ -37,10 +37,11 @@ public class ConnectionManager {
|
||||
private Map _pendingPings;
|
||||
private boolean _allowIncoming;
|
||||
private int _maxConcurrentStreams;
|
||||
private ConnectionOptions _defaultOptions;
|
||||
private volatile int _numWaiting;
|
||||
private Object _connectionLock;
|
||||
|
||||
public ConnectionManager(I2PAppContext context, I2PSession session, int maxConcurrent) {
|
||||
public ConnectionManager(I2PAppContext context, I2PSession session, int maxConcurrent, ConnectionOptions defaultOptions) {
|
||||
_context = context;
|
||||
_log = context.logManager().getLog(ConnectionManager.class);
|
||||
_connectionByInboundId = new HashMap(32);
|
||||
@@ -56,6 +57,7 @@ public class ConnectionManager {
|
||||
_outboundQueue = new PacketQueue(context, session, this);
|
||||
_allowIncoming = false;
|
||||
_maxConcurrentStreams = maxConcurrent;
|
||||
_defaultOptions = defaultOptions;
|
||||
_numWaiting = 0;
|
||||
_context.statManager().createRateStat("stream.con.lifetimeMessagesSent", "How many messages do we send on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 });
|
||||
_context.statManager().createRateStat("stream.con.lifetimeMessagesReceived", "How many messages do we receive on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 });
|
||||
@@ -103,7 +105,7 @@ public class ConnectionManager {
|
||||
* it, or null if the syn's streamId was already taken
|
||||
*/
|
||||
public Connection receiveConnection(Packet synPacket) {
|
||||
Connection con = new Connection(_context, this, _schedulerChooser, _outboundQueue, _conPacketHandler);
|
||||
Connection con = new Connection(_context, this, _schedulerChooser, _outboundQueue, _conPacketHandler, new ConnectionOptions(_defaultOptions));
|
||||
byte receiveId[] = new byte[4];
|
||||
_context.random().nextBytes(receiveId);
|
||||
boolean reject = false;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Properties;
|
||||
public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
private int _connectDelay;
|
||||
private boolean _fullySigned;
|
||||
private int _windowSize;
|
||||
private volatile int _windowSize;
|
||||
private int _receiveWindow;
|
||||
private int _profile;
|
||||
private int _rtt;
|
||||
@@ -21,6 +21,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
private int _inactivityTimeout;
|
||||
private int _inactivityAction;
|
||||
private int _inboundBufferSize;
|
||||
private int _maxWindowSize;
|
||||
|
||||
public static final int PROFILE_BULK = 1;
|
||||
public static final int PROFILE_INTERACTIVE = 2;
|
||||
@@ -43,6 +44,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
public static final String PROP_INITIAL_RECEIVE_WINDOW = "i2p.streaming.initialReceiveWindow";
|
||||
public static final String PROP_INACTIVITY_TIMEOUT = "i2p.streaming.inactivityTimeout";
|
||||
public static final String PROP_INACTIVITY_ACTION = "i2p.streaming.inactivityAction";
|
||||
public static final String PROP_MAX_WINDOW_SIZE = "i2p.streaming.maxWindowSize";
|
||||
|
||||
public ConnectionOptions() {
|
||||
super();
|
||||
@@ -71,6 +73,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
setInactivityTimeout(opts.getInactivityTimeout());
|
||||
setInactivityAction(opts.getInactivityAction());
|
||||
setInboundBufferSize(opts.getInboundBufferSize());
|
||||
setMaxWindowSize(opts.getMaxWindowSize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,11 +81,11 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
super.init(opts);
|
||||
setConnectDelay(getInt(opts, PROP_CONNECT_DELAY, -1));
|
||||
setProfile(getInt(opts, PROP_PROFILE, PROFILE_BULK));
|
||||
setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, Packet.MAX_PAYLOAD_SIZE));
|
||||
setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, 16*1024));
|
||||
setRTT(getInt(opts, PROP_INITIAL_RTT, 30*1000));
|
||||
setReceiveWindow(getInt(opts, PROP_INITIAL_RECEIVE_WINDOW, 1));
|
||||
setResendDelay(getInt(opts, PROP_INITIAL_RESEND_DELAY, 5*1000));
|
||||
setSendAckDelay(getInt(opts, PROP_INITIAL_ACK_DELAY, 2*1000));
|
||||
setResendDelay(getInt(opts, PROP_INITIAL_RESEND_DELAY, 1000));
|
||||
setSendAckDelay(getInt(opts, PROP_INITIAL_ACK_DELAY, 1000));
|
||||
setWindowSize(getInt(opts, PROP_INITIAL_WINDOW_SIZE, 1));
|
||||
setMaxResends(getInt(opts, PROP_MAX_RESENDS, 5));
|
||||
setWriteTimeout(getInt(opts, PROP_WRITE_TIMEOUT, -1));
|
||||
@@ -91,6 +94,42 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
setInboundBufferSize((getMaxMessageSize() + 2) * Connection.MAX_WINDOW_SIZE);
|
||||
|
||||
setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
|
||||
setMaxWindowSize(getInt(opts, PROP_MAX_WINDOW_SIZE, Connection.MAX_WINDOW_SIZE));
|
||||
}
|
||||
|
||||
public void setProperties(Properties opts) {
|
||||
super.setProperties(opts);
|
||||
if (opts == null) return;
|
||||
if (opts.containsKey(PROP_CONNECT_DELAY))
|
||||
setConnectDelay(getInt(opts, PROP_CONNECT_DELAY, -1));
|
||||
if (opts.containsKey(PROP_PROFILE))
|
||||
setProfile(getInt(opts, PROP_PROFILE, PROFILE_BULK));
|
||||
if (opts.containsKey(PROP_MAX_MESSAGE_SIZE))
|
||||
setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, Packet.MAX_PAYLOAD_SIZE));
|
||||
if (opts.containsKey(PROP_INITIAL_RTT))
|
||||
setRTT(getInt(opts, PROP_INITIAL_RTT, 30*1000));
|
||||
if (opts.containsKey(PROP_INITIAL_RECEIVE_WINDOW))
|
||||
setReceiveWindow(getInt(opts, PROP_INITIAL_RECEIVE_WINDOW, 1));
|
||||
if (opts.containsKey(PROP_INITIAL_RESEND_DELAY))
|
||||
setResendDelay(getInt(opts, PROP_INITIAL_RESEND_DELAY, 500));
|
||||
if (opts.containsKey(PROP_INITIAL_ACK_DELAY))
|
||||
setSendAckDelay(getInt(opts, PROP_INITIAL_ACK_DELAY, 500));
|
||||
if (opts.containsKey(PROP_INITIAL_WINDOW_SIZE))
|
||||
setWindowSize(getInt(opts, PROP_INITIAL_WINDOW_SIZE, 1));
|
||||
if (opts.containsKey(PROP_MAX_RESENDS))
|
||||
setMaxResends(getInt(opts, PROP_MAX_RESENDS, 5));
|
||||
if (opts.containsKey(PROP_WRITE_TIMEOUT))
|
||||
setWriteTimeout(getInt(opts, PROP_WRITE_TIMEOUT, -1));
|
||||
if (opts.containsKey(PROP_INACTIVITY_TIMEOUT))
|
||||
setInactivityTimeout(getInt(opts, PROP_INACTIVITY_TIMEOUT, 5*60*1000));
|
||||
if (opts.containsKey(PROP_INACTIVITY_ACTION))
|
||||
setInactivityAction(getInt(opts, PROP_INACTIVITY_ACTION, INACTIVITY_ACTION_DISCONNECT));
|
||||
setInboundBufferSize((getMaxMessageSize() + 2) * Connection.MAX_WINDOW_SIZE);
|
||||
|
||||
if (opts.containsKey(PROP_CONNECT_TIMEOUT))
|
||||
setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
|
||||
if (opts.containsKey(PROP_MAX_WINDOW_SIZE))
|
||||
setMaxWindowSize(getInt(opts, PROP_MAX_WINDOW_SIZE, Connection.MAX_WINDOW_SIZE));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,8 +158,8 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
*/
|
||||
public int getWindowSize() { return _windowSize; }
|
||||
public void setWindowSize(int numMsgs) {
|
||||
if (numMsgs > Connection.MAX_WINDOW_SIZE)
|
||||
numMsgs = Connection.MAX_WINDOW_SIZE;
|
||||
if (numMsgs > _maxWindowSize)
|
||||
numMsgs = _maxWindowSize;
|
||||
_windowSize = numMsgs;
|
||||
}
|
||||
|
||||
@@ -199,6 +238,16 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
public int getInactivityAction() { return _inactivityAction; }
|
||||
public void setInactivityAction(int action) { _inactivityAction = action; }
|
||||
|
||||
public int getMaxWindowSize() { return _maxWindowSize; }
|
||||
public void setMaxWindowSize(int msgs) {
|
||||
if (msgs > Connection.MAX_WINDOW_SIZE)
|
||||
_maxWindowSize = Connection.MAX_WINDOW_SIZE;
|
||||
else if (msgs < 1)
|
||||
_maxWindowSize = 1;
|
||||
else
|
||||
_maxWindowSize = msgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* how much data are we willing to accept in our buffer?
|
||||
*
|
||||
@@ -219,6 +268,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
buf.append(" writeTimeout=").append(getWriteTimeout());
|
||||
buf.append(" inactivityTimeout=").append(_inactivityTimeout);
|
||||
buf.append(" inboundBuffer=").append(_inboundBufferSize);
|
||||
buf.append(" maxWindowSize=").append(_maxWindowSize);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,16 @@ public class ConnectionPacketHandler {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (packet.isFlagSet(Packet.FLAG_MAX_PACKET_SIZE_INCLUDED)) {
|
||||
if (packet.getOptionalMaxSize() < con.getOptions().getMaxMessageSize()) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Reducing our max message size to " + packet.getOptionalMaxSize()
|
||||
+ " from " + con.getOptions().getMaxMessageSize());
|
||||
con.getOptions().setMaxMessageSize(packet.getOptionalMaxSize());
|
||||
con.getOutputStream().setBufferSize(packet.getOptionalMaxSize());
|
||||
}
|
||||
}
|
||||
|
||||
con.packetReceived();
|
||||
|
||||
@@ -185,20 +194,21 @@ public class ConnectionPacketHandler {
|
||||
oldSize >>>= 1;
|
||||
if (oldSize <= 0)
|
||||
oldSize = 1;
|
||||
con.getOptions().setWindowSize(oldSize);
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Congestion occurred - new windowSize " + oldSize + " congestionSeenAt: "
|
||||
+ con.getLastCongestionSeenAt() + " (#resends: " + numResends
|
||||
+ ") for " + con);
|
||||
|
||||
con.getOptions().setWindowSize(oldSize);
|
||||
|
||||
congested = true;
|
||||
}
|
||||
|
||||
long lowest = con.getHighestAckedThrough();
|
||||
if (lowest >= con.getCongestionWindowEnd()) {
|
||||
// new packet that ack'ed uncongested data, or an empty ack
|
||||
int newWindowSize = con.getOptions().getWindowSize();
|
||||
int oldWindow = con.getOptions().getWindowSize();
|
||||
int newWindowSize = oldWindow;
|
||||
|
||||
if ( (!congested) && (acked > 0) && (numResends <= 0) ) {
|
||||
if (newWindowSize > con.getLastCongestionSeenAt() / 2) {
|
||||
@@ -216,7 +226,7 @@ public class ConnectionPacketHandler {
|
||||
}
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("New window size " + newWindowSize + " congestionSeenAt: "
|
||||
_log.debug("New window size " + newWindowSize + "/" + oldWindow + " congestionSeenAt: "
|
||||
+ con.getLastCongestionSeenAt() + " (#resends: " + numResends
|
||||
+ ") for " + con);
|
||||
con.getOptions().setWindowSize(newWindowSize);
|
||||
|
||||
@@ -77,10 +77,10 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
_log.warn("Invalid max # of concurrent streams, defaulting to unlimited", nfe);
|
||||
_maxStreams = -1;
|
||||
}
|
||||
_connectionManager = new ConnectionManager(_context, _session, _maxStreams);
|
||||
_name = name + " " + (++__managerId);
|
||||
_acceptTimeout = ACCEPT_TIMEOUT_DEFAULT;
|
||||
_defaultOptions = new ConnectionOptions(opts);
|
||||
_connectionManager = new ConnectionManager(_context, _session, _maxStreams, _defaultOptions);
|
||||
_serverSocket = new I2PServerSocketFull(this);
|
||||
|
||||
if (_log.shouldLog(Log.INFO)) {
|
||||
@@ -91,7 +91,9 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
|
||||
public I2PSocketOptions buildOptions() { return buildOptions(null); }
|
||||
public I2PSocketOptions buildOptions(Properties opts) {
|
||||
return new ConnectionOptions(opts);
|
||||
ConnectionOptions curOpts = new ConnectionOptions(_defaultOptions);
|
||||
curOpts.setProperties(opts);
|
||||
return curOpts;
|
||||
}
|
||||
|
||||
public I2PSession getSession() {
|
||||
@@ -164,9 +166,13 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
options = _defaultOptions;
|
||||
ConnectionOptions opts = null;
|
||||
if (options instanceof ConnectionOptions)
|
||||
opts = (ConnectionOptions)options;
|
||||
opts = new ConnectionOptions((ConnectionOptions)options);
|
||||
else
|
||||
opts = new ConnectionOptions(options);
|
||||
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Connecting to " + peer.calculateHash().toBase64().substring(0,6)
|
||||
+ " with options: " + opts);
|
||||
Connection con = _connectionManager.connect(peer, opts);
|
||||
if (con == null)
|
||||
throw new TooManyStreamsException("Too many streams (max " + _maxStreams + ")");
|
||||
@@ -229,10 +235,10 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
public void setName(String name) { _name = name; }
|
||||
|
||||
|
||||
public void addDisconnectListener(DisconnectListener lsnr) {
|
||||
public void addDisconnectListener(I2PSocketManager.DisconnectListener lsnr) {
|
||||
_connectionManager.getMessageHandler().addDisconnectListener(lsnr);
|
||||
}
|
||||
public void removeDisconnectListener(DisconnectListener lsnr) {
|
||||
public void removeDisconnectListener(I2PSocketManager.DisconnectListener lsnr) {
|
||||
_connectionManager.getMessageHandler().removeDisconnectListener(lsnr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ public class MessageOutputStream extends OutputStream {
|
||||
private long _lastBuffered;
|
||||
/** if we enqueue data but don't flush it in this period, flush it passively */
|
||||
private int _passiveFlushDelay;
|
||||
/**
|
||||
* if we are changing the buffer size during operation, set this to the new
|
||||
* buffer size, and next time we are flushing, update the _buf array to the new
|
||||
* size
|
||||
*/
|
||||
private volatile int _nextBufferSize;
|
||||
|
||||
public MessageOutputStream(I2PAppContext ctx, DataReceiver receiver) {
|
||||
this(ctx, receiver, Packet.MAX_PAYLOAD_SIZE);
|
||||
@@ -48,6 +54,7 @@ public class MessageOutputStream extends OutputStream {
|
||||
_closed = false;
|
||||
_writeTimeout = -1;
|
||||
_passiveFlushDelay = 500;
|
||||
_nextBufferSize = -1;
|
||||
_flusher = new Flusher();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("MessageOutputStream created");
|
||||
@@ -55,6 +62,7 @@ public class MessageOutputStream extends OutputStream {
|
||||
|
||||
public void setWriteTimeout(int ms) { _writeTimeout = ms; }
|
||||
public int getWriteTimeout() { return _writeTimeout; }
|
||||
public void setBufferSize(int size) { _nextBufferSize = size; }
|
||||
|
||||
public void write(byte b[]) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
@@ -103,6 +111,8 @@ public class MessageOutputStream extends OutputStream {
|
||||
_valid = 0;
|
||||
throwAnyError();
|
||||
_lastFlushed = _context.clock().now();
|
||||
|
||||
locked_updateBufferSize();
|
||||
}
|
||||
}
|
||||
if (ws != null) {
|
||||
@@ -134,6 +144,22 @@ public class MessageOutputStream extends OutputStream {
|
||||
throwAnyError();
|
||||
}
|
||||
|
||||
/**
|
||||
* If the other side requested we shrink our buffer, do so.
|
||||
*
|
||||
*/
|
||||
private final void locked_updateBufferSize() {
|
||||
int size = _nextBufferSize;
|
||||
if (size > 0) {
|
||||
// update the buffer size to the requested amount
|
||||
_dataCache.release(new ByteArray(_buf));
|
||||
_dataCache = ByteCache.getInstance(128, size);
|
||||
ByteArray ba = _dataCache.acquire();
|
||||
_buf = ba.getData();
|
||||
_nextBufferSize = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush data that has been enqued but not flushed after a certain
|
||||
* period of inactivity
|
||||
@@ -172,7 +198,7 @@ public class MessageOutputStream extends OutputStream {
|
||||
WriteStatus ws = null;
|
||||
synchronized (_dataLock) {
|
||||
long flushTime = _lastBuffered + _passiveFlushDelay;
|
||||
if ( (_valid > 0) && (flushTime < _context.clock().now()) ) {
|
||||
if ( (_valid > 0) && (flushTime <= _context.clock().now()) ) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("doFlush() valid = " + _valid);
|
||||
if ( (_buf != null) && (_dataReceiver != null) ) {
|
||||
@@ -180,6 +206,7 @@ public class MessageOutputStream extends OutputStream {
|
||||
_written += _valid;
|
||||
_valid = 0;
|
||||
_lastFlushed = _context.clock().now();
|
||||
locked_updateBufferSize();
|
||||
_dataLock.notifyAll();
|
||||
sent = true;
|
||||
}
|
||||
@@ -213,6 +240,7 @@ public class MessageOutputStream extends OutputStream {
|
||||
ws = _dataReceiver.writeData(_buf, 0, _valid);
|
||||
_written += _valid;
|
||||
_valid = 0;
|
||||
locked_updateBufferSize();
|
||||
_lastFlushed = _context.clock().now();
|
||||
_dataLock.notifyAll();
|
||||
}
|
||||
@@ -251,6 +279,7 @@ public class MessageOutputStream extends OutputStream {
|
||||
ba = new ByteArray(_buf);
|
||||
_buf = null;
|
||||
_valid = 0;
|
||||
locked_updateBufferSize();
|
||||
}
|
||||
}
|
||||
if (ba != null) {
|
||||
@@ -314,6 +343,7 @@ public class MessageOutputStream extends OutputStream {
|
||||
ws = target.writeData(_buf, 0, _valid);
|
||||
_written += _valid;
|
||||
_valid = 0;
|
||||
locked_updateBufferSize();
|
||||
_dataLock.notifyAll();
|
||||
_lastFlushed = _context.clock().now();
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ public class Packet {
|
||||
if (isFlagSet(FLAG_DELAY_REQUESTED)) buf.append(" DELAY ").append(_optionDelay);
|
||||
if (isFlagSet(FLAG_ECHO)) buf.append(" ECHO");
|
||||
if (isFlagSet(FLAG_FROM_INCLUDED)) buf.append(" FROM");
|
||||
if (isFlagSet(FLAG_MAX_PACKET_SIZE_INCLUDED)) buf.append(" MS");
|
||||
if (isFlagSet(FLAG_MAX_PACKET_SIZE_INCLUDED)) buf.append(" MS ").append(_optionMaxSize);
|
||||
if (isFlagSet(FLAG_PROFILE_INTERACTIVE)) buf.append(" INTERACTIVE");
|
||||
if (isFlagSet(FLAG_RESET)) buf.append(" RESET");
|
||||
if (isFlagSet(FLAG_SIGNATURE_INCLUDED)) buf.append(" SIG");
|
||||
|
||||
@@ -35,7 +35,7 @@ public class PacketHandler {
|
||||
// artificial choke: 2% random drop and a 0-30s
|
||||
// random tiered delay from 0-30s
|
||||
if (_context.random().nextInt(100) >= 95) {
|
||||
displayPacket(packet, "DROP");
|
||||
displayPacket(packet, "DROP", null);
|
||||
return false;
|
||||
} else {
|
||||
// if (true) return true; // no lag, just drop
|
||||
@@ -87,8 +87,8 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
private void receivePacketDirect(Packet packet) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("packet received: " + packet);
|
||||
//if (_log.shouldLog(Log.DEBUG))
|
||||
// _log.debug("packet received: " + packet);
|
||||
|
||||
byte sendId[] = packet.getSendStreamId();
|
||||
if (!isNonZero(sendId))
|
||||
@@ -97,18 +97,18 @@ public class PacketHandler {
|
||||
Connection con = (sendId != null ? _manager.getConnectionByInboundId(sendId) : null);
|
||||
if (con != null) {
|
||||
receiveKnownCon(con, packet);
|
||||
displayPacket(packet, "RECV");
|
||||
displayPacket(packet, "RECV", "wsize " + con.getOptions().getWindowSize());
|
||||
} else {
|
||||
receiveUnknownCon(packet, sendId);
|
||||
displayPacket(packet, "UNKN");
|
||||
displayPacket(packet, "UNKN", null);
|
||||
}
|
||||
}
|
||||
|
||||
private static final SimpleDateFormat _fmt = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
void displayPacket(Packet packet, String prefix) {
|
||||
void displayPacket(Packet packet, String prefix, String suffix) {
|
||||
String msg = null;
|
||||
synchronized (_fmt) {
|
||||
msg = _fmt.format(new Date()) + ": " + prefix + " " + packet.toString();
|
||||
msg = _fmt.format(new Date()) + ": " + prefix + " " + packet.toString() + (suffix != null ? " " + suffix : "");
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
System.out.println(msg);
|
||||
@@ -118,8 +118,8 @@ public class PacketHandler {
|
||||
// the packet is pointed at a stream ID we're receiving on
|
||||
if (isValidMatch(con.getSendStreamId(), packet.getReceiveStreamId())) {
|
||||
// the packet's receive stream ID also matches what we expect
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("receive valid: " + packet);
|
||||
//if (_log.shouldLog(Log.DEBUG))
|
||||
// _log.debug("receive valid: " + packet);
|
||||
try {
|
||||
con.getPacketHandler().receivePacket(packet, con);
|
||||
} catch (I2PException ie) {
|
||||
|
||||
@@ -121,7 +121,9 @@ class PacketQueue {
|
||||
+ " con: " + conStr;
|
||||
_log.debug(msg);
|
||||
}
|
||||
_connectionManager.getPacketHandler().displayPacket(packet, "SEND");
|
||||
Connection c = packet.getConnection();
|
||||
String suffix = (c != null ? "wsize " + c.getOptions().getWindowSize() : null);
|
||||
_connectionManager.getPacketHandler().displayPacket(packet, "SEND", suffix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class SchedulerClosed extends SchedulerImpl {
|
||||
long timeSinceClose = _context.clock().now() - con.getCloseSentOn();
|
||||
boolean ok = (con.getCloseSentOn() > 0) &&
|
||||
(con.getCloseReceivedOn() > 0) &&
|
||||
(con.getUnackedPacketsReceived() <= 0) &&
|
||||
//(con.getUnackedPacketsReceived() <= 0) &&
|
||||
(con.getUnackedPacketsSent() <= 0) &&
|
||||
(!con.getResetReceived()) &&
|
||||
(timeSinceClose < Connection.DISCONNECT_TIMEOUT);
|
||||
|
||||
@@ -34,9 +34,12 @@ class SchedulerClosing extends SchedulerImpl {
|
||||
}
|
||||
|
||||
public boolean accept(Connection con) {
|
||||
long timeSinceClose = _context.clock().now() - con.getCloseSentOn();
|
||||
boolean ok = (con != null) &&
|
||||
(con.getCloseSentOn() > 0) &&
|
||||
(con.getCloseReceivedOn() > 0) &&
|
||||
(!con.getResetSent()) &&
|
||||
(!con.getResetReceived()) &&
|
||||
( (con.getCloseSentOn() > 0) || (con.getCloseReceivedOn() > 0) ) &&
|
||||
(timeSinceClose < Connection.DISCONNECT_TIMEOUT) &&
|
||||
( (con.getUnackedPacketsReceived() > 0) || (con.getUnackedPacketsSent() > 0) );
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class PingTest {
|
||||
try {
|
||||
I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
I2PSession session = createSession();
|
||||
ConnectionManager mgr = new ConnectionManager(context, session, -1);
|
||||
ConnectionManager mgr = new ConnectionManager(context, session, -1, null);
|
||||
Log log = context.logManager().getLog(PingTest.class);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log.debug("ping " + i);
|
||||
|
||||
42
apps/susimail/build.xml
Normal file
42
apps/susimail/build.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project basedir="." default="all" name="susimail">
|
||||
<target name="all" depends="clean, build" />
|
||||
<target name="build" depends="builddep, jar" />
|
||||
<target name="builddep">
|
||||
<ant dir="../jetty/" target="build" />
|
||||
</target>
|
||||
<target name="compile" depends="clean">
|
||||
<javac
|
||||
srcdir="./src/src"
|
||||
debug="true" deprecation="off" source="1.3" target="1.3"
|
||||
destdir="./src/WEB-INF/classes">
|
||||
<classpath>
|
||||
<pathelement location="../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../jetty/jettylib/org.mortbay.jetty.jar" />
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
<target name="jar" depends="compile, war" />
|
||||
<target name="war" depends="compile">
|
||||
<war destfile="susimail.war" webxml="src/WEB-INF/web.xml"
|
||||
basedir="src/" excludes="WEB-INF/web.xml">
|
||||
</war>
|
||||
</target>
|
||||
<target name="javadoc">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/javadoc" />
|
||||
<javadoc
|
||||
sourcepath="./src/src/" destdir="./build/javadoc"
|
||||
packagenames="*"
|
||||
use="true"
|
||||
splitindex="true"
|
||||
windowtitle="susimail" />
|
||||
</target>
|
||||
<target name="clean">
|
||||
<delete>
|
||||
<fileset dir="src/WEB-INF/classes/" includes="**/*.class, susimail.war" />
|
||||
</delete>
|
||||
</target>
|
||||
<target name="cleandep" depends="clean" />
|
||||
<target name="distclean" depends="clean" />
|
||||
</project>
|
||||
2
apps/susimail/readme.txt
Normal file
2
apps/susimail/readme.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
The src/ dir contains susimail 0.13 retrieved from http://susi.i2p/ on 2005/02/17
|
||||
The contents are released under GPL. Please see http://susi.i2p/ for more info
|
||||
BIN
apps/susimail/src/3down.png
Normal file
BIN
apps/susimail/src/3down.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 415 B |
BIN
apps/susimail/src/3up.png
Normal file
BIN
apps/susimail/src/3up.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 406 B |
340
apps/susimail/src/LICENSE
Normal file
340
apps/susimail/src/LICENSE
Normal file
@@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
20
apps/susimail/src/WEB-INF/classes/susimail.properties
Normal file
20
apps/susimail/src/WEB-INF/classes/susimail.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
susimail.encodings=i2p.susi.webmail.encoding.HeaderLine;i2p.susi.webmail.encoding.QuotedPrintable;i2p.susi.webmail.encoding.Base64;i2p.susi.webmail.encoding.SevenBit;i2p.susi.webmail.encoding.EightBit;i2p.susi.webmail.encoding.HTML
|
||||
|
||||
susimail.host=localhost
|
||||
|
||||
susimail.ports.fixed=true
|
||||
susimail.ports.pop3=7660
|
||||
susimail.ports.smtp=7659
|
||||
|
||||
susimail.fast.start=true
|
||||
|
||||
susimail.sender.fixed=true
|
||||
susimail.sender.domain=mail.i2p
|
||||
|
||||
susimail.pager.pagesize=10
|
||||
|
||||
susimail.composer.cols=80
|
||||
susimail.composer.rows=15
|
||||
susimail.composer.bcc.to.self=true
|
||||
|
||||
susimail.date.format=MM/dd/yyyy HH:mm:ss
|
||||
18
apps/susimail/src/WEB-INF/web.xml
Normal file
18
apps/susimail/src/WEB-INF/web.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE web-app
|
||||
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
|
||||
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
|
||||
<web-app>
|
||||
<display-name>susimail</display-name>
|
||||
<servlet>
|
||||
<servlet-name>SusiMail</servlet-name>
|
||||
<servlet-class>i2p.susi.webmail.WebMail</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>SusiMail</servlet-name>
|
||||
<url-pattern>/susimail</url-pattern>
|
||||
</servlet-mapping>
|
||||
<session-config>
|
||||
<session-timeout>15</session-timeout>
|
||||
</session-config>
|
||||
</web-app>
|
||||
10
apps/susimail/src/index.html
Normal file
10
apps/susimail/src/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;url=susimail" />
|
||||
<title>Susimail</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="susimail">Enter</a>
|
||||
</body>
|
||||
</html>
|
||||
43
apps/susimail/src/src/i2p/susi/debug/Debug.java
Normal file
43
apps/susimail/src/src/i2p/susi/debug/Debug.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Created on Nov 4, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.debug;
|
||||
|
||||
/**
|
||||
* @author susi23
|
||||
*/
|
||||
public class Debug {
|
||||
|
||||
public static final int ERROR = 1;
|
||||
public static final int DEBUG = 2;
|
||||
private static int level = ERROR;
|
||||
public static void setLevel( int newLevel )
|
||||
{
|
||||
level = newLevel;
|
||||
}
|
||||
public static void debug( int msgLevel, String msg )
|
||||
{
|
||||
if( msgLevel <= level )
|
||||
System.err.println( msg );
|
||||
}
|
||||
}
|
||||
128
apps/susimail/src/src/i2p/susi/util/Config.java
Normal file
128
apps/susimail/src/src/i2p/susi/util/Config.java
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Created on Nov 15, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
*/
|
||||
package i2p.susi.util;
|
||||
|
||||
import i2p.susi.debug.Debug;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
private static Properties properties = null, config = null;
|
||||
private static String configPrefix = null;
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty( String name )
|
||||
{
|
||||
if( configPrefix != null )
|
||||
name = configPrefix + name;
|
||||
|
||||
String result = null;
|
||||
|
||||
if( properties == null ) {
|
||||
reloadConfiguration();
|
||||
}
|
||||
|
||||
result = System.getProperty( name );
|
||||
|
||||
if( result != null )
|
||||
return result;
|
||||
|
||||
result = config.getProperty( name );
|
||||
|
||||
if( result != null )
|
||||
return result;
|
||||
|
||||
result = properties.getProperty( name );
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public static void reloadConfiguration()
|
||||
{
|
||||
properties = new Properties();
|
||||
config = new Properties();
|
||||
try {
|
||||
properties.load( Config.class.getResourceAsStream( "/susimail.properties" ) );
|
||||
} catch (Exception e) {
|
||||
Debug.debug( Debug.DEBUG, "Could not open WEB-INF/classes/susimail.properties (possibly in jar), reason: " + e.getMessage() );
|
||||
}
|
||||
try {
|
||||
config.load( new FileInputStream( "susimail.config" ) );
|
||||
} catch (Exception e) {
|
||||
Debug.debug( Debug.DEBUG, "Could not open susimail.config, reason: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty( String name, String defaultValue )
|
||||
{
|
||||
String result = getProperty( name );
|
||||
return result != null ? result : defaultValue;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public static int getProperty( String name, int defaultValue )
|
||||
{
|
||||
int result = defaultValue;
|
||||
|
||||
String str = getProperty( name );
|
||||
|
||||
if( str != null ) {
|
||||
try {
|
||||
result = Integer.parseInt( str );
|
||||
}
|
||||
catch( NumberFormatException nfe ) {
|
||||
result = defaultValue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param prefix
|
||||
*/
|
||||
public static void setPrefix( String prefix )
|
||||
{
|
||||
configPrefix = prefix.endsWith( "." ) ? prefix : prefix + ".";
|
||||
}
|
||||
}
|
||||
452
apps/susimail/src/src/i2p/susi/util/Folder.java
Normal file
452
apps/susimail/src/src/i2p/susi/util/Folder.java
Normal file
@@ -0,0 +1,452 @@
|
||||
/*
|
||||
* Created on Nov 23, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.util;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Folder object manages a array Object[] to support
|
||||
* paging and sorting.
|
||||
*
|
||||
* You create a folder object, set the contents with setElements(),
|
||||
* add Comparators with addSorter(), choose one with sortBy() and
|
||||
* and then fetch the content of the current page with
|
||||
* currentPageIterator().
|
||||
*
|
||||
* @author susi
|
||||
*/
|
||||
public class Folder {
|
||||
|
||||
public static final String PAGESIZE = "pager.pagesize";
|
||||
public static final int DEFAULT_PAGESIZE = 10;
|
||||
|
||||
public static final boolean DOWN = false;
|
||||
public static final boolean UP = true;
|
||||
|
||||
private int pages, pageSize, currentPage;
|
||||
private Object[] unsortedElements, elements;
|
||||
private Hashtable sorter;
|
||||
private boolean sortingDirection;
|
||||
Comparator currentSorter;
|
||||
|
||||
public Folder()
|
||||
{
|
||||
pages = 1;
|
||||
pageSize = 0;
|
||||
currentPage = 1;
|
||||
unsortedElements = null;
|
||||
sorter = new Hashtable();
|
||||
sortingDirection = UP;
|
||||
currentSorter = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current page.
|
||||
*
|
||||
* @return Returns the current page.
|
||||
*/
|
||||
public int getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current page to the given parameter.
|
||||
*
|
||||
* @param currentPage The current page to set.
|
||||
*/
|
||||
public void setCurrentPage(int currentPage) {
|
||||
if( currentPage >= 1 && currentPage <= pages )
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the folder.
|
||||
*
|
||||
* @return Returns the size of the folder.
|
||||
*/
|
||||
public int getSize() {
|
||||
return elements != null ? elements.length : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of pages in the folder.
|
||||
* @return Returns the number of pages.
|
||||
*/
|
||||
public int getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns page size. If no page size has been set, it returns property @link PAGESIZE.
|
||||
* If no property is set @link DEFAULT_PAGESIZE is returned.
|
||||
*
|
||||
* @return Returns the pageSize.
|
||||
*/
|
||||
public int getPageSize() {
|
||||
return pageSize > 0 ? pageSize : Config.getProperty( PAGESIZE, DEFAULT_PAGESIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set page size.
|
||||
*
|
||||
* @param pageSize The page size to set.
|
||||
*/
|
||||
public void setPageSize(int pageSize) {
|
||||
if( pageSize > 0 )
|
||||
this.pageSize = pageSize;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of an array by copying its elements.
|
||||
*
|
||||
* @param source Array to copy.
|
||||
* @return Copy of source.
|
||||
*/
|
||||
private Object[] copyArray( Object[] source )
|
||||
{
|
||||
Object[] destination = new Object[source.length];
|
||||
for( int i = 0; i < source.length; i++ )
|
||||
destination[i] = source[i];
|
||||
return destination;
|
||||
}
|
||||
/**
|
||||
* Recalculates variables.
|
||||
*/
|
||||
private void update() {
|
||||
if( elements != null ) {
|
||||
pages = elements.length / getPageSize();
|
||||
if( pages * getPageSize() < elements.length )
|
||||
pages++;
|
||||
if( currentPage > pages )
|
||||
currentPage = pages;
|
||||
}
|
||||
else {
|
||||
pages = 1;
|
||||
currentPage = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the elements according the order given by @link addSorter()
|
||||
* and @link sortBy().
|
||||
*/
|
||||
private void sort()
|
||||
{
|
||||
if( currentSorter != null ) {
|
||||
elements = copyArray( unsortedElements );
|
||||
Arrays.sort( elements, currentSorter );
|
||||
}
|
||||
else {
|
||||
elements = unsortedElements;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the array of objects the folder should manage.
|
||||
*
|
||||
* @param elements Array of Objects.
|
||||
*/
|
||||
public void setElements( Object[] elements )
|
||||
{
|
||||
this.unsortedElements = elements;
|
||||
if( currentSorter != null )
|
||||
sort();
|
||||
else
|
||||
this.elements = elements;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator containing the elements on the current page.
|
||||
* @return Iterator containing the elements on the current page.
|
||||
*/
|
||||
public Iterator currentPageIterator()
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
if( elements != null ) {
|
||||
int pageSize = getPageSize();
|
||||
int offset = ( currentPage - 1 ) * pageSize;
|
||||
int step = 1;
|
||||
if( sortingDirection == DOWN ) {
|
||||
offset = elements.length - offset - 1;
|
||||
step = -1;
|
||||
}
|
||||
for( int i = 0; i < pageSize && offset >= 0 && offset < elements.length; i++ ) {
|
||||
list.add( elements[offset] );
|
||||
offset += step;
|
||||
}
|
||||
}
|
||||
return list.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns folder to next page.
|
||||
*/
|
||||
public void nextPage()
|
||||
{
|
||||
currentPage++;
|
||||
if( currentPage > pages )
|
||||
currentPage = pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns folder to previous page.
|
||||
*/
|
||||
public void previousPage()
|
||||
{
|
||||
currentPage--;
|
||||
if( currentPage < 1 )
|
||||
currentPage = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets folder to display first page.
|
||||
*/
|
||||
public void firstPage()
|
||||
{
|
||||
currentPage = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets folder to display last page.
|
||||
*/
|
||||
public void lastPage()
|
||||
{
|
||||
currentPage = pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new sorter to the folder. You can sort the folder by
|
||||
* calling sortBy() and choose the given id there.
|
||||
*
|
||||
* @param id ID to identify the Comparator with @link sortBy()
|
||||
* @param sorter a Comparator to sort the Array given by @link setElements()
|
||||
*/
|
||||
public void addSorter( String id, Comparator sorter )
|
||||
{
|
||||
this.sorter.put( id, sorter );
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates sorting by the choosen Comparator. The id must
|
||||
* match the one, which the Comparator has been stored in the
|
||||
* folder with @link addSorter().
|
||||
*
|
||||
* @param id ID to identify the Comparator stored with @link addSorter()
|
||||
*/
|
||||
public void sortBy( String id )
|
||||
{
|
||||
currentSorter = (Comparator)sorter.get( id );
|
||||
sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element on the current page on the given position.
|
||||
*
|
||||
* @param Position of the element on the current page.
|
||||
* @return Element on the current page on the given position.
|
||||
*/
|
||||
public Object getElementAtPosXonCurrentPage( int x )
|
||||
{
|
||||
Object result = null;
|
||||
if( elements != null ) {
|
||||
int pageSize = getPageSize();
|
||||
int offset = ( currentPage - 1 ) * pageSize;
|
||||
int step = 1;
|
||||
if( sortingDirection == DOWN ) {
|
||||
offset = elements.length - offset - 1;
|
||||
step = -1;
|
||||
}
|
||||
offset += x * step;
|
||||
if( offset >= 0 && offset < elements.length )
|
||||
result = elements[offset];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sorting direction of the folder.
|
||||
*
|
||||
* @param direction @link UP or @link DOWN
|
||||
*/
|
||||
public void setSortingDirection( boolean direction )
|
||||
{
|
||||
sortingDirection = direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element of the sorted folder.
|
||||
*
|
||||
* @return First element.
|
||||
*/
|
||||
public Object getFirstElement()
|
||||
{
|
||||
/*
|
||||
* sorting direction is taken into account from getElement
|
||||
*/
|
||||
return elements == null ? null : getElement( 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last element of the sorted folder.
|
||||
*
|
||||
* @return Last element.
|
||||
*/
|
||||
public Object getLastElement()
|
||||
{
|
||||
/*
|
||||
* sorting direction is taken into account from getElement
|
||||
*/
|
||||
return elements == null ? null : getElement( elements.length - 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets index of an element in the array regardless of sorting direction.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
private int getIndexOf( Object element )
|
||||
{
|
||||
if( elements != null ) {
|
||||
for( int i = 0; i < elements.length; i++ )
|
||||
if( elements[i].equals( element ) )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the next element in the sorted array.
|
||||
* Sorting direction is taken into account.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public Object getNextElement( Object element )
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
int i = getIndexOf( element );
|
||||
|
||||
if( i != -1 && elements != null ) {
|
||||
i += sortingDirection == UP ? 1 : -1;
|
||||
if( i >= 0 && i < elements.length )
|
||||
result = elements[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the previous element in the sorted array.
|
||||
* Sorting direction is taken into account.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public Object getPreviousElement( Object element )
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
int i = getIndexOf( element );
|
||||
|
||||
if( i != -1 && elements != null ) {
|
||||
i += sortingDirection == DOWN ? 1 : -1;
|
||||
if( i >= 0 && i < elements.length )
|
||||
result = elements[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Retrieves element at index i. Depends on sorting direction.
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
private Object getElement( int i )
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
if( elements != null ) {
|
||||
if( sortingDirection == DOWN )
|
||||
i = elements.length - i - 1;
|
||||
result = elements[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if folder shows points to the last page.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isLastPage()
|
||||
{
|
||||
return currentPage == pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if folder shows points to the first page.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isFirstPage()
|
||||
{
|
||||
return currentPage == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if elements.equals( lastElementOfTheSortedArray ).
|
||||
* The sorting direction influences which element is taken for comparison.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public boolean isLastElement( Object element )
|
||||
{
|
||||
if( elements == null )
|
||||
return false;
|
||||
return elements[ sortingDirection == DOWN ? 0 : elements.length - 1 ].equals( element );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if elements.equals( firstElementOfTheSortedArray ).
|
||||
* The sorting direction influences which element is taken for comparison.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public boolean isFirstElement( Object element )
|
||||
{
|
||||
if( elements == null )
|
||||
return false;
|
||||
return elements[ sortingDirection == UP ? 0 : elements.length - 1 ].equals( element );
|
||||
}
|
||||
}
|
||||
60
apps/susimail/src/src/i2p/susi/util/HexTable.java
Normal file
60
apps/susimail/src/src/i2p/susi/util/HexTable.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.util;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class HexTable {
|
||||
|
||||
public static String[] table = null;
|
||||
|
||||
static {
|
||||
table = new String[256];
|
||||
for( int i = 0; i < 256; i++ ) {
|
||||
String str = intToHex( i );
|
||||
if( str.length() == 1 )
|
||||
str = "0" + str;
|
||||
table[i] = "=" + str;
|
||||
}
|
||||
}
|
||||
private static String intToHex( int b )
|
||||
{
|
||||
if( b == 0 )
|
||||
return "0";
|
||||
else {
|
||||
String str = "";
|
||||
while( b > 0 ) {
|
||||
byte c = (byte)(b % 16);
|
||||
if( c < 10 )
|
||||
c += '0';
|
||||
else
|
||||
c += 'A' - 10;
|
||||
str = "" + (char)c + str;
|
||||
b = (byte)(b / 16);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
apps/susimail/src/src/i2p/susi/util/ReadBuffer.java
Normal file
38
apps/susimail/src/src/i2p/susi/util/ReadBuffer.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Created on Nov 15, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.util;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class ReadBuffer {
|
||||
|
||||
public byte content[];
|
||||
public int length, offset;
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return content != null ? new String( content, offset, length ) : "";
|
||||
}
|
||||
}
|
||||
97
apps/susimail/src/src/i2p/susi/webmail/Attachment.java
Normal file
97
apps/susimail/src/src/i2p/susi/webmail/Attachment.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Created on 01.12.2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
*/
|
||||
public class Attachment {
|
||||
private String fileName, contentType, transferEncoding;
|
||||
private ReadBuffer buffer;
|
||||
private String data;
|
||||
/**
|
||||
* @return Returns the fileName.
|
||||
*/
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
/**
|
||||
* @param fileName The fileName to set.
|
||||
*/
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
/**
|
||||
* @return Returns the buffer.
|
||||
*/
|
||||
public ReadBuffer getBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
/**
|
||||
* @param buffer The buffer to set.
|
||||
*/
|
||||
public void setBuffer(ReadBuffer buffer) {
|
||||
this.buffer = buffer;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getTransferEncoding() {
|
||||
// TODO Auto-generated method stub
|
||||
return transferEncoding;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getContentType() {
|
||||
// TODO Auto-generated method stub
|
||||
return contentType;
|
||||
}
|
||||
/**
|
||||
* @param contentType The contentType to set.
|
||||
*/
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
/**
|
||||
* @param transferEncoding The transferEncoding to set.
|
||||
*/
|
||||
public void setTransferEncoding(String transferEncoding) {
|
||||
this.transferEncoding = transferEncoding;
|
||||
}
|
||||
/**
|
||||
* @param string
|
||||
*/
|
||||
public void setData(String data ) {
|
||||
this.data = data;
|
||||
}
|
||||
/**
|
||||
* @return Returns the data.
|
||||
*/
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
240
apps/susimail/src/src/i2p/susi/webmail/Mail.java
Normal file
240
apps/susimail/src/src/i2p/susi/webmail/Mail.java
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Created on Nov 9, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.5 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import i2p.susi.debug.Debug;
|
||||
import i2p.susi.util.Config;
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
import i2p.susi.webmail.encoding.Encoding;
|
||||
import i2p.susi.webmail.encoding.EncodingFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* data structure to hold a single message, mostly used with folder view and sorting
|
||||
*
|
||||
* @author susi
|
||||
*/
|
||||
public class Mail {
|
||||
|
||||
public static final String DATEFORMAT = "date.format";
|
||||
|
||||
public static final String unknown = "unknown";
|
||||
|
||||
public int id, size;
|
||||
public String sender, reply, subject, dateString,
|
||||
formattedSender, formattedSubject, formattedDate,
|
||||
shortSender, shortSubject, quotedDate, uidl;
|
||||
public Date date;
|
||||
public ReadBuffer header, body;
|
||||
public MailPart part;
|
||||
Object[] to, cc;
|
||||
|
||||
public String error;
|
||||
|
||||
public boolean markForDeletion;
|
||||
|
||||
public boolean deleted;
|
||||
|
||||
public Mail() {
|
||||
id = 0;
|
||||
size = 0;
|
||||
formattedSender = unknown;
|
||||
formattedSubject = unknown;
|
||||
formattedDate = unknown;
|
||||
shortSender = unknown;
|
||||
shortSubject = unknown;
|
||||
quotedDate = unknown;
|
||||
error = "";
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
public static boolean validateAddress( String address )
|
||||
{
|
||||
if( address == null || address.length() == 0 )
|
||||
return false;
|
||||
|
||||
address = address.trim();
|
||||
|
||||
if( address.indexOf( "\n" ) != -1 ||
|
||||
address.indexOf( "\r" ) != -1 )
|
||||
return false;
|
||||
|
||||
String[] tokens = address.split( "[ \t]+" );
|
||||
|
||||
int addresses = 0;
|
||||
|
||||
for( int i = 0; i < tokens.length; i++ ) {
|
||||
if( tokens[i].matches( "^[^@< \t]+@[^> \t]+$" ) ||
|
||||
tokens[i].matches( "^<[^@< \t]+@[^> \t]+>$" ) )
|
||||
addresses++;
|
||||
}
|
||||
return addresses == 1;
|
||||
}
|
||||
/**
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
public static String getAddress(String address )
|
||||
{
|
||||
String[] tokens = address.split( "[ \t]+" );
|
||||
|
||||
for( int i = 0; i < tokens.length; i++ ) {
|
||||
if( tokens[i].matches( "^[^@< \t]+@[^> \t]+$" ) )
|
||||
return "<" + tokens[i] + ">";
|
||||
if( tokens[i].matches( "^<[^@< \t]+@[^> \t]+>$" ) )
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static boolean getRecipientsFromList( ArrayList recipients, String text, boolean ok )
|
||||
{
|
||||
if( text != null && text.length() > 0 ) {
|
||||
String[] ccs = text.split( "," );
|
||||
for( int i = 0; i < ccs.length; i++ ) {
|
||||
String recipient = ccs[i].trim();
|
||||
if( validateAddress( recipient ) ) {
|
||||
String str = getAddress( recipient );
|
||||
if( str != null && str.length() > 0 ) {
|
||||
recipients.add( str );
|
||||
}
|
||||
else {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
public static void appendRecipients( StringBuffer buf, ArrayList recipients, String prefix )
|
||||
{
|
||||
for( Iterator it = recipients.iterator(); it.hasNext(); ) {
|
||||
buf.append( prefix );
|
||||
prefix ="\t";
|
||||
buf.append( (String)it.next() );
|
||||
buf.append( "\r\n" );
|
||||
}
|
||||
}
|
||||
public void parseHeaders()
|
||||
{
|
||||
DateFormat dateFormatter = new SimpleDateFormat( Config.getProperty( DATEFORMAT, "mm/dd/yyyy HH:mm:ss" ) );
|
||||
DateFormat mailDateFormatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH );
|
||||
|
||||
error = "";
|
||||
if( header != null ) {
|
||||
|
||||
boolean ok = true;
|
||||
|
||||
Encoding html = EncodingFactory.getEncoding( "HTML" );
|
||||
|
||||
if( html == null ) {
|
||||
error += "HTML encoder not found.<br>";
|
||||
ok = false;
|
||||
}
|
||||
|
||||
Encoding hl = EncodingFactory.getEncoding( "HEADERLINE" );
|
||||
|
||||
if( hl == null ) {
|
||||
error += "Header line encoder not found.<br>";
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if( ok ) {
|
||||
|
||||
try {
|
||||
ReadBuffer decoded = hl.decode( header );
|
||||
BufferedReader reader = new BufferedReader( new InputStreamReader( new ByteArrayInputStream( decoded.content, decoded.offset, decoded.length ), "ISO-8859-1" ) );
|
||||
String line;
|
||||
while( ( line = reader.readLine() ) != null ) {
|
||||
if( line.length() == 0 )
|
||||
break;
|
||||
|
||||
if( line.startsWith( "From:" ) ) {
|
||||
sender = line.substring( 5 ).trim();
|
||||
formattedSender = getAddress( sender );
|
||||
shortSender = formattedSender.trim();
|
||||
if( shortSender.length() > 40 ) {
|
||||
shortSender = shortSender.substring( 0, 37 ).trim() + "...";
|
||||
}
|
||||
shortSender = html.encode( shortSender );
|
||||
}
|
||||
else if( line.startsWith( "Date:" ) ) {
|
||||
dateString = line.substring( 5 ).trim();
|
||||
try {
|
||||
date = mailDateFormatter.parse( dateString );
|
||||
formattedDate = dateFormatter.format( date );
|
||||
quotedDate = html.encode( dateString );
|
||||
}
|
||||
catch (ParseException e) {
|
||||
date = null;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if( line.startsWith( "Subject:" ) ) {
|
||||
subject = line.substring( 8 ).trim();
|
||||
formattedSubject = subject;
|
||||
shortSubject = formattedSubject;
|
||||
if( formattedSubject.length() > 60 )
|
||||
shortSubject = formattedSubject.substring( 0, 57 ).trim() + "...";
|
||||
shortSubject = html.encode( shortSubject );
|
||||
}
|
||||
else if( line.toLowerCase().startsWith( "Reply-To:" ) ) {
|
||||
reply = Mail.getAddress( line.substring( 9 ).trim() );
|
||||
}
|
||||
else if( line.startsWith( "To:" ) ) {
|
||||
ArrayList list = new ArrayList();
|
||||
Mail.getRecipientsFromList( list, line.substring( 3 ).trim(), true );
|
||||
to = list.toArray();
|
||||
}
|
||||
else if( line.startsWith( "Cc:" ) ) {
|
||||
ArrayList list = new ArrayList();
|
||||
Mail.getRecipientsFromList( list, line.substring( 3 ).trim(), true );
|
||||
cc = list.toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception e ) {
|
||||
error += "Error parsing mail header: " + e.getClass().getName() + "<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
103
apps/susimail/src/src/i2p/susi/webmail/MailCache.java
Normal file
103
apps/susimail/src/src/i2p/susi/webmail/MailCache.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Created on Nov 23, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import i2p.susi.debug.Debug;
|
||||
import i2p.susi.webmail.pop3.POP3MailBox;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
*/
|
||||
public class MailCache {
|
||||
|
||||
public static final boolean FETCH_HEADER = true;
|
||||
public static final boolean FETCH_ALL = false;
|
||||
|
||||
private POP3MailBox mailbox;
|
||||
private String error;
|
||||
private Hashtable mails;
|
||||
private Object synchronizer;
|
||||
|
||||
MailCache( POP3MailBox mailbox ) {
|
||||
this.mailbox = mailbox;
|
||||
mails = new Hashtable();
|
||||
synchronizer = new Object();
|
||||
}
|
||||
/**
|
||||
* Fetch any needed data from pop3 server.
|
||||
*
|
||||
* @param id message id to get
|
||||
* @param headerOnly fetch only header lines?
|
||||
* @return
|
||||
*/
|
||||
public Mail getMail( String uidl, boolean headerOnly ) {
|
||||
|
||||
Mail mail = null, newMail = null;
|
||||
|
||||
if( mailbox != null ) {
|
||||
/*
|
||||
* synchronize update to hashtable
|
||||
*/
|
||||
synchronized( synchronizer ) {
|
||||
|
||||
mail = (Mail)mails.get( uidl );
|
||||
|
||||
if( mail == null ) {
|
||||
newMail = new Mail();
|
||||
mails.put( uidl, newMail );
|
||||
}
|
||||
}
|
||||
if( mail == null ) {
|
||||
mail = newMail;
|
||||
mail.uidl = uidl;
|
||||
mail.size = mailbox.getSize( uidl );
|
||||
}
|
||||
if( mail.size < 1024 )
|
||||
headerOnly = false;
|
||||
|
||||
boolean parseHeaders = mail.header == null;
|
||||
|
||||
if( headerOnly ) {
|
||||
if( mail.header == null )
|
||||
mail.header = mailbox.getHeader( uidl );
|
||||
}
|
||||
else {
|
||||
if( mail.body == null ) {
|
||||
mail.body = mailbox.getBody( uidl );
|
||||
if( mail.body != null ) {
|
||||
mail.header = mail.body;
|
||||
MailPart.parse( mail );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( parseHeaders && mail.header != null )
|
||||
mail.parseHeaders();
|
||||
}
|
||||
if( mail != null && mail.deleted )
|
||||
mail = null;
|
||||
return mail;
|
||||
}
|
||||
}
|
||||
260
apps/susimail/src/src/i2p/susi/webmail/MailPart.java
Normal file
260
apps/susimail/src/src/i2p/susi/webmail/MailPart.java
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Created on 07.11.2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
import i2p.susi.webmail.encoding.EncodingFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author susi23
|
||||
*/
|
||||
public class MailPart {
|
||||
|
||||
public String headerLines[], type, boundary, encoding, name,
|
||||
filename, description, disposition, charset, version;
|
||||
public int beginBody, begin, end;
|
||||
public ArrayList parts = null;
|
||||
public boolean multipart = false, message = false;
|
||||
public ReadBuffer buffer = null;
|
||||
|
||||
public void parse( ReadBuffer readBuffer )
|
||||
{
|
||||
parse( readBuffer, readBuffer.offset, readBuffer.length );
|
||||
}
|
||||
|
||||
public void parse( ReadBuffer readBuffer, int offset, int length )
|
||||
{
|
||||
begin = offset;
|
||||
end = offset + length;
|
||||
buffer = readBuffer;
|
||||
|
||||
if( parts == null )
|
||||
parts = new ArrayList();
|
||||
else
|
||||
parts.clear();
|
||||
|
||||
/*
|
||||
* parse header lines
|
||||
*/
|
||||
beginBody = end;
|
||||
for( int i = begin; i < end - 4; i++ )
|
||||
if( buffer.content[i] == '\r' &&
|
||||
buffer.content[i+1] == '\n' &&
|
||||
buffer.content[i+2] == '\r' &&
|
||||
buffer.content[i+3] == '\n' ) {
|
||||
beginBody = i + 2;
|
||||
break;
|
||||
}
|
||||
|
||||
ReadBuffer decodedHeaders = null;
|
||||
try {
|
||||
decodedHeaders = EncodingFactory.getEncoding( "HEADERLINE" ).decode( buffer.content, begin, beginBody - begin );
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
headerLines = new String( decodedHeaders.content, decodedHeaders.offset, decodedHeaders.length ).split( "\r\n" );
|
||||
|
||||
for( int i = 0; i < headerLines.length; i++ )
|
||||
{
|
||||
if( headerLines[i].toLowerCase().startsWith( "content-transfer-encoding: " ) ) {
|
||||
encoding = getFirstAttribute( headerLines[i] ).toLowerCase();
|
||||
}
|
||||
else if( headerLines[i].toLowerCase().startsWith( "content-disposition: " ) ) {
|
||||
disposition = getFirstAttribute( headerLines[i] ).toLowerCase();
|
||||
String str;
|
||||
str = getHeaderLineAttribute( headerLines[i], "filename" );
|
||||
if( str != null )
|
||||
name = str;
|
||||
}
|
||||
else if( headerLines[i].toLowerCase().startsWith( "content-type: " ) ) {
|
||||
type = getFirstAttribute( headerLines[i] ).toLowerCase();
|
||||
/*
|
||||
* extract boundary, name and charset from content type
|
||||
*/
|
||||
String str;
|
||||
str = getHeaderLineAttribute( headerLines[i], "boundary" );
|
||||
if( str != null )
|
||||
boundary = str;
|
||||
if( type != null && type.startsWith( "multipart" ) && boundary != null )
|
||||
multipart = true;
|
||||
if( type != null && type.startsWith( "message" ) )
|
||||
message = true;
|
||||
str = getHeaderLineAttribute( headerLines[i], "name" );
|
||||
if( str != null )
|
||||
name = str;
|
||||
str = getHeaderLineAttribute( headerLines[i], "charset" );
|
||||
if( str != null )
|
||||
charset = str.toUpperCase();
|
||||
}
|
||||
else if( headerLines[i].toLowerCase().startsWith( "content-description: " ) ) {
|
||||
description = getFirstAttribute( headerLines[i] );
|
||||
}
|
||||
else if( headerLines[i].toLowerCase().startsWith( "mime-version: " ) ) {
|
||||
version = getFirstAttribute( headerLines[i] );
|
||||
}
|
||||
}
|
||||
/*
|
||||
* parse body
|
||||
*/
|
||||
int beginLastPart = -1;
|
||||
if( multipart ) {
|
||||
byte boundaryArray[] = boundary.getBytes();
|
||||
for( int i = beginBody; i < end - 4; i++ ) {
|
||||
if( buffer.content[i] == '\r' &&
|
||||
buffer.content[i+1] == '\n' &&
|
||||
buffer.content[i+2] == '-' &&
|
||||
buffer.content[i+3] == '-' ) {
|
||||
/*
|
||||
* begin of possible boundary line
|
||||
*/
|
||||
int j = 0;
|
||||
for( ; j < boundaryArray.length && i + 4 + j < end; j++ )
|
||||
if( buffer.content[ i + 4 + j ] != boundaryArray[j] )
|
||||
break;
|
||||
if( j == boundaryArray.length ) {
|
||||
int k = i + 4 + j;
|
||||
if( k < end - 2 &&
|
||||
buffer.content[k] == '-' &&
|
||||
buffer.content[k+1] == '-' )
|
||||
k += 2;
|
||||
|
||||
if( k < end - 2 &&
|
||||
buffer.content[k] == '\r' &&
|
||||
buffer.content[k+1] == '\n' ) {
|
||||
|
||||
k += 2;
|
||||
|
||||
int endLastPart = i + 2;
|
||||
if( beginLastPart != -1 ) {
|
||||
MailPart newPart = new MailPart();
|
||||
newPart.parse( buffer, beginLastPart, endLastPart - beginLastPart );
|
||||
parts.add( newPart );
|
||||
}
|
||||
beginLastPart = k;
|
||||
}
|
||||
i = k;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( message ) {
|
||||
MailPart newPart = new MailPart();
|
||||
newPart.parse( buffer, beginBody, end );
|
||||
parts.add( newPart );
|
||||
}
|
||||
}
|
||||
public static String getFirstAttribute( String line )
|
||||
{
|
||||
String result = null;
|
||||
int i = line.indexOf( ": " );
|
||||
if( i != - 1 ) {
|
||||
int j = line.indexOf( ";", i + 2 );
|
||||
if( j == -1 )
|
||||
result = line.substring( i + 2 );
|
||||
else
|
||||
result = line.substring( i + 2, j );
|
||||
result = result.trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String getHeaderLineAttribute( String line, String attributeName )
|
||||
{
|
||||
String result = null;
|
||||
int h = 0;
|
||||
int l = attributeName.length();
|
||||
while( true ) {
|
||||
int i = line.indexOf( attributeName, h );
|
||||
// System.err.println( "i=" + i );
|
||||
if( i == -1 )
|
||||
break;
|
||||
h = i + l;
|
||||
int j = line.indexOf( "=", i + l );
|
||||
// System.err.println( "j=" + j );
|
||||
if( j != -1 ) {
|
||||
int k = line.indexOf( "\"", j + 1 );
|
||||
int m = line.indexOf( ";", j + 1 );
|
||||
// System.err.println( "k=" + k );
|
||||
if( k != -1 && ( m == -1 || k < m ) ) {
|
||||
/*
|
||||
* we found a " before a possible ;
|
||||
*
|
||||
* now we look for the 2nd (not quoted) "
|
||||
*/
|
||||
m = -1;
|
||||
int k2 = k + 1;
|
||||
while( true ) {
|
||||
m = line.indexOf( "\"", k2 );
|
||||
// System.err.println( "m=" + m + " '" + line.substring( m ) + "'" );
|
||||
if( m == -1 ) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* found one
|
||||
*/
|
||||
if( line.charAt( m - 1 ) != '\\' ) {
|
||||
/*
|
||||
* its not quoted, so it is the one we look for
|
||||
*/
|
||||
result = line.substring( k + 1, m );
|
||||
break;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* this is quoted, so we extract the quote and continue the search
|
||||
*/
|
||||
line = line.substring( 0, m - 1 ) + line.substring( m );
|
||||
// System.err.println( "quoting found, line='" + line + "'" );
|
||||
k2 = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( m != -1 ) {
|
||||
/*
|
||||
* no " found, but a ;
|
||||
*/
|
||||
result = line.substring( j + 1, m ).trim();
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* no " found and no ;
|
||||
*/
|
||||
result = line.substring( j + 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param mail
|
||||
*/
|
||||
public static void parse(Mail mail) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
214
apps/susimail/src/src/i2p/susi/webmail/RequestWrapper.java
Normal file
214
apps/susimail/src/src/i2p/susi/webmail/RequestWrapper.java
Normal file
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Created on Dec 8, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.mortbay.servlet.MultiPartRequest;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
*/
|
||||
public class RequestWrapper {
|
||||
|
||||
private HttpServletRequest httpRequest = null;
|
||||
private MultiPartRequest multiPartRequest = null;
|
||||
private Hashtable cache;
|
||||
private Hashtable cachedParameterNames;
|
||||
/**
|
||||
* do not call
|
||||
*/
|
||||
private RequestWrapper()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @param httpRequest
|
||||
*/
|
||||
public RequestWrapper(HttpServletRequest httpRequest) {
|
||||
cache = new Hashtable();
|
||||
this.httpRequest = httpRequest;
|
||||
String contentType = httpRequest.getContentType();
|
||||
if( contentType != null && contentType.toLowerCase().startsWith( "multipart/form-data" ) ) {
|
||||
try {
|
||||
multiPartRequest = new MultiPartRequest( httpRequest );
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
public HttpSession getSession(boolean b) {
|
||||
return httpRequest.getSession( b );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public String getParameter(String name ) {
|
||||
return getParameter( name, null );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public HttpSession getSession() {
|
||||
return httpRequest.getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Enumeration getParameterNames() {
|
||||
if( multiPartRequest != null ) {
|
||||
if( cachedParameterNames == null ) {
|
||||
cachedParameterNames = new Hashtable();
|
||||
String[] partNames = multiPartRequest.getPartNames();
|
||||
for( int i = 0; i < partNames.length; i++ )
|
||||
cachedParameterNames.put( partNames[i], new Integer( i ) );
|
||||
}
|
||||
return cachedParameterNames.keys();
|
||||
}
|
||||
else
|
||||
return httpRequest.getParameterNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getContentLength() {
|
||||
return httpRequest.getContentLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getContentType() {
|
||||
return httpRequest.getContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param partName
|
||||
* @return
|
||||
*/
|
||||
public String getContentType( String partName )
|
||||
{
|
||||
String result = null;
|
||||
if( multiPartRequest != null ) {
|
||||
Hashtable params = multiPartRequest.getParams( partName );
|
||||
for( Enumeration e = params.keys(); e.hasMoreElements(); ) {
|
||||
String key = (String)e.nextElement();
|
||||
if( key.toLowerCase().compareToIgnoreCase( "content-type") == 0 ) {
|
||||
String value = (String)params.get( key );
|
||||
int i = value.indexOf( ";" );
|
||||
if( i != -1 )
|
||||
result = value.substring( 0, i );
|
||||
else
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
public Object getAttribute(String string) {
|
||||
return httpRequest.getAttribute( string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param new_subject
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
public String getParameter( String name, String defaultValue )
|
||||
{
|
||||
String result = defaultValue;
|
||||
if( multiPartRequest != null ) {
|
||||
String str = (String)cache.get( name );
|
||||
if( str != null ) {
|
||||
result = str;
|
||||
}
|
||||
else {
|
||||
String[] partNames = multiPartRequest.getPartNames();
|
||||
for( int i = 0; i < partNames.length; i++ )
|
||||
if( partNames[i].compareToIgnoreCase( name ) == 0 ) {
|
||||
str = multiPartRequest.getString( partNames[i] );
|
||||
if( str != null ) {
|
||||
result = str;
|
||||
cache.put( name, result );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
String str = httpRequest.getParameter( name );
|
||||
if( str != null )
|
||||
result = str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param new_filename
|
||||
* @return
|
||||
*/
|
||||
public String getFilename(String partName )
|
||||
{
|
||||
String result = null;
|
||||
if( multiPartRequest != null ) {
|
||||
String str = multiPartRequest.getFilename( partName );
|
||||
if( str != null )
|
||||
result = str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param new_filename
|
||||
* @return
|
||||
*/
|
||||
public InputStream getInputStream(String partName )
|
||||
{
|
||||
InputStream result = null;
|
||||
if( multiPartRequest != null ) {
|
||||
result = multiPartRequest.getInputStream( partName );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
1703
apps/susimail/src/src/i2p/susi/webmail/WebMail.java
Normal file
1703
apps/susimail/src/src/i2p/susi/webmail/WebMail.java
Normal file
File diff suppressed because it is too large
Load Diff
237
apps/susimail/src/src/i2p/susi/webmail/encoding/Base64.java
Normal file
237
apps/susimail/src/src/i2p/susi/webmail/encoding/Base64.java
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Created on 09.11.2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.6 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringBufferInputStream;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class Base64 implements Encoding {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "base64";
|
||||
}
|
||||
/**
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException
|
||||
{
|
||||
try {
|
||||
return encode( new ByteArrayInputStream( in ) );
|
||||
}catch (IOException e) {
|
||||
throw new EncodingException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String str) throws EncodingException {
|
||||
try {
|
||||
return encode( new StringBufferInputStream( str ) );
|
||||
}catch (IOException e) {
|
||||
throw new EncodingException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
private String encode( InputStream in ) throws IOException, EncodingException
|
||||
{
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
|
||||
int buf[] = new int[3];
|
||||
int out[] = new int[4];
|
||||
int l = 0;
|
||||
while( true ) {
|
||||
int read = in.available();
|
||||
if( read == 0 )
|
||||
break;
|
||||
int i = 0;
|
||||
buf[0] = buf[1] = buf[2] = 0;
|
||||
while( read > 0 && i < 3 ) {
|
||||
buf[i] = in.read();
|
||||
if( buf[i] < 0 || buf[i] > 255 )
|
||||
throw new EncodingException( "Encoding supports only values 0..255 (" + buf[i] + ")" );
|
||||
i++;
|
||||
read--;
|
||||
}
|
||||
out[0] = encodeByte( ( buf[0] >> 2 ) & 63 );
|
||||
out[1] = encodeByte( ( ( buf[0] & 3 ) << 4 ) | ( ( buf[1] >> 4 ) & 15 ) );
|
||||
out[2] = encodeByte( ( ( buf[1] & 15 ) << 2 ) | ( ( buf[2] >> 6 ) & 3 ) );
|
||||
out[3] = encodeByte( buf[2] & 63 );
|
||||
strBuf.append( (char)out[0] );
|
||||
strBuf.append( (char)out[1] );
|
||||
if( i > 1 ) {
|
||||
strBuf.append( (char)out[2] );
|
||||
}
|
||||
else
|
||||
strBuf.append( "=" );
|
||||
if( i > 2 )
|
||||
strBuf.append( (char)out[3] );
|
||||
else
|
||||
strBuf.append( "=" );
|
||||
i += 3;
|
||||
l += 4;
|
||||
if( l >= 76 ) {
|
||||
strBuf.append( "\r\n" );
|
||||
l -= 76;
|
||||
}
|
||||
}
|
||||
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
private static int encodeByte(int b) {
|
||||
/*
|
||||
0 A 17 R 34 i 51 z
|
||||
1 B 18 S 35 j 52 0
|
||||
2 C 19 T 36 k 53 1
|
||||
3 D 20 U 37 l 54 2
|
||||
4 E 21 V 38 m 55 3
|
||||
5 F 22 W 39 n 56 4
|
||||
6 G 23 X 40 o 57 5
|
||||
7 H 24 Y 41 p 58 6
|
||||
8 I 25 Z 42 q 59 7
|
||||
9 J 26 a 43 r 60 8
|
||||
10 K 27 b 44 s 61 9
|
||||
11 L 28 c 45 t 62 +
|
||||
12 M 29 d 46 u 63 /
|
||||
13 N 30 e 47 v
|
||||
14 O 31 f 48 w (pad) =
|
||||
15 P 32 g 49 x
|
||||
16 Q 33 h 50 y
|
||||
*/
|
||||
if( b < 26 )
|
||||
b += 'A';
|
||||
else if( b < 52 )
|
||||
b += 'a' - 26;
|
||||
else if( b < 62 )
|
||||
b += '0' - 52;
|
||||
else if( b == 62 )
|
||||
b = '+';
|
||||
else
|
||||
b = '/';
|
||||
return b;
|
||||
}
|
||||
|
||||
private static byte decodeByte( byte b ) throws DecodingException {
|
||||
byte a = b;
|
||||
if( b >= 'A' && b <= 'Z' )
|
||||
b -= 'A';
|
||||
else if( b >= 'a' && b <= 'z' )
|
||||
b = (byte) (b - 'a' + 26);
|
||||
else if( b >= '0' && b <= '9' )
|
||||
b = (byte) (b - '0' + 52);
|
||||
else if( b == '+' )
|
||||
b = 62;
|
||||
else if( b == '/' )
|
||||
b = 63;
|
||||
else if( b == '=' )
|
||||
b = 0;
|
||||
else
|
||||
throw new DecodingException( "Decoding base64 failed (invalid data)." );
|
||||
// System.err.println( "decoded " + (char)a + " to " + b );
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode(String text) throws DecodingException {
|
||||
return text != null ? decode( text.getBytes() ) : null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#decode(byte[])
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in) throws DecodingException {
|
||||
return decode( in, 0, in.length );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#decode(byte[], int, int)
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in, int offset, int length) throws DecodingException {
|
||||
byte out[] = new byte[length * 3 / 4 + 1 ];
|
||||
int written = 0;
|
||||
while( length > 0 ) {
|
||||
if( in[offset] == '\r' || in[offset] == '\n' ||
|
||||
in[offset] == ' ' || in[offset] == '\t' ) {
|
||||
offset++;
|
||||
length--;
|
||||
continue;
|
||||
}
|
||||
if( length >= 4 ) {
|
||||
// System.out.println( "decode: " + (char)in[offset] + (char)in[offset+1]+ (char)in[offset+2]+ (char)in[offset+3] );
|
||||
byte b1 = decodeByte( in[offset++] );
|
||||
byte b2 = decodeByte( in[offset++] );
|
||||
out[written++] = (byte) (( b1 << 2 ) | ( ( b2 >> 4 ) & 3 ) );
|
||||
byte b3 = in[offset++];
|
||||
if( b3 != '=' ) {
|
||||
b3 = decodeByte( b3 );
|
||||
out[written++] = (byte)( ( ( b2 & 15 ) << 4 ) | ( ( b3 >> 2 ) & 15 ) );
|
||||
}
|
||||
byte b4 = in[offset++];
|
||||
if( b4 != '=' ) {
|
||||
b4 = decodeByte( b4 );
|
||||
out[written++] = (byte)( ( ( b3 & 3 ) << 6 ) | b4 & 63 );
|
||||
}
|
||||
length -= 4;
|
||||
}
|
||||
else {
|
||||
System.err.println( "" );
|
||||
throw new DecodingException( "Decoding base64 failed (trailing garbage)." );
|
||||
}
|
||||
}
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
readBuffer.content = out;
|
||||
readBuffer.offset = 0;
|
||||
readBuffer.length = written;
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#decode(i2p.susi23.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
return decode( in.content, in.offset, in.length );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Created on Nov 15, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class DecodingException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
DecodingException( String msg ) {
|
||||
super( msg );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Created on Nov 16, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class EightBit implements Encoding {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "8bit";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(byte[])
|
||||
*/
|
||||
public String encode(byte[] in) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String str) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[])
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in) throws DecodingException {
|
||||
return decode( in, 0, in.length );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[], int, int)
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in, int offset, int length)
|
||||
throws DecodingException {
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
readBuffer.content = in;
|
||||
readBuffer.offset = offset;
|
||||
readBuffer.length = length;
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode(String str) throws DecodingException {
|
||||
return decode( str.getBytes() );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(i2p.susi.webmail.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
return in;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* Interface to encode/decode content transfer encodings like quoted-printable, base64 etc.
|
||||
*
|
||||
* @author susi
|
||||
*/
|
||||
public interface Encoding {
|
||||
public String getName();
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException;
|
||||
/**
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public String encode( String str ) throws EncodingException;
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode( byte in[] ) throws DecodingException;
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode( byte in[], int offset, int length ) throws DecodingException;
|
||||
/**
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode( String str ) throws DecodingException;
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode( ReadBuffer in ) throws DecodingException;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Created on Nov 17, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class EncodingException extends Exception {
|
||||
/**
|
||||
* Comment for <code>serialVersionUID</code>
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
EncodingException( String msg )
|
||||
{
|
||||
super( msg );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.debug.Debug;
|
||||
import i2p.susi.util.Config;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Manager class to handle content transfer encodings.
|
||||
* @author susi
|
||||
*/
|
||||
public class EncodingFactory {
|
||||
|
||||
public static String CONFIG_ENCODING = "encodings";
|
||||
|
||||
private static Hashtable encodings = null;
|
||||
|
||||
static {
|
||||
encodings = new Hashtable();
|
||||
String list = Config.getProperty( CONFIG_ENCODING );
|
||||
if( list != null ) {
|
||||
String[] classNames = list.split( ";" );
|
||||
for( int i = 0; i < classNames.length; i++ ) {
|
||||
try {
|
||||
Class c = Class.forName( classNames[i] );
|
||||
Encoding e = (Encoding)c.newInstance();
|
||||
encodings.put( e.getName(), e );
|
||||
Debug.debug( Debug.DEBUG, "Registered " + e.getClass().getName() );
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.debug( Debug.ERROR, "Error loading class '" + classNames[i] + "', reason: " + e.getClass().getName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieve instance of an encoder for a supported encoding (or null).
|
||||
*
|
||||
* @param name name of encoding (e.g. quoted-printable)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Encoding getEncoding( String name )
|
||||
{
|
||||
return name != null && name.length() > 0 ? (Encoding)encodings.get( name ) : null;
|
||||
}
|
||||
/**
|
||||
* Returns list of available encodings;
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Set availableEncodings()
|
||||
{
|
||||
return encodings.keySet();
|
||||
}
|
||||
}
|
||||
89
apps/susimail/src/src/i2p/susi/webmail/encoding/HTML.java
Normal file
89
apps/susimail/src/src/i2p/susi/webmail/encoding/HTML.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Created on Nov 23, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
*/
|
||||
public class HTML implements Encoding {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "HTML";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(byte[])
|
||||
*/
|
||||
public String encode(byte[] in) throws EncodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String str) throws EncodingException
|
||||
{
|
||||
return str.replaceAll( "<", "<" ).replaceAll( ">", ">" ).replaceAll( "\r{0,1}\n", "<br>\r\n" );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[])
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in) throws DecodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[], int, int)
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in, int offset, int length)
|
||||
throws DecodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode(String str) throws DecodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(i2p.susi.webmail.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
303
apps/susimail/src/src/i2p/susi/webmail/encoding/HeaderLine.java
Normal file
303
apps/susimail/src/src/i2p/susi/webmail/encoding/HeaderLine.java
Normal file
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringBufferInputStream;
|
||||
|
||||
import i2p.susi.util.HexTable;
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class HeaderLine implements Encoding {
|
||||
public static final String NAME = "HEADERLINE";
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String text) throws EncodingException {
|
||||
try {
|
||||
return encode( new StringBufferInputStream( text ) );
|
||||
} catch (IOException e) {
|
||||
throw new EncodingException( "IOException occured." );
|
||||
}
|
||||
}
|
||||
private static final int BUFSIZE = 2;
|
||||
private String encode(InputStream in) throws IOException
|
||||
{
|
||||
StringBuffer out = new StringBuffer();
|
||||
int l = 0, buffered = 0, tmp[] = new int[BUFSIZE];
|
||||
boolean quoting = false;
|
||||
boolean quote = false;
|
||||
boolean linebreak = false;
|
||||
String quotedSequence = null;
|
||||
int rest = 0;
|
||||
while( true ) {
|
||||
rest = in.available();
|
||||
while( rest > 0 && buffered < BUFSIZE ) {
|
||||
tmp[buffered++] = in.read();
|
||||
rest--;
|
||||
}
|
||||
if( rest == 0 && buffered == 0 )
|
||||
break;
|
||||
|
||||
int c = tmp[0];
|
||||
buffered--;
|
||||
for( int j = 1; j < BUFSIZE; j++ )
|
||||
tmp[j-1] = tmp[j];
|
||||
|
||||
quote = true;
|
||||
if( c > 32 && c < 127 && c != 61 ) {
|
||||
quote = false;
|
||||
}
|
||||
else if( ( c == 32 || c == 9 ) ) {
|
||||
quote = false;
|
||||
if( rest == 0 && buffered == 1 )
|
||||
quote = true;
|
||||
if( buffered > 0 && ( tmp[0] == '\r' || tmp[0] == '\n' ) )
|
||||
quote = true;
|
||||
}
|
||||
else if( c == 13 && buffered > 0 && tmp[0] == 10 ) {
|
||||
quote = false;
|
||||
linebreak = true;
|
||||
buffered--;
|
||||
for( int j = 1; j < BUFSIZE; j++ )
|
||||
tmp[j-1] = tmp[j];
|
||||
}
|
||||
if( quote ) {
|
||||
if( ! quoting ) {
|
||||
quotedSequence = "=?iso-8859-1?Q?";
|
||||
quoting = true;
|
||||
}
|
||||
quotedSequence += HexTable.table[ c ];
|
||||
}
|
||||
else {
|
||||
if( quoting ) {
|
||||
quotedSequence += "?=";
|
||||
int sl = quotedSequence.length();
|
||||
if( l + sl > 76 ) {
|
||||
/*
|
||||
* wrap line
|
||||
*/
|
||||
out.append( "\r\n\t" );
|
||||
l = 0;
|
||||
}
|
||||
out.append( quotedSequence );
|
||||
l += sl;
|
||||
quoting = false;
|
||||
}
|
||||
if( linebreak ) {
|
||||
out.append( "\r\n" );
|
||||
linebreak = false;
|
||||
l = 0;
|
||||
}
|
||||
else {
|
||||
if( l > 76 ) {
|
||||
out.append( "\r\n\t" );
|
||||
l = 0;
|
||||
}
|
||||
out.append( (char)c );
|
||||
l++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( quoting ) {
|
||||
quotedSequence += "?=";
|
||||
int sl = quotedSequence.length();
|
||||
if( l + sl > 76 ) {
|
||||
/*
|
||||
* wrap line
|
||||
*/
|
||||
out.append( "\r\n\t" );
|
||||
l = 0;
|
||||
}
|
||||
out.append( quotedSequence );
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException {
|
||||
try {
|
||||
return encode( new ByteArrayInputStream( in ) );
|
||||
} catch (IOException e) {
|
||||
throw new EncodingException( "IOException occured." );
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode( byte in[] ) throws DecodingException {
|
||||
return decode( in, 0, in.length );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode( byte in[], int offset, int length ) throws DecodingException {
|
||||
byte[] out = new byte[length];
|
||||
int written = 0;
|
||||
int end = offset + length;
|
||||
if( end > in.length )
|
||||
throw new DecodingException( "Index out of bound." );
|
||||
boolean linebreak = false;
|
||||
boolean lastCharWasQuoted = false;
|
||||
while( length-- > 0 ) {
|
||||
byte c = in[offset++];
|
||||
if( c == '=' ) {
|
||||
if( length > 0 ) {
|
||||
if( in[offset] == '?' ) {
|
||||
// System.err.println( "=? found at " + ( offset -1 ) );
|
||||
int f2 = offset + 1;
|
||||
for( ; f2 < end && in[f2] != '?'; f2++ );
|
||||
if( f2 < end ) {
|
||||
/*
|
||||
* 2nd question mark found
|
||||
*/
|
||||
// System.err.println( "2nd ? found at " + f2 );
|
||||
int f3 = f2 + 1;
|
||||
for( ; f3 < end && in[f3] != '?'; f3++ );
|
||||
if( f3 < end ) {
|
||||
/*
|
||||
* 3rd question mark found
|
||||
*/
|
||||
// System.err.println( "3rd ? found at " + f3 );
|
||||
int f4 = f3 + 1;
|
||||
for( ; f4 < end && in[f4] != '?'; f4++ );
|
||||
if( f4 < end - 1 && in[f4+1] == '=' ) {
|
||||
/*
|
||||
* 4th question mark found, we are complete, so lets start
|
||||
*/
|
||||
String enc = ( in[f2+1] == 'Q' || in[f2+1] == 'q' ) ? "quoted-printable" : ( ( in[f2+1] == 'B' || in[f2+1] == 'b' ) ? "base64" : null );
|
||||
// System.err.println( "4th ? found at " + f4 + ", encoding=" + enc );
|
||||
if( enc != null ) {
|
||||
Encoding e = EncodingFactory.getEncoding( enc );
|
||||
if( e != null ) {
|
||||
// System.err.println( "encoder found" );
|
||||
ReadBuffer tmp = null;
|
||||
try {
|
||||
// System.err.println( "decode(" + (f3 + 1) + "," + ( f4 - f3 - 1 ) + ")" );
|
||||
tmp = e.decode( in, f3 + 1, f4 - f3 - 1 );
|
||||
for( int j = 0; j < tmp.length; j++ ) {
|
||||
byte d = tmp.content[ tmp.offset + j ];
|
||||
out[written++] = ( d == '_' ? 32 : d );
|
||||
}
|
||||
int distance = f4 + 2 - offset;
|
||||
offset += distance;
|
||||
length -= distance;
|
||||
lastCharWasQuoted = true;
|
||||
continue;
|
||||
}
|
||||
catch (Exception e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( c == '\r' ) {
|
||||
if( length > 0 && in[offset] == '\n' ) {
|
||||
/*
|
||||
* delay linebreak in case of long line
|
||||
*/
|
||||
linebreak = true;
|
||||
length--;
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if( linebreak ) {
|
||||
linebreak = false;
|
||||
if( c != ' ' && c != '\t' ) {
|
||||
/*
|
||||
* new line does not start with whitespace, so its not a new part of a
|
||||
* long line
|
||||
*/
|
||||
out[written++] = '\r';
|
||||
out[written++] = '\n';
|
||||
}
|
||||
else {
|
||||
if( !lastCharWasQuoted )
|
||||
out[written++] = ' ';
|
||||
/*
|
||||
* skip whitespace
|
||||
*/
|
||||
while( length > 0 && ( in[offset] == ' ' || in[offset] == '\t' ) ) {
|
||||
offset++;
|
||||
length--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* print out everything else literally
|
||||
*/
|
||||
out[written++] = c;
|
||||
lastCharWasQuoted = false;
|
||||
}
|
||||
if( linebreak ) {
|
||||
out[written++] = '\r';
|
||||
out[written++] = '\n';
|
||||
}
|
||||
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
readBuffer.content = out;
|
||||
readBuffer.offset = 0;
|
||||
readBuffer.length = written;
|
||||
|
||||
return readBuffer;
|
||||
}
|
||||
public ReadBuffer decode(String text) throws DecodingException {
|
||||
return text != null ? decode( text.getBytes() ) : null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(i2p.susi.webmail.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
return decode( in.content, in.offset, in.length );
|
||||
}
|
||||
public static void main( String[] args ) throws EncodingException {
|
||||
String text = "Subject: test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test \r\n" +
|
||||
"From: Sm<53>rebr<62>d <smoerebroed@mail.i2p>\r\n" +
|
||||
"To: <20><><EFBFBD><EFBFBD> <lalala@mail.i2p>\r\n";
|
||||
HeaderLine hl = new HeaderLine();
|
||||
System.out.println( hl.encode( text ) );
|
||||
System.out.println( hl.encode( "test <20><><EFBFBD>" ) );
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user