cleanups, javadoc

This commit is contained in:
zzz
2009-12-30 22:38:37 +00:00
parent cefc1f130d
commit 883b53de0a
7 changed files with 21 additions and 9 deletions

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 = 12;
public final static long BUILD = 13;
/** for example "-test" */
public final static String EXTRA = "";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;

View File

@@ -1,136 +0,0 @@
package net.i2p.router.networkdb.kademlia;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 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.
*
*/
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import net.i2p.crypto.KeyGenerator;
import net.i2p.data.Certificate;
import net.i2p.data.PrivateKey;
import net.i2p.data.PublicKey;
import net.i2p.data.RouterAddress;
import net.i2p.data.RouterIdentity;
import net.i2p.data.RouterInfo;
import net.i2p.data.SigningPrivateKey;
import net.i2p.data.SigningPublicKey;
import net.i2p.util.Clock;
public class RouterGenerator {
public static void main(String args[]) {
RouterGenerator gen = new RouterGenerator();
switch (args.length) {
case 0:
gen.createRouters(10000, "dummyRouters");
break;
case 1:
gen.createRouters(10000, args[0]);
break;
case 2:
try { gen.createRouters(Integer.parseInt(args[1]), args[0]); } catch (NumberFormatException nfe) { nfe.printStackTrace(); }
break;
}
}
private void createRouters(int numRouters, String outDir) {
File dir = new File(outDir);
if (!dir.exists())
dir.mkdirs();
int numSuccess = 0;
for (int i = 1; numSuccess < numRouters; i++) {
RouterInfo ri = createRouterInfo(i);
String hash = ri.getIdentity().getHash().toBase64();
if (!hash.startsWith("fwI")) {
System.out.print(".");
if ( (i % 100) == 0) System.out.println();
continue;
}
System.out.println("Router " + i + " created: \t" + hash);
numSuccess++;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(dir, "routerInfo-" + hash + ".dat"));
ri.writeBytes(fos);
} catch (Exception e) {
System.err.println("Error writing router - " + e.getMessage());
e.printStackTrace();
return;
} finally {
if (fos != null) try { fos.close(); } catch (Exception e) {}
}
}
}
private static PublicKey pubkey = null;
private static PrivateKey privkey = null;
private static SigningPublicKey signingPubKey = null;
private static SigningPrivateKey signingPrivKey = null;
private static Object keypair[] = KeyGenerator.getInstance().generatePKIKeypair();
private static Object signingKeypair[] = KeyGenerator.getInstance().generateSigningKeypair();
static {
pubkey = (PublicKey)keypair[0];
privkey = (PrivateKey)keypair[1];
signingPubKey = (SigningPublicKey)signingKeypair[0];
signingPrivKey = (SigningPrivateKey)signingKeypair[1];
}
static RouterInfo createRouterInfo(int num) {
RouterInfo info = new RouterInfo();
try {
info.setAddresses(createAddresses(num));
info.setOptions(new Properties());
info.setPeers(new HashSet());
info.setPublished(Clock.getInstance().now());
RouterIdentity ident = new RouterIdentity();
BigInteger bv = new BigInteger(""+num);
Certificate cert = new Certificate(Certificate.CERTIFICATE_TYPE_NULL, bv.toByteArray());
ident.setCertificate(cert);
ident.setPublicKey(pubkey);
ident.setSigningPublicKey(signingPubKey);
info.setIdentity(ident);
info.sign(signingPrivKey);
} catch (Exception e) {
System.err.println("Error building router " + num + ": " + e.getMessage());
e.printStackTrace();
}
return info;
}
static Set createAddresses(int num) {
Set addresses = new HashSet();
RouterAddress addr = createTCPAddress(num);
if (addr != null)
addresses.add(addr);
return addresses;
}
private static RouterAddress createTCPAddress(int num) {
RouterAddress addr = new RouterAddress();
addr.setCost(10);
addr.setExpiration(null);
Properties props = new Properties();
String name = "blah.random.host.org";
String port = "" + (1024+num);
props.setProperty("host", name);
props.setProperty("port", port);
addr.setOptions(props);
addr.setTransportStyle("TCP");
return addr;
}
}

View File

@@ -532,7 +532,7 @@ class SearchJob extends JobImpl {
void replyFound(DatabaseSearchReplyMessage message, Hash peer) {
long duration = _state.replyFound(peer);
// this processing can take a while, so split 'er up
getContext().jobQueue().addJob(new SearchReplyJob(getContext(), this, (DatabaseSearchReplyMessage)message, peer, duration));
getContext().jobQueue().addJob(new SearchReplyJob(getContext(), this, message, peer, duration));
}
/**

View File

@@ -28,13 +28,13 @@ public class TunnelHistory {
private RateStat _failRate;
private String _statGroup;
/** probabalistic tunnel rejection due to a flood of requests */
/** probabalistic tunnel rejection due to a flood of requests - essentially unused */
public static final int TUNNEL_REJECT_PROBABALISTIC_REJECT = 10;
/** tunnel rejection due to temporary cpu/job/tunnel overload */
/** tunnel rejection due to temporary cpu/job/tunnel overload - essentially unused */
public static final int TUNNEL_REJECT_TRANSIENT_OVERLOAD = 20;
/** tunnel rejection due to excess bandwidth usage */
public static final int TUNNEL_REJECT_BANDWIDTH = 30;
/** tunnel rejection due to system failure */
/** tunnel rejection due to system failure - essentially unused */
public static final int TUNNEL_REJECT_CRIT = 50;
public TunnelHistory(RouterContext context, String statGroup) {
@@ -100,8 +100,10 @@ public class TunnelHistory {
}
}
// Define this rate as the probability it really failed
// @param pct = probability * 100
/**
* Define this rate as the probability it really failed
* @param pct = probability * 100
*/
public void incrementFailed(int pct) {
_lifetimeFailed++;
_failRate.addData(pct, 1);
@@ -150,7 +152,7 @@ public class TunnelHistory {
_failRate.store(out, "tunnelHistory.failRate");
}
private void add(StringBuilder buf, String name, long val, String description) {
private static void add(StringBuilder buf, String name, long val, String description) {
buf.append("# ").append(name.toUpperCase()).append(NL).append("# ").append(description).append(NL);
buf.append("tunnels.").append(name).append('=').append(val).append(NL).append(NL);
}

View File

@@ -1170,6 +1170,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_introducersSelectedOn = _context.clock().now();
introducersIncluded = true;
} else {
// maybe we should fail to publish an address at all in this case?
if (_log.shouldLog(Log.WARN))
_log.warn("Need introducers but we don't know any");
}