public MTProtoClientConnection(
            [NotNull] IClientTransportConfig clientTransportConfig,
            [NotNull] IClientTransportFactory clientTransportFactory,
            [NotNull] TLRig tlRig,
            [NotNull] IMessageIdGenerator messageIdGenerator,
            [NotNull] IMessageCodec messageCodec)
        {
            Argument.IsNotNull(() => clientTransportConfig);
            Argument.IsNotNull(() => clientTransportFactory);
            Argument.IsNotNull(() => tlRig);
            Argument.IsNotNull(() => messageIdGenerator);
            Argument.IsNotNull(() => messageCodec);

            _tlRig = tlRig;
            _messageIdGenerator = messageIdGenerator;
            _messageCodec       = messageCodec;

            DefaultRpcTimeout     = Defaults.RpcTimeout;
            DefaultConnectTimeout = Defaults.ConnectTimeout;

            _methods = new MTProtoAsyncMethods(this);

            InitResponseDispatcher(_responseDispatcher);

            // Init transport.
            _clientTransport = clientTransportFactory.CreateTransport(clientTransportConfig);

            // Connector in/out.
            _clientTransport.ObserveOn(DefaultScheduler.Instance).Do(bytes => LogMessageInOut(bytes, "IN")).Subscribe(ProcessIncomingMessageBytes);
        }
Ejemplo n.º 2
0
 internal GiopClientConnectionManager(IClientTransportFactory transportFactory, MessageTimeout requestTimeOut,
                                      int unusedKeepAliveTime, int maxNumberOfConnections, bool allowMultiplex,
                                      int maxNumberOfMultplexedRequests, byte headerFlags)
 {
     Initalize(transportFactory, requestTimeOut, unusedKeepAliveTime,
               maxNumberOfConnections, allowMultiplex, maxNumberOfMultplexedRequests,
               headerFlags);
 }
Ejemplo n.º 3
0
        public MTProtoClientConnection(
            [NotNull] IClientTransportConfig clientTransportConfig,
            [NotNull] IClientTransportFactory clientTransportFactory,
            [NotNull] TLRig tlRig,
            [NotNull] IMessageIdGenerator messageIdGenerator,
            [NotNull] IMessageCodec messageCodec)
        {
            _tlRig = tlRig;
            _messageIdGenerator = messageIdGenerator;
            _messageCodec       = messageCodec;

            DefaultRpcTimeout     = Defaults.RpcTimeout;
            DefaultConnectTimeout = Defaults.ConnectTimeout;

            _methods = new MTProtoAsyncMethods(this);

            _updatesHandler = new UpdatesHandler(_tlRig);

            InitResponseDispatcher(_responseDispatcher);

            // Init transport.
            _clientTransport = clientTransportFactory.CreateTransport(clientTransportConfig);

            // Connector in/out.
            _clientTransport.ObserveOn(DefaultScheduler.Instance).Do(bytes => LogMessageInOut(bytes, "IN")).Subscribe(ProcessIncomingMessageBytes);

            _clientTransport.RegisterOnDisconnectInternally(() =>
            {
                Console.WriteLine("Client has been closed internally.");

                if (_onClosedInternally != null)
                {
                    _onClosedInternally(this, null);
                }

                if (_state == MTProtoConnectionState.Disconnected)

                {
                    return;
                }
                _state = MTProtoConnectionState.Disconnected;

                if (_connectionCts != null)
                {
                    _connectionCts.Cancel();
                    _connectionCts.Dispose();
                    _connectionCts = null;
                }
            });
        }
Ejemplo n.º 4
0
 public MTProtoClientBuilder(
     [NotNull] IClientTransportFactory clientTransportFactory,
     [NotNull] TLRig tlRig,
     [NotNull] IMessageIdGenerator messageIdGenerator,
     [NotNull] IMessageCodec messageCodec,
     [NotNull] IHashServices hashServices,
     [NotNull] IEncryptionServices encryptionServices,
     [NotNull] INonceGenerator nonceGenerator,
     [NotNull] IKeyChain keyChain)
 {
     _clientTransportFactory = clientTransportFactory;
     _tlRig = tlRig;
     _messageIdGenerator = messageIdGenerator;
     _messageCodec = messageCodec;
     _hashServices = hashServices;
     _encryptionServices = encryptionServices;
     _nonceGenerator = nonceGenerator;
     _keyChain = keyChain;
 }
Ejemplo n.º 5
0
 public MTProtoClientBuilder(
     [NotNull] IClientTransportFactory clientTransportFactory,
     [NotNull] TLRig tlRig,
     [NotNull] IMessageIdGenerator messageIdGenerator,
     [NotNull] IMessageCodec messageCodec,
     [NotNull] IHashServices hashServices,
     [NotNull] IEncryptionServices encryptionServices,
     [NotNull] INonceGenerator nonceGenerator,
     [NotNull] IKeyChain keyChain)
 {
     _clientTransportFactory = clientTransportFactory;
     _tlRig = tlRig;
     _messageIdGenerator = messageIdGenerator;
     _messageCodec = messageCodec;
     _hashServices = hashServices;
     _encryptionServices = encryptionServices;
     _nonceGenerator = nonceGenerator;
     _keyChain = keyChain;
 }
Ejemplo n.º 6
0
 private void Initalize(IClientTransportFactory transportFactory, MessageTimeout requestTimeOut,
                        int unusedKeepAliveTime, int maxNumberOfConnections, bool allowMultiplex,
                        int maxNumberOfMultplexedRequests, byte headerFlags)
 {
     m_transportFactory = transportFactory;
     m_requestTimeOut   = requestTimeOut;
     if (unusedKeepAliveTime != Timeout.Infinite)
     {
         m_connectionLifeTime = TimeSpan.FromMilliseconds(unusedKeepAliveTime);
         TimerCallback timerDelegate = new TimerCallback(DestroyUnusedConnections);
         // Create a timer which invokes the session destroyer every unusedKeepAliveTime
         m_destroyTimer = new Timer(timerDelegate, null, 2 * unusedKeepAliveTime, unusedKeepAliveTime);
     }
     m_maxNumberOfConnections = maxNumberOfConnections; // the max. number of concurrent connections to the same target.
     if (m_maxNumberOfConnections < 1)
     {
         throw new BAD_PARAM(579, CompletionStatus.Completed_MayBe);
     }
     m_allowMultiplex = allowMultiplex;
     m_maxNumberOfMultiplexedRequests = maxNumberOfMultplexedRequests;
     m_headerFlags = headerFlags;
 }
Ejemplo n.º 7
0
 internal GiopClientConnectionManager(IClientTransportFactory transportFactory, MessageTimeout requestTimeOut,
                                      int unusedKeepAliveTime, int maxNumberOfConnections, bool allowMultiplex,
                                      int maxNumberOfMultplexedRequests, byte headerFlags) {
     Initalize(transportFactory, requestTimeOut, unusedKeepAliveTime,
               maxNumberOfConnections, allowMultiplex, maxNumberOfMultplexedRequests,
               headerFlags);
 }
Ejemplo n.º 8
0
 private void Initalize(IClientTransportFactory transportFactory, MessageTimeout requestTimeOut,
                        int unusedKeepAliveTime, int maxNumberOfConnections, bool allowMultiplex,
                        int maxNumberOfMultplexedRequests, byte headerFlags) {
     m_transportFactory = transportFactory;
     m_requestTimeOut = requestTimeOut;
     if (unusedKeepAliveTime != Timeout.Infinite) {
         m_connectionLifeTime = TimeSpan.FromMilliseconds(unusedKeepAliveTime);
         TimerCallback timerDelegate = new TimerCallback(DestroyUnusedConnections);
         // Create a timer which invokes the session destroyer every unusedKeepAliveTime
         m_destroyTimer = new Timer(timerDelegate, null, 2 * unusedKeepAliveTime, unusedKeepAliveTime);
     }
     m_maxNumberOfConnections = maxNumberOfConnections; // the max. number of concurrent connections to the same target.
     if (m_maxNumberOfConnections < 1) {
         throw new BAD_PARAM(579, CompletionStatus.Completed_MayBe);
     }
     m_allowMultiplex = allowMultiplex;
     m_maxNumberOfMultiplexedRequests = maxNumberOfMultplexedRequests;
     m_headerFlags = headerFlags;
 }
Ejemplo n.º 9
0
        /// <summary>the constructor used by the config file</summary>
        public IiopClientChannel(IDictionary properties, IClientChannelSinkProvider sinkProvider)
        {
            if (!CheckSinkProviderChain(sinkProvider))
            {
                throw new ArgumentException(
                     "IIOPClientSideFormatter provider not found in chain, this channel is only usable with the IIOPFormatters");
            }
            m_providerChain = sinkProvider;
            IDictionary nonDefaultOptions = new Hashtable();
            int receiveTimeOut = 0;
            int sendTimeOut = 0;
            ArrayList interceptionOptions = new ArrayList();
            int maxNumberOfRetries = MAX_NUMBER_OF_RETRIES;
            int retryDelay = RETRY_DELAY;

            if (properties != null)
            {
                foreach (DictionaryEntry entry in properties)
                {
                    switch ((string)entry.Key)
                    {
                        case IiopChannel.CHANNEL_NAME_KEY:
                            m_channelName = (string)entry.Value;
                            break;
                        case IiopChannel.PRIORITY_KEY:
                            m_channelPriority = Convert.ToInt32(entry.Value);
                            break;
                        case IiopChannel.TRANSPORT_FACTORY_KEY:
                            Type transportFactoryType = Type.GetType((string)entry.Value, true);
                            m_transportFactory = (IClientTransportFactory)
                                Activator.CreateInstance(transportFactoryType);
                            break;
                        case IiopClientChannel.CLIENT_RECEIVE_TIMEOUT_KEY:
                            receiveTimeOut = Convert.ToInt32(entry.Value);
                            break;
                        case IiopClientChannel.CLIENT_SEND_TIMEOUT_KEY:
                            sendTimeOut = Convert.ToInt32(entry.Value);
                            break;
                        case IiopClientChannel.CLIENT_REQUEST_TIMEOUT_KEY:
                            int requestTimeOutMilllis = Convert.ToInt32(entry.Value);
                            m_requestTimeOut = new MessageTimeout(TimeSpan.FromMilliseconds(requestTimeOutMilllis));
                            break;
                        case IiopClientChannel.CLIENT_UNUSED_CONNECTION_KEEPALIVE_KEY:
                            m_unusedClientConnectionTimeOut = Convert.ToInt32(entry.Value);
                            break;
                        case IiopClientChannel.CLIENT_CONNECTION_LIMIT_KEY:
                            m_maxNumberOfConnections = Convert.ToInt32(entry.Value);
                            break;
                        case IiopClientChannel.ALLOW_REQUEST_MULTIPLEX_KEY:
                            m_allowMultiplex = Convert.ToBoolean(entry.Value);
                            break;
                        case IiopClientChannel.MAX_NUMBER_OF_MULTIPLEXED_REQUESTS_KEY:
                            m_maxNumberOfMultplexedRequests = Convert.ToInt32(entry.Value);
                            break;
                        case IiopClientChannel.MAX_NUMBER_OF_RETRIES_KEY:
                            maxNumberOfRetries = Convert.ToInt32(entry.Value);
                            break;
                        case IiopClientChannel.RETRY_DELAY_KEY:
                            retryDelay = Convert.ToInt32(entry.Value);
                            break;
                        case IiopChannel.BIDIR_KEY:
                            m_isBidir = Convert.ToBoolean(entry.Value);
                            interceptionOptions.Add(new BiDirIiopInterceptionOption());
                            break;
                        case IiopChannel.ENDIAN_KEY:
                            Endian endian =
                                (Endian)Enum.Parse(typeof(Endian), (string)entry.Value);
                            m_headerFlags = GiopHeader.GetDefaultHeaderFlagsForEndian(endian);
                            break;
                        default:
                            Debug.WriteLine("non-default property found for IIOPClient channel: " + entry.Key);
                            nonDefaultOptions[entry.Key] = entry.Value;
                            break;
                    }
                }
            }
            m_retryConfig = new RetryConfig(maxNumberOfRetries, retryDelay);
            m_interceptionOptions =
                (IInterceptionOption[])interceptionOptions.ToArray(typeof(IInterceptionOption));
            // handle the options now by transport factory
            m_transportFactory.SetClientTimeOut(receiveTimeOut, sendTimeOut);
            m_transportFactory.SetupClientOptions(nonDefaultOptions);
            InitChannel();
        }