use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class KademliaNetworkDatabaseFacade method processStoreFailure.
/**
* If the validate fails, call this
* to determine if it was because of unsupported crypto.
*
* If so, this will banlist-forever the router hash or permanently negative cache the dest hash,
* and then throw the exception. Otherwise it does nothing.
*
* @throws UnsupportedCryptoException if that's why it failed.
* @since 0.9.16
*/
private void processStoreFailure(Hash h, DatabaseEntry entry) throws UnsupportedCryptoException {
if (entry.getHash().equals(h)) {
if (entry.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
LeaseSet ls = (LeaseSet) entry;
Destination d = ls.getDestination();
Certificate c = d.getCertificate();
if (c.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY) {
try {
KeyCertificate kc = c.toKeyCertificate();
SigType type = kc.getSigType();
if (type == null || !type.isAvailable() || type.getBaseAlgorithm() == SigAlgo.RSA) {
failPermanently(d);
String stype = (type != null) ? type.toString() : Integer.toString(kc.getSigTypeCode());
if (_log.shouldLog(Log.WARN))
_log.warn("Unsupported sig type " + stype + " for destination " + h);
throw new UnsupportedCryptoException("Sig type " + stype);
}
} catch (DataFormatException dfe) {
}
}
} else if (entry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
RouterInfo ri = (RouterInfo) entry;
RouterIdentity id = ri.getIdentity();
Certificate c = id.getCertificate();
if (c.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY) {
try {
KeyCertificate kc = c.toKeyCertificate();
SigType type = kc.getSigType();
if (type == null || !type.isAvailable()) {
String stype = (type != null) ? type.toString() : Integer.toString(kc.getSigTypeCode());
_context.banlist().banlistRouterForever(h, "Unsupported signature type " + stype);
if (_log.shouldLog(Log.WARN))
_log.warn("Unsupported sig type " + stype + " for router " + h);
throw new UnsupportedCryptoException("Sig type " + stype);
}
} catch (DataFormatException dfe) {
}
}
}
}
if (_log.shouldLog(Log.WARN))
_log.warn("Verify fail, cause unknown: " + entry);
}
use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class RefreshRoutersJob method runJob.
public void runJob() {
if (_facade.isInitialized()) {
if (_routers == null) {
// make a list of all routers, floodfill first
_routers = _facade.getFloodfillPeers();
int ff = _routers.size();
Set<Hash> all = _facade.getAllRouters();
all.removeAll(_routers);
int non = all.size();
_routers.addAll(all);
if (_log.shouldLog(Log.INFO))
_log.info("To check: " + ff + " floodfills and " + non + " non-floodfills");
}
if (_routers.isEmpty()) {
if (_log.shouldLog(Log.INFO))
_log.info("Finished");
return;
}
long expire = getContext().clock().now() - EXPIRE;
for (Iterator<Hash> iter = _routers.iterator(); iter.hasNext(); ) {
Hash h = iter.next();
iter.remove();
if (h.equals(getContext().routerHash()))
continue;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Checking " + h);
RouterInfo ri = _facade.lookupRouterInfoLocally(h);
if (ri == null)
continue;
if (ri.getPublished() < expire) {
if (_log.shouldLog(Log.INFO))
_log.info("Refreshing " + h);
_facade.search(h, null, null, 15 * 1000, false);
break;
}
}
}
requeue(RERUN_DELAY_MS);
}
use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class Router method locked_rebuildRouterInfo.
/**
* Rebuild and republish our routerInfo since something significant
* has changed.
*/
private void locked_rebuildRouterInfo(boolean blockingRebuild) {
RouterInfo ri;
if (_routerInfo != null)
ri = new RouterInfo(_routerInfo);
else
ri = new RouterInfo();
try {
ri.setPublished(_context.clock().now());
Properties stats = _context.statPublisher().publishStatistics();
ri.setOptions(stats);
// deadlock thru createAddresses() thru SSU REA... move outside lock?
ri.setAddresses(_context.commSystem().createAddresses());
SigningPrivateKey key = _context.keyManager().getSigningPrivateKey();
if (key == null) {
_log.log(Log.CRIT, "Internal error - signing private key not known? Impossible?");
return;
}
ri.sign(key);
setRouterInfo(ri);
if (!ri.isValid())
throw new DataFormatException("Our RouterInfo has a bad signature");
Republish r = new Republish(_context);
if (blockingRebuild)
r.timeReached();
else
_context.simpleTimer2().addEvent(r, 0);
} catch (DataFormatException dfe) {
_log.log(Log.CRIT, "Internal error - unable to sign our own address?!", dfe);
}
}
use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class PeerTestJob method testPeer.
/**
* Fire off the necessary jobs and messages to test the given peer
* The message is a store of the peer's RI to itself,
* with a reply token.
*/
private void testPeer(RouterInfo peer) {
TunnelInfo inTunnel = getInboundTunnelId();
if (inTunnel == null) {
_log.warn("No tunnels to get peer test replies through!");
return;
}
TunnelId inTunnelId = inTunnel.getReceiveTunnelId(0);
RouterInfo inGateway = getContext().netDb().lookupRouterInfoLocally(inTunnel.getPeer(0));
if (inGateway == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("We can't find the gateway to our inbound tunnel?! Impossible?");
return;
}
int timeoutMs = getTestTimeout();
long expiration = getContext().clock().now() + timeoutMs;
long nonce = 1 + getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE - 1);
DatabaseStoreMessage msg = buildMessage(peer, inTunnelId, inGateway.getIdentity().getHash(), nonce, expiration);
TunnelInfo outTunnel = getOutboundTunnelId();
if (outTunnel == null) {
_log.warn("No tunnels to send search out through! Something is wrong...");
return;
}
TunnelId outTunnelId = outTunnel.getSendTunnelId(0);
if (_log.shouldLog(Log.DEBUG))
_log.debug(getJobId() + ": Sending peer test to " + peer.getIdentity().getHash().toBase64() + " out " + outTunnel + " w/ replies through " + inTunnel);
ReplySelector sel = new ReplySelector(peer.getIdentity().getHash(), nonce, expiration);
PeerReplyFoundJob reply = new PeerReplyFoundJob(getContext(), peer, inTunnel, outTunnel);
PeerReplyTimeoutJob timeoutJob = new PeerReplyTimeoutJob(getContext(), peer, inTunnel, outTunnel, sel);
getContext().messageRegistry().registerPending(sel, reply, timeoutJob);
getContext().tunnelDispatcher().dispatchOutbound(msg, outTunnelId, null, peer.getIdentity().getHash());
}
use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.
the class ProfileOrganizer method selectPeersLocallyUnreachable.
/**
* Get the peers the transport layer thinks are unreachable, and
* add in the peers with the SSU peer testing bug,
* and peers requiring introducers.
*/
public List<Hash> selectPeersLocallyUnreachable() {
List<Hash> n;
int count;
getReadLock();
try {
count = _notFailingPeers.size();
n = new ArrayList<Hash>(_notFailingPeers.keySet());
} finally {
releaseReadLock();
}
List<Hash> l = new ArrayList<Hash>(count / 4);
for (Hash peer : n) {
if (_context.commSystem().wasUnreachable(peer))
l.add(peer);
else {
// Blacklist <= 0.6.1.32 SSU-only peers, they don't know if they are unreachable,
// and we may not know either if they contacted us first, so assume they are.
// Also blacklist all peers requiring SSU introducers, because either
// a) it's slow; or
// b) it doesn't work very often; or
// c) in the event they are advertising NTCP, it probably won't work because
// they probably don't have a TCP hole punched in their firewall either.
RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
if (info != null) {
String v = info.getVersion();
// this only works if there is no 0.6.1.34!
if ((!v.equals("0.6.1.33")) && v.startsWith("0.6.1.") && info.getTargetAddress("NTCP") == null)
l.add(peer);
else {
RouterAddress ra = info.getTargetAddress("SSU");
// as long as they have NTCP
if (ra == null) {
if (info.getTargetAddress("NTCP") == null)
l.add(peer);
continue;
}
// This is the quick way of doing UDPAddress.getIntroducerCount() > 0
if (ra.getOption("ihost0") != null)
l.add(peer);
}
}
}
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("Unreachable: " + l);
return l;
}
Aggregations