Added JDK5 lint fixes

Streaming lib javadocs
This commit is contained in:
sponge
2008-10-11 13:23:55 +00:00
parent ca5c15d4de
commit 41c38e64c3
11 changed files with 155 additions and 32 deletions

View File

@ -574,7 +574,9 @@ public class Connection {
} }
private boolean _remotePeerSet = false; private boolean _remotePeerSet = false;
/** who are we talking with */ /** who are we talking with
* @return peer Destination
*/
public Destination getRemotePeer() { return _remotePeer; } public Destination getRemotePeer() { return _remotePeer; }
public void setRemotePeer(Destination peer) { public void setRemotePeer(Destination peer) {
if (_remotePeerSet) throw new RuntimeException("Remote peer already set [" + _remotePeer + ", " + peer + "]"); if (_remotePeerSet) throw new RuntimeException("Remote peer already set [" + _remotePeer + ", " + peer + "]");
@ -583,7 +585,9 @@ public class Connection {
} }
private boolean _sendStreamIdSet = false; private boolean _sendStreamIdSet = false;
/** what stream do we send data to the peer on? */ /** what stream do we send data to the peer on?
* @return non-global stream sending ID
*/
public long getSendStreamId() { return _sendStreamId; } public long getSendStreamId() { return _sendStreamId; }
public void setSendStreamId(long id) { public void setSendStreamId(long id) {
if (_sendStreamIdSet) throw new RuntimeException("Send stream ID already set [" + _sendStreamId + ", " + id + "]"); if (_sendStreamIdSet) throw new RuntimeException("Send stream ID already set [" + _sendStreamId + ", " + id + "]");
@ -592,7 +596,9 @@ public class Connection {
} }
private boolean _receiveStreamIdSet = false; private boolean _receiveStreamIdSet = false;
/** stream the peer sends data to us on. (may be null) */ /** The stream ID of a peer connection that sends data to us. (may be null)
* @return receive stream ID, or null if there isn't one
*/
public long getReceiveStreamId() { return _receiveStreamId; } public long getReceiveStreamId() { return _receiveStreamId; }
public void setReceiveStreamId(long id) { public void setReceiveStreamId(long id) {
if (_receiveStreamIdSet) throw new RuntimeException("Receive stream ID already set [" + _receiveStreamId + ", " + id + "]"); if (_receiveStreamIdSet) throw new RuntimeException("Receive stream ID already set [" + _receiveStreamId + ", " + id + "]");
@ -601,15 +607,33 @@ public class Connection {
synchronized (_connectLock) { _connectLock.notifyAll(); } synchronized (_connectLock) { _connectLock.notifyAll(); }
} }
/** when did we last send anything to the peer? */ /** When did we last send anything to the peer?
* @return Last time we sent data
*/
public long getLastSendTime() { return _lastSendTime; } public long getLastSendTime() { return _lastSendTime; }
/** Set the time we sent data.
* @param when The time we sent data
*/
public void setLastSendTime(long when) { _lastSendTime = when; } public void setLastSendTime(long when) { _lastSendTime = when; }
/** what was the last packet Id sent to the peer? */ /** What was the last packet Id sent to the peer?
* @return The last sent packet ID
*/
public long getLastSendId() { return _lastSendId; } public long getLastSendId() { return _lastSendId; }
/** Set the packet Id that was sent to a peer.
* @param id The packet ID
*/
public void setLastSendId(long id) { _lastSendId = id; } public void setLastSendId(long id) { _lastSendId = id; }
/**
* Retrieve the current ConnectionOptions.
* @return the current ConnectionOptions
*/
public ConnectionOptions getOptions() { return _options; } public ConnectionOptions getOptions() { return _options; }
/**
* Set the ConnectionOptions.
* @param opts ConnectionOptions
*/
public void setOptions(ConnectionOptions opts) { _options = opts; } public void setOptions(ConnectionOptions opts) { _options = opts; }
public I2PSession getSession() { return _connectionManager.getSession(); } public I2PSession getSession() { return _connectionManager.getSession(); }
@ -641,6 +665,7 @@ public class Connection {
* Time when the scheduler next want to send a packet, or -1 if * Time when the scheduler next want to send a packet, or -1 if
* never. This should be set when we want to send on timeout, for * never. This should be set when we want to send on timeout, for
* instance, or want to delay an ACK. * instance, or want to delay an ACK.
* @return the next time the scheduler will want to send a packet, or -1 if never.
*/ */
public long getNextSendTime() { return _nextSendTime; } public long getNextSendTime() { return _nextSendTime; }
public void setNextSendTime(long when) { public void setNextSendTime(long when) {
@ -665,7 +690,9 @@ public class Connection {
} }
} }
/** how many packets have we sent and the other side has ACKed? */ /** how many packets have we sent and the other side has ACKed?
* @return Count of how many packets ACKed.
*/
public long getAckedPackets() { return _ackedPackets; } public long getAckedPackets() { return _ackedPackets; }
public long getCreatedOn() { return _createdOn; } public long getCreatedOn() { return _createdOn; }
public long getCloseSentOn() { return _closeSentOn; } public long getCloseSentOn() { return _closeSentOn; }
@ -681,7 +708,9 @@ public class Connection {
public void incrementUnackedPacketsReceived() { _unackedPacketsReceived++; } public void incrementUnackedPacketsReceived() { _unackedPacketsReceived++; }
public int getUnackedPacketsReceived() { return _unackedPacketsReceived; } public int getUnackedPacketsReceived() { return _unackedPacketsReceived; }
/** how many packets have we sent but not yet received an ACK for? */ /** how many packets have we sent but not yet received an ACK for?
* @return Count of packets in-flight.
*/
public int getUnackedPacketsSent() { public int getUnackedPacketsSent() {
synchronized (_outboundPackets) { synchronized (_outboundPackets) {
return _outboundPackets.size(); return _outboundPackets.size();
@ -857,11 +886,16 @@ public class Connection {
} }
} }
/** stream that the local peer receives data on */ /** stream that the local peer receives data on
* @return the inbound message stream
*/
public MessageInputStream getInputStream() { return _inputStream; } public MessageInputStream getInputStream() { return _inputStream; }
/** stream that the local peer sends data to the remote peer on */ /** stream that the local peer sends data to the remote peer on
* @return the outbound message stream
*/
public MessageOutputStream getOutputStream() { return _outputStream; } public MessageOutputStream getOutputStream() { return _outputStream; }
@Override
public String toString() { public String toString() {
StringBuffer buf = new StringBuffer(128); StringBuffer buf = new StringBuffer(128);
buf.append("[Connection "); buf.append("[Connection ");
@ -927,7 +961,7 @@ public class Connection {
* fired to reschedule event notification * fired to reschedule event notification
*/ */
class ConEvent implements SimpleTimer.TimedEvent { class ConEvent implements SimpleTimer.TimedEvent {
private Exception _addedBy; private Exception _addedBy; // unused?
public ConEvent() { public ConEvent() {
//_addedBy = new Exception("added by"); //_addedBy = new Exception("added by");
} }

View File

@ -104,7 +104,7 @@ public class ConnectionManager {
/** /**
* Get the socket accept() timeout. * Get the socket accept() timeout.
* @return * @return accept timeout in ms.
*/ */
public long MgetSoTimeout() { public long MgetSoTimeout() {
return SoTimeout; return SoTimeout;
@ -121,6 +121,7 @@ public class ConnectionManager {
/** /**
* Create a new connection based on the SYN packet we received. * Create a new connection based on the SYN packet we received.
* *
* @param synPacket SYN packet to process
* @return created Connection with the packet's data already delivered to * @return created Connection with the packet's data already delivered to
* it, or null if the syn's streamId was already taken * it, or null if the syn's streamId was already taken
*/ */
@ -190,7 +191,9 @@ public class ConnectionManager {
* Build a new connection to the given peer. This blocks if there is no * Build a new connection to the given peer. This blocks if there is no
* connection delay, otherwise it returns immediately. * connection delay, otherwise it returns immediately.
* *
* @return new connection, or null if we have exceeded our limit * @param peer Destination to contact
* @param opts Connection's options
* @return new connection, or null if we have exceeded our limit
*/ */
public Connection connect(Destination peer, ConnectionOptions opts) { public Connection connect(Destination peer, ConnectionOptions opts) {
Connection con = null; Connection con = null;
@ -293,6 +296,7 @@ public class ConnectionManager {
/** /**
* Drop the (already closed) connection on the floor. * Drop the (already closed) connection on the floor.
* *
* @param con Connection to drop.
*/ */
public void removeConnection(Connection con) { public void removeConnection(Connection con) {
boolean removed = false; boolean removed = false;
@ -319,7 +323,9 @@ public class ConnectionManager {
} }
} }
/** return a set of Connection objects */ /** return a set of Connection objects
* @return set of Connection objects
*/
public Set listConnections() { public Set listConnections() {
synchronized (_connectionLock) { synchronized (_connectionLock) {
return new HashSet(_connectionByInboundId.values()); return new HashSet(_connectionByInboundId.values());

View File

@ -94,6 +94,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
} }
} }
@Override
protected void init(Properties opts) { protected void init(Properties opts) {
super.init(opts); super.init(opts);
_trend = new int[TREND_COUNT]; _trend = new int[TREND_COUNT];
@ -118,6 +119,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT)); setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
} }
@Override
public void setProperties(Properties opts) { public void setProperties(Properties opts) {
super.setProperties(opts); super.setProperties(opts);
if (opts == null) return; if (opts == null) return;
@ -164,6 +166,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
* until the output stream is flushed, the buffer fills, * until the output stream is flushed, the buffer fills,
* or that many milliseconds pass. * or that many milliseconds pass.
* *
* @return how long to wait before actually attempting to connect
*/ */
public int getConnectDelay() { return _connectDelay; } public int getConnectDelay() { return _connectDelay; }
public void setConnectDelay(int delayMs) { _connectDelay = delayMs; } public void setConnectDelay(int delayMs) { _connectDelay = delayMs; }
@ -173,6 +176,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
* or can we deal with signatures on the SYN and FIN packets * or can we deal with signatures on the SYN and FIN packets
* only? * only?
* *
* @return if we want signatures on all packets.
*/ */
public boolean getRequireFullySigned() { return _fullySigned; } public boolean getRequireFullySigned() { return _fullySigned; }
public void setRequireFullySigned(boolean sign) { _fullySigned = sign; } public void setRequireFullySigned(boolean sign) { _fullySigned = sign; }
@ -180,6 +184,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
/** /**
* How many messages will we send before waiting for an ACK? * How many messages will we send before waiting for an ACK?
* *
* @return Maximum amount of messages that can be in-flight
*/ */
public int getWindowSize() { return _windowSize; } public int getWindowSize() { return _windowSize; }
public void setWindowSize(int numMsgs) { public void setWindowSize(int numMsgs) {
@ -195,12 +200,15 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
_windowSize = numMsgs; _windowSize = numMsgs;
} }
/** after how many consecutive messages should we ack? */ /** after how many consecutive messages should we ack?
* @return receive window size.
*/
public int getReceiveWindow() { return _receiveWindow; } public int getReceiveWindow() { return _receiveWindow; }
public void setReceiveWindow(int numMsgs) { _receiveWindow = numMsgs; } public void setReceiveWindow(int numMsgs) { _receiveWindow = numMsgs; }
/** /**
* What to set the round trip time estimate to (in milliseconds) * What to set the round trip time estimate to (in milliseconds)
* @return round trip time estimate in ms
*/ */
public int getRTT() { return _rtt; } public int getRTT() { return _rtt; }
public void setRTT(int ms) { public void setRTT(int ms) {
@ -229,6 +237,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
* If we have 3 consecutive rtt increases, we are trending upwards (1), or if we have * If we have 3 consecutive rtt increases, we are trending upwards (1), or if we have
* 3 consecutive rtt decreases, we are trending downwards (-1), else we're stable. * 3 consecutive rtt decreases, we are trending downwards (-1), else we're stable.
* *
* @return positive/flat/negative trend in round trip time
*/ */
public int getRTTTrend() { public int getRTTTrend() {
synchronized (_trend) { synchronized (_trend) {
@ -255,7 +264,9 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
setRTT(smoothed); setRTT(smoothed);
} }
/** How long after sending a packet will we wait before resending? */ /** How long after sending a packet will we wait before resending?
* @return delay for a retransmission in ms
*/
public int getResendDelay() { return _resendDelay; } public int getResendDelay() { return _resendDelay; }
public void setResendDelay(int ms) { _resendDelay = ms; } public void setResendDelay(int ms) { _resendDelay = ms; }
@ -265,11 +276,14 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
* (_lastSendTime+_sendAckDelay), send an ACK of what * (_lastSendTime+_sendAckDelay), send an ACK of what
* we have received so far. * we have received so far.
* *
* @return ACK delay in ms
*/ */
public int getSendAckDelay() { return _sendAckDelay; } public int getSendAckDelay() { return _sendAckDelay; }
public void setSendAckDelay(int delayMs) { _sendAckDelay = delayMs; } public void setSendAckDelay(int delayMs) { _sendAckDelay = delayMs; }
/** What is the largest message we want to send or receive? */ /** What is the largest message we want to send or receive?
* @return Maximum message size (MTU/MRU)
*/
public int getMaxMessageSize() { return _maxMessageSize; } public int getMaxMessageSize() { return _maxMessageSize; }
public void setMaxMessageSize(int bytes) { _maxMessageSize = bytes; } public void setMaxMessageSize(int bytes) { _maxMessageSize = bytes; }
@ -277,13 +291,15 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
* how long we want to wait before any data is transferred on the * how long we want to wait before any data is transferred on the
* connection in either direction * connection in either direction
* *
* @return how long to wait before any data is transferred in either direction in ms
*/ */
public int getChoke() { return _choke; } public int getChoke() { return _choke; }
public void setChoke(int ms) { _choke = ms; } public void setChoke(int ms) { _choke = ms; }
/** /**
* What profile do we want to use for this connection? * What profile do we want to use for this connection?
* * TODO: Only bulk is supported so far.
* @return the profile of the connection.
*/ */
public int getProfile() { return _profile; } public int getProfile() { return _profile; }
public void setProfile(int profile) { public void setProfile(int profile) {
@ -295,6 +311,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
/** /**
* How many times will we try to send a message before giving up? * How many times will we try to send a message before giving up?
* *
* @return Maximum retrys before failing a sent message.
*/ */
public int getMaxResends() { return _maxResends; } public int getMaxResends() { return _maxResends; }
public void setMaxResends(int numSends) { _maxResends = numSends; } public void setMaxResends(int numSends) { _maxResends = numSends; }
@ -302,6 +319,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
/** /**
* What period of inactivity qualifies as "too long"? * What period of inactivity qualifies as "too long"?
* *
* @return period of inactivity qualifies as "too long"
*/ */
public int getInactivityTimeout() { return _inactivityTimeout; } public int getInactivityTimeout() { return _inactivityTimeout; }
public void setInactivityTimeout(int timeout) { _inactivityTimeout = timeout; } public void setInactivityTimeout(int timeout) { _inactivityTimeout = timeout; }
@ -322,6 +340,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
/** /**
* how much data are we willing to accept in our buffer? * how much data are we willing to accept in our buffer?
* *
* @return size of the buffer used to accept data
*/ */
public int getInboundBufferSize() { return _inboundBufferSize; } public int getInboundBufferSize() { return _inboundBufferSize; }
public void setInboundBufferSize(int bytes) { _inboundBufferSize = bytes; } public void setInboundBufferSize(int bytes) { _inboundBufferSize = bytes; }
@ -331,6 +350,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
* of 1/(windowSize*factor). In standard TCP, window sizes are in bytes, * of 1/(windowSize*factor). In standard TCP, window sizes are in bytes,
* while in I2P, window sizes are in messages, so setting factor=maxMessageSize * while in I2P, window sizes are in messages, so setting factor=maxMessageSize
* mimics TCP, but using a smaller factor helps grow a little more rapidly. * mimics TCP, but using a smaller factor helps grow a little more rapidly.
* @return window size to grow by to attempt to avoid congestion.
*/ */
public int getCongestionAvoidanceGrowthRateFactor() { return _congestionAvoidanceGrowthRateFactor; } public int getCongestionAvoidanceGrowthRateFactor() { return _congestionAvoidanceGrowthRateFactor; }
public void setCongestionAvoidanceGrowthRateFactor(int factor) { _congestionAvoidanceGrowthRateFactor = factor; } public void setCongestionAvoidanceGrowthRateFactor(int factor) { _congestionAvoidanceGrowthRateFactor = factor; }
@ -340,10 +360,12 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
* of 1/(factor). In standard TCP, window sizes are in bytes, * of 1/(factor). In standard TCP, window sizes are in bytes,
* while in I2P, window sizes are in messages, so setting factor=maxMessageSize * while in I2P, window sizes are in messages, so setting factor=maxMessageSize
* mimics TCP, but using a smaller factor helps grow a little more rapidly. * mimics TCP, but using a smaller factor helps grow a little more rapidly.
* @return slow start window size to grow by to attempt to avoid sending many small packets.
*/ */
public int getSlowStartGrowthRateFactor() { return _slowStartGrowthRateFactor; } public int getSlowStartGrowthRateFactor() { return _slowStartGrowthRateFactor; }
public void setSlowStartGrowthRateFactor(int factor) { _slowStartGrowthRateFactor = factor; } public void setSlowStartGrowthRateFactor(int factor) { _slowStartGrowthRateFactor = factor; }
@Override
public String toString() { public String toString() {
StringBuffer buf = new StringBuffer(128); StringBuffer buf = new StringBuffer(128);
buf.append("conDelay=").append(_connectDelay); buf.append("conDelay=").append(_connectDelay);

View File

@ -16,7 +16,7 @@ public class I2PServerSocketFull implements I2PServerSocket {
/** /**
* *
* @return * @return I2PSocket
* @throws net.i2p.I2PException * @throws net.i2p.I2PException
* @throws SocketTimeoutException * @throws SocketTimeoutException
*/ */

View File

@ -119,6 +119,7 @@ public class I2PSocketFull implements I2PSocket {
if (c != null) if (c != null)
c.disconnectComplete(); c.disconnectComplete();
} }
@Override
public String toString() { public String toString() {
Connection c = _connection; Connection c = _connection;
if (c == null) if (c == null)

View File

@ -112,7 +112,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
/** /**
* *
* @return * @return connected I2PSocket
* @throws net.i2p.I2PException * @throws net.i2p.I2PException
* @throws java.net.SocketTimeoutException * @throws java.net.SocketTimeoutException
*/ */
@ -141,7 +141,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
* *
* @param peer * @param peer
* @param timeoutMs * @param timeoutMs
* @return * @return true on success, false on failure
*/ */
public boolean ping(Destination peer, long timeoutMs) { public boolean ping(Destination peer, long timeoutMs) {
return _connectionManager.ping(peer, timeoutMs); return _connectionManager.ping(peer, timeoutMs);
@ -246,6 +246,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
/** /**
* Retrieve a set of currently connected I2PSockets, either initiated locally or remotely. * Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.
* *
* @return set of currently connected I2PSockets
*/ */
public Set listSockets() { public Set listSockets() {
Set connections = _connectionManager.listConnections(); Set connections = _connectionManager.listConnections();

View File

@ -70,6 +70,7 @@ public class MessageHandler implements I2PSessionListener {
/** /**
* Notify the client that the session has been terminated * Notify the client that the session has been terminated
* *
* @param session that has been terminated
*/ */
public void disconnected(I2PSession session) { public void disconnected(I2PSession session) {
if (_log.shouldLog(Log.ERROR)) if (_log.shouldLog(Log.ERROR))
@ -90,6 +91,9 @@ public class MessageHandler implements I2PSessionListener {
/** /**
* Notify the client that some error occurred * Notify the client that some error occurred
* *
* @param session of the client
* @param message to send to the client about the error
* @param error the actual error
*/ */
public void errorOccurred(I2PSession session, String message, Throwable error) { public void errorOccurred(I2PSession session, String message, Throwable error) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))

View File

@ -73,7 +73,9 @@ public class MessageInputStream extends InputStream {
_cache = ByteCache.getInstance(128, Packet.MAX_PAYLOAD_SIZE); _cache = ByteCache.getInstance(128, Packet.MAX_PAYLOAD_SIZE);
} }
/** What is the highest block ID we've completely received through? */ /** What is the highest block ID we've completely received through?
* @return highest data block ID completely received
*/
public long getHighestReadyBockId() { public long getHighestReadyBockId() {
// not synchronized as it doesnt hurt to read a too-low value // not synchronized as it doesnt hurt to read a too-low value
return _highestReadyBlockId; return _highestReadyBlockId;
@ -89,6 +91,7 @@ public class MessageInputStream extends InputStream {
* past the highest ready ID and below the highest received message * past the highest ready ID and below the highest received message
* ID. This may return null if there are no such IDs. * ID. This may return null if there are no such IDs.
* *
* @return array of message ID holes, or null if none
*/ */
public long[] getNacks() { public long[] getNacks() {
synchronized (_dataLock) { synchronized (_dataLock) {
@ -128,6 +131,7 @@ public class MessageInputStream extends InputStream {
* Ascending list of block IDs greater than the highest * Ascending list of block IDs greater than the highest
* ready block ID, or null if there aren't any. * ready block ID, or null if there aren't any.
* *
* @return block IDs greater than the highest ready block ID, or null if there aren't any.
*/ */
public long[] getOutOfOrderBlocks() { public long[] getOutOfOrderBlocks() {
long blocks[] = null; long blocks[] = null;
@ -146,7 +150,9 @@ public class MessageInputStream extends InputStream {
return blocks; return blocks;
} }
/** how many blocks have we received that we still have holes before? */ /** how many blocks have we received that we still have holes before?
* @return Count of blocks received that still have holes
*/
public int getOutOfOrderBlockCount() { public int getOutOfOrderBlockCount() {
synchronized (_dataLock) { synchronized (_dataLock) {
return _notYetReadyBlocks.size(); return _notYetReadyBlocks.size();
@ -156,6 +162,7 @@ public class MessageInputStream extends InputStream {
/** /**
* how long a read() call should block (if less than 0, block indefinitely, * how long a read() call should block (if less than 0, block indefinitely,
* but if it is 0, do not block at all) * but if it is 0, do not block at all)
* @return how long read calls should block, 0 or less indefinitely block
*/ */
public int getReadTimeout() { return _readTimeout; } public int getReadTimeout() { return _readTimeout; }
public void setReadTimeout(int timeout) { public void setReadTimeout(int timeout) {
@ -203,6 +210,8 @@ public class MessageInputStream extends InputStream {
* A new message has arrived - toss it on the appropriate queue (moving * A new message has arrived - toss it on the appropriate queue (moving
* previously pending messages to the ready queue if it fills the gap, etc). * previously pending messages to the ready queue if it fills the gap, etc).
* *
* @param messageId ID of the message
* @param payload message payload
* @return true if this is a new packet, false if it is a dup * @return true if this is a new packet, false if it is a dup
*/ */
public boolean messageReceived(long messageId, ByteArray payload) { public boolean messageReceived(long messageId, ByteArray payload) {
@ -260,10 +269,12 @@ public class MessageInputStream extends InputStream {
return _oneByte[0]; return _oneByte[0];
} }
@Override
public int read(byte target[]) throws IOException { public int read(byte target[]) throws IOException {
return read(target, 0, target.length); return read(target, 0, target.length);
} }
@Override
public int read(byte target[], int offset, int length) throws IOException { public int read(byte target[], int offset, int length) throws IOException {
if (_locallyClosed) throw new IOException("Already locally closed"); if (_locallyClosed) throw new IOException("Already locally closed");
throwAnyError(); throwAnyError();
@ -360,6 +371,7 @@ public class MessageInputStream extends InputStream {
return length; return length;
} }
@Override
public int available() throws IOException { public int available() throws IOException {
if (_locallyClosed) throw new IOException("Already closed, you wanker"); if (_locallyClosed) throw new IOException("Already closed, you wanker");
throwAnyError(); throwAnyError();
@ -383,6 +395,7 @@ public class MessageInputStream extends InputStream {
* How many bytes are queued up for reading (or sitting in the out-of-order * How many bytes are queued up for reading (or sitting in the out-of-order
* buffer)? * buffer)?
* *
* @return Count of bytes waiting to be read
*/ */
public int getTotalQueuedSize() { public int getTotalQueuedSize() {
synchronized (_dataLock) { synchronized (_dataLock) {
@ -418,6 +431,7 @@ public class MessageInputStream extends InputStream {
} }
} }
@Override
public void close() { public void close() {
synchronized (_dataLock) { synchronized (_dataLock) {
//while (_readyDataBlocks.size() > 0) //while (_readyDataBlocks.size() > 0)

View File

@ -77,10 +77,12 @@ public class MessageOutputStream extends OutputStream {
public int getWriteTimeout() { return _writeTimeout; } public int getWriteTimeout() { return _writeTimeout; }
public void setBufferSize(int size) { _nextBufferSize = size; } public void setBufferSize(int size) { _nextBufferSize = size; }
@Override
public void write(byte b[]) throws IOException { public void write(byte b[]) throws IOException {
write(b, 0, b.length); write(b, 0, b.length);
} }
@Override
public void write(byte b[], int off, int len) throws IOException { public void write(byte b[], int off, int len) throws IOException {
if (_closed) throw new IOException("Already closed"); if (_closed) throw new IOException("Already closed");
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
@ -159,7 +161,7 @@ public class MessageOutputStream extends OutputStream {
int periods = (int)Math.floor((now - _sendPeriodBeginTime) / 1000d); int periods = (int)Math.floor((now - _sendPeriodBeginTime) / 1000d);
if (periods > 0) { if (periods > 0) {
// first term decays on slow transmission // first term decays on slow transmission
_sendBps = (int)(((float)0.9f*((float)_sendBps/(float)periods)) + ((float)0.1f*((float)_sendPeriodBytes/(float)periods))); _sendBps = (int)((0.9f*((float)_sendBps/(float)periods)) + (0.1f*((float)_sendPeriodBytes/(float)periods)));
_sendPeriodBytes = len; _sendPeriodBytes = len;
_sendPeriodBeginTime = now; _sendPeriodBeginTime = now;
_context.statManager().addRateData("stream.sendBps", _sendBps, 0); _context.statManager().addRateData("stream.sendBps", _sendBps, 0);
@ -255,9 +257,12 @@ public class MessageOutputStream extends OutputStream {
* delivered. * delivered.
* *
* @throws IOException if the write fails * @throws IOException if the write fails
* @throws InterruptedIOException if the write times out
*/ */
@Override
public void flush() throws IOException { public void flush() throws IOException {
/* @throws InterruptedIOException if the write times out
* Documented here, but doesn't belong in the javadoc.
*/
long begin = _context.clock().now(); long begin = _context.clock().now();
WriteStatus ws = null; WriteStatus ws = null;
synchronized (_dataLock) { synchronized (_dataLock) {

View File

@ -149,7 +149,9 @@ public class Packet {
public Packet() { } public Packet() { }
private boolean _sendStreamIdSet = false; private boolean _sendStreamIdSet = false;
/** what stream do we send data to the peer on? */ /** what stream do we send data to the peer on?
* @return stream ID we use to send data
*/
public long getSendStreamId() { return _sendStreamId; } public long getSendStreamId() { return _sendStreamId; }
public void setSendStreamId(long id) { public void setSendStreamId(long id) {
if ( (_sendStreamIdSet) && (_sendStreamId > 0) ) if ( (_sendStreamIdSet) && (_sendStreamId > 0) )
@ -162,6 +164,7 @@ public class Packet {
/** /**
* stream the replies should be sent on. this should be 0 if the * stream the replies should be sent on. this should be 0 if the
* connection is still being built. * connection is still being built.
* @return stream ID we use to get data, zero if the connection is still being built.
*/ */
public long getReceiveStreamId() { return _receiveStreamId; } public long getReceiveStreamId() { return _receiveStreamId; }
public void setReceiveStreamId(long id) { public void setReceiveStreamId(long id) {
@ -171,7 +174,9 @@ public class Packet {
_receiveStreamId = id; _receiveStreamId = id;
} }
/** 0-indexed sequence number for this Packet in the sendStream */ /** 0-indexed sequence number for this Packet in the sendStream
* @return 0-indexed sequence number for current Packet in current sendStream
*/
public long getSequenceNum() { return _sequenceNum; } public long getSequenceNum() { return _sequenceNum; }
public void setSequenceNum(long num) { _sequenceNum = num; } public void setSequenceNum(long num) { _sequenceNum = num; }
@ -181,6 +186,7 @@ public class Packet {
* connection packet (where receiveStreamId is the unknown id) or * connection packet (where receiveStreamId is the unknown id) or
* if FLAG_NO_ACK is set. * if FLAG_NO_ACK is set.
* *
* @return The highest packet sequence number received on receiveStreamId
*/ */
public long getAckThrough() { public long getAckThrough() {
if (isFlagSet(FLAG_NO_ACK)) if (isFlagSet(FLAG_NO_ACK))
@ -198,6 +204,7 @@ public class Packet {
* List of packet sequence numbers below the getAckThrough() value * List of packet sequence numbers below the getAckThrough() value
* have not been received. this may be null. * have not been received. this may be null.
* *
* @return List of packet sequence numbers not ACKed, or null if there are none.
*/ */
public long[] getNacks() { return _nacks; } public long[] getNacks() { return _nacks; }
public void setNacks(long nacks[]) { _nacks = nacks; } public void setNacks(long nacks[]) { _nacks = nacks; }
@ -207,13 +214,16 @@ public class Packet {
* resending this packet (if it hasn't yet been ACKed). The * resending this packet (if it hasn't yet been ACKed). The
* value is seconds since the packet was created. * value is seconds since the packet was created.
* *
* @return Delay before resending a packet in seconds.
*/ */
public int getResendDelay() { return _resendDelay; } public int getResendDelay() { return _resendDelay; }
public void setResendDelay(int numSeconds) { _resendDelay = numSeconds; } public void setResendDelay(int numSeconds) { _resendDelay = numSeconds; }
public static final int MAX_PAYLOAD_SIZE = 32*1024; public static final int MAX_PAYLOAD_SIZE = 32*1024;
/** get the actual payload of the message. may be null */ /** get the actual payload of the message. may be null
* @return the payload of the message, null if none.
*/
public ByteArray getPayload() { return _payload; } public ByteArray getPayload() { return _payload; }
public void setPayload(ByteArray payload) { public void setPayload(ByteArray payload) {
_payload = payload; _payload = payload;
@ -232,7 +242,10 @@ public class Packet {
return _payload; return _payload;
} }
/** is a particular flag set on this packet? */ /** is a particular flag set on this packet?
* @param flag bitmask of any flag(s)
* @return true if set, false if not.
*/
public boolean isFlagSet(int flag) { return 0 != (_flags & flag); } public boolean isFlagSet(int flag) { return 0 != (_flags & flag); }
public void setFlag(int flag) { _flags |= flag; } public void setFlag(int flag) { _flags |= flag; }
public void setFlag(int flag, boolean set) { public void setFlag(int flag, boolean set) {
@ -243,14 +256,18 @@ public class Packet {
} }
public void setFlags(int flags) { _flags = flags; } public void setFlags(int flags) { _flags = flags; }
/** the signature on the packet (only included if the flag for it is set) */ /** the signature on the packet (only included if the flag for it is set)
* @return signature on the packet if the flag for signatures is set
*/
public Signature getOptionalSignature() { return _optionSignature; } public Signature getOptionalSignature() { return _optionSignature; }
public void setOptionalSignature(Signature sig) { public void setOptionalSignature(Signature sig) {
setFlag(FLAG_SIGNATURE_INCLUDED, sig != null); setFlag(FLAG_SIGNATURE_INCLUDED, sig != null);
_optionSignature = sig; _optionSignature = sig;
} }
/** the sender of the packet (only included if the flag for it is set) */ /** the sender of the packet (only included if the flag for it is set)
* @return the sending Destination
*/
public Destination getOptionalFrom() { return _optionFrom; } public Destination getOptionalFrom() { return _optionFrom; }
public void setOptionalFrom(Destination from) { public void setOptionalFrom(Destination from) {
setFlag(FLAG_FROM_INCLUDED, from != null); setFlag(FLAG_FROM_INCLUDED, from != null);
@ -262,6 +279,7 @@ public class Packet {
* How many milliseconds the sender of this packet wants the recipient * How many milliseconds the sender of this packet wants the recipient
* to wait before sending any more data (only valid if the flag for it is * to wait before sending any more data (only valid if the flag for it is
* set) * set)
* @return How long the sender wants the recipient to wait before sending any more data in ms.
*/ */
public int getOptionalDelay() { return _optionDelay; } public int getOptionalDelay() { return _optionDelay; }
public void setOptionalDelay(int delayMs) { public void setOptionalDelay(int delayMs) {
@ -276,6 +294,7 @@ public class Packet {
/** /**
* What is the largest payload the sender of this packet wants to receive? * What is the largest payload the sender of this packet wants to receive?
* *
* @return Maximum payload size sender can receive (MRU)
*/ */
public int getOptionalMaxSize() { return _optionMaxSize; } public int getOptionalMaxSize() { return _optionMaxSize; }
public void setOptionalMaxSize(int numBytes) { public void setOptionalMaxSize(int numBytes) {
@ -287,6 +306,9 @@ public class Packet {
* Write the packet to the buffer (starting at the offset) and return * Write the packet to the buffer (starting at the offset) and return
* the number of bytes written. * the number of bytes written.
* *
* @param buffer bytes to write to a destination
* @param offset starting point in the buffer to send
* @return Count actually written
* @throws IllegalStateException if there is data missing or otherwise b0rked * @throws IllegalStateException if there is data missing or otherwise b0rked
*/ */
public int writePacket(byte buffer[], int offset) throws IllegalStateException { public int writePacket(byte buffer[], int offset) throws IllegalStateException {
@ -370,6 +392,8 @@ public class Packet {
/** /**
* how large would this packet be if we wrote it * how large would this packet be if we wrote it
* @return How large the current packet would be
* @throws IllegalStateException
*/ */
public int writtenSize() throws IllegalStateException { public int writtenSize() throws IllegalStateException {
int size = 0; int size = 0;
@ -497,7 +521,10 @@ public class Packet {
/** /**
* Determine whether the signature on the data is valid. * Determine whether the signature on the data is valid.
* *
* @return true if the signature exists and validates against the data, * @param ctx Application context
* @param from the Destination the data came from
* @param buffer data to validate with signature
* @return true if the signature exists and validates against the data,
* false otherwise. * false otherwise.
*/ */
public boolean verifySignature(I2PAppContext ctx, Destination from, byte buffer[]) { public boolean verifySignature(I2PAppContext ctx, Destination from, byte buffer[]) {
@ -530,6 +557,11 @@ public class Packet {
* Sign and write the packet to the buffer (starting at the offset) and return * Sign and write the packet to the buffer (starting at the offset) and return
* the number of bytes written. * the number of bytes written.
* *
* @param buffer data to be written
* @param offset starting point in the buffer
* @param ctx Application Context
* @param key signing key
* @return Count of bytes written
* @throws IllegalStateException if there is data missing or otherwise b0rked * @throws IllegalStateException if there is data missing or otherwise b0rked
*/ */
public int writeSignedPacket(byte buffer[], int offset, I2PAppContext ctx, SigningPrivateKey key) throws IllegalStateException { public int writeSignedPacket(byte buffer[], int offset, I2PAppContext ctx, SigningPrivateKey key) throws IllegalStateException {
@ -560,6 +592,7 @@ public class Packet {
return size; return size;
} }
@Override
public String toString() { public String toString() {
StringBuffer str = formatAsString(); StringBuffer str = formatAsString();
return str.toString(); return str.toString();

View File

@ -107,7 +107,9 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
} }
public SimpleTimer.TimedEvent getResendEvent() { return _resendEvent; } public SimpleTimer.TimedEvent getResendEvent() { return _resendEvent; }
/** how long after packet creation was it acked? */ /** how long after packet creation was it acked?
* @return how long after packet creation the packet was ACKed in ms
*/
public int getAckTime() { public int getAckTime() {
if (_ackOn <= 0) if (_ackOn <= 0)
return -1; return -1;
@ -130,6 +132,7 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
public void setResendPacketEvent(SimpleTimer.TimedEvent evt) { _resendEvent = evt; } public void setResendPacketEvent(SimpleTimer.TimedEvent evt) { _resendEvent = evt; }
@Override
public StringBuffer formatAsString() { public StringBuffer formatAsString() {
StringBuffer buf = super.formatAsString(); StringBuffer buf = super.formatAsString();