Search in sources :

Example 11 with SessionId

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

the class LocalClientMessageEventListener method handleHostLookup.

/**
 *  Look only in current local dests
 */
@Override
protected void handleHostLookup(HostLookupMessage message) {
    Hash h = message.getHash();
    String name = message.getHostname();
    long reqID = message.getReqID();
    SessionId sessID = message.getSessionId();
    if (h == null && name != null && name.length() == 60) {
        // convert a b32 lookup to a hash lookup
        String nlc = name.toLowerCase(Locale.US);
        if (nlc.endsWith(".b32.i2p")) {
            byte[] b = Base32.decode(nlc.substring(0, 52));
            if (b != null && b.length == Hash.HASH_LENGTH) {
                h = Hash.create(b);
            }
        }
    }
    Destination d = null;
    if (h != null)
        d = ((LocalClientConnectionRunner) _runner).localLookup(h);
    HostReplyMessage msg;
    if (d != null)
        msg = new HostReplyMessage(sessID, d, reqID);
    else
        msg = new HostReplyMessage(sessID, HostReplyMessage.RESULT_FAILURE, reqID);
    try {
        _runner.doSend(msg);
    } catch (I2CPMessageException ime) {
        ime.printStackTrace();
    }
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) Destination(net.i2p.data.Destination) HostReplyMessage(net.i2p.data.i2cp.HostReplyMessage) Hash(net.i2p.data.Hash) SessionId(net.i2p.data.i2cp.SessionId)

Example 12 with SessionId

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

the class I2CPMessageProducer method updateTunnels.

/**
 * Update number of tunnels
 *
 * @param tunnels 0 for original configured number
 */
public void updateTunnels(I2PSessionImpl session, int tunnels) throws I2PSessionException {
    ReconfigureSessionMessage msg = new ReconfigureSessionMessage();
    SessionConfig cfg = new SessionConfig(session.getMyDestination());
    Properties props = session.getOptions();
    if (tunnels > 0) {
        Properties newprops = new Properties();
        newprops.putAll(props);
        props = newprops;
        props.setProperty("inbound.quantity", "" + tunnels);
        props.setProperty("outbound.quantity", "" + tunnels);
        props.setProperty("inbound.backupQuantity", "0");
        props.setProperty("outbound.backupQuantity", "0");
    }
    cfg.setOptions(props);
    try {
        cfg.signSessionConfig(session.getPrivateKey());
    } catch (DataFormatException dfe) {
        throw new I2PSessionException("Unable to sign the session config", dfe);
    }
    msg.setSessionConfig(cfg);
    SessionId sid = session.getSessionId();
    if (sid == null) {
        _log.error(session.toString() + " update config w/o session", new Exception());
        return;
    }
    msg.setSessionId(sid);
    session.sendMessage(msg);
}
Also used : ReconfigureSessionMessage(net.i2p.data.i2cp.ReconfigureSessionMessage) DataFormatException(net.i2p.data.DataFormatException) SessionConfig(net.i2p.data.i2cp.SessionConfig) I2PSessionException(net.i2p.client.I2PSessionException) Properties(java.util.Properties) SessionId(net.i2p.data.i2cp.SessionId) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException)

Example 13 with SessionId

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

the class I2CPMessageProducer method sendMessage.

/**
 * Package up and send the payload to the router for delivery
 *
 * @param nonce 0 to 0xffffffff; if 0, the router will not reply with a MessageStatusMessage
 * @since 0.8.4
 */
public void sendMessage(I2PSessionImpl session, Destination dest, long nonce, byte[] payload, long expires, int flags) throws I2PSessionException {
    if (!updateBps(payload.length, expires))
        // drop the message... send fail notification?
        return;
    SendMessageMessage msg;
    if (expires > 0 || flags > 0) {
        SendMessageExpiresMessage smsg = new SendMessageExpiresMessage();
        smsg.setExpiration(expires);
        smsg.setFlags(flags);
        msg = smsg;
    } else
        msg = new SendMessageMessage();
    msg.setDestination(dest);
    SessionId sid = session.getSessionId();
    if (sid == null) {
        _log.error(session.toString() + " send message w/o session", new Exception());
        return;
    }
    msg.setSessionId(sid);
    msg.setNonce(nonce);
    Payload data = createPayload(dest, payload, null, null, null, null);
    msg.setPayload(data);
    session.sendMessage(msg);
}
Also used : SendMessageMessage(net.i2p.data.i2cp.SendMessageMessage) SendMessageExpiresMessage(net.i2p.data.i2cp.SendMessageExpiresMessage) Payload(net.i2p.data.Payload) SessionId(net.i2p.data.i2cp.SessionId) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException)

Example 14 with SessionId

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

the class I2PSessionImpl method getPrefix.

/**
 * try hard to make a decent identifier as this will appear in error logs
 */
protected String getPrefix() {
    StringBuilder buf = new StringBuilder();
    buf.append('[');
    buf.append(_state.toString()).append(' ');
    String s = _options.getProperty("inbound.nickname");
    if (s != null)
        buf.append(s);
    else
        buf.append(getClass().getSimpleName());
    SessionId id = _sessionId;
    if (id != null)
        buf.append(" #").append(id.getSessionId());
    buf.append("]: ");
    return buf.toString();
}
Also used : SessionId(net.i2p.data.i2cp.SessionId)

Example 15 with SessionId

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

the class I2PSessionImpl method lookupDest.

/**
 *  Ask the router to lookup a Destination by host name.
 *  Blocking. See above for details.
 *  @param maxWait ms
 *  @since 0.9.11
 *  @return null on failure
 */
public Destination lookupDest(String name, long maxWait) throws I2PSessionException {
    if (name.length() == 0)
        return null;
    // Shortcut for b64
    if (name.length() >= 516) {
        try {
            return new Destination(name);
        } catch (DataFormatException dfe) {
            return null;
        }
    }
    // won't fit in Mapping
    if (name.length() >= 256 && !_context.isRouterContext())
        return null;
    synchronized (_lookupCache) {
        Destination rv = _lookupCache.get(name);
        if (rv != null)
            return rv;
    }
    if (isClosed()) {
        if (_log.shouldLog(Log.INFO))
            _log.info("Session closed, cannot lookup " + name);
        return null;
    }
    if (!_routerSupportsHostLookup) {
        // do them a favor and convert to Hash lookup
        if (name.length() == 60 && name.toLowerCase(Locale.US).endsWith(".b32.i2p"))
            return lookupDest(Hash.create(Base32.decode(name.toLowerCase(Locale.US).substring(0, 52))), maxWait);
        // else unsupported
        if (_log.shouldLog(Log.WARN))
            _log.warn("Router does not support HostLookup for " + name);
        return null;
    }
    int nonce = _lookupID.incrementAndGet() & 0x7fffffff;
    LookupWaiter waiter = new LookupWaiter(name, nonce);
    _pendingLookups.offer(waiter);
    Destination rv = null;
    try {
        if (_log.shouldLog(Log.INFO))
            _log.info("Sending HostLookup for " + name);
        SessionId id = _sessionId;
        if (id == null)
            id = new SessionId(65535);
        sendMessage_unchecked(new HostLookupMessage(id, name, nonce, maxWait));
        try {
            synchronized (waiter) {
                waiter.wait(maxWait);
                rv = waiter.destination;
            }
        } catch (InterruptedException ie) {
            throw new I2PSessionException("Interrupted", ie);
        }
    } finally {
        _pendingLookups.remove(waiter);
    }
    return rv;
}
Also used : Destination(net.i2p.data.Destination) DataFormatException(net.i2p.data.DataFormatException) HostLookupMessage(net.i2p.data.i2cp.HostLookupMessage) I2PSessionException(net.i2p.client.I2PSessionException) SessionId(net.i2p.data.i2cp.SessionId)

Aggregations

SessionId (net.i2p.data.i2cp.SessionId)24 I2PSessionException (net.i2p.client.I2PSessionException)7 Destination (net.i2p.data.Destination)7 DataFormatException (net.i2p.data.DataFormatException)5 SessionConfig (net.i2p.data.i2cp.SessionConfig)5 Hash (net.i2p.data.Hash)4 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)4 Properties (java.util.Properties)3 Payload (net.i2p.data.Payload)2 HostLookupMessage (net.i2p.data.i2cp.HostLookupMessage)2 MessageStatusMessage (net.i2p.data.i2cp.MessageStatusMessage)2 SendMessageExpiresMessage (net.i2p.data.i2cp.SendMessageExpiresMessage)2 SendMessageMessage (net.i2p.data.i2cp.SendMessageMessage)2 ClientTunnelSettings (net.i2p.router.ClientTunnelSettings)2 Date (java.util.Date)1 SigType (net.i2p.crypto.SigType)1 Lease (net.i2p.data.Lease)1 LeaseSet (net.i2p.data.LeaseSet)1 PublicKey (net.i2p.data.PublicKey)1 AbuseReason (net.i2p.data.i2cp.AbuseReason)1