/** * Send a message and request an asynchronous notification of delivery status. * * See I2PSessionMuxedImpl for proto/port details. * See SendMessageOptions for option details. * * @return the message ID to be used for later notification to the listener * @throws I2PSessionException on all errors * @since 0.9.14 */ @Override public long sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options, SendMessageStatusListener listener) throws I2PSessionException { payload = prepPayload(payload, offset, size, proto, fromPort, toPort, options.getGzip()); long nonce = _sendMessageNonce.incrementAndGet(); long expires = Math.max(_context.clock().now() + 60*1000L, options.getTime()); MessageState state = new MessageState(_context, nonce, this, expires, listener); _sendingStates.put(Long.valueOf(nonce), state); _producer.sendMessage(this, dest, nonce, payload, options); return nonce; }
/** * 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(payload); msg.setPayload(data); session.sendMessage(msg); }