Esempio n. 1
0
        public BrokerProcessor(
            IReadableChannel <ITransportConnection> incomingConnections,
            IProtocolSerializerFactory serializerFactory,
            IInteropContext interopContext)
        {
            _incomingConnections = incomingConnections;
            var registryService = new RegistryService(interopContext.RegistryProvider);
            var protocol        = new ProtocolImplementation(DefaultProtocolMessageFactory, serializerFactory);

            _appLifecycleManager   = interopContext.AppLifecycleManager;
            _authenticationHandler = new AuthenticationHandler(interopContext.AppLifecycleManager, protocol, registryService);
            _clientRequestHandler  = new ClientRequestHandler(interopContext.AppLifecycleManager, protocol, registryService, interopContext.InvocationEventProvider, interopContext.ContextLinkageManager);
        }
Esempio n. 2
0
        public BrokerProcessor(
            IReadableChannel <ITransportConnection> incomingConnections,
            IRegistryProvider registryProvider,
            IProtocolSerializerFactory serializerFactory,
            IAppLifecycleManager connectionTracker)
        {
            _incomingConnections = incomingConnections;
            var registryService = new RegistryService(registryProvider);
            var protocol        = new ProtocolImplementation(DefaultProtocolMessageFactory, serializerFactory);

            _authenticationHandler = new AuthenticationHandler(connectionTracker, protocol, registryService);
            _clientRequestHandler  = new ClientRequestHandler(connectionTracker, protocol, registryService);
        }
Esempio n. 3
0
        public BrokerProcessor(
            IReadableChannel <ITransportConnection> incomingConnections,
            IRegistryProvider registryProvider,
            IProtocolSerializerFactory serializerFactory,
            IAppLifecycleManager appLifecycleManager = null)
        {
            _incomingConnections = incomingConnections;
            var registryService = new RegistryService(registryProvider);
            var protocol        = new ProtocolImplementation(DefaultProtocolMessageFactory, serializerFactory);

            _appLifecycleManager = appLifecycleManager ?? new NoopAppLifecycleManager();
            var connectionTracker = new ClientConnectionTracker(_appLifecycleManager);

            _authenticationHandler = new AuthenticationHandler(connectionTracker, protocol, registryService);
            _clientRequestHandler  = new ClientRequestHandler(connectionTracker, protocol, registryService);
            Completion             = TaskRunner.RunInBackground(ProcessAsync);
        }
Esempio n. 4
0
        public void init_zeroconf()
        {
            browser = new Mono.Zeroconf.ServiceBrowser();

            browser.ServiceAdded += delegate(object o, Mono.Zeroconf.ServiceBrowseEventArgs args)
            {
                bool   added    = reg_edit.AddPartnerEntry(args.Service.Name);
                string to_write = "Service found: " + args.Service.Name + " : " + added;
                Service1.WirteLog(to_write);
            };

            browser.ServiceRemoved += delegate(object o, Mono.Zeroconf.ServiceBrowseEventArgs args)
            {
                bool removed = reg_edit.deletePartnerEntry(args.Service.Name);
                Service1.WirteLog("Service disconnected: " + args.Service.Name + " : " + removed);
            };
            browser.Browse("_drop._tcp", "local");

            service = new Mono.Zeroconf.RegisterService();

            service.Name        = "Drop windows";
            service.RegType     = "_drop._tcp";
            service.ReplyDomain = "local.";
            service.Port        = 7431;

            Mono.Zeroconf.TxtRecord txt = new Mono.Zeroconf.TxtRecord();
            txt.Add("display-name", "Windows");
            txt.Add("server-enabled", "true");
            txt.Add("protocol-implementation", "windows");
            txt.Add("unencrypted-port", "7432");
            txt.Add("protocol-version", "1");

            service.TxtRecord = txt;

            service.Register();

            var protocol_test = new ProtocolImplementation("192.168.100.120");
        }
Esempio n. 5
0
        // Note: The connection management methods below should only be called in a synchronized manner!
        // In this case, this is ensured by the main part of this class.

        // Used for establishing the initial connection as well as for reconnects.
        private async Task EstablishNewConnectionAsync(CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Doing one more cleanup won't hurt.
            CleanupPreviousConnection();

            _logger.LogInformation("Connecting to VNC-Server on {endpoint}...", Parameters.TransportParameters);

            // Create a new connection context
            var context = new RfbConnectionContext(this);

            context.State        = ProtocolImplementation.CreateStateObject(context);
            context.ZLibInflater = ProtocolImplementation.CreateZLibInflater(context);
            context.JpegDecoder  = ProtocolImplementation.CreateJpegDecoder(context);

            // Create message and encoding types collections in an order which allows e.g. the message types to get an overview of all registered encodings.
            context.SupportedEncodingTypes = ProtocolImplementation.CreateEncodingTypesCollection(context);
            context.SupportedMessageTypes  = ProtocolImplementation.CreateMessageTypesCollection(context);
            context.SupportedSecurityTypes = ProtocolImplementation.CreateSecurityTypesCollection(context);

            // Prepare the state for first use
            context.State.Prepare();

            try
            {
                // Establish a new transport connection
                context.Transport = await ProtocolImplementation.CreateTransportConnector(context).ConnectAsync(cancellationToken).ConfigureAwait(false);

                // Do the handshake
                ITransport?tunnelTransport = await ProtocolImplementation.CreateRfbHandshaker(context).DoHandshakeAsync(cancellationToken).ConfigureAwait(false);

                // Replace the current transport in case a tunnel has been built during handshake
                if (tunnelTransport != null)
                {
                    context.Transport = tunnelTransport;
                }

                // Initialize the connection
                await ProtocolImplementation.CreateRfbInitializer(context).InitializeAsync(cancellationToken).ConfigureAwait(false);

                // Setup send and receive loops
                context.MessageReceiver = ProtocolImplementation.CreateMessageReceiver(context);
                context.MessageSender   = ProtocolImplementation.CreateMessageSender(context);
                context.MessageSender.EnqueueInitialMessages(cancellationToken);
                context.MessageReceiver.StartReceiveLoop();
                context.MessageSender.StartSendLoop();
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "Connecting to VNC-Server on {endpoint} failed: {exception}", Parameters.TransportParameters, ex.Message);

                // Ensure cleanup on failure
                context.MessageReceiver?.Dispose();
                context.MessageSender?.Dispose();
                context.Transport?.Dispose();

                throw;
            }

            // From now on, exceptions will only land in the Failed event handler.
            // This should be the last real operation to ensure that exceptions are not propagated by two ways at the same time.
            context.MessageReceiver.Failed += BackgroundThreadOnFailed;
            context.MessageSender.Failed   += BackgroundThreadOnFailed;

            _activeConnection = context;

            _logger.LogInformation("Connection to {endpoint} established successfully.", Parameters.TransportParameters);
        }