2005-07-22 jrandom
* Use the small thread pool for I2PTunnelHTTPServer (already used for I2PTunnelServer) * Minor memory churn reduction in I2CP * Small stats update
This commit is contained in:
@ -29,20 +29,27 @@ import net.i2p.util.Log;
|
||||
class I2PClientMessageHandlerMap {
|
||||
private final static Log _log = new Log(I2PClientMessageHandlerMap.class);
|
||||
/** map of message type id --> I2CPMessageHandler */
|
||||
private Map _handlers;
|
||||
private I2CPMessageHandler _handlers[];
|
||||
|
||||
public I2PClientMessageHandlerMap(I2PAppContext context) {
|
||||
_handlers = new HashMap();
|
||||
_handlers.put(new Integer(DisconnectMessage.MESSAGE_TYPE), new DisconnectMessageHandler(context));
|
||||
_handlers.put(new Integer(SessionStatusMessage.MESSAGE_TYPE), new SessionStatusMessageHandler(context));
|
||||
_handlers.put(new Integer(RequestLeaseSetMessage.MESSAGE_TYPE), new RequestLeaseSetMessageHandler(context));
|
||||
_handlers.put(new Integer(MessagePayloadMessage.MESSAGE_TYPE), new MessagePayloadMessageHandler(context));
|
||||
_handlers.put(new Integer(MessageStatusMessage.MESSAGE_TYPE), new MessageStatusMessageHandler(context));
|
||||
_handlers.put(new Integer(SetDateMessage.MESSAGE_TYPE), new SetDateMessageHandler(context));
|
||||
int highest = DisconnectMessage.MESSAGE_TYPE;
|
||||
highest = Math.max(highest, SessionStatusMessage.MESSAGE_TYPE);
|
||||
highest = Math.max(highest, RequestLeaseSetMessage.MESSAGE_TYPE);
|
||||
highest = Math.max(highest, MessagePayloadMessage.MESSAGE_TYPE);
|
||||
highest = Math.max(highest, MessageStatusMessage.MESSAGE_TYPE);
|
||||
highest = Math.max(highest, SetDateMessage.MESSAGE_TYPE);
|
||||
|
||||
_handlers = new I2CPMessageHandler[highest+1];
|
||||
_handlers[DisconnectMessage.MESSAGE_TYPE] = new DisconnectMessageHandler(context);
|
||||
_handlers[SessionStatusMessage.MESSAGE_TYPE] = new SessionStatusMessageHandler(context);
|
||||
_handlers[RequestLeaseSetMessage.MESSAGE_TYPE] = new RequestLeaseSetMessageHandler(context);
|
||||
_handlers[MessagePayloadMessage.MESSAGE_TYPE] = new MessagePayloadMessageHandler(context);
|
||||
_handlers[MessageStatusMessage.MESSAGE_TYPE] = new MessageStatusMessageHandler(context);
|
||||
_handlers[SetDateMessage.MESSAGE_TYPE] = new SetDateMessageHandler(context);
|
||||
}
|
||||
|
||||
public I2CPMessageHandler getHandler(int messageTypeId) {
|
||||
I2CPMessageHandler handler = (I2CPMessageHandler) _handlers.get(new Integer(messageTypeId));
|
||||
return handler;
|
||||
if ( (messageTypeId < 0) || (messageTypeId >= _handlers.length) ) return null;
|
||||
return _handlers[messageTypeId];
|
||||
}
|
||||
}
|
@ -78,7 +78,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
|
||||
/** class that generates new messages */
|
||||
protected I2CPMessageProducer _producer;
|
||||
/** map of integer --> MessagePayloadMessage */
|
||||
/** map of Long --> MessagePayloadMessage */
|
||||
private Map _availableMessages;
|
||||
|
||||
protected I2PClientMessageHandlerMap _handlerMap;
|
||||
@ -295,7 +295,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
public byte[] receiveMessage(int msgId) throws I2PSessionException {
|
||||
MessagePayloadMessage msg = null;
|
||||
synchronized (_availableMessages) {
|
||||
msg = (MessagePayloadMessage) _availableMessages.remove(new Integer(msgId));
|
||||
msg = (MessagePayloadMessage) _availableMessages.remove(new Long(msgId));
|
||||
}
|
||||
if (msg == null) return null;
|
||||
return msg.getPayload().getUnencryptedData();
|
||||
@ -346,9 +346,9 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
*/
|
||||
public void addNewMessage(MessagePayloadMessage msg) {
|
||||
synchronized (_availableMessages) {
|
||||
_availableMessages.put(new Integer(msg.getMessageId().getMessageId()), msg);
|
||||
_availableMessages.put(new Long(msg.getMessageId()), msg);
|
||||
}
|
||||
int id = msg.getMessageId().getMessageId();
|
||||
long id = msg.getMessageId();
|
||||
byte data[] = msg.getPayload().getUnencryptedData();
|
||||
if ((data == null) || (data.length <= 0)) {
|
||||
if (_log.shouldLog(Log.CRIT))
|
||||
@ -363,12 +363,12 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
SimpleTimer.getInstance().addEvent(new VerifyUsage(id), 30*1000);
|
||||
}
|
||||
private class VerifyUsage implements SimpleTimer.TimedEvent {
|
||||
private int _msgId;
|
||||
public VerifyUsage(int id) { _msgId = id; }
|
||||
private long _msgId;
|
||||
public VerifyUsage(long id) { _msgId = id; }
|
||||
public void timeReached() {
|
||||
MessagePayloadMessage removed = null;
|
||||
synchronized (_availableMessages) {
|
||||
removed = (MessagePayloadMessage)_availableMessages.remove(new Integer(_msgId));
|
||||
removed = (MessagePayloadMessage)_availableMessages.remove(new Long(_msgId));
|
||||
}
|
||||
if (removed != null)
|
||||
_log.log(Log.CRIT, "Message NOT removed! id=" + _msgId + ": " + removed);
|
||||
@ -393,9 +393,9 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
}
|
||||
}
|
||||
|
||||
public void available(int msgId, int size) {
|
||||
public void available(long msgId, int size) {
|
||||
synchronized (AvailabilityNotifier.this) {
|
||||
_pendingIds.add(new Integer(msgId));
|
||||
_pendingIds.add(new Long(msgId));
|
||||
_pendingSizes.add(new Integer(size));
|
||||
AvailabilityNotifier.this.notifyAll();
|
||||
}
|
||||
@ -403,7 +403,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
public void run() {
|
||||
_alive = true;
|
||||
while (_alive) {
|
||||
Integer msgId = null;
|
||||
Long msgId = null;
|
||||
Integer size = null;
|
||||
synchronized (AvailabilityNotifier.this) {
|
||||
if (_pendingIds.size() <= 0) {
|
||||
@ -413,7 +413,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
}
|
||||
}
|
||||
if (_pendingIds.size() > 0) {
|
||||
msgId = (Integer)_pendingIds.remove(0);
|
||||
msgId = (Long)_pendingIds.remove(0);
|
||||
size = (Integer)_pendingSizes.remove(0);
|
||||
}
|
||||
}
|
||||
@ -532,8 +532,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
* Pass off the error to the listener
|
||||
*/
|
||||
void propogateError(String msg, Throwable error) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error(getPrefix() + "Error occurred: " + msg + " - " + error.getMessage());
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn(getPrefix() + "Error occurred: " + msg + " - " + error.getMessage());
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn(getPrefix() + " cause", error);
|
||||
|
||||
|
@ -35,7 +35,7 @@ class MessagePayloadMessageHandler extends HandlerImpl {
|
||||
_log.debug("Handle message " + message);
|
||||
try {
|
||||
MessagePayloadMessage msg = (MessagePayloadMessage) message;
|
||||
MessageId id = msg.getMessageId();
|
||||
long id = msg.getMessageId();
|
||||
Payload payload = decryptPayload(msg, session);
|
||||
session.addNewMessage(msg);
|
||||
|
||||
|
@ -46,7 +46,7 @@ class MessageStatusMessageHandler extends HandlerImpl {
|
||||
}
|
||||
return;
|
||||
case MessageStatusMessage.STATUS_SEND_ACCEPTED:
|
||||
session.receiveStatus(msg.getMessageId().getMessageId(), msg.getNonce(), msg.getStatus());
|
||||
session.receiveStatus((int)msg.getMessageId(), msg.getNonce(), msg.getStatus());
|
||||
// noop
|
||||
return;
|
||||
case MessageStatusMessage.STATUS_SEND_BEST_EFFORT_SUCCESS:
|
||||
@ -54,14 +54,14 @@ class MessageStatusMessageHandler extends HandlerImpl {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Message delivery succeeded for message " + msg.getMessageId());
|
||||
//if (!skipStatus)
|
||||
session.receiveStatus(msg.getMessageId().getMessageId(), msg.getNonce(), msg.getStatus());
|
||||
session.receiveStatus((int)msg.getMessageId(), msg.getNonce(), msg.getStatus());
|
||||
return;
|
||||
case MessageStatusMessage.STATUS_SEND_BEST_EFFORT_FAILURE:
|
||||
case MessageStatusMessage.STATUS_SEND_GUARANTEED_FAILURE:
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Message delivery FAILED for message " + msg.getMessageId());
|
||||
//if (!skipStatus)
|
||||
session.receiveStatus(msg.getMessageId().getMessageId(), msg.getNonce(), msg.getStatus());
|
||||
session.receiveStatus((int)msg.getMessageId(), msg.getNonce(), msg.getStatus());
|
||||
return;
|
||||
default:
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
|
@ -61,6 +61,7 @@ public abstract class I2CPMessageImpl extends DataStructureImpl implements I2CPM
|
||||
+ " class: " + getClass().getName() + ")");
|
||||
if (length < 0) throw new IOException("Negative payload size");
|
||||
|
||||
/*
|
||||
byte buf[] = new byte[length];
|
||||
int read = DataHelper.read(in, buf);
|
||||
if (read != length)
|
||||
@ -69,6 +70,8 @@ public abstract class I2CPMessageImpl extends DataStructureImpl implements I2CPM
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(buf);
|
||||
|
||||
doReadMessage(bis, length);
|
||||
*/
|
||||
doReadMessage(in, length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,22 +26,25 @@ import net.i2p.util.Log;
|
||||
*/
|
||||
public class MessageId extends DataStructureImpl {
|
||||
private final static Log _log = new Log(MessageId.class);
|
||||
private int _messageId;
|
||||
private long _messageId;
|
||||
|
||||
public MessageId() {
|
||||
setMessageId(-1);
|
||||
}
|
||||
public MessageId(long id) {
|
||||
setMessageId(id);
|
||||
}
|
||||
|
||||
public int getMessageId() {
|
||||
public long getMessageId() {
|
||||
return _messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(int id) {
|
||||
public void setMessageId(long id) {
|
||||
_messageId = id;
|
||||
}
|
||||
|
||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||
_messageId = (int) DataHelper.readLong(in, 4);
|
||||
_messageId = DataHelper.readLong(in, 4);
|
||||
}
|
||||
|
||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||
@ -55,7 +58,7 @@ public class MessageId extends DataStructureImpl {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return getMessageId();
|
||||
return (int)getMessageId();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -27,29 +27,29 @@ import net.i2p.util.Log;
|
||||
public class MessagePayloadMessage extends I2CPMessageImpl {
|
||||
private final static Log _log = new Log(MessagePayloadMessage.class);
|
||||
public final static int MESSAGE_TYPE = 31;
|
||||
private SessionId _sessionId;
|
||||
private MessageId _messageId;
|
||||
private long _sessionId;
|
||||
private long _messageId;
|
||||
private Payload _payload;
|
||||
|
||||
public MessagePayloadMessage() {
|
||||
setSessionId(null);
|
||||
setMessageId(null);
|
||||
setSessionId(-1);
|
||||
setMessageId(-1);
|
||||
setPayload(null);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
public long getSessionId() {
|
||||
return _sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(SessionId id) {
|
||||
public void setSessionId(long id) {
|
||||
_sessionId = id;
|
||||
}
|
||||
|
||||
public MessageId getMessageId() {
|
||||
public long getMessageId() {
|
||||
return _messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(MessageId id) {
|
||||
public void setMessageId(long id) {
|
||||
_messageId = id;
|
||||
}
|
||||
|
||||
@ -63,10 +63,8 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
|
||||
|
||||
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
|
||||
try {
|
||||
_sessionId = new SessionId();
|
||||
_sessionId.readBytes(in);
|
||||
_messageId = new MessageId();
|
||||
_messageId.readBytes(in);
|
||||
_sessionId = DataHelper.readLong(in, 2);
|
||||
_messageId = DataHelper.readLong(in, 4);
|
||||
_payload = new Payload();
|
||||
_payload.readBytes(in);
|
||||
} catch (DataFormatException dfe) {
|
||||
@ -84,9 +82,9 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
|
||||
*
|
||||
*/
|
||||
public void writeMessage(OutputStream out) throws I2CPMessageException, IOException {
|
||||
if (_sessionId == null)
|
||||
if (_sessionId <= 0)
|
||||
throw new I2CPMessageException("Unable to write out the message, as the session ID has not been defined");
|
||||
if (_messageId == null)
|
||||
if (_messageId < 0)
|
||||
throw new I2CPMessageException("Unable to write out the message, as the message ID has not been defined");
|
||||
if (_payload == null)
|
||||
throw new I2CPMessageException("Unable to write out the message, as the payload has not been defined");
|
||||
@ -95,8 +93,8 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
|
||||
try {
|
||||
DataHelper.writeLong(out, 4, size);
|
||||
DataHelper.writeLong(out, 1, getType());
|
||||
DataHelper.writeLong(out, 2, _sessionId.getSessionId());
|
||||
DataHelper.writeLong(out, 4, _messageId.getMessageId());
|
||||
DataHelper.writeLong(out, 2, _sessionId);
|
||||
DataHelper.writeLong(out, 4, _messageId);
|
||||
DataHelper.writeLong(out, 4, _payload.getSize());
|
||||
out.write(_payload.getEncryptedData());
|
||||
} catch (DataFormatException dfe) {
|
||||
|
@ -12,6 +12,7 @@ package net.i2p.data.i2cp;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataHelper;
|
||||
@ -26,8 +27,8 @@ import net.i2p.util.Log;
|
||||
public class MessageStatusMessage extends I2CPMessageImpl {
|
||||
private final static Log _log = new Log(SessionStatusMessage.class);
|
||||
public final static int MESSAGE_TYPE = 22;
|
||||
private SessionId _sessionId;
|
||||
private MessageId _messageId;
|
||||
private long _sessionId;
|
||||
private long _messageId;
|
||||
private long _nonce;
|
||||
private long _size;
|
||||
private int _status;
|
||||
@ -40,18 +41,18 @@ public class MessageStatusMessage extends I2CPMessageImpl {
|
||||
public final static int STATUS_SEND_GUARANTEED_FAILURE = 5;
|
||||
|
||||
public MessageStatusMessage() {
|
||||
setSessionId(null);
|
||||
setSessionId(-1);
|
||||
setStatus(-1);
|
||||
setMessageId(null);
|
||||
setMessageId(-1);
|
||||
setSize(-1);
|
||||
setNonce(-1);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
public long getSessionId() {
|
||||
return _sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(SessionId id) {
|
||||
public void setSessionId(long id) {
|
||||
_sessionId = id;
|
||||
}
|
||||
|
||||
@ -63,11 +64,11 @@ public class MessageStatusMessage extends I2CPMessageImpl {
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public MessageId getMessageId() {
|
||||
public long getMessageId() {
|
||||
return _messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(MessageId id) {
|
||||
public void setMessageId(long id) {
|
||||
_messageId = id;
|
||||
}
|
||||
|
||||
@ -108,10 +109,8 @@ public class MessageStatusMessage extends I2CPMessageImpl {
|
||||
|
||||
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
|
||||
try {
|
||||
_sessionId = new SessionId();
|
||||
_sessionId.readBytes(in);
|
||||
_messageId = new MessageId();
|
||||
_messageId.readBytes(in);
|
||||
_sessionId = DataHelper.readLong(in, 2);
|
||||
_messageId = DataHelper.readLong(in, 4);
|
||||
_status = (int) DataHelper.readLong(in, 1);
|
||||
_size = DataHelper.readLong(in, 4);
|
||||
_nonce = DataHelper.readLong(in, 4);
|
||||
@ -120,20 +119,32 @@ public class MessageStatusMessage extends I2CPMessageImpl {
|
||||
}
|
||||
}
|
||||
|
||||
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
|
||||
if ((_sessionId == null) || (_messageId == null) || (_status < 0) || (_nonce <= 0))
|
||||
throw new I2CPMessageException("Unable to write out the message as there is not enough data");
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(64);
|
||||
|
||||
/**
|
||||
* Override to reduce mem churn
|
||||
*/
|
||||
public void writeMessage(OutputStream out) throws I2CPMessageException, IOException {
|
||||
int len = 2 + // sessionId
|
||||
4 + // messageId
|
||||
1 + // status
|
||||
4 + // size
|
||||
4; // nonce
|
||||
|
||||
try {
|
||||
_sessionId.writeBytes(os);
|
||||
_messageId.writeBytes(os);
|
||||
DataHelper.writeLong(os, 1, _status);
|
||||
DataHelper.writeLong(os, 4, _size);
|
||||
DataHelper.writeLong(os, 4, _nonce);
|
||||
DataHelper.writeLong(out, 4, len);
|
||||
DataHelper.writeLong(out, 1, getType());
|
||||
DataHelper.writeLong(out, 2, _sessionId);
|
||||
DataHelper.writeLong(out, 4, _messageId);
|
||||
DataHelper.writeLong(out, 1, _status);
|
||||
DataHelper.writeLong(out, 4, _size);
|
||||
DataHelper.writeLong(out, 4, _nonce);
|
||||
} catch (DataFormatException dfe) {
|
||||
throw new I2CPMessageException("Error writing out the message data", dfe);
|
||||
throw new I2CPMessageException("Unable to write the message length or type", dfe);
|
||||
}
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
|
||||
throw new UnsupportedOperationException("This shouldn't be called... use writeMessage(out)");
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
|
@ -12,6 +12,7 @@ package net.i2p.data.i2cp;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataHelper;
|
||||
@ -26,50 +27,62 @@ import net.i2p.util.Log;
|
||||
public class ReceiveMessageBeginMessage extends I2CPMessageImpl {
|
||||
private final static Log _log = new Log(ReceiveMessageBeginMessage.class);
|
||||
public final static int MESSAGE_TYPE = 6;
|
||||
private SessionId _sessionId;
|
||||
private MessageId _messageId;
|
||||
private long _sessionId;
|
||||
private long _messageId;
|
||||
|
||||
public ReceiveMessageBeginMessage() {
|
||||
setSessionId(null);
|
||||
setMessageId(null);
|
||||
setSessionId(-1);
|
||||
setMessageId(-1);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
public long getSessionId() {
|
||||
return _sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(SessionId id) {
|
||||
public void setSessionId(long id) {
|
||||
_sessionId = id;
|
||||
}
|
||||
|
||||
public MessageId getMessageId() {
|
||||
public long getMessageId() {
|
||||
return _messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(MessageId id) {
|
||||
public void setMessageId(long id) {
|
||||
_messageId = id;
|
||||
}
|
||||
|
||||
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
|
||||
try {
|
||||
_sessionId = new SessionId();
|
||||
_sessionId.readBytes(in);
|
||||
_messageId = new MessageId();
|
||||
_messageId.readBytes(in);
|
||||
_sessionId = DataHelper.readLong(in, 2);
|
||||
_messageId = DataHelper.readLong(in, 4);
|
||||
} catch (DataFormatException dfe) {
|
||||
throw new I2CPMessageException("Unable to load the message data", dfe);
|
||||
}
|
||||
}
|
||||
|
||||
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
|
||||
if ((_sessionId == null) || (_messageId == null))
|
||||
throw new I2CPMessageException("Unable to write out the message as there is not enough data");
|
||||
byte rv[] = new byte[2+4];
|
||||
DataHelper.toLong(rv, 0, 2, _sessionId.getSessionId());
|
||||
DataHelper.toLong(rv, 2, 4, _messageId.getMessageId());
|
||||
return rv;
|
||||
throw new UnsupportedOperationException("This shouldn't be called... use writeMessage(out)");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override to reduce mem churn
|
||||
*/
|
||||
public void writeMessage(OutputStream out) throws I2CPMessageException, IOException {
|
||||
int len = 2 + // sessionId
|
||||
4; // messageId
|
||||
|
||||
try {
|
||||
DataHelper.writeLong(out, 4, len);
|
||||
DataHelper.writeLong(out, 1, getType());
|
||||
DataHelper.writeLong(out, 2, _sessionId);
|
||||
DataHelper.writeLong(out, 4, _messageId);
|
||||
} catch (DataFormatException dfe) {
|
||||
throw new I2CPMessageException("Unable to write the message length or type", dfe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getType() {
|
||||
return MESSAGE_TYPE;
|
||||
}
|
||||
|
@ -26,47 +26,45 @@ import net.i2p.util.Log;
|
||||
public class ReceiveMessageEndMessage extends I2CPMessageImpl {
|
||||
private final static Log _log = new Log(ReceiveMessageEndMessage.class);
|
||||
public final static int MESSAGE_TYPE = 7;
|
||||
private SessionId _sessionId;
|
||||
private MessageId _messageId;
|
||||
private long _sessionId;
|
||||
private long _messageId;
|
||||
|
||||
public ReceiveMessageEndMessage() {
|
||||
setSessionId(null);
|
||||
setMessageId(null);
|
||||
setSessionId(-1);
|
||||
setMessageId(-1);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
public long getSessionId() {
|
||||
return _sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(SessionId id) {
|
||||
public void setSessionId(long id) {
|
||||
_sessionId = id;
|
||||
}
|
||||
|
||||
public MessageId getMessageId() {
|
||||
public long getMessageId() {
|
||||
return _messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(MessageId id) {
|
||||
public void setMessageId(long id) {
|
||||
_messageId = id;
|
||||
}
|
||||
|
||||
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
|
||||
try {
|
||||
_sessionId = new SessionId();
|
||||
_sessionId.readBytes(in);
|
||||
_messageId = new MessageId();
|
||||
_messageId.readBytes(in);
|
||||
_sessionId = DataHelper.readLong(in, 2);
|
||||
_messageId = DataHelper.readLong(in, 4);
|
||||
} catch (DataFormatException dfe) {
|
||||
throw new I2CPMessageException("Unable to load the message data", dfe);
|
||||
}
|
||||
}
|
||||
|
||||
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
|
||||
if ((_sessionId == null) || (_messageId == null))
|
||||
if ((_sessionId < 0) || (_messageId < 0))
|
||||
throw new I2CPMessageException("Unable to write out the message as there is not enough data");
|
||||
byte rv[] = new byte[2+4];
|
||||
DataHelper.toLong(rv, 0, 2, _sessionId.getSessionId());
|
||||
DataHelper.toLong(rv, 2, 4, _messageId.getMessageId());
|
||||
DataHelper.toLong(rv, 0, 2, _sessionId);
|
||||
DataHelper.toLong(rv, 2, 4, _messageId);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user