propagate from branch 'i2p.i2p.zzz.test' (head dc817d70812b80e35a7c37eaa881e4b866435838)

to branch 'i2p.i2p' (head 5551e9b0487e14e901cd1081ce3e1ffd33c4a354)
This commit is contained in:
zzz
2009-05-26 15:02:52 +00:00
12 changed files with 77 additions and 62 deletions

View File

@ -8,7 +8,9 @@ package net.i2p.router.networkdb.kademlia;
*
*/
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.i2p.data.Hash;
import net.i2p.data.TunnelId;
@ -96,7 +98,13 @@ class ExploreJob extends SearchJob {
available = MAX_CLOSEST - msg.getDontIncludePeers().size();
if (available > 0) {
List peers = _peerSelector.selectNearestExplicit(getState().getTarget(), available, msg.getDontIncludePeers(), getFacade().getKBuckets());
// selectNearestExplicit adds our hash to the dontInclude set (3rd param) ...
// And we end up with MAX_CLOSEST+1 entries.
// We don't want our hash in the message's don't-include list though.
// We're just exploring, but this could give things away, and tie our exploratory tunnels to our router,
// so let's not put our hash in there.
Set dontInclude = new HashSet(msg.getDontIncludePeers());
List peers = _peerSelector.selectNearestExplicit(getState().getTarget(), available, dontInclude, getFacade().getKBuckets());
msg.getDontIncludePeers().addAll(peers);
}
@ -106,17 +114,6 @@ class ExploreJob extends SearchJob {
return msg;
}
/**
* We're looking for a router, so lets build the lookup message (no need to tunnel route either, so just have
* replies sent back to us directly). This uses the similar overrides as the other buildMessage above.
*
*/
@Override
protected DatabaseLookupMessage buildMessage(long expiration) {
return buildMessage(null, getContext().router().getRouterInfo().getIdentity().getHash(), expiration);
}
/** max # of concurrent searches */
@Override
protected int getBredth() { return EXPLORE_BREDTH; }

View File

@ -44,7 +44,7 @@ class FloodfillPeerSelector extends PeerSelector {
public List selectNearestExplicitThin(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets, boolean preferConnected) {
if (peersToIgnore == null)
peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash());
peersToIgnore.add(_context.routerHash());
FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters);
if (kbuckets == null) return new ArrayList();
kbuckets.getAll(matches);

View File

@ -61,7 +61,7 @@ public class PeerSelector {
if (peersToIgnore == null)
peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash());
peersToIgnore.add(_context.routerHash());
Set allHashes = kbuckets.getAll(peersToIgnore);
removeFailingPeers(allHashes);
Map diffMap = new HashMap(allHashes.size());
@ -94,7 +94,7 @@ public class PeerSelector {
public List selectNearestExplicitThin(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets) { // LINT -- Exporting non-public type through public API
if (peersToIgnore == null)
peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash());
peersToIgnore.add(_context.routerHash());
MatchSelectionCollector matches = new MatchSelectionCollector(key, peersToIgnore);
kbuckets.getAll(matches);
List rv = matches.get(maxNumRouters);

View File

@ -106,8 +106,10 @@ class PersistentDataStore extends TransientDataStore {
*/
@Override
public DataStructure remove(Hash key, boolean persist) {
if (persist)
if (persist) {
_writer.remove(key);
_context.jobQueue().addJob(new RemoveJob(key));
}
return super.remove(key);
}
@ -183,6 +185,10 @@ class PersistentDataStore extends TransientDataStore {
return _keys.get(key);
}
public void remove(Hash key) {
_keys.remove(key);
}
public void run() {
_quit = false;
Hash key = null;

View File

@ -452,6 +452,7 @@ class SearchJob extends JobImpl {
}
/** we're searching for a router, so we can just send direct */
/******* always send through the lease
protected void sendRouterSearch(RouterInfo router) {
int timeout = _facade.getPeerTimeout(router.getIdentity().getHash());
long expiration = getContext().clock().now() + timeout;
@ -471,6 +472,7 @@ class SearchJob extends JobImpl {
j.runJob();
//getContext().jobQueue().addJob(j);
}
**********/
/**
* what tunnel will we send the search out through?
@ -513,6 +515,7 @@ class SearchJob extends JobImpl {
* replies sent back to us directly)
*
*/
/******* always send through the lease
protected DatabaseLookupMessage buildMessage(long expiration) {
DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
msg.setSearchKey(_state.getTarget());
@ -522,6 +525,7 @@ class SearchJob extends JobImpl {
msg.setReplyTunnel(null);
return msg;
}
*********/
void replyFound(DatabaseSearchReplyMessage message, Hash peer) {
long duration = _state.replyFound(peer);

View File

@ -58,9 +58,10 @@ class ProfileOrganizerRenderer {
int failing = 0;
StringBuffer buf = new StringBuffer(16*1024);
buf.append("<h2>Peer Profiles</h2>\n");
buf.append("<p>Showing ").append(order.size()).append(" recent profiles, hiding ").append(peers.size()-order.size()).append(" older profiles</p>");
buf.append("<table border=\"1\">");
buf.append("<tr>");
buf.append("<td><b>Peer</b> (").append(order.size()).append(", hiding ").append(peers.size()-order.size()).append(")</td>");
buf.append("<td><b>Peer</b></td>");
buf.append("<td><b>Groups (Caps)</b></td>");
buf.append("<td><b>Speed</b></td>");
buf.append("<td><b>Capacity</b></td>");
@ -97,7 +98,7 @@ class ProfileOrganizerRenderer {
buf.append("<tr><td colspan=\"7\"><hr /></td></tr>\n");
prevTier = tier;
buf.append("<tr><td>");
buf.append("<tr><td nowrap>");
buf.append(_context.commSystem().renderPeerHTML(peer));
buf.append("</td><td>");
@ -179,7 +180,7 @@ class ProfileOrganizerRenderer {
PeerProfile prof = (PeerProfile)iter.next();
Hash peer = prof.getPeer();
buf.append("<tr><td>");
buf.append("<tr><td nowrap>");
buf.append(_context.commSystem().renderPeerHTML(peer));
buf.append("</td>");
RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);

View File

@ -128,6 +128,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
}
int getTransportCount() { return _manager.getTransportCount(); }
/** Send the message out */
public void processMessage(OutNetMessage msg) {
//GetBidsJob j = new GetBidsJob(_context, this, msg);
//j.runJob();
@ -436,6 +437,16 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
public String renderPeerHTML(Hash peer) {
String h = peer.toBase64().substring(0, 4);
StringBuffer buf = new StringBuffer(128);
String c = getCountry(peer);
if (c != null) {
buf.append("<img alt=\"").append(c.toUpperCase()).append("\" title=\"");
String n = _geoIP.fullName(c);
if (n != null)
buf.append(n);
else
buf.append(c);
buf.append("\" src=\"/flags.jsp?c=").append(c).append("\"> ");
}
buf.append("<tt><font size=\"+1\">");
boolean found = _context.netDb().lookupRouterInfoLocally(peer) != null;
if (found)
@ -444,16 +455,6 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
if (found)
buf.append("</a>");
buf.append("</font></tt>");
String c = getCountry(peer);
if (c != null) {
buf.append(" <img alt=\"").append(c.toUpperCase()).append("\" title=\"");
String n = _geoIP.fullName(c);
if (n != null)
buf.append(n);
else
buf.append(c);
buf.append("\" src=\"/flags.jsp?c=").append(c).append("\">");
}
return buf.toString();
}
}

View File

@ -265,7 +265,7 @@ public class NTCPTransport extends TransportImpl {
boolean established = isEstablished(toAddress.getIdentity());
if (established) { // should we check the queue size? nah, if its valid, use it
if (_log.shouldLog(Log.DEBUG))
_log.debug("fast bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64() + " as its already established");
_log.debug("fast bid when trying to send to " + peer.toBase64() + " as its already established");
return _fastBid;
}
RouterAddress addr = toAddress.getTargetAddress(STYLE);
@ -275,7 +275,7 @@ public class NTCPTransport extends TransportImpl {
_context.statManager().addRateData("ntcp.bidRejectedNoNTCPAddress", 1, 0);
//_context.shitlist().shitlistRouter(toAddress.getIdentity().calculateHash(), "No NTCP address", STYLE);
if (_log.shouldLog(Log.DEBUG))
_log.debug("no bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64() + " as they don't have an ntcp address");
_log.debug("no bid when trying to send to " + peer.toBase64() + " as they don't have an ntcp address");
return null;
}
NTCPAddress naddr = new NTCPAddress(addr);
@ -284,7 +284,7 @@ public class NTCPTransport extends TransportImpl {
markUnreachable(peer);
//_context.shitlist().shitlistRouter(toAddress.getIdentity().calculateHash(), "Invalid NTCP address", STYLE);
if (_log.shouldLog(Log.DEBUG))
_log.debug("no bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64() + " as they don't have a valid ntcp address");
_log.debug("no bid when trying to send to " + peer.toBase64() + " as they don't have a valid ntcp address");
return null;
}
if (!naddr.isPubliclyRoutable()) {
@ -292,14 +292,14 @@ public class NTCPTransport extends TransportImpl {
_context.statManager().addRateData("ntcp.bidRejectedLocalAddress", 1, 0);
markUnreachable(peer);
if (_log.shouldLog(Log.DEBUG))
_log.debug("no bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64() + " as they have a private ntcp address");
_log.debug("no bid when trying to send to " + peer.toBase64() + " as they have a private ntcp address");
return null;
}
}
if (!allowConnection()) {
if (_log.shouldLog(Log.WARN))
_log.warn("no bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64() + ", max connection limit reached");
_log.warn("no bid when trying to send to " + peer.toBase64() + ", max connection limit reached");
return _transientFail;
}
@ -307,7 +307,7 @@ public class NTCPTransport extends TransportImpl {
// return null; // dont talk to yourself
if (_log.shouldLog(Log.DEBUG))
_log.debug("slow bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64());
_log.debug("slow bid when trying to send to " + peer.toBase64());
return _slowBid;
}
@ -655,7 +655,7 @@ public class NTCPTransport extends TransportImpl {
buf.setLength(0);
for (Iterator iter = peers.iterator(); iter.hasNext(); ) {
NTCPConnection con = (NTCPConnection)iter.next();
buf.append("<tr><td>");
buf.append("<tr><td nowrap>");
buf.append(_context.commSystem().renderPeerHTML(con.getRemotePeer().calculateHash()));
//byte[] ip = getIP(con.getRemotePeer().calculateHash());
//if (ip != null)

View File

@ -1807,7 +1807,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
buf.append("<tr>");
buf.append("<td>");
buf.append("<td nowrap>");
buf.append(_context.commSystem().renderPeerHTML(peer.getRemotePeer()));
//byte ip[] = peer.getRemoteIP();
//if (ip != null)