diff --git a/transport/pom.xml b/transport/pom.xml index fc35ea38d1..4436015e3c 100644 --- a/transport/pom.xml +++ b/transport/pom.xml @@ -35,5 +35,19 @@ ${project.version} + + + + + maven-jar-plugin + + + + **/com/** + + + + + diff --git a/transport/src/main/java/com/sun/nio/sctp/AbstractNotificationHandler.java b/transport/src/main/java/com/sun/nio/sctp/AbstractNotificationHandler.java new file mode 100644 index 0000000000..bade95b264 --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/AbstractNotificationHandler.java @@ -0,0 +1,42 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/Association.java b/transport/src/main/java/com/sun/nio/sctp/Association.java new file mode 100644 index 0000000000..e190295f5e --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/Association.java @@ -0,0 +1,22 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/AssociationChangeNotification.java b/transport/src/main/java/com/sun/nio/sctp/AssociationChangeNotification.java new file mode 100644 index 0000000000..8b8098c851 --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/AssociationChangeNotification.java @@ -0,0 +1,22 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/HandlerResult.java b/transport/src/main/java/com/sun/nio/sctp/HandlerResult.java new file mode 100644 index 0000000000..f75088140b --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/HandlerResult.java @@ -0,0 +1,25 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/MessageInfo.java b/transport/src/main/java/com/sun/nio/sctp/MessageInfo.java new file mode 100644 index 0000000000..1f7eaccbd0 --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/MessageInfo.java @@ -0,0 +1,38 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/Notification.java b/transport/src/main/java/com/sun/nio/sctp/Notification.java new file mode 100644 index 0000000000..32f1a809c9 --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/Notification.java @@ -0,0 +1,20 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/NotificationHandler.java b/transport/src/main/java/com/sun/nio/sctp/NotificationHandler.java new file mode 100644 index 0000000000..1b86c0c57e --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/NotificationHandler.java @@ -0,0 +1,19 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/PeerAddressChangeNotification.java b/transport/src/main/java/com/sun/nio/sctp/PeerAddressChangeNotification.java new file mode 100644 index 0000000000..7c61551edb --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/PeerAddressChangeNotification.java @@ -0,0 +1,22 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/SctpChannel.java b/transport/src/main/java/com/sun/nio/sctp/SctpChannel.java new file mode 100644 index 0000000000..4d0c906d0e --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/SctpChannel.java @@ -0,0 +1,57 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/SctpServerChannel.java b/transport/src/main/java/com/sun/nio/sctp/SctpServerChannel.java new file mode 100644 index 0000000000..eaf617e5f7 --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/SctpServerChannel.java @@ -0,0 +1,50 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/SctpSocketOption.java b/transport/src/main/java/com/sun/nio/sctp/SctpSocketOption.java new file mode 100644 index 0000000000..66ca504ceb --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/SctpSocketOption.java @@ -0,0 +1,21 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/SctpStandardSocketOptions.java b/transport/src/main/java/com/sun/nio/sctp/SctpStandardSocketOptions.java new file mode 100644 index 0000000000..0cbca3061f --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/SctpStandardSocketOptions.java @@ -0,0 +1,51 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/SendFailedNotification.java b/transport/src/main/java/com/sun/nio/sctp/SendFailedNotification.java new file mode 100644 index 0000000000..47bbe89ad9 --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/SendFailedNotification.java @@ -0,0 +1,22 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/ShutdownNotification.java b/transport/src/main/java/com/sun/nio/sctp/ShutdownNotification.java new file mode 100644 index 0000000000..d0f408c2da --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/ShutdownNotification.java @@ -0,0 +1,22 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java b/transport/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java new file mode 100644 index 0000000000..8cd99f1783 --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java @@ -0,0 +1,41 @@ +/* + * 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/src/main/java/com/sun/nio/sctp/package-info.java b/transport/src/main/java/com/sun/nio/sctp/package-info.java new file mode 100644 index 0000000000..beefdb38ca --- /dev/null +++ b/transport/src/main/java/com/sun/nio/sctp/package-info.java @@ -0,0 +1,22 @@ +/* + * 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/src/main/java/io/netty/channel/socket/DefaultSctpChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/DefaultSctpChannelConfig.java new file mode 100644 index 0000000000..baab403715 --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/DefaultSctpChannelConfig.java @@ -0,0 +1,156 @@ +/* + * 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; + +import com.sun.nio.sctp.SctpChannel; +import io.netty.channel.ChannelException; +import io.netty.channel.ChannelOption; +import io.netty.channel.DefaultChannelConfig; + +import java.io.IOException; +import java.util.Map; + +import com.sun.nio.sctp.SctpStandardSocketOptions; +import static io.netty.channel.ChannelOption.*; + +/** + * The default {@link SctpChannelConfig} implementation for SCTP. + */ +class DefaultSctpChannelConfig extends DefaultChannelConfig implements SctpChannelConfig { + + private SctpChannel channel; + + DefaultSctpChannelConfig(SctpChannel channel) { + if (channel == null) { + throw new NullPointerException("channel"); + } + this.channel = channel; + } + + @Override + public Map, Object> getOptions() { + 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()); + } + 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) { + setInitMaxStreams((SctpStandardSocketOptions.InitMaxStreams) value); + } else { + return super.setOption(option, value); + } + + return true; + } + + + @Override + public boolean isSctpNoDelay() { + try { + return channel.getOption(SctpStandardSocketOptions.SCTP_NODELAY); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setSctpNoDelay(boolean sctpNoDelay) { + try { + channel.setOption(SctpStandardSocketOptions.SCTP_NODELAY, sctpNoDelay); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public int getSendBufferSize() { + try { + return channel.getOption(SctpStandardSocketOptions.SO_SNDBUF); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setSendBufferSize(int sendBufferSize) { + try { + channel.setOption(SctpStandardSocketOptions.SO_SNDBUF, sendBufferSize); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public int getReceiveBufferSize() { + try { + return channel.getOption(SctpStandardSocketOptions.SO_RCVBUF); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setReceiveBufferSize(int receiveBufferSize) { + try { + channel.setOption(SctpStandardSocketOptions.SO_RCVBUF, receiveBufferSize); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public SctpStandardSocketOptions.InitMaxStreams getInitMaxStreams() { + try { + return channel.getOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS); + } catch (IOException e) { + throw new ChannelException(e); + } + } + + @Override + public void setInitMaxStreams(SctpStandardSocketOptions.InitMaxStreams initMaxStreams) { + try { + channel.setOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS, initMaxStreams); + } catch (IOException e) { + throw new ChannelException(e); + } + } +} diff --git a/transport/src/main/java/io/netty/channel/socket/SctpChannel.java b/transport/src/main/java/io/netty/channel/socket/SctpChannel.java new file mode 100644 index 0000000000..bc726cca55 --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/SctpChannel.java @@ -0,0 +1,93 @@ +/* + * 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; + +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; + +/** + * A SCTP/IP {@link io.netty.channel.Channel} + */ +public interface SctpChannel extends Channel { + + /** + * Bind a address to the already bound channel to enable multi-homing. + * The Channel bust be bound and yet to be connected. + */ + ChannelFuture bindAddress(InetAddress localAddress); + + + /** + * Unbind the address from channel's multi-homing address list. + * The address should be added already in multi-homing address list. + */ + ChannelFuture unbindAddress(InetAddress localAddress); + + /** + * Returns the underlying SCTP association. + */ + Association association(); + + /** + * Return the (primary) local address of the SCTP channel. + * + * Please note that, this return the first local address in the underlying SCTP Channel's + * local address iterator to support Netty Channel API. In other words, its the application's + * responsibility to keep track of it's local primary address. + * + * (To set a local address as primary, the application can request by calling local SCTP stack, + * with SctpStandardSocketOption.SCTP_PRIMARY_ADDR option). + */ + @Override + InetSocketAddress localAddress(); + + /** + * Return all local addresses of the SCTP channel. + * Please note that, it will return more than one address if this channel is using multi-homing + */ + Set allLocalAddresses(); + + /** + * Returns the {@link SctpChannelConfig} configuration of the channel. + */ + @Override + SctpChannelConfig config(); + + /** + * Return the (primary) remote address of the SCTP channel. + * + * Please note that, this return the first remote address in the underlying SCTP Channel's + * remote address iterator to support Netty Channel API. In other words, its the application's + * responsibility to keep track of it's peer's primary address. + * + * (The application can request it's remote peer to set a specific address as primary by + * calling the local SCTP stack with SctpStandardSocketOption.SCTP_SET_PEER_PRIMARY_ADDR option) + */ + @Override + InetSocketAddress remoteAddress(); + + + /** + * Return all remote addresses of the SCTP server channel. + * Please note that, it will return more than one address if the remote is using multi-homing. + */ + Set allRemoteAddresses(); +} diff --git a/transport/src/main/java/io/netty/channel/socket/SctpChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/SctpChannelConfig.java new file mode 100644 index 0000000000..d75670721c --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/SctpChannelConfig.java @@ -0,0 +1,94 @@ +/* + * 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; + +import io.netty.channel.ChannelConfig; + +import static com.sun.nio.sctp.SctpStandardSocketOptions.InitMaxStreams; + +/** + * A {@link io.netty.channel.ChannelConfig} for a {@link SctpChannel}. + *

+ *

Available options

+ *

+ * In addition to the options provided by {@link io.netty.channel.ChannelConfig}, + * {@link 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(com.sun.nio.sctp.SctpStandardSocketOptions.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/src/main/java/io/netty/channel/socket/SctpFrame.java b/transport/src/main/java/io/netty/channel/socket/SctpFrame.java new file mode 100644 index 0000000000..469fc8e869 --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/SctpFrame.java @@ -0,0 +1,120 @@ +/* + * 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; + +import com.sun.nio.sctp.MessageInfo; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; + +/** + * Representation of SCTP Data Chunk + */ +public final class SctpFrame { + private final int streamIdentifier; + private final int protocolIdentifier; + + private final ByteBuf 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, ByteBuf payloadBuffer) { + this.protocolIdentifier = protocolIdentifier; + this.streamIdentifier = streamIdentifier; + this.payloadBuffer = payloadBuffer; + } + + public SctpFrame(MessageInfo msgInfo, ByteBuf 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 ByteBuf getPayloadBuffer() { + if (payloadBuffer.readable()) { + return payloadBuffer.slice(); + } else { + return Unpooled.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(ByteBufUtil.hexDump(getPayloadBuffer())). + append('}').toString(); + } +} diff --git a/transport/src/main/java/io/netty/channel/socket/SctpServerChannel.java b/transport/src/main/java/io/netty/channel/socket/SctpServerChannel.java new file mode 100644 index 0000000000..b31ebe39b4 --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/SctpServerChannel.java @@ -0,0 +1,69 @@ +/* + * 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; + +import io.netty.channel.ChannelFuture; +import io.netty.channel.ServerChannel; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Set; + +/** + * A SCTP/IP {@link io.netty.channel.ServerChannel} which accepts incoming SCTP/IP connections. + * + * The {@link SctpServerChannel} provides the additional operations, available in the + * underlying JDK SCTP Server Channel like multi-homing etc. + */ +public interface SctpServerChannel extends ServerChannel { + /** + * Bind a address to the already bound channel to enable multi-homing. + * The Channel bust be bound and yet to be connected. + */ + ChannelFuture bindAddress(InetAddress localAddress); + + + /** + * Unbind the address from channel's multi-homing address list. + * The address should be added already in multi-homing address list. + */ + ChannelFuture unbindAddress(InetAddress localAddress); + + /** + * Returns the {@link SctpServerChannelConfig} configuration of the channel. + */ + @Override + SctpServerChannelConfig config(); + + /** + * Return the (primary) local address of the SCTP server channel. + * + * Please note that, this return the first local address in the underlying SCTP ServerChannel's + * local address iterator to support Netty Channel API. In other words, its the application's + * responsibility to keep track of it's local primary address. + * + * (To set a local address as primary, the application can request by calling local SCTP stack, + * with SctpStandardSocketOption.SCTP_PRIMARY_ADDR option). + */ + @Override + InetSocketAddress localAddress(); + + /** + * Return all local addresses of the SCTP server channel. + * Please note that, it will return more than one address if this channel is using multi-homing + */ + Set allLocalAddresses(); +} diff --git a/transport/src/main/java/io/netty/channel/socket/SctpServerChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/SctpServerChannelConfig.java new file mode 100644 index 0000000000..dfef7b7c2c --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/SctpServerChannelConfig.java @@ -0,0 +1,95 @@ +/* + * 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; + +import io.netty.channel.ChannelConfig; + +import static com.sun.nio.sctp.SctpStandardSocketOptions.InitMaxStreams; + +/** + * 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(com.sun.nio.sctp.SctpStandardSocketOptions.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); +}