Пример #1
0
        private void connect(
            IncomingMessageDispatchCallback incomingMessageDispatchCallback, IOWorker ioWorker)
        {
            if (NetworkUtils.protocolIsTcp(target))
            {
                connection = NetworkUtils.connectTcp(target, options);
            }
            else if (NetworkUtils.protocolIsTcps(target))
            {
                connection = NetworkUtils.connectTcps(target, options, ioWorker);

                // additionally, instruct I/O Worker that blocking sockets
                // are the only ones that should be acted upon

                ioWorker.UseBlockingChannelsOnly();
            }
            else if (NetworkUtils.protocolIsUdp(target))
            {
                connection = NetworkUtils.createUdp(target, options);
            }
            else if (target.Equals("null"))
            {
                // do nothing - this protocol is used for testing only
                channelWriter = new ChannelWriter(
                    null, null, null, LogEventArgs.LogLevel.LOW);
            }
            else
            {
                throw new BadProtocolException(target);
            }

            createReaderWriter(incomingMessageDispatchCallback);
        }
Пример #2
0
        public DispatchManager(
            object sender, // Agent reference for callbacks
            Options options, WaterFlowManager incomingFlowManager, 
            IOWorker ioWorker, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.sender = sender;
            this.incomingFlowManager = incomingFlowManager;
            this.ioWorker = ioWorker;

            this.logCallback = logCallback;
            this.logLevel = logLevel;

            messageQueue = new LinkedList<IncomingMessage>();

            objectMap = new Dictionary<string, IncomingMessageHandler>();
            anyObjectCallback = null;

            int numOfThreads = options.dispatcherThreads;

            dispatchers = new List<Thread>();
            for (int i = 0; i != numOfThreads; ++i)
            {

                Thread th = new Thread((new Dispatcher(this)).run);
                th.Name = "YAMI4 message dispatcher";
                th.IsBackground = true;
                th.Start();
                dispatchers.Add(th);
            }
        }
Пример #3
0
        public DispatchManager(
            object sender, // Agent reference for callbacks
            Options options, WaterFlowManager incomingFlowManager,
            IOWorker ioWorker,
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.sender = sender;
            this.incomingFlowManager = incomingFlowManager;
            this.ioWorker            = ioWorker;

            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            messageQueue = new LinkedList <IncomingMessage>();

            objectMap         = new Dictionary <string, IncomingMessageHandler>();
            anyObjectCallback = null;

            int numOfThreads = options.dispatcherThreads;

            dispatchers = new List <Thread>();
            for (int i = 0; i != numOfThreads; ++i)
            {
                Thread th = new Thread((new Dispatcher(this)).run);
                th.Name         = "YAMI4 message dispatcher";
                th.IsBackground = true;
                th.Start();
                dispatchers.Add(th);
            }
        }
Пример #4
0
        internal static TransportChannel connectTcps(string target,
                                                     Options options, IOWorker ioWorker)
        {
            IpComponents tcpComponents = parseTcps(target);

            TcpClient tcpClient = new System.Net.Sockets.TcpClient();

            Int32 timeout;

            if (options.tcpConnectTimeout > 0)
            {
                timeout = options.tcpConnectTimeout;
            }
            else
            {
                timeout = Timeout.Infinite;
            }

            IAsyncResult result = tcpClient.BeginConnect(tcpComponents.hostName, tcpComponents.port, null, null);
            bool         connectionAttempted = result.AsyncWaitHandle.WaitOne(timeout);

            if (!connectionAttempted || !tcpClient.Connected)
            {
                throw new YAMIIOException("Cannot create SSL connection");
            }

            SslStream ssl = new SslStream(tcpClient.GetStream(), false,
                                          new RemoteCertificateValidationCallback(
                                              (object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors errors) =>
            {
                return(true);
            })
                                          );

            try
            {
                ssl.AuthenticateAsClient(tcpComponents.hostName, new X509CertificateCollection(),
                                         System.Security.Authentication.SslProtocols.Default, false);
            }
            catch (AuthenticationException)
            {
                throw new YAMIIOException("SSL authentication error");
            }

            tcpClient.NoDelay = options.tcpNoDelay;
            tcpClient.Client.SetSocketOption(
                SocketOptionLevel.Socket,
                SocketOptionName.KeepAlive,
                options.tcpKeepAlive ? 1 : 0);

            return(new TransportChannel(ssl, options.tcpFrameSize, ioWorker));
        }
Пример #5
0
            internal TransportChannel(Socket connectedChannel)
            {
                this.connectedChannel = connectedChannel;
                this.datagramChannel  = null;
                this.targetAddress    = null;

                this.ssl          = null;
                this.readingQueue = null;
                this.socketReader = null;
                this.writingQueue = null;
                this.socketWriter = null;
                this.ioWorker     = null;
                frameSize         = 0;
            }
Пример #6
0
        internal Channel(string target, Options options,
                         IncomingMessageDispatchCallback incomingMessageDispatchCallback,
                         IOWorker ioWorker,
                         LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.target  = target;
            this.options = options;

            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            connect(incomingMessageDispatchCallback, ioWorker);

            if (logCallback != null)
            {
                logCallback.Log(LogEventArgs.LogLevel.LOW,
                                "Connected to " + target);
            }
        }
Пример #7
0
            internal TransportChannel(SslStream ssl, int bufferSize, IOWorker worker)
            {
                this.connectedChannel = null;
                this.datagramChannel  = null;
                this.targetAddress    = null;

                this.ssl = ssl;

                this.readingQueue = new Buffer(bufferSize * 2);
                this.writingQueue = new Buffer(bufferSize * 2);
                this.frameSize    = bufferSize;

                this.ioWorker = worker;

                this.socketReader              = new Thread(new SocketReader(this).run);
                this.socketReader.Name         = "YAMI4 SSL Reader";
                this.socketReader.IsBackground = true;
                this.socketReader.Start();

                this.socketWriter              = new Thread(new SocketWriter(this).run);
                this.socketWriter.Name         = "YAMI4 SSL Writer";
                this.socketWriter.IsBackground = true;
                this.socketWriter.Start();
            }