I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 6d4a9abd authored by zzz's avatar zzz
Browse files

- Fix major bug from 2005 that corrupted outbound messages

      that were an exact multiple of the fragment size.
parent 533f7620
No related branches found
No related tags found
No related merge requests found
...@@ -148,9 +148,11 @@ class OutboundMessageState { ...@@ -148,9 +148,11 @@ class OutboundMessageState {
public long getMessageId() { return _messageId; } public long getMessageId() { return _messageId; }
public PeerState getPeer() { return _peer; } public PeerState getPeer() { return _peer; }
public void setPeer(PeerState peer) { _peer = peer; } public void setPeer(PeerState peer) { _peer = peer; }
public boolean isExpired() { public boolean isExpired() {
return _expiration < _context.clock().now(); return _expiration < _context.clock().now();
} }
public boolean isComplete() { public boolean isComplete() {
short sends[] = _fragmentSends; short sends[] = _fragmentSends;
if (sends == null) return false; if (sends == null) return false;
...@@ -160,6 +162,7 @@ class OutboundMessageState { ...@@ -160,6 +162,7 @@ class OutboundMessageState {
// nothing else pending ack // nothing else pending ack
return true; return true;
} }
public int getUnackedSize() { public int getUnackedSize() {
short fragmentSends[] = _fragmentSends; short fragmentSends[] = _fragmentSends;
ByteArray messageBuf = _messageBuf; ByteArray messageBuf = _messageBuf;
...@@ -180,6 +183,7 @@ class OutboundMessageState { ...@@ -180,6 +183,7 @@ class OutboundMessageState {
} }
return rv; return rv;
} }
public boolean needsSending(int fragment) { public boolean needsSending(int fragment) {
short sends[] = _fragmentSends; short sends[] = _fragmentSends;
...@@ -187,6 +191,7 @@ class OutboundMessageState { ...@@ -187,6 +191,7 @@ class OutboundMessageState {
return false; return false;
return (sends[fragment] >= (short)0); return (sends[fragment] >= (short)0);
} }
public long getLifetime() { return _context.clock().now() - _startedOn; } public long getLifetime() { return _context.clock().now() - _startedOn; }
/** /**
...@@ -227,6 +232,7 @@ class OutboundMessageState { ...@@ -227,6 +232,7 @@ class OutboundMessageState {
public void setNextSendTime(long when) { _nextSendTime = when; } public void setNextSendTime(long when) { _nextSendTime = when; }
public int getMaxSends() { return _maxSends; } public int getMaxSends() { return _maxSends; }
public int getPushCount() { return _pushCount; } public int getPushCount() { return _pushCount; }
/** note that we have pushed the message fragments */ /** note that we have pushed the message fragments */
public void push() { public void push() {
_pushCount++; _pushCount++;
...@@ -238,7 +244,9 @@ class OutboundMessageState { ...@@ -238,7 +244,9 @@ class OutboundMessageState {
_fragmentSends[i] = (short)(1 + _fragmentSends[i]); _fragmentSends[i] = (short)(1 + _fragmentSends[i]);
} }
public boolean isFragmented() { return _fragmentSends != null; } public boolean isFragmented() { return _fragmentSends != null; }
/** /**
* Prepare the message for fragmented delivery, using no more than * Prepare the message for fragmented delivery, using no more than
* fragmentSize bytes per fragment. * fragmentSize bytes per fragment.
...@@ -258,10 +266,11 @@ class OutboundMessageState { ...@@ -258,10 +266,11 @@ class OutboundMessageState {
//_fragmentEnd = new int[numFragments]; //_fragmentEnd = new int[numFragments];
_fragmentSends = new short[numFragments]; _fragmentSends = new short[numFragments];
//Arrays.fill(_fragmentEnd, -1); //Arrays.fill(_fragmentEnd, -1);
Arrays.fill(_fragmentSends, (short)0); //Arrays.fill(_fragmentSends, (short)0);
_fragmentSize = fragmentSize; _fragmentSize = fragmentSize;
} }
/** how many fragments in the message */ /** how many fragments in the message */
public int getFragmentCount() { public int getFragmentCount() {
if (_fragmentSends == null) if (_fragmentSends == null)
...@@ -269,17 +278,21 @@ class OutboundMessageState { ...@@ -269,17 +278,21 @@ class OutboundMessageState {
else else
return _fragmentSends.length; return _fragmentSends.length;
} }
public int getFragmentSize() { return _fragmentSize; } public int getFragmentSize() { return _fragmentSize; }
/** should we continue sending this fragment? */ /** should we continue sending this fragment? */
public boolean shouldSend(int fragmentNum) { return _fragmentSends[fragmentNum] >= (short)0; } public boolean shouldSend(int fragmentNum) { return _fragmentSends[fragmentNum] >= (short)0; }
public int fragmentSize(int fragmentNum) { public int fragmentSize(int fragmentNum) {
if (_messageBuf == null) return -1; if (_messageBuf == null) return -1;
if (fragmentNum + 1 == _fragmentSends.length) { if (fragmentNum + 1 == _fragmentSends.length) {
int valid = _messageBuf.getValid(); int valid = _messageBuf.getValid();
if (valid <= _fragmentSize) if (valid <= _fragmentSize)
return valid; return valid;
else // bugfix 0.8.12
return valid % _fragmentSize; int mod = valid % _fragmentSize;
return mod == 0 ? _fragmentSize : mod;
} else { } else {
return _fragmentSize; return _fragmentSize;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment