Search in sources :

Example 1 with SendMessageDirectJob

use of net.i2p.router.message.SendMessageDirectJob in project i2p.i2p by i2p.

the class HandleFloodfillDatabaseStoreMessageJob method sendAck.

private void sendAck(Hash storedKey) {
    DeliveryStatusMessage msg = new DeliveryStatusMessage(getContext());
    msg.setMessageId(_message.getReplyToken());
    // Randomize for a little protection against clock-skew fingerprinting.
    // But the "arrival" isn't used for anything, right?
    // TODO just set to 0?
    // TODO we have no session to garlic wrap this with, needs new message
    msg.setArrival(getContext().clock().now() - getContext().random().nextInt(3 * 1000));
    // may be null
    TunnelId replyTunnel = _message.getReplyTunnel();
    // A store of our own RI, only if we are not FF
    DatabaseStoreMessage msg2;
    if ((getContext().netDb().floodfillEnabled() && !getContext().router().gracefulShutdownInProgress()) || storedKey.equals(getContext().routerHash())) {
        // don't send our RI if the store was our RI (from PeerTestJob)
        msg2 = null;
    } else {
        // we aren't ff, send a go-away message
        msg2 = new DatabaseStoreMessage(getContext());
        RouterInfo me = getContext().router().getRouterInfo();
        msg2.setEntry(me);
        if (_log.shouldWarn())
            _log.warn("Got a store w/ reply token, but we aren't ff: from: " + _from + " fromHash: " + _fromHash + " msg: " + _message, new Exception());
    }
    Hash toPeer = _message.getReplyGateway();
    boolean toUs = getContext().routerHash().equals(toPeer);
    // else through an exploratory tunnel.
    if (toUs && replyTunnel != null) {
        // if we are the gateway, act as if we received it
        TunnelGatewayMessage tgm = new TunnelGatewayMessage(getContext());
        tgm.setMessage(msg);
        tgm.setTunnelId(replyTunnel);
        tgm.setMessageExpiration(msg.getMessageExpiration());
        getContext().tunnelDispatcher().dispatch(tgm);
        if (msg2 != null) {
            TunnelGatewayMessage tgm2 = new TunnelGatewayMessage(getContext());
            tgm2.setMessage(msg2);
            tgm2.setTunnelId(replyTunnel);
            tgm2.setMessageExpiration(msg.getMessageExpiration());
            getContext().tunnelDispatcher().dispatch(tgm2);
        }
    } else if (toUs || getContext().commSystem().isEstablished(toPeer)) {
        Job send = new SendMessageDirectJob(getContext(), msg, toPeer, REPLY_TIMEOUT, MESSAGE_PRIORITY);
        send.runJob();
        if (msg2 != null) {
            Job send2 = new SendMessageDirectJob(getContext(), msg2, toPeer, REPLY_TIMEOUT, MESSAGE_PRIORITY);
            send2.runJob();
        }
    } else {
        // pick tunnel with endpoint closest to toPeer
        TunnelInfo outTunnel = getContext().tunnelManager().selectOutboundExploratoryTunnel(toPeer);
        if (outTunnel == null) {
            if (_log.shouldLog(Log.WARN))
                _log.warn("No outbound tunnel could be found");
            return;
        }
        getContext().tunnelDispatcher().dispatchOutbound(msg, outTunnel.getSendTunnelId(0), replyTunnel, toPeer);
        if (msg2 != null)
            getContext().tunnelDispatcher().dispatchOutbound(msg2, outTunnel.getSendTunnelId(0), replyTunnel, toPeer);
    }
}
Also used : TunnelGatewayMessage(net.i2p.data.i2np.TunnelGatewayMessage) RouterInfo(net.i2p.data.router.RouterInfo) DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage) TunnelInfo(net.i2p.router.TunnelInfo) Hash(net.i2p.data.Hash) SendMessageDirectJob(net.i2p.router.message.SendMessageDirectJob) Job(net.i2p.router.Job) TunnelId(net.i2p.data.TunnelId) SendMessageDirectJob(net.i2p.router.message.SendMessageDirectJob) DeliveryStatusMessage(net.i2p.data.i2np.DeliveryStatusMessage)

Example 2 with SendMessageDirectJob

use of net.i2p.router.message.SendMessageDirectJob in project i2p.i2p by i2p.

the class HandleDatabaseLookupMessageJob method sendMessage.

protected void sendMessage(I2NPMessage message, Hash toPeer, TunnelId replyTunnel) {
    if (replyTunnel != null) {
        sendThroughTunnel(message, toPeer, replyTunnel);
    } else {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Sending reply directly to " + toPeer);
        Job send = new SendMessageDirectJob(getContext(), message, toPeer, REPLY_TIMEOUT, MESSAGE_PRIORITY);
        send.runJob();
    // getContext().netDb().lookupRouterInfo(toPeer, send, null, REPLY_TIMEOUT);
    }
}
Also used : SendMessageDirectJob(net.i2p.router.message.SendMessageDirectJob) Job(net.i2p.router.Job) SendMessageDirectJob(net.i2p.router.message.SendMessageDirectJob)

Example 3 with SendMessageDirectJob

use of net.i2p.router.message.SendMessageDirectJob in project i2p.i2p by i2p.

the class SearchJob method sendRouterSearch.

/**
 * we're searching for a router, so we can just send direct
 */
protected void sendRouterSearch(RouterInfo router) {
    int timeout = _facade.getPeerTimeout(router.getIdentity().getHash());
    long expiration = getContext().clock().now() + timeout;
    // use the 4-arg one so we pick up the override in ExploreJob
    // I2NPMessage msg = buildMessage(expiration);
    I2NPMessage msg = buildMessage(null, router.getIdentity().getHash(), expiration, router);
    if (msg == null) {
        getContext().jobQueue().addJob(new FailedJob(getContext(), router));
        return;
    }
    if (_log.shouldLog(Log.DEBUG))
        _log.debug(getJobId() + ": Sending router search directly to " + router.getIdentity().getHash() + " for " + _state.getTarget());
    SearchMessageSelector sel = new SearchMessageSelector(getContext(), router, _expiration, _state);
    SearchUpdateReplyFoundJob reply = new SearchUpdateReplyFoundJob(getContext(), router, _state, _facade, this);
    SendMessageDirectJob j = new SendMessageDirectJob(getContext(), msg, router.getIdentity().getHash(), reply, new FailedJob(getContext(), router), sel, timeout, OutNetMessage.PRIORITY_EXPLORATORY);
    if (FloodfillNetworkDatabaseFacade.isFloodfill(router))
        _floodfillSearchesOutstanding++;
    j.runJob();
// getContext().jobQueue().addJob(j);
}
Also used : I2NPMessage(net.i2p.data.i2np.I2NPMessage) SendMessageDirectJob(net.i2p.router.message.SendMessageDirectJob)

Example 4 with SendMessageDirectJob

use of net.i2p.router.message.SendMessageDirectJob in project i2p.i2p by i2p.

the class HandleDatabaseLookupMessageJob method sendThroughTunnel.

private void sendThroughTunnel(I2NPMessage message, Hash toPeer, TunnelId replyTunnel) {
    if (getContext().routerHash().equals(toPeer)) {
        // if we are the gateway, act as if we received it
        TunnelGatewayMessage m = new TunnelGatewayMessage(getContext());
        m.setMessage(message);
        m.setTunnelId(replyTunnel);
        m.setMessageExpiration(message.getMessageExpiration());
        getContext().tunnelDispatcher().dispatch(m);
    } else {
        // if we aren't the gateway, forward it on
        if (!_replyKeyConsumed) {
            // if we send a followup DSM w/ our RI, don't reuse key
            SessionKey replyKey = _message.getReplyKey();
            if (replyKey != null) {
                // encrypt the reply
                if (_log.shouldLog(Log.INFO))
                    _log.info("Sending encrypted reply to " + toPeer + ' ' + replyKey + ' ' + _message.getReplyTag());
                message = MessageWrapper.wrap(getContext(), message, replyKey, _message.getReplyTag());
                if (message == null) {
                    _log.error("Encryption error");
                    return;
                }
                _replyKeyConsumed = true;
            }
        }
        TunnelGatewayMessage m = new TunnelGatewayMessage(getContext());
        m.setMessage(message);
        m.setMessageExpiration(message.getMessageExpiration());
        m.setTunnelId(replyTunnel);
        SendMessageDirectJob j = new SendMessageDirectJob(getContext(), m, toPeer, 10 * 1000, MESSAGE_PRIORITY);
        j.runJob();
    // getContext().jobQueue().addJob(j);
    }
}
Also used : TunnelGatewayMessage(net.i2p.data.i2np.TunnelGatewayMessage) SessionKey(net.i2p.data.SessionKey) SendMessageDirectJob(net.i2p.router.message.SendMessageDirectJob)

Aggregations

SendMessageDirectJob (net.i2p.router.message.SendMessageDirectJob)4 TunnelGatewayMessage (net.i2p.data.i2np.TunnelGatewayMessage)2 Job (net.i2p.router.Job)2 Hash (net.i2p.data.Hash)1 SessionKey (net.i2p.data.SessionKey)1 TunnelId (net.i2p.data.TunnelId)1 DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)1 DeliveryStatusMessage (net.i2p.data.i2np.DeliveryStatusMessage)1 I2NPMessage (net.i2p.data.i2np.I2NPMessage)1 RouterInfo (net.i2p.data.router.RouterInfo)1 TunnelInfo (net.i2p.router.TunnelInfo)1