Search in sources :

Example 1 with HostReplyMessage

use of net.i2p.data.i2cp.HostReplyMessage 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 2 with HostReplyMessage

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

the class HostReplyMessageHandler method handleMessage.

public void handleMessage(I2CPMessage message, I2PSessionImpl session) {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Handle message " + message);
    HostReplyMessage msg = (HostReplyMessage) message;
    Destination d = msg.getDestination();
    long id = msg.getReqID();
    if (d != null) {
        session.destReceived(id, d);
    } else {
        session.destLookupFailed(id);
    }
}
Also used : Destination(net.i2p.data.Destination) HostReplyMessage(net.i2p.data.i2cp.HostReplyMessage)

Aggregations

Destination (net.i2p.data.Destination)2 HostReplyMessage (net.i2p.data.i2cp.HostReplyMessage)2 Hash (net.i2p.data.Hash)1 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)1 SessionId (net.i2p.data.i2cp.SessionId)1