2 * Copyright (c) 2013 Robert Varga. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.bgpcep.tcpmd5.nio;
10 import java.io.IOException;
11 import java.net.ServerSocket;
12 import java.net.SocketAddress;
13 import java.net.SocketOption;
14 import java.nio.channels.ServerSocketChannel;
17 import org.opendaylight.bgpcep.tcpmd5.KeyAccessFactory;
19 import com.google.common.base.Preconditions;
22 * {@link ServerSocketChannel} augmented with support for TCP MD5 Signature
25 public final class MD5ServerSocketChannel extends ServerSocketChannel {
26 private final KeyAccessFactory keyAccessFactory;
27 private final ServerSocketChannel inner;
28 private final MD5ChannelOptions options;
30 public MD5ServerSocketChannel(final ServerSocketChannel inner, final KeyAccessFactory keyAccessFactory) {
31 super(inner.provider());
33 this.keyAccessFactory = Preconditions.checkNotNull(keyAccessFactory);
34 this.options = MD5ChannelOptions.create(keyAccessFactory, inner);
37 public MD5ServerSocketChannel(final ServerSocketChannel inner) {
38 this(inner, DefaultKeyAccessFactoryFactory.getKeyAccessFactory());
41 public static MD5ServerSocketChannel open() throws IOException {
42 return new MD5ServerSocketChannel(ServerSocketChannel.open());
46 public SocketAddress getLocalAddress() throws IOException {
47 return inner.getLocalAddress();
51 public <T> T getOption(final SocketOption<T> name) throws IOException {
52 return options.getOption(name);
56 public Set<SocketOption<?>> supportedOptions() {
57 return options.supportedOptions();
61 public ServerSocketChannel bind(final SocketAddress local, final int backlog) throws IOException {
62 inner.bind(local, backlog);
67 public <T> ServerSocketChannel setOption(final SocketOption<T> name, final T value) throws IOException {
68 options.setOption(name, value);
73 public ServerSocket socket() {
74 // FIXME: provider a wrapper
75 return inner.socket();
79 public MD5SocketChannel accept() throws IOException {
80 return new MD5SocketChannel(inner.accept(), keyAccessFactory);
84 protected void implCloseSelectableChannel() throws IOException {
89 protected void implConfigureBlocking(final boolean block) throws IOException {
90 inner.configureBlocking(block);