- Prep for delivery of detailed failure codes to the client (ticket #788)
   - Store session ID as an int instead of a long
   - Clean up some duplicate createRateStat calls (ticket #787 comment 2)
   - Other optimizations, cleanups, final
This commit is contained in:
zzz
2012-12-26 14:29:49 +00:00
parent f4740d2639
commit 38214cf5be
18 changed files with 259 additions and 66 deletions

View File

@@ -6,6 +6,7 @@ import java.io.OutputStream;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import net.i2p.data.i2cp.I2CPMessage;
import net.i2p.data.i2cp.I2CPMessageException;
@@ -20,10 +21,10 @@ import net.i2p.util.I2PAppThread;
* @author zzz from net.i2p.router.client.ClientWriterRunner
*/
class ClientWriterRunner implements Runnable {
private OutputStream _out;
private I2PSessionImpl _session;
private BlockingQueue<I2CPMessage> _messagesToWrite;
private static volatile long __Id = 0;
private final OutputStream _out;
private final I2PSessionImpl _session;
private final BlockingQueue<I2CPMessage> _messagesToWrite;
private static final AtomicLong __Id = new AtomicLong();
private static final int MAX_QUEUE_SIZE = 32;
private static final long MAX_SEND_WAIT = 10*1000;
@@ -33,7 +34,7 @@ class ClientWriterRunner implements Runnable {
_out = new BufferedOutputStream(out);
_session = session;
_messagesToWrite = new LinkedBlockingQueue(MAX_QUEUE_SIZE);
Thread t = new I2PAppThread(this, "I2CP Client Writer " + (++__Id), true);
Thread t = new I2PAppThread(this, "I2CP Client Writer " + __Id.incrementAndGet(), true);
t.start();
}

View File

@@ -218,10 +218,7 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 {
/**
* See SendMessageOptions for option details.
*
* Always uses sendNoEffort for now. These are presumed to be datagrams.
* SendMessageOptions 16-bit flag field is currently undefined, so
* serialization won't work; therefore this only makes sense in RouterContext,
* for now.
* Always uses sendNoEffort for now.
*
* @param proto 1-254 or 0 for unset; recommended:
* I2PSession.PROTO_UNSPECIFIED
@@ -294,7 +291,7 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 {
}
protected class MuxedAvailabilityNotifier extends AvailabilityNotifier {
private LinkedBlockingQueue<MsgData> _msgs;
private final LinkedBlockingQueue<MsgData> _msgs;
private volatile boolean _alive = false;
private static final int POISON_SIZE = -99999;
private final AtomicBoolean stopping = new AtomicBoolean(false);
@@ -364,7 +361,7 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 {
/** let's keep this simple */
private static class MsgData {
public int id, size, proto, fromPort, toPort;
public final int id, size, proto, fromPort, toPort;
public MsgData(int i, int s, int p, int f, int t) {
id = i;
size = s;

View File

@@ -24,7 +24,7 @@ import net.i2p.data.Payload;
*/
public class MessagePayloadMessage extends I2CPMessageImpl {
public final static int MESSAGE_TYPE = 31;
private long _sessionId;
private int _sessionId;
private long _messageId;
private Payload _payload;
@@ -37,8 +37,9 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
return _sessionId;
}
/** @param id 0-65535 */
public void setSessionId(long id) {
_sessionId = id;
_sessionId = (int) id;
}
public long getMessageId() {
@@ -60,7 +61,7 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
@Override
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
try {
_sessionId = DataHelper.readLong(in, 2);
_sessionId = (int) DataHelper.readLong(in, 2);
_messageId = DataHelper.readLong(in, 4);
_payload = new Payload();
_payload.readBytes(in);

View File

@@ -17,28 +17,166 @@ import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper;
/**
* Defines the message a client sends to a router when destroying
* existing session.
* Defines the message a router sends to a client about a single message.
* For incoming messages, it tells the client that a new message is available.
* For outgoing messages, it tells the client whether the message was delivered.
*
* @author jrandom
*/
public class MessageStatusMessage extends I2CPMessageImpl {
public final static int MESSAGE_TYPE = 22;
private long _sessionId;
private int _sessionId;
private long _messageId;
private long _nonce;
private long _size;
private int _status;
/**
* For incoming messages. All the rest are for outgoing.
*/
public final static int STATUS_AVAILABLE = 0;
public final static int STATUS_SEND_ACCEPTED = 1;
/** unused */
public final static int STATUS_SEND_BEST_EFFORT_SUCCESS = 2;
/** unused */
public final static int STATUS_SEND_BEST_EFFORT_FAILURE = 3;
/**
* Generic success.
* May not really be guaranteed, as the best-effort
* success code is unused.
*/
public final static int STATUS_SEND_GUARANTEED_SUCCESS = 4;
/**
* Generic failure, specific cause unknown.
* May not really be a guaranteed failure, as the best-effort
* failure code is unused.
*/
public final static int STATUS_SEND_GUARANTEED_FAILURE = 5;
/**
* The far-end destination is local and we are pretty darn sure
* the delivery succeeded.
* @since 0.9.5
*/
public final static int STATUS_SEND_SUCCESS_LOCAL = 6;
/**
* The far-end destination is local but delivery failed for some reason.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_LOCAL = 7;
/**
* The router is not ready, has shut down, or has major problems.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_ROUTER = 8;
/**
* The PC apparently has no network connectivity at all.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_NETWORK = 9;
/**
* The session is invalid or closed.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_BAD_SESSION = 10;
/**
* The message payload is invalid or zero-length or too big.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_BAD_MESSAGE = 11;
/**
* Something is invalid in the message options, or the expiration
* is too far in the future.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_BAD_OPTIONS = 12;
/**
* Some queue or buffer in the router is full and the message was dropped.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_OVERFLOW = 13;
/**
* Message expired before it could be sent.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_EXPIRED = 14;
/**
* Local leaseset problems. The client has not yet signed
* a leaseset, or the local keys are invalid, or it has expired,
* or it does not have any tunnels in it.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_LOCAL_LEASESET = 15;
/**
* Local problems - no outbound tunnel to send through,
* or no inbound tunnel if a reply is required.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_NO_TUNNELS = 16;
/**
* The certs or options in the destination or leaseset indicate that
* it uses an encryption format that we don't support, so we can't talk to it.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_UNSUPPORTED_ENCRYPTION = 17;
/**
* Something strange is wrong with the far-end destination.
* Bad format, unsupported options, certificates, etc.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_DESTINATION = 18;
/**
* We got the far-end leaseset but something strange is wrong with it.
* Unsupported options or certificates, no tunnels, etc.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_BAD_LEASESET = 19;
/**
* We got the far-end leaseset but it's expired and can't get a new one.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_EXPIRED_LEASESET = 20;
/**
* Could not find the far-end destination's lease set.
* This is a common failure, equivalent to a DNS lookup fail.
* This is a guaranteed failure.
* @since 0.9.5
*/
public final static int STATUS_SEND_FAILURE_NO_LEASESET = 21;
public MessageStatusMessage() {
_sessionId = -1;
_status = -1;
@@ -51,18 +189,40 @@ public class MessageStatusMessage extends I2CPMessageImpl {
return _sessionId;
}
/** @param id 0-65535 */
public void setSessionId(long id) {
_sessionId = id;
_sessionId = (int) id;
}
public int getStatus() {
return _status;
}
/** @param status 0-255 */
public void setStatus(int status) {
_status = status;
}
/**
* Is the status code a success status code?
* @since 0.9.5
*/
public boolean isSuccessful() {
return isSuccessful(_status);
}
/**
* Is the status code a success status code?
* @since 0.9.5
*/
public static boolean isSuccessful(int status) {
return status == STATUS_SEND_GUARANTEED_SUCCESS ||
status == STATUS_SEND_BEST_EFFORT_SUCCESS ||
status == STATUS_SEND_SUCCESS_LOCAL ||
status == STATUS_SEND_ACCEPTED ||
status == STATUS_AVAILABLE;
}
public long getMessageId() {
return _messageId;
}
@@ -95,21 +255,19 @@ public class MessageStatusMessage extends I2CPMessageImpl {
return "SEND ACCEPTED ";
case STATUS_SEND_BEST_EFFORT_SUCCESS:
return "BEST EFFORT SUCCESS";
case STATUS_SEND_BEST_EFFORT_FAILURE:
return "BEST EFFORT FAILURE";
case STATUS_SEND_GUARANTEED_SUCCESS:
return "GUARANTEED SUCCESS ";
case STATUS_SEND_GUARANTEED_FAILURE:
return "GUARANTEED FAILURE ";
case STATUS_SEND_SUCCESS_LOCAL:
return "LOCAL SUCCESS ";
default:
return "***INVALID STATUS: " + status;
return "SEND FAILURE CODE: " + status;
}
}
@Override
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
try {
_sessionId = DataHelper.readLong(in, 2);
_sessionId = (int) DataHelper.readLong(in, 2);
_messageId = DataHelper.readLong(in, 4);
_status = (int) DataHelper.readLong(in, 1);
_size = DataHelper.readLong(in, 4);

View File

@@ -24,7 +24,7 @@ import net.i2p.data.DataHelper;
*/
public class ReceiveMessageBeginMessage extends I2CPMessageImpl {
public final static int MESSAGE_TYPE = 6;
private long _sessionId;
private int _sessionId;
private long _messageId;
public ReceiveMessageBeginMessage() {
@@ -36,8 +36,9 @@ public class ReceiveMessageBeginMessage extends I2CPMessageImpl {
return _sessionId;
}
/** @param id 0-65535 */
public void setSessionId(long id) {
_sessionId = id;
_sessionId = (int) id;
}
public long getMessageId() {
@@ -51,7 +52,7 @@ public class ReceiveMessageBeginMessage extends I2CPMessageImpl {
@Override
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
try {
_sessionId = DataHelper.readLong(in, 2);
_sessionId = (int) DataHelper.readLong(in, 2);
_messageId = DataHelper.readLong(in, 4);
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Unable to load the message data", dfe);

View File

@@ -23,7 +23,7 @@ import net.i2p.data.DataHelper;
*/
public class ReceiveMessageEndMessage extends I2CPMessageImpl {
public final static int MESSAGE_TYPE = 7;
private long _sessionId;
private int _sessionId;
private long _messageId;
public ReceiveMessageEndMessage() {
@@ -35,8 +35,9 @@ public class ReceiveMessageEndMessage extends I2CPMessageImpl {
return _sessionId;
}
/** @param id 0-65535 */
public void setSessionId(long id) {
_sessionId = id;
_sessionId = (int) id;
}
public long getMessageId() {
@@ -50,7 +51,7 @@ public class ReceiveMessageEndMessage extends I2CPMessageImpl {
@Override
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
try {
_sessionId = DataHelper.readLong(in, 2);
_sessionId = (int) DataHelper.readLong(in, 2);
_messageId = DataHelper.readLong(in, 4);
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Unable to load the message data", dfe);

View File

@@ -33,6 +33,7 @@ public class SessionId extends DataStructureImpl {
return _sessionId;
}
/** @param id 0-65535 */
public void setSessionId(int id) {
_sessionId = id;
}