* SSUDemo: Adapt for NTCP testing too

* RouterAddress and RouterInfo toString() cleanups; don't cache RI in _stringified
* NTCP: Fix publishing address when host specified but interface is not
* log tweaks
This commit is contained in:
zzz
2013-05-19 15:18:45 +00:00
parent 729282c0c4
commit 55880844a5
5 changed files with 46 additions and 27 deletions

View File

@@ -309,10 +309,10 @@ public class RouterAddress extends DataStructureImpl {
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("[RouterAddress: ");
buf.append("\n\tTransportStyle: ").append(_transportStyle);
buf.append("\n\tType: ").append(_transportStyle);
buf.append("\n\tCost: ").append(_cost);
//buf.append("\n\tExpiration: ").append(_expiration);
buf.append("\n\tOptions: #: ").append(_options.size());
buf.append("\n\tOptions (").append(_options.size()).append("):");
for (Map.Entry e : _options.entrySet()) {
String key = (String) e.getKey();
String val = (String) e.getValue();

View File

@@ -61,7 +61,7 @@ public class RouterInfo extends DatabaseEntry {
private final Properties _options;
private volatile boolean _validated;
private volatile boolean _isValid;
private volatile String _stringified;
//private volatile String _stringified;
private volatile byte _byteified[];
private volatile int _hashCode;
private volatile boolean _hashCodeInitialized;
@@ -612,30 +612,34 @@ public class RouterInfo extends DatabaseEntry {
@Override
public String toString() {
if (_stringified != null) return _stringified;
StringBuilder buf = new StringBuilder(5*1024);
//if (_stringified != null) return _stringified;
StringBuilder buf = new StringBuilder(1024);
buf.append("[RouterInfo: ");
buf.append("\n\tIdentity: ").append(_identity);
buf.append("\n\tSignature: ").append(_signature);
buf.append("\n\tPublished on: ").append(new Date(_published));
buf.append("\n\tAddresses: #: ").append(_addresses.size());
for (RouterAddress addr : _addresses) {
buf.append("\n\t\tAddress: ").append(addr);
}
Set<Hash> peers = getPeers();
buf.append("\n\tPeers: #: ").append(peers.size());
for (Hash hash : peers) {
buf.append("\n\tPublished: ").append(new Date(_published));
if (_peers != null) {
buf.append("\n\tPeers (").append(_peers.size()).append("):");
for (Hash hash : _peers) {
buf.append("\n\t\tPeer hash: ").append(hash);
}
buf.append("\n\tOptions: #: ").append(_options.size());
}
buf.append("\n\tOptions (").append(_options.size()).append("):");
for (Map.Entry e : _options.entrySet()) {
String key = (String) e.getKey();
String val = (String) e.getValue();
buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]");
}
if (!_addresses.isEmpty()) {
buf.append("\n\tAddresses (").append(_addresses.size()).append("):");
for (RouterAddress addr : _addresses) {
buf.append("\n\t").append(addr);
}
}
buf.append("]");
_stringified = buf.toString();
return _stringified;
String rv = buf.toString();
//_stringified = rv;
return rv;
}
/**

View File

@@ -261,8 +261,8 @@ class EstablishState {
// ok, we are onto the encrypted area
while (src.hasRemaining() && !_corrupt) {
if (_log.shouldLog(Log.DEBUG))
_log.debug(prefix()+"Encrypted bytes available (" + src.hasRemaining() + ")");
//if (_log.shouldLog(Log.DEBUG))
// _log.debug(prefix()+"Encrypted bytes available (" + src.hasRemaining() + ")");
while (_curEncryptedOffset < _curEncrypted.length && src.hasRemaining()) {
_curEncrypted[_curEncryptedOffset++] = src.get();
_received++;
@@ -299,8 +299,8 @@ class EstablishState {
} catch (IOException ioe) {
if (_log.shouldLog(Log.ERROR)) _log.error(prefix()+"Error writing to the baos?", ioe);
}
if (_log.shouldLog(Log.DEBUG))
_log.debug(prefix()+"subsequent block decrypted (" + _sz_aliceIdent_tsA_padding_aliceSig.size() + ")");
//if (_log.shouldLog(Log.DEBUG))
// _log.debug(prefix()+"subsequent block decrypted (" + _sz_aliceIdent_tsA_padding_aliceSig.size() + ")");
if (_sz_aliceIdent_tsA_padding_aliceSig.size() >= _sz_aliceIdent_tsA_padding_aliceSigSize) {
verifyInbound();

View File

@@ -490,8 +490,13 @@ public class NTCPTransport extends TransportImpl {
port = _ssuPort;
RouterAddress myAddress = bindAddress(port);
if (myAddress != null) {
// fixed interface, or bound to the specified host
replaceAddress(myAddress);
} else if (addr != null) {
// specified host, bound to wildcard
replaceAddress(addr);
} else if (port > 0) {
// all detected interfaces
for (InetAddress ia : getSavedLocalAddresses()) {
OrderedProperties props = new OrderedProperties();
props.setProperty(RouterAddress.PROP_HOST, ia.getHostAddress());

View File

@@ -27,15 +27,16 @@ public class SSUDemo {
RouterContext _us;
public static void main(String args[]) {
boolean testNTCP = args.length > 0 && args[0].equals("ntcp");
SSUDemo demo = new SSUDemo();
demo.run();
demo.run(testNTCP);
}
public SSUDemo() {}
public void run() {
public void run(boolean testNTCP) {
String cfgFile = "router.config";
Properties envProps = getEnv();
Properties envProps = getEnv(testNTCP);
Router r = new Router(cfgFile, envProps);
r.runRouter();
_us = r.getContext();
@@ -51,9 +52,12 @@ public class SSUDemo {
loadPeers();
}
private static Properties getEnv() {
private static Properties getEnv(boolean testNTCP) {
Properties envProps = new Properties();
// disable the NTCP transport and UPnP
// disable one of the transports and UPnP
if (testNTCP)
envProps.setProperty("i2np.udp.enable", "false");
else
envProps.setProperty("i2np.ntcp.enable", "false");
envProps.setProperty("i2np.upnp.enable", "false");
// we want SNTP synchronization for replay prevention
@@ -61,17 +65,23 @@ public class SSUDemo {
// allow 127.0.0.1/10.0.0.1/etc (useful for testing). If this is false,
// peers who say they're on an invalid IP are banlisted
envProps.setProperty("i2np.udp.allowLocal", "true");
envProps.setProperty("i2np.ntcp.allowLocal", "true");
// IPv6
envProps.setProperty("i2np.udp.ipv6", "enable");
envProps.setProperty("i2np.ntcp.ipv6", "enable");
// explicit IP+port. at least one router on the net has to have their IP+port
// set, since there has to be someone to detect one's IP off. most don't need
// to set these though
//envProps.setProperty("i2np.udp.host", "127.0.0.1");
envProps.setProperty("i2np.udp.host", "::1");
envProps.setProperty("i2np.ntcp.autoip", "false");
envProps.setProperty("i2np.ntcp.hostname", "::1");
// we don't have a context yet to use its random
String port = Integer.toString(44000 + (((int) System.currentTimeMillis()) & (16384 - 1)));
envProps.setProperty("i2np.udp.internalPort", port);
envProps.setProperty("i2np.udp.port", port);
envProps.setProperty("i2np.ntcp.autoport", "false");
envProps.setProperty("i2np.ntcp.port", port);
// disable I2CP, the netDb, peer testing/profile persistence, and tunnel
// creation/management
envProps.setProperty("i2p.dummyClientFacade", "true");