Search in sources :

Example 16 with DatabaseStoreMessage

use of net.i2p.data.i2np.DatabaseStoreMessage in project i2p.i2p by i2p.

the class SearchJob method resend.

/**
 * Resend the leaseSet to the peer who had previously failed to
 * provide us with the data when we asked them.
 */
private boolean resend(RouterInfo toPeer, LeaseSet ls) {
    Hash to = toPeer.getIdentity().getHash();
    DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
    msg.setEntry(ls);
    msg.setMessageExpiration(getContext().clock().now() + RESEND_TIMEOUT);
    TunnelInfo outTunnel = getContext().tunnelManager().selectOutboundExploratoryTunnel(to);
    if (outTunnel != null) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("resending leaseSet out to " + to + " through " + outTunnel + ": " + msg);
        // TODO pass a priority to the dispatcher
        getContext().tunnelDispatcher().dispatchOutbound(msg, outTunnel.getSendTunnelId(0), null, to);
        return true;
    } else {
        if (_log.shouldLog(Log.WARN))
            _log.warn("unable to resend a leaseSet - no outbound exploratory tunnels!");
        return false;
    }
}
Also used : DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage) TunnelInfo(net.i2p.router.TunnelInfo) Hash(net.i2p.data.Hash)

Example 17 with DatabaseStoreMessage

use of net.i2p.data.i2np.DatabaseStoreMessage in project i2p.i2p by i2p.

the class PeerTestJob method buildMessage.

/**
 * Build a message to test the peer with.
 * The message is a store of the peer's RI to itself,
 * with a reply token.
 */
private DatabaseStoreMessage buildMessage(RouterInfo peer, TunnelId replyTunnel, Hash replyGateway, long nonce, long expiration) {
    DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
    msg.setEntry(peer);
    msg.setReplyGateway(replyGateway);
    msg.setReplyTunnel(replyTunnel);
    msg.setReplyToken(nonce);
    msg.setMessageExpiration(expiration);
    return msg;
}
Also used : DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage)

Example 18 with DatabaseStoreMessage

use of net.i2p.data.i2np.DatabaseStoreMessage in project i2p.i2p by i2p.

the class HandleDatabaseLookupMessageJob method sendData.

private void sendData(Hash key, DatabaseEntry data, Hash toPeer, TunnelId replyTunnel) {
    if (!key.equals(data.getHash())) {
        _log.error("Hash mismatch HDLMJ");
        return;
    }
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Sending data matching key " + key + " to peer " + toPeer + " tunnel " + replyTunnel);
    DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
    if (data.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
        getContext().statManager().addRateData("netDb.lookupsMatchedLeaseSet", 1);
    }
    msg.setEntry(data);
    getContext().statManager().addRateData("netDb.lookupsMatched", 1);
    getContext().statManager().addRateData("netDb.lookupsHandled", 1);
    sendMessage(msg, toPeer, replyTunnel);
}
Also used : DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage)

Example 19 with DatabaseStoreMessage

use of net.i2p.data.i2np.DatabaseStoreMessage in project i2p.i2p by i2p.

the class FloodfillRouterInfoFloodJob method runJob.

public void runJob() {
    FloodfillPeerSelector sel = (FloodfillPeerSelector) _facade.getPeerSelector();
    DatabaseStoreMessage dsm;
    OutNetMessage outMsg;
    RouterInfo nextPeerInfo;
    List<Hash> peers = sel.selectFloodfillParticipants(getContext().routerHash(), FLOOD_PEERS, null);
    for (Hash ri : peers) {
        // Iterate through list of nearby (ff) peers
        dsm = new DatabaseStoreMessage(getContext());
        dsm.setMessageExpiration(getContext().clock().now() + 10 * 1000);
        dsm.setEntry(getContext().router().getRouterInfo());
        nextPeerInfo = getContext().netDb().lookupRouterInfoLocally(ri);
        if (nextPeerInfo == null) {
            continue;
        }
        outMsg = new OutNetMessage(getContext(), dsm, getContext().clock().now() + 10 * 1000, OutNetMessage.PRIORITY_MY_NETDB_STORE, nextPeerInfo);
        // Whoosh!
        getContext().outNetMessagePool().add(outMsg);
        if (_log.shouldLog(Log.DEBUG)) {
            _log.logAlways(Log.DEBUG, "Sending our RI to: " + nextPeerInfo.getHash());
        }
    }
}
Also used : OutNetMessage(net.i2p.router.OutNetMessage) RouterInfo(net.i2p.data.router.RouterInfo) DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage) Hash(net.i2p.data.Hash)

Example 20 with DatabaseStoreMessage

use of net.i2p.data.i2np.DatabaseStoreMessage in project i2p.i2p by i2p.

the class HandleFloodfillDatabaseLookupMessageJob method sendClosest.

/**
 * We extend this here to send our routerInfo back as well, if we are not floodfill.
 * This gets the word out to routers that we are no longer floodfill, so they
 * will stop bugging us.
 */
@Override
protected void sendClosest(Hash key, Set<Hash> routerInfoSet, Hash toPeer, TunnelId replyTunnel) {
    super.sendClosest(key, routerInfoSet, toPeer, replyTunnel);
    // go away, you got the wrong guy, send our RI back unsolicited
    if (!getContext().netDb().floodfillEnabled()) {
        // We could just call sendData(myhash, myri, toPeer, replyTunnel) but
        // that would increment the netDb.lookupsHandled and netDb.lookupsMatched stats
        DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
        RouterInfo me = getContext().router().getRouterInfo();
        msg.setEntry(me);
        sendMessage(msg, toPeer, replyTunnel);
    }
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage)

Aggregations

DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)21 Hash (net.i2p.data.Hash)9 RouterInfo (net.i2p.data.router.RouterInfo)8 OutNetMessage (net.i2p.router.OutNetMessage)5 DatabaseSearchReplyMessage (net.i2p.data.i2np.DatabaseSearchReplyMessage)4 TunnelInfo (net.i2p.router.TunnelInfo)4 TunnelId (net.i2p.data.TunnelId)3 I2NPMessage (net.i2p.data.i2np.I2NPMessage)3 ArrayList (java.util.ArrayList)2 DatabaseEntry (net.i2p.data.DatabaseEntry)2 DeliveryStatusMessage (net.i2p.data.i2np.DeliveryStatusMessage)2 RouterIdentity (net.i2p.data.router.RouterIdentity)2 Job (net.i2p.router.Job)2 IOException (java.io.IOException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 LeaseSet (net.i2p.data.LeaseSet)1 Payload (net.i2p.data.Payload)1 DataMessage (net.i2p.data.i2np.DataMessage)1 TunnelGatewayMessage (net.i2p.data.i2np.TunnelGatewayMessage)1