From 528b5c43280d3514748f3f53e55a088805e68e7b Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sun, 27 May 2012 19:28:28 -0700 Subject: [PATCH] Removed the modules that are not part of 4.0.0.Alpha1 - Will add them back before Beta1 is out --- example/pom.xml | 10 +- handler/pom.xml | 5 - pom.xml | 3 - transport-http/pom.xml | 47 -- .../AcceptedServerChannelPipelineFactory.java | 53 -- .../AcceptedServerChannelRequestDispatch.java | 178 ----- .../socket/http/DefaultTunnelIdGenerator.java | 46 -- .../http/HttpTunnelAcceptedChannel.java | 132 ---- .../http/HttpTunnelAcceptedChannelConfig.java | 111 --- .../HttpTunnelAcceptedChannelFactory.java | 30 - .../HttpTunnelAcceptedChannelReceiver.java | 36 - .../http/HttpTunnelAcceptedChannelSink.java | 128 ---- .../socket/http/HttpTunnelChannelConfig.java | 150 ---- .../socket/http/HttpTunnelClientChannel.java | 400 ----------- .../http/HttpTunnelClientChannelConfig.java | 172 ----- .../http/HttpTunnelClientChannelFactory.java | 52 -- .../http/HttpTunnelClientChannelSink.java | 76 --- .../http/HttpTunnelClientPollHandler.java | 93 --- .../http/HttpTunnelClientSendHandler.java | 241 ------- .../http/HttpTunnelClientWorkerOwner.java | 64 -- .../socket/http/HttpTunnelMessageUtils.java | 340 --------- .../socket/http/HttpTunnelServerChannel.java | 129 ---- .../http/HttpTunnelServerChannelConfig.java | 139 ---- .../http/HttpTunnelServerChannelFactory.java | 65 -- .../http/HttpTunnelServerChannelSink.java | 85 --- .../socket/http/HttpTunnelingServlet.java | 248 ------- .../socket/http/SaturationManager.java | 69 -- .../socket/http/SaturationStateChange.java | 29 - .../socket/http/ServerMessageSwitch.java | 283 -------- ...erverMessageSwitchDownstreamInterface.java | 32 - .../ServerMessageSwitchUpstreamInterface.java | 53 -- .../socket/http/TunnelIdGenerator.java | 33 - .../TunnelWrappedServerChannelHandler.java | 81 --- .../channel/socket/http/WriteFragmenter.java | 71 -- .../channel/socket/http/WriteSplitter.java | 56 -- .../channel/socket/http/package-info.java | 115 ---- ...eptedServerChannelRequestDispatchTest.java | 255 ------- .../socket/http/FakeChannelConfig.java | 212 ------ .../channel/socket/http/FakeChannelSink.java | 39 -- .../http/FakeClientSocketChannelFactory.java | 52 -- .../socket/http/FakeServerSocketChannel.java | 94 --- .../http/FakeServerSocketChannelConfig.java | 80 --- .../http/FakeServerSocketChannelFactory.java | 45 -- .../socket/http/FakeSocketChannel.java | 108 --- .../HttpTunnelAcceptedChannelSinkTest.java | 89 --- .../HttpTunnelClientChannelConfigTest.java | 293 -------- .../http/HttpTunnelClientChannelTest.java | 269 -------- .../http/HttpTunnelClientPollHandlerTest.java | 122 ---- .../http/HttpTunnelClientSendHandlerTest.java | 222 ------ .../HttpTunnelServerChannelFactoryTest.java | 105 --- .../http/HttpTunnelServerChannelSinkTest.java | 155 ----- .../http/HttpTunnelServerChannelTest.java | 239 ------- .../socket/http/HttpTunnelSoakTester.java | 481 ------------- .../channel/socket/http/HttpTunnelTest.java | 239 ------- .../socket/http/MockChannelStateListener.java | 65 -- .../channel/socket/http/NettyTestUtils.java | 181 ----- .../socket/http/NettyTestUtilsTest.java | 123 ---- .../socket/http/NullChannelHandler.java | 42 -- .../socket/http/SaturationManagerTest.java | 52 -- .../socket/http/ServerMessageSwitchTest.java | 183 ----- .../socket/http/UpstreamEventCatcher.java | 41 -- .../socket/http/WriteFragmenterTest.java | 156 ----- .../socket/http/WriteSplitterTest.java | 98 --- transport-rxtx/pom.xml | 43 -- .../io/netty/channel/rxtx/RxtxChannel.java | 77 --- .../netty/channel/rxtx/RxtxChannelConfig.java | 201 ------ .../channel/rxtx/RxtxChannelFactory.java | 57 -- .../netty/channel/rxtx/RxtxChannelSink.java | 332 --------- .../netty/channel/rxtx/RxtxDeviceAddress.java | 41 -- .../io/netty/channel/rxtx/package-info.java | 20 - transport-sctp/pom.xml | 63 -- .../nio/sctp/AbstractNotificationHandler.java | 42 -- .../java/com/sun/nio/sctp/Association.java | 22 - .../sctp/AssociationChangeNotification.java | 22 - .../java/com/sun/nio/sctp/HandlerResult.java | 25 - .../java/com/sun/nio/sctp/MessageInfo.java | 38 -- .../java/com/sun/nio/sctp/Notification.java | 20 - .../com/sun/nio/sctp/NotificationHandler.java | 19 - .../sctp/PeerAddressChangeNotification.java | 22 - .../java/com/sun/nio/sctp/SctpChannel.java | 57 -- .../com/sun/nio/sctp/SctpServerChannel.java | 50 -- .../com/sun/nio/sctp/SctpSocketOption.java | 21 - .../nio/sctp/SctpStandardSocketOptions.java | 51 -- .../sun/nio/sctp/SendFailedNotification.java | 22 - .../sun/nio/sctp/ShutdownNotification.java | 22 - .../UnsupportedOperatingSystemException.java | 41 -- .../java/com/sun/nio/sctp/package-info.java | 22 - .../sctp/DefaultNioSctpChannelConfig.java | 187 ----- .../sctp/DefaultSctpChannelConfig.java | 170 ----- .../sctp/DefaultSctpServerChannelConfig.java | 128 ---- .../channel/sctp/NioSctpChannelConfig.java | 95 --- .../channel/sctp/SctpAcceptedChannel.java | 42 -- .../channel/sctp/SctpBindAddressEvent.java | 38 -- .../io/netty/channel/sctp/SctpChannel.java | 74 -- .../netty/channel/sctp/SctpChannelConfig.java | 84 --- .../netty/channel/sctp/SctpChannelImpl.java | 230 ------- .../netty/channel/sctp/SctpClientChannel.java | 83 --- .../channel/sctp/SctpClientPipelineSink.java | 159 ----- .../sctp/SctpClientSocketChannelFactory.java | 130 ---- .../java/io/netty/channel/sctp/SctpFrame.java | 118 ---- .../io/netty/channel/sctp/SctpJdkChannel.java | 109 --- .../channel/sctp/SctpNotificationEvent.java | 74 -- .../channel/sctp/SctpNotificationHandler.java | 69 -- .../channel/sctp/SctpSendBufferPool.java | 181 ----- .../netty/channel/sctp/SctpServerChannel.java | 68 -- .../channel/sctp/SctpServerChannelConfig.java | 90 --- .../channel/sctp/SctpServerChannelImpl.java | 162 ----- .../channel/sctp/SctpServerPipelineSink.java | 173 ----- .../sctp/SctpServerSocketChannelFactory.java | 132 ---- .../channel/sctp/SctpUnbindAddressEvent.java | 38 -- .../io/netty/channel/sctp/SctpWorker.java | 464 ------------- .../io/netty/channel/sctp/SctpWorkerPool.java | 33 - .../codec/DefaultInboundStreamFilter.java | 26 - .../codec/DefaultOutboundStreamSelector.java | 25 - .../sctp/codec/InboundStreamFilter.java | 24 - .../sctp/codec/OutboundStreamSelector.java | 22 - .../channel/sctp/codec/SctpFrameDecoder.java | 76 --- .../channel/sctp/codec/SctpFrameEncoder.java | 59 -- .../channel/sctp/codec/package-info.java | 20 - .../handler/SimpleSctpChannelHandler.java | 44 -- .../handler/SimpleSctpDownstreamHandler.java | 24 - .../handler/SimpleSctpUpstreamHandler.java | 42 -- .../channel/sctp/handler/package-info.java | 21 - .../io/netty/channel/sctp/package-info.java | 20 - .../AbstractSocketClientBootstrapTest.java | 205 ------ ...tSocketCompatibleObjectStreamEchoTest.java | 193 ------ .../transport/AbstractSocketEchoTest.java | 189 ----- .../AbstractSocketFixedLengthEchoTest.java | 193 ------ .../AbstractSocketObjectStreamEchoTest.java | 201 ------ .../AbstractSocketServerBootstrapTest.java | 228 ------- .../transport/AbstractSocketSslEchoTest.java | 643 ------------------ .../AbstractSocketStringEchoTest.java | 199 ------ .../sctp/SctpClientBootstrapTest.java | 29 - .../SctpCompatibleObjectStreamEchoTest.java | 35 - .../transport/sctp/SctpEchoTest.java | 35 - .../sctp/SctpFixedLengthEchoTest.java | 36 - .../sctp/SctpMultiHomingEchoTest.java | 234 ------- .../sctp/SctpMultiStreamingEchoTest.java | 176 ----- .../sctp/SctpObjectStreamEchoTest.java | 35 - .../sctp/SctpServerBootstrapTest.java | 29 - .../transport/sctp/SctpSslEchoTest.java | 35 - .../transport/sctp/SctpStringEchoTest.java | 35 - .../io/netty/testsuite/util/DummyHandler.java | 34 - .../io/netty/testsuite/util/SctpTestUtil.java | 37 - 144 files changed, 5 insertions(+), 15555 deletions(-) delete mode 100644 transport-http/pom.xml delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/AcceptedServerChannelPipelineFactory.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/AcceptedServerChannelRequestDispatch.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/DefaultTunnelIdGenerator.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannel.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelConfig.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelFactory.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelReceiver.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelSink.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelChannelConfig.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannel.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelConfig.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelFactory.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelSink.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientPollHandler.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientSendHandler.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientWorkerOwner.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelMessageUtils.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannel.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelConfig.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelFactory.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelSink.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelingServlet.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/SaturationManager.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/SaturationStateChange.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitch.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitchDownstreamInterface.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitchUpstreamInterface.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/TunnelIdGenerator.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/TunnelWrappedServerChannelHandler.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/WriteFragmenter.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/WriteSplitter.java delete mode 100644 transport-http/src/main/java/io/netty/channel/socket/http/package-info.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/AcceptedServerChannelRequestDispatchTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/FakeChannelConfig.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/FakeChannelSink.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/FakeClientSocketChannelFactory.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannel.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannelConfig.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannelFactory.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/FakeSocketChannel.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelSinkTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientChannelConfigTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientChannelTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientPollHandlerTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientSendHandlerTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelFactoryTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelSinkTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelSoakTester.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/MockChannelStateListener.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/NettyTestUtils.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/NettyTestUtilsTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/NullChannelHandler.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/SaturationManagerTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/ServerMessageSwitchTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/UpstreamEventCatcher.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/WriteFragmenterTest.java delete mode 100644 transport-http/src/test/java/io/netty/channel/socket/http/WriteSplitterTest.java delete mode 100644 transport-rxtx/pom.xml delete mode 100644 transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java delete mode 100644 transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelConfig.java delete mode 100644 transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelFactory.java delete mode 100644 transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelSink.java delete mode 100644 transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxDeviceAddress.java delete mode 100644 transport-rxtx/src/main/java/io/netty/channel/rxtx/package-info.java delete mode 100644 transport-sctp/pom.xml delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/AbstractNotificationHandler.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/Association.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/AssociationChangeNotification.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/HandlerResult.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/MessageInfo.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/Notification.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/NotificationHandler.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/PeerAddressChangeNotification.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/SctpChannel.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/SctpServerChannel.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/SctpSocketOption.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/SctpStandardSocketOptions.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/SendFailedNotification.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/ShutdownNotification.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java delete mode 100644 transport-sctp/src/main/java/com/sun/nio/sctp/package-info.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/DefaultNioSctpChannelConfig.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/NioSctpChannelConfig.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpAcceptedChannel.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpBindAddressEvent.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannel.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelConfig.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelImpl.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientChannel.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientPipelineSink.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientSocketChannelFactory.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpFrame.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpJdkChannel.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationEvent.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationHandler.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpSendBufferPool.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannel.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannelConfig.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannelImpl.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerPipelineSink.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerSocketChannelFactory.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpUnbindAddressEvent.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorkerPool.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/codec/DefaultInboundStreamFilter.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/codec/DefaultOutboundStreamSelector.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/codec/InboundStreamFilter.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/codec/OutboundStreamSelector.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/codec/SctpFrameDecoder.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/codec/SctpFrameEncoder.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/codec/package-info.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpChannelHandler.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpDownstreamHandler.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpUpstreamHandler.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/handler/package-info.java delete mode 100644 transport-sctp/src/main/java/io/netty/channel/sctp/package-info.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketClientBootstrapTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketCompatibleObjectStreamEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketFixedLengthEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketObjectStreamEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketServerBootstrapTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketSslEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketStringEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpClientBootstrapTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpCompatibleObjectStreamEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpFixedLengthEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiHomingEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiStreamingEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpObjectStreamEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpServerBootstrapTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpSslEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpStringEchoTest.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/util/DummyHandler.java delete mode 100644 transport-sctp/src/test/java/io/netty/testsuite/util/SctpTestUtil.java diff --git a/example/pom.xml b/example/pom.xml index c06ddcb577..75f0d7d9c0 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -29,6 +29,11 @@ Netty/Example + + ${project.groupId} + netty-transport + ${project.version} + ${project.groupId} netty-handler @@ -39,11 +44,6 @@ netty-codec-http ${project.version} - - ${project.groupId} - netty-transport-sctp - ${project.version} - com.google.protobuf diff --git a/handler/pom.xml b/handler/pom.xml index 284046706b..4f89f71406 100644 --- a/handler/pom.xml +++ b/handler/pom.xml @@ -34,11 +34,6 @@ netty-buffer ${project.version} - - ${project.groupId} - netty-codec - ${project.version} - ${project.groupId} netty-transport diff --git a/pom.xml b/pom.xml index 5cd75226a5..27dd5a5c23 100644 --- a/pom.xml +++ b/pom.xml @@ -72,9 +72,6 @@ codec codec-http transport - transport-http - transport-rxtx - transport-sctp handler example all diff --git a/transport-http/pom.xml b/transport-http/pom.xml deleted file mode 100644 index 65e21d10f4..0000000000 --- a/transport-http/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - 4.0.0 - - io.netty - netty-parent - 4.0.0.Alpha1-SNAPSHOT - - - netty-transport-http - jar - - Netty/Transport/HTTP - - - - ${project.groupId} - netty-codec-http - ${project.version} - - - - - - javax.servlet - servlet-api - true - - - - diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/AcceptedServerChannelPipelineFactory.java b/transport-http/src/main/java/io/netty/channel/socket/http/AcceptedServerChannelPipelineFactory.java deleted file mode 100644 index 763aa634c9..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/AcceptedServerChannelPipelineFactory.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPipelineFactory; -import io.netty.channel.Channels; -import io.netty.handler.codec.http.HttpChunkAggregator; -import io.netty.handler.codec.http.HttpRequestDecoder; -import io.netty.handler.codec.http.HttpResponseEncoder; - -/** - * Creates pipelines for incoming http tunnel connections, capable of decoding the incoming HTTP - * requests, determining their type (client sending data, client polling data, or unknown) and - * handling them appropriately. - */ -class AcceptedServerChannelPipelineFactory implements ChannelPipelineFactory { - - private final ServerMessageSwitch messageSwitch; - - public AcceptedServerChannelPipelineFactory( - ServerMessageSwitch messageSwitch) { - this.messageSwitch = messageSwitch; - } - - @Override - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - - pipeline.addLast("httpResponseEncoder", new HttpResponseEncoder()); - pipeline.addLast("httpRequestDecoder", new HttpRequestDecoder()); - pipeline.addLast("httpChunkAggregator", new HttpChunkAggregator( - HttpTunnelMessageUtils.MAX_BODY_SIZE)); - pipeline.addLast("messageSwitchClient", - new AcceptedServerChannelRequestDispatch(messageSwitch)); - - return pipeline; - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/AcceptedServerChannelRequestDispatch.java b/transport-http/src/main/java/io/netty/channel/socket/http/AcceptedServerChannelRequestDispatch.java deleted file mode 100644 index 8ce8142bfc..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/AcceptedServerChannelRequestDispatch.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; - -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.Channels; -import io.netty.channel.MessageEvent; -import io.netty.channel.SimpleChannelUpstreamHandler; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; - -/** - * Upstream handler which is responsible for determining whether a received HTTP request is a legal - * tunnel request, and if so, invoking the appropriate request method on the - * {@link ServerMessageSwitch} to service the request. - */ -class AcceptedServerChannelRequestDispatch extends SimpleChannelUpstreamHandler { - - public static final String NAME = "AcceptedServerChannelRequestDispatch"; - - private static final InternalLogger LOG = InternalLoggerFactory - .getInstance(AcceptedServerChannelRequestDispatch.class); - - private final ServerMessageSwitchUpstreamInterface messageSwitch; - - public AcceptedServerChannelRequestDispatch( - ServerMessageSwitchUpstreamInterface messageSwitch) { - this.messageSwitch = messageSwitch; - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - HttpRequest request = (HttpRequest) e.getMessage(); - - if (HttpTunnelMessageUtils.isOpenTunnelRequest(request)) { - handleOpenTunnel(ctx); - } else if (HttpTunnelMessageUtils.isSendDataRequest(request)) { - handleSendData(ctx, request); - } else if (HttpTunnelMessageUtils.isReceiveDataRequest(request)) { - handleReceiveData(ctx, request); - } else if (HttpTunnelMessageUtils.isCloseTunnelRequest(request)) { - handleCloseTunnel(ctx, request); - } else { - respondWithRejection(ctx, request, - "invalid request to netty HTTP tunnel gateway"); - } - } - - private void handleOpenTunnel(ChannelHandlerContext ctx) { - String tunnelId = - messageSwitch.createTunnel((InetSocketAddress) ctx.channel() - .getRemoteAddress()); - if (LOG.isDebugEnabled()) { - LOG.debug("open tunnel request received from " + - ctx.channel().getRemoteAddress() + " - allocated ID " + - tunnelId); - } - respondWith(ctx, - HttpTunnelMessageUtils.createTunnelOpenResponse(tunnelId)); - } - - private void handleCloseTunnel(ChannelHandlerContext ctx, - HttpRequest request) { - String tunnelId = checkTunnelId(request, ctx); - if (tunnelId == null) { - return; - } - - if (LOG.isDebugEnabled()) { - LOG.debug("close tunnel request received for tunnel " + tunnelId); - } - messageSwitch.clientCloseTunnel(tunnelId); - respondWith(ctx, HttpTunnelMessageUtils.createTunnelCloseResponse()) - .addListener(ChannelFutureListener.CLOSE); - } - - private void handleSendData(ChannelHandlerContext ctx, HttpRequest request) { - String tunnelId = checkTunnelId(request, ctx); - if (tunnelId == null) { - return; - } - if (LOG.isDebugEnabled()) { - LOG.debug("send data request received for tunnel " + tunnelId); - } - - if (HttpHeaders.getContentLength(request, 0) == 0 || - request.getContent() == null || - request.getContent().readableBytes() == 0) { - respondWithRejection(ctx, request, - "Send data requests must contain data"); - return; - } - - messageSwitch.routeInboundData(tunnelId, request.getContent()); - respondWith(ctx, HttpTunnelMessageUtils.createSendDataResponse()); - } - - private void handleReceiveData(ChannelHandlerContext ctx, - HttpRequest request) { - String tunnelId = checkTunnelId(request, ctx); - if (tunnelId == null) { - return; - } - if (LOG.isDebugEnabled()) { - LOG.debug("poll data request received for tunnel " + tunnelId); - } - messageSwitch.pollOutboundData(tunnelId, ctx.channel()); - } - - private String checkTunnelId(HttpRequest request, ChannelHandlerContext ctx) { - String tunnelId = HttpTunnelMessageUtils.extractTunnelId(request); - if (tunnelId == null) { - respondWithRejection(ctx, request, - "no tunnel id specified in request"); - } else if (!messageSwitch.isOpenTunnel(tunnelId)) { - respondWithRejection(ctx, request, - "specified tunnel is either closed or does not exist"); - return null; - } - - return tunnelId; - } - - /** - * Sends the provided response back on the channel, returning the created ChannelFuture - * for this operation. - */ - private ChannelFuture respondWith(ChannelHandlerContext ctx, - HttpResponse response) { - ChannelFuture writeFuture = Channels.future(ctx.channel()); - Channels.write(ctx, writeFuture, response); - return writeFuture; - } - - /** - * Sends an HTTP 400 message back to on the channel with the specified error message, and asynchronously - * closes the channel after this is successfully sent. - */ - private void respondWithRejection(ChannelHandlerContext ctx, - HttpRequest rejectedRequest, String errorMessage) { - if (LOG.isWarnEnabled()) { - SocketAddress remoteAddress = ctx.channel().getRemoteAddress(); - String tunnelId = - HttpTunnelMessageUtils.extractTunnelId(rejectedRequest); - if (tunnelId == null) { - tunnelId = ""; - } - LOG.warn("Rejecting request from " + remoteAddress + - " representing tunnel " + tunnelId + ": " + errorMessage); - } - HttpResponse rejection = - HttpTunnelMessageUtils.createRejection(rejectedRequest, - errorMessage); - respondWith(ctx, rejection).addListener(ChannelFutureListener.CLOSE); - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/DefaultTunnelIdGenerator.java b/transport-http/src/main/java/io/netty/channel/socket/http/DefaultTunnelIdGenerator.java deleted file mode 100644 index 120f27b015..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/DefaultTunnelIdGenerator.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import java.security.SecureRandom; - -/** - * Default implementation of TunnelIdGenerator, which uses a - * {@link java.security.SecureRandom SecureRandom} generator - * to produce 32-bit tunnel identifiers. - */ -public class DefaultTunnelIdGenerator implements TunnelIdGenerator { - - private SecureRandom generator; - - public DefaultTunnelIdGenerator() { - this(new SecureRandom()); - } - - public DefaultTunnelIdGenerator(SecureRandom generator) { - this.generator = generator; - } - - @Override - public synchronized String generateId() { - // synchronized to ensure that this code is thread safe. The Sun - // standard implementations seem to be synchronized or lock free - // but are not documented as guaranteeing this - return Integer.toHexString(generator.nextInt()); - } - -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannel.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannel.java deleted file mode 100644 index 7fa4a5f124..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannel.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import static io.netty.channel.Channels.fireChannelBound; -import static io.netty.channel.Channels.fireChannelConnected; -import static io.netty.channel.Channels.fireChannelOpen; - -import java.net.InetSocketAddress; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.AbstractChannel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.SocketChannelConfig; - -/** - * Represents the server end of an HTTP tunnel, created after a legal tunnel creation - * request is received from a client. The server end of a tunnel does not have any - * directly related TCP connections - the connections used by a client are likely - * to change over the lifecycle of a tunnel, especially when an HTTP proxy is in - * use. - */ -final class HttpTunnelAcceptedChannel extends AbstractChannel implements - SocketChannel, HttpTunnelAcceptedChannelReceiver { - - private final HttpTunnelAcceptedChannelConfig config; - - private final HttpTunnelAcceptedChannelSink sink; - - private final InetSocketAddress remoteAddress; - - protected static HttpTunnelAcceptedChannel create( - HttpTunnelServerChannel parent, ChannelFactory factory, - ChannelPipeline pipeline, HttpTunnelAcceptedChannelSink sink, - InetSocketAddress remoteAddress, - HttpTunnelAcceptedChannelConfig config) { - HttpTunnelAcceptedChannel instance = new HttpTunnelAcceptedChannel(parent, factory, pipeline, sink, - remoteAddress, config); - fireChannelOpen(instance); - fireChannelBound(instance, instance.getLocalAddress()); - fireChannelConnected(instance, instance.getRemoteAddress()); - return instance; - } - - private HttpTunnelAcceptedChannel(HttpTunnelServerChannel parent, - ChannelFactory factory, ChannelPipeline pipeline, - HttpTunnelAcceptedChannelSink sink, - InetSocketAddress remoteAddress, - HttpTunnelAcceptedChannelConfig config) { - super(parent, factory, pipeline, sink); - this.config = config; - this.sink = sink; - this.remoteAddress = remoteAddress; - } - - @Override - public SocketChannelConfig getConfig() { - return config; - } - - @Override - public InetSocketAddress getLocalAddress() { - - return ((HttpTunnelServerChannel) getParent()).getLocalAddress(); - } - - @Override - public InetSocketAddress getRemoteAddress() { - return remoteAddress; - } - - @Override - public boolean isBound() { - return sink.isActive(); - } - - @Override - public boolean isConnected() { - return sink.isActive(); - } - - @Override - public void clientClosed() { - this.setClosed(); - Channels.fireChannelClosed(this); - } - - @Override - public void dataReceived(ChannelBuffer data) { - Channels.fireMessageReceived(this, data); - } - - @Override - public void updateInterestOps(SaturationStateChange transition) { - switch (transition) { - case SATURATED: - fireWriteEnabled(false); - break; - case DESATURATED: - fireWriteEnabled(true); - break; - case NO_CHANGE: - break; - } - } - - private void fireWriteEnabled(boolean enabled) { - int ops = OP_READ; - if (!enabled) { - ops |= OP_WRITE; - } - - setInterestOpsNow(ops); - Channels.fireChannelInterestChanged(this); - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelConfig.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelConfig.java deleted file mode 100644 index 6eb1d73c85..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelConfig.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -/** - * Configuration the server end of an http tunnel. - * - * These properties largely have no effect in the current implementation, and exist - * for API compatibility with TCP channels. With the exception of high / low water - * marks, any changes in the values will not be honoured. - */ -public class HttpTunnelAcceptedChannelConfig extends HttpTunnelChannelConfig { - - private static final int SO_LINGER_DISABLED = -1; - - private static final int FAKE_SEND_BUFFER_SIZE = 16 * 1024; - - private static final int FAKE_RECEIVE_BUFFER_SIZE = 16 * 1024; - - // based on the values in RFC 791 - private static final int DEFAULT_TRAFFIC_CLASS = 0; - - @Override - public boolean isTcpNoDelay() { - return true; - } - - @Override - public void setTcpNoDelay(boolean tcpNoDelay) { - // we do not allow the value to be changed, as it will not be honoured - } - - @Override - public int getSoLinger() { - return SO_LINGER_DISABLED; - } - - @Override - public void setSoLinger(int soLinger) { - // we do not allow the value to be changed, as it will not be honoured - } - - @Override - public int getSendBufferSize() { - return FAKE_SEND_BUFFER_SIZE; - } - - @Override - public void setSendBufferSize(int sendBufferSize) { - // we do not allow the value to be changed, as it will not be honoured - } - - @Override - public int getReceiveBufferSize() { - return FAKE_RECEIVE_BUFFER_SIZE; - } - - @Override - public void setReceiveBufferSize(int receiveBufferSize) { - // we do not allow the value to be changed, as it will not be honoured - } - - @Override - public boolean isKeepAlive() { - return true; - } - - @Override - public void setKeepAlive(boolean keepAlive) { - // we do not allow the value to be changed, as it will not be honoured - } - - @Override - public int getTrafficClass() { - return DEFAULT_TRAFFIC_CLASS; - } - - @Override - public void setTrafficClass(int trafficClass) { - // we do not allow the value to be changed, as it will not be honoured - } - - @Override - public boolean isReuseAddress() { - return false; - } - - @Override - public void setReuseAddress(boolean reuseAddress) { - // we do not allow the value to be changed, as it will not be honoured - } - - @Override - public void setPerformancePreferences(int connectionTime, int latency, - int bandwidth) { - // we do not allow the value to be changed, as it will not be honoured - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelFactory.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelFactory.java deleted file mode 100644 index 8a4f1e7540..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; - -/** - * Simple interface provided to a {@link ServerMessageSwitch}, allowing it to - * create the server end of tunnels in response to legal tunnel creation - * requests from clients. - */ -interface HttpTunnelAcceptedChannelFactory { - HttpTunnelAcceptedChannelReceiver newChannel(String newTunnelId, - InetSocketAddress remoteAddress); - - String generateTunnelId(); -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelReceiver.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelReceiver.java deleted file mode 100644 index f0caf07390..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelReceiver.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import io.netty.buffer.ChannelBuffer; - -/** - * Interface from the server message switch and channel sink to an - * accepted channel. Exists primarily for mock testing purposes. - * - - - - */ -interface HttpTunnelAcceptedChannelReceiver { - - void updateInterestOps(SaturationStateChange transition); - - void dataReceived(ChannelBuffer data); - - void clientClosed(); - -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelSink.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelSink.java deleted file mode 100644 index 5805456244..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelSink.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.util.concurrent.atomic.AtomicBoolean; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.AbstractChannelSink; -import io.netty.channel.Channel; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.Channels; -import io.netty.channel.MessageEvent; - -/** - * Sink for the server end of an http tunnel. Data sent down through the server end is dispatched - * from here to the ServerMessageSwitch, which queues the data awaiting a poll request from the - * client end of the tunnel. - */ -class HttpTunnelAcceptedChannelSink extends AbstractChannelSink { - - final SaturationManager saturationManager; - - private final ServerMessageSwitchDownstreamInterface messageSwitch; - - private final String tunnelId; - - private final AtomicBoolean active = new AtomicBoolean(false); - - private final HttpTunnelAcceptedChannelConfig config; - - public HttpTunnelAcceptedChannelSink( - ServerMessageSwitchDownstreamInterface messageSwitch, - String tunnelId, HttpTunnelAcceptedChannelConfig config) { - this.messageSwitch = messageSwitch; - this.tunnelId = tunnelId; - this.config = config; - saturationManager = - new SaturationManager(config.getWriteBufferLowWaterMark(), - config.getWriteBufferHighWaterMark()); - } - - @Override - public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) - throws Exception { - if (e instanceof MessageEvent) { - handleMessageEvent((MessageEvent) e); - } else if (e instanceof ChannelStateEvent) { - handleStateEvent((ChannelStateEvent) e); - } - } - - private void handleMessageEvent(MessageEvent ev) { - if (!(ev.getMessage() instanceof ChannelBuffer)) { - throw new IllegalArgumentException( - "Attempt to send data which is not a ChannelBuffer:" + - ev.getMessage()); - } - - final HttpTunnelAcceptedChannelReceiver channel = - (HttpTunnelAcceptedChannelReceiver) ev.channel(); - final ChannelBuffer message = (ChannelBuffer) ev.getMessage(); - final int messageSize = message.readableBytes(); - final ChannelFuture future = ev.getFuture(); - - saturationManager.updateThresholds(config.getWriteBufferLowWaterMark(), - config.getWriteBufferHighWaterMark()); - channel.updateInterestOps(saturationManager - .queueSizeChanged(messageSize)); - future.addListener(new ChannelFutureListener() { - - @Override - public void operationComplete(ChannelFuture future) - throws Exception { - channel.updateInterestOps(saturationManager - .queueSizeChanged(-messageSize)); - } - }); - messageSwitch.routeOutboundData(tunnelId, message, future); - } - - private void handleStateEvent(ChannelStateEvent ev) { - /* TODO: as any of disconnect, unbind or close destroys a server - channel, should we fire all three events always? */ - Channel owner = ev.channel(); - switch (ev.getState()) { - case OPEN: - if (Boolean.FALSE.equals(ev.getValue())) { - messageSwitch.serverCloseTunnel(tunnelId); - active.set(false); - Channels.fireChannelClosed(owner); - } - break; - case BOUND: - if (ev.getValue() == null) { - messageSwitch.serverCloseTunnel(tunnelId); - active.set(false); - Channels.fireChannelUnbound(owner); - } - case CONNECTED: - if (ev.getValue() == null) { - messageSwitch.serverCloseTunnel(tunnelId); - active.set(false); - Channels.fireChannelDisconnected(owner); - } - } - } - - public boolean isActive() { - return active.get(); - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelChannelConfig.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelChannelConfig.java deleted file mode 100644 index 9b0505e57b..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelChannelConfig.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import io.netty.channel.DefaultChannelConfig; -import io.netty.channel.socket.SocketChannelConfig; -import io.netty.channel.socket.nio.NioSocketChannelConfig; - -/** - * Configuration for HTTP tunnels. Where possible, properties set on this configuration will - * be applied to the two channels that service sending and receiving data on this end of the - * tunnel. - *

- * HTTP tunnel clients have the following additional options: - * - * - * - * - * - * - * - *
NameAssociated setter method
{@code "writeBufferHighWaterMark"}{@link #setWriteBufferHighWaterMark(int)}
{@code "writeBufferLowWaterMark"}{@link #setWriteBufferLowWaterMark(int)}
- */ -public abstract class HttpTunnelChannelConfig extends DefaultChannelConfig - implements SocketChannelConfig { - - /** - * The minimum value that the high water mark may be set to, in addition to the - * constraint that the high water mark must be strictly greater than the low - * water mark. - */ - public static final int MIN_HIGH_WATER_MARK = 1; - - /** - * The minimum value that the low water mark may be set to. - */ - public static final int MIN_LOW_WATER_MARK = 0; - - /** - * The default level for the write buffer's high water mark, presently set to - * 64KByte. - */ - public static final int DEFAULT_HIGH_WATER_MARK = 64 * 1024; - - /** - * The default level for the write buffer's low water mark, presently set to - * 32KByte. - */ - public static final int DEFAULT_LOW_WATER_MARK = 32 * 1024; - - static final String HIGH_WATER_MARK_OPTION = "writeBufferhHighWaterMark"; - - static final String LOW_WATER_MARK_OPTION = "writeBufferLowWaterMark"; - - protected volatile int writeBufferLowWaterMark = DEFAULT_LOW_WATER_MARK; - - protected volatile int writeBufferHighWaterMark = DEFAULT_HIGH_WATER_MARK; - - /** - * @return the current value (in bytes) of the high water mark. - */ - public int getWriteBufferHighWaterMark() { - return writeBufferHighWaterMark; - } - - /** - * Similarly to {@link io.netty.channel.socket.nio.NioSocketChannelConfig#setWriteBufferHighWaterMark(int) - * NioSocketChannelConfig.setWriteBufferHighWaterMark()}, - * the high water mark refers to the buffer size at which a user of the channel should stop writing. When the - * number of queued bytes exceeds the high water mark, {@link io.netty.channel.Channel#isWritable() Channel.isWritable()} will - * return false. Once the number of queued bytes falls below the {@link #setWriteBufferLowWaterMark(int) low water mark}, - * {@link io.netty.channel.Channel#isWritable() Channel.isWritable()} will return true again, indicating that the client - * can begin to send more data. - * - * @param level the number of queued bytes required to flip {@link io.netty.channel.Channel#isWritable()} to - * false. - * - * @see NioSocketChannelConfig#setWriteBufferHighWaterMark(int) - */ - public void setWriteBufferHighWaterMark(int level) { - if (level <= writeBufferLowWaterMark) { - throw new IllegalArgumentException( - "Write buffer high water mark must be strictly greater than the low water mark"); - } - - if (level < MIN_HIGH_WATER_MARK) { - throw new IllegalArgumentException( - "Cannot set write buffer high water mark lower than " + - MIN_HIGH_WATER_MARK); - } - - writeBufferHighWaterMark = level; - } - - /** - * @return the current value (in bytes) of the low water mark. - */ - public int getWriteBufferLowWaterMark() { - return writeBufferLowWaterMark; - } - - /** - * The low water mark refers to the "safe" size of the queued byte buffer at which more data can be enqueued. When - * the {@link #setWriteBufferHighWaterMark(int) high water mark} is exceeded, {@link io.netty.channel.Channel#isWritable() Channel.isWriteable()} - * will return false until the buffer drops below this level. By creating a sufficient gap between the high and low - * water marks, rapid oscillation between "write enabled" and "write disabled" can be avoided. - * - * @see io.netty.channel.socket.nio.NioSocketChannelConfig#setWriteBufferLowWaterMark(int) - */ - public void setWriteBufferLowWaterMark(int level) { - if (level >= writeBufferHighWaterMark) { - throw new IllegalArgumentException( - "Write buffer low water mark must be strictly less than the high water mark"); - } - - if (level < MIN_LOW_WATER_MARK) { - throw new IllegalArgumentException( - "Cannot set write buffer low water mark lower than " + - MIN_LOW_WATER_MARK); - } - - writeBufferLowWaterMark = level; - } - - @Override - public boolean setOption(String key, Object value) { - if (HIGH_WATER_MARK_OPTION.equals(key)) { - setWriteBufferHighWaterMark((Integer) value); - } else if (LOW_WATER_MARK_OPTION.equals(key)) { - setWriteBufferLowWaterMark((Integer) value); - } else { - return super.setOption(key, value); - } - - return true; - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannel.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannel.java deleted file mode 100644 index 5f35c04a63..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannel.java +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.concurrent.atomic.AtomicInteger; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.AbstractChannel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.MessageEvent; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.socket.ClientSocketChannelFactory; -import io.netty.channel.socket.SocketChannel; -import io.netty.handler.codec.http.HttpChunkAggregator; -import io.netty.handler.codec.http.HttpRequestEncoder; -import io.netty.handler.codec.http.HttpResponseDecoder; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; - -/** - * The client end of an HTTP tunnel, created by an {@link HttpTunnelClientChannelFactory}. Channels of - * this type are designed to emulate a normal TCP based socket channel as far as is feasible within the limitations - * of the HTTP 1.1 protocol, and the usage patterns permitted by commonly used HTTP proxies and firewalls. - */ -final class HttpTunnelClientChannel extends AbstractChannel implements - SocketChannel { - - static final InternalLogger LOG = InternalLoggerFactory - .getInstance(HttpTunnelClientChannel.class); - - private final HttpTunnelClientChannelConfig config; - - final SocketChannel sendChannel; - - final SocketChannel pollChannel; - - volatile String tunnelId; - - volatile ChannelFuture connectFuture; - - volatile boolean connected; - - volatile boolean bound; - - volatile InetSocketAddress serverAddress; - - volatile String serverHostName; - - private final WorkerCallbacks callbackProxy; - - private final SaturationManager saturationManager; - - protected static HttpTunnelClientChannel create(ChannelFactory factory, - ChannelPipeline pipeline, HttpTunnelClientChannelSink sink, - ClientSocketChannelFactory outboundFactory, - ChannelGroup realConnections) { - HttpTunnelClientChannel instance = new HttpTunnelClientChannel(factory, pipeline, sink, - outboundFactory, realConnections); - Channels.fireChannelOpen(instance); - return instance; - } - - /** - * @see HttpTunnelClientChannelFactory#newChannel(ChannelPipeline) - */ - private HttpTunnelClientChannel(ChannelFactory factory, - ChannelPipeline pipeline, HttpTunnelClientChannelSink sink, - ClientSocketChannelFactory outboundFactory, - ChannelGroup realConnections) { - super(null, factory, pipeline, sink); - - callbackProxy = new WorkerCallbacks(); - - sendChannel = outboundFactory.newChannel(createSendPipeline()); - pollChannel = outboundFactory.newChannel(createPollPipeline()); - config = - new HttpTunnelClientChannelConfig(sendChannel.getConfig(), - pollChannel.getConfig()); - saturationManager = - new SaturationManager(config.getWriteBufferLowWaterMark(), - config.getWriteBufferHighWaterMark()); - serverAddress = null; - - realConnections.add(sendChannel); - realConnections.add(pollChannel); - - } - - @Override - public HttpTunnelClientChannelConfig getConfig() { - return config; - } - - @Override - public boolean isBound() { - return bound; - } - - @Override - public boolean isConnected() { - return connected; - } - - @Override - public InetSocketAddress getLocalAddress() { - return sendChannel.getLocalAddress(); - } - - @Override - public InetSocketAddress getRemoteAddress() { - return serverAddress; - } - - @Override - protected boolean setClosed() { - return super.setClosed(); - } - - void onConnectRequest(ChannelFuture connectFuture, - InetSocketAddress remoteAddress) { - this.connectFuture = connectFuture; - /* if we are using a proxy, the remoteAddress is swapped here for the address of the proxy. - * The send and poll channels can later ask for the correct server address using - * getServerHostName(). - */ - serverAddress = remoteAddress; - - SocketAddress connectTarget; - if (config.getProxyAddress() != null) { - connectTarget = config.getProxyAddress(); - } else { - connectTarget = remoteAddress; - } - - Channels.connect(sendChannel, connectTarget); - } - - void onDisconnectRequest(final ChannelFuture disconnectFuture) { - ChannelFutureListener disconnectListener = - new ConsolidatingFutureListener(disconnectFuture, 2); - sendChannel.disconnect().addListener(disconnectListener); - pollChannel.disconnect().addListener(disconnectListener); - - disconnectFuture.addListener(new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) - throws Exception { - serverAddress = null; - } - }); - } - - void onBindRequest(InetSocketAddress localAddress, - final ChannelFuture bindFuture) { - ChannelFutureListener bindListener = - new ConsolidatingFutureListener(bindFuture, 2); - // bind the send channel to the specified local address, and the poll channel to - // an ephemeral port on the same interface as the send channel - sendChannel.bind(localAddress).addListener(bindListener); - InetSocketAddress pollBindAddress; - if (localAddress.isUnresolved()) { - pollBindAddress = - InetSocketAddress.createUnresolved( - localAddress.getHostName(), 0); - } else { - pollBindAddress = - new InetSocketAddress(localAddress.getAddress(), 0); - } - pollChannel.bind(pollBindAddress).addListener(bindListener); - } - - void onUnbindRequest(final ChannelFuture unbindFuture) { - ChannelFutureListener unbindListener = - new ConsolidatingFutureListener(unbindFuture, 2); - sendChannel.unbind().addListener(unbindListener); - pollChannel.unbind().addListener(unbindListener); - } - - void onCloseRequest(final ChannelFuture closeFuture) { - ChannelFutureListener closeListener = - new CloseConsolidatingFutureListener(closeFuture, 2); - sendChannel.close().addListener(closeListener); - pollChannel.close().addListener(closeListener); - } - - private ChannelPipeline createSendPipeline() { - ChannelPipeline pipeline = Channels.pipeline(); - - pipeline.addLast("reqencoder", new HttpRequestEncoder()); // downstream - pipeline.addLast("respdecoder", new HttpResponseDecoder()); // upstream - pipeline.addLast("aggregator", new HttpChunkAggregator( - HttpTunnelMessageUtils.MAX_BODY_SIZE)); // upstream - pipeline.addLast("sendHandler", new HttpTunnelClientSendHandler( - callbackProxy)); // both - pipeline.addLast("writeFragmenter", new WriteFragmenter( - HttpTunnelMessageUtils.MAX_BODY_SIZE)); - - return pipeline; - } - - private ChannelPipeline createPollPipeline() { - ChannelPipeline pipeline = Channels.pipeline(); - - pipeline.addLast("reqencoder", new HttpRequestEncoder()); // downstream - pipeline.addLast("respdecoder", new HttpResponseDecoder()); // upstream - pipeline.addLast("aggregator", new HttpChunkAggregator( - HttpTunnelMessageUtils.MAX_BODY_SIZE)); // upstream - pipeline.addLast(HttpTunnelClientPollHandler.NAME, - new HttpTunnelClientPollHandler(callbackProxy)); // both - - return pipeline; - } - - void setTunnelIdForPollChannel() { - HttpTunnelClientPollHandler pollHandler = - pollChannel.pipeline() - .get(HttpTunnelClientPollHandler.class); - pollHandler.setTunnelId(tunnelId); - } - - void sendData(final MessageEvent e) { - saturationManager.updateThresholds(config.getWriteBufferLowWaterMark(), - config.getWriteBufferHighWaterMark()); - final ChannelFuture originalFuture = e.getFuture(); - final ChannelBuffer message = (ChannelBuffer) e.getMessage(); - final int messageSize = message.readableBytes(); - updateSaturationStatus(messageSize); - Channels.write(sendChannel, e.getMessage()).addListener( - new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) - throws Exception { - if (future.isSuccess()) { - originalFuture.setSuccess(); - } else { - originalFuture.setFailure(future.cause()); - } - updateSaturationStatus(-messageSize); - } - }); - } - - void updateSaturationStatus(int queueSizeDelta) { - SaturationStateChange transition = - saturationManager.queueSizeChanged(queueSizeDelta); - switch (transition) { - case SATURATED: - fireWriteEnabled(false); - break; - case DESATURATED: - fireWriteEnabled(true); - break; - case NO_CHANGE: - break; - } - } - - private void fireWriteEnabled(boolean enabled) { - int ops = OP_READ; - if (!enabled) { - ops |= OP_WRITE; - } - - setInterestOpsNow(ops); - Channels.fireChannelInterestChanged(this); - } - - private static class ConsolidatingFutureListener implements ChannelFutureListener { - - private final ChannelFuture completionFuture; - - private final AtomicInteger eventsLeft; - - public ConsolidatingFutureListener(ChannelFuture completionFuture, - int numToConsolidate) { - this.completionFuture = completionFuture; - eventsLeft = new AtomicInteger(numToConsolidate); - } - - @Override - public void operationComplete(ChannelFuture future) throws Exception { - if (!future.isSuccess()) { - futureFailed(future); - } else { - if (eventsLeft.decrementAndGet() == 0) { - allFuturesComplete(); - } - } - } - - protected void allFuturesComplete() { - completionFuture.setSuccess(); - } - - protected void futureFailed(ChannelFuture future) { - completionFuture.setFailure(future.cause()); - } - } - - /** - * Close futures are a special case, as marking them as successful or failed has no effect. - * Instead, we must call setClosed() on the channel itself, once all the child channels are - * closed or if we fail to close them for whatever reason. - */ - private final class CloseConsolidatingFutureListener extends - ConsolidatingFutureListener { - - public CloseConsolidatingFutureListener(ChannelFuture completionFuture, - int numToConsolidate) { - super(completionFuture, numToConsolidate); - } - - @Override - protected void futureFailed(ChannelFuture future) { - LOG.warn("Failed to close one of the child channels of tunnel " + - tunnelId); - setClosed(); - } - - @Override - protected void allFuturesComplete() { - if (LOG.isDebugEnabled()) { - LOG.debug("Tunnel " + tunnelId + " closed"); - } - setClosed(); - } - - } - - /** - * Contains the implementing methods of HttpTunnelClientWorkerOwner, so that these are hidden - * from the public API. - */ - class WorkerCallbacks implements HttpTunnelClientWorkerOwner { - - @Override - public void onConnectRequest(ChannelFuture connectFuture, - InetSocketAddress remoteAddress) { - HttpTunnelClientChannel.this.onConnectRequest(connectFuture, - remoteAddress); - } - - @Override - public void onTunnelOpened(String tunnelId) { - HttpTunnelClientChannel.this.tunnelId = tunnelId; - setTunnelIdForPollChannel(); - Channels.connect(pollChannel, sendChannel.getRemoteAddress()); - } - - @Override - public void fullyEstablished() { - if (!bound) { - bound = true; - Channels.fireChannelBound(HttpTunnelClientChannel.this, - getLocalAddress()); - } - - connected = true; - connectFuture.setSuccess(); - Channels.fireChannelConnected(HttpTunnelClientChannel.this, - getRemoteAddress()); - } - - @Override - public void onMessageReceived(ChannelBuffer content) { - Channels.fireMessageReceived(HttpTunnelClientChannel.this, content); - } - - @Override - public String getServerHostName() { - if (serverHostName == null) { - serverHostName = - HttpTunnelMessageUtils - .convertToHostString(serverAddress); - } - - return serverHostName; - } - - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelConfig.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelConfig.java deleted file mode 100644 index 897d36b82c..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelConfig.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.SocketAddress; - -import io.netty.channel.socket.SocketChannelConfig; - -/** - * Configuration for the client end of an HTTP tunnel. Any socket channel properties set here - * will be applied uniformly to the underlying send and poll channels, created from the channel - * factory provided to the {@link HttpTunnelClientChannelFactory}. - *

- * HTTP tunnel clients have the following additional options: - * - * - * - * - * - * - * - * - *
NameAssociated setter method
{@code "proxyAddress"}{@link #setProxyAddress(SocketAddress)}
{@code "writeBufferHighWaterMark"}{@link #setWriteBufferHighWaterMark(int)}
{@code "writeBufferLowWaterMark"}{@link #setWriteBufferLowWaterMark(int)}
- */ -public class HttpTunnelClientChannelConfig extends HttpTunnelChannelConfig { - - static final String PROXY_ADDRESS_OPTION = "proxyAddress"; - - private final SocketChannelConfig sendChannelConfig; - - private final SocketChannelConfig pollChannelConfig; - - private volatile SocketAddress proxyAddress; - - HttpTunnelClientChannelConfig(SocketChannelConfig sendChannelConfig, - SocketChannelConfig pollChannelConfig) { - this.sendChannelConfig = sendChannelConfig; - this.pollChannelConfig = pollChannelConfig; - } - - /* HTTP TUNNEL SPECIFIC CONFIGURATION */ - // TODO Support all options in the old tunnel (see HttpTunnelingSocketChannelConfig) - // Mostly SSL, virtual host, and URL prefix - @Override - public boolean setOption(String key, Object value) { - if (PROXY_ADDRESS_OPTION.equals(key)) { - setProxyAddress((SocketAddress) value); - } else { - return super.setOption(key, value); - } - - return true; - } - - /** - * @return the address of the http proxy. If this is null, then no proxy - * should be used. - */ - public SocketAddress getProxyAddress() { - return proxyAddress; - } - - /** - * Specify a proxy to be used for the http tunnel. If this is null, then - * no proxy should be used, otherwise this should be a directly accessible IPv4/IPv6 - * address and port. - */ - public void setProxyAddress(SocketAddress proxyAddress) { - this.proxyAddress = proxyAddress; - } - - /* GENERIC SOCKET CHANNEL CONFIGURATION */ - - @Override - public int getReceiveBufferSize() { - return pollChannelConfig.getReceiveBufferSize(); - } - - @Override - public int getSendBufferSize() { - return pollChannelConfig.getSendBufferSize(); - } - - @Override - public int getSoLinger() { - return pollChannelConfig.getSoLinger(); - } - - @Override - public int getTrafficClass() { - return pollChannelConfig.getTrafficClass(); - } - - @Override - public boolean isKeepAlive() { - return pollChannelConfig.isKeepAlive(); - } - - @Override - public boolean isReuseAddress() { - return pollChannelConfig.isReuseAddress(); - } - - @Override - public boolean isTcpNoDelay() { - return pollChannelConfig.isTcpNoDelay(); - } - - @Override - public void setKeepAlive(boolean keepAlive) { - pollChannelConfig.setKeepAlive(keepAlive); - sendChannelConfig.setKeepAlive(keepAlive); - } - - @Override - public void setPerformancePreferences(int connectionTime, int latency, - int bandwidth) { - pollChannelConfig.setPerformancePreferences(connectionTime, latency, - bandwidth); - sendChannelConfig.setPerformancePreferences(connectionTime, latency, - bandwidth); - } - - @Override - public void setReceiveBufferSize(int receiveBufferSize) { - pollChannelConfig.setReceiveBufferSize(receiveBufferSize); - sendChannelConfig.setReceiveBufferSize(receiveBufferSize); - } - - @Override - public void setReuseAddress(boolean reuseAddress) { - pollChannelConfig.setReuseAddress(reuseAddress); - sendChannelConfig.setReuseAddress(reuseAddress); - } - - @Override - public void setSendBufferSize(int sendBufferSize) { - pollChannelConfig.setSendBufferSize(sendBufferSize); - sendChannelConfig.setSendBufferSize(sendBufferSize); - } - - @Override - public void setSoLinger(int soLinger) { - pollChannelConfig.setSoLinger(soLinger); - sendChannelConfig.setSoLinger(soLinger); - } - - @Override - public void setTcpNoDelay(boolean tcpNoDelay) { - pollChannelConfig.setTcpNoDelay(true); - sendChannelConfig.setTcpNoDelay(true); - } - - @Override - public void setTrafficClass(int trafficClass) { - pollChannelConfig.setTrafficClass(1); - sendChannelConfig.setTrafficClass(1); - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelFactory.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelFactory.java deleted file mode 100644 index dd7d0e16ae..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import io.netty.channel.ChannelPipeline; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.socket.ClientSocketChannelFactory; - -/** - * Factory used to create new client channels. - */ -public class HttpTunnelClientChannelFactory implements - ClientSocketChannelFactory { - - private final ClientSocketChannelFactory factory; - - private final ChannelGroup realConnections = new DefaultChannelGroup(); - - public HttpTunnelClientChannelFactory(ClientSocketChannelFactory factory) { - if (factory == null) { - throw new NullPointerException("factory"); - } - this.factory = factory; - } - - @Override - public HttpTunnelClientChannel newChannel(ChannelPipeline pipeline) { - return HttpTunnelClientChannel.create(this, pipeline, new HttpTunnelClientChannelSink(), factory, - realConnections); - } - - @Override - public void releaseExternalResources() { - realConnections.close().awaitUninterruptibly(); - factory.releaseExternalResources(); - } - -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelSink.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelSink.java deleted file mode 100644 index 5edf86ec54..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientChannelSink.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; - -import io.netty.channel.AbstractChannelSink; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.MessageEvent; - -/** - * Sink of a client channel, deals with sunk events and then makes appropriate calls - * on the channel itself to push data. - */ -class HttpTunnelClientChannelSink extends AbstractChannelSink { - - @Override - public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) - throws Exception { - if (e instanceof ChannelStateEvent) { - handleChannelStateEvent((ChannelStateEvent) e); - } else if (e instanceof MessageEvent) { - handleMessageEvent((MessageEvent) e); - } - } - - private void handleMessageEvent(MessageEvent e) { - HttpTunnelClientChannel channel = - (HttpTunnelClientChannel) e.channel(); - channel.sendData(e); - } - - private void handleChannelStateEvent(ChannelStateEvent e) { - HttpTunnelClientChannel channel = - (HttpTunnelClientChannel) e.channel(); - - switch (e.getState()) { - case CONNECTED: - if (e.getValue() != null) { - channel.onConnectRequest(e.getFuture(), - (InetSocketAddress) e.getValue()); - } else { - channel.onDisconnectRequest(e.getFuture()); - } - break; - case BOUND: - if (e.getValue() != null) { - channel.onBindRequest((InetSocketAddress) e.getValue(), - e.getFuture()); - } else { - channel.onUnbindRequest(e.getFuture()); - } - break; - case OPEN: - if (Boolean.FALSE.equals(e.getValue())) { - channel.onCloseRequest(e.getFuture()); - } - break; - } - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientPollHandler.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientPollHandler.java deleted file mode 100644 index b5cc36b4db..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientPollHandler.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.Channels; -import io.netty.channel.MessageEvent; -import io.netty.channel.SimpleChannelHandler; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; - -/** - * Pipeline component which controls the client poll loop to the server. - */ -class HttpTunnelClientPollHandler extends SimpleChannelHandler { - - public static final String NAME = "server2client"; - - private static final InternalLogger LOG = InternalLoggerFactory - .getInstance(HttpTunnelClientPollHandler.class); - - private String tunnelId; - - private final HttpTunnelClientWorkerOwner tunnelChannel; - - private long pollTime; - - public HttpTunnelClientPollHandler(HttpTunnelClientWorkerOwner tunnelChannel) { - this.tunnelChannel = tunnelChannel; - } - - public void setTunnelId(String tunnelId) { - this.tunnelId = tunnelId; - } - - @Override - public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - if (LOG.isDebugEnabled()) { - LOG.debug("Poll channel for tunnel " + tunnelId + " established"); - } - tunnelChannel.fullyEstablished(); - sendPoll(ctx); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - HttpResponse response = (HttpResponse) e.getMessage(); - - if (HttpTunnelMessageUtils.isOKResponse(response)) { - long rtTime = System.nanoTime() - pollTime; - if (LOG.isDebugEnabled()) { - LOG.debug("OK response received for poll on tunnel " + - tunnelId + " after " + rtTime + " ns"); - } - tunnelChannel.onMessageReceived(response.getContent()); - sendPoll(ctx); - } else { - if (LOG.isWarnEnabled()) { - LOG.warn("non-OK response received for poll on tunnel " + - tunnelId); - } - } - } - - private void sendPoll(ChannelHandlerContext ctx) { - pollTime = System.nanoTime(); - if (LOG.isDebugEnabled()) { - LOG.debug("sending poll request for tunnel " + tunnelId); - } - HttpRequest request = - HttpTunnelMessageUtils.createReceiveDataRequest( - tunnelChannel.getServerHostName(), tunnelId); - Channels.write(ctx, Channels.future(ctx.channel()), request); - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientSendHandler.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientSendHandler.java deleted file mode 100644 index 4fcf1cf41e..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientSendHandler.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.Channels; -import io.netty.channel.DownstreamMessageEvent; -import io.netty.channel.MessageEvent; -import io.netty.channel.SimpleChannelHandler; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; - -/** - * Pipeline component which deals with sending data from the client to server. - */ -class HttpTunnelClientSendHandler extends SimpleChannelHandler { - - public static final String NAME = "client2server"; - - private static final InternalLogger LOG = InternalLoggerFactory - .getInstance(HttpTunnelClientSendHandler.class); - - private final HttpTunnelClientWorkerOwner tunnelChannel; - - private String tunnelId; - - private final AtomicBoolean disconnecting; - - private ChannelStateEvent postShutdownEvent; - - private final ConcurrentLinkedQueue queuedWrites; - - private final AtomicInteger pendingRequestCount; - - private long sendRequestTime; - - public HttpTunnelClientSendHandler(HttpTunnelClientWorkerOwner tunnelChannel) { - this.tunnelChannel = tunnelChannel; - queuedWrites = new ConcurrentLinkedQueue(); - pendingRequestCount = new AtomicInteger(0); - disconnecting = new AtomicBoolean(false); - } - - @Override - public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - if (tunnelId == null) { - if (LOG.isDebugEnabled()) { - LOG.debug("connection to " + e.getValue() + - " succeeded - sending open tunnel request"); - } - HttpRequest request = - HttpTunnelMessageUtils - .createOpenTunnelRequest(tunnelChannel - .getServerHostName()); - Channel thisChannel = ctx.channel(); - DownstreamMessageEvent event = - new DownstreamMessageEvent(thisChannel, - Channels.future(thisChannel), request, - thisChannel.getRemoteAddress()); - queuedWrites.offer(event); - pendingRequestCount.incrementAndGet(); - sendQueuedData(ctx); - } - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - HttpResponse response = (HttpResponse) e.getMessage(); - - if (HttpTunnelMessageUtils.isOKResponse(response)) { - long roundTripTime = System.nanoTime() - sendRequestTime; - if (LOG.isDebugEnabled()) { - LOG.debug("OK response received for tunnel " + tunnelId + - ", after " + roundTripTime + " ns"); - } - sendNextAfterResponse(ctx); - } else if (HttpTunnelMessageUtils.isTunnelOpenResponse(response)) { - tunnelId = HttpTunnelMessageUtils.extractCookie(response); - if (LOG.isDebugEnabled()) { - LOG.debug("tunnel open request accepted - id " + tunnelId); - } - tunnelChannel.onTunnelOpened(tunnelId); - sendNextAfterResponse(ctx); - } else if (HttpTunnelMessageUtils.isTunnelCloseResponse(response)) { - if (LOG.isDebugEnabled()) { - if (disconnecting.get()) { - LOG.debug("server acknowledged disconnect for tunnel " + - tunnelId); - } else { - LOG.debug("server closed tunnel " + tunnelId); - } - } - ctx.sendDownstream(postShutdownEvent); - } else { - // TODO: kill connection - if (LOG.isWarnEnabled()) { - LOG.warn("unknown response received for tunnel " + tunnelId + - ", closing connection"); - } - Channels.close(ctx, ctx.channel().getCloseFuture()); - } - } - - private void sendNextAfterResponse(ChannelHandlerContext ctx) { - if (pendingRequestCount.decrementAndGet() > 0) { - if (LOG.isDebugEnabled()) { - LOG.debug("Immediately sending next send request for tunnel " + - tunnelId); - } - sendQueuedData(ctx); - } - } - - private synchronized void sendQueuedData(ChannelHandlerContext ctx) { - if (disconnecting.get()) { - if (LOG.isDebugEnabled()) { - LOG.debug("sending close request for tunnel " + tunnelId); - } - HttpRequest closeRequest = - HttpTunnelMessageUtils.createCloseTunnelRequest( - tunnelChannel.getServerHostName(), tunnelId); - Channels.write(ctx, Channels.future(ctx.channel()), closeRequest); - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("sending next request for tunnel " + tunnelId); - } - MessageEvent nextWrite = queuedWrites.poll(); - sendRequestTime = System.nanoTime(); - ctx.sendDownstream(nextWrite); - } - } - - @Override - public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - if (LOG.isDebugEnabled()) { - LOG.debug("request to send data for tunnel " + tunnelId); - } - if (disconnecting.get()) { - if (LOG.isWarnEnabled()) { - LOG.warn("rejecting write request for tunnel " + tunnelId + - " received after disconnect requested"); - } - e.getFuture().setFailure( - new IllegalStateException("tunnel is closing")); - return; - } - ChannelBuffer data = (ChannelBuffer) e.getMessage(); - HttpRequest request = - HttpTunnelMessageUtils.createSendDataRequest( - tunnelChannel.getServerHostName(), tunnelId, data); - DownstreamMessageEvent translatedEvent = - new DownstreamMessageEvent(ctx.channel(), e.getFuture(), - request, ctx.channel().getRemoteAddress()); - queuedWrites.offer(translatedEvent); - if (pendingRequestCount.incrementAndGet() == 1) { - sendQueuedData(ctx); - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("write request for tunnel " + tunnelId + " queued"); - } - } - } - - @Override - public void closeRequested(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - shutdownTunnel(ctx, e); - } - - @Override - public void disconnectRequested(ChannelHandlerContext ctx, - ChannelStateEvent e) throws Exception { - shutdownTunnel(ctx, e); - } - - @Override - public void unbindRequested(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - shutdownTunnel(ctx, e); - } - - private void shutdownTunnel(ChannelHandlerContext ctx, - ChannelStateEvent postShutdownEvent) { - if (LOG.isDebugEnabled()) { - LOG.debug("tunnel shutdown requested for send channel of tunnel " + - tunnelId); - } - if (!ctx.channel().isConnected()) { - if (LOG.isDebugEnabled()) { - LOG.debug("send channel of tunnel " + tunnelId + - " is already disconnected"); - } - ctx.sendDownstream(postShutdownEvent); - return; - } - - if (!disconnecting.compareAndSet(false, true)) { - if (LOG.isWarnEnabled()) { - LOG.warn("tunnel shutdown process already initiated for tunnel " + - tunnelId); - } - return; - } - - this.postShutdownEvent = postShutdownEvent; - - // if the channel is idle, send a close request immediately - if (pendingRequestCount.incrementAndGet() == 1) { - sendQueuedData(ctx); - } - } - - public String getTunnelId() { - return tunnelId; - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientWorkerOwner.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientWorkerOwner.java deleted file mode 100644 index e37195bf74..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelClientWorkerOwner.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.ChannelFuture; - -/** - * Interface which is used by the send and poll "worker" channels - * to notify the virtual tunnel channel of key events, and to get - * access to higher level information required for correct - * operation. - */ -interface HttpTunnelClientWorkerOwner { - /** - * The HTTP tunnel client sink invokes this when the application code requests the connection - * of an HTTP tunnel to the specified remote address. - */ - void onConnectRequest(ChannelFuture connectFuture, - InetSocketAddress remoteAddress); - - /** - * The send channel handler calls this method when the server accepts the open tunnel request, - * returning a unique tunnel ID. - * - * @param tunnelId the server allocated tunnel ID - */ - void onTunnelOpened(String tunnelId); - - /** - * The poll channel handler calls this method when the poll channel is connected, indicating - * that full duplex communications are now possible. - */ - void fullyEstablished(); - - /** - * The poll handler calls this method when some data is received and decoded from the server. - * @param content the data received from the server - */ - void onMessageReceived(ChannelBuffer content); - - /** - * @return the name of the server with whom we are communicating with - this is used within - * the HOST HTTP header for all requests. This is particularly important for operation behind - * a proxy, where the HOST string is used to route the request. - */ - String getServerHostName(); - -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelMessageUtils.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelMessageUtils.java deleted file mode 100644 index 81e81cb88f..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelMessageUtils.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.io.StringWriter; -import java.io.UnsupportedEncodingException; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Arrays; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.handler.codec.http.DefaultHttpRequest; -import io.netty.handler.codec.http.DefaultHttpResponse; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; - -/** - * Utility class for creating http requests for the operation of the full duplex - * http tunnel, and verifying that received requests are of the correct types. - */ -final class HttpTunnelMessageUtils { - - private static final String HTTP_URL_PREFIX = "http://"; - - /** - * An upper bound is enforced on the size of message bodies, so as - * to ensure we do not dump large chunks of data on either peer. - */ - public static final int MAX_BODY_SIZE = 16 * 1024; - - /** - * The tunnel will only accept connections from this specific user agent. This - * allows us to distinguish a legitimate tunnel connection from someone pointing - * a web browser or robot at the tunnel URL. - */ - static final String USER_AGENT = "HttpTunnelClient"; - - static final String OPEN_TUNNEL_REQUEST_URI = "/http-tunnel/open"; - - static final String CLOSE_TUNNEL_REQUEST_URI = "/http-tunnel/close"; - - static final String CLIENT_SEND_REQUEST_URI = "/http-tunnel/send"; - - static final String CLIENT_RECV_REQUEST_URI = "/http-tunnel/poll"; - - static final String CONTENT_TYPE = "application/octet-stream"; - - public static HttpRequest createOpenTunnelRequest(SocketAddress host) { - return createOpenTunnelRequest(convertToHostString(host)); - } - - public static HttpRequest createOpenTunnelRequest(String host) { - HttpRequest request = - createRequestTemplate(host, null, OPEN_TUNNEL_REQUEST_URI); - setNoData(request); - return request; - } - - public static boolean isOpenTunnelRequest(HttpRequest request) { - return isRequestTo(request, OPEN_TUNNEL_REQUEST_URI); - } - - public static boolean checkHost(HttpRequest request, - SocketAddress expectedHost) { - String host = request.getHeader(HttpHeaders.Names.HOST); - return expectedHost == null? host == null : HttpTunnelMessageUtils - .convertToHostString(expectedHost).equals(host); - } - - public static HttpRequest createSendDataRequest(SocketAddress host, - String cookie, ChannelBuffer data) { - return createSendDataRequest(convertToHostString(host), cookie, data); - } - - public static HttpRequest createSendDataRequest(String host, String cookie, - ChannelBuffer data) { - HttpRequest request = - createRequestTemplate(host, cookie, CLIENT_SEND_REQUEST_URI); - request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, - Long.toString(data.readableBytes())); - request.setContent(data); - - return request; - } - - public static boolean isSendDataRequest(HttpRequest request) { - return isRequestTo(request, CLIENT_SEND_REQUEST_URI); - } - - public static HttpRequest createReceiveDataRequest(SocketAddress host, - String tunnelId) { - return createReceiveDataRequest(convertToHostString(host), tunnelId); - } - - public static HttpRequest createReceiveDataRequest(String host, - String tunnelId) { - HttpRequest request = - createRequestTemplate(host, tunnelId, CLIENT_RECV_REQUEST_URI); - setNoData(request); - return request; - } - - public static boolean isReceiveDataRequest(HttpRequest request) { - return isRequestTo(request, CLIENT_RECV_REQUEST_URI); - } - - public static HttpRequest createCloseTunnelRequest(String host, - String tunnelId) { - HttpRequest request = - createRequestTemplate(host, tunnelId, CLOSE_TUNNEL_REQUEST_URI); - setNoData(request); - return request; - } - - public static boolean isCloseTunnelRequest(HttpRequest request) { - return isRequestTo(request, CLOSE_TUNNEL_REQUEST_URI); - } - - public static boolean isServerToClientRequest(HttpRequest request) { - return isRequestTo(request, CLIENT_RECV_REQUEST_URI); - } - - public static String convertToHostString(SocketAddress hostAddress) { - StringWriter host = new StringWriter(); - InetSocketAddress inetSocketAddr = (InetSocketAddress) hostAddress; - InetAddress addr = inetSocketAddr.getAddress(); - if (addr instanceof Inet6Address) { - host.append('['); - host.append(addr.getHostAddress()); - host.append(']'); - } else if (addr != null) { - host.append(addr.getHostAddress()); - } else { - host.append(inetSocketAddr.getHostName()); - } - - host.append(':'); - host.append(Integer.toString(inetSocketAddr.getPort())); - return host.toString(); - } - - private static HttpRequest createRequestTemplate(String host, - String tunnelId, String uri) { - HttpRequest request = - new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, - createCompleteUri(host, uri)); - request.setHeader(HttpHeaders.Names.HOST, host); - request.setHeader(HttpHeaders.Names.USER_AGENT, USER_AGENT); - if (tunnelId != null) { - request.setHeader(HttpHeaders.Names.COOKIE, tunnelId); - } - - return request; - } - - private static String createCompleteUri(String host, String uri) { - StringBuilder builder = - new StringBuilder(HTTP_URL_PREFIX.length() + host.length() + - uri.length()); - builder.append(HTTP_URL_PREFIX); - builder.append(host); - builder.append(uri); - - return builder.toString(); - } - - private static boolean isRequestTo(HttpRequest request, String uri) { - URI decodedUri; - try { - decodedUri = new URI(request.getUri()); - } catch (URISyntaxException e) { - return false; - } - - return HttpVersion.HTTP_1_1.equals(request.getProtocolVersion()) && - USER_AGENT.equals(request - .getHeader(HttpHeaders.Names.USER_AGENT)) && - HttpMethod.POST.equals(request.getMethod()) && - uri.equals(decodedUri.getPath()); - } - - private static void setNoData(HttpRequest request) { - request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, "0"); - request.setContent(null); - } - - public static String extractTunnelId(HttpRequest request) { - return request.getHeader(HttpHeaders.Names.COOKIE); - } - - private static byte[] toBytes(String string) { - try { - return string.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - // UTF-8 is meant to be supported on all platforms - throw new RuntimeException("UTF-8 encoding not supported!"); - } - } - - public static HttpResponse createTunnelOpenResponse(String tunnelId) { - HttpResponse response = - createResponseTemplate(HttpResponseStatus.CREATED, null); - response.setHeader(HttpHeaders.Names.SET_COOKIE, tunnelId); - return response; - } - - public static boolean isTunnelOpenResponse(HttpResponse response) { - return isResponseWithCode(response, HttpResponseStatus.CREATED); - } - - public static boolean isOKResponse(HttpResponse response) { - return isResponseWithCode(response, HttpResponseStatus.OK); - } - - public static boolean hasContents(HttpResponse response, - byte[] expectedContents) { - if (response.getContent() != null && - HttpHeaders.getContentLength(response, 0) == expectedContents.length && - response.getContent().readableBytes() == expectedContents.length) { - byte[] compareBytes = new byte[expectedContents.length]; - response.getContent().readBytes(compareBytes); - return Arrays.equals(expectedContents, compareBytes); - } - - return false; - } - - public static HttpResponse createTunnelCloseResponse() { - return createResponseTemplate(HttpResponseStatus.RESET_CONTENT, null); - } - - public static boolean isTunnelCloseResponse(HttpResponse response) { - return isResponseWithCode(response, HttpResponseStatus.RESET_CONTENT); - } - - public static String extractCookie(HttpResponse response) { - if (response.containsHeader(HttpHeaders.Names.SET_COOKIE)) { - return response.getHeader(HttpHeaders.Names.SET_COOKIE); - } - - return null; - } - - public static HttpResponse createSendDataResponse() { - return createOKResponseTemplate(null); - } - - public static HttpResponse createRecvDataResponse(ChannelBuffer data) { - return createOKResponseTemplate(data); - } - - public static HttpResponse createRejection(HttpRequest request, - String reason) { - HttpVersion version = - request != null? request.getProtocolVersion() - : HttpVersion.HTTP_1_1; - HttpResponse response = - new DefaultHttpResponse(version, HttpResponseStatus.BAD_REQUEST); - response.setHeader(HttpHeaders.Names.CONTENT_TYPE, - "text/plain; charset=\"utf-8\""); - ChannelBuffer reasonBuffer = - ChannelBuffers.wrappedBuffer(toBytes(reason)); - response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, - Integer.toString(reasonBuffer.readableBytes())); - response.setContent(reasonBuffer); - return response; - } - - public static boolean isRejection(HttpResponse response) { - return !HttpResponseStatus.OK.equals(response.getStatus()); - } - - public static Object extractErrorMessage(HttpResponse response) { - if (response.getContent() == null || - HttpHeaders.getContentLength(response, 0) == 0) { - return ""; - } - - byte[] bytes = new byte[response.getContent().readableBytes()]; - response.getContent().readBytes(bytes); - try { - return new String(bytes, "UTF-8"); - } catch (UnsupportedEncodingException e) { - return ""; - } - } - - private static boolean isResponseWithCode(HttpResponse response, - HttpResponseStatus status) { - return HttpVersion.HTTP_1_1.equals(response.getProtocolVersion()) && - status.equals(response.getStatus()); - } - - private static HttpResponse createOKResponseTemplate(ChannelBuffer data) { - return createResponseTemplate(HttpResponseStatus.OK, data); - } - - private static HttpResponse createResponseTemplate( - HttpResponseStatus status, ChannelBuffer data) { - HttpResponse response = - new DefaultHttpResponse(HttpVersion.HTTP_1_1, status); - if (data != null) { - response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, - Integer.toString(data.readableBytes())); - response.setHeader(HttpHeaders.Names.CONTENT_TYPE, - "application/octet-stream"); - response.setContent(data); - } else { - response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, "0"); - response.setContent(null); - } - return response; - } - - private HttpTunnelMessageUtils() { - // Unused - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannel.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannel.java deleted file mode 100644 index d4b5f8ae06..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannel.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; - -import io.netty.channel.AbstractServerChannel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPipelineException; -import io.netty.channel.Channels; -import io.netty.channel.socket.ServerSocketChannel; -import io.netty.channel.socket.ServerSocketChannelConfig; - -/** - */ -final class HttpTunnelServerChannel extends AbstractServerChannel implements - ServerSocketChannel { - - private final ServerSocketChannel realChannel; - - final HttpTunnelServerChannelConfig config; - - final ServerMessageSwitch messageSwitch; - - private final ChannelFutureListener CLOSE_FUTURE_PROXY = - new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) - throws Exception { - HttpTunnelServerChannel.this.setClosed(); - } - }; - - protected static HttpTunnelServerChannel create( - HttpTunnelServerChannelFactory factory, ChannelPipeline pipeline) { - HttpTunnelServerChannel instance = new HttpTunnelServerChannel(factory, pipeline); - Channels.fireChannelOpen(instance); - return instance; - } - - private HttpTunnelServerChannel(HttpTunnelServerChannelFactory factory, - ChannelPipeline pipeline) { - super(factory, pipeline, new HttpTunnelServerChannelSink()); - - messageSwitch = new ServerMessageSwitch(new TunnelCreator()); - realChannel = factory.createRealChannel(this, messageSwitch); - // TODO fix calling of overrideable getPipeline() from constructor - HttpTunnelServerChannelSink sink = - (HttpTunnelServerChannelSink) pipeline().getSink(); - sink.setRealChannel(realChannel); - sink.setCloseListener(CLOSE_FUTURE_PROXY); - config = new HttpTunnelServerChannelConfig(realChannel); - } - - @Override - public ServerSocketChannelConfig getConfig() { - return config; - } - - @Override - public InetSocketAddress getLocalAddress() { - return realChannel.getLocalAddress(); - } - - @Override - public InetSocketAddress getRemoteAddress() { - // server channels never have a remote address - return null; - } - - @Override - public boolean isBound() { - return realChannel.isBound(); - } - - @Override - protected boolean setClosed() { - return super.setClosed(); - } - - /** - * Used to hide the newChannel method from the public API. - */ - private final class TunnelCreator implements - HttpTunnelAcceptedChannelFactory { - - TunnelCreator() { - } - - @Override - public HttpTunnelAcceptedChannelReceiver newChannel( - String newTunnelId, InetSocketAddress remoteAddress) { - ChannelPipeline childPipeline = null; - try { - childPipeline = getConfig().getPipelineFactory().pipeline(); - } catch (Exception e) { - throw new ChannelPipelineException( - "Failed to initialize a pipeline.", e); - } - HttpTunnelAcceptedChannelConfig config = - new HttpTunnelAcceptedChannelConfig(); - HttpTunnelAcceptedChannelSink sink = - new HttpTunnelAcceptedChannelSink(messageSwitch, - newTunnelId, config); - return HttpTunnelAcceptedChannel.create(HttpTunnelServerChannel.this, getFactory(), childPipeline, sink, - remoteAddress, config); - } - - @Override - public String generateTunnelId() { - return config.getTunnelIdGenerator().generateId(); - } - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelConfig.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelConfig.java deleted file mode 100644 index 4c18fc30f2..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelConfig.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.util.Map; -import java.util.Map.Entry; - -import io.netty.buffer.ChannelBufferFactory; -import io.netty.channel.ChannelPipelineFactory; -import io.netty.channel.socket.ServerSocketChannel; -import io.netty.channel.socket.ServerSocketChannelConfig; - -/** - */ -public class HttpTunnelServerChannelConfig implements ServerSocketChannelConfig { - - private ChannelPipelineFactory pipelineFactory; - - private final ServerSocketChannel realChannel; - - private TunnelIdGenerator tunnelIdGenerator = - new DefaultTunnelIdGenerator(); - - public HttpTunnelServerChannelConfig(ServerSocketChannel realChannel) { - this.realChannel = realChannel; - } - - private ServerSocketChannelConfig getWrappedConfig() { - return realChannel.getConfig(); - } - - @Override - public int getBacklog() { - return getWrappedConfig().getBacklog(); - } - - @Override - public int getReceiveBufferSize() { - return getWrappedConfig().getReceiveBufferSize(); - } - - @Override - public boolean isReuseAddress() { - return getWrappedConfig().isReuseAddress(); - } - - @Override - public void setBacklog(int backlog) { - getWrappedConfig().setBacklog(backlog); - } - - @Override - public void setPerformancePreferences(int connectionTime, int latency, - int bandwidth) { - getWrappedConfig().setPerformancePreferences(connectionTime, latency, - bandwidth); - } - - @Override - public void setReceiveBufferSize(int receiveBufferSize) { - getWrappedConfig().setReceiveBufferSize(receiveBufferSize); - } - - @Override - public void setReuseAddress(boolean reuseAddress) { - getWrappedConfig().setReuseAddress(reuseAddress); - } - - @Override - public ChannelBufferFactory getBufferFactory() { - return getWrappedConfig().getBufferFactory(); - } - - @Override - public int getConnectTimeoutMillis() { - return getWrappedConfig().getConnectTimeoutMillis(); - } - - @Override - public ChannelPipelineFactory getPipelineFactory() { - return pipelineFactory; - } - - @Override - public void setBufferFactory(ChannelBufferFactory bufferFactory) { - getWrappedConfig().setBufferFactory(bufferFactory); - } - - @Override - public void setConnectTimeoutMillis(int connectTimeoutMillis) { - getWrappedConfig().setConnectTimeoutMillis(connectTimeoutMillis); - } - - @Override - public boolean setOption(String name, Object value) { - if (name.equals("pipelineFactory")) { - setPipelineFactory((ChannelPipelineFactory) value); - return true; - } else if (name.equals("tunnelIdGenerator")) { - setTunnelIdGenerator((TunnelIdGenerator) value); - return true; - } else { - return getWrappedConfig().setOption(name, value); - } - } - - @Override - public void setOptions(Map options) { - for (Entry e: options.entrySet()) { - setOption(e.getKey(), e.getValue()); - } - } - - @Override - public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) { - this.pipelineFactory = pipelineFactory; - } - - public void setTunnelIdGenerator(TunnelIdGenerator tunnelIdGenerator) { - this.tunnelIdGenerator = tunnelIdGenerator; - } - - public TunnelIdGenerator getTunnelIdGenerator() { - return tunnelIdGenerator; - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelFactory.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelFactory.java deleted file mode 100644 index 21dfcfde0a..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.socket.ServerSocketChannel; -import io.netty.channel.socket.ServerSocketChannelFactory; - -/** - */ -public class HttpTunnelServerChannelFactory implements - ServerSocketChannelFactory { - - private final ServerSocketChannelFactory realConnectionFactory; - - private final ChannelGroup realConnections; - - public HttpTunnelServerChannelFactory( - ServerSocketChannelFactory realConnectionFactory) { - this.realConnectionFactory = realConnectionFactory; - realConnections = new DefaultChannelGroup(); - } - - @Override - public HttpTunnelServerChannel newChannel(ChannelPipeline pipeline) { - return HttpTunnelServerChannel.create(this, pipeline); - } - - ServerSocketChannel createRealChannel(HttpTunnelServerChannel channel, - ServerMessageSwitch messageSwitch) { - ChannelPipeline realChannelPipeline = Channels.pipeline(); - AcceptedServerChannelPipelineFactory realPipelineFactory = - new AcceptedServerChannelPipelineFactory(messageSwitch); - realChannelPipeline.addFirst(TunnelWrappedServerChannelHandler.NAME, - new TunnelWrappedServerChannelHandler(channel, - realPipelineFactory, realConnections)); - ServerSocketChannel newChannel = - realConnectionFactory.newChannel(realChannelPipeline); - realConnections.add(newChannel); - return newChannel; - } - - @Override - public void releaseExternalResources() { - realConnections.close().awaitUninterruptibly(); - realConnectionFactory.releaseExternalResources(); - } - -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelSink.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelSink.java deleted file mode 100644 index d7aa5b0f12..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelServerChannelSink.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.SocketAddress; - -import io.netty.channel.AbstractChannelSink; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.socket.ServerSocketChannel; - -/** - */ -class HttpTunnelServerChannelSink extends AbstractChannelSink { - - private ChannelFutureListener closeHook; - - private ServerSocketChannel realChannel; - - @Override - public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) - throws Exception { - - if (e instanceof ChannelStateEvent) { - ChannelStateEvent ev = (ChannelStateEvent) e; - switch (ev.getState()) { - case OPEN: - if (Boolean.FALSE.equals(ev.getValue())) { - realChannel.close().addListener(closeHook); - } - break; - case BOUND: - if (ev.getValue() != null) { - realChannel.bind((SocketAddress) ev.getValue()) - .addListener(new ChannelFutureProxy(e.getFuture())); - } else { - realChannel.unbind().addListener( - new ChannelFutureProxy(e.getFuture())); - } - break; - } - } - } - - private static final class ChannelFutureProxy implements ChannelFutureListener { - private final ChannelFuture upstreamFuture; - - ChannelFutureProxy(ChannelFuture upstreamFuture) { - this.upstreamFuture = upstreamFuture; - } - - @Override - public void operationComplete(ChannelFuture future) throws Exception { - if (future.isSuccess()) { - upstreamFuture.setSuccess(); - } else { - upstreamFuture.setFailure(future.cause()); - } - } - } - - public void setRealChannel(ServerSocketChannel realChannel) { - this.realChannel = realChannel; - } - - public void setCloseListener(ChannelFutureListener closeHook) { - this.closeHook = closeHook; - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelingServlet.java b/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelingServlet.java deleted file mode 100644 index 6d44bae295..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/HttpTunnelingServlet.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.io.EOFException; -import java.io.IOException; -import java.io.PushbackInputStream; -import java.net.SocketAddress; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.ExceptionEvent; -import io.netty.channel.MessageEvent; -import io.netty.channel.SimpleChannelUpstreamHandler; -import io.netty.channel.local.DefaultLocalClientChannelFactory; -import io.netty.channel.local.LocalAddress; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; - -/** - * An {@link HttpServlet} that proxies an incoming data to the actual server - * and vice versa. Please refer to the - * package summary for - * the detailed usage. - * @apiviz.landmark - */ -public class HttpTunnelingServlet extends HttpServlet { - - private static final long serialVersionUID = 4259910275899756070L; - - private static final String ENDPOINT = "endpoint"; - - static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpTunnelingServlet.class); - - private volatile SocketAddress remoteAddress; - private volatile ChannelFactory channelFactory; - - @Override - public void init() throws ServletException { - ServletConfig config = getServletConfig(); - String endpoint = config.getInitParameter(ENDPOINT); - if (endpoint == null) { - throw new ServletException("init-param '" + ENDPOINT + "' must be specified."); - } - - try { - remoteAddress = parseEndpoint(endpoint.trim()); - } catch (ServletException e) { - throw e; - } catch (Exception e) { - throw new ServletException("Failed to parse an endpoint.", e); - } - - try { - channelFactory = createChannelFactory(remoteAddress); - } catch (ServletException e) { - throw e; - } catch (Exception e) { - throw new ServletException("Failed to create a channel factory.", e); - } - - // Stuff for testing purpose - //ServerBootstrap b = new ServerBootstrap(new DefaultLocalServerChannelFactory()); - //b.getPipeline().addLast("logger", new LoggingHandler(getClass(), InternalLogLevel.INFO, true)); - //b.getPipeline().addLast("handler", new EchoHandler()); - //b.bind(remoteAddress); - } - - protected SocketAddress parseEndpoint(String endpoint) throws Exception { - if (endpoint.startsWith("local:")) { - return new LocalAddress(endpoint.substring(6).trim()); - } else { - throw new ServletException( - "Invalid or unknown endpoint: " + endpoint); - } - } - - protected ChannelFactory createChannelFactory(SocketAddress remoteAddress) throws Exception { - if (remoteAddress instanceof LocalAddress) { - return new DefaultLocalClientChannelFactory(); - } else { - throw new ServletException( - "Unsupported remote address type: " + - remoteAddress.getClass().getName()); - } - } - - @Override - public void destroy() { - try { - destroyChannelFactory(channelFactory); - } catch (Exception e) { - if (logger.isWarnEnabled()) { - logger.warn("Failed to destroy a channel factory.", e); - } - } - } - - protected void destroyChannelFactory(ChannelFactory factory) throws Exception { - factory.releaseExternalResources(); - } - - @Override - protected void service(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { - if (!"POST".equalsIgnoreCase(req.getMethod())) { - if (logger.isWarnEnabled()) { - logger.warn("Unallowed method: " + req.getMethod()); - } - res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); - return; - } - - final ChannelPipeline pipeline = Channels.pipeline(); - final ServletOutputStream out = res.getOutputStream(); - final OutboundConnectionHandler handler = new OutboundConnectionHandler(out); - pipeline.addLast("handler", handler); - - Channel channel = channelFactory.newChannel(pipeline); - ChannelFuture future = channel.connect(remoteAddress).awaitUninterruptibly(); - if (!future.isSuccess()) { - Throwable cause = future.cause(); - if (logger.isWarnEnabled()) { - logger.warn("Endpoint unavailable: " + cause.getMessage(), cause); - } - res.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); - return; - } - - ChannelFuture lastWriteFuture = null; - try { - res.setStatus(HttpServletResponse.SC_OK); - res.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/octet-stream"); - res.setHeader(HttpHeaders.Names.CONTENT_TRANSFER_ENCODING, HttpHeaders.Values.BINARY); - - // Initiate chunked encoding by flushing the headers. - out.flush(); - - PushbackInputStream in = - new PushbackInputStream(req.getInputStream()); - while (channel.isConnected()) { - ChannelBuffer buffer; - try { - buffer = read(in); - } catch (EOFException e) { - break; - } - if (buffer == null) { - break; - } - lastWriteFuture = channel.write(buffer); - } - } finally { - if (lastWriteFuture == null) { - channel.close(); - } else { - lastWriteFuture.addListener(ChannelFutureListener.CLOSE); - } - } - } - - private static ChannelBuffer read(PushbackInputStream in) throws IOException { - byte[] buf; - int readBytes; - - int bytesToRead = in.available(); - if (bytesToRead > 0) { - buf = new byte[bytesToRead]; - readBytes = in.read(buf); - } else if (bytesToRead == 0) { - int b = in.read(); - if (b < 0 || in.available() < 0) { - return null; - } - in.unread(b); - bytesToRead = in.available(); - buf = new byte[bytesToRead]; - readBytes = in.read(buf); - } else { - return null; - } - - assert readBytes > 0; - - ChannelBuffer buffer; - if (readBytes == buf.length) { - buffer = ChannelBuffers.wrappedBuffer(buf); - } else { - // A rare case, but it sometimes happen. - buffer = ChannelBuffers.wrappedBuffer(buf, 0, readBytes); - } - return buffer; - } - - private static final class OutboundConnectionHandler extends SimpleChannelUpstreamHandler { - - private final ServletOutputStream out; - - public OutboundConnectionHandler(ServletOutputStream out) { - this.out = out; - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ChannelBuffer buffer = (ChannelBuffer) e.getMessage(); - synchronized (this) { - buffer.readBytes(out, buffer.readableBytes()); - out.flush(); - } - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { - if (logger.isWarnEnabled()) { - logger.warn("Unexpected exception while HTTP tunneling", e.cause()); - } - e.channel().close(); - } - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/SaturationManager.java b/transport-http/src/main/java/io/netty/channel/socket/http/SaturationManager.java deleted file mode 100644 index f3302ff10d..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/SaturationManager.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import static io.netty.channel.socket.http.SaturationStateChange.DESATURATED; -import static io.netty.channel.socket.http.SaturationStateChange.NO_CHANGE; -import static io.netty.channel.socket.http.SaturationStateChange.SATURATED; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; - -/** - * This class is used to monitor the amount of data that has yet to be pushed to - * the underlying socket, in order to implement the "high/low water mark" facility - * that controls Channel.isWritable() and the interest ops of http tunnels. - * - - - - */ -class SaturationManager { - private final AtomicLong desaturationPoint; - - private final AtomicLong saturationPoint; - - private final AtomicLong queueSize; - - private final AtomicBoolean saturated; - - public SaturationManager(long desaturationPoint, long saturationPoint) { - this.desaturationPoint = new AtomicLong(desaturationPoint); - this.saturationPoint = new AtomicLong(saturationPoint); - queueSize = new AtomicLong(0); - saturated = new AtomicBoolean(false); - } - - public SaturationStateChange queueSizeChanged(long sizeDelta) { - long newQueueSize = queueSize.addAndGet(sizeDelta); - if (newQueueSize <= desaturationPoint.get()) { - if (saturated.compareAndSet(true, false)) { - return DESATURATED; - } - } else if (newQueueSize > saturationPoint.get()) { - if (saturated.compareAndSet(false, true)) { - return SATURATED; - } - } - - return NO_CHANGE; - } - - public void updateThresholds(long desaturationPoint, long saturationPoint) { - this.desaturationPoint.set(desaturationPoint); - this.saturationPoint.set(saturationPoint); - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/SaturationStateChange.java b/transport-http/src/main/java/io/netty/channel/socket/http/SaturationStateChange.java deleted file mode 100644 index f7fdb0b609..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/SaturationStateChange.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -/** - * Represents the state change of a chanel in response in the amount of pending data to be - * sent - either no change occurs, the channel becomes desaturated (indicating that writing - * can safely commence) or it becomes saturated (indicating that writing should cease). - * - - - - */ -enum SaturationStateChange { - NO_CHANGE, DESATURATED, SATURATED -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitch.java b/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitch.java deleted file mode 100644 index ef7b2dbb46..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitch.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; -import java.util.List; -import java.util.Queue; -import java.util.Random; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureAggregator; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.Channels; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; - -/** - * This is the gateway between the accepted TCP channels that are used to communicate with the client - * ends of the http tunnel and the virtual server accepted tunnel. As a tunnel can last for longer than - * the lifetime of the client channels that are used to service it, this layer of abstraction is - * necessary. - */ -class ServerMessageSwitch implements ServerMessageSwitchUpstreamInterface, - ServerMessageSwitchDownstreamInterface { - - private static final InternalLogger LOG = InternalLoggerFactory - .getInstance(ServerMessageSwitch.class.getName()); - - private final String tunnelIdPrefix; - - private final HttpTunnelAcceptedChannelFactory newChannelFactory; - - private final ConcurrentHashMap tunnelsById; - - public ServerMessageSwitch( - HttpTunnelAcceptedChannelFactory newChannelFactory) { - this.newChannelFactory = newChannelFactory; - tunnelIdPrefix = Long.toHexString(new Random().nextLong()); - tunnelsById = new ConcurrentHashMap(); - } - - @Override - public String createTunnel(InetSocketAddress remoteAddress) { - String newTunnelId = - String.format("%s_%s", tunnelIdPrefix, - newChannelFactory.generateTunnelId()); - TunnelInfo newTunnel = new TunnelInfo(); - newTunnel.tunnelId = newTunnelId; - tunnelsById.put(newTunnelId, newTunnel); - newTunnel.localChannel = - newChannelFactory.newChannel(newTunnelId, remoteAddress); - return newTunnelId; - } - - @Override - public boolean isOpenTunnel(String tunnelId) { - TunnelInfo tunnel = tunnelsById.get(tunnelId); - return tunnel != null; - } - - @Override - public void pollOutboundData(String tunnelId, Channel channel) { - TunnelInfo tunnel = tunnelsById.get(tunnelId); - if (tunnel == null) { - if (LOG.isWarnEnabled()) { - LOG.warn("Poll request for tunnel " + tunnelId + - " which does not exist or already closed"); - } - respondAndClose(channel, HttpTunnelMessageUtils.createRejection( - null, "Unknown tunnel, possibly already closed")); - return; - } - - if (!tunnel.responseChannel.compareAndSet(null, channel)) { - if (LOG.isWarnEnabled()) { - LOG.warn("Duplicate poll request detected for tunnel " + - tunnelId); - } - respondAndClose(channel, HttpTunnelMessageUtils.createRejection( - null, "Only one poll request at a time per tunnel allowed")); - return; - } - - sendQueuedData(tunnel); - } - - private void respondAndClose(Channel channel, HttpResponse response) { - Channels.write(channel, response).addListener( - ChannelFutureListener.CLOSE); - } - - private void sendQueuedData(TunnelInfo state) { - Queue queuedData = state.queuedResponses; - Channel responseChannel = state.responseChannel.getAndSet(null); - if (responseChannel == null) { - // no response channel, or another thread has already used it - return; - } - - if (LOG.isDebugEnabled()) { - LOG.debug("sending response for tunnel id " + state.tunnelId + - " to " + responseChannel.getRemoteAddress()); - } - QueuedResponse messageToSend = queuedData.poll(); - if (messageToSend == null) { - // no data to send, restore the response channel and bail out - state.responseChannel.set(responseChannel); - return; - } - - HttpResponse response = - HttpTunnelMessageUtils - .createRecvDataResponse(messageToSend.data); - final ChannelFuture originalFuture = messageToSend.writeFuture; - Channels.write(responseChannel, response).addListener( - new RelayedChannelFutureListener(originalFuture)); - } - - @Override - public TunnelStatus routeInboundData(String tunnelId, - ChannelBuffer inboundData) { - TunnelInfo tunnel = tunnelsById.get(tunnelId); - if (tunnel == null) { - return TunnelStatus.CLOSED; - } - - if (tunnel.closing.get()) { - // client has now been notified, forget the tunnel - tunnelsById.remove(tunnel); - return TunnelStatus.CLOSED; - } - - if (LOG.isDebugEnabled()) { - LOG.debug("routing inbound data for tunnel " + tunnelId); - } - tunnel.localChannel.dataReceived(inboundData); - return TunnelStatus.ALIVE; - } - - @Override - public void clientCloseTunnel(String tunnelId) { - TunnelInfo tunnel = tunnelsById.get(tunnelId); - if (tunnel == null) { - if (LOG.isWarnEnabled()) { - LOG.warn("attempt made to close tunnel id " + - tunnelId + " which is unknown or closed"); - } - - return; - } - - tunnel.localChannel.clientClosed(); - tunnelsById.remove(tunnelId); - } - - @Override - public void serverCloseTunnel(String tunnelId) { - TunnelInfo tunnel = tunnelsById.get(tunnelId); - if (tunnel == null) { - if (LOG.isWarnEnabled()) { - LOG.warn("attempt made to close tunnel id " + - tunnelId + " which is unknown or closed"); - } - - return; - } - - tunnel.closing.set(true); - - Channel responseChannel = tunnel.responseChannel.getAndSet(null); - if (responseChannel == null) { - // response channel is already in use, client will be notified - // of close at next opportunity - return; - } - - respondAndClose(responseChannel, - HttpTunnelMessageUtils.createTunnelCloseResponse()); - // client has been notified, forget the tunnel - tunnelsById.remove(tunnelId); - } - - @Override - public void routeOutboundData(String tunnelId, ChannelBuffer data, - ChannelFuture writeFuture) { - TunnelInfo tunnel = tunnelsById.get(tunnelId); - if (tunnel == null) { - // tunnel is closed - if (LOG.isWarnEnabled()) { - LOG.warn("attempt made to send data out on tunnel id " + - tunnelId + " which is unknown or closed"); - } - return; - } - - ChannelFutureAggregator aggregator = - new ChannelFutureAggregator(writeFuture); - List fragments = - WriteSplitter.split(data, HttpTunnelMessageUtils.MAX_BODY_SIZE); - - if (LOG.isDebugEnabled()) { - LOG.debug("routing outbound data for tunnel " + tunnelId); - } - for (ChannelBuffer fragment: fragments) { - ChannelFuture fragmentFuture = - Channels.future(writeFuture.channel()); - aggregator.addFuture(fragmentFuture); - tunnel.queuedResponses.offer(new QueuedResponse(fragment, - fragmentFuture)); - } - - sendQueuedData(tunnel); - } - - /** - * Used to pass the result received from one ChannelFutureListener to another verbatim. - */ - private static final class RelayedChannelFutureListener implements - ChannelFutureListener { - private final ChannelFuture originalFuture; - - RelayedChannelFutureListener(ChannelFuture originalFuture) { - this.originalFuture = originalFuture; - } - - @Override - public void operationComplete(ChannelFuture future) throws Exception { - if (future.isSuccess()) { - originalFuture.setSuccess(); - } else { - originalFuture.setFailure(future.cause()); - } - } - } - - private static final class TunnelInfo { - TunnelInfo() { - } - - public String tunnelId; - - public HttpTunnelAcceptedChannelReceiver localChannel; - - public final AtomicReference responseChannel = - new AtomicReference(null); - - public final Queue queuedResponses = - new ConcurrentLinkedQueue(); - - public final AtomicBoolean closing = new AtomicBoolean(false); - } - - private static final class QueuedResponse { - public ChannelBuffer data; - - public ChannelFuture writeFuture; - - QueuedResponse(ChannelBuffer data, ChannelFuture writeFuture) { - this.data = data; - this.writeFuture = writeFuture; - } - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitchDownstreamInterface.java b/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitchDownstreamInterface.java deleted file mode 100644 index de42c6a528..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitchDownstreamInterface.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.ChannelFuture; - -/** - * The interface from a HttpTunnelAcceptedChannel to the ServerMessageSwitch. - * This primarily exists for mock object testing purposes. - */ -interface ServerMessageSwitchDownstreamInterface { - - void serverCloseTunnel(String tunnelId); - - void routeOutboundData(String tunnelId, ChannelBuffer data, - ChannelFuture writeFuture); - -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitchUpstreamInterface.java b/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitchUpstreamInterface.java deleted file mode 100644 index 7581fb1375..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/ServerMessageSwitchUpstreamInterface.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.Channel; - -/** - * The interface from a TCP channel which is being used to communicate with the client - * end of an http tunnel and the server message switch. - * - * This primarily exists for mock testing purposes. - */ -interface ServerMessageSwitchUpstreamInterface { - - String createTunnel(InetSocketAddress remoteAddress); - - boolean isOpenTunnel(String tunnelId); - - void clientCloseTunnel(String tunnelId); - - /** - * Passes some received data from a client for forwarding to the server's view - * of the tunnel. - * @return the current status of the tunnel. ALIVE indicates the tunnel is still - * functional, CLOSED indicates it is closed and the client should be notified - * of this (and will be forgotten after this notification). - */ - TunnelStatus routeInboundData(String tunnelId, - ChannelBuffer inboundData); - - void pollOutboundData(String tunnelId, Channel responseChannel); - - enum TunnelStatus { - ALIVE, CLOSED - } - -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/TunnelIdGenerator.java b/transport-http/src/main/java/io/netty/channel/socket/http/TunnelIdGenerator.java deleted file mode 100644 index 846f0c6223..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/TunnelIdGenerator.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -/** - * This interface is used by the server end of an http tunnel to generate new - * tunnel ids for accepted client connections. - */ -public interface TunnelIdGenerator { - - /** - * Generates the next tunnel ID to be used, which must be unique - * (i.e. ensure with high probability that it will not clash with - * an existing tunnel ID). This method must be thread safe, and - * preferably lock free. - */ - String generateId(); - -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/TunnelWrappedServerChannelHandler.java b/transport-http/src/main/java/io/netty/channel/socket/http/TunnelWrappedServerChannelHandler.java deleted file mode 100644 index 110f06e5ec..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/TunnelWrappedServerChannelHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.net.SocketAddress; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.Channels; -import io.netty.channel.ChildChannelStateEvent; -import io.netty.channel.SimpleChannelUpstreamHandler; -import io.netty.channel.group.ChannelGroup; - -/** - */ -class TunnelWrappedServerChannelHandler extends SimpleChannelUpstreamHandler { - - public static final String NAME = "TunnelWrappedServerChannelHandler"; - - private final HttpTunnelServerChannel tunnelChannel; - - private final AcceptedServerChannelPipelineFactory pipelineFactory; - - private final ChannelGroup allChannels; - - public TunnelWrappedServerChannelHandler( - HttpTunnelServerChannel tunnelChannel, - AcceptedServerChannelPipelineFactory pipelineFactory, - ChannelGroup allChannels) { - this.tunnelChannel = tunnelChannel; - this.pipelineFactory = pipelineFactory; - this.allChannels = allChannels; - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - e.channel().getConfig().setPipelineFactory(pipelineFactory); - super.channelOpen(ctx, e); - } - - @Override - public void channelBound(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - Channels.fireChannelBound(tunnelChannel, (SocketAddress) e.getValue()); - super.channelBound(ctx, e); - } - - @Override - public void channelUnbound(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - Channels.fireChannelUnbound(tunnelChannel); - super.channelUnbound(ctx, e); - } - - @Override - public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - Channels.fireChannelClosed(tunnelChannel); - super.channelClosed(ctx, e); - } - - @Override - public void childChannelOpen(ChannelHandlerContext ctx, - ChildChannelStateEvent e) throws Exception { - allChannels.add(e.getChildChannel()); - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/WriteFragmenter.java b/transport-http/src/main/java/io/netty/channel/socket/http/WriteFragmenter.java deleted file mode 100644 index 6239b9c114..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/WriteFragmenter.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.util.List; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureAggregator; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.Channels; -import io.netty.channel.MessageEvent; -import io.netty.channel.SimpleChannelDownstreamHandler; - -/** - * Downstream handler which places an upper bound on the size of written - * {@link ChannelBuffer ChannelBuffers}. If a buffer - * is bigger than the specified upper bound, the buffer is broken up - * into two or more smaller pieces. - *

- * This is utilised by the http tunnel to smooth out the per-byte latency, - * by placing an upper bound on HTTP request / response body sizes. - */ -public class WriteFragmenter extends SimpleChannelDownstreamHandler { - - public static final String NAME = "writeFragmenter"; - - private int splitThreshold; - - public WriteFragmenter(int splitThreshold) { - this.splitThreshold = splitThreshold; - } - - public void setSplitThreshold(int splitThreshold) { - this.splitThreshold = splitThreshold; - } - - @Override - public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - ChannelBuffer data = (ChannelBuffer) e.getMessage(); - - if (data.readableBytes() <= splitThreshold) { - super.writeRequested(ctx, e); - } else { - List fragments = - WriteSplitter.split(data, splitThreshold); - ChannelFutureAggregator aggregator = - new ChannelFutureAggregator(e.getFuture()); - for (ChannelBuffer fragment: fragments) { - ChannelFuture fragmentFuture = - Channels.future(ctx.channel(), true); - aggregator.addFuture(fragmentFuture); - Channels.write(ctx, fragmentFuture, fragment); - } - } - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/WriteSplitter.java b/transport-http/src/main/java/io/netty/channel/socket/http/WriteSplitter.java deleted file mode 100644 index 8d8ed5ab03..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/WriteSplitter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import java.util.ArrayList; -import java.util.List; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; - -/** - * Provides functionality to split a provided ChannelBuffer into multiple fragments which fit - * under a specified size threshold. - */ -final class WriteSplitter { - - public static List split(ChannelBuffer buffer, - int splitThreshold) { - int listSize = (int) ((float) buffer.readableBytes() / splitThreshold); - ArrayList fragmentList = - new ArrayList(listSize); - - if (buffer.readableBytes() > splitThreshold) { - int slicePosition = buffer.readerIndex(); - while (slicePosition < buffer.writerIndex()) { - int chunkSize = - Math.min(splitThreshold, buffer.writerIndex() - - slicePosition); - ChannelBuffer chunk = buffer.slice(slicePosition, chunkSize); - fragmentList.add(chunk); - slicePosition += chunkSize; - } - } else { - fragmentList.add(ChannelBuffers.wrappedBuffer(buffer)); - } - - return fragmentList; - } - - private WriteSplitter() { - // Unused - } -} diff --git a/transport-http/src/main/java/io/netty/channel/socket/http/package-info.java b/transport-http/src/main/java/io/netty/channel/socket/http/package-info.java deleted file mode 100644 index 2e48958a9d..0000000000 --- a/transport-http/src/main/java/io/netty/channel/socket/http/package-info.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * An HTTP-based client-side {@link io.netty.channel.socket.SocketChannel} - * and its corresponding server-side Servlet implementation that make your - * existing server application work in a firewalled network. - * - *

Deploying the HTTP tunnel as a Servlet

- * - * First, {@link io.netty.channel.socket.http.HttpTunnelingServlet} must be - * configured in a web.xml. - * - *
- * <?xml version="1.0" encoding="UTF-8"?>
- * <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
- *             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- *             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
- *             version="2.4">
- *
- *   <servlet>
- *     <servlet-name>NettyTunnelingServlet</servlet-name>
- *     <servlet-class>io.netty.channel.socket.http.HttpTunnelingServlet</servlet-class>
- *     <!--
- *       The name of the channel, this should be a registered local channel.
- *       See LocalTransportRegister.
- *     -->
- *     <init-param>
- *       <param-name>endpoint</param-name>
- *       <param-value>local:myLocalServer</param-value>
- *     </init-param>
- *     <load-on-startup>1</load-on-startup>
- *   </servlet>
- *
- *   <servlet-mapping>
- *     <servlet-name>NettyTunnelingServlet</servlet-name>
- *     <url-pattern>/netty-tunnel</url-pattern>
- *   </servlet-mapping>
- * </web-app>
- * 
- * - * Second, you have to bind your Netty-based server application in the same - * Servlet context or shared class loader space using the local transport - * (see {@link io.netty.channel.local.LocalServerChannelFactory}.) - * You can use your favorite IoC framework such as JBoss Microcontainer, Guice, - * and Spring to do this. The following example shows how to bind an echo - * server to the endpoint specifed above (web.xml) in JBossAS 5: - * - *
- * <bean name="my-local-echo-server"
- *       class="io.netty.example.http.tunnel.LocalEchoServerRegistration" />
- *
- * ...
- *
- * package io.netty.example.http.tunnel;
- * ...
- *
- * public class LocalEchoServerRegistration {
- *
- *     private final ChannelFactory factory = new DefaultLocalServerChannelFactory();
- *     private volatile Channel serverChannel;
- *
- *     public void start() {
- *         ServerBootstrap serverBootstrap = new ServerBootstrap(factory);
- *         EchoHandler handler = new EchoHandler();
- *         serverBootstrap.getPipeline().addLast("handler", handler);
- *
- *         // Note that "myLocalServer" is the endpoint which was specified in web.xml.
- *         serverChannel = serverBootstrap.bind(new LocalAddress("myLocalServer"));
- *     }
- *
- *     public void stop() {
- *         serverChannel.close();
- *     }
- * }
- * 
- * - *

Connecting to the HTTP tunnel

- * - * Once the tunnel has been configured, your client-side application needs only - * a couple lines of changes. - * - *
- * ClientBootstrap b = new ClientBootstrap(
- *         new HttpTunnelingClientSocketChannelFactory(
- *                 new NioClientSocketChannelFactory(...)));
- *
- * // Configure the pipeline (or pipeline factory) here.
- * ...
- *
- * // The host name of the HTTP server
- * b.setOption("serverName", "example.com");
- * // The path to the HTTP tunneling Servlet, which was specified in in web.xml
- * b.setOption("serverPath", "contextPath/netty-tunnel");
- * b.connect(new InetSocketAddress("example.com", 80);
- * 
- * - * For more configuration parameters such as HTTPS options, - * refer to {@link io.netty.channel.socket.http.HttpTunnelingSocketChannelConfig}. - */ -package io.netty.channel.socket.http; - diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/AcceptedServerChannelRequestDispatchTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/AcceptedServerChannelRequestDispatchTest.java deleted file mode 100644 index 25c85fde9c..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/AcceptedServerChannelRequestDispatchTest.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.net.InetSocketAddress; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelState; -import io.netty.channel.Channels; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import org.jmock.Expectations; -import org.jmock.integration.junit4.JMock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tests an accepted server channel request dispatch - */ -@RunWith(JMock.class) -public class AcceptedServerChannelRequestDispatchTest { - - private static final String HOST = "test.server.com"; - - private static final String KNOWN_TUNNEL_ID = "1"; - - protected static final String UNKNOWN_TUNNEL_ID = "unknownTunnel"; - - JUnit4Mockery mockContext = new JUnit4Mockery(); - - private AcceptedServerChannelRequestDispatch handler; - - FakeSocketChannel channel; - - private FakeChannelSink sink; - - ServerMessageSwitchUpstreamInterface messageSwitch; - - @Before - public void setUp() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - messageSwitch = - mockContext.mock(ServerMessageSwitchUpstreamInterface.class); - handler = new AcceptedServerChannelRequestDispatch(messageSwitch); - pipeline.addLast(AcceptedServerChannelRequestDispatch.NAME, handler); - sink = new FakeChannelSink(); - channel = new FakeSocketChannel(null, null, pipeline, sink); - channel.remoteAddress = - InetSocketAddress.createUnresolved("test.client.com", 51231); - - mockContext.checking(new Expectations() { - { - ignoring(messageSwitch).isOpenTunnel(KNOWN_TUNNEL_ID); - will(returnValue(true)); - } - }); - } - - @Test - public void testTunnelOpenRequest() { - mockContext.checking(new Expectations() { - { - one(messageSwitch).createTunnel(channel.remoteAddress); - will(returnValue(KNOWN_TUNNEL_ID)); - } - }); - - Channels.fireMessageReceived(channel, - HttpTunnelMessageUtils.createOpenTunnelRequest(HOST)); - assertEquals(1, sink.events.size()); - HttpResponse response = - NettyTestUtils.checkIsDownstreamMessageEvent( - sink.events.poll(), HttpResponse.class); - assertTrue(HttpTunnelMessageUtils.isTunnelOpenResponse(response)); - } - - @Test - public void testTunnelCloseRequest() { - mockContext.checking(new Expectations() { - { - one(messageSwitch).clientCloseTunnel(KNOWN_TUNNEL_ID); - } - }); - - HttpRequest request = - HttpTunnelMessageUtils.createCloseTunnelRequest(HOST, - KNOWN_TUNNEL_ID); - Channels.fireMessageReceived(channel, request); - assertEquals(1, sink.events.size()); - ChannelEvent responseEvent = sink.events.poll(); - HttpResponse response = - NettyTestUtils.checkIsDownstreamMessageEvent(responseEvent, - HttpResponse.class); - assertTrue(HttpTunnelMessageUtils.isTunnelCloseResponse(response)); - checkClosesAfterWrite(responseEvent); - } - - @Test - public void testTunnelCloseRequestWithoutTunnelIdRejected() { - HttpRequest request = - HttpTunnelMessageUtils.createCloseTunnelRequest(HOST, null); - checkRequestWithoutTunnelIdIsRejected(request); - } - - @Test - public void testTunnelCloseRequestWithUnknownTunnelId() { - HttpRequest request = - HttpTunnelMessageUtils.createCloseTunnelRequest(HOST, - UNKNOWN_TUNNEL_ID); - checkRequestWithUnknownTunnelIdIsRejected(request); - } - - @Test - public void testSendDataRequest() { - final ChannelBuffer expectedData = ChannelBuffers.dynamicBuffer(); - expectedData.writeLong(1234L); - mockContext.checking(new Expectations() { - { - one(messageSwitch).routeInboundData(KNOWN_TUNNEL_ID, - expectedData); - } - }); - - HttpRequest request = - HttpTunnelMessageUtils.createSendDataRequest(HOST, - KNOWN_TUNNEL_ID, expectedData); - Channels.fireMessageReceived(channel, request); - - assertEquals(1, sink.events.size()); - HttpResponse response = - NettyTestUtils.checkIsDownstreamMessageEvent( - sink.events.poll(), HttpResponse.class); - assertTrue(HttpTunnelMessageUtils.isOKResponse(response)); - } - - @Test - public void testSendDataRequestWithNoContentRejected() { - HttpRequest request = - HttpTunnelMessageUtils.createSendDataRequest(HOST, - KNOWN_TUNNEL_ID, ChannelBuffers.dynamicBuffer()); - Channels.fireMessageReceived(channel, request); - - assertEquals(1, sink.events.size()); - checkResponseIsRejection("Send data requests must contain data"); - } - - @Test - public void testSendDataRequestForUnknownTunnelIdRejected() { - HttpRequest request = - HttpTunnelMessageUtils.createSendDataRequest(HOST, - UNKNOWN_TUNNEL_ID, ChannelBuffers.dynamicBuffer()); - checkRequestWithUnknownTunnelIdIsRejected(request); - } - - @Test - public void testSendDataRequestWithoutTunnelIdRejected() { - HttpRequest request = - HttpTunnelMessageUtils.createSendDataRequest(HOST, null, - ChannelBuffers.dynamicBuffer()); - checkRequestWithoutTunnelIdIsRejected(request); - } - - @Test - public void testReceiveDataRequest() { - mockContext.checking(new Expectations() { - { - one(messageSwitch).pollOutboundData(KNOWN_TUNNEL_ID, channel); - } - }); - HttpRequest request = - HttpTunnelMessageUtils.createReceiveDataRequest(HOST, - KNOWN_TUNNEL_ID); - Channels.fireMessageReceived(channel, request); - } - - @Test - public void testReceiveDataRequestWithoutTunnelIdRejected() { - HttpRequest request = - HttpTunnelMessageUtils.createReceiveDataRequest(HOST, null); - checkRequestWithoutTunnelIdIsRejected(request); - } - - @Test - public void testReceiveDataRequestForUnknownTunnelIdRejected() { - HttpRequest request = - HttpTunnelMessageUtils.createReceiveDataRequest(HOST, - UNKNOWN_TUNNEL_ID); - checkRequestWithUnknownTunnelIdIsRejected(request); - } - - private void checkRequestWithoutTunnelIdIsRejected(HttpRequest request) { - Channels.fireMessageReceived(channel, request); - assertEquals(1, sink.events.size()); - ChannelEvent responseEvent = - checkResponseIsRejection("no tunnel id specified in request"); - checkClosesAfterWrite(responseEvent); - } - - private void checkRequestWithUnknownTunnelIdIsRejected(HttpRequest request) { - mockContext.checking(new Expectations() { - { - one(messageSwitch).isOpenTunnel(UNKNOWN_TUNNEL_ID); - will(returnValue(false)); - } - }); - - Channels.fireMessageReceived(channel, request); - assertEquals(1, sink.events.size()); - ChannelEvent responseEvent = - checkResponseIsRejection("specified tunnel is either closed or does not exist"); - checkClosesAfterWrite(responseEvent); - } - - private ChannelEvent checkResponseIsRejection(String errorMessage) { - ChannelEvent responseEvent = sink.events.poll(); - - HttpResponse response = - NettyTestUtils.checkIsDownstreamMessageEvent(responseEvent, - HttpResponse.class); - assertTrue(HttpTunnelMessageUtils.isRejection(response)); - assertEquals(errorMessage, - HttpTunnelMessageUtils.extractErrorMessage(response)); - - return responseEvent; - } - - private void checkClosesAfterWrite(ChannelEvent responseEvent) { - responseEvent.getFuture().setSuccess(); - assertEquals(1, sink.events.size()); - NettyTestUtils.checkIsStateEvent(sink.events.poll(), ChannelState.OPEN, - false); - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/FakeChannelConfig.java b/transport-http/src/test/java/io/netty/channel/socket/http/FakeChannelConfig.java deleted file mode 100644 index 4de34b94ce..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/FakeChannelConfig.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import java.util.Map; -import java.util.Map.Entry; - -import io.netty.buffer.ChannelBufferFactory; -import io.netty.buffer.HeapChannelBufferFactory; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPipelineFactory; -import io.netty.channel.Channels; -import io.netty.channel.socket.SocketChannelConfig; -import io.netty.util.internal.ConversionUtil; - -/** - * A face channel config class for use in testing - */ -public class FakeChannelConfig implements SocketChannelConfig { - - private int receiveBufferSize = 1024; - - private int sendBufferSize = 1024; - - private int soLinger = 500; - - private int trafficClass = 0; - - private boolean keepAlive = true; - - private boolean reuseAddress = true; - - private boolean tcpNoDelay = false; - - private ChannelBufferFactory bufferFactory = new HeapChannelBufferFactory(); - - private int connectTimeout = 5000; - - private ChannelPipelineFactory pipelineFactory = - new ChannelPipelineFactory() { - @Override - public ChannelPipeline getPipeline() throws Exception { - return Channels.pipeline(); - } - }; - - private int writeTimeout = 3000; - - @Override - public int getReceiveBufferSize() { - return receiveBufferSize; - } - - @Override - public void setReceiveBufferSize(int receiveBufferSize) { - this.receiveBufferSize = receiveBufferSize; - } - - @Override - public int getSendBufferSize() { - return sendBufferSize; - } - - @Override - public void setSendBufferSize(int sendBufferSize) { - this.sendBufferSize = sendBufferSize; - } - - @Override - public int getSoLinger() { - return soLinger; - } - - @Override - public void setSoLinger(int soLinger) { - this.soLinger = soLinger; - } - - @Override - public int getTrafficClass() { - return trafficClass; - } - - @Override - public void setTrafficClass(int trafficClass) { - this.trafficClass = trafficClass; - } - - @Override - public boolean isKeepAlive() { - return keepAlive; - } - - @Override - public void setKeepAlive(boolean keepAlive) { - this.keepAlive = keepAlive; - } - - @Override - public boolean isReuseAddress() { - return reuseAddress; - } - - @Override - public void setReuseAddress(boolean reuseAddress) { - this.reuseAddress = reuseAddress; - } - - @Override - public boolean isTcpNoDelay() { - return tcpNoDelay; - } - - @Override - public void setTcpNoDelay(boolean tcpNoDelay) { - this.tcpNoDelay = tcpNoDelay; - } - - @Override - public void setPerformancePreferences(int connectionTime, int latency, - int bandwidth) { - // do nothing - } - - @Override - public ChannelBufferFactory getBufferFactory() { - return bufferFactory; - } - - @Override - public void setBufferFactory(ChannelBufferFactory bufferFactory) { - this.bufferFactory = bufferFactory; - } - - @Override - public int getConnectTimeoutMillis() { - return connectTimeout; - } - - @Override - public void setConnectTimeoutMillis(int connectTimeoutMillis) { - connectTimeout = connectTimeoutMillis; - } - - @Override - public ChannelPipelineFactory getPipelineFactory() { - return pipelineFactory; - } - - @Override - public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) { - this.pipelineFactory = pipelineFactory; - } - - public int getWriteTimeoutMillis() { - return writeTimeout; - } - - public void setWriteTimeoutMillis(int writeTimeoutMillis) { - writeTimeout = writeTimeoutMillis; - } - - @Override - public boolean setOption(String key, Object value) { - if (key.equals("pipelineFactory")) { - setPipelineFactory((ChannelPipelineFactory) value); - } else if (key.equals("connectTimeoutMillis")) { - setConnectTimeoutMillis(ConversionUtil.toInt(value)); - } else if (key.equals("bufferFactory")) { - setBufferFactory((ChannelBufferFactory) value); - } else if (key.equals("receiveBufferSize")) { - setReceiveBufferSize(ConversionUtil.toInt(value)); - } else if (key.equals("sendBufferSize")) { - setSendBufferSize(ConversionUtil.toInt(value)); - } else if (key.equals("tcpNoDelay")) { - setTcpNoDelay(ConversionUtil.toBoolean(value)); - } else if (key.equals("keepAlive")) { - setKeepAlive(ConversionUtil.toBoolean(value)); - } else if (key.equals("reuseAddress")) { - setReuseAddress(ConversionUtil.toBoolean(value)); - } else if (key.equals("soLinger")) { - setSoLinger(ConversionUtil.toInt(value)); - } else if (key.equals("trafficClass")) { - setTrafficClass(ConversionUtil.toInt(value)); - } else { - return false; - } - return true; - } - - @Override - public void setOptions(Map options) { - for (Entry e: options.entrySet()) { - setOption(e.getKey(), e.getValue()); - } - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/FakeChannelSink.java b/transport-http/src/test/java/io/netty/channel/socket/http/FakeChannelSink.java deleted file mode 100644 index 0798eb94ad..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/FakeChannelSink.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import java.util.LinkedList; -import java.util.Queue; - -import io.netty.channel.AbstractChannelSink; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelPipeline; - -/** - * A fake channel sink for use in testing - */ -public class FakeChannelSink extends AbstractChannelSink { - - public Queue events = new LinkedList(); - - @Override - public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) - throws Exception { - events.add(e); - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/FakeClientSocketChannelFactory.java b/transport-http/src/test/java/io/netty/channel/socket/http/FakeClientSocketChannelFactory.java deleted file mode 100644 index a27bedc813..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/FakeClientSocketChannelFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import java.util.ArrayList; -import java.util.List; - -import io.netty.channel.ChannelPipeline; -import io.netty.channel.socket.ClientSocketChannelFactory; -import io.netty.channel.socket.SocketChannel; - -/** - * A fake client socket channel factory for use in testing - */ -public class FakeClientSocketChannelFactory implements - ClientSocketChannelFactory { - - public List createdChannels; - - public FakeClientSocketChannelFactory() { - createdChannels = new ArrayList(); - } - - @Override - public SocketChannel newChannel(ChannelPipeline pipeline) { - FakeSocketChannel channel = - new FakeSocketChannel(null, this, pipeline, - new FakeChannelSink()); - createdChannels.add(channel); - return channel; - } - - @Override - public void releaseExternalResources() { - // nothing to do - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannel.java b/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannel.java deleted file mode 100644 index d7a519d0ff..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannel.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static io.netty.channel.Channels.fireChannelBound; -import static io.netty.channel.Channels.fireChannelConnected; -import static io.netty.channel.Channels.fireChannelOpen; - -import java.net.InetSocketAddress; - -import io.netty.channel.AbstractChannel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.channel.socket.ServerSocketChannel; -import io.netty.channel.socket.ServerSocketChannelConfig; - -/** - * A fake server socket channel for use in testing - */ -public class FakeServerSocketChannel extends AbstractChannel implements - ServerSocketChannel { - - public boolean bound; - - public boolean connected; - - public InetSocketAddress remoteAddress; - - public InetSocketAddress localAddress; - - public ServerSocketChannelConfig config = - new FakeServerSocketChannelConfig(); - - public FakeServerSocketChannel(ChannelFactory factory, - ChannelPipeline pipeline, ChannelSink sink) { - super(null, factory, pipeline, sink); - } - - @Override - public ServerSocketChannelConfig getConfig() { - return config; - } - - @Override - public InetSocketAddress getLocalAddress() { - return localAddress; - } - - @Override - public InetSocketAddress getRemoteAddress() { - return remoteAddress; - } - - @Override - public boolean isBound() { - return bound; - } - - @Override - public boolean isConnected() { - return connected; - } - - public FakeSocketChannel acceptNewConnection( - InetSocketAddress remoteAddress, ChannelSink sink) throws Exception { - ChannelPipeline newPipeline = - getConfig().getPipelineFactory().pipeline(); - FakeSocketChannel newChannel = - new FakeSocketChannel(this, getFactory(), newPipeline, sink); - newChannel.localAddress = localAddress; - newChannel.remoteAddress = remoteAddress; - fireChannelOpen(newChannel); - fireChannelBound(newChannel, newChannel.localAddress); - fireChannelConnected(this, newChannel.remoteAddress); - - return newChannel; - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannelConfig.java b/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannelConfig.java deleted file mode 100644 index 680e47bb1c..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannelConfig.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import io.netty.buffer.ChannelBufferFactory; -import io.netty.buffer.HeapChannelBufferFactory; -import io.netty.channel.ChannelPipelineFactory; -import io.netty.channel.DefaultChannelConfig; -import io.netty.channel.socket.ServerSocketChannelConfig; - -/** - * A fake server socket channel config class for use in testing - */ -public class FakeServerSocketChannelConfig extends DefaultChannelConfig - implements ServerSocketChannelConfig { - - public int backlog = 5; - - public int receiveBufferSize = 1024; - - public boolean reuseAddress = false; - - public int connectionTimeout = 5000; - - public ChannelPipelineFactory pipelineFactory; - - public int writeTimeout = 5000; - - public ChannelBufferFactory bufferFactory = new HeapChannelBufferFactory(); - - @Override - public int getBacklog() { - return backlog; - } - - @Override - public void setBacklog(int backlog) { - this.backlog = backlog; - } - - @Override - public int getReceiveBufferSize() { - return receiveBufferSize; - } - - @Override - public void setReceiveBufferSize(int receiveBufferSize) { - this.receiveBufferSize = receiveBufferSize; - } - - @Override - public boolean isReuseAddress() { - return reuseAddress; - } - - @Override - public void setReuseAddress(boolean reuseAddress) { - this.reuseAddress = reuseAddress; - } - - @Override - public void setPerformancePreferences(int connectionTime, int latency, - int bandwidth) { - // ignore - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannelFactory.java b/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannelFactory.java deleted file mode 100644 index a0f5330133..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/FakeServerSocketChannelFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.channel.socket.ServerSocketChannel; -import io.netty.channel.socket.ServerSocketChannelFactory; - -/** - * A fake server socket channel factory for use in testing - */ -public class FakeServerSocketChannelFactory implements - ServerSocketChannelFactory { - - public ChannelSink sink = new FakeChannelSink(); - - public FakeServerSocketChannel createdChannel; - - @Override - public ServerSocketChannel newChannel(ChannelPipeline pipeline) { - createdChannel = new FakeServerSocketChannel(this, pipeline, sink); - return createdChannel; - } - - @Override - public void releaseExternalResources() { - // nothing to do - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/FakeSocketChannel.java b/transport-http/src/test/java/io/netty/channel/socket/http/FakeSocketChannel.java deleted file mode 100644 index 3e385bfcca..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/FakeSocketChannel.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; - -import io.netty.channel.AbstractChannel; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.channel.Channels; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.SocketChannelConfig; - -/** - * A fake socket channel for use in testing - */ -public class FakeSocketChannel extends AbstractChannel implements SocketChannel { - - public InetSocketAddress localAddress; - - public InetSocketAddress remoteAddress; - - public SocketChannelConfig config = new FakeChannelConfig(); - - public boolean bound = false; - - public boolean connected = false; - - public ChannelSink sink; - - public FakeSocketChannel(Channel parent, ChannelFactory factory, - ChannelPipeline pipeline, ChannelSink sink) { - super(parent, factory, pipeline, sink); - this.sink = sink; - } - - @Override - public InetSocketAddress getLocalAddress() { - return localAddress; - } - - @Override - public SocketChannelConfig getConfig() { - return config; - } - - @Override - public InetSocketAddress getRemoteAddress() { - return remoteAddress; - } - - @Override - public boolean isBound() { - return bound; - } - - @Override - public boolean isConnected() { - return connected; - } - - public void emulateConnected(InetSocketAddress localAddress, - InetSocketAddress remoteAddress, ChannelFuture connectedFuture) { - if (connected) { - return; - } - - emulateBound(localAddress, null); - this.remoteAddress = remoteAddress; - connected = true; - Channels.fireChannelConnected(this, remoteAddress); - if (connectedFuture != null) { - connectedFuture.setSuccess(); - } - } - - public void emulateBound(InetSocketAddress localAddress, - ChannelFuture boundFuture) { - if (bound) { - return; - } - - bound = true; - this.localAddress = localAddress; - Channels.fireChannelBound(this, localAddress); - if (boundFuture != null) { - boundFuture.setSuccess(); - } - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelSinkTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelSinkTest.java deleted file mode 100644 index 4a853f69ef..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelAcceptedChannelSinkTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; - -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import org.jmock.Expectations; -import org.jmock.integration.junit4.JMock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tests HTTP tunnel accepted channel sinks - */ -@RunWith(JMock.class) -public class HttpTunnelAcceptedChannelSinkTest { - - private static final String TUNNEL_ID = "1"; - - private final JUnit4Mockery mockContext = new JUnit4Mockery(); - - ServerMessageSwitchDownstreamInterface messageSwitch; - - private HttpTunnelAcceptedChannelSink sink; - - private FakeSocketChannel channel; - - private UpstreamEventCatcher upstreamCatcher; - - @Before - public void setUp() throws Exception { - messageSwitch = - mockContext.mock(ServerMessageSwitchDownstreamInterface.class); - sink = - new HttpTunnelAcceptedChannelSink(messageSwitch, TUNNEL_ID, - new HttpTunnelAcceptedChannelConfig()); - ChannelPipeline pipeline = Channels.pipeline(); - upstreamCatcher = new UpstreamEventCatcher(); - pipeline.addLast(UpstreamEventCatcher.NAME, upstreamCatcher); - channel = new FakeSocketChannel(null, null, pipeline, sink); - upstreamCatcher.events.clear(); - } - - @Test - public void testSendInvalidDataType() { - Channels.write(channel, new Object()); - assertEquals(1, upstreamCatcher.events.size()); - NettyTestUtils.checkIsExceptionEvent(upstreamCatcher.events.poll()); - } - - @Test - public void testUnbind() { - mockContext.checking(new Expectations() { - { - one(messageSwitch).serverCloseTunnel(TUNNEL_ID); - } - }); - Channels.unbind(channel); - } - - @Test - public void testDisconnect() { - mockContext.checking(new Expectations() { - { - one(messageSwitch).serverCloseTunnel(TUNNEL_ID); - } - }); - - Channels.disconnect(channel); - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientChannelConfigTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientChannelConfigTest.java deleted file mode 100644 index 9bf4ddb78e..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientChannelConfigTest.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import io.netty.channel.socket.SocketChannelConfig; -import org.jmock.Expectations; -import org.jmock.integration.junit4.JMock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tests HTTP tunnel client channel config - */ -@RunWith(JMock.class) -public class HttpTunnelClientChannelConfigTest { - - JUnit4Mockery mockContext = new JUnit4Mockery(); - - SocketChannelConfig sendChannelConfig; - - SocketChannelConfig pollChannelConfig; - - HttpTunnelClientChannelConfig config; - - @Before - public void setUp() { - sendChannelConfig = - mockContext - .mock(SocketChannelConfig.class, "sendChannelConfig"); - pollChannelConfig = - mockContext - .mock(SocketChannelConfig.class, "pollChannelConfig"); - - config = - new HttpTunnelClientChannelConfig(sendChannelConfig, - pollChannelConfig); - } - - @Test - public void testGetReceiveBufferSize() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).getReceiveBufferSize(); - will(returnValue(100)); - } - }); - - assertEquals(100, config.getReceiveBufferSize()); - } - - @Test - public void testGetSendBufferSize() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).getSendBufferSize(); - will(returnValue(100)); - } - }); - - assertEquals(100, config.getSendBufferSize()); - } - - @Test - public void testGetSoLinger() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).getSoLinger(); - will(returnValue(100)); - } - }); - - assertEquals(100, config.getSoLinger()); - } - - @Test - public void testTrafficClass() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).getTrafficClass(); - will(returnValue(1)); - } - }); - - assertEquals(1, config.getTrafficClass()); - } - - @Test - public void testIsKeepAlive() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).isKeepAlive(); - will(returnValue(true)); - } - }); - - assertTrue(config.isKeepAlive()); - } - - @Test - public void testIsReuseAddress() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).isReuseAddress(); - will(returnValue(true)); - } - }); - - assertTrue(config.isReuseAddress()); - } - - @Test - public void testIsTcpNoDelay() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).isTcpNoDelay(); - will(returnValue(true)); - } - }); - - assertTrue(config.isTcpNoDelay()); - } - - @Test - public void testSetKeepAlive() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).setKeepAlive(true); - one(sendChannelConfig).setKeepAlive(true); - } - }); - - config.setKeepAlive(true); - } - - @Test - public void testSetPerformancePreferences() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).setPerformancePreferences(100, 200, 300); - one(sendChannelConfig).setPerformancePreferences(100, 200, 300); - } - }); - - config.setPerformancePreferences(100, 200, 300); - } - - @Test - public void testSetReceiveBufferSize() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).setReceiveBufferSize(100); - one(sendChannelConfig).setReceiveBufferSize(100); - } - }); - - config.setReceiveBufferSize(100); - } - - @Test - public void testSetReuseAddress() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).setReuseAddress(true); - one(sendChannelConfig).setReuseAddress(true); - } - }); - - config.setReuseAddress(true); - } - - @Test - public void testSetSendBufferSize() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).setSendBufferSize(100); - one(sendChannelConfig).setSendBufferSize(100); - } - }); - - config.setSendBufferSize(100); - } - - @Test - public void testSetSoLinger() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).setSoLinger(100); - one(sendChannelConfig).setSoLinger(100); - } - }); - - config.setSoLinger(100); - } - - @Test - public void testTcpNoDelay() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).setTcpNoDelay(true); - one(sendChannelConfig).setTcpNoDelay(true); - } - }); - - config.setTcpNoDelay(true); - } - - @Test - public void testSetTrafficClass() { - mockContext.checking(new Expectations() { - { - one(pollChannelConfig).setTrafficClass(1); - one(sendChannelConfig).setTrafficClass(1); - } - }); - - config.setTrafficClass(1); - } - - @Test - public void testSetHighWaterMark() { - config.setWriteBufferHighWaterMark(128 * 1024); - assertEquals(128 * 1024, config.getWriteBufferHighWaterMark()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetHighWaterMark_negative() { - config.setWriteBufferHighWaterMark(-1); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetHighWaterMark_zero() { - config.setWriteBufferHighWaterMark(0); - } - - @Test - public void testSetLowWaterMark() { - config.setWriteBufferLowWaterMark(100); - assertEquals(100, config.getWriteBufferLowWaterMark()); - } - - @Test - public void testSetLowWaterMark_zero() { - // zero is permitted for the low water mark, unlike high water mark - config.setWriteBufferLowWaterMark(0); - assertEquals(0, config.getWriteBufferLowWaterMark()); - } - - @Test - public void testSetHighWaterMark_lowerThanLow() { - config.setWriteBufferLowWaterMark(100); - try { - config.setWriteBufferHighWaterMark(80); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - assertEquals( - "Write buffer high water mark must be strictly greater than the low water mark", - e.getMessage()); - } - } - - @Test - public void testSetLowWaterMark_higherThanHigh() { - config.setWriteBufferHighWaterMark(128 * 1024); - try { - config.setWriteBufferLowWaterMark(256 * 1024); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - assertEquals( - "Write buffer low water mark must be strictly less than the high water mark", - e.getMessage()); - } - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientChannelTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientChannelTest.java deleted file mode 100644 index 55303fe995..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientChannelTest.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelState; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.Channels; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests HTTP tunnel client channels - */ -public class HttpTunnelClientChannelTest { - - public static final int LOCAL_PORT = 50123; - - /** used to emulate the selection of a random port in response to a bind request - * on an ephemeral port. - */ - public static final int OTHER_LOCAL_PORT = 40652; - - public static final InetSocketAddress LOCAL_ADDRESS = InetSocketAddress - .createUnresolved("localhost", LOCAL_PORT); - - public static final InetSocketAddress LOCAL_ADDRESS_EPHEMERAL_PORT = - InetSocketAddress.createUnresolved("localhost", 0); - - public static final InetSocketAddress REMOTE_ADDRESS = InetSocketAddress - .createUnresolved("test.server.com", 12345); - - public static final InetSocketAddress RESOLVED_LOCAL_ADDRESS_IPV4; - - public static final InetSocketAddress RESOLVED_LOCAL_ADDRESS_IPV6; - - public static final InetSocketAddress RESOLVED_LOCAL_ADDRESS_IPV4_EPHEMERAL_PORT; - - public static final InetSocketAddress RESOLVED_LOCAL_ADDRESS_IPV6_EPHEMERAL_PORT; - - public static final InetSocketAddress RESOLVED_LOCAL_ADDRESS_IPV4_SELECTED_PORT; - - public static final InetSocketAddress RESOLVED_LOCAL_ADDRESS_IPV6_SELECTED_PORT; - - static { - try { - InetAddress localhostIPV4 = - InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }); - InetAddress localhostIPV6 = - InetAddress.getByAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1 }); - RESOLVED_LOCAL_ADDRESS_IPV4 = - new InetSocketAddress(localhostIPV4, LOCAL_PORT); - RESOLVED_LOCAL_ADDRESS_IPV6 = - new InetSocketAddress(localhostIPV6, LOCAL_PORT); - RESOLVED_LOCAL_ADDRESS_IPV4_EPHEMERAL_PORT = - new InetSocketAddress(localhostIPV4, 0); - RESOLVED_LOCAL_ADDRESS_IPV6_EPHEMERAL_PORT = - new InetSocketAddress(localhostIPV6, 0); - RESOLVED_LOCAL_ADDRESS_IPV4_SELECTED_PORT = - new InetSocketAddress(localhostIPV4, OTHER_LOCAL_PORT); - RESOLVED_LOCAL_ADDRESS_IPV6_SELECTED_PORT = - new InetSocketAddress(localhostIPV6, OTHER_LOCAL_PORT); - } catch (UnknownHostException e) { - throw new RuntimeException( - "Creation of InetAddresses should not fail when explicitly specified and the correct length", - e); - } - } - - private UpstreamEventCatcher upstreamCatcher; - - private HttpTunnelClientChannel channel; - - private FakeClientSocketChannelFactory outboundFactory; - - private FakeSocketChannel sendChannel; - - private FakeSocketChannel pollChannel; - - private FakeChannelSink sendSink; - - private FakeChannelSink pollSink; - - @Before - public void setUp() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - upstreamCatcher = new UpstreamEventCatcher(); - pipeline.addLast(UpstreamEventCatcher.NAME, upstreamCatcher); - - outboundFactory = new FakeClientSocketChannelFactory(); - - HttpTunnelClientChannelFactory factory = - new HttpTunnelClientChannelFactory(outboundFactory); - channel = factory.newChannel(pipeline); - - assertEquals(2, outboundFactory.createdChannels.size()); - - sendChannel = outboundFactory.createdChannels.get(0); - pollChannel = outboundFactory.createdChannels.get(1); - sendSink = (FakeChannelSink) sendChannel.sink; - pollSink = (FakeChannelSink) pollChannel.sink; - } - - @Test - public void testConnect() { - Channels.connect(channel, REMOTE_ADDRESS); - - // this should result in a CONNECTED state event on the send channel, but not on the poll - // channel just yet - assertEquals(1, sendSink.events.size()); - assertEquals(0, pollSink.events.size()); - ChannelEvent sendChannelEvent = sendSink.events.poll(); - NettyTestUtils.checkIsStateEvent(sendChannelEvent, - ChannelState.CONNECTED, REMOTE_ADDRESS); - - // once the send channel indicates that it is connected, we should see the tunnel open request - // being sent - sendChannel.emulateConnected(LOCAL_ADDRESS, REMOTE_ADDRESS, - ((ChannelStateEvent) sendChannelEvent).getFuture()); - assertEquals(1, sendSink.events.size()); - ChannelEvent openTunnelRequest = sendSink.events.poll(); - NettyTestUtils.checkIsDownstreamMessageEvent(openTunnelRequest, - ChannelBuffer.class); - } - - @Test - public void testBind_unresolvedAddress() { - // requesting a binding with an unresolved local address - // should attempt to bind the send channel with that address unaltered - // and attempt to bind the poll address with the same host name but - // an ephemeral port. We emulate a resolved IPV4 address for the bind - // response. - checkBinding(LOCAL_ADDRESS, LOCAL_ADDRESS, - LOCAL_ADDRESS_EPHEMERAL_PORT, RESOLVED_LOCAL_ADDRESS_IPV4, - RESOLVED_LOCAL_ADDRESS_IPV4_SELECTED_PORT); - } - - @Test - public void testBind_resolvedAddress_ipv4() { - // variant that uses resolved addresses. The bind request - // for the poll channel should also use a resolved address, - // built from the provided resolved address. - checkBinding(RESOLVED_LOCAL_ADDRESS_IPV4, RESOLVED_LOCAL_ADDRESS_IPV4, - RESOLVED_LOCAL_ADDRESS_IPV4_EPHEMERAL_PORT, - RESOLVED_LOCAL_ADDRESS_IPV4, - RESOLVED_LOCAL_ADDRESS_IPV4_SELECTED_PORT); - } - - @Test - public void testBind_resolvedAddress_ipv6() { - // variant that uses a resolved IPV6 address. - // bind request on the poll channel should use the same - // IPv6 host, with an ephemeral port. - checkBinding(RESOLVED_LOCAL_ADDRESS_IPV6, RESOLVED_LOCAL_ADDRESS_IPV6, - RESOLVED_LOCAL_ADDRESS_IPV6_EPHEMERAL_PORT, - RESOLVED_LOCAL_ADDRESS_IPV6, - RESOLVED_LOCAL_ADDRESS_IPV6_SELECTED_PORT); - } - - private void checkBinding(InetSocketAddress requestedBindAddress, - InetSocketAddress expectedPollBindRequest, - InetSocketAddress expectedSendBindRequest, - InetSocketAddress emulatedPollBindAddress, - InetSocketAddress emulatedSendBindAddress) { - - ChannelFuture bindFuture = Channels.bind(channel, requestedBindAddress); - assertFalse(bindFuture.isDone()); - - assertEquals(1, sendSink.events.size()); - assertEquals(1, pollSink.events.size()); - - ChannelEvent sendChannelEvent = sendSink.events.poll(); - NettyTestUtils.checkIsStateEvent(sendChannelEvent, ChannelState.BOUND, - expectedPollBindRequest); - ChannelEvent pollChannelEvent = pollSink.events.poll(); - NettyTestUtils.checkIsStateEvent(pollChannelEvent, ChannelState.BOUND, - expectedSendBindRequest); - - sendChannel.emulateBound(emulatedPollBindAddress, - sendChannelEvent.getFuture()); - assertFalse(bindFuture.isDone()); - pollChannel.emulateBound(emulatedSendBindAddress, - pollChannelEvent.getFuture()); - assertTrue(bindFuture.isDone()); - assertTrue(bindFuture.isSuccess()); - - assertEquals(channel.getLocalAddress(), emulatedPollBindAddress); - } - - @Test - public void testBind_preResolvedAddress_ipv6() { - ChannelFuture bindFuture = - Channels.bind(channel, RESOLVED_LOCAL_ADDRESS_IPV6); - assertFalse(bindFuture.isDone()); - - assertEquals(1, sendSink.events.size()); - assertEquals(1, pollSink.events.size()); - - ChannelEvent sendChannelEvent = sendSink.events.poll(); - NettyTestUtils.checkIsStateEvent(sendChannelEvent, ChannelState.BOUND, - RESOLVED_LOCAL_ADDRESS_IPV6); - ChannelEvent pollChannelEvent = pollSink.events.poll(); - NettyTestUtils.checkIsStateEvent(pollChannelEvent, ChannelState.BOUND, - RESOLVED_LOCAL_ADDRESS_IPV6_EPHEMERAL_PORT); - - sendChannel.emulateBound(RESOLVED_LOCAL_ADDRESS_IPV6, - sendChannelEvent.getFuture()); - assertFalse(bindFuture.isDone()); - pollChannel.emulateBound(RESOLVED_LOCAL_ADDRESS_IPV4_SELECTED_PORT, - pollChannelEvent.getFuture()); - assertTrue(bindFuture.isDone()); - assertTrue(bindFuture.isSuccess()); - - assertEquals(channel.getLocalAddress(), RESOLVED_LOCAL_ADDRESS_IPV6); - } - - @Test - public void testBind_sendBindFails() { - ChannelFuture bindFuture = Channels.bind(channel, LOCAL_ADDRESS); - assertFalse(bindFuture.isDone()); - - Exception bindFailureReason = new Exception("could not bind"); - ((ChannelStateEvent) sendSink.events.poll()).getFuture().setFailure( - bindFailureReason); - assertTrue(bindFuture.isDone()); - assertFalse(bindFuture.isSuccess()); - assertSame(bindFailureReason, bindFuture.cause()); - } - - @Test - public void testBind_pollBindFails() { - ChannelFuture bindFuture = Channels.bind(channel, LOCAL_ADDRESS); - assertFalse(bindFuture.isDone()); - - Exception bindFailureReason = new Exception("could not bind"); - ((ChannelStateEvent) pollSink.events.poll()).getFuture().setFailure( - bindFailureReason); - assertTrue(bindFuture.isDone()); - assertFalse(bindFuture.isSuccess()); - assertSame(bindFailureReason, bindFuture.cause()); - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientPollHandlerTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientPollHandlerTest.java deleted file mode 100644 index 7a5cbecbbb..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientPollHandlerTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; - -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.DownstreamMessageEvent; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests HTTP tunnel client polling - */ -public class HttpTunnelClientPollHandlerTest { - - private static final String TUNNEL_ID = "1"; - - private static final InetSocketAddress SERVER_ADDRESS = createAddress( - new byte[] { 10, 0, 0, 3 }, 12345); - - private static final InetSocketAddress PROXY_ADDRESS = createAddress( - new byte[] { 10, 0, 0, 2 }, 8888); - - private static final InetSocketAddress LOCAL_ADDRESS = createAddress( - new byte[] { 10, 0, 0, 1 }, 54321); - - private FakeSocketChannel channel; - - private FakeChannelSink sink; - - private HttpTunnelClientPollHandler handler; - - private MockChannelStateListener listener; - - private static InetSocketAddress createAddress(byte[] addr, int port) { - try { - return new InetSocketAddress(InetAddress.getByAddress(addr), port); - } catch (UnknownHostException e) { - throw new RuntimeException("Bad address in test"); - } - } - - @Before - public void setUp() throws Exception { - sink = new FakeChannelSink(); - - ChannelPipeline pipeline = Channels.pipeline(); - listener = new MockChannelStateListener(); - listener.serverHostName = - HttpTunnelMessageUtils.convertToHostString(SERVER_ADDRESS); - handler = new HttpTunnelClientPollHandler(listener); - handler.setTunnelId(TUNNEL_ID); - pipeline.addLast(HttpTunnelClientPollHandler.NAME, handler); - - channel = new FakeSocketChannel(null, null, pipeline, sink); - channel.remoteAddress = PROXY_ADDRESS; - channel.localAddress = LOCAL_ADDRESS; - } - - @Test - public void testSendsRequestOnConnect() { - Channels.fireChannelConnected(channel, PROXY_ADDRESS); - assertEquals(1, sink.events.size()); - HttpRequest request = - checkIsMessageEventContainingHttpRequest(sink.events.poll()); - assertTrue(HttpTunnelMessageUtils.isServerToClientRequest(request)); - assertTrue(HttpTunnelMessageUtils.checkHost(request, SERVER_ADDRESS)); - assertTrue(listener.fullyEstablished); - } - - @Test - public void testSendsReceivedDataSentUpstream() { - HttpResponse response = - HttpTunnelMessageUtils.createRecvDataResponse(NettyTestUtils - .createData(1234L)); - Channels.fireMessageReceived(channel, response); - assertEquals(1, listener.messages.size()); - assertEquals(1234L, listener.messages.get(0).readLong()); - } - - @Test - public void testSendsAnotherRequestAfterResponse() { - HttpResponse response = - HttpTunnelMessageUtils.createRecvDataResponse(NettyTestUtils - .createData(1234L)); - Channels.fireMessageReceived(channel, response); - assertEquals(1, sink.events.size()); - checkIsMessageEventContainingHttpRequest(sink.events.poll()); - } - - private HttpRequest checkIsMessageEventContainingHttpRequest( - ChannelEvent event) { - assertTrue(event instanceof DownstreamMessageEvent); - DownstreamMessageEvent messageEvent = (DownstreamMessageEvent) event; - assertTrue(messageEvent.getMessage() instanceof HttpRequest); - return (HttpRequest) messageEvent.getMessage(); - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientSendHandlerTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientSendHandlerTest.java deleted file mode 100644 index 545c3f8cf3..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelClientSendHandlerTest.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelState; -import io.netty.channel.Channels; -import io.netty.channel.DownstreamMessageEvent; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpRequest; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests HTTP tunnel client sending - */ -public class HttpTunnelClientSendHandlerTest { - - private static final InetSocketAddress SERVER_ADDRESS = createAddress( - new byte[] { 10, 0, 0, 3 }, 12345); - - private static final InetSocketAddress PROXY_ADDRESS = createAddress( - new byte[] { 10, 0, 0, 2 }, 8888); - - private static final InetSocketAddress LOCAL_ADDRESS = createAddress( - new byte[] { 10, 0, 0, 1 }, 54321); - - private FakeSocketChannel channel; - - private FakeChannelSink sink; - - private HttpTunnelClientSendHandler handler; - - private MockChannelStateListener listener; - - @Before - public void setUp() { - sink = new FakeChannelSink(); - ChannelPipeline pipeline = Channels.pipeline(); - listener = new MockChannelStateListener(); - listener.serverHostName = - HttpTunnelMessageUtils.convertToHostString(SERVER_ADDRESS); - handler = new HttpTunnelClientSendHandler(listener); - pipeline.addLast(HttpTunnelClientSendHandler.NAME, handler); - channel = new FakeSocketChannel(null, null, pipeline, sink); - channel.remoteAddress = PROXY_ADDRESS; - channel.localAddress = LOCAL_ADDRESS; - } - - private static InetSocketAddress createAddress(byte[] addr, int port) { - try { - return new InetSocketAddress(InetAddress.getByAddress(addr), port); - } catch (UnknownHostException e) { - throw new RuntimeException("Bad address in test"); - } - } - - @Test - public void testSendsTunnelOpen() throws Exception { - Channels.fireChannelConnected(channel, PROXY_ADDRESS); - assertEquals(1, sink.events.size()); - HttpRequest request = - NettyTestUtils.checkIsDownstreamMessageEvent( - sink.events.poll(), HttpRequest.class); - assertTrue(HttpTunnelMessageUtils.isOpenTunnelRequest(request)); - assertTrue(HttpTunnelMessageUtils.checkHost(request, SERVER_ADDRESS)); - } - - @Test - public void testStoresTunnelId() throws Exception { - emulateConnect(); - Channels.fireMessageReceived(channel, - HttpTunnelMessageUtils.createTunnelOpenResponse("newTunnel")); - assertEquals("newTunnel", handler.getTunnelId()); - assertEquals("newTunnel", listener.tunnelId); - } - - @Test - public void testSendData() { - emulateConnectAndOpen(); - channel.write(NettyTestUtils.createData(1234L)); - assertEquals(1, sink.events.size()); - ChannelEvent sentEvent = sink.events.poll(); - checkIsSendDataRequestWithData(sentEvent, - NettyTestUtils.createData(1234L)); - } - - @Test - public void testWillNotSendDataUntilTunnelIdSet() { - emulateConnect(); - channel.write(NettyTestUtils.createData(1234L)); - - assertEquals(0, sink.events.size()); - - Channels.fireChannelConnected(channel, PROXY_ADDRESS); - assertEquals(1, sink.events.size()); - } - - @Test - public void testOnlyOneRequestAtATime() { - emulateConnectAndOpen(); - - channel.write(NettyTestUtils.createData(1234L)); - assertEquals(1, sink.events.size()); - checkIsSendDataRequestWithData(sink.events.poll(), - NettyTestUtils.createData(1234L)); - - channel.write(NettyTestUtils.createData(5678L)); - assertEquals(0, sink.events.size()); - - Channels.fireMessageReceived(channel, - HttpTunnelMessageUtils.createSendDataResponse()); - assertEquals(1, sink.events.size()); - checkIsSendDataRequestWithData(sink.events.poll(), - NettyTestUtils.createData(5678L)); - } - - @Test - public void testDisconnect() { - emulateConnectAndOpen(); - - channel.write(NettyTestUtils.createData(1234L)); - assertEquals(1, sink.events.size()); - checkIsSendDataRequestWithData(sink.events.poll(), - NettyTestUtils.createData(1234L)); - - channel.disconnect(); - Channels.fireMessageReceived(channel, - HttpTunnelMessageUtils.createSendDataResponse()); - assertEquals(1, sink.events.size()); - - HttpRequest request = - NettyTestUtils.checkIsDownstreamMessageEvent( - sink.events.poll(), HttpRequest.class); - assertTrue(HttpTunnelMessageUtils.isCloseTunnelRequest(request)); - assertEquals("newTunnel", - HttpTunnelMessageUtils.extractTunnelId(request)); - Channels.fireMessageReceived(channel, - HttpTunnelMessageUtils.createTunnelCloseResponse()); - assertEquals(1, sink.events.size()); - NettyTestUtils.checkIsStateEvent(sink.events.poll(), - ChannelState.CONNECTED, null); - } - - @Test - public void testClose() { - emulateConnectAndOpen(); - - channel.close(); - assertEquals(1, sink.events.size()); - HttpRequest request = - NettyTestUtils.checkIsDownstreamMessageEvent( - sink.events.poll(), HttpRequest.class); - assertTrue(HttpTunnelMessageUtils.isCloseTunnelRequest(request)); - assertEquals("newTunnel", - HttpTunnelMessageUtils.extractTunnelId(request)); - Channels.fireMessageReceived(channel, - HttpTunnelMessageUtils.createTunnelCloseResponse()); - assertEquals(1, sink.events.size()); - NettyTestUtils.checkIsStateEvent(sink.events.poll(), ChannelState.OPEN, - false); - } - - @Test - public void testWritesAfterCloseAreRejected() { - emulateConnectAndOpen(); - - channel.close(); - assertFalse(channel.write(NettyTestUtils.createData(1234L)).isSuccess()); - } - - private void checkIsSendDataRequestWithData(ChannelEvent event, - ChannelBuffer data) { - assertTrue(event instanceof DownstreamMessageEvent); - DownstreamMessageEvent messageEvent = (DownstreamMessageEvent) event; - assertTrue(messageEvent.getMessage() instanceof HttpRequest); - HttpRequest request = (HttpRequest) messageEvent.getMessage(); - assertTrue(HttpTunnelMessageUtils.isSendDataRequest(request)); - assertEquals(data.readableBytes(), - HttpHeaders.getContentLength(request)); - - ChannelBuffer content = request.getContent(); - NettyTestUtils.assertEquals(data, content); - } - - private void emulateConnect() { - channel.emulateConnected(LOCAL_ADDRESS, PROXY_ADDRESS, null); - sink.events.clear(); - } - - private void emulateConnectAndOpen() { - emulateConnect(); - Channels.fireMessageReceived(channel, - HttpTunnelMessageUtils.createTunnelOpenResponse("newTunnel")); - - sink.events.clear(); - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelFactoryTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelFactoryTest.java deleted file mode 100644 index 152609d2dc..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelFactoryTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; - -import io.netty.channel.ChannelException; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.socket.ServerSocketChannel; -import io.netty.channel.socket.ServerSocketChannelFactory; -import org.jmock.Expectations; -import org.jmock.integration.junit4.JMock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tests HTTP tunnel server channel factories - */ -@RunWith(JMock.class) -public class HttpTunnelServerChannelFactoryTest { - - private final JUnit4Mockery mockContext = new JUnit4Mockery(); - - ServerSocketChannelFactory realChannelFactory; - - private HttpTunnelServerChannelFactory factory; - - ServerSocketChannel realChannel; - - @Before - public void setUp() throws Exception { - realChannelFactory = mockContext.mock(ServerSocketChannelFactory.class); - factory = new HttpTunnelServerChannelFactory(realChannelFactory); - ChannelPipeline pipeline = Channels.pipeline(); - realChannel = - new FakeServerSocketChannel(factory, pipeline, - new FakeChannelSink()); - } - - @Test - public void testNewChannel() { - mockContext.checking(new Expectations() { - { - one(realChannelFactory).newChannel( - with(any(ChannelPipeline.class))); - will(returnValue(realChannel)); - } - }); - ChannelPipeline pipeline = Channels.pipeline(); - HttpTunnelServerChannel newChannel = factory.newChannel(pipeline); - assertNotNull(newChannel); - assertSame(pipeline, newChannel.pipeline()); - } - - @Test - public void testNewChannel_forwardsWrappedFactoryFailure() { - final ChannelException innerException = new ChannelException(); - mockContext.checking(new Expectations() { - { - one(realChannelFactory).newChannel( - with(any(ChannelPipeline.class))); - will(throwException(innerException)); - } - }); - - try { - factory.newChannel(Channels.pipeline()); - fail("Expected ChannelException"); - } catch (ChannelException e) { - assertSame(innerException, e); - } - } - - // @Test - // public void testChannelCreation_withServerBootstrap() { - // mockContext.checking(new Expectations() {{ - // one(realChannelFactory).newChannel(with(any(ChannelPipeline.class))); will(returnValue(realChannel)); - // }}); - // - // ServerBootstrap bootstrap = new ServerBootstrap(factory); - // Channel newChannel = bootstrap.bind(new InetSocketAddress(80)); - // assertNotNull(newChannel); - // - // } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelSinkTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelSinkTest.java deleted file mode 100644 index b96a9ee1fa..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelSinkTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; - -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.ExceptionEvent; -import io.netty.channel.SimpleChannelUpstreamHandler; -import io.netty.channel.socket.ServerSocketChannel; -import org.jmock.Expectations; -import org.jmock.integration.junit4.JMock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tests HTTP tunnel server channel sinks - */ -@RunWith(JMock.class) -public class HttpTunnelServerChannelSinkTest { - - private final JUnit4Mockery mockContext = new JUnit4Mockery(); - - private HttpTunnelServerChannelSink sink; - - private ChannelPipeline pipeline; - - private FakeSocketChannel channel; - - ServerSocketChannel realChannel; - - ChannelFuture realFuture; - - Throwable exceptionInPipeline; - - @Before - public void setUp() throws Exception { - realChannel = mockContext.mock(ServerSocketChannel.class); - pipeline = Channels.pipeline(); - pipeline.addLast("exceptioncatcher", new ExceptionCatcher()); - sink = new HttpTunnelServerChannelSink(); - sink.setRealChannel(realChannel); - channel = new FakeSocketChannel(null, null, pipeline, sink); - realFuture = Channels.future(realChannel); - } - - @After - public void teardown() throws Exception { - assertTrue("exception caught in pipeline: " + exceptionInPipeline, - exceptionInPipeline == null); - } - - public void testCloseRequest() throws Exception { - mockContext.checking(new Expectations() { - { - one(realChannel).close(); - will(returnValue(realFuture)); - } - }); - - ChannelFuture virtualFuture = Channels.close(channel); - mockContext.assertIsSatisfied(); - realFuture.setSuccess(); - assertTrue(virtualFuture.isSuccess()); - } - - @Test - public void testUnbindRequest_withSuccess() throws Exception { - ChannelFuture virtualFuture = checkUnbind(); - realFuture.setSuccess(); - assertTrue(virtualFuture.isSuccess()); - } - - @Test - public void testUnbindRequest_withFailure() throws Exception { - ChannelFuture virtualFuture = checkUnbind(); - realFuture.setFailure(new Exception("Something bad happened")); - assertFalse(virtualFuture.isSuccess()); - } - - private ChannelFuture checkUnbind() { - mockContext.checking(new Expectations() { - { - one(realChannel).unbind(); - will(returnValue(realFuture)); - } - }); - - ChannelFuture virtualFuture = Channels.unbind(channel); - mockContext.assertIsSatisfied(); - return virtualFuture; - } - - @Test - public void testBindRequest_withSuccess() { - ChannelFuture virtualFuture = checkBind(); - realFuture.setSuccess(); - assertTrue(virtualFuture.isSuccess()); - } - - @Test - public void testBindRequest_withFailure() { - ChannelFuture virtualFuture = checkBind(); - realFuture.setFailure(new Exception("Something bad happened")); - assertFalse(virtualFuture.isSuccess()); - } - - private ChannelFuture checkBind() { - final SocketAddress toAddress = new InetSocketAddress(80); - mockContext.checking(new Expectations() { - { - one(realChannel).bind(toAddress); - will(returnValue(realFuture)); - } - }); - - return Channels.bind(channel, toAddress); - } - - private final class ExceptionCatcher extends SimpleChannelUpstreamHandler { - - ExceptionCatcher() { - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - exceptionInPipeline = e.cause(); - } - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelTest.java deleted file mode 100644 index bea8e0afa7..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelServerChannelTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPipelineFactory; -import io.netty.channel.ChannelState; -import io.netty.channel.Channels; -import io.netty.channel.UpstreamChannelStateEvent; -import io.netty.channel.socket.ServerSocketChannelConfig; -import org.jmock.Expectations; -import org.jmock.integration.junit4.JMock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tests HTTP tunnel server channels - */ -@RunWith(JMock.class) -public class HttpTunnelServerChannelTest { - - JUnit4Mockery mockContext = new JUnit4Mockery(); - - private HttpTunnelServerChannel virtualChannel; - - private UpstreamEventCatcher upstreamEvents; - - private FakeServerSocketChannelFactory realChannelFactory; - - @Before - public void setUp() throws Exception { - realChannelFactory = new FakeServerSocketChannelFactory(); - realChannelFactory.sink = new FakeChannelSink(); - - HttpTunnelServerChannelFactory factory = - new HttpTunnelServerChannelFactory(realChannelFactory); - virtualChannel = factory.newChannel(createVirtualChannelPipeline()); - } - - private ChannelPipeline createVirtualChannelPipeline() { - ChannelPipeline pipeline = Channels.pipeline(); - upstreamEvents = new UpstreamEventCatcher(); - pipeline.addLast(UpstreamEventCatcher.NAME, upstreamEvents); - return pipeline; - } - - @Test - public void testGetLocalAddress_delegatedToRealChannel() { - realChannelFactory.createdChannel.localAddress = - InetSocketAddress.createUnresolved("mycomputer", 80); - SocketAddress returned = virtualChannel.getLocalAddress(); - assertSame(realChannelFactory.createdChannel.localAddress, returned); - } - - @Test - public void testGetRemoteAddress_returnsNull() { - assertNull(virtualChannel.getRemoteAddress()); - } - - @Test - public void testIsBound_delegatedToRealChannel() { - realChannelFactory.createdChannel.bound = true; - assertTrue(virtualChannel.isBound()); - realChannelFactory.createdChannel.bound = false; - assertFalse(virtualChannel.isBound()); - } - - @Test - public void testConstruction_firesOpenEvent() { - assertTrue(upstreamEvents.events.size() > 0); - checkIsUpstreamChannelStateEvent(upstreamEvents.events.poll(), - virtualChannel, ChannelState.OPEN, Boolean.TRUE); - } - - @Test - public void testChannelBoundEventFromReal_replicatedOnVirtual() { - upstreamEvents.events.clear(); - InetSocketAddress boundAddr = - InetSocketAddress.createUnresolved("mycomputer", 12345); - Channels.fireChannelBound(realChannelFactory.createdChannel, boundAddr); - assertEquals(1, upstreamEvents.events.size()); - checkIsUpstreamChannelStateEvent(upstreamEvents.events.poll(), - virtualChannel, ChannelState.BOUND, boundAddr); - } - - @Test - public void testChannelUnboundEventFromReal_replicatedOnVirtual() { - upstreamEvents.events.clear(); - Channels.fireChannelUnbound(realChannelFactory.createdChannel); - assertEquals(1, upstreamEvents.events.size()); - checkIsUpstreamChannelStateEvent(upstreamEvents.events.poll(), - virtualChannel, ChannelState.BOUND, null); - } - - @Test - public void testChannelClosedEventFromReal_replicatedOnVirtual() { - upstreamEvents.events.clear(); - Channels.fireChannelClosed(realChannelFactory.createdChannel); - assertEquals(1, upstreamEvents.events.size()); - checkIsUpstreamChannelStateEvent(upstreamEvents.events.poll(), - virtualChannel, ChannelState.OPEN, Boolean.FALSE); - } - - @Test - public void testHasConfiguration() { - assertNotNull(virtualChannel.getConfig()); - } - - @Test - public void testChangePipelineFactoryDoesNotAffectRealChannel() { - ChannelPipelineFactory realPipelineFactory = - realChannelFactory.createdChannel.getConfig() - .getPipelineFactory(); - ChannelPipelineFactory virtualPipelineFactory = - mockContext.mock(ChannelPipelineFactory.class); - virtualChannel.getConfig().setPipelineFactory(virtualPipelineFactory); - assertSame(virtualPipelineFactory, virtualChannel.getConfig() - .getPipelineFactory()); - - // channel pipeline factory is a special case: we do not want it set on the configuration - // of the underlying factory - assertSame(realPipelineFactory, realChannelFactory.createdChannel - .getConfig().getPipelineFactory()); - } - - @Test - public void testChangingBacklogAffectsRealChannel() { - virtualChannel.getConfig().setBacklog(1234); - assertEquals(1234, realChannelFactory.createdChannel.getConfig() - .getBacklog()); - } - - @Test - public void testChangingConnectTimeoutMillisAffectsRealChannel() { - virtualChannel.getConfig().setConnectTimeoutMillis(54321); - assertEquals(54321, realChannelFactory.createdChannel.getConfig() - .getConnectTimeoutMillis()); - } - - @Test - public void testChangingPerformancePreferencesAffectsRealChannel() { - final ServerSocketChannelConfig mockConfig = - mockContext.mock(ServerSocketChannelConfig.class); - realChannelFactory.createdChannel.config = mockConfig; - mockContext.checking(new Expectations() { - { - one(mockConfig).setPerformancePreferences(100, 200, 300); - } - }); - virtualChannel.getConfig().setPerformancePreferences(100, 200, 300); - mockContext.assertIsSatisfied(); - } - - @Test - public void testChangingReceiveBufferSizeAffectsRealChannel() { - virtualChannel.getConfig().setReceiveBufferSize(10101); - assertEquals(10101, realChannelFactory.createdChannel.getConfig() - .getReceiveBufferSize()); - } - - @Test - public void testChangingReuseAddressAffectsRealChannel() { - virtualChannel.getConfig().setReuseAddress(true); - assertEquals(true, realChannelFactory.createdChannel.getConfig() - .isReuseAddress()); - } - - @Test - public void testSetChannelPipelineFactoryViaOption() { - final ServerSocketChannelConfig mockConfig = - mockContext.mock(ServerSocketChannelConfig.class); - realChannelFactory.createdChannel.config = mockConfig; - - mockContext.checking(new Expectations() { - { - never(mockConfig); - } - }); - - ChannelPipelineFactory factory = - mockContext.mock(ChannelPipelineFactory.class); - virtualChannel.getConfig().setOption("pipelineFactory", factory); - assertSame(factory, virtualChannel.getConfig().getPipelineFactory()); - } - - @Test - public void testSetOptionAffectsRealChannel() { - final ServerSocketChannelConfig mockConfig = - mockContext.mock(ServerSocketChannelConfig.class); - realChannelFactory.createdChannel.config = mockConfig; - - mockContext.checking(new Expectations() { - { - one(mockConfig).setOption("testOption", "testValue"); - } - }); - - virtualChannel.getConfig().setOption("testOption", "testValue"); - } - - private void checkIsUpstreamChannelStateEvent(ChannelEvent ev, - Channel expectedChannel, ChannelState expectedState, - Object expectedValue) { - assertTrue(ev instanceof UpstreamChannelStateEvent); - UpstreamChannelStateEvent checkedEv = (UpstreamChannelStateEvent) ev; - assertSame(expectedChannel, checkedEv.channel()); - assertEquals(expectedState, checkedEv.getState()); - assertEquals(expectedValue, checkedEv.getValue()); - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelSoakTester.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelSoakTester.java deleted file mode 100644 index 6a0a781d15..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelSoakTester.java +++ /dev/null @@ -1,481 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import java.util.Random; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Level; -import java.util.logging.Logger; - -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPipelineFactory; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.Channels; -import io.netty.channel.MessageEvent; -import io.netty.channel.SimpleChannelUpstreamHandler; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.socket.ClientSocketChannelFactory; -import io.netty.channel.socket.ServerSocketChannelFactory; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.nio.NioClientSocketChannelFactory; -import io.netty.channel.socket.nio.NioServerSocketChannelFactory; - -/** - * Tests HTTP tunnel soaking - */ -public class HttpTunnelSoakTester { - - private static final int SERVER_PORT = 20100; - - static final Logger LOG = Logger.getLogger(HttpTunnelSoakTester.class - .getName()); - - private static final long BYTES_TO_SEND = 1024 * 1024 * 1024; - - private static final int MAX_WRITE_SIZE = 64 * 1024; - - private final ServerBootstrap serverBootstrap; - - private final ClientBootstrap clientBootstrap; - - final ChannelGroup channels; - - final ExecutorService executor; - - final ScheduledExecutorService scheduledExecutor; - - final DataSender c2sDataSender = new DataSender("C2S"); - - final DataSender s2cDataSender = new DataSender("S2C"); - - final DataVerifier c2sVerifier = new DataVerifier("C2S-Verifier"); - - final DataVerifier s2cVerifier = new DataVerifier("S2C-Verifier"); - - private static final byte[] SEND_STREAM; - - static { - SEND_STREAM = new byte[MAX_WRITE_SIZE + 127]; - for (int i = 0; i < SEND_STREAM.length; i ++) { - SEND_STREAM[i] = (byte) (i % 127); - } - } - - public HttpTunnelSoakTester() { - scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); - executor = Executors.newCachedThreadPool(); - ServerSocketChannelFactory serverChannelFactory = - new NioServerSocketChannelFactory(executor); - HttpTunnelServerChannelFactory serverTunnelFactory = - new HttpTunnelServerChannelFactory(serverChannelFactory); - - serverBootstrap = new ServerBootstrap(serverTunnelFactory); - serverBootstrap.setPipelineFactory(createServerPipelineFactory()); - - ClientSocketChannelFactory clientChannelFactory = - new NioClientSocketChannelFactory(executor); - HttpTunnelClientChannelFactory clientTunnelFactory = - new HttpTunnelClientChannelFactory(clientChannelFactory); - - clientBootstrap = new ClientBootstrap(clientTunnelFactory); - clientBootstrap.setPipelineFactory(createClientPipelineFactory()); - configureProxy(); - - channels = new DefaultChannelGroup(); - } - - private void configureProxy() { - String proxyHost = System.getProperty("http.proxyHost"); - if (proxyHost != null && proxyHost.length() != 0) { - int proxyPort = Integer.getInteger("http.proxyPort", 80); - InetAddress chosenAddress = chooseAddress(proxyHost); - InetSocketAddress proxyAddress = - new InetSocketAddress(chosenAddress, proxyPort); - if (!proxyAddress.isUnresolved()) { - clientBootstrap.setOption( - HttpTunnelClientChannelConfig.PROXY_ADDRESS_OPTION, - proxyAddress); - System.out.println("Using " + proxyAddress + - " as a proxy for this test run"); - } else { - System.err.println("Failed to resolve proxy address " + - proxyAddress); - } - } else { - System.out - .println("No proxy specified, will connect to server directly"); - } - } - - private InetAddress chooseAddress(String proxyHost) { - try { - InetAddress[] allByName = InetAddress.getAllByName(proxyHost); - for (InetAddress address: allByName) { - if (address.isAnyLocalAddress() || address.isLinkLocalAddress()) { - continue; - } - - return address; - } - - return null; - } catch (UnknownHostException e) { - return null; - } - } - - protected ChannelPipelineFactory createClientPipelineFactory() { - return new ChannelPipelineFactory() { - - @Override - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - pipeline.addLast("s2cVerifier", s2cVerifier); - pipeline.addLast("throttleControl", new SendThrottle( - c2sDataSender)); - return pipeline; - } - }; - } - - protected ChannelPipelineFactory createServerPipelineFactory() { - return new ChannelPipelineFactory() { - - @Override - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - pipeline.addLast("c2sVerifier", c2sVerifier); - pipeline.addLast("throttleControl", new SendThrottle( - s2cDataSender)); - pipeline.addLast("sendStarter", - new SimpleChannelUpstreamHandler() { - @Override - public void channelConnected( - ChannelHandlerContext ctx, - ChannelStateEvent e) throws Exception { - Channel childChannel = e.channel(); - channels.add(childChannel); - s2cDataSender.setChannel(childChannel); - executor.execute(s2cDataSender); - } - }); - return pipeline; - } - }; - } - - public void run() throws InterruptedException { - LOG.info("binding server channel"); - Channel serverChannel = - serverBootstrap.bind(new InetSocketAddress(SERVER_PORT)); - channels.add(serverChannel); - LOG.log(Level.INFO, "server channel bound to {0}", - serverChannel.getLocalAddress()); - - SocketChannel clientChannel = createClientChannel(); - if (clientChannel == null) { - LOG.severe("no client channel - bailing out"); - return; - } - - channels.add(clientChannel); - c2sDataSender.setChannel(clientChannel); - - executor.execute(c2sDataSender); - - if (!c2sDataSender.waitForFinish(5, TimeUnit.MINUTES)) { - LOG.severe("Data send from client to server failed"); - } - - if (!s2cDataSender.waitForFinish(5, TimeUnit.MINUTES)) { - LOG.severe("Data send from server to client failed"); - } - - LOG.log(Level.INFO, "Waiting for verification to complete"); - if (!c2sVerifier.waitForCompletion(30L, TimeUnit.SECONDS)) { - LOG.warning("Timed out waiting for verification of client-to-server stream"); - } - - if (!s2cVerifier.waitForCompletion(30L, TimeUnit.SECONDS)) { - LOG.warning("Timed out waiting for verification of server-to-client stream"); - } - - LOG.info("closing client channel"); - closeChannel(clientChannel); - LOG.info("server channel status: " + - (serverChannel.isOpen()? "open" : "closed")); - LOG.info("closing server channel"); - closeChannel(serverChannel); - } - - private void closeChannel(Channel channel) { - try { - if (!channel.close().await(5L, TimeUnit.SECONDS)) { - LOG.warning("Failed to close connection within reasonable amount of time"); - } - } catch (InterruptedException e) { - LOG.severe("Interrupted while closing connection"); - } - - } - - private SocketChannel createClientChannel() { - InetSocketAddress serverAddress = - new InetSocketAddress("localhost", SERVER_PORT); - ChannelFuture clientChannelFuture = - clientBootstrap.connect(serverAddress); - try { - if (!clientChannelFuture.await(1000, TimeUnit.MILLISECONDS)) { - LOG.severe("did not connect within acceptable time period"); - return null; - } - } catch (InterruptedException e) { - LOG.severe("Interrupted while waiting for client connect to be established"); - return null; - } - - if (!clientChannelFuture.isSuccess()) { - LOG.log(Level.SEVERE, "did not connect successfully", - clientChannelFuture.cause()); - return null; - } - - HttpTunnelClientChannelConfig config = - (HttpTunnelClientChannelConfig) clientChannelFuture - .channel().getConfig(); - config.setWriteBufferHighWaterMark(2 * 1024 * 1024); - config.setWriteBufferLowWaterMark(1024 * 1024); - - return (SocketChannel) clientChannelFuture.channel(); - } - - ChannelBuffer createRandomSizeBuffer(AtomicInteger nextWriteByte) { - Random random = new Random(); - int arraySize = random.nextInt(MAX_WRITE_SIZE) + 1; - - // cheaply create the buffer by wrapping an appropriately sized section of the pre-built array - ChannelBuffer buffer = - ChannelBuffers.wrappedBuffer(SEND_STREAM, nextWriteByte.get(), - arraySize); - nextWriteByte.set((nextWriteByte.get() + arraySize) % 127); - - return buffer; - } - - public static void main(String[] args) throws Exception { - HttpTunnelSoakTester soakTester = new HttpTunnelSoakTester(); - try { - soakTester.run(); - } finally { - soakTester.shutdown(); - } - } - - private void shutdown() { - serverBootstrap.releaseExternalResources(); - clientBootstrap.releaseExternalResources(); - executor.shutdownNow(); - scheduledExecutor.shutdownNow(); - } - - private class DataVerifier extends SimpleChannelUpstreamHandler { - private final String name; - - private int expectedNext = 0; - - private int verifiedBytes = 0; - - private final CountDownLatch completionLatch = new CountDownLatch(1); - - public DataVerifier(String name) { - this.name = name; - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - ChannelBuffer bytesToVerify = (ChannelBuffer) e.getMessage(); - - while (bytesToVerify.readable()) { - byte readByte = bytesToVerify.readByte(); - if (readByte != expectedNext) { - LOG.log(Level.SEVERE, - "{0}: received a byte out of sequence. Expected {1}, got {2}", - new Object[] { name, expectedNext, readByte }); - System.exit(-1); - return; - } - - expectedNext = (expectedNext + 1) % 127; - verifiedBytes ++; - } - - if (verifiedBytes >= BYTES_TO_SEND) { - completionLatch.countDown(); - } - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channels.add(ctx.channel()); - } - - public boolean waitForCompletion(long timeout, TimeUnit timeoutUnit) - throws InterruptedException { - return completionLatch.await(timeout, timeoutUnit); - } - } - - private class SendThrottle extends SimpleChannelUpstreamHandler { - private final DataSender sender; - - public SendThrottle(DataSender sender) { - this.sender = sender; - } - - @Override - public void channelInterestChanged(ChannelHandlerContext ctx, - ChannelStateEvent e) throws Exception { - boolean writeEnabled = ctx.channel().isWritable(); - sender.setWriteEnabled(writeEnabled); - - } - } - - private class DataSender implements Runnable { - - private final AtomicReference channel = - new AtomicReference(); - - private long totalBytesSent = 0; - - private long numWrites = 0; - - private long runStartTime = System.currentTimeMillis(); - - private boolean firstRun = true; - - private final AtomicBoolean writeEnabled = new AtomicBoolean(true); - - private final AtomicBoolean running = new AtomicBoolean(false); - - private final CountDownLatch finishLatch = new CountDownLatch(1); - - private final String name; - - private final AtomicInteger nextWriteByte = new AtomicInteger(0); - - public DataSender(String name) { - this.name = name; - } - - public void setChannel(Channel channel) { - this.channel.set(channel); - } - - public void setWriteEnabled(boolean enabled) { - writeEnabled.set(enabled); - if (enabled && !isRunning() && finishLatch.getCount() > 0) { - executor.execute(this); - } - } - - @Override - public void run() { - if (!running.compareAndSet(false, true)) { - LOG.log(Level.WARNING, - "{0}: Attempt made to run duplicate sender!", name); - return; - } - - if (finishLatch.getCount() == 0) { - LOG.log(Level.SEVERE, - "{0}: Attempt made to run after completion!", name); - } - - if (firstRun) { - firstRun = false; - runStartTime = System.currentTimeMillis(); - LOG.log(Level.INFO, "{0}: sending data", name); - } - - while (totalBytesSent < BYTES_TO_SEND) { - if (!writeEnabled.get()) { - running.set(false); - return; - } - - ChannelBuffer randomBytesForSend = - createRandomSizeBuffer(nextWriteByte); - totalBytesSent += randomBytesForSend.readableBytes(); - - channel.get().write( - ChannelBuffers.wrappedBuffer(randomBytesForSend)); - - numWrites ++; - if (numWrites % 100 == 0) { - LOG.log(Level.INFO, - "{0}: {1} writes dispatched, totalling {2} bytes", - new Object[] { name, numWrites, totalBytesSent }); - } - } - - LOG.log(Level.INFO, "{0}: completed send cycle", name); - - long runEndTime = System.currentTimeMillis(); - long totalTime = runEndTime - runStartTime; - long totalKB = totalBytesSent / 1024; - double rate = totalKB / (totalTime / 1000.0); - LOG.log(Level.INFO, "{0}: Sent {1} bytes", new Object[] { name, - totalBytesSent }); - LOG.log(Level.INFO, "{0}: Average throughput: {1} KB/s", - new Object[] { name, rate }); - - finishLatch.countDown(); - running.set(false); - } - - public boolean isRunning() { - return running.get(); - } - - public boolean waitForFinish(long timeout, TimeUnit timeoutUnit) - throws InterruptedException { - return finishLatch.await(timeout, timeoutUnit); - } - - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelTest.java deleted file mode 100644 index c084bfd5af..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/HttpTunnelTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPipelineFactory; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.Channels; -import io.netty.channel.MessageEvent; -import io.netty.channel.SimpleChannelUpstreamHandler; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.socket.nio.NioClientSocketChannelFactory; -import io.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests HTTP tunnelling - */ -public class HttpTunnelTest { - - private HttpTunnelClientChannelFactory clientFactory; - - private HttpTunnelServerChannelFactory serverFactory; - - private ClientBootstrap clientBootstrap; - - private ServerBootstrap serverBootstrap; - - ChannelGroup activeConnections; - - ChannelHandler clientCaptureHandler; - - ServerEndHandler connectionCaptureHandler; - - Channel serverEnd; - - CountDownLatch serverEndLatch; - - ChannelBuffer receivedBytes; - - CountDownLatch messageReceivedLatch; - - ChannelBuffer clientReceivedBytes; - - CountDownLatch clientMessageReceivedLatch; - - private Channel serverChannel; - - @Before - public void setUp() throws UnknownHostException { - activeConnections = new DefaultChannelGroup(); - clientFactory = - new HttpTunnelClientChannelFactory( - new NioClientSocketChannelFactory( - Executors.newCachedThreadPool())); - serverFactory = - new HttpTunnelServerChannelFactory( - new NioServerSocketChannelFactory( - Executors.newCachedThreadPool())); - - clientBootstrap = new ClientBootstrap(clientFactory); - - clientCaptureHandler = new ClientEndHandler(); - clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() { - - @Override - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - pipeline.addLast("clientCapture", clientCaptureHandler); - return pipeline; - } - }); - - clientReceivedBytes = ChannelBuffers.dynamicBuffer(); - clientMessageReceivedLatch = new CountDownLatch(1); - - serverBootstrap = new ServerBootstrap(serverFactory); - - connectionCaptureHandler = new ServerEndHandler(); - serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { - - @Override - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - pipeline.addLast("capture", connectionCaptureHandler); - return pipeline; - } - }); - - serverEndLatch = new CountDownLatch(1); - receivedBytes = ChannelBuffers.dynamicBuffer(); - messageReceivedLatch = new CountDownLatch(1); - - serverChannel = - serverBootstrap.bind(new InetSocketAddress(InetAddress - .getLocalHost(), 12345)); - activeConnections.add(serverChannel); - } - - @After - public void tearDown() throws Exception { - activeConnections.disconnect().await(1000L); - clientBootstrap.releaseExternalResources(); - serverBootstrap.releaseExternalResources(); - } - - @Test(timeout = 2000) - public void testConnectClientToServer() throws Exception { - ChannelFuture connectFuture = - clientBootstrap.connect(new InetSocketAddress(InetAddress - .getLocalHost(), 12345)); - assertTrue(connectFuture.await(1000L)); - assertTrue(connectFuture.isSuccess()); - assertNotNull(connectFuture.channel()); - - Channel clientChannel = connectFuture.channel(); - activeConnections.add(clientChannel); - assertEquals(serverChannel.getLocalAddress(), - clientChannel.getRemoteAddress()); - - assertTrue(serverEndLatch.await(1000, TimeUnit.MILLISECONDS)); - assertNotNull(serverEnd); - - // TODO: See if we can do something about it - // - // Fails on windows, seems like ipv6 is the problem here. - // - // Failed tests: testConnectClientToServer(io.netty.channel.socket.http.HttpTunnelTest): expected: but was: - // assertEquals(clientChannel.getLocalAddress(), serverEnd.getRemoteAddress()); - } - - @Test - public void testSendDataFromClientToServer() throws Exception { - ChannelFuture connectFuture = - clientBootstrap.connect(new InetSocketAddress(InetAddress - .getLocalHost(), 12345)); - assertTrue(connectFuture.await(1000L)); - - Channel clientEnd = connectFuture.channel(); - activeConnections.add(clientEnd); - - assertTrue(serverEndLatch.await(1000, TimeUnit.MILLISECONDS)); - - ChannelFuture writeFuture = - Channels.write(clientEnd, NettyTestUtils.createData(100L)); - assertTrue(writeFuture.await(1000L)); - assertTrue(writeFuture.isSuccess()); - - assertTrue(messageReceivedLatch.await(1000L, TimeUnit.MILLISECONDS)); - assertEquals(100L, receivedBytes.readLong()); - } - - @Test - public void testSendDataFromServerToClient() throws Exception { - ChannelFuture connectFuture = - clientBootstrap.connect(new InetSocketAddress(InetAddress - .getLocalHost(), 12345)); - assertTrue(connectFuture.await(1000L)); - - Channel clientEnd = connectFuture.channel(); - activeConnections.add(clientEnd); - - assertTrue(serverEndLatch.await(1000, TimeUnit.MILLISECONDS)); - - ChannelFuture writeFuture = - Channels.write(serverEnd, NettyTestUtils.createData(4321L)); - assertTrue(writeFuture.await(1000L)); - assertTrue(writeFuture.isSuccess()); - - assertTrue(clientMessageReceivedLatch - .await(1000, TimeUnit.MILLISECONDS)); - assertEquals(4321L, clientReceivedBytes.readLong()); - } - - class ServerEndHandler extends SimpleChannelUpstreamHandler { - - @Override - public void channelConnected(ChannelHandlerContext ctx, - ChannelStateEvent e) throws Exception { - serverEnd = e.channel(); - activeConnections.add(serverEnd); - serverEndLatch.countDown(); - super.channelConnected(ctx, e); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - receivedBytes.writeBytes((ChannelBuffer) e.getMessage()); - messageReceivedLatch.countDown(); - } - } - - class ClientEndHandler extends SimpleChannelUpstreamHandler { - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - clientReceivedBytes.writeBytes((ChannelBuffer) e.getMessage()); - clientMessageReceivedLatch.countDown(); - } - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/MockChannelStateListener.java b/transport-http/src/test/java/io/netty/channel/socket/http/MockChannelStateListener.java deleted file mode 100644 index 8d37b3c422..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/MockChannelStateListener.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.ChannelFuture; - -/** - * A mock channel state listener - */ -public class MockChannelStateListener implements HttpTunnelClientWorkerOwner { - - public boolean fullyEstablished = false; - - public List messages = new ArrayList(); - - public String tunnelId = null; - - public String serverHostName = null; - - @Override - public void fullyEstablished() { - fullyEstablished = true; - } - - @Override - public void onConnectRequest(ChannelFuture connectFuture, - InetSocketAddress remoteAddress) { - // not relevant for test - } - - @Override - public void onMessageReceived(ChannelBuffer content) { - messages.add(content); - } - - @Override - public void onTunnelOpened(String tunnelId) { - this.tunnelId = tunnelId; - } - - @Override - public String getServerHostName() { - return serverHostName; - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/NettyTestUtils.java b/transport-http/src/test/java/io/netty/channel/socket/http/NettyTestUtils.java deleted file mode 100644 index 1f82529108..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/NettyTestUtils.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertTrue; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import junit.framework.Assert; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelState; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.DownstreamMessageEvent; -import io.netty.channel.ExceptionEvent; -import io.netty.channel.UpstreamMessageEvent; - -/** - * Test utilities for Netty - */ -public class NettyTestUtils { - - public static ByteBuffer convertReadable(ChannelBuffer b) { - int startIndex = b.readerIndex(); - ByteBuffer converted = ByteBuffer.allocate(b.readableBytes()); - b.readBytes(converted); - b.readerIndex(startIndex); - converted.flip(); - return converted; - } - - public static void assertEquals(ChannelBuffer expected, ChannelBuffer actual) { - if (expected.readableBytes() != actual.readableBytes()) { - Assert.failNotEquals( - "channel buffers have differing readable sizes", - expected.readableBytes(), actual.readableBytes()); - } - - int startPositionExpected = expected.readerIndex(); - int startPositionActual = actual.readerIndex(); - int position = 0; - while (expected.readable()) { - byte expectedByte = expected.readByte(); - byte actualByte = actual.readByte(); - if (expectedByte != actualByte) { - Assert.failNotEquals("channel buffers differ at position " + - position, expectedByte, actualByte); - } - - position ++; - } - - expected.readerIndex(startPositionExpected); - actual.readerIndex(startPositionActual); - } - - public static boolean checkEquals(ChannelBuffer expected, - ChannelBuffer actual) { - if (expected.readableBytes() != actual.readableBytes()) { - return false; - } - - while (expected.readable()) { - byte expectedByte = expected.readByte(); - byte actualByte = actual.readByte(); - if (expectedByte != actualByte) { - return false; - } - } - - return true; - } - - public static List splitIntoChunks(int chunkSize, - ChannelBuffer... buffers) { - LinkedList chunks = new LinkedList(); - - ArrayList sourceBuffers = new ArrayList(); - Collections.addAll(sourceBuffers, buffers); - Iterator sourceIter = sourceBuffers.iterator(); - ChannelBuffer chunk = ChannelBuffers.buffer(chunkSize); - while (sourceIter.hasNext()) { - ChannelBuffer source = sourceIter.next(); - - int index = source.readerIndex(); - while (source.writerIndex() > index) { - int fragmentSize = - Math.min(source.writerIndex() - index, - chunk.writableBytes()); - chunk.writeBytes(source, index, fragmentSize); - if (!chunk.writable()) { - chunks.add(chunk); - chunk = ChannelBuffers.buffer(chunkSize); - } - index += fragmentSize; - } - } - - if (chunk.readable()) { - chunks.add(chunk); - } - - return chunks; - } - - public static ChannelBuffer createData(long containedNumber) { - ChannelBuffer data = ChannelBuffers.dynamicBuffer(); - data.writeLong(containedNumber); - return data; - } - - public static void checkIsUpstreamMessageEventContainingData( - ChannelEvent event, ChannelBuffer expectedData) { - ChannelBuffer data = - checkIsUpstreamMessageEvent(event, ChannelBuffer.class); - assertEquals(expectedData, data); - } - - public static T checkIsUpstreamMessageEvent(ChannelEvent event, - Class expectedMessageType) { - assertTrue(event instanceof UpstreamMessageEvent); - UpstreamMessageEvent messageEvent = (UpstreamMessageEvent) event; - assertTrue(expectedMessageType.isInstance(messageEvent.getMessage())); - return expectedMessageType.cast(messageEvent.getMessage()); - } - - public static T checkIsDownstreamMessageEvent(ChannelEvent event, - Class expectedMessageType) { - assertTrue(event instanceof DownstreamMessageEvent); - DownstreamMessageEvent messageEvent = (DownstreamMessageEvent) event; - assertTrue(expectedMessageType.isInstance(messageEvent.getMessage())); - return expectedMessageType.cast(messageEvent.getMessage()); - } - - public static InetSocketAddress createAddress(byte[] addr, int port) { - try { - return new InetSocketAddress(InetAddress.getByAddress(addr), port); - } catch (UnknownHostException e) { - throw new RuntimeException("Bad address in test"); - } - } - - public static Throwable checkIsExceptionEvent(ChannelEvent ev) { - assertTrue(ev instanceof ExceptionEvent); - ExceptionEvent exceptionEv = (ExceptionEvent) ev; - return exceptionEv.cause(); - } - - public static ChannelStateEvent checkIsStateEvent(ChannelEvent event, - ChannelState expectedState, Object expectedValue) { - assertTrue(event instanceof ChannelStateEvent); - ChannelStateEvent stateEvent = (ChannelStateEvent) event; - Assert.assertEquals(expectedState, stateEvent.getState()); - Assert.assertEquals(expectedValue, stateEvent.getValue()); - return stateEvent; - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/NettyTestUtilsTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/NettyTestUtilsTest.java deleted file mode 100644 index 34a402bc26..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/NettyTestUtilsTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.util.List; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import org.junit.Test; - -/** - * Tests the Netty utilities - */ -public class NettyTestUtilsTest { - - @Test - public void testSplitIntoChunks() { - ChannelBuffer a = createFullBuffer(20, (byte) 0); - ChannelBuffer b = createFullBuffer(20, (byte) 1); - ChannelBuffer c = createFullBuffer(20, (byte) 2); - - List chunks = - NettyTestUtils.splitIntoChunks(10, a, b, c); - assertEquals(6, chunks.size()); - for (ChannelBuffer chunk: chunks) { - assertEquals(10, chunk.readableBytes()); - } - - // reader index should not be modified by splitIntoChunks() - assertEquals(0, a.readerIndex()); - assertEquals(0, b.readerIndex()); - assertEquals(0, c.readerIndex()); - } - - @Test - public void testSplitIntoChunks_chunksCrossBoundaries() { - ChannelBuffer a = createFullBuffer(5, (byte) 0); - ChannelBuffer b = createFullBuffer(5, (byte) 1); - ChannelBuffer c = createFullBuffer(5, (byte) 2); - - List chunks = NettyTestUtils.splitIntoChunks(4, a, b, c); - assertEquals(4, chunks.size()); - checkBufferContains(chunks.get(0), new byte[] { 0, 0, 0, 0 }); - checkBufferContains(chunks.get(1), new byte[] { 0, 1, 1, 1 }); - checkBufferContains(chunks.get(2), new byte[] { 1, 1, 2, 2 }); - checkBufferContains(chunks.get(3), new byte[] { 2, 2, 2 }); - } - - @Test - public void testSplitIntoChunks_smallestChunksPossible() { - ChannelBuffer a = createFullBuffer(5, (byte) 0); - ChannelBuffer b = createFullBuffer(5, (byte) 1); - ChannelBuffer c = createFullBuffer(5, (byte) 2); - - List chunks = NettyTestUtils.splitIntoChunks(1, a, b, c); - assertEquals(15, chunks.size()); - checkBufferContains(chunks.get(0), new byte[] { 0 }); - checkBufferContains(chunks.get(5), new byte[] { 1 }); - checkBufferContains(chunks.get(10), new byte[] { 2 }); - } - - @Test - public void testSplitIntoChunks_sourceBuffersArePartiallyRead() { - ChannelBuffer a = createFullBuffer(5, (byte) 0); - a.readerIndex(1); - ChannelBuffer b = createFullBuffer(5, (byte) 1); - b.readerIndex(2); - ChannelBuffer c = createFullBuffer(5, (byte) 2); - - // will be ignored, as fully read - ChannelBuffer d = createFullBuffer(5, (byte) 3); - d.readerIndex(5); - ChannelBuffer e = createFullBuffer(5, (byte) 4); - e.readerIndex(4); - - List chunks = - NettyTestUtils.splitIntoChunks(3, a, b, c, d, e); - checkBufferContains(chunks.get(0), new byte[] { 0, 0, 0 }); - checkBufferContains(chunks.get(1), new byte[] { 0, 1, 1 }); - checkBufferContains(chunks.get(2), new byte[] { 1, 2, 2 }); - checkBufferContains(chunks.get(3), new byte[] { 2, 2, 2 }); - checkBufferContains(chunks.get(4), new byte[] { 4 }); - } - - private void checkBufferContains(ChannelBuffer channelBuffer, byte[] bs) { - if (channelBuffer.readableBytes() != bs.length) { - fail("buffer does not have enough bytes"); - } - - for (int i = 0; i < bs.length; i ++) { - assertEquals("byte at position " + i + " does not match", bs[i], - channelBuffer.getByte(i)); - } - } - - private ChannelBuffer createFullBuffer(int size, byte value) { - ChannelBuffer buffer = ChannelBuffers.buffer(size); - byte[] contents = new byte[size]; - for (int i = 0; i < contents.length; i ++) { - contents[i] = value; - } - buffer.writeBytes(contents); - return buffer; - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/NullChannelHandler.java b/transport-http/src/test/java/io/netty/channel/socket/http/NullChannelHandler.java deleted file mode 100644 index 34499d2490..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/NullChannelHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import io.netty.channel.ChannelDownstreamHandler; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelUpstreamHandler; - -/** - * A channel handler that simply sends events upstream or downstream - */ -public class NullChannelHandler implements ChannelUpstreamHandler, - ChannelDownstreamHandler { - - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) - throws Exception { - ctx.sendUpstream(e); - } - - @Override - public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) - throws Exception { - ctx.sendDownstream(e); - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/SaturationManagerTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/SaturationManagerTest.java deleted file mode 100644 index 36292c706e..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/SaturationManagerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.socket.http; - -import static org.junit.Assert.*; -import static io.netty.channel.socket.http.SaturationStateChange.*; - -import org.junit.Before; -import org.junit.Test; - -/** - * Tests saturation managers - * - - */ -public class SaturationManagerTest { - - private SaturationManager manager; - - @Before - public void setUp() { - manager = new SaturationManager(100L, 200L); - } - - @Test - public void testQueueSizeChanged() { - assertEquals(NO_CHANGE, manager.queueSizeChanged(100L)); - assertEquals(NO_CHANGE, manager.queueSizeChanged(99L)); - assertEquals(NO_CHANGE, manager.queueSizeChanged(1L)); - assertEquals(SATURATED, manager.queueSizeChanged(1L)); - assertEquals(NO_CHANGE, manager.queueSizeChanged(10L)); - - assertEquals(NO_CHANGE, manager.queueSizeChanged(-10L)); - assertEquals(NO_CHANGE, manager.queueSizeChanged(-1L)); - assertEquals(NO_CHANGE, manager.queueSizeChanged(-1L)); - assertEquals(DESATURATED, manager.queueSizeChanged(-99L)); - assertEquals(NO_CHANGE, manager.queueSizeChanged(-100L)); - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/ServerMessageSwitchTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/ServerMessageSwitchTest.java deleted file mode 100644 index bbd364ec82..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/ServerMessageSwitchTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.*; - -import java.net.InetSocketAddress; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.socket.http.ServerMessageSwitchUpstreamInterface.TunnelStatus; -import io.netty.handler.codec.http.HttpResponse; -import org.jmock.Expectations; -import org.jmock.integration.junit4.JMock; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tests server message switching - */ -@RunWith(JMock.class) -public class ServerMessageSwitchTest { - - public static final InetSocketAddress REMOTE_ADDRESS = InetSocketAddress - .createUnresolved("test.client.com", 52354); - - private final JUnit4Mockery mockContext = new JUnit4Mockery(); - - private ServerMessageSwitch messageSwitch; - - HttpTunnelAcceptedChannelFactory newChannelFactory; - - private FakeChannelSink responseCatcher; - - private FakeSocketChannel htunChannel; - - private FakeSocketChannel requesterChannel; - - HttpTunnelAcceptedChannelReceiver htunAcceptedChannel; - - @Before - public void setUp() throws Exception { - newChannelFactory = - mockContext.mock(HttpTunnelAcceptedChannelFactory.class); - messageSwitch = new ServerMessageSwitch(newChannelFactory); - - htunAcceptedChannel = - mockContext.mock(HttpTunnelAcceptedChannelReceiver.class); - createRequesterChannel(); - - mockContext.checking(new Expectations() { - { - one(newChannelFactory).newChannel(with(any(String.class)), - with(equal(REMOTE_ADDRESS))); - will(returnValue(htunAcceptedChannel)); - ignoring(newChannelFactory).generateTunnelId(); - will(returnValue("TEST_TUNNEL")); - } - }); - } - - private FakeSocketChannel createRequesterChannel() { - ChannelPipeline requesterChannelPipeline = Channels.pipeline(); - responseCatcher = new FakeChannelSink(); - requesterChannel = - new FakeSocketChannel(null, null, requesterChannelPipeline, - responseCatcher); - responseCatcher.events.clear(); - - return requesterChannel; - } - - @Test - public void testRouteInboundData() { - final ChannelBuffer inboundData = ChannelBuffers.dynamicBuffer(); - inboundData.writeLong(1234L); - - mockContext.checking(new Expectations() { - { - one(htunAcceptedChannel).dataReceived(with(same(inboundData))); - } - }); - - String tunnelId = messageSwitch.createTunnel(REMOTE_ADDRESS); - messageSwitch.routeInboundData(tunnelId, inboundData); - mockContext.assertIsSatisfied(); - } - - @Test - public void testRouteOutboundData_onPoll() { - ChannelBuffer outboundData = ChannelBuffers.dynamicBuffer(); - outboundData.writeLong(1234L); - - String tunnelId = messageSwitch.createTunnel(REMOTE_ADDRESS); - messageSwitch.routeOutboundData(tunnelId, outboundData, - Channels.future(htunChannel)); - messageSwitch.pollOutboundData(tunnelId, requesterChannel); - - assertEquals(1, responseCatcher.events.size()); - HttpResponse response = - NettyTestUtils.checkIsDownstreamMessageEvent( - responseCatcher.events.poll(), HttpResponse.class); - NettyTestUtils.assertEquals(outboundData, response.getContent()); - } - - @Test - public void testRouteOutboundData_withDanglingRequest() { - String tunnelId = messageSwitch.createTunnel(REMOTE_ADDRESS); - messageSwitch.pollOutboundData(tunnelId, requesterChannel); - assertEquals(0, responseCatcher.events.size()); - - ChannelBuffer outboundData = ChannelBuffers.dynamicBuffer(); - outboundData.writeLong(1234L); - - messageSwitch.routeOutboundData(tunnelId, outboundData, - Channels.future(htunChannel)); - assertEquals(1, responseCatcher.events.size()); - HttpResponse response = - NettyTestUtils.checkIsDownstreamMessageEvent( - responseCatcher.events.poll(), HttpResponse.class); - NettyTestUtils.assertEquals(outboundData, response.getContent()); - } - - @Test - public void testCloseTunnel() { - String tunnelId = messageSwitch.createTunnel(REMOTE_ADDRESS); - messageSwitch.serverCloseTunnel(tunnelId); - assertEquals( - TunnelStatus.CLOSED, - messageSwitch.routeInboundData(tunnelId, - ChannelBuffers.dynamicBuffer())); - } - - /* TODO: require tests that check the various permutations of a client sending or polling - data after the server has closed the connection */ - - /* TODO: require tests that check what happens when a client closes a connection */ - - @Test - public void testRouteInboundDataIgnoredAfterClose() { - ChannelBuffer data = NettyTestUtils.createData(1234L); - String tunnelId = messageSwitch.createTunnel(REMOTE_ADDRESS); - messageSwitch.serverCloseTunnel(tunnelId); - - mockContext.checking(new Expectations() { - { - never(htunAcceptedChannel).dataReceived( - with(any(ChannelBuffer.class))); - } - }); - - messageSwitch.routeInboundData(tunnelId, data); - mockContext.assertIsSatisfied(); - } - - @Test - public void testRouteOutboundDataIgnoredAfterClose() { - ChannelBuffer data = NettyTestUtils.createData(1234L); - String tunnelId = messageSwitch.createTunnel(REMOTE_ADDRESS); - messageSwitch.serverCloseTunnel(tunnelId); - messageSwitch.routeOutboundData(tunnelId, data, - Channels.future(htunChannel)); - assertEquals(0, responseCatcher.events.size()); - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/UpstreamEventCatcher.java b/transport-http/src/test/java/io/netty/channel/socket/http/UpstreamEventCatcher.java deleted file mode 100644 index 411c0eb564..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/UpstreamEventCatcher.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import java.util.LinkedList; -import java.util.Queue; - -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelUpstreamHandler; - -/** - * Tests the upstream event catcher - */ -public class UpstreamEventCatcher implements ChannelUpstreamHandler { - - public static final String NAME = "upstreamCatcher"; - - public Queue events = new LinkedList(); - - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) - throws Exception { - events.add(e); - } - -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/WriteFragmenterTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/WriteFragmenterTest.java deleted file mode 100644 index 7865ca18a3..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/WriteFragmenterTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; -import io.netty.channel.MessageEvent; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests write fragmenting capabilities - */ -public class WriteFragmenterTest { - - private FakeSocketChannel channel; - - private WriteFragmenter fragmenter; - - private FakeChannelSink downstreamCatcher; - - @Before - public void setUp() throws Exception { - fragmenter = new WriteFragmenter(100); - - ChannelPipeline pipeline = Channels.pipeline(); - pipeline.addLast(WriteFragmenter.NAME, fragmenter); - downstreamCatcher = new FakeChannelSink(); - channel = - new FakeSocketChannel(null, null, pipeline, downstreamCatcher); - } - - @Test - public void testLeavesWritesBeneathThresholdUntouched() { - ChannelBuffer data = ChannelBuffers.wrappedBuffer(new byte[99]); - Channels.write(channel, data); - - assertEquals(1, downstreamCatcher.events.size()); - ChannelBuffer sentData = - NettyTestUtils.checkIsDownstreamMessageEvent( - downstreamCatcher.events.poll(), ChannelBuffer.class); - assertSame(data, sentData); - } - - @Test - public void testLeavesMessagesOnThresholdUntouched() { - ChannelBuffer data = ChannelBuffers.wrappedBuffer(new byte[100]); - Channels.write(channel, data); - - assertEquals(1, downstreamCatcher.events.size()); - ChannelBuffer sentData = - NettyTestUtils.checkIsDownstreamMessageEvent( - downstreamCatcher.events.poll(), ChannelBuffer.class); - assertSame(data, sentData); - } - - @Test - public void testSplitsMessagesAboveThreshold_twoChunks() { - ChannelBuffer data = ChannelBuffers.wrappedBuffer(new byte[101]); - Channels.write(channel, data); - - assertEquals(2, downstreamCatcher.events.size()); - ChannelBuffer chunk1 = - NettyTestUtils.checkIsDownstreamMessageEvent( - downstreamCatcher.events.poll(), ChannelBuffer.class); - ChannelBuffer chunk2 = - NettyTestUtils.checkIsDownstreamMessageEvent( - downstreamCatcher.events.poll(), ChannelBuffer.class); - assertEquals(100, chunk1.readableBytes()); - assertEquals(1, chunk2.readableBytes()); - } - - @Test - public void testSplitsMessagesAboveThreshold_multipleChunks() { - ChannelBuffer data = ChannelBuffers.wrappedBuffer(new byte[2540]); - Channels.write(channel, data); - - assertEquals(26, downstreamCatcher.events.size()); - for (int i = 0; i < 25; i ++) { - ChannelBuffer chunk = - NettyTestUtils.checkIsDownstreamMessageEvent( - downstreamCatcher.events.poll(), - ChannelBuffer.class); - assertEquals(100, chunk.readableBytes()); - } - - ChannelBuffer endChunk = - NettyTestUtils.checkIsDownstreamMessageEvent( - downstreamCatcher.events.poll(), ChannelBuffer.class); - assertEquals(40, endChunk.readableBytes()); - } - - @Test - public void testChannelFutureTriggeredOnlyWhenAllChunksWritten() { - ChannelBuffer data = ChannelBuffers.wrappedBuffer(new byte[2540]); - ChannelFuture mainWriteFuture = Channels.write(channel, data); - - assertEquals(26, downstreamCatcher.events.size()); - for (int i = 0; i < 25; i ++) { - ((MessageEvent) downstreamCatcher.events.poll()).getFuture() - .setSuccess(); - assertFalse(mainWriteFuture.isDone()); - } - - ((MessageEvent) downstreamCatcher.events.poll()).getFuture() - .setSuccess(); - assertTrue(mainWriteFuture.isDone()); - assertTrue(mainWriteFuture.isSuccess()); - } - - @Test - public void testChannelFutureFailsOnFirstWriteFailure() { - ChannelBuffer data = ChannelBuffers.wrappedBuffer(new byte[2540]); - ChannelFuture mainWriteFuture = Channels.write(channel, data); - - assertEquals(26, downstreamCatcher.events.size()); - for (int i = 0; i < 10; i ++) { - ((MessageEvent) downstreamCatcher.events.poll()).getFuture() - .setSuccess(); - assertFalse(mainWriteFuture.isDone()); - } - - ((MessageEvent) downstreamCatcher.events.poll()).getFuture() - .setFailure(new Exception("Something bad happened")); - assertTrue(mainWriteFuture.isDone()); - assertFalse(mainWriteFuture.isSuccess()); - - // check all the subsequent writes got cancelled - for (int i = 0; i < 15; i ++) { - assertTrue(((MessageEvent) downstreamCatcher.events.poll()) - .getFuture().isCancelled()); - } - } -} diff --git a/transport-http/src/test/java/io/netty/channel/socket/http/WriteSplitterTest.java b/transport-http/src/test/java/io/netty/channel/socket/http/WriteSplitterTest.java deleted file mode 100644 index 58a09f1684..0000000000 --- a/transport-http/src/test/java/io/netty/channel/socket/http/WriteSplitterTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.socket.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import org.junit.Test; - -/** - * Tests write splitting capabilities - */ -public class WriteSplitterTest { - - private static final int SPLIT_THRESHOLD = 1024; - - @Test - public void testSplit_bufferUnderThreshold() { - ChannelBuffer buffer = createBufferWithContents(800); - List fragments = - WriteSplitter.split(buffer, SPLIT_THRESHOLD); - assertNotNull(fragments); - assertEquals(1, fragments.size()); - } - - @Test - public void testSplit_bufferMatchesThreshold() { - ChannelBuffer buffer = createBufferWithContents(SPLIT_THRESHOLD); - List fragments = - WriteSplitter.split(buffer, SPLIT_THRESHOLD); - assertNotNull(fragments); - assertEquals(1, fragments.size()); - } - - @Test - public void testSplit_bufferOverThreshold() { - ChannelBuffer buffer = - createBufferWithContents((int) (SPLIT_THRESHOLD * 1.5)); - List fragments = - WriteSplitter.split(buffer, SPLIT_THRESHOLD); - assertNotNull(fragments); - assertEquals(2, fragments.size()); - - ChannelBuffer fragment1 = fragments.get(0); - checkMatches(buffer, fragment1); - ChannelBuffer fragment2 = fragments.get(1); - checkMatches(buffer, fragment2); - } - - @Test - public void testSplit_largeNumberOfFragments() { - ChannelBuffer buffer = createBufferWithContents(SPLIT_THRESHOLD * 250); - List fragments = - WriteSplitter.split(buffer, SPLIT_THRESHOLD); - assertNotNull(fragments); - assertEquals(250, fragments.size()); - - for (ChannelBuffer fragment: fragments) { - checkMatches(buffer, fragment); - } - } - - private void checkMatches(ChannelBuffer mainBuffer, ChannelBuffer fragment) { - assertTrue(mainBuffer.readableBytes() >= fragment.readableBytes()); - while (fragment.readable()) { - assertEquals(mainBuffer.readByte(), fragment.readByte()); - } - } - - private ChannelBuffer createBufferWithContents(int size) { - byte[] contents = new byte[size]; - for (int i = 0; i < contents.length; i ++) { - contents[i] = (byte) (i % 10); - } - - return ChannelBuffers.copiedBuffer(contents); - } - -} diff --git a/transport-rxtx/pom.xml b/transport-rxtx/pom.xml deleted file mode 100644 index dafb386e1c..0000000000 --- a/transport-rxtx/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - 4.0.0 - - io.netty - netty-parent - 4.0.0.Alpha1-SNAPSHOT - - - netty-transport-rxtx - jar - - Netty/Transport/RXTX - - - - ${project.groupId} - netty-transport - ${project.version} - - - org.rxtx - rxtx - - - - diff --git a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java deleted file mode 100644 index 51611aa442..0000000000 --- a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.rxtx; - - -import java.net.SocketAddress; - -import io.netty.channel.AbstractChannel; -import io.netty.channel.Channel; -import io.netty.channel.ChannelConfig; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; - -/** - * A channel to a serial device using the RXTX library. - */ -public class RxtxChannel extends AbstractChannel { - - RxtxChannel(final Channel parent, final ChannelFactory factory, final ChannelPipeline pipeline, - final ChannelSink sink) { - super(parent, factory, pipeline, sink); - } - - @Override - public ChannelConfig getConfig() { - return ((RxtxChannelSink) getPipeline().getSink()).getConfig(); - } - - @Override - public boolean isBound() { - return ((RxtxChannelSink) getPipeline().getSink()).isBound(); - } - - @Override - public boolean isConnected() { - return ((RxtxChannelSink) getPipeline().getSink()).isConnected(); - } - - @Override - public SocketAddress getLocalAddress() { - return null; - } - - @Override - public SocketAddress getRemoteAddress() { - return ((RxtxChannelSink) getPipeline().getSink()).getRemoteAddress(); - } - - @Override - public ChannelFuture bind(final SocketAddress localAddress) { - throw new UnsupportedOperationException(); - } - - @Override - public ChannelFuture unbind() { - throw new UnsupportedOperationException(); - } - - void doSetClosed() { - setClosed(); - } -} diff --git a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelConfig.java b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelConfig.java deleted file mode 100644 index cf623db903..0000000000 --- a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelConfig.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.rxtx; - -import gnu.io.SerialPort; - -import io.netty.channel.DefaultChannelConfig; -import io.netty.util.internal.ConversionUtil; - -/** - * A configuration class for RXTX device connections. - */ -public class RxtxChannelConfig extends DefaultChannelConfig { - - public enum Stopbits { - - STOPBITS_1(SerialPort.STOPBITS_1), - STOPBITS_2(SerialPort.STOPBITS_2), - STOPBITS_1_5(SerialPort.STOPBITS_1_5); - - private final int value; - - Stopbits(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static Stopbits ofValue(int value) { - for (Stopbits stopbit : Stopbits.values()) { - if (stopbit.value == value) { - return stopbit; - } - } - throw new IllegalArgumentException("Unknown value for Stopbits: " + value + "."); - } - } - - public enum Databits { - - DATABITS_5(SerialPort.DATABITS_5), - DATABITS_6(SerialPort.DATABITS_6), - DATABITS_7(SerialPort.DATABITS_7), - DATABITS_8(SerialPort.DATABITS_8); - - private final int value; - - Databits(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static Databits ofValue(int value) { - for (Databits databit : Databits.values()) { - if (databit.value == value) { - return databit; - } - } - throw new IllegalArgumentException("Unknown value for Databits: " + value + "."); - } - } - - public enum Paritybit { - - NONE(SerialPort.PARITY_NONE), - ODD(SerialPort.PARITY_ODD), - EVEN(SerialPort.PARITY_EVEN), - MARK(SerialPort.PARITY_MARK), - SPACE(SerialPort.PARITY_SPACE); - - private final int value; - - Paritybit(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static Paritybit ofValue(int value) { - for (Paritybit paritybit : Paritybit.values()) { - if (paritybit.value == value) { - return paritybit; - } - } - throw new IllegalArgumentException("Unknown value for paritybit: " + value + "."); - } - } - - private int baudrate = 115200; - - private boolean dtr; - - private boolean rts; - - private Stopbits stopbits = RxtxChannelConfig.Stopbits.STOPBITS_1; - - private Databits databits = RxtxChannelConfig.Databits.DATABITS_8; - - private Paritybit paritybit = RxtxChannelConfig.Paritybit.NONE; - - public RxtxChannelConfig() { - // work with defaults ... - } - - public RxtxChannelConfig(final int baudrate, final boolean dtr, final boolean rts, final Stopbits stopbits, - final Databits databits, final Paritybit paritybit) { - this.baudrate = baudrate; - this.dtr = dtr; - this.rts = rts; - this.stopbits = stopbits; - this.databits = databits; - this.paritybit = paritybit; - } - - @Override - public boolean setOption(final String key, final Object value) { - if (key.equals("baudrate")) { - setBaudrate(ConversionUtil.toInt(value)); - return true; - } else if (key.equals("stopbits")) { - setStopbits((Stopbits) value); - return true; - } else if (key.equals("databits")) { - setDatabits((Databits) value); - return true; - } else if (key.equals("paritybit")) { - setParitybit((Paritybit) value); - return true; - } else { - return super.setOption(key, value); - } - } - - public void setBaudrate(final int baudrate) { - this.baudrate = baudrate; - } - - public void setStopbits(final Stopbits stopbits) { - this.stopbits = stopbits; - } - - public void setDatabits(final Databits databits) { - this.databits = databits; - } - - private void setParitybit(final Paritybit paritybit) { - this.paritybit = paritybit; - } - - public int getBaudrate() { - return baudrate; - } - - public Stopbits getStopbits() { - return stopbits; - } - - public Databits getDatabits() { - return databits; - } - - public Paritybit getParitybit() { - return paritybit; - } - - public boolean isDtr() { - return dtr; - } - - public void setDtr(final boolean dtr) { - this.dtr = dtr; - } - - public boolean isRts() { - return rts; - } - - public void setRts(final boolean rts) { - this.rts = rts; - } -} diff --git a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelFactory.java b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelFactory.java deleted file mode 100644 index 095b708c69..0000000000 --- a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.rxtx; - - -import java.util.concurrent.ExecutorService; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.ChannelGroupFuture; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.util.internal.ExecutorUtil; - -/** - * A {@link ChannelFactory} for creating {@link RxtxChannel} instances. - */ -public class RxtxChannelFactory implements ChannelFactory { - - private final ChannelGroup channels = new DefaultChannelGroup("RXTXChannelFactory-ChannelGroup"); - - private final ExecutorService executor; - - public RxtxChannelFactory(ExecutorService executor) { - this.executor = executor; - } - - @Override - public Channel newChannel(final ChannelPipeline pipeline) { - RxtxChannelSink sink = new RxtxChannelSink(executor); - RxtxChannel channel = new RxtxChannel(null, this, pipeline, sink); - sink.setChannel(channel); - channels.add(channel); - return channel; - } - - @Override - public void releaseExternalResources() { - ChannelGroupFuture close = channels.close(); - close.awaitUninterruptibly(); - ExecutorUtil.terminate(executor); - } -} diff --git a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelSink.java b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelSink.java deleted file mode 100644 index fd1c34c0a0..0000000000 --- a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannelSink.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.rxtx; - -import gnu.io.CommPort; -import gnu.io.CommPortIdentifier; -import gnu.io.NoSuchPortException; -import gnu.io.PortInUseException; -import gnu.io.SerialPort; -import gnu.io.SerialPortEvent; -import gnu.io.SerialPortEventListener; -import gnu.io.UnsupportedCommOperationException; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.util.TooManyListenersException; -import java.util.concurrent.Executor; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.AbstractChannelSink; -import io.netty.channel.ChannelConfig; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.channel.ChannelState; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.Channels; -import io.netty.channel.DefaultChannelFuture; -import io.netty.channel.MessageEvent; -import io.netty.channel.UpstreamMessageEvent; - -/** - * A {@link ChannelSink} implementation of the RXTX support for Netty. - */ -public class RxtxChannelSink extends AbstractChannelSink { - - private static class WriteRunnable implements Runnable { - - private final DefaultChannelFuture future; - - private final RxtxChannelSink channelSink; - - private final ChannelBuffer message; - - public WriteRunnable(final DefaultChannelFuture future, final RxtxChannelSink channelSink, - final ChannelBuffer message) { - this.future = future; - this.channelSink = channelSink; - this.message = message; - } - - @Override - public void run() { - try { - - channelSink.outputStream.write(message.array(), message.readerIndex(), message.readableBytes()); - channelSink.outputStream.flush(); - future.setSuccess(); - - } catch (Exception e) { - future.setFailure(e); - } - } - } - - private static class ConnectRunnable implements Runnable { - - private final DefaultChannelFuture channelFuture; - - private final RxtxChannelSink channelSink; - - ConnectRunnable(final DefaultChannelFuture channelFuture, final RxtxChannelSink channelSink) { - this.channelFuture = channelFuture; - this.channelSink = channelSink; - } - - @Override - public void run() { - - if (channelSink.closed) { - channelFuture.setFailure(new Exception("Channel is already closed.")); - } else { - try { - connectInternal(); - channelFuture.setSuccess(); - } catch (Exception e) { - channelFuture.setFailure(e); - } - } - - } - - private void connectInternal() - throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException, - TooManyListenersException { - - final CommPort commPort; - try { - - final CommPortIdentifier cpi = - CommPortIdentifier.getPortIdentifier(channelSink.remoteAddress.getDeviceAddress()); - commPort = cpi.open(this.getClass().getName(), 1000); - - } catch (NoSuchPortException e) { - throw e; - } catch (PortInUseException e) { - throw e; - } - - channelSink.serialPort = (SerialPort) commPort; - channelSink.serialPort.addEventListener(new RXTXSerialPortEventListener(channelSink)); - channelSink.serialPort.notifyOnDataAvailable(true); - channelSink.serialPort.setSerialPortParams( - channelSink.config.getBaudrate(), - channelSink.config.getDatabits().getValue(), - channelSink.config.getStopbits().getValue(), - channelSink.config.getParitybit().getValue() - ); - - channelSink.serialPort.setDTR(channelSink.config.isDtr()); - channelSink.serialPort.setRTS(channelSink.config.isRts()); - - channelSink.outputStream = new BufferedOutputStream(channelSink.serialPort.getOutputStream()); - channelSink.inputStream = new BufferedInputStream(channelSink.serialPort.getInputStream()); - } - } - - private static class DisconnectRunnable implements Runnable { - - private final DefaultChannelFuture channelFuture; - - private final RxtxChannelSink channelSink; - - public DisconnectRunnable(final DefaultChannelFuture channelFuture, final RxtxChannelSink channelSink) { - this.channelFuture = channelFuture; - this.channelSink = channelSink; - } - - @Override - public void run() { - if (channelSink.closed) { - channelFuture.setFailure(new Exception("Channel is already closed.")); - } else { - try { - disconnectInternal(); - channelSink.channel.doSetClosed(); - } catch (Exception e) { - channelFuture.setFailure(e); - } - } - } - - private void disconnectInternal() throws Exception { - - Exception exception = null; - - try { - if (channelSink.inputStream != null) { - channelSink.inputStream.close(); - } - } catch (IOException e) { - exception = e; - } - - try { - if (channelSink.outputStream != null) { - channelSink.outputStream.close(); - } - } catch (IOException e) { - exception = e; - } - - if (channelSink.serialPort != null) { - channelSink.serialPort.removeEventListener(); - channelSink.serialPort.close(); - } - - channelSink.inputStream = null; - channelSink.outputStream = null; - channelSink.serialPort = null; - - if (exception != null) { - throw exception; - } - } - } - - private final Executor executor; - - final RxtxChannelConfig config; - - RxtxChannel channel; - - public RxtxChannelSink(final Executor executor) { - this.executor = executor; - config = new RxtxChannelConfig(); - } - - public boolean isConnected() { - return inputStream != null && outputStream != null; - } - - public RxtxDeviceAddress getRemoteAddress() { - return remoteAddress; - } - - public boolean isBound() { - return false; - } - - public ChannelConfig getConfig() { - return config; - } - - public void setChannel(final RxtxChannel channel) { - this.channel = channel; - } - - private static class RXTXSerialPortEventListener implements SerialPortEventListener { - - private final RxtxChannelSink channelSink; - - public RXTXSerialPortEventListener(final RxtxChannelSink channelSink) { - this.channelSink = channelSink; - } - - @Override - public void serialEvent(final SerialPortEvent event) { - switch (event.getEventType()) { - case SerialPortEvent.DATA_AVAILABLE: - try { - if (channelSink.inputStream != null && channelSink.inputStream.available() > 0) { - int available = channelSink.inputStream.available(); - byte[] buffer = new byte[available]; - int read = channelSink.inputStream.read(buffer); - if (read > 0) { - ChannelBuffer channelBuffer = ChannelBuffers.wrappedBuffer(buffer, 0, read); - UpstreamMessageEvent upstreamMessageEvent = new UpstreamMessageEvent( - channelSink.channel, - channelBuffer, - channelSink.getRemoteAddress() - ); - channelSink.channel.getPipeline().sendUpstream(upstreamMessageEvent); - } - } - } catch (IOException e) { - Channels.fireExceptionCaught(channelSink.channel, e); - channelSink.channel.close(); - } - break; - } - } - } - - RxtxDeviceAddress remoteAddress; - - BufferedOutputStream outputStream; - - BufferedInputStream inputStream; - - SerialPort serialPort; - - volatile boolean closed; - - @Override - public void eventSunk(final ChannelPipeline pipeline, final ChannelEvent e) throws Exception { - - final ChannelFuture future = e.getFuture(); - - if (e instanceof ChannelStateEvent) { - - final ChannelStateEvent stateEvent = (ChannelStateEvent) e; - final ChannelState state = stateEvent.getState(); - final Object value = stateEvent.getValue(); - - switch (state) { - - case OPEN: - if (Boolean.FALSE.equals(value)) { - executor.execute(new DisconnectRunnable((DefaultChannelFuture) future, this)); - } - break; - - case BOUND: - throw new UnsupportedOperationException(); - - case CONNECTED: - if (value != null) { - remoteAddress = (RxtxDeviceAddress) value; - executor.execute(new ConnectRunnable((DefaultChannelFuture) future, this)); - } else { - executor.execute(new DisconnectRunnable((DefaultChannelFuture) future, this)); - } - break; - - case INTEREST_OPS: - throw new UnsupportedOperationException(); - - } - - } else if (e instanceof MessageEvent) { - - final MessageEvent event = (MessageEvent) e; - if (event.getMessage() instanceof ChannelBuffer) { - executor.execute( - new WriteRunnable((DefaultChannelFuture) future, this, (ChannelBuffer) event.getMessage()) - ); - } else { - throw new IllegalArgumentException( - "Only ChannelBuffer objects are supported to be written onto the RXTXChannelSink! " - + "Please check if the encoder pipeline is configured correctly." - ); - } - } - } -} diff --git a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxDeviceAddress.java b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxDeviceAddress.java deleted file mode 100644 index d018823891..0000000000 --- a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxDeviceAddress.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.rxtx; - -import java.net.SocketAddress; - -/** - * A {@link SocketAddress} subclass to wrap the serial port address of a RXTX - * device (e.g. COM1, /dev/ttyUSB0). - */ -public class RxtxDeviceAddress extends SocketAddress { - - private static final long serialVersionUID = -2907820090993709523L; - - private final String deviceAddress; - - /** - * - * @param deviceAddress the address of the device (e.g. COM1, /dev/ttyUSB0, ...) - */ - public RxtxDeviceAddress(String deviceAddress) { - this.deviceAddress = deviceAddress; - } - - public String getDeviceAddress() { - return deviceAddress; - } -} diff --git a/transport-rxtx/src/main/java/io/netty/channel/rxtx/package-info.java b/transport-rxtx/src/main/java/io/netty/channel/rxtx/package-info.java deleted file mode 100644 index 90719423ef..0000000000 --- a/transport-rxtx/src/main/java/io/netty/channel/rxtx/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * A serial and parallel port communication transport based on RXTX. - */ -package io.netty.channel.rxtx; diff --git a/transport-sctp/pom.xml b/transport-sctp/pom.xml deleted file mode 100644 index 1803e2fa45..0000000000 --- a/transport-sctp/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - 4.0.0 - - io.netty - netty-parent - 4.0.0.Alpha1-SNAPSHOT - - - netty-transport-sctp - jar - - Netty/Transport/SCTP - - - - ${project.groupId} - netty-transport - ${project.version} - - - ${project.groupId} - netty-codec - ${project.version} - - - ${project.groupId} - netty-handler - ${project.version} - - - - - - - maven-jar-plugin - - - - **/com/** - - - - - - - diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/AbstractNotificationHandler.java b/transport-sctp/src/main/java/com/sun/nio/sctp/AbstractNotificationHandler.java deleted file mode 100644 index bade95b264..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/AbstractNotificationHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public class AbstractNotificationHandler implements NotificationHandler { - static { - UnsupportedOperatingSystemException.raise(); - } - - public HandlerResult handleNotification(AssociationChangeNotification notification, Object o) { - return null; - } - - public HandlerResult handleNotification(Notification notification, Object o) { - return null; - } - - public HandlerResult handleNotification(PeerAddressChangeNotification notification, Object o) { - return null; - } - - public HandlerResult handleNotification(SendFailedNotification notification, Object o) { - return null; - } - - public HandlerResult handleNotification(ShutdownNotification notification, Object o) { - return null; - } -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/Association.java b/transport-sctp/src/main/java/com/sun/nio/sctp/Association.java deleted file mode 100644 index e190295f5e..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/Association.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public class Association { - static { - UnsupportedOperatingSystemException.raise(); - } -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/AssociationChangeNotification.java b/transport-sctp/src/main/java/com/sun/nio/sctp/AssociationChangeNotification.java deleted file mode 100644 index 8b8098c851..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/AssociationChangeNotification.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public abstract class AssociationChangeNotification implements Notification { - static { - UnsupportedOperatingSystemException.raise(); - } -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/HandlerResult.java b/transport-sctp/src/main/java/com/sun/nio/sctp/HandlerResult.java deleted file mode 100644 index f75088140b..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/HandlerResult.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -/** - * TODO Document me. - * - * @author Trustin Lee - */ -public enum HandlerResult { - CONTINUE, RETURN; -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/MessageInfo.java b/transport-sctp/src/main/java/com/sun/nio/sctp/MessageInfo.java deleted file mode 100644 index 1f7eaccbd0..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/MessageInfo.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -import java.net.SocketAddress; - -public abstract class MessageInfo { - static { - UnsupportedOperatingSystemException.raise(); - } - - public static MessageInfo createOutgoing(Association association, SocketAddress address, int streamNumber) { - return null; - } - - public abstract SocketAddress address(); - public abstract int streamNumber(); - public abstract MessageInfo streamNumber(int streamNumber); - public abstract int payloadProtocolID(); - public abstract MessageInfo payloadProtocolID(int ppid); - public abstract boolean isComplete(); - public abstract boolean isUnordered(); - public abstract MessageInfo unordered(boolean b); - -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/Notification.java b/transport-sctp/src/main/java/com/sun/nio/sctp/Notification.java deleted file mode 100644 index 32f1a809c9..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/Notification.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public interface Notification { - Association association(); -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/NotificationHandler.java b/transport-sctp/src/main/java/com/sun/nio/sctp/NotificationHandler.java deleted file mode 100644 index 1b86c0c57e..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/NotificationHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public interface NotificationHandler { -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/PeerAddressChangeNotification.java b/transport-sctp/src/main/java/com/sun/nio/sctp/PeerAddressChangeNotification.java deleted file mode 100644 index 7c61551edb..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/PeerAddressChangeNotification.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public abstract class PeerAddressChangeNotification implements Notification { - static { - UnsupportedOperatingSystemException.raise(); - } -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/SctpChannel.java b/transport-sctp/src/main/java/com/sun/nio/sctp/SctpChannel.java deleted file mode 100644 index 4d0c906d0e..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/SctpChannel.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.spi.AbstractSelectableChannel; -import java.nio.channels.spi.SelectorProvider; -import java.util.Set; - -public abstract class SctpChannel extends AbstractSelectableChannel { - static { - UnsupportedOperatingSystemException.raise(); - } - - public static SctpChannel open() throws IOException { - return null; - } - - protected SctpChannel(SelectorProvider provider) { - super(provider); - } - - public abstract T getOption(SctpSocketOption name) throws IOException; - public abstract SctpChannel setOption(SctpSocketOption name, T value) throws IOException; - - public abstract Set getAllLocalAddresses() throws IOException; - public abstract Set getRemoteAddresses() throws IOException; - - public abstract Association association() throws IOException; - public abstract SctpChannel bind(SocketAddress local) throws IOException; - public abstract boolean connect(SocketAddress remote) throws IOException; - public abstract boolean finishConnect() throws IOException; - - public abstract SctpChannel bindAddress(InetAddress inetAddress) throws IOException; - public abstract SctpChannel unbindAddress(InetAddress inetAddress) throws IOException; - - public abstract MessageInfo receive(ByteBuffer dst, T attachment, NotificationHandler handler) throws IOException; - public abstract int send(ByteBuffer src, MessageInfo messageInfo) throws IOException; - - public abstract Set> supportedOptions(); -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/SctpServerChannel.java b/transport-sctp/src/main/java/com/sun/nio/sctp/SctpServerChannel.java deleted file mode 100644 index eaf617e5f7..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/SctpServerChannel.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.SocketAddress; -import java.nio.channels.spi.AbstractSelectableChannel; -import java.nio.channels.spi.SelectorProvider; -import java.util.Set; - -public abstract class SctpServerChannel extends AbstractSelectableChannel { - static { - UnsupportedOperatingSystemException.raise(); - } - - public static SctpServerChannel open() throws IOException { - return null; - } - - protected SctpServerChannel(SelectorProvider provider) { - super(provider); - } - - public abstract T getOption(SctpSocketOption name) throws IOException; - public abstract SctpChannel setOption(SctpSocketOption name, T value) throws IOException; - - public abstract Set getAllLocalAddresses() throws IOException; - - public abstract SctpServerChannel bind(SocketAddress local) throws IOException; - public abstract SctpServerChannel bind(SocketAddress local, int backlog) throws IOException; - - public abstract SctpServerChannel bindAddress(InetAddress inetAddress) throws IOException; - public abstract SctpServerChannel unbindAddress(InetAddress inetAddress) throws IOException; - - public abstract SctpChannel accept() throws IOException; -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/SctpSocketOption.java b/transport-sctp/src/main/java/com/sun/nio/sctp/SctpSocketOption.java deleted file mode 100644 index 66ca504ceb..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/SctpSocketOption.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public interface SctpSocketOption { - String name(); - Class type(); -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/SctpStandardSocketOptions.java b/transport-sctp/src/main/java/com/sun/nio/sctp/SctpStandardSocketOptions.java deleted file mode 100644 index 0cbca3061f..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/SctpStandardSocketOptions.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -import java.net.SocketAddress; - -public class SctpStandardSocketOptions { - static { - UnsupportedOperatingSystemException.raise(); - } - - public static final SctpSocketOption SCTP_DISABLE_FRAGMENTS = null; - public static final SctpSocketOption SCTP_EXPLICIT_COMPLETE = null; - public static final SctpSocketOption SCTP_FRAGMENT_INTERLEAVE = null; - public static final SctpSocketOption SCTP_INIT_MAXSTREAMS = null; - public static final SctpSocketOption SCTP_NODELAY = null; - public static final SctpSocketOption SCTP_PRIMARY_ADDR = null; - public static final SctpSocketOption SCTP_SET_PEER_PRIMARY_ADDR = null; - public static final SctpSocketOption SO_LINGER = null; - public static final SctpSocketOption SO_RCVBUF = null; - public static final SctpSocketOption SO_SNDBUF = null; - - public static class InitMaxStreams { - - public static InitMaxStreams create(int i, int i1) { - return null; - } - - public int maxInStreams() { - return 0; - } - - public int maxOutStreams() { - return 0; - } - - } -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/SendFailedNotification.java b/transport-sctp/src/main/java/com/sun/nio/sctp/SendFailedNotification.java deleted file mode 100644 index 47bbe89ad9..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/SendFailedNotification.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public abstract class SendFailedNotification implements Notification { - static { - UnsupportedOperatingSystemException.raise(); - } -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/ShutdownNotification.java b/transport-sctp/src/main/java/com/sun/nio/sctp/ShutdownNotification.java deleted file mode 100644 index d0f408c2da..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/ShutdownNotification.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public abstract class ShutdownNotification implements Notification { - static { - UnsupportedOperatingSystemException.raise(); - } -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java b/transport-sctp/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java deleted file mode 100644 index 8cd99f1783..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package com.sun.nio.sctp; - -public class UnsupportedOperatingSystemException extends RuntimeException { - - private static final long serialVersionUID = -221782446524784377L; - - public static void raise() { - throw new UnsupportedOperatingSystemException(); - } - - public UnsupportedOperatingSystemException() { - super(); - } - - public UnsupportedOperatingSystemException(String message) { - super(message); - } - - public UnsupportedOperatingSystemException(String message, Throwable cause) { - super(message, cause); - } - - public UnsupportedOperatingSystemException(Throwable cause) { - super(cause); - } -} diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/package-info.java b/transport-sctp/src/main/java/com/sun/nio/sctp/package-info.java deleted file mode 100644 index beefdb38ca..0000000000 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * This package is only included to let SCTP also compile on non-unix operation systems. - * - * This will not get included in the generated jar! - */ -package com.sun.nio.sctp; diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultNioSctpChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultNioSctpChannelConfig.java deleted file mode 100644 index 0598804db8..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultNioSctpChannelConfig.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import com.sun.nio.sctp.SctpChannel; -import java.util.Map; - -import io.netty.channel.AdaptiveReceiveBufferSizePredictorFactory; -import io.netty.channel.ChannelException; -import io.netty.channel.ReceiveBufferSizePredictor; -import io.netty.channel.ReceiveBufferSizePredictorFactory; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; -import io.netty.util.internal.ConversionUtil; - -/** - * The default {@link io.netty.channel.socket.nio.NioSocketChannelConfig} implementation for SCTP. - */ -class DefaultNioSctpChannelConfig extends DefaultSctpChannelConfig implements NioSctpChannelConfig { - - private static final InternalLogger logger = - InternalLoggerFactory.getInstance(DefaultNioSctpChannelConfig.class); - - private static final ReceiveBufferSizePredictorFactory DEFAULT_PREDICTOR_FACTORY = - new AdaptiveReceiveBufferSizePredictorFactory(); - - private volatile int writeBufferHighWaterMark = 64 * 1024; - private volatile int writeBufferLowWaterMark = 32 * 1024; - private volatile ReceiveBufferSizePredictor predictor; - private volatile ReceiveBufferSizePredictorFactory predictorFactory = DEFAULT_PREDICTOR_FACTORY; - private volatile int writeSpinCount = 16; - - DefaultNioSctpChannelConfig(SctpChannel channel) { - super(channel); - } - - @Override - public void setOptions(Map options) { - super.setOptions(options); - if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) { - // Recover the integrity of the configuration with a sensible value. - setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1); - if (logger.isWarnEnabled()) { - // Notify the user about misconfiguration. - logger.warn( - "writeBufferLowWaterMark cannot be greater than " + - "writeBufferHighWaterMark; setting to the half of the " + - "writeBufferHighWaterMark."); - } - } - } - - @Override - public boolean setOption(String key, Object value) { - if (super.setOption(key, value)) { - return true; - } - - if (key.equals("writeBufferHighWaterMark")) { - setWriteBufferHighWaterMark0(ConversionUtil.toInt(value)); - } else if (key.equals("writeBufferLowWaterMark")) { - setWriteBufferLowWaterMark0(ConversionUtil.toInt(value)); - } else if (key.equals("writeSpinCount")) { - setWriteSpinCount(ConversionUtil.toInt(value)); - } else if (key.equals("receiveBufferSizePredictorFactory")) { - setReceiveBufferSizePredictorFactory((ReceiveBufferSizePredictorFactory) value); - } else if (key.equals("receiveBufferSizePredictor")) { - setReceiveBufferSizePredictor((ReceiveBufferSizePredictor) value); - } else { - return false; - } - return true; - } - - @Override - public int getWriteBufferHighWaterMark() { - return writeBufferHighWaterMark; - } - - @Override - public void setWriteBufferHighWaterMark(int writeBufferHighWaterMark) { - if (writeBufferHighWaterMark < getWriteBufferLowWaterMark()) { - throw new IllegalArgumentException( - "writeBufferHighWaterMark cannot be less than " + - "writeBufferLowWaterMark (" + getWriteBufferLowWaterMark() + "): " + - writeBufferHighWaterMark); - } - setWriteBufferHighWaterMark0(writeBufferHighWaterMark); - } - - private void setWriteBufferHighWaterMark0(int writeBufferHighWaterMark) { - if (writeBufferHighWaterMark < 0) { - throw new IllegalArgumentException( - "writeBufferHighWaterMark: " + writeBufferHighWaterMark); - } - this.writeBufferHighWaterMark = writeBufferHighWaterMark; - } - - @Override - public int getWriteBufferLowWaterMark() { - return writeBufferLowWaterMark; - } - - @Override - public void setWriteBufferLowWaterMark(int writeBufferLowWaterMark) { - if (writeBufferLowWaterMark > getWriteBufferHighWaterMark()) { - throw new IllegalArgumentException( - "writeBufferLowWaterMark cannot be greater than " + - "writeBufferHighWaterMark (" + getWriteBufferHighWaterMark() + "): " + - writeBufferLowWaterMark); - } - setWriteBufferLowWaterMark0(writeBufferLowWaterMark); - } - - private void setWriteBufferLowWaterMark0(int writeBufferLowWaterMark) { - if (writeBufferLowWaterMark < 0) { - throw new IllegalArgumentException( - "writeBufferLowWaterMark: " + writeBufferLowWaterMark); - } - this.writeBufferLowWaterMark = writeBufferLowWaterMark; - } - - @Override - public int getWriteSpinCount() { - return writeSpinCount; - } - - @Override - public void setWriteSpinCount(int writeSpinCount) { - if (writeSpinCount <= 0) { - throw new IllegalArgumentException( - "writeSpinCount must be a positive integer."); - } - this.writeSpinCount = writeSpinCount; - } - - @Override - public ReceiveBufferSizePredictor getReceiveBufferSizePredictor() { - ReceiveBufferSizePredictor predictor = this.predictor; - if (predictor == null) { - try { - this.predictor = predictor = getReceiveBufferSizePredictorFactory().getPredictor(); - } catch (Exception e) { - throw new ChannelException( - "Failed to create a new " + - ReceiveBufferSizePredictor.class.getSimpleName() + '.', - e); - } - } - return predictor; - } - - @Override - public void setReceiveBufferSizePredictor( - ReceiveBufferSizePredictor predictor) { - if (predictor == null) { - throw new NullPointerException("predictor"); - } - this.predictor = predictor; - } - - @Override - public ReceiveBufferSizePredictorFactory getReceiveBufferSizePredictorFactory() { - return predictorFactory; - } - - @Override - public void setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory predictorFactory) { - if (predictorFactory == null) { - throw new NullPointerException("predictorFactory"); - } - this.predictorFactory = predictorFactory; - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java deleted file mode 100644 index 6f66119e9e..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static io.netty.channel.ChannelOption.*; -import io.netty.channel.ChannelException; -import io.netty.channel.ChannelOption; -import io.netty.channel.DefaultChannelConfig; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import com.sun.nio.sctp.SctpChannel; -import com.sun.nio.sctp.SctpStandardSocketOptions.InitMaxStreams; - -/** - * The default {@link NioSocketChannelConfig} implementation for SCTP. - */ -class DefaultSctpChannelConfig extends DefaultChannelConfig implements SctpChannelConfig { - - private final SctpChannel channel; - - DefaultSctpChannelConfig(SctpChannel channel) { - if (channel == null) { - throw new NullPointerException("channel"); - } - this.channel = channel; - } - - @Override - public Map, Object> getOptions() { - // TODO: Investigate if other SCTP options such as SCTP_PRIMARY_ADDR can be exposed. - return getOptions(super.getOptions(), SO_RCVBUF, SO_SNDBUF, SCTP_NODELAY, SCTP_INIT_MAXSTREAMS); - } - - @Override - public T getOption(ChannelOption option) { - if (option == SO_RCVBUF) { - return (T) Integer.valueOf(getReceiveBufferSize()); - } - if (option == SO_SNDBUF) { - return (T) Integer.valueOf(getSendBufferSize()); - } - if (option == SCTP_NODELAY) { - return (T) Boolean.valueOf(isSctpNoDelay()); - } - if (option == SCTP_INIT_MAXSTREAMS) { - InitMaxStreams ims = getInitMaxStreams(); - if (ims == null) { - return null; - } - List values = new ArrayList(2); - values.add(ims.maxInStreams()); - values.add(ims.maxOutStreams()); - @SuppressWarnings("unchecked") - T ret = (T) values; - return ret; - } - - return super.getOption(option); - } - - @Override - public boolean setOption(ChannelOption option, T value) { - validate(option, value); - - if (option == SO_RCVBUF) { - setReceiveBufferSize((Integer) value); - } else if (option == SO_SNDBUF) { - setSendBufferSize((Integer) value); - } else if (option == SCTP_NODELAY) { - setSctpNoDelay((Boolean) value); - } else if (option == SCTP_INIT_MAXSTREAMS) { - @SuppressWarnings("unchecked") - List values = (List) value; - setInitMaxStreams(InitMaxStreams.create(values.get(0), values.get(1))); - } else { - return super.setOption(option, value); - } - - return true; - } - - @Override - public boolean isSctpNoDelay() { - try { - return channel.getOption(com.sun.nio.sctp.SctpStandardSocketOptions.SCTP_NODELAY); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public void setSctpNoDelay(boolean sctpNoDelay) { - try { - channel.setOption(com.sun.nio.sctp.SctpStandardSocketOptions.SCTP_NODELAY, sctpNoDelay); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public int getSendBufferSize() { - try { - return channel.getOption(com.sun.nio.sctp.SctpStandardSocketOptions.SO_SNDBUF); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public void setSendBufferSize(int sendBufferSize) { - try { - channel.setOption(com.sun.nio.sctp.SctpStandardSocketOptions.SO_SNDBUF, sendBufferSize); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public int getReceiveBufferSize() { - try { - return channel.getOption(com.sun.nio.sctp.SctpStandardSocketOptions.SO_RCVBUF); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public void setReceiveBufferSize(int receiveBufferSize) { - try { - channel.setOption(com.sun.nio.sctp.SctpStandardSocketOptions.SO_RCVBUF, receiveBufferSize); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public InitMaxStreams getInitMaxStreams() { - try { - return channel.getOption(com.sun.nio.sctp.SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public void setInitMaxStreams(InitMaxStreams initMaxStreams) { - try { - channel.setOption(com.sun.nio.sctp.SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS, initMaxStreams); - } catch (IOException e) { - throw new ChannelException(e); - } - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java deleted file mode 100644 index 56cccf2645..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static com.sun.nio.sctp.SctpStandardSocketOptions.*; - -import io.netty.channel.ChannelException; -import io.netty.channel.DefaultServerChannelConfig; -import io.netty.util.internal.ConversionUtil; - -import java.io.IOException; - -/** - * The default {@link io.netty.channel.socket.ServerSocketChannelConfig} implementation for SCTP. - */ -public class DefaultSctpServerChannelConfig extends DefaultServerChannelConfig - implements SctpServerChannelConfig { - - private final com.sun.nio.sctp.SctpServerChannel serverChannel; - private volatile int backlog; - - /** - * Creates a new instance. - */ - public DefaultSctpServerChannelConfig(com.sun.nio.sctp.SctpServerChannel serverChannel) { - if (serverChannel == null) { - throw new NullPointerException("serverChannel"); - } - this.serverChannel = serverChannel; - } - - @Override - public boolean setOption(String key, Object value) { - if (super.setOption(key, value)) { - return true; - } - - if (key.equals("sctpInitMaxStreams")) { - final Integer maxInOutStreams = ConversionUtil.toInt(value); - setInitMaxStreams(InitMaxStreams.create(maxInOutStreams, maxInOutStreams)); - } else if (key.equals("backlog")) { - setBacklog(ConversionUtil.toInt(value)); - } else { - return false; - } - return true; - } - - @Override - public int getSendBufferSize() { - try { - return serverChannel.getOption(SO_SNDBUF); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public void setSendBufferSize(int sendBufferSize) { - try { - serverChannel.setOption(SO_SNDBUF, sendBufferSize); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public int getReceiveBufferSize() { - try { - return serverChannel.getOption(SO_RCVBUF); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public void setReceiveBufferSize(int receiveBufferSize) { - try { - serverChannel.setOption(SO_RCVBUF, receiveBufferSize); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public InitMaxStreams getInitMaxStreams() { - try { - return serverChannel.getOption(SCTP_INIT_MAXSTREAMS); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public void setInitMaxStreams(InitMaxStreams initMaxStreams) { - try { - serverChannel.setOption(SCTP_INIT_MAXSTREAMS, initMaxStreams); - } catch (IOException e) { - throw new ChannelException(e); - } - } - - @Override - public int getBacklog() { - return backlog; - } - - @Override - public void setBacklog(int backlog) { - if (backlog < 0) { - throw new IllegalArgumentException("backlog: " + backlog); - } - this.backlog = backlog; - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/NioSctpChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/NioSctpChannelConfig.java deleted file mode 100644 index dfa1be49c7..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/NioSctpChannelConfig.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import io.netty.channel.ReceiveBufferSizePredictor; -import io.netty.channel.ReceiveBufferSizePredictorFactory; -import io.netty.channel.socket.nio.NioChannelConfig; - -/** - * A {@link io.netty.channel.sctp.SctpChannelConfig} for a NIO SCTP/IP {@link io.netty.channel.sctp.SctpChannel}. - * - *

Available options

- * - * In addition to the options provided by {@link io.netty.channel.ChannelConfig} and - * {@link io.netty.channel.sctp.SctpChannelConfig}, {@link io.netty.channel.sctp.NioSctpChannelConfig} allows the - * following options in the option map: - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
NameAssociated setter method
{@code "writeBufferHighWaterMark"}{@link #setWriteBufferHighWaterMark(int)}
{@code "writeBufferLowWaterMark"}{@link #setWriteBufferLowWaterMark(int)}
{@code "writeSpinCount"}{@link #setWriteSpinCount(int)}
{@code "receiveBufferSizePredictor"}{@link #setReceiveBufferSizePredictor(io.netty.channel.ReceiveBufferSizePredictor)}
{@code "receiveBufferSizePredictorFactory"}{@link #setReceiveBufferSizePredictorFactory(io.netty.channel.ReceiveBufferSizePredictorFactory)}
- */ -public interface NioSctpChannelConfig extends SctpChannelConfig, NioChannelConfig { - - /** - * Sets the maximum loop count for a write operation until - * {@link java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer)} returns a non-zero value. - * It is similar to what a spin lock is used for in concurrency programming. - * It improves memory utilization and write throughput depending on - * the platform that JVM runs on. The default value is {@code 16}. - * - * @throws IllegalArgumentException - * if the specified value is {@code 0} or less than {@code 0} - */ - void setWriteSpinCount(int writeSpinCount); - - /** - * Returns the {@link io.netty.channel.ReceiveBufferSizePredictor} which predicts the - * number of readable bytes in the socket receive buffer. The default - * predictor is {@link io.netty.channel.AdaptiveReceiveBufferSizePredictor}(64, 1024, 65536). - */ - ReceiveBufferSizePredictor getReceiveBufferSizePredictor(); - - /** - * Sets the {@link io.netty.channel.ReceiveBufferSizePredictor} which predicts the - * number of readable bytes in the socket receive buffer. The default - * predictor is {@link io.netty.channel.AdaptiveReceiveBufferSizePredictor}(64, 1024, 65536). - */ - void setReceiveBufferSizePredictor(ReceiveBufferSizePredictor predictor); - - /** - * Returns the {@link io.netty.channel.ReceiveBufferSizePredictorFactory} which creates a new - * {@link io.netty.channel.ReceiveBufferSizePredictor} when a new channel is created and - * no {@link io.netty.channel.ReceiveBufferSizePredictor} was set. If no predictor was set - * for the channel, {@link #setReceiveBufferSizePredictor(io.netty.channel.ReceiveBufferSizePredictor)} - * will be called with the new predictor. The default factory is - * {@link io.netty.channel.AdaptiveReceiveBufferSizePredictorFactory}(64, 1024, 65536). - */ - ReceiveBufferSizePredictorFactory getReceiveBufferSizePredictorFactory(); - - /** - * Sets the {@link io.netty.channel.ReceiveBufferSizePredictor} which creates a new - * {@link io.netty.channel.ReceiveBufferSizePredictor} when a new channel is created and - * no {@link io.netty.channel.ReceiveBufferSizePredictor} was set. If no predictor was set - * for the channel, {@link #setReceiveBufferSizePredictor(io.netty.channel.ReceiveBufferSizePredictor)} - * will be called with the new predictor. The default factory is - * {@link io.netty.channel.AdaptiveReceiveBufferSizePredictorFactory}(64, 1024, 65536). - */ - void setReceiveBufferSizePredictorFactory( - ReceiveBufferSizePredictorFactory predictorFactory); -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpAcceptedChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpAcceptedChannel.java deleted file mode 100644 index 8e9bca344f..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpAcceptedChannel.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import com.sun.nio.sctp.SctpChannel; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; - -import static io.netty.channel.Channels.*; - -/** - */ -final class SctpAcceptedChannel extends SctpChannelImpl { - - SctpAcceptedChannel( - ChannelFactory factory, ChannelPipeline pipeline, - Channel parent, ChannelSink sink, - SctpChannel socket, SctpWorker worker) { - - super(parent, factory, pipeline, sink, socket, worker); - - setConnected(); - fireChannelOpen(this); - fireChannelBound(this, getLocalAddress()); - fireChannelConnected(this, getRemoteAddress()); - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpBindAddressEvent.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpBindAddressEvent.java deleted file mode 100644 index 40e71b2a4d..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpBindAddressEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelState; -import io.netty.channel.DownstreamChannelStateEvent; - -import java.net.InetAddress; - -public class SctpBindAddressEvent extends DownstreamChannelStateEvent { - - /** - * Creates a new instance. - */ - public SctpBindAddressEvent(Channel channel, ChannelFuture future, InetAddress localAddress) { - super(channel, future, ChannelState.INTEREST_OPS, localAddress); - } - - @Override - public InetAddress getValue() { - return (InetAddress) super.getValue(); - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannel.java deleted file mode 100644 index fd0d70c15b..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannel.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import com.sun.nio.sctp.Association; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.Set; - -/** - */ -public interface SctpChannel extends Channel { - - /** - * Return the primary local address of the SCTP channel. - */ - @Override - InetSocketAddress getLocalAddress(); - - /** - * Return all local addresses of the SCTP channel. - */ - Set getAllLocalAddresses(); - - /** - * Returns the configuration of this channel. - */ - @Override - NioSctpChannelConfig getConfig(); - - /** - * Return the primary remote address of the SCTP channel. - */ - @Override - InetSocketAddress getRemoteAddress(); - - - /** - * Return all remote addresses of the SCTP channel. - */ - Set getAllRemoteAddresses(); - - /** - * Bind a multi-homing address to the already bound channel - */ - ChannelFuture bindAddress(InetAddress localAddress); - - - /** - * Unbind a multi-homing address from a already established channel - */ - ChannelFuture unbindAddress(InetAddress localAddress); - - /** - * Get the underlying SCTP association - */ - Association association(); -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelConfig.java deleted file mode 100644 index 798285abcc..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelConfig.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static com.sun.nio.sctp.SctpStandardSocketOptions.*; -import io.netty.channel.ChannelConfig; - -/** - * A {@link io.netty.channel.ChannelConfig} for a {@link io.netty.channel.sctp.SctpChannel}. - *

- *

Available options

- *

- * In addition to the options provided by {@link io.netty.channel.ChannelConfig}, - * {@link io.netty.channel.sctp.SctpChannelConfig} allows the following options in the option map: - *

- * - * - * - * - * - * - * - * - * - * - * - * - *
NameAssociated setter method
{@code "sctpNoDelay"}{@link #setSctpNoDelay(boolean)}}
{@code "receiveBufferSize"}{@link #setReceiveBufferSize(int)}
{@code "sendBufferSize"}{@link #setSendBufferSize(int)}
{@code "sctpInitMaxStreams"}{@link #setInitMaxStreams(InitMaxStreams)}
- */ -public interface SctpChannelConfig extends ChannelConfig { - - /** - * Gets the {@code SCTP_NODELAY} option. - */ - boolean isSctpNoDelay(); - - /** - * Sets the {@code SCTP_NODELAY} option. - */ - void setSctpNoDelay(boolean sctpNoDelay); - - /** - * Gets the {@code SO_SNDBUF} option. - */ - int getSendBufferSize(); - - /** - * Sets the {@code SO_SNDBUF} option. - */ - void setSendBufferSize(int sendBufferSize); - - /** - * Gets the {@code SO_RCVBUF} option. - */ - int getReceiveBufferSize(); - - /** - * Gets the {@code SO_RCVBUF} option. - */ - void setReceiveBufferSize(int receiveBufferSize); - - /** - * Gets the {@code SCTP_INIT_MAXSTREAMS} option. - */ - InitMaxStreams getInitMaxStreams(); - - /** - * Gets the {@code SCTP_INIT_MAXSTREAMS} option. - */ - void setInitMaxStreams(InitMaxStreams initMaxStreams); -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelImpl.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelImpl.java deleted file mode 100644 index 1faa593c3c..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelImpl.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static io.netty.channel.Channels.future; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.channel.MessageEvent; -import io.netty.channel.sctp.SctpSendBufferPool.SctpSendBuffer; -import io.netty.channel.socket.nio.AbstractNioChannel; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.Collections; -import java.util.HashSet; -import java.util.Queue; -import java.util.Set; - -import com.sun.nio.sctp.Association; - -/** - */ -class SctpChannelImpl extends AbstractNioChannel implements SctpChannel { - - private static final int ST_OPEN = 0; - private static final int ST_BOUND = 1; - private static final int ST_CONNECTED = 2; - private static final int ST_CLOSED = -1; - volatile int state = ST_OPEN; - - private final NioSctpChannelConfig config; - - final SctpNotificationHandler notificationHandler = new SctpNotificationHandler(this); - - public SctpChannelImpl(Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, - com.sun.nio.sctp.SctpChannel channel, SctpWorker worker) { - super(parent, factory, pipeline, sink, worker, new SctpJdkChannel(channel)); - - config = new DefaultNioSctpChannelConfig(channel); - - getCloseFuture().addListener(new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) throws Exception { - state = ST_CLOSED; - } - }); - } - - Queue getWriteBufferQueue() { - return writeBufferQueue; - } - - Object getWriteLock() { - return writeLock; - } - - Object getInterestedOpsLock() { - return interestOpsLock; - } - - - void setWriteSuspended(boolean writeSuspended) { - this.writeSuspended = writeSuspended; - } - - boolean getWriteSuspended() { - return writeSuspended; - } - - void setInWriteNowLoop(boolean inWriteNowLoop) { - this.inWriteNowLoop = inWriteNowLoop; - } - - MessageEvent getCurrentWriteEvent() { - return currentWriteEvent; - } - - void setCurrentWriteEvent(MessageEvent currentWriteEvent) { - this.currentWriteEvent = currentWriteEvent; - } - - int getRawInterestOps() { - return super.getInterestOps(); - } - - void setRawInterestOpsNow(int interestOps) { - super.setInterestOpsNow(interestOps); - } - - SctpSendBuffer getCurrentWriteBuffer() { - return (SctpSendBuffer) currentWriteBuffer; - } - - void setCurrentWriteBuffer(SctpSendBuffer currentWriteBuffer) { - this.currentWriteBuffer = currentWriteBuffer; - } - - @Override - public SctpWorker getWorker() { - return (SctpWorker) super.getWorker(); - } - - - @Override - public NioSctpChannelConfig getConfig() { - return config; - } - - @Override - public SctpJdkChannel getJdkChannel() { - return (SctpJdkChannel) super.getJdkChannel(); - } - - - @Override - public Set getAllLocalAddresses() { - try { - final Set allLocalAddresses = getJdkChannel().getChannel().getAllLocalAddresses(); - final Set addresses = new HashSet(allLocalAddresses.size()); - for (SocketAddress socketAddress: allLocalAddresses) { - addresses.add((InetSocketAddress) socketAddress); - } - return addresses; - } catch (Throwable t) { - return Collections.emptySet(); - } - } - - @Override - public Set getAllRemoteAddresses() { - try { - final Set allLocalAddresses = getJdkChannel().getChannel().getRemoteAddresses(); - final Set addresses = new HashSet(allLocalAddresses.size()); - for (SocketAddress socketAddress: allLocalAddresses) { - addresses.add((InetSocketAddress) socketAddress); - } - return addresses; - } catch (Throwable t) { - return Collections.emptySet(); - } - } - - @Override - public ChannelFuture bindAddress(InetAddress localAddress) { - ChannelFuture future = future(this); - pipeline().sendDownstream(new SctpBindAddressEvent(this, future, localAddress)); - return future; - } - - @Override - public ChannelFuture unbindAddress(InetAddress localAddress) { - ChannelFuture future = future(this); - pipeline().sendDownstream(new SctpUnbindAddressEvent(this, future, localAddress)); - return future; - } - - @Override - public Association association() { - try { - return getJdkChannel().getChannel().association(); - } catch (Throwable e) { - return null; - } - } - - @Override - public boolean isOpen() { - return state >= ST_OPEN; - } - - @Override - public boolean isBound() { - return state >= ST_BOUND; - } - - @Override - public boolean isConnected() { - return state == ST_CONNECTED; - } - - final void setBound() { - assert state == ST_OPEN : "Invalid state: " + state; - state = ST_BOUND; - } - - protected final void setConnected() { - if (state != ST_CLOSED) { - state = ST_CONNECTED; - } - } - - @Override - protected boolean setClosed() { - return super.setClosed(); - } - - @Override - protected WriteRequestQueue createRequestQueue() { - return new WriteRequestQueue() { - - @Override - protected int getMessageSize(MessageEvent e) { - Object m = e.getMessage(); - if (m instanceof SctpFrame) { - return ((SctpFrame) m).getPayloadBuffer().readableBytes(); - } - return 0; - } - }; - } - -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientChannel.java deleted file mode 100644 index 4f12cf512a..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientChannel.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static io.netty.channel.Channels.*; - -import java.io.IOException; - -import com.sun.nio.sctp.SctpChannel; - -import io.netty.channel.ChannelException; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; - -/** - */ -final class SctpClientChannel extends SctpChannelImpl { - - private static final InternalLogger logger = - InternalLoggerFactory.getInstance(SctpClientChannel.class); - - private static SctpChannel newChannael() { - SctpChannel underlayingChannel; - try { - underlayingChannel = SctpChannel.open(); - } catch (IOException e) { - throw new ChannelException("Failed to open a sctp channel.", e); - } - - boolean success = false; - try { - underlayingChannel.configureBlocking(false); - success = true; - } catch (IOException e) { - throw new ChannelException("Failed to enter non-blocking mode.", e); - } finally { - if (!success) { - try { - underlayingChannel.close(); - } catch (IOException e) { - if (logger.isWarnEnabled()) { - logger.warn( - "Failed to close a partially initialized socket.", - e); - } - } - } - } - - return underlayingChannel; - } - - volatile ChannelFuture connectFuture; - volatile boolean boundManually; - - // Does not need to be volatile as it's accessed by only one thread. - long connectDeadlineNanos; - - SctpClientChannel( - ChannelFactory factory, ChannelPipeline pipeline, - ChannelSink sink, SctpWorker worker) { - - super(null, factory, pipeline, sink, newChannael(), worker); - fireChannelOpen(this); - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientPipelineSink.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientPipelineSink.java deleted file mode 100644 index b2ea0b4ac0..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientPipelineSink.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static io.netty.channel.Channels.fireChannelBound; -import static io.netty.channel.Channels.fireExceptionCaught; -import static io.netty.channel.Channels.succeededFuture; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelState; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.MessageEvent; -import io.netty.channel.socket.nio.AbstractNioChannelSink; - -import java.net.InetAddress; -import java.net.SocketAddress; -import java.nio.channels.ClosedChannelException; - -/** - */ -class SctpClientPipelineSink extends AbstractNioChannelSink { - - @Override - public void eventSunk( - ChannelPipeline pipeline, ChannelEvent e) throws Exception { - if (e instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) e; - SctpClientChannel channel = - (SctpClientChannel) event.channel(); - ChannelFuture future = event.getFuture(); - ChannelState state = event.getState(); - Object value = event.getValue(); - - switch (state) { - case OPEN: - if (Boolean.FALSE.equals(value)) { - channel.getWorker().close(channel, future); - } - break; - case BOUND: - if (value != null) { - bind(channel, future, (SocketAddress) value); - } else { - channel.getWorker().close(channel, future); - } - break; - case CONNECTED: - if (value != null) { - connect(channel, future, (SocketAddress) value); - } else { - channel.getWorker().close(channel, future); - } - break; - case INTEREST_OPS: - if (event instanceof SctpBindAddressEvent) { - SctpBindAddressEvent bindAddressEvent = (SctpBindAddressEvent) event; - bindAddress(channel, bindAddressEvent.getFuture(), bindAddressEvent.getValue()); - } else if (event instanceof SctpUnbindAddressEvent) { - SctpUnbindAddressEvent unbindAddressEvent = (SctpUnbindAddressEvent) event; - unbindAddress(channel, unbindAddressEvent.getFuture(), unbindAddressEvent.getValue()); - } else { - channel.getWorker().setInterestOps(channel, future, ((Integer) value).intValue()); - } - break; - } - } else if (e instanceof MessageEvent) { - MessageEvent event = (MessageEvent) e; - SctpChannelImpl channel = (SctpChannelImpl) event.channel(); - boolean offered = channel.getWriteBufferQueue().offer(event); - assert offered; - channel.getWorker().writeFromUserCode(channel); - } - } - - private void bind( - SctpClientChannel channel, ChannelFuture future, - SocketAddress localAddress) { - try { - channel.getJdkChannel().bind(localAddress); - channel.boundManually = true; - channel.setBound(); - future.setSuccess(); - fireChannelBound(channel, channel.getLocalAddress()); - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - - private void bindAddress( - SctpClientChannel channel, ChannelFuture future, - InetAddress localAddress) { - try { - channel.getJdkChannel().getChannel().bindAddress(localAddress); - future.setSuccess(); - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - - private void unbindAddress( - SctpClientChannel channel, ChannelFuture future, - InetAddress localAddress) { - try { - channel.getJdkChannel().getChannel().unbindAddress(localAddress); - future.setSuccess(); - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - - - - private void connect( - final SctpClientChannel channel, final ChannelFuture cf, - SocketAddress remoteAddress) { - try { - channel.getJdkChannel().connect(remoteAddress); - - channel.getCloseFuture().addListener(new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture f) - throws Exception { - if (!cf.isDone()) { - cf.setFailure(new ClosedChannelException()); - } - } - }); - cf.addListener(ChannelFutureListener.CLOSE_ON_FAILURE); - channel.connectFuture = cf; - channel.getWorker().registerWithWorker(channel, cf); - - - } catch (Throwable t) { - cf.setFailure(t); - fireExceptionCaught(channel, t); - channel.getWorker().close(channel, succeededFuture(channel)); - } - } - - -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientSocketChannelFactory.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientSocketChannelFactory.java deleted file mode 100644 index 9fe1b23a3f..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpClientSocketChannelFactory.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.channel.socket.nio.SelectorUtil; -import io.netty.channel.socket.nio.WorkerPool; -import io.netty.util.ExternalResourceReleasable; - -import java.util.concurrent.Executor; - -/** - * A {@link io.netty.channel.socket.ClientSocketChannelFactory} which creates a client-side NIO-based - * {@link io.netty.channel.socket.SocketChannel}. It utilizes the non-blocking I/O mode which was - * introduced with NIO to serve many number of concurrent connections - * efficiently. - * - *

How threads work

- *

- * There are two types of threads in a {@link SctpClientSocketChannelFactory}; - * one is boss thread and the other is worker thread. - * - *

Boss thread

- *

- * One {@link SctpClientSocketChannelFactory} has one boss thread. It makes - * a connection attempt on request. Once a connection attempt succeeds, - * the boss thread passes the connected {@link io.netty.channel.Channel} to one of the worker - * threads that the {@link SctpClientSocketChannelFactory} manages. - * - *

Worker threads

- *

- * One {@link SctpClientSocketChannelFactory} can have one or more worker - * threads. A worker thread performs non-blocking read and write for one or - * more {@link io.netty.channel.Channel}s in a non-blocking mode. - * - *

Life cycle of threads and graceful shutdown

- *

- * All threads are acquired from the {@link java.util.concurrent.Executor}s which were specified - * when a {@link SctpClientSocketChannelFactory} was created. A boss thread is - * acquired from the {@code bossExecutor}, and worker threads are acquired from - * the {@code workerExecutor}. Therefore, you should make sure the specified - * {@link java.util.concurrent.Executor}s are able to lend the sufficient number of threads. - * It is the best bet to specify {@linkplain java.util.concurrent.Executors#newCachedThreadPool() a cached thread pool}. - *

- * Both boss and worker threads are acquired lazily, and then released when - * there's nothing left to process. All the related resources such as - * {@link java.nio.channels.Selector} are also released when the boss and worker threads are - * released. Therefore, to shut down a service gracefully, you should do the - * following: - * - *

    - *
  1. close all channels created by the factory usually using - * {@link io.netty.channel.group.ChannelGroup#close()}, and
  2. - *
  3. call {@link #releaseExternalResources()}.
  4. - *
- * - * Please make sure not to shut down the executor until all channels are - * closed. Otherwise, you will end up with a {@link java.util.concurrent.RejectedExecutionException} - * and the related resources might not be released properly. - * - * @apiviz.landmark - */ -public class SctpClientSocketChannelFactory implements ChannelFactory { - - private final WorkerPool workerPool; - private final ChannelSink sink; - - /** - * Creates a new instance. Calling this constructor is same with calling - * {@link #SctpClientSocketChannelFactory(java.util.concurrent.Executor, java.util.concurrent.Executor, int)} with 2 * - * the number of available processors in the machine. The number of - * available processors is obtained by {@link Runtime#availableProcessors()}. - * - * @param workerExecutor - * the {@link java.util.concurrent.Executor} which will execute the I/O worker threads - */ - public SctpClientSocketChannelFactory(Executor workerExecutor) { - this(workerExecutor, SelectorUtil.DEFAULT_IO_THREADS); - } - - /** - * Creates a new instance. - * - * @param workerExecutor - * the {@link java.util.concurrent.Executor} which will execute the I/O worker threads - * @param workerCount - * the maximum number of I/O worker threads - */ - public SctpClientSocketChannelFactory(Executor workerExecutor, - int workerCount) { - this(new SctpWorkerPool(workerExecutor, workerCount, true)); - } - - public SctpClientSocketChannelFactory(WorkerPool workerPool) { - if (workerPool == null) { - throw new NullPointerException("workerPool"); - } - - this.workerPool = workerPool; - sink = new SctpClientPipelineSink(); - } - - @Override - public SctpChannel newChannel(ChannelPipeline pipeline) { - return new SctpClientChannel(this, pipeline, sink, workerPool.nextWorker()); - } - - @Override - public void releaseExternalResources() { - if (workerPool instanceof ExternalResourceReleasable) { - ((ExternalResourceReleasable) workerPool).releaseExternalResources(); - } - - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpFrame.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpFrame.java deleted file mode 100644 index 3a12600f4c..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpFrame.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import com.sun.nio.sctp.MessageInfo; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; - -/** - */ -public final class SctpFrame { - private final int streamIdentifier; - private final int protocolIdentifier; - - private final ChannelBuffer payloadBuffer; - - private MessageInfo msgInfo; - - /** - * Essential data that is being carried within SCTP Data Chunk - * @param protocolIdentifier of payload - * @param streamIdentifier that you want to send the payload - * @param payloadBuffer channel buffer - */ - public SctpFrame(int protocolIdentifier, int streamIdentifier, ChannelBuffer payloadBuffer) { - this.protocolIdentifier = protocolIdentifier; - this.streamIdentifier = streamIdentifier; - this.payloadBuffer = payloadBuffer; - } - - public SctpFrame(MessageInfo msgInfo, ChannelBuffer payloadBuffer) { - this.msgInfo = msgInfo; - this.streamIdentifier = msgInfo.streamNumber(); - this.protocolIdentifier = msgInfo.payloadProtocolID(); - this.payloadBuffer = payloadBuffer; - } - - public int getStreamIdentifier() { - return streamIdentifier; - } - - public int getProtocolIdentifier() { - return protocolIdentifier; - } - - public ChannelBuffer getPayloadBuffer() { - if (payloadBuffer.readable()) { - return payloadBuffer.slice(); - } else { - return ChannelBuffers.EMPTY_BUFFER; - } - } - - public MessageInfo getMessageInfo() { - return msgInfo; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - SctpFrame sctpFrame = (SctpFrame) o; - - if (protocolIdentifier != sctpFrame.protocolIdentifier) { - return false; - } - - if (streamIdentifier != sctpFrame.streamIdentifier) { - return false; - } - - if (!payloadBuffer.equals(sctpFrame.payloadBuffer)) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = streamIdentifier; - result = 31 * result + protocolIdentifier; - result = 31 * result + payloadBuffer.hashCode(); - return result; - } - - @Override - public String toString() { - return new StringBuilder(). - append("SctpFrame{"). - append("streamIdentifier="). - append(streamIdentifier). - append(", protocolIdentifier="). - append(protocolIdentifier). - append(", payloadBuffer="). - append(ChannelBuffers.hexDump(getPayloadBuffer())). - append('}').toString(); - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpJdkChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpJdkChannel.java deleted file mode 100644 index 3ab9b80c6e..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpJdkChannel.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel.sctp; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.ByteBuffer; - -import com.sun.nio.sctp.SctpChannel; - -import io.netty.channel.socket.nio.AbstractJdkChannel; - -public class SctpJdkChannel extends AbstractJdkChannel { - - SctpJdkChannel(SctpChannel channel) { - super(channel); - } - - @Override - protected SctpChannel getChannel() { - return (SctpChannel) super.getChannel(); - } - - @Override - public InetSocketAddress getRemoteSocketAddress() { - try { - for (SocketAddress address : getChannel().getRemoteAddresses()) { - return (InetSocketAddress) address; - } - } catch (IOException e) { - // ignore - } - return null; - } - - @Override - public SocketAddress getLocalSocketAddress() { - try { - for (SocketAddress address : getChannel().getAllLocalAddresses()) { - return (InetSocketAddress) address; - } - } catch (IOException e) { - // ignore - } - return null; - } - - @Override - public boolean isConnected() { - return getChannel().isOpen(); - } - - @Override - public boolean isSocketBound() { - try { - return !getChannel().getAllLocalAddresses().isEmpty(); - } catch (IOException e) { - return false; - } - } - - @Override - public void disconnectSocket() throws IOException { - closeSocket(); - } - - @Override - public void closeSocket() throws IOException { - for (SocketAddress address: getChannel().getAllLocalAddresses()) { - getChannel().unbindAddress(((InetSocketAddress) address).getAddress()); - } - } - - @Override - public void bind(SocketAddress local) throws IOException { - getChannel().bind(local); - } - - @Override - public void connect(SocketAddress remote) throws IOException { - getChannel().connect(remote); - } - - @Override - public int write(ByteBuffer src) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public boolean finishConnect() throws IOException { - return getChannel().finishConnect(); - } - -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationEvent.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationEvent.java deleted file mode 100644 index 0e209f0430..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationEvent.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import com.sun.nio.sctp.Notification; -import io.netty.channel.Channel; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelFuture; -import io.netty.channel.Channels; - -/** - */ -public class SctpNotificationEvent implements ChannelEvent { - private Channel channel; - private Notification notification; - private Object value; - - public SctpNotificationEvent(Channel channel, Notification notification, Object value) { - if (channel == null) { - throw new NullPointerException("channel"); - } - if (notification == null) { - throw new NullPointerException("notification"); - } - - this.channel = channel; - this.notification = notification; - this.value = value; - } - - @Override - public Channel getChannel() { - return channel; - } - - @Override - public ChannelFuture getFuture() { - return Channels.succeededFuture(channel); - } - - public Notification getNotification() { - return notification; - } - - /** - * Return the attachment comes with SCTP notification - * Please note that, it may be null - */ - public Object getValue() { - return value; - } - - @Override - public String toString() { - return "SctpNotificationEvent{" + - "channel=" + channel + - ", notification=" + notification + - ", value=" + value + - '}'; - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationHandler.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationHandler.java deleted file mode 100644 index 1d0edf440f..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; - -import com.sun.nio.sctp.AbstractNotificationHandler; -import com.sun.nio.sctp.AssociationChangeNotification; -import com.sun.nio.sctp.HandlerResult; -import com.sun.nio.sctp.Notification; -import com.sun.nio.sctp.PeerAddressChangeNotification; -import com.sun.nio.sctp.SendFailedNotification; -import com.sun.nio.sctp.ShutdownNotification; - -/** - */ - -class SctpNotificationHandler extends AbstractNotificationHandler { - - private final SctpChannelImpl sctpChannel; - private final ChannelPipeline pipeline; - - SctpNotificationHandler(SctpChannelImpl sctpChannel) { - this.sctpChannel = sctpChannel; - pipeline = sctpChannel.pipeline(); - } - - @Override - public HandlerResult handleNotification(AssociationChangeNotification notification, Object o) { - fireNotificationReceived(notification, o); - return HandlerResult.CONTINUE; - } - - @Override - public HandlerResult handleNotification(PeerAddressChangeNotification notification, Object o) { - fireNotificationReceived(notification, o); - return HandlerResult.CONTINUE; - } - - @Override - public HandlerResult handleNotification(SendFailedNotification notification, Object o) { - fireNotificationReceived(notification, o); - return HandlerResult.CONTINUE; - } - - @Override - public HandlerResult handleNotification(ShutdownNotification notification, Object o) { - sctpChannel.getWorker().close(sctpChannel, Channels.succeededFuture(sctpChannel)); - return HandlerResult.RETURN; - } - - private void fireNotificationReceived(Notification notification, Object o) { - pipeline.sendUpstream(new SctpNotificationEvent(sctpChannel, notification, o)); - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpSendBufferPool.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpSendBufferPool.java deleted file mode 100644 index b3bbb7b95e..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpSendBufferPool.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import com.sun.nio.sctp.MessageInfo; -import com.sun.nio.sctp.SctpChannel; -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.socket.nio.SendBufferPool; - -import java.io.IOException; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.DatagramChannel; -import java.nio.channels.WritableByteChannel; - -final class SctpSendBufferPool extends SendBufferPool { - - private static final SctpSendBuffer EMPTY_BUFFER = new EmptySendBuffer(); - - - @Override - public SctpSendBuffer acquire(Object message) { - if (message instanceof SctpFrame) { - return acquire((SctpFrame) message); - } else { - throw new IllegalArgumentException( - "unsupported message type: " + message.getClass() + " required: io.netty.channel.sctp.SctpFrame"); - } - } - - private SctpSendBuffer acquire(SctpFrame message) { - final ChannelBuffer src = message.getPayloadBuffer(); - final int streamNo = message.getStreamIdentifier(); - final int protocolId = message.getProtocolIdentifier(); - - final int size = src.readableBytes(); - if (size == 0) { - return EMPTY_BUFFER; - } - - if (src.isDirect()) { - return new SctpUnpooledSendBuffer(streamNo, protocolId, src.toByteBuffer()); - } - if (src.readableBytes() > DEFAULT_PREALLOCATION_SIZE) { - return new SctpUnpooledSendBuffer(streamNo, protocolId, src.toByteBuffer()); - } - - Preallocation current = this.current; - ByteBuffer buffer = current.buffer; - int remaining = buffer.remaining(); - SctpPooledSendBuffer dst; - - if (size < remaining) { - int nextPos = buffer.position() + size; - ByteBuffer slice = buffer.duplicate(); - buffer.position(align(nextPos)); - slice.limit(nextPos); - current.refCnt++; - dst = new SctpPooledSendBuffer(streamNo, protocolId, current, slice); - } else if (size > remaining) { - this.current = current = getPreallocation(); - buffer = current.buffer; - ByteBuffer slice = buffer.duplicate(); - buffer.position(align(size)); - slice.limit(size); - current.refCnt++; - dst = new SctpPooledSendBuffer(streamNo, protocolId, current, slice); - } else { // size == remaining - current.refCnt++; - this.current = getPreallocation0(); - dst = new SctpPooledSendBuffer(streamNo, protocolId, current, current.buffer); - } - - ByteBuffer dstbuf = dst.buffer; - dstbuf.mark(); - src.getBytes(src.readerIndex(), dstbuf); - dstbuf.reset(); - return dst; - } - - - interface SctpSendBuffer extends SendBuffer { - - long transferTo(SctpChannel ch) throws IOException; - - } - - class SctpUnpooledSendBuffer extends UnpooledSendBuffer implements SctpSendBuffer { - - final int streamNo; - final int protocolId; - - SctpUnpooledSendBuffer(int streamNo, int protocolId, ByteBuffer buffer) { - super(buffer); - this.streamNo = streamNo; - this.protocolId = protocolId; - } - - @Override - public long transferTo(SctpChannel ch) throws IOException { - final MessageInfo messageInfo = MessageInfo.createOutgoing(ch.association(), null, streamNo); - messageInfo.payloadProtocolID(protocolId); - messageInfo.streamNumber(streamNo); - return ch.send(buffer, messageInfo); - } - } - - final class SctpPooledSendBuffer extends PooledSendBuffer implements SctpSendBuffer { - - final int streamNo; - final int protocolId; - - SctpPooledSendBuffer(int streamNo, int protocolId, Preallocation parent, ByteBuffer buffer) { - super(parent, buffer); - this.streamNo = streamNo; - this.protocolId = protocolId; - } - - @Override - public long transferTo(SctpChannel ch) throws IOException { - final MessageInfo messageInfo = MessageInfo.createOutgoing(ch.association(), null, streamNo); - messageInfo.payloadProtocolID(protocolId); - messageInfo.streamNumber(streamNo); - return ch.send(buffer, messageInfo); - } - } - - static final class EmptySendBuffer implements SctpSendBuffer { - - EmptySendBuffer() { - super(); - } - - @Override - public boolean finished() { - return true; - } - - @Override - public long writtenBytes() { - return 0; - } - - @Override - public long totalBytes() { - return 0; - } - - @Override - public long transferTo(SctpChannel ch) throws IOException { - return 0; - } - - @Override - public long transferTo(WritableByteChannel ch) throws IOException { - return 0; - } - - @Override - public long transferTo(DatagramChannel ch, SocketAddress raddr) throws IOException { - return 0; - } - @Override - public void release() { - // Unpooled. - } - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannel.java deleted file mode 100644 index 3257f080d6..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannel.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import io.netty.channel.ChannelFuture; -import io.netty.channel.ServerChannel; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.Set; - -/** - * A SCTP {@link io.netty.channel.ServerChannel} which accepts incoming SCTP connections. - */ -public interface SctpServerChannel extends ServerChannel { - /** - * Bind a multi-homing address to the already bound channel - */ - ChannelFuture bindAddress(InetAddress localAddress); - - - /** - * Unbind a multi-homing address from a already established channel - */ - ChannelFuture unbindAddress(InetAddress localAddress); - - /** - * Returns the configuration of this channel. - */ - @Override - SctpServerChannelConfig getConfig(); - - /** - * Return the primary local address of the SCTP server channel. - */ - @Override - InetSocketAddress getLocalAddress(); - - /** - * Return all local addresses of the SCTP server channel. - */ - Set getAllLocalAddresses(); - - /** - * Return the primary remote address of the server SCTP channel. - */ - @Override - InetSocketAddress getRemoteAddress(); - - - /** - * Return all remote addresses of the SCTP server channel. - */ - Set getAllRemoteAddresses(); -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannelConfig.java deleted file mode 100644 index 82732220a5..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannelConfig.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static com.sun.nio.sctp.SctpStandardSocketOptions.*; - -import io.netty.channel.ChannelConfig; - -/** - * A {@link io.netty.channel.ChannelConfig} for a {@link SctpServerChannelConfig}. - *

- *

Available options

- *

- * In addition to the options provided by {@link io.netty.channel.ChannelConfig}, - * {@link SctpServerChannelConfig} allows the following options in the - * option map: - *

- * - * - * - * - * - * - * * - * - * - * - * - * - *
NameAssociated setter method
{@code "backlog"}{@link #setBacklog(int)}
{@code "receiveBufferSize"}{@link #setReceiveBufferSize(int)}
{@code "sendBufferSize"}{@link #setSendBufferSize(int)}
{@code "sctpInitMaxStreams"}{@link #setInitMaxStreams(InitMaxStreams)} (int)}}
- */ -public interface SctpServerChannelConfig extends ChannelConfig { - - /** - * Gets the backlog value to specify when the channel binds to a local - * address. - */ - int getBacklog(); - - /** - * Sets the backlog value to specify when the channel binds to a local - * address. - */ - void setBacklog(int backlog); - - - /** - * Gets the {@code SO_SNDBUF} option. - */ - int getSendBufferSize(); - - /** - * Sets the {@code SO_SNDBUF} option. - */ - void setSendBufferSize(int sendBufferSize); - - /** - * Gets the {@code SO_RCVBUF} option. - */ - int getReceiveBufferSize(); - - /** - * Gets the {@code SO_RCVBUF} option. - */ - void setReceiveBufferSize(int receiveBufferSize); - - - /** - * Gets the {@code SCTP_INIT_MAXSTREAMS} option. - */ - InitMaxStreams getInitMaxStreams(); - - /** - * Gets the {@code SCTP_INIT_MAXSTREAMS} option. - */ - void setInitMaxStreams(InitMaxStreams initMaxStreams); -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannelImpl.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannelImpl.java deleted file mode 100644 index 7e540e3111..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerChannelImpl.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static io.netty.channel.Channels.*; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import io.netty.channel.AbstractServerChannel; -import io.netty.channel.ChannelException; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.channel.socket.nio.NioChannel; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; - -/** - */ -class SctpServerChannelImpl extends AbstractServerChannel - implements SctpServerChannel, NioChannel { - - private static final InternalLogger logger = - InternalLoggerFactory.getInstance(SctpServerChannelImpl.class); - - final com.sun.nio.sctp.SctpServerChannel serverChannel; - final Lock shutdownLock = new ReentrantLock(); - private final SctpServerChannelConfig config; - - private volatile boolean bound; - - private SctpWorker worker; - - SctpServerChannelImpl( - ChannelFactory factory, - ChannelPipeline pipeline, - ChannelSink sink, SctpWorker worker) { - - super(factory, pipeline, sink); - this.worker = worker; - try { - serverChannel = com.sun.nio.sctp.SctpServerChannel.open(); - } catch (IOException e) { - throw new ChannelException( - "Failed to open a server sctp channel.", e); - } - - try { - serverChannel.configureBlocking(false); - } catch (IOException e) { - try { - serverChannel.close(); - } catch (IOException e2) { - if (logger.isWarnEnabled()) { - logger.warn( - "Failed to close a partially initialized socket.", e2); - } - } - - throw new ChannelException("Failed to enter non-blocking mode.", e); - } - - config = new DefaultSctpServerChannelConfig(serverChannel); - - fireChannelOpen(this); - } - - @Override - public ChannelFuture bindAddress(InetAddress localAddress) { - ChannelFuture future = future(this); - pipeline().sendDownstream(new SctpBindAddressEvent(this, future, localAddress)); - return future; - } - - @Override - public ChannelFuture unbindAddress(InetAddress localAddress) { - ChannelFuture future = future(this); - pipeline().sendDownstream(new SctpUnbindAddressEvent(this, future, localAddress)); - return future; - } - - @Override - public SctpServerChannelConfig getConfig() { - return config; - } - - @Override - public InetSocketAddress getLocalAddress() { - try { - final Iterator iterator = serverChannel.getAllLocalAddresses().iterator(); - return iterator.hasNext() ? (InetSocketAddress) iterator.next() : null; - } catch (IOException e) { - return null; - } - } - - @Override - public Set getAllLocalAddresses() { - try { - final Set allLocalAddresses = serverChannel.getAllLocalAddresses(); - final Set addresses = new HashSet(allLocalAddresses.size()); - for (SocketAddress socketAddress : allLocalAddresses) { - addresses.add((InetSocketAddress) socketAddress); - } - return addresses; - } catch (Throwable t) { - return Collections.emptySet(); - } - } - - @Override - public InetSocketAddress getRemoteAddress() { - return null; // not available for server channel - } - - @Override - public Set getAllRemoteAddresses() { - return null; // not available for server channel - } - - @Override - public boolean isBound() { - return isOpen() && bound; - } - - public void setBound() { - bound = true; - } - - @Override - protected boolean setClosed() { - return super.setClosed(); - } - - @Override - public SctpWorker getWorker() { - return worker; - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerPipelineSink.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerPipelineSink.java deleted file mode 100644 index ee23fda4bf..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerPipelineSink.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static io.netty.channel.Channels.fireChannelBound; -import static io.netty.channel.Channels.fireExceptionCaught; -import io.netty.channel.Channel; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelState; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.MessageEvent; -import io.netty.channel.socket.nio.AbstractNioChannelSink; -import io.netty.channel.socket.nio.WorkerPool; - -import java.net.InetAddress; -import java.net.SocketAddress; - -/** - */ -class SctpServerPipelineSink extends AbstractNioChannelSink { - - private final WorkerPool workerPool; - - SctpServerPipelineSink(WorkerPool workerPool) { - this.workerPool = workerPool; - } - - @Override - public void eventSunk( - ChannelPipeline pipeline, ChannelEvent e) throws Exception { - Channel channel = e.getChannel(); - if (channel instanceof SctpServerChannelImpl) { - handleServerSocket(e); - } else if (channel instanceof SctpChannelImpl) { - handleAcceptedSocket(e); - } - } - - private void handleServerSocket(ChannelEvent e) { - if (!(e instanceof ChannelStateEvent)) { - return; - } - - ChannelStateEvent event = (ChannelStateEvent) e; - SctpServerChannelImpl channel = - (SctpServerChannelImpl) event.channel(); - ChannelFuture future = event.getFuture(); - ChannelState state = event.getState(); - Object value = event.getValue(); - - switch (state) { - case OPEN: - if (Boolean.FALSE.equals(value)) { - channel.getWorker().close(channel, future); - } - break; - case BOUND: - if (value != null) { - bind(channel, future, (SocketAddress) value); - } else { - channel.getWorker().close(channel, future); - } - case INTEREST_OPS: - if (event instanceof SctpBindAddressEvent) { - SctpBindAddressEvent bindAddressEvent = (SctpBindAddressEvent) event; - bindAddress(channel, bindAddressEvent.getFuture(), bindAddressEvent.getValue()); - } - - if (event instanceof SctpUnbindAddressEvent) { - SctpUnbindAddressEvent unbindAddressEvent = (SctpUnbindAddressEvent) event; - unbindAddress(channel, unbindAddressEvent.getFuture(), unbindAddressEvent.getValue()); - } - break; - } - } - - private void handleAcceptedSocket(ChannelEvent e) { - if (e instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) e; - SctpChannelImpl channel = (SctpChannelImpl) event.channel(); - ChannelFuture future = event.getFuture(); - ChannelState state = event.getState(); - Object value = event.getValue(); - - switch (state) { - case OPEN: - if (Boolean.FALSE.equals(value)) { - channel.getWorker().close(channel, future); - } - break; - case BOUND: - case CONNECTED: - if (value == null) { - channel.getWorker().close(channel, future); - } - break; - case INTEREST_OPS: - channel.getWorker().setInterestOps(channel, future, (Integer) value); - break; - } - } else if (e instanceof MessageEvent) { - MessageEvent event = (MessageEvent) e; - SctpChannelImpl channel = (SctpChannelImpl) event.channel(); - boolean offered = channel.getWriteBufferQueue().offer(event); - assert offered; - channel.getWorker().writeFromUserCode(channel); - } - } - - private void bind( - SctpServerChannelImpl channel, ChannelFuture future, - SocketAddress localAddress) { - boolean bound = false; - try { - channel.serverChannel.bind(localAddress, channel.getConfig().getBacklog()); - bound = true; - - future.setSuccess(); - fireChannelBound(channel, channel.getLocalAddress()); - - workerPool.nextWorker().registerWithWorker(channel, future); - - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } finally { - if (!bound) { - channel.getWorker().close(channel, future); - } - } - } - - private void bindAddress( - SctpServerChannelImpl channel, ChannelFuture future, - InetAddress localAddress) { - try { - channel.serverChannel.bindAddress(localAddress); - future.setSuccess(); - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - - private void unbindAddress( - SctpServerChannelImpl channel, ChannelFuture future, - InetAddress localAddress) { - try { - channel.serverChannel.unbindAddress(localAddress); - future.setSuccess(); - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - - -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerSocketChannelFactory.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerSocketChannelFactory.java deleted file mode 100644 index c7a632db1c..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpServerSocketChannelFactory.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelSink; -import io.netty.channel.ServerChannelFactory; -import io.netty.channel.socket.nio.SelectorUtil; -import io.netty.channel.socket.nio.WorkerPool; -import io.netty.util.ExternalResourceReleasable; - -import java.util.concurrent.Executor; - -/** - * A {@link io.netty.channel.socket.ServerSocketChannelFactory} which creates a server-side NIO-based - * {@link io.netty.channel.socket.ServerSocketChannel}. It utilizes the non-blocking I/O mode which - * was introduced with NIO to serve many number of concurrent connections - * efficiently. - * - *

How threads work

- *

- * There are two types of threads in a {@link SctpServerSocketChannelFactory}; - * one is boss thread and the other is worker thread. - * - *

Boss threads

- *

- * Each bound {@link io.netty.channel.socket.ServerSocketChannel} has its own boss thread. - * For example, if you opened two server ports such as 80 and 443, you will - * have two boss threads. A boss thread accepts incoming connections until - * the port is unbound. Once a connection is accepted successfully, the boss - * thread passes the accepted {@link io.netty.channel.Channel} to one of the worker - * threads that the {@link SctpServerSocketChannelFactory} manages. - * - *

Worker threads

- *

- * One {@link SctpServerSocketChannelFactory} can have one or more worker - * threads. A worker thread performs non-blocking read and write for one or - * more {@link io.netty.channel.Channel}s in a non-blocking mode. - * - *

Life cycle of threads and graceful shutdown

- *

- * All threads are acquired from the {@link java.util.concurrent.Executor}s which were specified - * when a {@link SctpServerSocketChannelFactory} was created. Boss threads are - * acquired from the {@code bossExecutor}, and worker threads are acquired from - * the {@code workerExecutor}. Therefore, you should make sure the specified - * {@link java.util.concurrent.Executor}s are able to lend the sufficient number of threads. - * It is the best bet to specify {@linkplain java.util.concurrent.Executors#newCachedThreadPool() a cached thread pool}. - *

- * Both boss and worker threads are acquired lazily, and then released when - * there's nothing left to process. All the related resources such as - * {@link java.nio.channels.Selector} are also released when the boss and worker threads are - * released. Therefore, to shut down a service gracefully, you should do the - * following: - * - *

    - *
  1. unbind all channels created by the factory, - *
  2. close all child channels accepted by the unbound channels, and - * (these two steps so far is usually done using {@link io.netty.channel.group.ChannelGroup#close()})
  3. - *
  4. call {@link #releaseExternalResources()}.
  5. - *
- * - * Please make sure not to shut down the executor until all channels are - * closed. Otherwise, you will end up with a {@link java.util.concurrent.RejectedExecutionException} - * and the related resources might not be released properly. - * @apiviz.landmark - */ -public class SctpServerSocketChannelFactory implements ServerChannelFactory { - - private final ChannelSink sink; - private final WorkerPool workerPool; - - /** - * Creates a new instance. Calling this constructor is same with calling - * {@link #SctpServerSocketChannelFactory(java.util.concurrent.Executor, java.util.concurrent.Executor, int)} with 2 * - * the number of available processors in the machine. The number of - * available processors is obtained by {@link Runtime#availableProcessors()}. - * - * @param workerExecutor - * the {@link java.util.concurrent.Executor} which will execute the I/O worker threads - */ - public SctpServerSocketChannelFactory(Executor workerExecutor) { - this(workerExecutor, SelectorUtil.DEFAULT_IO_THREADS); - } - - /** - * Creates a new instance. - * - * @param workerExecutor - * the {@link java.util.concurrent.Executor} which will execute the I/O worker threads - * @param workerCount - * the maximum number of I/O worker threads - */ - public SctpServerSocketChannelFactory(Executor workerExecutor, - int workerCount) { - this(new SctpWorkerPool(workerExecutor, workerCount, true)); - } - - public SctpServerSocketChannelFactory(WorkerPool workerPool) { - if (workerPool == null) { - throw new NullPointerException("workerPool"); - } - this.workerPool = workerPool; - sink = new SctpServerPipelineSink(workerPool); - } - - @Override - public SctpServerChannel newChannel(ChannelPipeline pipeline) { - return new SctpServerChannelImpl(this, pipeline, sink, workerPool.nextWorker()); - } - - - @Override - public void releaseExternalResources() { - if (workerPool instanceof ExternalResourceReleasable) { - ((ExternalResourceReleasable) workerPool).releaseExternalResources(); - } - - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpUnbindAddressEvent.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpUnbindAddressEvent.java deleted file mode 100644 index f6d7e828bc..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpUnbindAddressEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelState; -import io.netty.channel.DownstreamChannelStateEvent; - -import java.net.InetAddress; - -public class SctpUnbindAddressEvent extends DownstreamChannelStateEvent { - - /** - * Creates a new instance. - */ - public SctpUnbindAddressEvent(Channel channel, ChannelFuture future, InetAddress value) { - super(channel, future, ChannelState.INTEREST_OPS, value); - } - - @Override - public InetAddress getValue() { - return (InetAddress) super.getValue(); - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java deleted file mode 100644 index 0006dc919e..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java +++ /dev/null @@ -1,464 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import static io.netty.channel.Channels.fireChannelBound; -import static io.netty.channel.Channels.fireChannelClosed; -import static io.netty.channel.Channels.fireChannelConnected; -import static io.netty.channel.Channels.fireChannelUnbound; -import static io.netty.channel.Channels.fireExceptionCaught; -import static io.netty.channel.Channels.fireMessageReceived; -import static io.netty.channel.Channels.fireWriteComplete; -import static io.netty.channel.Channels.succeededFuture; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBufferFactory; -import io.netty.channel.Channel; -import io.netty.channel.ChannelException; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.MessageEvent; -import io.netty.channel.ReceiveBufferSizePredictor; -import io.netty.channel.sctp.SctpSendBufferPool.SctpSendBuffer; -import io.netty.channel.socket.nio.AbstractNioChannel; -import io.netty.channel.socket.nio.NioWorker; - -import java.io.IOException; -import java.net.ConnectException; -import java.net.SocketAddress; -import java.net.SocketTimeoutException; -import java.nio.ByteBuffer; -import java.nio.channels.AsynchronousCloseException; -import java.nio.channels.CancelledKeyException; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.ClosedSelectorException; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.util.Queue; -import java.util.Set; -import java.util.concurrent.Executor; - -import com.sun.nio.sctp.MessageInfo; -import com.sun.nio.sctp.SctpChannel; - -/** - */ -public class SctpWorker extends NioWorker { - - private final SctpSendBufferPool sendBufferPool = new SctpSendBufferPool(); - - public SctpWorker(Executor executor) { - super(executor); - } - - public SctpWorker(Executor executor, boolean allowShutdownOnIdle) { - super(executor, allowShutdownOnIdle); - } - - @Override - public void registerWithWorker(final Channel channel, final ChannelFuture future) { - final Selector selector = start(); - - try { - if (channel instanceof SctpServerChannelImpl) { - final SctpServerChannelImpl ch = (SctpServerChannelImpl) channel; - registerTaskQueue.add(new Runnable() { - - @Override - public void run() { - try { - ch.serverChannel.register(selector, SelectionKey.OP_ACCEPT, ch); - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - }); - if (wakenUp.compareAndSet(false, true)) { - selector.wakeup(); - } - } else if (channel instanceof SctpClientChannel) { - final SctpClientChannel clientChannel = (SctpClientChannel) channel; - - registerTaskQueue.add(new Runnable() { - - @Override - public void run() { - try { - try { - clientChannel.getJdkChannel().register(selector, clientChannel.getRawInterestOps() | SelectionKey.OP_CONNECT, clientChannel); - } catch (ClosedChannelException e) { - clientChannel.getWorker().close(clientChannel, succeededFuture(channel)); - } - int connectTimeout = channel.getConfig().getConnectTimeoutMillis(); - if (connectTimeout > 0) { - clientChannel.connectDeadlineNanos = System.nanoTime() + connectTimeout * 1000000L; - } - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - }); - if (wakenUp.compareAndSet(false, true)) { - selector.wakeup(); - } - } else { - super.registerWithWorker(channel, future); - } - - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - - @Override - protected boolean accept(SelectionKey key) { - SctpServerChannelImpl channel = (SctpServerChannelImpl) key.attachment(); - try { - SctpChannel acceptedSocket = channel.serverChannel.accept(); - if (acceptedSocket != null) { - - ChannelPipeline pipeline = - channel.getConfig().getPipelineFactory().pipeline(); - registerTask(new SctpAcceptedChannel(channel.getFactory(), pipeline, channel, - channel.pipeline().getSink(), acceptedSocket, this), null); - return true; - } - return false; - } catch (SocketTimeoutException e) { - // Thrown every second to get ClosedChannelException - // raised. - } catch (CancelledKeyException e) { - // Raised by accept() when the server socket was closed. - } catch (ClosedSelectorException e) { - // Raised by accept() when the server socket was closed. - } catch (ClosedChannelException e) { - // Closed as requested. - } catch (Throwable e) { - if (logger.isWarnEnabled()) { - logger.warn( - "Failed to accept a connection.", e); - } - } - return true; - } - - - @Override - protected boolean read(SelectionKey k) { - final SctpChannelImpl channel = (SctpChannelImpl) k.attachment(); - - final ReceiveBufferSizePredictor predictor = - channel.getConfig().getReceiveBufferSizePredictor(); - final int predictedRecvBufSize = predictor.nextReceiveBufferSize(); - - boolean messageReceived = false; - MessageInfo messageInfo = null; - - ByteBuffer bb = recvBufferPool.acquire(predictedRecvBufSize); - try { - messageInfo = channel.getJdkChannel().getChannel().receive(bb, null, channel.notificationHandler); - messageReceived = messageInfo != null; - } catch (ClosedChannelException e) { - // Can happen, and does not need a user attention. - } catch (Throwable t) { - fireExceptionCaught(channel, t); - } - - if (messageReceived) { - bb.flip(); - - final ChannelBufferFactory bufferFactory = - channel.getConfig().getBufferFactory(); - final int receivedBytes = bb.remaining(); - final ChannelBuffer buffer = bufferFactory.getBuffer(receivedBytes); - buffer.setBytes(0, bb); - buffer.writerIndex(receivedBytes); - - recvBufferPool.release(bb); - - // Update the predictor. - predictor.previousReceiveBufferSize(receivedBytes); - - // Fire the event. - fireMessageReceived(channel, - new SctpFrame(messageInfo, buffer), - messageInfo.address()); - } else { - recvBufferPool.release(bb); - } - - if (channel.getJdkChannel().getChannel().isBlocking() && !messageReceived) { - k.cancel(); // Some JDK implementations run into an infinite loop without this. - close(channel, succeededFuture(channel)); - return false; - } - - return true; - } - - @Override - protected void connect(SelectionKey k) { - final SctpClientChannel ch = (SctpClientChannel) k.attachment(); - try { - if (ch.getJdkChannel().finishConnect()) { - registerTask(ch, ch.connectFuture); - } - } catch (Throwable t) { - ch.connectFuture.setFailure(t); - fireExceptionCaught(ch, t); - k.cancel(); // Some JDK implementations run into an infinite loop without this. - ch.getWorker().close(ch, succeededFuture(ch)); - } - } - - @Override - protected void write0(AbstractNioChannel ach) { - SctpChannelImpl channel = (SctpChannelImpl) ach; - boolean open = true; - boolean addOpWrite = false; - boolean removeOpWrite = false; - - long writtenBytes = 0; - - final SctpSendBufferPool sendBufferPool = this.sendBufferPool; - final com.sun.nio.sctp.SctpChannel ch = channel.getJdkChannel().getChannel(); - final Queue writeBuffer = channel.getWriteBufferQueue(); - final int writeSpinCount = channel.getConfig().getWriteSpinCount(); - synchronized (channel.getWriteLock()) { - channel.setInWriteNowLoop(true); - for (; ;) { - MessageEvent evt = channel.getCurrentWriteEvent(); - SctpSendBuffer buf; - if (evt == null) { - if ((evt = writeBuffer.poll()) == null) { - removeOpWrite = true; - channel.setWriteSuspended(false); - break; - } - channel.setCurrentWriteEvent(evt); - - buf = sendBufferPool.acquire(evt.getMessage()); - channel.setCurrentWriteBuffer(buf); - } else { - buf = channel.getCurrentWriteBuffer(); - } - - ChannelFuture future = evt.getFuture(); - try { - long localWrittenBytes = 0; - for (int i = writeSpinCount; i > 0; i--) { - localWrittenBytes = buf.transferTo(ch); - if (localWrittenBytes != 0) { - writtenBytes += localWrittenBytes; - break; - } - if (buf.finished()) { - break; - } - } - - if (buf.finished()) { - // Successful write - proceed to the next message. - buf.release(); - channel.setCurrentWriteEvent(null); - channel.setCurrentWriteBuffer(null); - evt = null; - buf = null; - future.setSuccess(); - } else { - // Not written fully - perhaps the kernel buffer is full. - addOpWrite = true; - channel.setWriteSuspended(true); - - if (localWrittenBytes > 0) { - // Notify progress listeners if necessary. - future.setProgress( - localWrittenBytes, - buf.writtenBytes(), buf.totalBytes()); - } - break; - } - } catch (AsynchronousCloseException e) { - // Doesn't need a user attention - ignore. - } catch (Throwable t) { - buf.release(); - channel.setCurrentWriteEvent(null); - channel.setCurrentWriteBuffer(null); - buf = null; - evt = null; - future.setFailure(t); - fireExceptionCaught(channel, t); - if (t instanceof IOException) { - open = false; - close(channel, succeededFuture(channel)); - } - } - } - channel.setInWriteNowLoop(false); - } - - if (open) { - if (addOpWrite) { - setOpWrite(channel); - } else if (removeOpWrite) { - clearOpWrite(channel); - } - } - - fireWriteComplete(channel, writtenBytes); - } - - @Override - protected void registerTask(AbstractNioChannel ch, ChannelFuture future) { - boolean server = !(ch instanceof SctpClientChannel); - SctpChannelImpl channel = (SctpChannelImpl) ch; - - SocketAddress localAddress = channel.getLocalAddress(); - SocketAddress remoteAddress = channel.getRemoteAddress(); - if (localAddress == null || remoteAddress == null) { - if (future != null) { - future.setFailure(new ClosedChannelException()); - } - close(channel, succeededFuture(channel)); - return; - } - - try { - if (server) { - channel.getJdkChannel().configureBlocking(false); - } - - boolean registered = channel.getJdkChannel().isRegistered(); - if (!registered) { - synchronized (channel.getInterestedOpsLock()) { - channel.getJdkChannel().register( - selector, channel.getRawInterestOps(), channel); - } - - } else { - setInterestOps(channel, succeededFuture(channel), channel.getRawInterestOps()); - } - if (future != null) { - ((SctpChannelImpl) channel).setConnected(); - future.setSuccess(); - } - - if (!server) { - if (!((SctpClientChannel) channel).boundManually) { - fireChannelBound(channel, localAddress); - } - fireChannelConnected(channel, remoteAddress); - } - } catch (IOException e) { - if (future != null) { - future.setFailure(e); - } - close(channel, succeededFuture(channel)); - if (!(e instanceof ClosedChannelException)) { - throw new ChannelException( - "Failed to register a socket to the selector.", e); - } - } - } - - @Override - protected void processConnectTimeout(Set keys, long currentTimeNanos) { - ConnectException cause = null; - for (SelectionKey k: keys) { - if (!k.isValid()) { - // Comment the close call again as it gave us major problems with ClosedChannelExceptions. - // - // See: - // * https://github.com/netty/netty/issues/142 - // * https://github.com/netty/netty/issues/138 - // - //close(k); - continue; - } - - // Something is ready so skip it - if (k.readyOps() != 0) { - continue; - } - // check if the channel is in - Object attachment = k.attachment(); - if (attachment instanceof SctpClientChannel) { - SctpClientChannel ch = (SctpClientChannel) attachment; - if (!ch.isConnected() && ch.connectDeadlineNanos > 0 && currentTimeNanos >= ch.connectDeadlineNanos) { - - if (cause == null) { - cause = new ConnectException("connection timed out"); - } - - ch.connectFuture.setFailure(cause); - fireExceptionCaught(ch, cause); - ch.getWorker().close(ch, succeededFuture(ch)); - } - } - - - - } - } - - @Override - protected void close(SelectionKey k) { - Object attachment = k.attachment(); - if (attachment instanceof SctpServerChannelImpl) { - SctpServerChannelImpl ch = (SctpServerChannelImpl) attachment; - close(ch, succeededFuture(ch)); - } else { - super.close(k); - } - } - - void close(SctpServerChannelImpl channel, ChannelFuture future) { - boolean bound = channel.isBound(); - try { - if (channel.serverChannel.isOpen()) { - channel.serverChannel.close(); - if (selector != null) { - selector.wakeup(); - } - } - - // Make sure the boss thread is not running so that that the future - // is notified after a new connection cannot be accepted anymore. - // See NETTY-256 for more information. - channel.shutdownLock.lock(); - try { - if (channel.setClosed()) { - future.setSuccess(); - if (bound) { - fireChannelUnbound(channel); - } - fireChannelClosed(channel); - } else { - future.setSuccess(); - } - } finally { - channel.shutdownLock.unlock(); - } - } catch (Throwable t) { - future.setFailure(t); - fireExceptionCaught(channel, t); - } - } - - -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorkerPool.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorkerPool.java deleted file mode 100644 index 11d8b8bd5d..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorkerPool.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp; - -import java.util.concurrent.Executor; - -import io.netty.channel.socket.nio.AbstractNioWorkerPool; - -public class SctpWorkerPool extends AbstractNioWorkerPool { - - public SctpWorkerPool(Executor executor, int workerCount, boolean allowShutdownOnIdle) { - super(executor, workerCount, allowShutdownOnIdle); - } - - @Override - protected SctpWorker createWorker(Executor executor, boolean allowShutdownOnIdle) { - return new SctpWorker(executor, allowShutdownOnIdle); - } - -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/DefaultInboundStreamFilter.java b/transport-sctp/src/main/java/io/netty/channel/sctp/codec/DefaultInboundStreamFilter.java deleted file mode 100644 index ae8ae6e35a..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/DefaultInboundStreamFilter.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.codec; - -import io.netty.channel.sctp.SctpChannel; -import io.netty.channel.sctp.SctpFrame; - -public class DefaultInboundStreamFilter implements InboundStreamFilter { - @Override - public boolean filter(SctpChannel sctpChannel, SctpFrame sctpFrame) { - return true; - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/DefaultOutboundStreamSelector.java b/transport-sctp/src/main/java/io/netty/channel/sctp/codec/DefaultOutboundStreamSelector.java deleted file mode 100644 index c712d2052f..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/DefaultOutboundStreamSelector.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.codec; - -import io.netty.channel.sctp.SctpChannel; - -public class DefaultOutboundStreamSelector implements OutboundStreamSelector { - @Override - public int streamIdentifier(SctpChannel sctpChannel, Object msg) { - return 1; - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/InboundStreamFilter.java b/transport-sctp/src/main/java/io/netty/channel/sctp/codec/InboundStreamFilter.java deleted file mode 100644 index a28beb8111..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/InboundStreamFilter.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.codec; - -import io.netty.channel.sctp.SctpChannel; -import io.netty.channel.sctp.SctpFrame; - -public interface InboundStreamFilter { - - boolean filter(SctpChannel sctpChannel, SctpFrame sctpFrame); -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/OutboundStreamSelector.java b/transport-sctp/src/main/java/io/netty/channel/sctp/codec/OutboundStreamSelector.java deleted file mode 100644 index 188e1eb214..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/OutboundStreamSelector.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.codec; - -import io.netty.channel.sctp.SctpChannel; - -public interface OutboundStreamSelector { - int streamIdentifier(SctpChannel sctpChannel, Object msg); -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/SctpFrameDecoder.java b/transport-sctp/src/main/java/io/netty/channel/sctp/codec/SctpFrameDecoder.java deleted file mode 100644 index b3e6a9ca02..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/SctpFrameDecoder.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.codec; - -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.sctp.SctpChannel; -import io.netty.channel.sctp.SctpFrame; -import io.netty.handler.codec.oneone.OneToOneDecoder; - -/** - * SCTP Frame Decoder which extract payload channel buffer - * Note: Supported SCTP Frame Interleave Level - 0 - */ - -public class SctpFrameDecoder extends OneToOneDecoder { - - private final InboundStreamFilter inboundStreamFilter; - - private volatile ChannelBuffer cumulation; - - public SctpFrameDecoder() { - this.inboundStreamFilter = new DefaultInboundStreamFilter(); - } - - public SctpFrameDecoder(InboundStreamFilter inboundStreamFilter) { - this.inboundStreamFilter = inboundStreamFilter; - } - - @Override - protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { - if (!(msg instanceof SctpFrame)) { - return msg; - } - final SctpChannel sctpChannel = (SctpChannel) channel; - final SctpFrame sctpFrame = (SctpFrame) msg; - - if (inboundStreamFilter.filter(sctpChannel, sctpFrame)) { - - final boolean complete = sctpFrame.getMessageInfo().isComplete(); - if (complete) { - if (cumulation == null) { - return sctpFrame.getPayloadBuffer(); - } else { - final ChannelBuffer extractedFrame = ChannelBuffers.wrappedBuffer(cumulation, sctpFrame.getPayloadBuffer()); - cumulation = null; - return extractedFrame; - } - } else { - if (cumulation == null) { - cumulation = sctpFrame.getPayloadBuffer(); - } else { - cumulation = ChannelBuffers.wrappedBuffer(cumulation, sctpFrame.getPayloadBuffer()); - } - return null; - } - } else { - return msg; - } - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/SctpFrameEncoder.java b/transport-sctp/src/main/java/io/netty/channel/sctp/codec/SctpFrameEncoder.java deleted file mode 100644 index 96dd2b242a..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/SctpFrameEncoder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.codec; - -import io.netty.buffer.ChannelBuffer; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.sctp.SctpChannel; -import io.netty.channel.sctp.SctpFrame; -import io.netty.handler.codec.oneone.OneToOneEncoder; - -/** - * SCTP Frame Encoder which encode a channel buffer to SctpFrame object - */ -public class SctpFrameEncoder extends OneToOneEncoder { - - private final int protocolIdentifier; - private final OutboundStreamSelector sctpWriteStreamSelector; - - public SctpFrameEncoder() { - this(0); - } - - public SctpFrameEncoder(int protocolIdentifier) { - this(protocolIdentifier, new DefaultOutboundStreamSelector()); - } - - public SctpFrameEncoder(final int protocolIdentifier, final OutboundStreamSelector sctpWriteStreamSelector) { - if (sctpWriteStreamSelector == null) { - throw new NullPointerException("sctpWriteStreamSelector"); - } - this.protocolIdentifier = Math.max(0, protocolIdentifier); - this.sctpWriteStreamSelector = sctpWriteStreamSelector; - } - - @Override - protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { - if (!(msg instanceof ChannelBuffer)) { - return msg; - } else { - SctpChannel sctpChannel = (SctpChannel) channel; - final int streamIdentifier = sctpWriteStreamSelector.streamIdentifier(sctpChannel, msg); - return new SctpFrame(protocolIdentifier, streamIdentifier, (ChannelBuffer) msg); - } - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/package-info.java b/transport-sctp/src/main/java/io/netty/channel/sctp/codec/package-info.java deleted file mode 100644 index d9fd0907d2..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/codec/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * - */ -package io.netty.channel.sctp.codec; diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpChannelHandler.java b/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpChannelHandler.java deleted file mode 100644 index 910fd0093b..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpChannelHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.handler; - -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelHandler; -import io.netty.channel.sctp.SctpNotificationEvent; - -/** - * SCTP Channel Handler (upstream + downstream) with SCTP notification handling - */ - -public class SimpleSctpChannelHandler extends SimpleChannelHandler { - - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception { - if (!(event instanceof SctpNotificationEvent)) { - super.handleUpstream(ctx, event); - - } - if (event instanceof SctpNotificationEvent) { - sctpNotificationReceived(ctx, (SctpNotificationEvent) event); - } - } - - public void sctpNotificationReceived(ChannelHandlerContext ctx, SctpNotificationEvent event) { - ctx.sendUpstream(event); - } - -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpDownstreamHandler.java b/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpDownstreamHandler.java deleted file mode 100644 index 7a70491a37..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpDownstreamHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.handler; - -import io.netty.channel.SimpleChannelDownstreamHandler; - -/** - * Sctp Downstream handler for sake of completeness - */ -public class SimpleSctpDownstreamHandler extends SimpleChannelDownstreamHandler { -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpUpstreamHandler.java b/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpUpstreamHandler.java deleted file mode 100644 index 37c3696de4..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/handler/SimpleSctpUpstreamHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.sctp.handler; - -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelUpstreamHandler; -import io.netty.channel.sctp.SctpNotificationEvent; - -/** - * SCTP Upstream Channel Handler with SCTP notification handling - */ -public class SimpleSctpUpstreamHandler extends SimpleChannelUpstreamHandler { - - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception { - if (!(event instanceof SctpNotificationEvent)) { - super.handleUpstream(ctx, event); - - } - if (event instanceof SctpNotificationEvent) { - sctpNotificationReceived(ctx, (SctpNotificationEvent) event); - } - } - - public void sctpNotificationReceived(ChannelHandlerContext ctx, SctpNotificationEvent event) { - ctx.sendUpstream(event); - } -} diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/handler/package-info.java b/transport-sctp/src/main/java/io/netty/channel/sctp/handler/package-info.java deleted file mode 100644 index 790d7ec30b..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/handler/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * NIO-based socket channel - * API implementation - recommended for a large number of connections (>= 1000). - */ -package io.netty.channel.sctp.handler; diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/package-info.java b/transport-sctp/src/main/java/io/netty/channel/sctp/package-info.java deleted file mode 100644 index 8da61a048b..0000000000 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * NIO -based SCTP channel API implementation. - */ -package io.netty.channel.sctp; diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketClientBootstrapTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketClientBootstrapTest.java deleted file mode 100644 index 3ad1a13814..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketClientBootstrapTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport; - -import com.sun.nio.sctp.SctpServerChannel; -import io.netty.bootstrap.ClientBootstrap; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelPipelineException; -import io.netty.channel.ChannelPipelineFactory; -import io.netty.channel.sctp.codec.SctpFrameDecoder; -import io.netty.channel.sctp.codec.SctpFrameEncoder; -import io.netty.testsuite.util.DummyHandler; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; -import org.easymock.EasyMock; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.Iterator; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - - -/** - * An abstract test class to test socket client bootstraps - */ -public abstract class AbstractSocketClientBootstrapTest { - - private static ExecutorService executor; - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); - - @Test(timeout = 10000) - public void testFailedConnectionAttempt() throws Exception { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ClientBootstrap bootstrap = new ClientBootstrap(); - bootstrap.setFactory(newClientSocketChannelFactory(executor)); - bootstrap.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - bootstrap.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - bootstrap.pipeline().addLast("dummy", new DummyHandler()); - bootstrap.setOption("remoteAddress", new InetSocketAddress("255.255.255.255", 1)); - ChannelFuture future = bootstrap.connect(); - future.awaitUninterruptibly(); - assertFalse(future.isSuccess()); - assertTrue(future.cause() instanceof IOException); - } - - @Test(timeout = 10000) - public void testSuccessfulConnectionAttempt() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - SctpServerChannel serverChannel = SctpServerChannel.open(); - serverChannel.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - - try { - serverChannel.configureBlocking(false); - - final Iterator serverAddresses = serverChannel.getAllLocalAddresses().iterator(); - InetSocketAddress serverAddress = (InetSocketAddress) serverAddresses.next(); - int serverPort = serverAddress.getPort(); - - ClientBootstrap bootstrap = - new ClientBootstrap(newClientSocketChannelFactory(executor)); - - bootstrap.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - bootstrap.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - bootstrap.pipeline().addLast("dummy", new DummyHandler()); - bootstrap.setOption( - "remoteAddress", - new InetSocketAddress( - SctpTestUtil.LOOP_BACK, - serverPort)); - - ChannelFuture future = bootstrap.connect(); - serverChannel.accept(); - future.awaitUninterruptibly(); - - if (future.cause() != null) { - throw future.cause(); - } - assertTrue(future.isSuccess()); - - future.channel().close().awaitUninterruptibly(); - } finally { - try { - serverChannel.close(); - } catch (IOException e) { - // Ignore. - } - } - } - - @Test(timeout = 10000) - public void testSuccessfulConnectionAttemptWithLocalAddress() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - SctpServerChannel serverChannel = SctpServerChannel.open(); - - try { - serverChannel.configureBlocking(false); - serverChannel = serverChannel.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - - final Iterator serverAddresses = serverChannel.getAllLocalAddresses().iterator(); - InetSocketAddress serverAddress = (InetSocketAddress) serverAddresses.next(); - int serverPort = serverAddress.getPort(); - ClientBootstrap bootstrap = - new ClientBootstrap(newClientSocketChannelFactory(executor)); - - bootstrap.pipeline().addLast("dummy", new DummyHandler()); - bootstrap.setOption( - "remoteAddress", - new InetSocketAddress( - SctpTestUtil.LOOP_BACK, - serverPort)); - bootstrap.setOption("localAddress", new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - - ChannelFuture future = bootstrap.connect(); - serverChannel.accept(); - future.awaitUninterruptibly(); - - if (future.cause() != null) { - throw future.cause(); - } - assertTrue(future.isSuccess()); - - future.channel().close().awaitUninterruptibly(); - } finally { - try { - serverChannel.close(); - } catch (IOException e) { - // Ignore. - } - } - } - - @Test(expected = ChannelPipelineException.class) - public void testFailedPipelineInitialization() throws Exception { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ClientBootstrap bootstrap = new ClientBootstrap(EasyMock.createMock(ChannelFactory.class)); - ChannelPipelineFactory pipelineFactory = EasyMock.createMock(ChannelPipelineFactory.class); - bootstrap.setPipelineFactory(pipelineFactory); - - EasyMock.expect(pipelineFactory.pipeline()).andThrow(new ChannelPipelineException()); - EasyMock.replay(pipelineFactory); - - bootstrap.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 1)); - } - - @Test(expected = IllegalStateException.class) - public void shouldHaveRemoteAddressOption() { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - new ClientBootstrap(EasyMock.createMock(ChannelFactory.class)).connect(); - } - - - @Test(expected = NullPointerException.class) - public void shouldDisallowNullRemoteAddressParameter1() { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - new ClientBootstrap(EasyMock.createMock(ChannelFactory.class)).connect(null); - } - - @Test(expected = NullPointerException.class) - public void shouldDisallowNullRemoteAddressParameter2() { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - new ClientBootstrap(EasyMock.createMock(ChannelFactory.class)).connect(null, null); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketCompatibleObjectStreamEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketCompatibleObjectStreamEchoTest.java deleted file mode 100644 index 964bfb2693..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketCompatibleObjectStreamEchoTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport; - -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.*; -import io.netty.channel.sctp.codec.SctpFrameDecoder; -import io.netty.channel.sctp.codec.SctpFrameEncoder; -import io.netty.handler.codec.serialization.CompatibleObjectDecoder; -import io.netty.handler.codec.serialization.CompatibleObjectEncoder; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractSocketCompatibleObjectStreamEchoTest { - - static final Random random = new Random(); - static final String[] data = new String[512];//could not test with jumbo sctp frame - - private static ExecutorService executor; - - static { - for (int i = 0; i < data.length; i ++) { - int eLen = random.nextInt(512); - char[] e = new char[eLen]; - for (int j = 0; j < eLen; j ++) { - e[j] = (char) ('a' + random.nextInt(26)); - } - - data[i] = new String(e); - } - } - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); - protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); - - @Test - @SuppressWarnings("deprecation") - public void testCompatibleObjectEcho() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); - ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); - - EchoHandler sh = new EchoHandler(); - EchoHandler ch = new EchoHandler(); - - sb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - sb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - sb.pipeline().addLast("decoder", new CompatibleObjectDecoder()); - sb.pipeline().addLast("encoder", new CompatibleObjectEncoder()); - sb.pipeline().addLast("handler", sh); - - cb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - cb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - cb.pipeline().addLast("decoder", new CompatibleObjectDecoder()); - cb.pipeline().addLast("encoder", new CompatibleObjectEncoder()); - cb.pipeline().addLast("handler", ch); - - Channel sc = sb.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); - - ChannelFuture ccf = cb.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, port)); - assertTrue(ccf.awaitUninterruptibly().isSuccess()); - - Channel cc = ccf.channel(); - for (String element : data) { - cc.write(element); - } - - while (ch.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - - while (sh.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - sc.close().awaitUninterruptibly(); - - if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { - throw sh.exception.get(); - } - if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { - throw ch.exception.get(); - } - if (sh.exception.get() != null) { - throw sh.exception.get(); - } - if (ch.exception.get() != null) { - throw ch.exception.get(); - } - } - - private static class EchoHandler extends SimpleChannelUpstreamHandler { - volatile Channel channel; - final AtomicReference exception = new AtomicReference(); - volatile int counter; - - EchoHandler() { - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channel = e.channel(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - - String m = (String) e.getMessage(); - assertEquals(data[counter], m); - - if (channel.getParent() != null) { - channel.write(m); - } - - counter ++; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - if (exception.compareAndSet(null, e.cause())) { - e.channel().close(); - } - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketEchoTest.java deleted file mode 100644 index d5434c199f..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketEchoTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport; - -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.*; -import io.netty.channel.sctp.codec.SctpFrameDecoder; -import io.netty.channel.sctp.codec.SctpFrameEncoder; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractSocketEchoTest { - - private static final Random random = new Random(); - static final byte[] data = new byte[4096];//could not test ultra jumbo frames - - private static ExecutorService executor; - - static { - random.nextBytes(data); - } - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); - protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); - - @Test - public void testSimpleEcho() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); - - ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); - - - EchoHandler sh = new EchoHandler(); - EchoHandler ch = new EchoHandler(); - - sb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - sb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - sb.pipeline().addLast("handler", sh); - - cb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - cb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - cb.pipeline().addLast("handler", ch); - - Channel sc = sb.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); - - ChannelFuture ccf = cb.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, port)); - assertTrue(ccf.awaitUninterruptibly().isSuccess()); - - Channel cc = ccf.channel(); - for (int i = 0; i < data.length;) { - int length = Math.min(random.nextInt(1024 * 64), data.length - i); - cc.write(ChannelBuffers.wrappedBuffer(data, i, length)); - i += length; - } - - while (ch.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(5); - } catch (InterruptedException e) { - // Ignore. - } - } - - while (sh.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(5); - } catch (InterruptedException e) { - // Ignore. - } - } - - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - sc.close().awaitUninterruptibly(); - - if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { - throw sh.exception.get(); - } - if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { - throw ch.exception.get(); - } - if (sh.exception.get() != null) { - throw sh.exception.get(); - } - if (ch.exception.get() != null) { - throw ch.exception.get(); - } - } - - private static class EchoHandler extends SimpleChannelUpstreamHandler { - volatile Channel channel; - final AtomicReference exception = new AtomicReference(); - volatile int counter; - - EchoHandler() { - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channel = e.channel(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - ChannelBuffer m = (ChannelBuffer) e.getMessage(); - byte[] actual = new byte[m.readableBytes()]; - m.getBytes(0, actual); - - int lastIdx = counter; - for (int i = 0; i < actual.length; i ++) { - assertEquals(data[i + lastIdx], actual[i]); - } - - if (channel.getParent() != null) { - channel.write(m); - } - - counter += actual.length; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - if (exception.compareAndSet(null, e.cause())) { - e.channel().close(); - } - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketFixedLengthEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketFixedLengthEchoTest.java deleted file mode 100644 index 692af1dfcb..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketFixedLengthEchoTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport; - -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.*; -import io.netty.channel.sctp.codec.SctpFrameDecoder; -import io.netty.channel.sctp.codec.SctpFrameEncoder; -import io.netty.handler.codec.FixedLengthFrameDecoder; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractSocketFixedLengthEchoTest { - - private static final Random random = new Random(); - static final byte[] data = new byte[1024];//could not test with jumbo frames - - private static ExecutorService executor; - - static { - random.nextBytes(data); - } - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); - protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); - - @Test - public void testFixedLengthEcho() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); - ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); - - EchoHandler sh = new EchoHandler(); - EchoHandler ch = new EchoHandler(); - - sb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - sb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - sb.pipeline().addLast("decoder", new FixedLengthFrameDecoder(1024)); - sb.pipeline().addAfter("decoder", "handler", sh); - - - cb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - cb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - cb.pipeline().addLast("decoder", new FixedLengthFrameDecoder(1024)); - cb.pipeline().addAfter("decoder", "handler", ch); - - Channel sc = sb.bind(new InetSocketAddress(0)); - int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); - - ChannelFuture ccf = cb.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, port)); - assertTrue(ccf.awaitUninterruptibly().isSuccess()); - - Channel cc = ccf.channel(); - for (int i = 0; i < data.length;) { - int length = Math.min(random.nextInt(1024 * 3), data.length - i); - cc.write(ChannelBuffers.wrappedBuffer(data, i, length)); - i += length; - } - - while (ch.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - - while (sh.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - sc.close().awaitUninterruptibly(); - - if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { - throw sh.exception.get(); - } - if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { - throw ch.exception.get(); - } - if (sh.exception.get() != null) { - throw sh.exception.get(); - } - if (ch.exception.get() != null) { - throw ch.exception.get(); - } - } - - private static class EchoHandler extends SimpleChannelUpstreamHandler { - volatile Channel channel; - final AtomicReference exception = new AtomicReference(); - volatile int counter; - - EchoHandler() { - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channel = e.channel(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - ChannelBuffer m = (ChannelBuffer) e.getMessage(); - assertEquals(1024, m.readableBytes()); - - byte[] actual = new byte[m.readableBytes()]; - m.getBytes(0, actual); - - int lastIdx = counter; - for (int i = 0; i < actual.length; i ++) { - assertEquals(data[i + lastIdx], actual[i]); - } - - if (channel.getParent() != null) { - channel.write(m); - } - - counter += actual.length; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - if (exception.compareAndSet(null, e.cause())) { - e.channel().close(); - } - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketObjectStreamEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketObjectStreamEchoTest.java deleted file mode 100644 index 8d40f97051..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketObjectStreamEchoTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport; - -import static org.junit.Assert.*; -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.ExceptionEvent; -import io.netty.channel.MessageEvent; -import io.netty.channel.SimpleChannelUpstreamHandler; -import io.netty.channel.sctp.codec.SctpFrameDecoder; -import io.netty.channel.sctp.codec.SctpFrameEncoder; -import io.netty.handler.codec.serialization.ClassResolvers; -import io.netty.handler.codec.serialization.ObjectDecoder; -import io.netty.handler.codec.serialization.ObjectEncoder; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -public abstract class AbstractSocketObjectStreamEchoTest { - - static final Random random = new Random(); - static final String[] data = new String[512];//could not test jumbo frames - - private static ExecutorService executor; - - static { - for (int i = 0; i < data.length; i ++) { - int eLen = random.nextInt(512); - char[] e = new char[eLen]; - for (int j = 0; j < eLen; j ++) { - e[j] = (char) ('a' + random.nextInt(26)); - } - - data[i] = new String(e); - } - } - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); - protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); - - @Test - public void testObjectEcho() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); - ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); - - EchoHandler sh = new EchoHandler(); - EchoHandler ch = new EchoHandler(); - - sb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - sb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - sb.pipeline().addLast("decoder", new ObjectDecoder( - ClassResolvers.cacheDisabled(getClass().getClassLoader()))); - sb.pipeline().addLast("encoder", new ObjectEncoder()); - sb.pipeline().addLast("handler", sh); - - cb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - cb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - cb.pipeline().addLast("decoder", new ObjectDecoder( - ClassResolvers.cacheDisabled(getClass().getClassLoader()))); - cb.pipeline().addLast("encoder", new ObjectEncoder()); - cb.pipeline().addLast("handler", ch); - - Channel sc = sb.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); - - ChannelFuture ccf = cb.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, port)); - assertTrue(ccf.awaitUninterruptibly().isSuccess()); - - Channel cc = ccf.channel(); - for (String element : data) { - cc.write(element); - } - - while (ch.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(5); - } catch (InterruptedException e) { - // Ignore. - } - } - - while (sh.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(5); - } catch (InterruptedException e) { - // Ignore. - } - } - - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - sc.close().awaitUninterruptibly(); - - if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { - throw sh.exception.get(); - } - if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { - throw ch.exception.get(); - } - if (sh.exception.get() != null) { - throw sh.exception.get(); - } - if (ch.exception.get() != null) { - throw ch.exception.get(); - } - } - - private static class EchoHandler extends SimpleChannelUpstreamHandler { - volatile Channel channel; - final AtomicReference exception = new AtomicReference(); - volatile int counter; - - EchoHandler() { - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channel = e.channel(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - - String m = (String) e.getMessage(); - assertEquals(data[counter], m); - - if (channel.getParent() != null) { - channel.write(m); - } - - counter ++; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - if (exception.compareAndSet(null, e.cause())) { - e.channel().close(); - } - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketServerBootstrapTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketServerBootstrapTest.java deleted file mode 100644 index 0ebd8d9e34..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketServerBootstrapTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport; - -import com.sun.nio.sctp.SctpChannel; -import com.sun.nio.sctp.SctpServerChannel; -import com.sun.nio.sctp.SctpStandardSocketOptions; -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.*; -import io.netty.channel.sctp.SctpChannelConfig; -import io.netty.testsuite.util.DummyHandler; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; -import org.easymock.EasyMock; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.Iterator; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static org.junit.Assert.assertEquals; - - -/** - * An abstract test class to test server socket bootstraps - */ -public abstract class AbstractSocketServerBootstrapTest { - - private static final boolean BUFSIZE_MODIFIABLE; - - static { - boolean bufSizeModifiable = true; - - SctpChannel s = null; - try { - s = SctpChannel.open(); - bufSizeModifiable = s.supportedOptions().contains(SctpStandardSocketOptions.SO_RCVBUF); - } catch (Exception e) { - bufSizeModifiable = false; - System.err.println( - "SCTP SO_RCVBUF does not work: " + e); - } finally { - BUFSIZE_MODIFIABLE = bufSizeModifiable; - try { - if (s != null) { - s.close(); - } - } catch (IOException e) { - // Ignore. - } - } - } - - private static ExecutorService executor; - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); - - @Test(timeout = 30000, expected = ChannelException.class) - public void testFailedBindAttempt() throws Exception { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - SctpServerChannel serverChannel = SctpServerChannel.open(); - serverChannel.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - - try { - final Iterator serverAddresses = serverChannel.getAllLocalAddresses().iterator(); - InetSocketAddress serverAddress = (InetSocketAddress) serverAddresses.next(); - final int boundPort = serverAddress.getPort(); - ServerBootstrap bootstrap = new ServerBootstrap(); - bootstrap.setFactory(newServerSocketChannelFactory(executor)); - bootstrap.setOption("localAddress", new InetSocketAddress(SctpTestUtil.LOOP_BACK, boundPort)); - bootstrap.bind().close().awaitUninterruptibly(); - } finally { - serverChannel.close(); - } - } - - @Test(timeout = 30000) - public void testSuccessfulBindAttempt() throws Exception { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap bootstrap = new ServerBootstrap( - newServerSocketChannelFactory(executor)); - - bootstrap.setParentHandler(new ParentChannelHandler()); - bootstrap.setOption("localAddress", new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - bootstrap.setOption("child.receiveBufferSize", 9753); - bootstrap.setOption("child.sendBufferSize", 8642); - - bootstrap.pipeline().addLast("dummy", new DummyHandler()); - - Channel channel = bootstrap.bind(); - ParentChannelHandler pch = - channel.pipeline().get(ParentChannelHandler.class); - - SctpChannel sctpChannel = SctpChannel.open(); - try { - sctpChannel.connect( - new InetSocketAddress( - SctpTestUtil.LOOP_BACK, - ((InetSocketAddress) channel.getLocalAddress()).getPort())); - - // Wait until the connection is open in the server side. - while (pch.child == null) { - Thread.yield(); - } - - SctpChannelConfig cfg = (SctpChannelConfig) pch.child.getConfig(); - if (BUFSIZE_MODIFIABLE) { - assertEquals(9753, cfg.getReceiveBufferSize()); - assertEquals(8642, cfg.getSendBufferSize()); - } - } finally { - if (sctpChannel != null) { - try { - sctpChannel.close(); - } catch (IOException e) { - // Ignore. - } - } - channel.close().awaitUninterruptibly(); - } - - // Wait until the child connection is closed in the client side. - // We do not use Channel.close() to make sure it is closed automatically. - while (pch.child.isOpen()) { - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore - } - } - - // Wait until all child events are fired. - while (pch.result.length() < 2) { - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore - } - } - - // Confirm the received child events. - assertEquals("12", pch.result.toString()); - } - - @Test(expected = ChannelPipelineException.class) - public void testFailedPipelineInitialization() throws Exception { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ClientBootstrap bootstrap = new ClientBootstrap(EasyMock.createMock(ChannelFactory.class)); - ChannelPipelineFactory pipelineFactory = EasyMock.createMock(ChannelPipelineFactory.class); - bootstrap.setPipelineFactory(pipelineFactory); - - EasyMock.expect(pipelineFactory.pipeline()).andThrow(new ChannelPipelineException()); - EasyMock.replay(pipelineFactory); - - bootstrap.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 1)); - } - - @Test(expected = IllegalStateException.class) - public void shouldHaveLocalAddressOption() { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - new ServerBootstrap(EasyMock.createMock(ServerChannelFactory.class)).bind(); - } - - - @Test(expected = NullPointerException.class) - public void shouldDisallowNullLocalAddressParameter() { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - new ServerBootstrap(EasyMock.createMock(ServerChannelFactory.class)).bind(null); - } - - private static class ParentChannelHandler extends SimpleChannelUpstreamHandler { - - volatile Channel child; - final StringBuffer result = new StringBuffer(); - - ParentChannelHandler() { - } - - @Override - public void childChannelClosed(ChannelHandlerContext ctx, - ChildChannelStateEvent e) throws Exception { - result.append('2'); - } - - @Override - public void childChannelOpen(ChannelHandlerContext ctx, - ChildChannelStateEvent e) throws Exception { - child = e.getChildChannel(); - result.append('1'); - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketSslEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketSslEchoTest.java deleted file mode 100644 index a4ccea0e39..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketSslEchoTest.java +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport; - -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.*; -import io.netty.channel.sctp.codec.SctpFrameDecoder; -import io.netty.channel.sctp.codec.SctpFrameEncoder; -import io.netty.handler.execution.ExecutionHandler; -import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor; -import io.netty.handler.ssl.SslHandler; -import io.netty.logging.InternalLogger; -import io.netty.logging.InternalLoggerFactory; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.net.ssl.*; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetSocketAddress; -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.Security; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractSocketSslEchoTest { - static final InternalLogger logger = - InternalLoggerFactory.getInstance(AbstractSocketSslEchoTest.class); - - private static final Random random = new Random(); - static final byte[] data = new byte[4096];//could not test jumbo frames - - private static ExecutorService executor; - private static ExecutorService eventExecutor; - - static { - random.nextBytes(data); - } - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - eventExecutor = new OrderedMemoryAwareThreadPoolExecutor(16, 0, 0); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor, eventExecutor); - } - - protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); - protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); - - protected boolean isExecutorRequired() { - return false; - } - - @Test - public void testSslEcho() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); - ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); - - EchoHandler sh = new EchoHandler(true); - EchoHandler ch = new EchoHandler(false); - - SSLEngine sse = BogusSslContextFactory.getServerContext().createSSLEngine(); - SSLEngine cse = BogusSslContextFactory.getClientContext().createSSLEngine(); - sse.setUseClientMode(false); - cse.setUseClientMode(true); - - - sb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - sb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - sb.pipeline().addLast("ssl", new SslHandler(sse)); - sb.pipeline().addLast("handler", sh); - - cb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - cb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - cb.pipeline().addLast("ssl", new SslHandler(cse)); - cb.pipeline().addLast("handler", ch); - - if (isExecutorRequired()) { - sb.pipeline().addFirst("executor", new ExecutionHandler(eventExecutor)); - cb.pipeline().addFirst("executor", new ExecutionHandler(eventExecutor)); - } - - Channel sc = sb.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); - - ChannelFuture ccf = cb.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, port)); - ccf.awaitUninterruptibly(); - if (!ccf.isSuccess()) { - logger.error("Connection attempt failed", ccf.cause()); - sc.close().awaitUninterruptibly(); - } - assertTrue(ccf.isSuccess()); - - Channel cc = ccf.channel(); - ChannelFuture hf = cc.pipeline().get(SslHandler.class).handshake(); - hf.awaitUninterruptibly(); - if (!hf.isSuccess()) { - logger.error("Handshake failed", hf.cause()); - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - sc.close().awaitUninterruptibly(); - } - - assertTrue(hf.isSuccess()); - - for (int i = 0; i < data.length;) { - int length = Math.min(random.nextInt(1024 * 64), data.length - i); - cc.write(ChannelBuffers.wrappedBuffer(data, i, length)); - i += length; - } - - while (ch.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - - while (sh.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - sc.close().awaitUninterruptibly(); - - if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { - throw sh.exception.get(); - } - if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { - throw ch.exception.get(); - } - if (sh.exception.get() != null) { - throw sh.exception.get(); - } - if (ch.exception.get() != null) { - throw ch.exception.get(); - } - } - - private static class EchoHandler extends SimpleChannelUpstreamHandler { - volatile Channel channel; - final AtomicReference exception = new AtomicReference(); - volatile int counter; - private final boolean server; - - EchoHandler(boolean server) { - this.server = server; - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channel = e.channel(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - ChannelBuffer m = (ChannelBuffer) e.getMessage(); - byte[] actual = new byte[m.readableBytes()]; - m.getBytes(0, actual); - - int lastIdx = counter; - for (int i = 0; i < actual.length; i ++) { - assertEquals(data[i + lastIdx], actual[i]); - } - - if (channel.getParent() != null) { - channel.write(m); - } - - counter += actual.length; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - logger.warn( - "Unexpected exception from the " + - (server? "server" : "client") + " side", e.cause()); - - exception.compareAndSet(null, e.cause()); - e.channel().close(); - } - } - - private static class BogusSslContextFactory { - - private static final String PROTOCOL = "TLS"; - private static final SSLContext SERVER_CONTEXT; - private static final SSLContext CLIENT_CONTEXT; - - static { - String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm"); - if (algorithm == null) { - algorithm = "SunX509"; - } - - SSLContext serverContext = null; - SSLContext clientContext = null; - try { - KeyStore ks = KeyStore.getInstance("JKS"); - ks.load(BogusKeyStore.asInputStream(), - BogusKeyStore.getKeyStorePassword()); - - // Set up key manager factory to use our key store - KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); - kmf.init(ks, BogusKeyStore.getCertificatePassword()); - - // Initialize the SSLContext to work with our key managers. - serverContext = SSLContext.getInstance(PROTOCOL); - serverContext.init(kmf.getKeyManagers(), null, null); - } catch (Exception e) { - throw new Error( - "Failed to initialize the server-side SSLContext", e); - } - - try { - clientContext = SSLContext.getInstance(PROTOCOL); - clientContext.init(null, BogusTrustManagerFactory.getTrustManagers(), null); - } catch (Exception e) { - throw new Error( - "Failed to initialize the client-side SSLContext", e); - } - - SERVER_CONTEXT = serverContext; - CLIENT_CONTEXT = clientContext; - } - - public static SSLContext getServerContext() { - return SERVER_CONTEXT; - } - - public static SSLContext getClientContext() { - return CLIENT_CONTEXT; - } - } - - /** - * Bogus {@link javax.net.ssl.TrustManagerFactorySpi} which accepts any certificate - * even if it is invalid. - */ - private static class BogusTrustManagerFactory extends TrustManagerFactorySpi { - - private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() { - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - @Override - public void checkClientTrusted( - X509Certificate[] chain, String authType) throws CertificateException { - // Always trust - it is an example. - // You should do something in the real world. - // You will reach here only if you enabled client certificate auth, - // as described in SecureChatSslContextFactory. - System.err.println( - "UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN()); - } - - @Override - public void checkServerTrusted( - X509Certificate[] chain, String authType) throws CertificateException { - // Always trust - it is an example. - // You should do something in the real world. - System.err.println( - "UNKNOWN SERVER CERTIFICATE: " + chain[0].getSubjectDN()); - } - }; - - public static TrustManager[] getTrustManagers() { - return new TrustManager[] { DUMMY_TRUST_MANAGER }; - } - - @Override - protected TrustManager[] engineGetTrustManagers() { - return getTrustManagers(); - } - - @Override - protected void engineInit(KeyStore keystore) throws KeyStoreException { - // Unused - } - - @Override - protected void engineInit(ManagerFactoryParameters managerFactoryParameters) - throws InvalidAlgorithmParameterException { - // Unused - } - } - - /** - * A bogus key store which provides all the required information to - * create an example SSL connection. - * - * To generate a bogus key store: - *
-     * keytool  -genkey -alias bogus -keysize 2048 -validity 36500
-     *          -keyalg RSA -dname "CN=bogus"
-     *          -keypass secret -storepass secret
-     *          -keystore cert.jks
-     * 
- */ - private static final class BogusKeyStore { - private static final short[] DATA = { - 0xfe, 0xed, 0xfe, 0xed, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 0x00, 0x00, 0x01, 0x1a, 0x9f, 0x57, 0xa5, - 0x27, 0x00, 0x00, 0x01, 0x9a, 0x30, 0x82, 0x01, - 0x96, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, - 0x04, 0x01, 0x2a, 0x02, 0x11, 0x01, 0x01, 0x05, - 0x00, 0x04, 0x82, 0x01, 0x82, 0x48, 0x6d, 0xcf, - 0x16, 0xb5, 0x50, 0x95, 0x36, 0xbf, 0x47, 0x27, - 0x50, 0x58, 0x0d, 0xa2, 0x52, 0x7e, 0x25, 0xab, - 0x14, 0x1a, 0x26, 0x5e, 0x2d, 0x8a, 0x23, 0x90, - 0x60, 0x7f, 0x12, 0x20, 0x56, 0xd1, 0x43, 0xa2, - 0x6b, 0x47, 0x5d, 0xed, 0x9d, 0xd4, 0xe5, 0x83, - 0x28, 0x89, 0xc2, 0x16, 0x4c, 0x76, 0x06, 0xad, - 0x8e, 0x8c, 0x29, 0x1a, 0x9b, 0x0f, 0xdd, 0x60, - 0x4b, 0xb4, 0x62, 0x82, 0x9e, 0x4a, 0x63, 0x83, - 0x2e, 0xd2, 0x43, 0x78, 0xc2, 0x32, 0x1f, 0x60, - 0xa9, 0x8a, 0x7f, 0x0f, 0x7c, 0xa6, 0x1d, 0xe6, - 0x92, 0x9e, 0x52, 0xc7, 0x7d, 0xbb, 0x35, 0x3b, - 0xaa, 0x89, 0x73, 0x4c, 0xfb, 0x99, 0x54, 0x97, - 0x99, 0x28, 0x6e, 0x66, 0x5b, 0xf7, 0x9b, 0x7e, - 0x6d, 0x8a, 0x2f, 0xfa, 0xc3, 0x1e, 0x71, 0xb9, - 0xbd, 0x8f, 0xc5, 0x63, 0x25, 0x31, 0x20, 0x02, - 0xff, 0x02, 0xf0, 0xc9, 0x2c, 0xdd, 0x3a, 0x10, - 0x30, 0xab, 0xe5, 0xad, 0x3d, 0x1a, 0x82, 0x77, - 0x46, 0xed, 0x03, 0x38, 0xa4, 0x73, 0x6d, 0x36, - 0x36, 0x33, 0x70, 0xb2, 0x63, 0x20, 0xca, 0x03, - 0xbf, 0x5a, 0xf4, 0x7c, 0x35, 0xf0, 0x63, 0x1a, - 0x12, 0x33, 0x12, 0x58, 0xd9, 0xa2, 0x63, 0x6b, - 0x63, 0x82, 0x41, 0x65, 0x70, 0x37, 0x4b, 0x99, - 0x04, 0x9f, 0xdd, 0x5e, 0x07, 0x01, 0x95, 0x9f, - 0x36, 0xe8, 0xc3, 0x66, 0x2a, 0x21, 0x69, 0x68, - 0x40, 0xe6, 0xbc, 0xbb, 0x85, 0x81, 0x21, 0x13, - 0xe6, 0xa4, 0xcf, 0xd3, 0x67, 0xe3, 0xfd, 0x75, - 0xf0, 0xdf, 0x83, 0xe0, 0xc5, 0x36, 0x09, 0xac, - 0x1b, 0xd4, 0xf7, 0x2a, 0x23, 0x57, 0x1c, 0x5c, - 0x0f, 0xf4, 0xcf, 0xa2, 0xcf, 0xf5, 0xbd, 0x9c, - 0x69, 0x98, 0x78, 0x3a, 0x25, 0xe4, 0xfd, 0x85, - 0x11, 0xcc, 0x7d, 0xef, 0xeb, 0x74, 0x60, 0xb1, - 0xb7, 0xfb, 0x1f, 0x0e, 0x62, 0xff, 0xfe, 0x09, - 0x0a, 0xc3, 0x80, 0x2f, 0x10, 0x49, 0x89, 0x78, - 0xd2, 0x08, 0xfa, 0x89, 0x22, 0x45, 0x91, 0x21, - 0xbc, 0x90, 0x3e, 0xad, 0xb3, 0x0a, 0xb4, 0x0e, - 0x1c, 0xa1, 0x93, 0x92, 0xd8, 0x72, 0x07, 0x54, - 0x60, 0xe7, 0x91, 0xfc, 0xd9, 0x3c, 0xe1, 0x6f, - 0x08, 0xe4, 0x56, 0xf6, 0x0b, 0xb0, 0x3c, 0x39, - 0x8a, 0x2d, 0x48, 0x44, 0x28, 0x13, 0xca, 0xe9, - 0xf7, 0xa3, 0xb6, 0x8a, 0x5f, 0x31, 0xa9, 0x72, - 0xf2, 0xde, 0x96, 0xf2, 0xb1, 0x53, 0xb1, 0x3e, - 0x24, 0x57, 0xfd, 0x18, 0x45, 0x1f, 0xc5, 0x33, - 0x1b, 0xa4, 0xe8, 0x21, 0xfa, 0x0e, 0xb2, 0xb9, - 0xcb, 0xc7, 0x07, 0x41, 0xdd, 0x2f, 0xb6, 0x6a, - 0x23, 0x18, 0xed, 0xc1, 0xef, 0xe2, 0x4b, 0xec, - 0xc9, 0xba, 0xfb, 0x46, 0x43, 0x90, 0xd7, 0xb5, - 0x68, 0x28, 0x31, 0x2b, 0x8d, 0xa8, 0x51, 0x63, - 0xf7, 0x53, 0x99, 0x19, 0x68, 0x85, 0x66, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x05, 0x58, 0x2e, 0x35, - 0x30, 0x39, 0x00, 0x00, 0x02, 0x3a, 0x30, 0x82, - 0x02, 0x36, 0x30, 0x82, 0x01, 0xe0, 0xa0, 0x03, - 0x02, 0x01, 0x02, 0x02, 0x04, 0x48, 0x59, 0xf1, - 0x92, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, - 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, - 0x30, 0x81, 0xa0, 0x31, 0x0b, 0x30, 0x09, 0x06, - 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4b, 0x52, - 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, - 0x08, 0x13, 0x0a, 0x4b, 0x79, 0x75, 0x6e, 0x67, - 0x67, 0x69, 0x2d, 0x64, 0x6f, 0x31, 0x14, 0x30, - 0x12, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x0b, - 0x53, 0x65, 0x6f, 0x6e, 0x67, 0x6e, 0x61, 0x6d, - 0x2d, 0x73, 0x69, 0x31, 0x1a, 0x30, 0x18, 0x06, - 0x03, 0x55, 0x04, 0x0a, 0x13, 0x11, 0x54, 0x68, - 0x65, 0x20, 0x4e, 0x65, 0x74, 0x74, 0x79, 0x20, - 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x31, - 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x0b, - 0x13, 0x0f, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, - 0x73, 0x31, 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, - 0x04, 0x03, 0x13, 0x27, 0x73, 0x65, 0x63, 0x75, - 0x72, 0x65, 0x63, 0x68, 0x61, 0x74, 0x2e, 0x65, - 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x6e, - 0x65, 0x74, 0x74, 0x79, 0x2e, 0x67, 0x6c, 0x65, - 0x61, 0x6d, 0x79, 0x6e, 0x6f, 0x64, 0x65, 0x2e, - 0x6e, 0x65, 0x74, 0x30, 0x20, 0x17, 0x0d, 0x30, - 0x38, 0x30, 0x36, 0x31, 0x39, 0x30, 0x35, 0x34, - 0x31, 0x33, 0x38, 0x5a, 0x18, 0x0f, 0x32, 0x31, - 0x38, 0x37, 0x31, 0x31, 0x32, 0x34, 0x30, 0x35, - 0x34, 0x31, 0x33, 0x38, 0x5a, 0x30, 0x81, 0xa0, - 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, - 0x06, 0x13, 0x02, 0x4b, 0x52, 0x31, 0x13, 0x30, - 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, - 0x4b, 0x79, 0x75, 0x6e, 0x67, 0x67, 0x69, 0x2d, - 0x64, 0x6f, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, - 0x55, 0x04, 0x07, 0x13, 0x0b, 0x53, 0x65, 0x6f, - 0x6e, 0x67, 0x6e, 0x61, 0x6d, 0x2d, 0x73, 0x69, - 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, - 0x0a, 0x13, 0x11, 0x54, 0x68, 0x65, 0x20, 0x4e, - 0x65, 0x74, 0x74, 0x79, 0x20, 0x50, 0x72, 0x6f, - 0x6a, 0x65, 0x63, 0x74, 0x31, 0x18, 0x30, 0x16, - 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x0f, 0x45, - 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x41, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x31, 0x30, - 0x30, 0x2e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, - 0x27, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x63, - 0x68, 0x61, 0x74, 0x2e, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x74, - 0x79, 0x2e, 0x67, 0x6c, 0x65, 0x61, 0x6d, 0x79, - 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, 0x74, - 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, - 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, - 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, - 0x00, 0xc3, 0xe3, 0x5e, 0x41, 0xa7, 0x87, 0x11, - 0x00, 0x42, 0x2a, 0xb0, 0x4b, 0xed, 0xb2, 0xe0, - 0x23, 0xdb, 0xb1, 0x3d, 0x58, 0x97, 0x35, 0x60, - 0x0b, 0x82, 0x59, 0xd3, 0x00, 0xea, 0xd4, 0x61, - 0xb8, 0x79, 0x3f, 0xb6, 0x3c, 0x12, 0x05, 0x93, - 0x2e, 0x9a, 0x59, 0x68, 0x14, 0x77, 0x3a, 0xc8, - 0x50, 0x25, 0x57, 0xa4, 0x49, 0x18, 0x63, 0x41, - 0xf0, 0x2d, 0x28, 0xec, 0x06, 0xfb, 0xb4, 0x9f, - 0xbf, 0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x0d, - 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, - 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, 0x00, - 0x65, 0x6c, 0x30, 0x01, 0xc2, 0x8e, 0x3e, 0xcb, - 0xb3, 0x77, 0x48, 0xe9, 0x66, 0x61, 0x9a, 0x40, - 0x86, 0xaf, 0xf6, 0x03, 0xeb, 0xba, 0x6a, 0xf2, - 0xfd, 0xe2, 0xaf, 0x36, 0x5e, 0x7b, 0xaa, 0x22, - 0x04, 0xdd, 0x2c, 0x20, 0xc4, 0xfc, 0xdd, 0xd0, - 0x82, 0x20, 0x1c, 0x3d, 0xd7, 0x9e, 0x5e, 0x5c, - 0x92, 0x5a, 0x76, 0x71, 0x28, 0xf5, 0x07, 0x7d, - 0xa2, 0x81, 0xba, 0x77, 0x9f, 0x2a, 0xd9, 0x44, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x6d, 0x79, - 0x6b, 0x65, 0x79, 0x00, 0x00, 0x01, 0x1a, 0x9f, - 0x5b, 0x56, 0xa0, 0x00, 0x00, 0x01, 0x99, 0x30, - 0x82, 0x01, 0x95, 0x30, 0x0e, 0x06, 0x0a, 0x2b, - 0x06, 0x01, 0x04, 0x01, 0x2a, 0x02, 0x11, 0x01, - 0x01, 0x05, 0x00, 0x04, 0x82, 0x01, 0x81, 0x29, - 0xa8, 0xb6, 0x08, 0x0c, 0x85, 0x75, 0x3e, 0xdd, - 0xb5, 0xe5, 0x1a, 0x87, 0x68, 0xd1, 0x90, 0x4b, - 0x29, 0x31, 0xee, 0x90, 0xbc, 0x9d, 0x73, 0xa0, - 0x3f, 0xe9, 0x0b, 0xa4, 0xef, 0x30, 0x9b, 0x36, - 0x9a, 0xb2, 0x54, 0x77, 0x81, 0x07, 0x4b, 0xaa, - 0xa5, 0x77, 0x98, 0xe1, 0xeb, 0xb5, 0x7c, 0x4e, - 0x48, 0xd5, 0x08, 0xfc, 0x2c, 0x36, 0xe2, 0x65, - 0x03, 0xac, 0xe5, 0xf3, 0x96, 0xb7, 0xd0, 0xb5, - 0x3b, 0x92, 0xe4, 0x14, 0x05, 0x7a, 0x6a, 0x92, - 0x56, 0xfe, 0x4e, 0xab, 0xd3, 0x0e, 0x32, 0x04, - 0x22, 0x22, 0x74, 0x47, 0x7d, 0xec, 0x21, 0x99, - 0x30, 0x31, 0x64, 0x46, 0x64, 0x9b, 0xc7, 0x13, - 0xbf, 0xbe, 0xd0, 0x31, 0x49, 0xe7, 0x3c, 0xbf, - 0xba, 0xb1, 0x20, 0xf9, 0x42, 0xf4, 0xa9, 0xa9, - 0xe5, 0x13, 0x65, 0x32, 0xbf, 0x7c, 0xcc, 0x91, - 0xd3, 0xfd, 0x24, 0x47, 0x0b, 0xe5, 0x53, 0xad, - 0x50, 0x30, 0x56, 0xd1, 0xfa, 0x9c, 0x37, 0xa8, - 0xc1, 0xce, 0xf6, 0x0b, 0x18, 0xaa, 0x7c, 0xab, - 0xbd, 0x1f, 0xdf, 0xe4, 0x80, 0xb8, 0xa7, 0xe0, - 0xad, 0x7d, 0x50, 0x74, 0xf1, 0x98, 0x78, 0xbc, - 0x58, 0xb9, 0xc2, 0x52, 0xbe, 0xd2, 0x5b, 0x81, - 0x94, 0x83, 0x8f, 0xb9, 0x4c, 0xee, 0x01, 0x2b, - 0x5e, 0xc9, 0x6e, 0x9b, 0xf5, 0x63, 0x69, 0xe4, - 0xd8, 0x0b, 0x47, 0xd8, 0xfd, 0xd8, 0xe0, 0xed, - 0xa8, 0x27, 0x03, 0x74, 0x1e, 0x5d, 0x32, 0xe6, - 0x5c, 0x63, 0xc2, 0xfb, 0x3f, 0xee, 0xb4, 0x13, - 0xc6, 0x0e, 0x6e, 0x74, 0xe0, 0x22, 0xac, 0xce, - 0x79, 0xf9, 0x43, 0x68, 0xc1, 0x03, 0x74, 0x2b, - 0xe1, 0x18, 0xf8, 0x7f, 0x76, 0x9a, 0xea, 0x82, - 0x3f, 0xc2, 0xa6, 0xa7, 0x4c, 0xfe, 0xae, 0x29, - 0x3b, 0xc1, 0x10, 0x7c, 0xd5, 0x77, 0x17, 0x79, - 0x5f, 0xcb, 0xad, 0x1f, 0xd8, 0xa1, 0xfd, 0x90, - 0xe1, 0x6b, 0xb2, 0xef, 0xb9, 0x41, 0x26, 0xa4, - 0x0b, 0x4f, 0xc6, 0x83, 0x05, 0x6f, 0xf0, 0x64, - 0x40, 0xe1, 0x44, 0xc4, 0xf9, 0x40, 0x2b, 0x3b, - 0x40, 0xdb, 0xaf, 0x35, 0xa4, 0x9b, 0x9f, 0xc4, - 0x74, 0x07, 0xe5, 0x18, 0x60, 0xc5, 0xfe, 0x15, - 0x0e, 0x3a, 0x25, 0x2a, 0x11, 0xee, 0x78, 0x2f, - 0xb8, 0xd1, 0x6e, 0x4e, 0x3c, 0x0a, 0xb5, 0xb9, - 0x40, 0x86, 0x27, 0x6d, 0x8f, 0x53, 0xb7, 0x77, - 0x36, 0xec, 0x5d, 0xed, 0x32, 0x40, 0x43, 0x82, - 0xc3, 0x52, 0x58, 0xc4, 0x26, 0x39, 0xf3, 0xb3, - 0xad, 0x58, 0xab, 0xb7, 0xf7, 0x8e, 0x0e, 0xba, - 0x8e, 0x78, 0x9d, 0xbf, 0x58, 0x34, 0xbd, 0x77, - 0x73, 0xa6, 0x50, 0x55, 0x00, 0x60, 0x26, 0xbf, - 0x6d, 0xb4, 0x98, 0x8a, 0x18, 0x83, 0x89, 0xf8, - 0xcd, 0x0d, 0x49, 0x06, 0xae, 0x51, 0x6e, 0xaf, - 0xbd, 0xe2, 0x07, 0x13, 0xd8, 0x64, 0xcc, 0xbf, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x58, 0x2e, - 0x35, 0x30, 0x39, 0x00, 0x00, 0x02, 0x34, 0x30, - 0x82, 0x02, 0x30, 0x30, 0x82, 0x01, 0xda, 0xa0, - 0x03, 0x02, 0x01, 0x02, 0x02, 0x04, 0x48, 0x59, - 0xf2, 0x84, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, - 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, - 0x00, 0x30, 0x81, 0x9d, 0x31, 0x0b, 0x30, 0x09, - 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4b, - 0x52, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, - 0x04, 0x08, 0x13, 0x0a, 0x4b, 0x79, 0x75, 0x6e, - 0x67, 0x67, 0x69, 0x2d, 0x64, 0x6f, 0x31, 0x14, - 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, - 0x0b, 0x53, 0x65, 0x6f, 0x6e, 0x67, 0x6e, 0x61, - 0x6d, 0x2d, 0x73, 0x69, 0x31, 0x1a, 0x30, 0x18, - 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x11, 0x54, - 0x68, 0x65, 0x20, 0x4e, 0x65, 0x74, 0x74, 0x79, - 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, - 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, - 0x0b, 0x13, 0x0c, 0x43, 0x6f, 0x6e, 0x74, 0x72, - 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x73, 0x31, - 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, 0x04, 0x03, - 0x13, 0x27, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, - 0x63, 0x68, 0x61, 0x74, 0x2e, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x6e, 0x65, 0x74, - 0x74, 0x79, 0x2e, 0x67, 0x6c, 0x65, 0x61, 0x6d, - 0x79, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, - 0x74, 0x30, 0x20, 0x17, 0x0d, 0x30, 0x38, 0x30, - 0x36, 0x31, 0x39, 0x30, 0x35, 0x34, 0x35, 0x34, - 0x30, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x38, 0x37, - 0x31, 0x31, 0x32, 0x33, 0x30, 0x35, 0x34, 0x35, - 0x34, 0x30, 0x5a, 0x30, 0x81, 0x9d, 0x31, 0x0b, - 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, - 0x02, 0x4b, 0x52, 0x31, 0x13, 0x30, 0x11, 0x06, - 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, 0x4b, 0x79, - 0x75, 0x6e, 0x67, 0x67, 0x69, 0x2d, 0x64, 0x6f, - 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, - 0x07, 0x13, 0x0b, 0x53, 0x65, 0x6f, 0x6e, 0x67, - 0x6e, 0x61, 0x6d, 0x2d, 0x73, 0x69, 0x31, 0x1a, - 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, - 0x11, 0x54, 0x68, 0x65, 0x20, 0x4e, 0x65, 0x74, - 0x74, 0x79, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, - 0x55, 0x04, 0x0b, 0x13, 0x0c, 0x43, 0x6f, 0x6e, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, - 0x73, 0x31, 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, - 0x04, 0x03, 0x13, 0x27, 0x73, 0x65, 0x63, 0x75, - 0x72, 0x65, 0x63, 0x68, 0x61, 0x74, 0x2e, 0x65, - 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x6e, - 0x65, 0x74, 0x74, 0x79, 0x2e, 0x67, 0x6c, 0x65, - 0x61, 0x6d, 0x79, 0x6e, 0x6f, 0x64, 0x65, 0x2e, - 0x6e, 0x65, 0x74, 0x30, 0x5c, 0x30, 0x0d, 0x06, - 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, - 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, - 0x48, 0x02, 0x41, 0x00, 0x95, 0xb3, 0x47, 0x17, - 0x95, 0x0f, 0x57, 0xcf, 0x66, 0x72, 0x0a, 0x7e, - 0x5b, 0x54, 0xea, 0x8c, 0x6f, 0x79, 0xde, 0x94, - 0xac, 0x0b, 0x5a, 0xd4, 0xd6, 0x1b, 0x58, 0x12, - 0x1a, 0x16, 0x3d, 0xfe, 0xdf, 0xa5, 0x2b, 0x86, - 0xbc, 0x64, 0xd4, 0x80, 0x1e, 0x3f, 0xf9, 0xe2, - 0x04, 0x03, 0x79, 0x9b, 0xc1, 0x5c, 0xf0, 0xf1, - 0xf3, 0xf1, 0xe3, 0xbf, 0x3f, 0xc0, 0x1f, 0xdd, - 0xdb, 0xc0, 0x5b, 0x21, 0x02, 0x03, 0x01, 0x00, - 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, - 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, - 0x03, 0x41, 0x00, 0x02, 0xd7, 0xdd, 0xbd, 0x0c, - 0x8e, 0x21, 0x20, 0xef, 0x9e, 0x4f, 0x1f, 0xf5, - 0x49, 0xf1, 0xae, 0x58, 0x9b, 0x94, 0x3a, 0x1f, - 0x70, 0x33, 0xf0, 0x9b, 0xbb, 0xe9, 0xc0, 0xf3, - 0x72, 0xcb, 0xde, 0xb6, 0x56, 0x72, 0xcc, 0x1c, - 0xf0, 0xd6, 0x5a, 0x2a, 0xbc, 0xa1, 0x7e, 0x23, - 0x83, 0xe9, 0xe7, 0xcf, 0x9e, 0xa5, 0xf9, 0xcc, - 0xc2, 0x61, 0xf4, 0xdb, 0x40, 0x93, 0x1d, 0x63, - 0x8a, 0x50, 0x4c, 0x11, 0x39, 0xb1, 0x91, 0xc1, - 0xe6, 0x9d, 0xd9, 0x1a, 0x62, 0x1b, 0xb8, 0xd3, - 0xd6, 0x9a, 0x6d, 0xb9, 0x8e, 0x15, 0x51 }; - - public static InputStream asInputStream() { - byte[] data = new byte[DATA.length]; - for (int i = 0; i < data.length; i ++) { - data[i] = (byte) DATA[i]; - } - return new ByteArrayInputStream(data); - } - - public static char[] getCertificatePassword() { - return "secret".toCharArray(); - } - - public static char[] getKeyStorePassword() { - return "secret".toCharArray(); - } - - private BogusKeyStore() { - // Unused - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketStringEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketStringEchoTest.java deleted file mode 100644 index 154ae76717..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketStringEchoTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport; - -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.*; -import io.netty.channel.sctp.codec.SctpFrameDecoder; -import io.netty.channel.sctp.codec.SctpFrameEncoder; -import io.netty.handler.codec.DelimiterBasedFrameDecoder; -import io.netty.handler.codec.Delimiters; -import io.netty.handler.codec.string.StringDecoder; -import io.netty.handler.codec.string.StringEncoder; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.CharsetUtil; -import io.netty.util.internal.ExecutorUtil; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractSocketStringEchoTest { - - static final Random random = new Random(); - static final String[] data = new String[1024]; - - private static ExecutorService executor; - - static { - for (int i = 0; i < data.length; i ++) { - int eLen = random.nextInt(512); - char[] e = new char[eLen]; - for (int j = 0; j < eLen; j ++) { - e[j] = (char) ('a' + random.nextInt(26)); - } - - data[i] = new String(e); - } - } - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); - protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); - - @Test - public void testStringEcho() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); - ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); - - EchoHandler sh = new EchoHandler(); - EchoHandler ch = new EchoHandler(); - - sb.pipeline().addFirst("sctp-decoder", new SctpFrameDecoder()); - sb.pipeline().addFirst("sctp-encoder", new SctpFrameEncoder()); - sb.pipeline().addLast("framer", new DelimiterBasedFrameDecoder(512, Delimiters.lineDelimiter())); - sb.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.ISO_8859_1)); - sb.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.ISO_8859_1)); - sb.pipeline().addLast("handler", sh); - - cb.pipeline().addFirst("sctp-decoder", new SctpFrameDecoder()); - cb.pipeline().addFirst("sctp-encoder", new SctpFrameEncoder()); - cb.pipeline().addLast("framer", new DelimiterBasedFrameDecoder(512, Delimiters.lineDelimiter())); - cb.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.ISO_8859_1)); - cb.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.ISO_8859_1)); - cb.pipeline().addLast("handler", ch); - - Channel sc = sb.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); - - ChannelFuture ccf = cb.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, port)); - assertTrue(ccf.awaitUninterruptibly().isSuccess()); - - Channel cc = ccf.channel(); - for (String element : data) { - String delimiter = random.nextBoolean() ? "\r\n" : "\n"; - cc.write(element + delimiter); - } - - while (ch.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - - while (sh.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - sc.close().awaitUninterruptibly(); - - if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { - throw sh.exception.get(); - } - if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { - throw ch.exception.get(); - } - if (sh.exception.get() != null) { - throw sh.exception.get(); - } - if (ch.exception.get() != null) { - throw ch.exception.get(); - } - } - - private static class EchoHandler extends SimpleChannelUpstreamHandler { - volatile Channel channel; - final AtomicReference exception = new AtomicReference(); - volatile int counter; - - EchoHandler() { - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channel = e.channel(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - - String m = (String) e.getMessage(); - assertEquals(data[counter], m); - - if (channel.getParent() != null) { - String delimiter = random.nextBoolean() ? "\r\n" : "\n"; - channel.write(m + delimiter); - } - - counter ++; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - if (exception.compareAndSet(null, e.cause())) { - e.channel().close(); - } - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpClientBootstrapTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpClientBootstrapTest.java deleted file mode 100644 index c4769b60c1..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpClientBootstrapTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.testsuite.transport.AbstractSocketClientBootstrapTest; - -import java.util.concurrent.Executor; - -public class SctpClientBootstrapTest extends AbstractSocketClientBootstrapTest { - @Override - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpCompatibleObjectStreamEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpCompatibleObjectStreamEchoTest.java deleted file mode 100644 index 2bfb16595c..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpCompatibleObjectStreamEchoTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.testsuite.transport.AbstractSocketCompatibleObjectStreamEchoTest; - -import java.util.concurrent.Executor; - -public class SctpCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest { - @Override - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } - - @Override - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java deleted file mode 100644 index a5cc3cab20..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.testsuite.transport.AbstractSocketEchoTest; - -import java.util.concurrent.Executor; - -public class SctpEchoTest extends AbstractSocketEchoTest { - @Override - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } - - @Override - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpFixedLengthEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpFixedLengthEchoTest.java deleted file mode 100644 index 44a2ea1bb4..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpFixedLengthEchoTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.testsuite.transport.AbstractSocketFixedLengthEchoTest; - -import java.util.concurrent.Executor; - -public class SctpFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest { - @Override - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } - - @Override - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } - -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiHomingEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiHomingEchoTest.java deleted file mode 100644 index 14f4934138..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiHomingEchoTest.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import static org.junit.Assert.*; -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFactory; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelStateEvent; -import io.netty.channel.ExceptionEvent; -import io.netty.channel.MessageEvent; -import io.netty.channel.sctp.SctpChannel; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.channel.sctp.SctpNotificationEvent; -import io.netty.channel.sctp.SctpServerChannel; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.channel.sctp.codec.SctpFrameDecoder; -import io.netty.channel.sctp.codec.SctpFrameEncoder; -import io.netty.channel.sctp.handler.SimpleSctpChannelHandler; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -public class SctpMultiHomingEchoTest { - private static final Random random = new Random(); - static final byte[] data = new byte[4096];//could not test ultra jumbo frames - - private static ExecutorService executor; - - static { - random.nextBytes(data); - } - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } - - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } - - @Test(timeout = 15000) - public void testSimpleEcho() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); - - ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); - - - EchoHandler sh = new EchoHandler(); - EchoHandler ch = new EchoHandler(); - - sb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - sb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - sb.pipeline().addLast("handler", sh); - - cb.pipeline().addLast("sctp-decoder", new SctpFrameDecoder()); - cb.pipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - cb.pipeline().addLast("handler", ch); - - SctpServerChannel serverChannel = (SctpServerChannel) sb.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - int port = serverChannel.getLocalAddress().getPort(); - - ChannelFuture multiHomingServerBindFuture = serverChannel.bindAddress(InetAddress.getByName(SctpTestUtil.LOOP_BACK2)); - assertTrue(multiHomingServerBindFuture.awaitUninterruptibly().isSuccess()); - - ChannelFuture bindFuture = cb.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - assertTrue(bindFuture.awaitUninterruptibly().isSuccess()); - - SctpChannel clientChannel = (SctpChannel) bindFuture.channel(); - - //adding a muti-homing address to client channel - ChannelFuture multiHomingBindFuture = clientChannel.bindAddress(InetAddress.getByName(SctpTestUtil.LOOP_BACK2)); - assertTrue(multiHomingBindFuture.awaitUninterruptibly().isSuccess()); - - ChannelFuture connectFuture = clientChannel.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, port)); - assertTrue(connectFuture.awaitUninterruptibly().isSuccess()); - - assertEquals("Client local addresses count should be 2", 2, clientChannel.getAllLocalAddresses().size()); - assertEquals("Client remote addresses count should be 2", 2, clientChannel.getAllRemoteAddresses().size()); - - assertEquals("Server local addresses count should be 2", 2, serverChannel.getAllLocalAddresses().size()); - - for (int i = 0; i < data.length;) { - int length = Math.min(random.nextInt(1024 * 64), data.length - i); - clientChannel.write(ChannelBuffers.wrappedBuffer(data, i, length)); - i += length; - } - - while (ch.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(5); - } catch (InterruptedException e) { - // Ignore. - } - } - - while (sh.counter < data.length) { - if (sh.exception.get() != null) { - break; - } - if (ch.exception.get() != null) { - break; - } - - try { - Thread.sleep(5); - } catch (InterruptedException e) { - // Ignore. - } - } - - //removing already added muti-homing address from client channel - ChannelFuture multiHomingUnbindFuture = clientChannel.unbindAddress(InetAddress.getByName(SctpTestUtil.LOOP_BACK2)); - assertTrue(multiHomingUnbindFuture.awaitUninterruptibly().isSuccess()); - - ChannelFuture multiHomingServerUnbindFuture = serverChannel.unbindAddress(InetAddress.getByName(SctpTestUtil.LOOP_BACK2)); - assertTrue(multiHomingServerUnbindFuture.awaitUninterruptibly().isSuccess()); - - - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - serverChannel.close().awaitUninterruptibly(); - - if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { - throw sh.exception.get(); - } - if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { - throw ch.exception.get(); - } - if (sh.exception.get() != null) { - throw sh.exception.get(); - } - if (ch.exception.get() != null) { - throw ch.exception.get(); - } - } - - private static class EchoHandler extends SimpleSctpChannelHandler { - volatile Channel channel; - final AtomicReference exception = new AtomicReference(); - volatile int counter; - - EchoHandler() { - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channel = e.channel(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - ChannelBuffer m = (ChannelBuffer) e.getMessage(); - byte[] actual = new byte[m.readableBytes()]; - m.getBytes(0, actual); - - int lastIdx = counter; - for (int i = 0; i < actual.length; i ++) { - assertEquals(data[i + lastIdx], actual[i]); - } - - if (channel.getParent() != null) { - channel.write(m); - } - - counter += actual.length; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - if (exception.compareAndSet(null, e.cause())) { - e.channel().close(); - } - } - - @Override - public void sctpNotificationReceived(ChannelHandlerContext ctx, SctpNotificationEvent event) { - System.out.println("SCTP notification event received :" + event); - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiStreamingEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiStreamingEchoTest.java deleted file mode 100644 index 51747e53db..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiStreamingEchoTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.bootstrap.ClientBootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; -import io.netty.channel.*; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.channel.sctp.SctpFrame; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.testsuite.util.SctpTestUtil; -import io.netty.util.internal.ExecutorUtil; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class SctpMultiStreamingEchoTest { - private static final Random random = new Random(); - - static final SctpFrame [] sctpFrames = new SctpFrame [4]; - - - private static ExecutorService executor; - - static ChannelBuffer makeRandomFrame() { - byte [] data = new byte[512]; - random.nextBytes(data); - return ChannelBuffers.wrappedBuffer(data); - } - - static { - int protocolId = 0;//unknown - for(int streamNumber = 0; streamNumber <= 3; streamNumber ++) { - sctpFrames [streamNumber] = new SctpFrame(protocolId, streamNumber, makeRandomFrame()); - } - } - - @BeforeClass - public static void init() { - executor = Executors.newCachedThreadPool(); - } - - @AfterClass - public static void destroy() { - ExecutorUtil.terminate(executor); - } - - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } - - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } - - @Test(timeout = 10000) - public void testMultiStreamingEcho() throws Throwable { - Assume.assumeTrue(SctpTestUtil.isSctpSupported()); - - ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); - - ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); - cb.setOption("sctpInitMaxStreams", 4); - - EchoHandler sh = new EchoHandler(); - EchoHandler ch = new EchoHandler(); - - sb.pipeline().addLast("handler", sh); - - cb.pipeline().addLast("handler", ch); - - Channel sc = sb.bind(new InetSocketAddress(SctpTestUtil.LOOP_BACK, 0)); - int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); - - ChannelFuture ccf = cb.connect(new InetSocketAddress(SctpTestUtil.LOOP_BACK, port)); - assertTrue(ccf.awaitUninterruptibly().isSuccess()); - - Channel cc = ccf.channel(); - - for(SctpFrame sctpFrame: sctpFrames) { - cc.write(sctpFrame); - } - - while (sh.counter < sctpFrames.length) { - Thread.sleep(5); - } - while (ch.counter < sctpFrames.length) { - Thread.sleep(5); - } - - assertEquals(sctpFrames.length, sh.counter); - assertEquals(sctpFrames.length, ch.counter); - - - sh.channel.close().awaitUninterruptibly(); - ch.channel.close().awaitUninterruptibly(); - sc.close().awaitUninterruptibly(); - - if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { - throw sh.exception.get(); - } - if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { - throw ch.exception.get(); - } - if (sh.exception.get() != null) { - throw sh.exception.get(); - } - if (ch.exception.get() != null) { - throw ch.exception.get(); - } - } - - private static class EchoHandler extends SimpleChannelUpstreamHandler { - volatile Channel channel; - final AtomicReference exception = new AtomicReference(); - volatile int counter; - - EchoHandler() { - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - channel = e.channel(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - SctpFrame sctpFrame = (SctpFrame) e.getMessage(); - - assertEquals(sctpFrames[counter], sctpFrame); - - if (channel.getParent() != null) { - channel.write(sctpFrame); - } - - counter ++ ; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - if (exception.compareAndSet(null, e.cause())) { - e.channel().close(); - } - } - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpObjectStreamEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpObjectStreamEchoTest.java deleted file mode 100644 index bd3ed20428..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpObjectStreamEchoTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.testsuite.transport.AbstractSocketObjectStreamEchoTest; - -import java.util.concurrent.Executor; - -public class SctpObjectStreamEchoTest extends AbstractSocketObjectStreamEchoTest { - @Override - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } - - @Override - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpServerBootstrapTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpServerBootstrapTest.java deleted file mode 100644 index 2e450c7178..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpServerBootstrapTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.testsuite.transport.AbstractSocketServerBootstrapTest; - -import java.util.concurrent.Executor; - -public class SctpServerBootstrapTest extends AbstractSocketServerBootstrapTest { - @Override - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpSslEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpSslEchoTest.java deleted file mode 100644 index 1bdfc323f7..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpSslEchoTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.testsuite.transport.AbstractSocketSslEchoTest; - -import java.util.concurrent.Executor; - -public class SctpSslEchoTest extends AbstractSocketSslEchoTest { - @Override - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } - - @Override - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpStringEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpStringEchoTest.java deleted file mode 100644 index a0709c176d..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpStringEchoTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.transport.sctp; - -import io.netty.channel.ChannelFactory; -import io.netty.channel.sctp.SctpClientSocketChannelFactory; -import io.netty.channel.sctp.SctpServerSocketChannelFactory; -import io.netty.testsuite.transport.AbstractSocketStringEchoTest; - -import java.util.concurrent.Executor; - -public class SctpStringEchoTest extends AbstractSocketStringEchoTest { - @Override - protected ChannelFactory newServerSocketChannelFactory(Executor executor) { - return new SctpServerSocketChannelFactory(executor); - } - - @Override - protected ChannelFactory newClientSocketChannelFactory(Executor executor) { - return new SctpClientSocketChannelFactory(executor); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/util/DummyHandler.java b/transport-sctp/src/test/java/io/netty/testsuite/util/DummyHandler.java deleted file mode 100644 index 5ec679a904..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/util/DummyHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.util; - -import io.netty.channel.ChannelDownstreamHandler; -import io.netty.channel.ChannelEvent; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelUpstreamHandler; - -public class DummyHandler implements ChannelUpstreamHandler, ChannelDownstreamHandler { - - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) - throws Exception { - ctx.sendUpstream(e); - } - - public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) - throws Exception { - ctx.sendDownstream(e); - } -} diff --git a/transport-sctp/src/test/java/io/netty/testsuite/util/SctpTestUtil.java b/transport-sctp/src/test/java/io/netty/testsuite/util/SctpTestUtil.java deleted file mode 100644 index 5a3b3abd63..0000000000 --- a/transport-sctp/src/test/java/io/netty/testsuite/util/SctpTestUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.testsuite.util; - -import java.util.Locale; - -public class SctpTestUtil { - //io.netty.util.SocketAddresses.LOCALHOST interface has MTU SIZE issues with SCTP, we have to use local loop back interface for testing - public final static String LOOP_BACK = "127.0.0.1"; - public final static String LOOP_BACK2 = "127.0.0.2"; - - /** - * Return true if SCTP is supported by the running os. - * - */ - public static boolean isSctpSupported() { - String os = System.getProperty("os.name").toLowerCase(Locale.UK); - if (os.equals("unix") || os.equals("linux") || os.equals("sun") || os.equals("solaris")) { - return true; - } - return false; - } - -}