use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class IterativeSearchJob method newPeerToTry.
/**
* A new (floodfill) peer was discovered that may have the answer.
* @param peer may not actually be new
*/
void newPeerToTry(Hash peer) {
// don't ask ourselves or the target
if (peer.equals(getContext().routerHash()) || peer.equals(_key))
return;
if (getContext().banlist().isBanlistedForever(peer)) {
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": banlisted peer from DSRM " + peer);
return;
}
RouterInfo ri = getContext().netDb().lookupRouterInfoLocally(peer);
if (ri != null && !FloodfillNetworkDatabaseFacade.isFloodfill(ri)) {
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": non-ff peer from DSRM " + peer);
return;
}
synchronized (this) {
if (_failedPeers.contains(peer) || _unheardFrom.contains(peer) || _skippedPeers.contains(peer))
// already tried or skipped
return;
if (!_toTry.add(peer))
// already in the list
return;
}
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": new peer from DSRM: known? " + (ri != null) + ' ' + peer);
retry();
}
use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class FloodfillNetworkDatabaseFacade method getKnownRouterData.
public List<RouterInfo> getKnownRouterData() {
List<RouterInfo> rv = new ArrayList<RouterInfo>();
DataStore ds = getDataStore();
if (ds != null) {
for (DatabaseEntry o : ds.getEntries()) {
if (o.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO)
rv.add((RouterInfo) o);
}
}
return rv;
}
use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class FloodfillNetworkDatabaseFacade method flood.
/**
* Send to a subset of all floodfill peers.
* We do this to implement Kademlia within the floodfills, i.e.
* we flood to those closest to the key.
*/
public void flood(DatabaseEntry ds) {
Hash key = ds.getHash();
RouterKeyGenerator gen = _context.routerKeyGenerator();
Hash rkey = gen.getRoutingKey(key);
FloodfillPeerSelector sel = (FloodfillPeerSelector) getPeerSelector();
List<Hash> peers = sel.selectFloodfillParticipants(rkey, MAX_TO_FLOOD, getKBuckets());
// todo key cert skip?
long until = gen.getTimeTillMidnight();
if (until < NEXT_RKEY_LS_ADVANCE_TIME || (ds.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO && until < NEXT_RKEY_RI_ADVANCE_TIME)) {
// to avoid lookup faulures after midnight, also flood to some closest to the
// next routing key for a period of time before midnight.
Hash nkey = gen.getNextRoutingKey(key);
List<Hash> nextPeers = sel.selectFloodfillParticipants(nkey, NEXT_FLOOD_QTY, getKBuckets());
int i = 0;
for (Hash h : nextPeers) {
// But other implementations may not...
if (h.equals(key))
continue;
// todo key cert skip?
if (!peers.contains(h)) {
peers.add(h);
i++;
}
}
if (i > 0 && _log.shouldLog(Log.INFO))
_log.info("Flooding the entry for " + key + " to " + i + " more, just before midnight");
}
int flooded = 0;
for (int i = 0; i < peers.size(); i++) {
Hash peer = peers.get(i);
RouterInfo target = lookupRouterInfoLocally(peer);
if ((target == null) || (_context.banlist().isBanlisted(peer)))
continue;
// But other implementations may not...
if (ds.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO && peer.equals(key))
continue;
if (peer.equals(_context.routerHash()))
continue;
DatabaseStoreMessage msg = new DatabaseStoreMessage(_context);
msg.setEntry(ds);
OutNetMessage m = new OutNetMessage(_context, msg, _context.clock().now() + FLOOD_TIMEOUT, FLOOD_PRIORITY, target);
Job floodFail = new FloodFailedJob(_context, peer);
m.setOnFailedSendJob(floodFail);
// we want to give credit on success, even if we aren't sure,
// because otherwise no use noting failure
Job floodGood = new FloodSuccessJob(_context, peer);
m.setOnSendJob(floodGood);
_context.commSystem().processMessage(m);
flooded++;
if (_log.shouldLog(Log.INFO))
_log.info("Flooding the entry for " + key.toBase64() + " to " + peer.toBase64());
}
if (_log.shouldLog(Log.INFO))
_log.info("Flooded the data to " + flooded + " of " + peers.size() + " peers");
}
use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class TransportImpl method wasUnreachable.
/**
* Was the peer UNreachable (outbound only) the last time we tried it?
* This is NOT reset if the peer contacts us.
*/
public boolean wasUnreachable(Hash peer) {
long now = _context.clock().now();
synchronized (_wasUnreachableEntries) {
Long when = _wasUnreachableEntries.get(peer);
if (when != null) {
if (when.longValue() + WAS_UNREACHABLE_PERIOD < now) {
_unreachableEntries.remove(peer);
return false;
} else {
return true;
}
}
}
RouterInfo ri = _context.netDb().lookupRouterInfoLocally(peer);
if (ri == null)
return false;
return null == ri.getTargetAddress(this.getStyle());
}
use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class OutboundMessageFragments method add.
/**
* Add a new message to the active pool
*/
public void add(OutNetMessage msg) {
RouterInfo target = msg.getTarget();
if (target == null)
return;
PeerState peer = _transport.getPeerState(target.getIdentity().calculateHash());
try {
// will throw IAE if peer == null
OutboundMessageState state = new OutboundMessageState(_context, msg, peer);
peer.add(state);
add(peer);
} catch (IllegalArgumentException iae) {
_transport.failed(msg, "Peer disconnected quickly");
return;
}
}
Aggregations