Search in sources :

Example 1 with RequestLeaseSetMessage

use of net.i2p.data.i2cp.RequestLeaseSetMessage in project i2p.i2p by i2p.

the class RequestLeaseSetMessageHandler method handleMessage.

public void handleMessage(I2CPMessage message, I2PSessionImpl session) {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Handle message " + message);
    RequestLeaseSetMessage msg = (RequestLeaseSetMessage) message;
    LeaseSet leaseSet = new LeaseSet();
    for (int i = 0; i < msg.getEndpoints(); i++) {
        Lease lease = new Lease();
        lease.setGateway(msg.getRouter(i));
        lease.setTunnelId(msg.getTunnelId(i));
        lease.setEndDate(msg.getEndDate());
        // lease.setStartDate(msg.getStartDate());
        leaseSet.addLease(lease);
    }
    signLeaseSet(leaseSet, session);
}
Also used : LeaseSet(net.i2p.data.LeaseSet) Lease(net.i2p.data.Lease) RequestLeaseSetMessage(net.i2p.data.i2cp.RequestLeaseSetMessage)

Example 2 with RequestLeaseSetMessage

use of net.i2p.data.i2cp.RequestLeaseSetMessage in project i2p.i2p by i2p.

the class RequestLeaseSetJob method runJob.

public void runJob() {
    if (_runner.isDead())
        return;
    LeaseSet requested = _requestState.getRequested();
    long endTime = requested.getEarliestLeaseDate();
    // Add a small number of ms (0 to MAX_FUDGE) that increases as we approach the expire time.
    // Since the earliest date functions as a version number,
    // this will force the floodfill to flood each new version;
    // otherwise it won't if the earliest time hasn't changed.
    long fudge = MAX_FUDGE - ((endTime - getContext().clock().now()) / (10 * 60 * 1000 / MAX_FUDGE));
    // if (_log.shouldLog(Log.DEBUG))
    // _log.debug("Adding fudge " + fudge);
    endTime += fudge;
    SessionId id = _runner.getSessionId(requested.getDestination().calculateHash());
    if (id == null) {
        _runner.failLeaseRequest(_requestState);
        return;
    }
    I2CPMessage msg;
    if (getContext().getProperty(PROP_VARIABLE, DFLT_VARIABLE) && (_runner instanceof QueuedClientConnectionRunner || RequestVariableLeaseSetMessage.isSupported(_runner.getClientVersion()))) {
        // new style - leases will have individual expirations
        RequestVariableLeaseSetMessage rmsg = new RequestVariableLeaseSetMessage();
        rmsg.setSessionId(id);
        for (int i = 0; i < requested.getLeaseCount(); i++) {
            Lease lease = requested.getLease(i);
            if (lease.getEndDate().getTime() < endTime) {
                // don't modify old object, we don't know where it came from
                Lease nl = new Lease();
                nl.setGateway(lease.getGateway());
                nl.setTunnelId(lease.getTunnelId());
                nl.setEndDate(new Date(endTime));
                lease = nl;
            // if (_log.shouldLog(Log.INFO))
            // _log.info("Adjusted end date to " + endTime + " for " + lease);
            }
            rmsg.addEndpoint(lease);
        }
        msg = rmsg;
    } else {
        // old style - all leases will have same expiration
        RequestLeaseSetMessage rmsg = new RequestLeaseSetMessage();
        Date end = new Date(endTime);
        rmsg.setEndDate(end);
        rmsg.setSessionId(id);
        for (int i = 0; i < requested.getLeaseCount(); i++) {
            Lease lease = requested.getLease(i);
            rmsg.addEndpoint(lease.getGateway(), lease.getTunnelId());
        }
        msg = rmsg;
    }
    try {
        // _runner.setLeaseRequest(state);
        _runner.doSend(msg);
        getContext().jobQueue().addJob(new CheckLeaseRequestStatus());
    } catch (I2CPMessageException ime) {
        getContext().statManager().addRateData("client.requestLeaseSetDropped", 1);
        _log.error("Error sending I2CP message requesting the lease set", ime);
        _requestState.setIsSuccessful(false);
        if (_requestState.getOnFailed() != null)
            RequestLeaseSetJob.this.getContext().jobQueue().addJob(_requestState.getOnFailed());
        _runner.failLeaseRequest(_requestState);
    // Don't disconnect, the tunnel will retry
    // _runner.disconnectClient("I2CP error requesting leaseSet");
    }
}
Also used : LeaseSet(net.i2p.data.LeaseSet) I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) Lease(net.i2p.data.Lease) I2CPMessage(net.i2p.data.i2cp.I2CPMessage) RequestVariableLeaseSetMessage(net.i2p.data.i2cp.RequestVariableLeaseSetMessage) SessionId(net.i2p.data.i2cp.SessionId) Date(java.util.Date) RequestLeaseSetMessage(net.i2p.data.i2cp.RequestLeaseSetMessage)

Aggregations

Lease (net.i2p.data.Lease)2 LeaseSet (net.i2p.data.LeaseSet)2 RequestLeaseSetMessage (net.i2p.data.i2cp.RequestLeaseSetMessage)2 Date (java.util.Date)1 I2CPMessage (net.i2p.data.i2cp.I2CPMessage)1 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)1 RequestVariableLeaseSetMessage (net.i2p.data.i2cp.RequestVariableLeaseSetMessage)1 SessionId (net.i2p.data.i2cp.SessionId)1