Revision: 440 http://skycastle.svn.sourceforge.net/skycastle/?rev=440&view=rev Author: zzorn Date: 2008-04-05 07:11:05 -0700 (Sat, 05 Apr 2008) Log Message: ----------- A bit of code cleanup, added some JavaDoc comments. Modified Paths: -------------- trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/AbstractProtocolNegotiator.java trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/ClientSideProtocolNegotiator.java trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/NegotiationStatus.java trunk/skycastle/modules/core/src/test/java/org/skycastle/protocol/negotiation/ProtocolNegotiationTest.java Modified: trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/AbstractProtocolNegotiator.java =================================================================== --- trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/AbstractProtocolNegotiator.java 2008-04-04 15:44:16 UTC (rev 439) +++ trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/AbstractProtocolNegotiator.java 2008-04-05 14:11:05 UTC (rev 440) @@ -144,7 +144,7 @@ protected final String getAvailableProtocolIdsAsString() { final StringBuffer protocolIds = new StringBuffer(); - for ( String protocolId : getAvailableProtocolsIds() ) + for ( final String protocolId : getAvailableProtocolsIds() ) { protocolIds.append( protocolId ); protocolIds.append( " " ); @@ -163,7 +163,7 @@ if ( incomingString != null ) { final String[] lines = incomingString.split( "\n" ); - for ( String line : lines ) + for ( final String line : lines ) { final int spaceIndex = line.indexOf( " " ); Modified: trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/ClientSideProtocolNegotiator.java =================================================================== --- trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/ClientSideProtocolNegotiator.java 2008-04-04 15:44:16 UTC (rev 439) +++ trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/ClientSideProtocolNegotiator.java 2008-04-05 14:11:05 UTC (rev 440) @@ -35,8 +35,8 @@ * @param version the version of the client. */ public ClientSideProtocolNegotiator( final ProtocolRegistry protocolRegistry, - String clientType, - String version ) + final String clientType, + final String version ) { super( protocolRegistry ); myClientType = clientType; @@ -74,6 +74,7 @@ //====================================================================== // Protected Methods + @Override protected String handleMessage( final String incomingMessage, final Map<String, String> parameters ) { myStep++; Modified: trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/NegotiationStatus.java =================================================================== --- trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/NegotiationStatus.java 2008-04-04 15:44:16 UTC (rev 439) +++ trunk/skycastle/modules/core/src/main/java/org/skycastle/protocol/negotiation/NegotiationStatus.java 2008-04-05 14:11:05 UTC (rev 440) @@ -1,38 +1,60 @@ package org.skycastle.protocol.negotiation; /** - * Describes the result of a protocol negotiation, in the event of failure, it describes the reason for the failure. + * Describes the result of a protocol negotiation, in the event of failure, it describes the reason for the + * failure. * * @author Hans Haggstrom */ public enum NegotiationStatus { + /** + * Used to indicate that protocol negotiation is ongoing. + */ ONGOING( false, false, "Ongoing", "Protocol negotiation is ongoing." ), + /** + * Used to indicate that Protocol negotiation succeeded. + */ SUCCESS( true, true, "Success", "Protocol negotiation succeeded." ), + /** + * Used to indicate that Protocol negotiation was finished, but no common protocol was found. + */ NO_COMMON_PROTOCOL_FOUND( true, false, "NoCommonProtocolFound", "Protocol negotiation was finished, but no common protocol was found." ), + /** + * Used to indicate that Protocol negotiation was terminated because the other party failed to respond in + * time. + */ TIMEOUT( true, false, "Timeout", "Protocol negotiation was terminated because the other party failed to respond in time." ), + /** + * Used to indicate that Protocol negotiation was terminated because the other party returned incorretly + * formatted messages (possible DoS / cracking attempt). + */ INVALID_MESSAGE( true, false, "InvalidMessage", "Protocol negotiation was terminated because the other party returned " + - "incorretly formatted messages (possible DoS / cracking attempt)." ), + "incorretly formatted messages (possible DoS or cracking attempt)." ), + /** + * Used to indicate that Protocol negotiation was terminated because the other party returned corretly + * formatted but too long messages (possible DoS / cracking attempt). + */ TOO_LONG_MESSAGE( true, false, "TooLongMessage", "Protocol negotiation was terminated because the other party returned " + - "corretly formatted but too long messages (possible DoS / cracking attempt)." ); + "corretly formatted but too long messages (possible DoS or cracking attempt)." ); //====================================================================== // Private Fields @@ -48,7 +70,10 @@ //---------------------------------------------------------------------- // Constructors - NegotiationStatus( final boolean finished, final boolean success, final String name, final String description ) + NegotiationStatus( final boolean finished, + final boolean success, + final String name, + final String description ) { myFinished = finished; mySuccess = success; @@ -106,6 +131,7 @@ //---------------------------------------------------------------------- // Caononical Methods + @Override public String toString() { return myName + ": " + myDescription; Modified: trunk/skycastle/modules/core/src/test/java/org/skycastle/protocol/negotiation/ProtocolNegotiationTest.java =================================================================== --- trunk/skycastle/modules/core/src/test/java/org/skycastle/protocol/negotiation/ProtocolNegotiationTest.java 2008-04-04 15:44:16 UTC (rev 439) +++ trunk/skycastle/modules/core/src/test/java/org/skycastle/protocol/negotiation/ProtocolNegotiationTest.java 2008-04-05 14:11:05 UTC (rev 440) @@ -13,7 +13,7 @@ import org.skycastle.protocol.registry.ProtocolRegistryImpl; import org.skycastle.util.StringUtilities; -@SuppressWarnings( { "JavaDoc" } ) +@SuppressWarnings( { "JavaDoc", "HardcodedLineSeparator" } ) public class ProtocolNegotiationTest extends TestCase { @@ -30,45 +30,15 @@ // Private Constants private static final String DUMMY_PROTOCOL_ID = "DummyProtocol"; - private static final Protocol DUMMY_PROTOCOL = new AbstractProtocol( DUMMY_PROTOCOL_ID, - new MessageValidator() ) - { + private static final Protocol DUMMY_PROTOCOL = createDummyProtocol( DUMMY_PROTOCOL_ID ); - protected byte[] encodeWithoutCheck( final Message messageToSend ) throws ProtocolException - { - return new byte[0]; - } - - - protected Message decodeWithoutCheck( final byte[] receivedBytes ) throws ProtocolException - { - return null; - } - - }; - private static final String FOO_PROTOCOL_ID = "FooProtocol"; - private static final Protocol FOO_PROTOCOL = new AbstractProtocol( FOO_PROTOCOL_ID, - new MessageValidator() ) - { + private static final Protocol FOO_PROTOCOL = createDummyProtocol( FOO_PROTOCOL_ID ); - protected byte[] encodeWithoutCheck( final Message messageToSend ) throws ProtocolException - { - return new byte[0]; - } - - protected Message decodeWithoutCheck( final byte[] receivedBytes ) throws ProtocolException - { - return null; - - } - - }; - - private static final String CLIENT_TYPE = "Test client"; private static final String CLIENT_VERSION = "1.0"; + private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; //====================================================================== // Public Methods @@ -177,6 +147,7 @@ //====================================================================== // Protected Methods + @Override protected void setUp() throws Exception { super.setUp(); @@ -197,6 +168,31 @@ //====================================================================== // Private Methods + private static AbstractProtocol createDummyProtocol( final String protocolId ) + { + return new AbstractProtocol( protocolId, + new MessageValidator() ) + { + + private static final long serialVersionUID = -7040248263147842541L; + + @Override + protected byte[] encodeWithoutCheck( final Message messageToSend ) throws ProtocolException + { + return EMPTY_BYTE_ARRAY; + } + + + @Override + protected Message decodeWithoutCheck( final byte[] receivedBytes ) throws ProtocolException + { + return null; + } + + }; + } + + private void exerciseBothNegotiators( final String serverIntro, final String clientIntro, final String serverProtocolSelection, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.