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

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

SAM: more Log conditionals, javadocs

parent 22aff497
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -43,7 +43,7 @@ class SAMv2StreamSession extends SAMStreamSession
/** /**
* Create a new SAM STREAM session. * Create a new SAM STREAM session.
* *
* @param dest Base64-encoded destination (private key) * @param dest Base64-encoded destination and private keys (same format as PrivateKeyFile)
* @param dir Session direction ("RECEIVE", "CREATE" or "BOTH") * @param dir Session direction ("RECEIVE", "CREATE" or "BOTH")
* @param props Properties to setup the I2P session * @param props Properties to setup the I2P session
* @param recv Object that will receive incoming data * @param recv Object that will receive incoming data
...@@ -60,7 +60,7 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -60,7 +60,7 @@ class SAMv2StreamSession extends SAMStreamSession
/** /**
* Create a new SAM STREAM session. * Create a new SAM STREAM session.
* *
* @param destStream Input stream containing the destination keys * @param destStream Input stream containing the destination and private keys (same format as PrivateKeyFile)
* @param dir Session direction ("RECEIVE", "CREATE" or "BOTH") * @param dir Session direction ("RECEIVE", "CREATE" or "BOTH")
* @param props Properties to setup the I2P session * @param props Properties to setup the I2P session
* @param recv Object that will receive incoming data * @param recv Object that will receive incoming data
...@@ -93,13 +93,15 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -93,13 +93,15 @@ class SAMv2StreamSession extends SAMStreamSession
{ {
if ( !canCreate ) if ( !canCreate )
{ {
_log.debug ( "Trying to create an outgoing connection using a receive-only session" ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Trying to create an outgoing connection using a receive-only session" );
throw new SAMInvalidDirectionException ( "Trying to create connections through a receive-only session" ); throw new SAMInvalidDirectionException ( "Trying to create connections through a receive-only session" );
} }
if ( checkSocketHandlerId ( id ) ) if ( checkSocketHandlerId ( id ) )
{ {
_log.debug ( "The specified id (" + id + ") is already in use" ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "The specified id (" + id + ") is already in use" );
return false ; return false ;
} }
...@@ -112,7 +114,8 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -112,7 +114,8 @@ class SAMv2StreamSession extends SAMStreamSession
if ( props.getProperty ( I2PSocketOptions.PROP_CONNECT_TIMEOUT ) == null ) if ( props.getProperty ( I2PSocketOptions.PROP_CONNECT_TIMEOUT ) == null )
opts.setConnectTimeout ( 60 * 1000 ); opts.setConnectTimeout ( 60 * 1000 );
_log.debug ( "Connecting new I2PSocket..." ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Connecting new I2PSocket..." );
// non-blocking connection (SAMv2) // non-blocking connection (SAMv2)
...@@ -155,7 +158,8 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -155,7 +158,8 @@ class SAMv2StreamSession extends SAMStreamSession
public StreamConnector ( int id, Destination dest, I2PSocketOptions opts )// throws IOException public StreamConnector ( int id, Destination dest, I2PSocketOptions opts )// throws IOException
{ {
_log.debug ( "Instantiating new SAM STREAM connector" ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Instantiating new SAM STREAM connector" );
this.id = id ; this.id = id ;
this.opts = opts ; this.opts = opts ;
...@@ -165,7 +169,8 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -165,7 +169,8 @@ class SAMv2StreamSession extends SAMStreamSession
public void run() public void run()
{ {
_log.debug ( "run() called for socket connector " + id ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "run() called for socket connector " + id );
try try
{ {
...@@ -180,37 +185,44 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -180,37 +185,44 @@ class SAMv2StreamSession extends SAMStreamSession
catch ( DataFormatException e ) catch ( DataFormatException e )
{ {
_log.debug ( "Invalid destination in STREAM CONNECT message" ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Invalid destination in STREAM CONNECT message" );
recv.notifyStreamOutgoingConnection ( id, "INVALID_KEY", e.getMessage() ); recv.notifyStreamOutgoingConnection ( id, "INVALID_KEY", e.getMessage() );
} }
catch ( ConnectException e ) catch ( ConnectException e )
{ {
_log.debug ( "STREAM CONNECT failed: " + e.getMessage() ); if (_log.shouldLog(Log.DEBUG))
_log.debug("STREAM CONNECT failed", e);
recv.notifyStreamOutgoingConnection ( id, "CONNECTION_REFUSED", e.getMessage() ); recv.notifyStreamOutgoingConnection ( id, "CONNECTION_REFUSED", e.getMessage() );
} }
catch ( NoRouteToHostException e ) catch ( NoRouteToHostException e )
{ {
_log.debug ( "STREAM CONNECT failed: " + e.getMessage() ); if (_log.shouldLog(Log.DEBUG))
_log.debug("STREAM CONNECT failed", e);
recv.notifyStreamOutgoingConnection ( id, "CANT_REACH_PEER", e.getMessage() ); recv.notifyStreamOutgoingConnection ( id, "CANT_REACH_PEER", e.getMessage() );
} }
catch ( InterruptedIOException e ) catch ( InterruptedIOException e )
{ {
_log.debug ( "STREAM CONNECT failed: " + e.getMessage() ); if (_log.shouldLog(Log.DEBUG))
_log.debug("STREAM CONNECT failed", e);
recv.notifyStreamOutgoingConnection ( id, "TIMEOUT", e.getMessage() ); recv.notifyStreamOutgoingConnection ( id, "TIMEOUT", e.getMessage() );
} }
catch ( I2PException e ) catch ( I2PException e )
{ {
_log.debug ( "STREAM CONNECT failed: " + e.getMessage() ); if (_log.shouldLog(Log.DEBUG))
_log.debug("STREAM CONNECT failed", e);
recv.notifyStreamOutgoingConnection ( id, "I2P_ERROR", e.getMessage() ); recv.notifyStreamOutgoingConnection ( id, "I2P_ERROR", e.getMessage() );
} }
} }
catch ( IOException e ) catch ( IOException e )
{ {
_log.debug ( "Error sending disconnection notice for handler " if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Error sending disconnection notice for handler "
+ id, e ); + id, e );
} }
_log.debug ( "Shutting down SAM STREAM session connector " + id ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Shutting down SAM STREAM session connector " + id );
} }
} }
...@@ -312,7 +324,8 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -312,7 +324,8 @@ class SAMv2StreamSession extends SAMStreamSession
@Override @Override
public void stopRunning() public void stopRunning()
{ {
_log.debug ( "stopRunning() invoked on socket sender " + _id ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "stopRunning() invoked on socket sender " + _id );
synchronized ( runningLock ) synchronized ( runningLock )
{ {
...@@ -326,7 +339,8 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -326,7 +339,8 @@ class SAMv2StreamSession extends SAMStreamSession
} }
catch ( IOException e ) catch ( IOException e )
{ {
_log.debug ( "Caught IOException", e ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Caught IOException", e );
} }
synchronized ( _data ) synchronized ( _data )
...@@ -345,14 +359,16 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -345,14 +359,16 @@ class SAMv2StreamSession extends SAMStreamSession
@Override @Override
public void shutDownGracefully() public void shutDownGracefully()
{ {
_log.debug ( "shutDownGracefully() invoked on socket sender " + _id ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "shutDownGracefully() invoked on socket sender " + _id );
_shuttingDownGracefully = true; _shuttingDownGracefully = true;
} }
@Override @Override
public void run() public void run()
{ {
_log.debug ( "run() called for socket sender " + _id ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "run() called for socket sender " + _id );
ByteArray data = null; ByteArray data = null;
while ( _stillRunning ) while ( _stillRunning )
...@@ -491,13 +507,15 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -491,13 +507,15 @@ class SAMv2StreamSession extends SAMStreamSession
this.nolimit = nolimit ; this.nolimit = nolimit ;
runningLock.notify() ; runningLock.notify() ;
} }
_log.debug ( "new limit set for socket reader " + id + " : " + (nolimit ? "NOLIMIT" : limit + " bytes" ) ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "new limit set for socket reader " + id + " : " + (nolimit ? "NOLIMIT" : limit + " bytes" ) );
} }
@Override @Override
public void run() public void run()
{ {
_log.debug ( "run() called for socket reader " + id ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "run() called for socket reader " + id );
int read = -1; int read = -1;
ByteBuffer data = ByteBuffer.allocate(SOCKET_HANDLER_BUF_SIZE); ByteBuffer data = ByteBuffer.allocate(SOCKET_HANDLER_BUF_SIZE);
...@@ -527,7 +545,8 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -527,7 +545,8 @@ class SAMv2StreamSession extends SAMStreamSession
if ( read == -1 ) if ( read == -1 )
{ {
_log.debug ( "Handler " + id + ": connection closed" ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Handler " + id + ": connection closed" );
break; break;
} }
...@@ -538,7 +557,8 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -538,7 +557,8 @@ class SAMv2StreamSession extends SAMStreamSession
} }
catch ( IOException e ) catch ( IOException e )
{ {
_log.debug ( "Caught IOException", e ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Caught IOException", e );
} }
try try
...@@ -547,7 +567,8 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -547,7 +567,8 @@ class SAMv2StreamSession extends SAMStreamSession
} }
catch ( IOException e ) catch ( IOException e )
{ {
_log.debug ( "Caught IOException", e ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Caught IOException", e );
} }
if ( stillRunning ) if ( stillRunning )
...@@ -561,12 +582,14 @@ class SAMv2StreamSession extends SAMStreamSession ...@@ -561,12 +582,14 @@ class SAMv2StreamSession extends SAMStreamSession
} }
catch ( IOException e ) catch ( IOException e )
{ {
_log.debug ( "Error sending disconnection notice for handler " if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Error sending disconnection notice for handler "
+ id, e ); + id, e );
} }
} }
_log.debug ( "Shutting down SAM STREAM session socket handler " + id ); if (_log.shouldLog(Log.DEBUG))
_log.debug ( "Shutting down SAM STREAM session socket handler " + id );
} }
} }
......
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