use of net.i2p.data.i2cp.MessagePayloadMessage in project i2p.i2p by i2p.
the class I2PSessionImpl method receiveMessage.
/**
* Pull the unencrypted data from the message that we've already prefetched and
* notified the user that its available.
*/
public byte[] receiveMessage(int msgId) throws I2PSessionException {
MessagePayloadMessage msg = _availableMessages.remove(Long.valueOf(msgId));
if (msg == null) {
_log.error("Receive message " + msgId + " had no matches");
return null;
}
updateActivity();
return msg.getPayload().getUnencryptedData();
}
use of net.i2p.data.i2cp.MessagePayloadMessage in project i2p.i2p by i2p.
the class MessagePayloadMessageHandler method handleMessage.
public void handleMessage(I2CPMessage message, I2PSessionImpl session) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Handle message " + message + " for session " + session);
try {
MessagePayloadMessage msg = (MessagePayloadMessage) message;
long id = msg.getMessageId();
decryptPayload(msg, session);
session.addNewMessage(msg);
// (needs router version saving support in SetDateMessageHandler)
if (!session.getFastReceive()) {
ReceiveMessageEndMessage m = new ReceiveMessageEndMessage();
m.setMessageId(id);
m.setSessionId(msg.getSessionId());
session.sendMessage(m);
}
} catch (DataFormatException dfe) {
session.propogateError("Error handling a new payload message", dfe);
} catch (I2PSessionException ise) {
session.propogateError("Error handling a new payload message", ise);
}
}
use of net.i2p.data.i2cp.MessagePayloadMessage in project i2p.i2p by i2p.
the class ClientMessageEventListener method handleReceiveBegin.
/**
* The client asked for a message, so we send it to them.
*
* This is only when not in fast receive mode.
* In the default fast receive mode, data is sent in MessageReceivedJob.
*/
private void handleReceiveBegin(ReceiveMessageBeginMessage message) {
if (_runner.isDead())
return;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Handling receive begin: id = " + message.getMessageId());
MessagePayloadMessage msg = new MessagePayloadMessage();
msg.setMessageId(message.getMessageId());
// TODO validate session id
msg.setSessionId(message.getSessionId());
Payload payload = _runner.getPayload(new MessageId(message.getMessageId()));
if (payload == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("Payload for message id [" + message.getMessageId() + "] is null! Dropped or Unknown message id");
return;
}
msg.setPayload(payload);
try {
_runner.doSend(msg);
} catch (I2CPMessageException ime) {
String emsg = "Error sending data to client " + _runner.getDestHash();
if (_log.shouldWarn())
_log.warn(emsg, ime);
else
_log.logAlways(Log.WARN, emsg);
_runner.removePayload(new MessageId(message.getMessageId()));
}
}
use of net.i2p.data.i2cp.MessagePayloadMessage in project i2p.i2p by i2p.
the class MessageReceivedJob method sendMessage.
/**
* Deliver the message directly, skip notification
* @since 0.9.4
*/
private void sendMessage(long id) throws I2CPMessageException {
MessagePayloadMessage msg = new MessagePayloadMessage();
msg.setMessageId(id);
SessionId sid = _runner.getSessionId(_toDest.calculateHash());
if (sid == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("No session for " + _toDest.calculateHash());
return;
}
msg.setSessionId(sid.getSessionId());
msg.setPayload(_payload);
_runner.doSend(msg);
}
Aggregations