Search in sources :

Example 41 with RouterInfo

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);
}
Also used : LeaseSet(net.i2p.data.LeaseSet) Destination(net.i2p.data.Destination) KeyCertificate(net.i2p.data.KeyCertificate) DataFormatException(net.i2p.data.DataFormatException) RouterInfo(net.i2p.data.router.RouterInfo) RouterIdentity(net.i2p.data.router.RouterIdentity) SigType(net.i2p.crypto.SigType) Certificate(net.i2p.data.Certificate) KeyCertificate(net.i2p.data.KeyCertificate)

Example 42 with RouterInfo

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);
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) Hash(net.i2p.data.Hash)

Example 43 with RouterInfo

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);
    }
}
Also used : SigningPrivateKey(net.i2p.data.SigningPrivateKey) DataFormatException(net.i2p.data.DataFormatException) RouterInfo(net.i2p.data.router.RouterInfo) OrderedProperties(net.i2p.util.OrderedProperties) Properties(java.util.Properties)

Example 44 with RouterInfo

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());
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage) TunnelInfo(net.i2p.router.TunnelInfo) TunnelId(net.i2p.data.TunnelId)

Example 45 with RouterInfo

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;
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) ArrayList(java.util.ArrayList) RouterAddress(net.i2p.data.router.RouterAddress) Hash(net.i2p.data.Hash)

Aggregations

RouterInfo (net.i2p.data.router.RouterInfo)95 Hash (net.i2p.data.Hash)45 ArrayList (java.util.ArrayList)18 RouterAddress (net.i2p.data.router.RouterAddress)17 DataFormatException (net.i2p.data.DataFormatException)11 IOException (java.io.IOException)10 RouterIdentity (net.i2p.data.router.RouterIdentity)10 DatabaseEntry (net.i2p.data.DatabaseEntry)9 OutNetMessage (net.i2p.router.OutNetMessage)9 File (java.io.File)8 DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)8 Properties (java.util.Properties)7 LeaseSet (net.i2p.data.LeaseSet)6 BigInteger (java.math.BigInteger)5 Date (java.util.Date)5 SigType (net.i2p.crypto.SigType)5 TunnelId (net.i2p.data.TunnelId)5 TunnelInfo (net.i2p.router.TunnelInfo)5 FileOutputStream (java.io.FileOutputStream)4 HashMap (java.util.HashMap)4