예제 #1
0
 private static void AddAggregateListener(List <string> builder, AggregateNetworkListener listener)
 {
     AddListener(builder, listener._left);
     AddListener(builder, listener._right);
 }
예제 #2
0
        /// <summary>
        /// Method to create a network service
        /// </summary>
        /// <param name="logger">The logger to use</param>
        /// <returns>The network service</returns>
        /// <exception cref="NetServiceException">Thrown in configuration invalid</exception>
        public override ProxyNetworkService Create(Logger logger)
        {
            ProxyNetworkService ret = null;

            if (logger == null)
            {
                logger = Logger.GetSystemLogger();
            }

            if ((_port < 0) || (_port > 65535))
            {
                throw new NetServiceException(Properties.Resources.GenericProxyDocument_MustSpecifyAValidPort);
            }
            else
            {
                try
                {
                    List<ProxyFilter> filters = new List<ProxyFilter>();

                    foreach (ProxyFilterFactory item in _filters)
                    {
                        filters.Add(item.CreateFilter());
                    }

                    ProxyServer server = CreateServer(logger);
                    ProxyClient client = null;

                    if (_clientFactory != null)
                    {
                        client = _clientFactory.Create(logger);
                    }
                    else
                    {
                        client = new IpProxyClient();
                    }

                    INetworkListener listener = null;

                    if (NetUtils.OSSupportsIPv4)
                    {
                        listener = new TcpNetworkListener(_anyBind, false, _port, logger, false);
                    }

                    if (_ipv6Bind && NetUtils.OSSupportsIPv6)
                    {
                        INetworkListener ipv6Listener = new TcpNetworkListener(_anyBind, true, _port, logger, false);

                        if (listener != null)
                        {
                            listener = new AggregateNetworkListener(listener, ipv6Listener);
                        }
                        else
                        {
                            listener = ipv6Listener;
                        }
                    }

                    if (listener == null)
                    {
                        throw new NetServiceException(CANAPE.Documents.Properties.Resources.NetServiceDocument_CannotSetupListener);
                    }

                    ret = new ProxyNetworkService(
                        _packets,
                        listener,
                        _netGraph == null ? BuildDefaultProxyFactory() : _netGraph.Factory, logger, _globalMeta, _history,
                        _credentials, server, client, filters.ToArray(), Timeout.Infinite, false);

                    ret.DefaultBinding = CANAPE.Net.Layers.NetworkLayerBinding.ClientAndServer;
                }
                catch (SocketException ex)
                {
                    throw new NetServiceException(Properties.Resources.GenericProxyDocument_ErrorCreatingService, ex);
                }
                catch (IOException ex)
                {
                    throw new NetServiceException(Properties.Resources.GenericProxyDocument_ErrorCreatingService, ex);
                }

                return ret;
            }
        }
예제 #3
0
        /// <summary>
        /// Create the base service
        /// </summary>
        /// <param name="logger">The logger to use</param>
        /// <returns>The new network service</returns>
        public override ProxyNetworkService Create(Logger logger)
        {
            ProxyNetworkService ret = null;

            if (logger == null)
            {
                logger = Logger.GetSystemLogger();
            }

            if ((_port < 0) || (_port > 65535))
            {
                throw new NetServiceException(Properties.Resources.NetServerDocument_ValidPort);
            }
            else if (_factory == null)
            {
                throw new NetServiceException(Properties.Resources.NetServerDocument_MustSpecifyServer);
            }
            else
            {
                try
                {
                    ProxyServer server = new PassThroughProxyServer(logger, _layers);

                    ProxyClient client = new NetServerProxyClient(_factory);

                    INetworkListener listener = null;

                    if (!_udp)
                    {
                        if (NetUtils.OSSupportsIPv4)
                        {
                            listener = new TcpNetworkListener(_anyBind, false, _port, logger, false);
                        }

                        if (_ipv6Bind && NetUtils.OSSupportsIPv6)
                        {
                            INetworkListener ipv6Listener = new TcpNetworkListener(_anyBind, true, _port, logger, false);

                            if (listener != null)
                            {
                                listener = new AggregateNetworkListener(listener, ipv6Listener);
                            }
                            else
                            {
                                listener = ipv6Listener;
                            }
                        }
                    }
                    else
                    {
                        if (NetUtils.OSSupportsIPv4)
                        {
                            listener = new UdpNetworkListener(_anyBind, false, _port, _enableBroadcast, logger);
                        }

                        if (_ipv6Bind && NetUtils.OSSupportsIPv6)
                        {
                            INetworkListener ipv6Listener = new UdpNetworkListener(_anyBind, true, _port, _enableBroadcast, logger);

                            if(listener != null)
                            {
                                listener = new AggregateNetworkListener(listener, ipv6Listener);
                            }
                            else
                            {
                                listener = ipv6Listener;
                            }
                        }
                    }

                    if (listener == null)
                    {
                        throw new NetServiceException(CANAPE.Documents.Properties.Resources.NetServiceDocument_CannotSetupListener);
                    }

                    ret = new ProxyNetworkService(
                        _packets,
                        listener,
                        _netGraph == null ? BuildDefaultProxyFactory() : _netGraph.Factory, logger, _globalMeta, _history,
                        _credentials, server, client, null, Timeout.Infinite, false);

                    ret.DefaultBinding = NetworkLayerBinding.Server;
                }
                catch (SocketException ex)
                {
                    throw new NetServiceException(Properties.Resources.NetServerDocument_ErrorCreatingServer, ex);
                }
                catch (IOException ex)
                {
                    throw new NetServiceException(Properties.Resources.NetServerDocument_ErrorCreatingServer, ex);
                }

                return ret;
            }
        }
예제 #4
0
 private static void AddAggregateListener(List<string> builder, AggregateNetworkListener listener)
 {
     AddListener(builder, listener._left);
     AddListener(builder, listener._right);
 }