propagate from branch 'i2p.i2p' (head 36bd43007b45f4b59b1dc14a2cb02b06c9e7fa84)

to branch 'i2p.i2p.zzz.dhtsnark' (head 2960be09b366cb629d254d72f0654ff9ecc0133b)
This commit is contained in:
zzz
2010-12-31 16:28:53 +00:00
29 changed files with 1162 additions and 898 deletions

View File

@ -107,6 +107,17 @@ public class I2PSnarkServlet extends Default {
return _resourceBase.addPath(pathInContext);
}
/**
* Tell the browser to cache the icons
* @since 0.8.3
*/
@Override
public void handleGet(HttpServletRequest request, HttpServletResponse response, String pathInContext, Resource resource, boolean endsWithSlash) throws ServletException, IOException {
if (resource.getName().startsWith("jar:file:"))
response.setHeader("Cache-Control", "max-age=86400"); // cache for a day
super.handleGet(request, response, pathInContext, resource, endsWithSlash);
}
/**
* Some parts modified from:
* <pre>

View File

@ -9,7 +9,7 @@ msgstr ""
"Project-Id-Version: I2P i2psnark\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-12-19 03:16+0000\n"
"PO-Revision-Date: 2010-12-28 00:36+0100\n"
"PO-Revision-Date: 2010-12-31 01:09+0100\n"
"Last-Translator: mixxy <m1xxy@mail.i2p>\n"
"Language-Team: foo <foo@bar>\n"
"MIME-Version: 1.0\n"
@ -453,7 +453,7 @@ msgstr "completo"
#: ../java/src/org/klomp/snark/web/I2PSnarkServlet.java:787
#: ../java/src/org/klomp/snark/web/I2PSnarkServlet.java:792
msgid "OK"
msgstr "Bien"
msgstr "bien"
#: ../java/src/org/klomp/snark/web/I2PSnarkServlet.java:796
#: ../java/src/org/klomp/snark/web/I2PSnarkServlet.java:801

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ msgstr ""
"Project-Id-Version: I2P i2psnark\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-12-19 03:16+0000\n"
"PO-Revision-Date: 2010-12-29 16:29+0100\n"
"PO-Revision-Date: 2010-12-31 01:09+0100\n"
"Last-Translator: mixxy <m1xxy@mail.i2p>\n"
"Language-Team: foo <foo@bar>\n"
"MIME-Version: 1.0\n"
@ -453,7 +453,7 @@ msgstr "completo"
#: ../java/src/org/klomp/snark/web/I2PSnarkServlet.java:787
#: ../java/src/org/klomp/snark/web/I2PSnarkServlet.java:792
msgid "OK"
msgstr "Bem"
msgstr "bem"
#: ../java/src/org/klomp/snark/web/I2PSnarkServlet.java:796
#: ../java/src/org/klomp/snark/web/I2PSnarkServlet.java:801

View File

@ -22,6 +22,7 @@ import net.i2p.util.ShellCommand;
import org.mortbay.http.DigestAuthenticator;
import org.mortbay.http.HashUserRealm;
import org.mortbay.http.NCSARequestLog;
import org.mortbay.http.SecurityConstraint;
import org.mortbay.http.SslListener;
import org.mortbay.http.handler.SecurityHandler;
@ -141,6 +142,18 @@ public class RouterConsoleRunner {
// so Jetty can find WebAppConfiguration
System.setProperty("jetty.class.path", I2PAppContext.getGlobalContext().getBaseDir() + "/lib/routerconsole.jar");
_server = new Server();
String log = I2PAppContext.getGlobalContext().getProperty("routerconsole.log");
if (log != null) {
File logFile = new File(log);
if (!logFile.isAbsolute())
logFile = new File(I2PAppContext.getGlobalContext().getLogDir(), "logs/" + log);
try {
_server.setRequestLog(new NCSARequestLog(logFile.getAbsolutePath()));
} catch (IOException ioe) {
System.err.println("ERROR: Unable to create Jetty log: " + ioe);
}
}
boolean rewrite = false;
Properties props = webAppProperties();
if (props.isEmpty()) {

View File

@ -174,7 +174,7 @@ details on other applications available, as well as their licenses, please see t
client applications can be found on our <a href="http://www.i2p2.i2p/download">download page</a>.
.</p>
<h2>Release history</h2>
<h2>Change Log</h2>
<jsp:useBean class="net.i2p.router.web.ContentHelper" id="contenthelper" scope="request" />
<% java.io.File fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getBaseDir(), "history.txt"); %>
<jsp:setProperty name="contenthelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
@ -182,6 +182,5 @@ client applications can be found on our <a href="http://www.i2p2.i2p/download">d
<jsp:setProperty name="contenthelper" property="startAtBeginning" value="true" />
<jsp:getProperty name="contenthelper" property="textContent" />
<p>A more complete list of changes can be found
in the history.txt file in your i2p directory.
<p><a href="/history.txt">View the full change log</a>
</p><hr></div></body></html>

View File

@ -8,5 +8,9 @@
*/
response.setContentType("text/plain");
String base = net.i2p.I2PAppContext.getGlobalContext().getBaseDir().getAbsolutePath();
net.i2p.util.FileUtil.readFile("history.txt", base, response.getOutputStream());
try {
net.i2p.util.FileUtil.readFile("history.txt", base, response.getOutputStream());
} catch (java.io.IOException ioe) {
response.sendError(403, ioe.toString());
}
%>

View File

@ -44,5 +44,9 @@ if (themePath != null)
else
base = net.i2p.I2PAppContext.getGlobalContext().getBaseDir().getAbsolutePath() +
java.io.File.separatorChar + "docs";
net.i2p.util.FileUtil.readFile(uri, base, response.getOutputStream());
try {
net.i2p.util.FileUtil.readFile(uri, base, response.getOutputStream());
} catch (java.io.IOException ioe) {
response.sendError(403, ioe.toString());
}
%>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -274,7 +274,7 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 implements I2PSession {
_demultiplexer.messageAvailable(I2PSessionMuxedImpl.this,
msg.id, msg.size, msg.proto, msg.fromPort, msg.toPort);
} catch (Exception e) {
_log.error("Error notifying app of message availability");
_log.error("Error notifying app of message availability", e);
}
}
}

View File

@ -37,9 +37,9 @@ public final class I2PDatagramDissector {
private Hash rxHash = null;
private Signature rxSign = new Signature();
private Signature rxSign;
private Destination rxDest = new Destination();
private Destination rxDest;
private byte[] rxPayload = new byte[DGRAM_BUFSIZE];
@ -68,6 +68,9 @@ public final class I2PDatagramDissector {
this.valid = false;
try {
rxDest = new Destination();
rxSign = new Signature();
// read destination
rxDest.readBytes(dgStream);
@ -153,6 +156,8 @@ public final class I2PDatagramDissector {
* @return The Destination of the I2P repliable datagram sender
*/
public Destination extractSender() {
if (this.rxDest == null)
return null;
Destination retDest = new Destination();
try {
retDest.fromByteArray(this.rxDest.toByteArray());
@ -184,6 +189,10 @@ public final class I2PDatagramDissector {
if(this.valid)
return;
if (rxSign == null || rxSign.getData() == null ||
rxDest == null || rxDest.getSigningPublicKey() == null)
throw new I2PInvalidDatagramException("Datagram not yet read");
// now validate
if (!this.dsaEng.verifySignature(rxSign, rxHash.getData(), rxDest.getSigningPublicKey()))
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");

View File

@ -54,7 +54,7 @@ class LookupDest {
/** @param h 32 byte hash */
static Destination lookupHash(I2PAppContext ctx, byte[] h) {
Hash key = new Hash(h);
Hash key = Hash.create(h);
Destination rv = null;
try {
I2PClient client = new I2PSimpleClient();

View File

@ -43,6 +43,24 @@ public class Certificate extends DataStructureImpl {
/** Contains multiple certs */
public final static int CERTIFICATE_TYPE_MULTIPLE = 4;
/**
* Pull from cache or return new
* @throws AIOOBE if not enough bytes
* @since 0.8.3
*/
public static Certificate create(byte[] data, int off) {
int type = data[off] & 0xff;
int length = (int) DataHelper.fromLong(data, off + 1, 2);
if (type == 0 && length == 0)
return NULL_CERT;
// from here down roughly the same as readBytes() below
if (length == 0)
return new Certificate(type, null);
byte[] payload = new byte[length];
System.arraycopy(data, off = 3, payload, 0, length);
return new Certificate(type, payload);
}
/**
* If null cert, return immutable static instance, else create new
* @since 0.8.3

View File

@ -49,20 +49,14 @@ public class Destination extends KeysAndCert {
throw new DataFormatException("Not enough data (len=" + source.length + " off=" + offset + ")");
int cur = offset;
_publicKey = new PublicKey();
byte buf[] = new byte[PublicKey.KEYSIZE_BYTES];
System.arraycopy(source, cur, buf, 0, PublicKey.KEYSIZE_BYTES);
_publicKey.setData(buf);
_publicKey = PublicKey.create(source, cur);
cur += PublicKey.KEYSIZE_BYTES;
_signingKey = new SigningPublicKey();
buf = new byte[SigningPublicKey.KEYSIZE_BYTES];
System.arraycopy(source, cur, buf, 0, SigningPublicKey.KEYSIZE_BYTES);
_signingKey.setData(buf);
_signingKey = SigningPublicKey.create(source, cur);
cur += SigningPublicKey.KEYSIZE_BYTES;
_certificate = new Certificate();
cur += _certificate.readBytes(source, cur);
_certificate = Certificate.create(source, cur);
cur += _certificate.size();
return cur - offset;
}

View File

@ -25,6 +25,15 @@ public class PublicKey extends SimpleDataStructure {
private static final SDSCache<PublicKey> _cache = new SDSCache(PublicKey.class, KEYSIZE_BYTES, CACHE_SIZE);
/**
* Pull from cache or return new
* @throws AIOOBE if not enough bytes
* @since 0.8.3
*/
public static PublicKey create(byte[] data, int off) {
return _cache.get(data, off);
}
/**
* Pull from cache or return new
* @since 0.8.3

View File

@ -26,6 +26,15 @@ public class SigningPublicKey extends SimpleDataStructure {
private static final SDSCache<SigningPublicKey> _cache = new SDSCache(SigningPublicKey.class, KEYSIZE_BYTES, CACHE_SIZE);
/**
* Pull from cache or return new
* @throws AIOOBE if not enough bytes
* @since 0.8.3
*/
public static SigningPublicKey create(byte[] data, int off) {
return _cache.get(data, off);
}
/**
* Pull from cache or return new
* @since 0.8.3

View File

@ -60,9 +60,7 @@ public class DestReplyMessage extends I2CPMessageImpl {
} else {
try {
if (size == Hash.HASH_LENGTH) {
Hash h = new Hash();
h.readBytes(in);
_hash = h;
_hash = Hash.create(in);
} else {
Destination d = new Destination();
d.readBytes(in);

View File

@ -50,7 +50,8 @@ public abstract class Addresses {
/**
* @return a sorted array of all addresses
* @param whether to exclude IPV6 and local
* @param includeLocal whether to include local
* @param includeIPv6 whether to include IPV6
* @return an array of all addresses
* @since 0.8.3
*/

View File

@ -1,3 +1,17 @@
2010-12-31 zzz
* Console:
- Make themes and history.txt return 403 on error,
not 500, to avoid the new error page
- Add logging, enable with routerconsole.log=filename
- Link to full history.txt on help page
* Data Structures: Caching cleanups
* Datagram Dissector: Fix RuntimeException caused by reuse,
preventing iMule from connecting on UDP
(thanks devzero)
* i2psnark:
- Send cache directive for in-war icons
* OCMOSJ: Refactor cache keys for efficiency
2010-12-30 zzz
* Data Structures:
- New SDSCache for SimpleDataStructures

View File

@ -53,7 +53,7 @@
<h2>Willst Du Deine eigene Eepseite?</h2>
<p>Das I2P-Paket beinhaltet Software, die es Dir erm&ouml;glicht, Deine eigene Eepseite zu betreiben
<p>Das I2P-Paket beinhaltet Software, die es Dir erm&ouml;glicht, Deine eigene Eepseite zu betreiben
: Eine
<a href="http://jetty.mortbay.org/">Jetty</a>-Instanz horcht auf
<a href="http://127.0.0.1:7658/">http://127.0.0.1:7658/</a>. Platziere einfach

View File

@ -59,7 +59,7 @@ body {
font-weight: bold;
font-size: 11pt;
color: #fb0;
background: #eeb url('images/snarknav_lowlight.png') repeat-x scroll center center;
background: #eeb;
}
.snarkRefresh:last-child {

View File

@ -305,7 +305,7 @@ public class Blocklist {
if (end1 - start1 == 44 && buf.substring(start1).indexOf(".") < 0) {
byte b[] = Base64.decode(buf.substring(start1));
if (b != null)
return new Entry(comment, new Hash(b), null, null);
return new Entry(comment, Hash.create(b), null, null);
}
index = buf.indexOf("-", start1);
if (index >= 0) {

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 5;
public final static long BUILD = 6;
/** for example "-test" */
public final static String EXTRA = "";

View File

@ -39,8 +39,10 @@ public class ClientManagerFacadeImpl extends ClientManagerFacade implements Inte
private final static Log _log = new Log(ClientManagerFacadeImpl.class);
private ClientManager _manager;
private RouterContext _context;
/** note that this is different than the property the client side uses, i2cp.tcp.port */
public final static String PROP_CLIENT_PORT = "i2cp.port";
public final static int DEFAULT_PORT = 7654;
/** note that this is different than the property the client side uses, i2cp.tcp.host */
public final static String PROP_CLIENT_HOST = "i2cp.hostname";
public final static String DEFAULT_HOST = "127.0.0.1";

View File

@ -216,7 +216,8 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
*
* Key the cache on the source+dest pair.
*/
private final static HashMap<String, LeaseSet> _leaseSetCache = new HashMap();
private final static HashMap<HashPair, LeaseSet> _leaseSetCache = new HashMap();
private LeaseSet getReplyLeaseSet(boolean force) {
LeaseSet newLS = getContext().netDb().lookupLeaseSetLocally(_from.calculateHash());
if (newLS == null)
@ -316,7 +317,8 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
* lease).
*
*/
private final static HashMap<String, Lease> _leaseCache = new HashMap();
private final static HashMap<HashPair, Lease> _leaseCache = new HashMap();
private boolean getNextLease() {
_leaseSet = getContext().netDb().lookupLeaseSetLocally(_to.calculateHash());
if (_leaseSet == null) {
@ -456,7 +458,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
* before upper layers like streaming lib fail, even for low-bandwidth
* connections like IRC.
*/
private final static HashMap<String, Long> _lastReplyRequestCache = new HashMap();
private final static HashMap<HashPair, Long> _lastReplyRequestCache = new HashMap();
/**
* Send the message to the specified tunnel by creating a new garlic message containing
@ -628,23 +630,46 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
*/
/**
* String used to cache things with based on source + dest
* Put the dest first to make string matching faster
* Key used to cache things with based on source + dest
*/
private String _hashPair;
private String hashPair() {
private HashPair _hashPair;
private HashPair hashPair() {
if (_hashPair == null)
_hashPair = _to.calculateHash().toBase64() + _from.calculateHash().toBase64();
_hashPair = new HashPair(_from.calculateHash(), _to.calculateHash());
return _hashPair;
}
/**
* Key used to cache things with based on source + dest
* @since 0.8.3
*/
private static class HashPair {
private final Hash sh, dh;
public HashPair(Hash s, Hash d) {
sh = s;
dh = d;
}
public int hashCode() {
return sh.hashCode() + dh.hashCode();
}
public boolean equals(Object o) {
if (o == null || !(o instanceof HashPair))
return false;
HashPair hp = (HashPair) o;
return sh.equals(hp.sh) && dh.equals(hp.dh);
}
}
/**
* This is a little sneaky, but get the _from back out of the "opaque" hash key
* (needed for cleanTunnelCache)
* 44 = 32 * 4 / 3
*/
private static Hash sourceFromHashPair(String s) {
return new Hash(Base64.decode(s.substring(44, 88)));
private static Hash sourceFromHashPair(HashPair s) {
return s.sh;
}
/**
@ -655,7 +680,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
* But it's a start.
*/
private void clearCaches() {
String key = hashPair();
HashPair key = hashPair();
if (_inTunnel != null) { // if we wanted an ack, we sent our lease too
synchronized(_leaseSetCache) {
_leaseSetCache.remove(key);
@ -681,42 +706,38 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
}
/**
* Clean out old leaseSets from a set.
* Clean out old leaseSets
* Caller must synchronize on tc.
*/
private static void cleanLeaseSetCache(RouterContext ctx, HashMap tc) {
private static void cleanLeaseSetCache(RouterContext ctx, Map<HashPair, LeaseSet> tc) {
long now = ctx.clock().now();
for (Iterator iter = tc.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry)iter.next();
String k = (String) entry.getKey();
LeaseSet l = (LeaseSet) entry.getValue();
for (Iterator<LeaseSet> iter = tc.values().iterator(); iter.hasNext(); ) {
LeaseSet l = iter.next();
if (l.getEarliestLeaseDate() < now)
iter.remove();
}
}
/**
* Clean out old leases from a set.
* Clean out old leases
* Caller must synchronize on tc.
*/
private static void cleanLeaseCache(HashMap tc) {
for (Iterator iter = tc.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry)iter.next();
String k = (String) entry.getKey();
Lease l = (Lease) entry.getValue();
private static void cleanLeaseCache(Map<HashPair, Lease> tc) {
for (Iterator<Lease> iter = tc.values().iterator(); iter.hasNext(); ) {
Lease l = iter.next();
if (l.isExpired(Router.CLOCK_FUDGE_FACTOR))
iter.remove();
}
}
/**
* Clean out old tunnels from a set.
* Clean out old tunnels
* Caller must synchronize on tc.
*/
private static void cleanTunnelCache(RouterContext ctx, HashMap tc) {
private static void cleanTunnelCache(RouterContext ctx, Map<HashPair, TunnelInfo> tc) {
for (Iterator iter = tc.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry)iter.next();
String k = (String) entry.getKey();
HashPair k = (HashPair) entry.getKey();
TunnelInfo tunnel = (TunnelInfo) entry.getValue();
if (!ctx.tunnelManager().isValidTunnel(sourceFromHashPair(k), tunnel))
iter.remove();
@ -727,7 +748,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
* Clean out old reply times
* Caller must synchronize on tc.
*/
private static void cleanReplyCache(RouterContext ctx, HashMap tc) {
private static void cleanReplyCache(RouterContext ctx, Map<HashPair, Long> tc) {
long now = ctx.clock().now();
for (Iterator iter = tc.values().iterator(); iter.hasNext(); ) {
Long l = (Long) iter.next();
@ -766,8 +787,10 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
* Key the caches on the source+dest pair.
*
*/
private static final HashMap<String, TunnelInfo> _tunnelCache = new HashMap();
private static HashMap<String, TunnelInfo> _backloggedTunnelCache = new HashMap();
private static final HashMap<HashPair, TunnelInfo> _tunnelCache = new HashMap();
private static HashMap<HashPair, TunnelInfo> _backloggedTunnelCache = new HashMap();
private TunnelInfo selectOutboundTunnel(Destination to) {
TunnelInfo tunnel;
long now = getContext().clock().now();

View File

@ -28,7 +28,7 @@ import net.i2p.util.Log;
*/
class LocalHash extends Hash {
private final static Log _log = new Log(LocalHash.class);
private /* FIXME final FIXME */ Map _xorCache;
private /* FIXME final FIXME */ Map<Hash, byte[]> _xorCache;
private static final int MAX_CACHED_XOR = 1024;
@ -65,7 +65,7 @@ class LocalHash extends Hash {
public byte[] cachedXor(Hash key) throws IllegalStateException {
if (_xorCache == null)
throw new IllegalStateException("To use the cache, you must first prepare it");
byte[] distance = (byte[])_xorCache.get(key);
byte[] distance = _xorCache.get(key);
if (distance == null) {
// not cached, lets cache it
@ -83,7 +83,7 @@ class LocalHash extends Hash {
_xorCache.remove(iter.next());
}
distance = DataHelper.xor(key.getData(), getData());
_xorCache.put(key, (Object) distance);
_xorCache.put(key, distance);
cached = _xorCache.size();
}
if (_log.shouldLog(Log.DEBUG)) {

View File

@ -18,6 +18,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentHashMap;
import net.i2p.data.Base64;
import net.i2p.data.DataFormatException;
import net.i2p.data.DataStructure;
import net.i2p.data.Hash;
@ -481,8 +482,12 @@ class PersistentDataStore extends TransientDataStore {
try {
String key = filename.substring(prefix.length());
key = key.substring(0, key.length() - suffix.length());
Hash h = new Hash();
h.fromBase64(key);
//Hash h = new Hash();
//h.fromBase64(key);
byte[] b = Base64.decode(key);
if (b == null)
return null;
Hash h = Hash.create(b);
return h;
} catch (Exception e) {
// static

View File

@ -937,11 +937,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
RouterAddress addr = _externalAddress;
UDPAddress ua = new UDPAddress(addr);
int valid = 0;
Hash peerHash = new Hash();
for (int i = 0; i < ua.getIntroducerCount(); i++) {
// warning: this is only valid as long as we use the ident hash as their key.
peerHash.setData(ua.getIntroducerKey(i));
PeerState peer = getPeerState(peerHash);
PeerState peer = getPeerState(Hash.create(ua.getIntroducerKey(i)));
if (peer != null)
valid++;
}