Search in sources :

Example 1 with SendMessageMessage

use of net.i2p.data.i2cp.SendMessageMessage 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.9.2
 */
public void sendMessage(I2PSessionImpl session, Destination dest, long nonce, byte[] payload, SendMessageOptions options) throws I2PSessionException {
    long expires = options.getTime();
    if (!updateBps(payload.length, expires))
        // drop the message... send fail notification?
        return;
    SendMessageMessage msg = new SendMessageExpiresMessage(options);
    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 2 with SendMessageMessage

use of net.i2p.data.i2cp.SendMessageMessage 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)

Aggregations

I2PSessionException (net.i2p.client.I2PSessionException)2 DataFormatException (net.i2p.data.DataFormatException)2 Payload (net.i2p.data.Payload)2 SendMessageExpiresMessage (net.i2p.data.i2cp.SendMessageExpiresMessage)2 SendMessageMessage (net.i2p.data.i2cp.SendMessageMessage)2 SessionId (net.i2p.data.i2cp.SessionId)2