public Acceptor(IPEndPoint endPoint, DistributorRole distributorRole, EventQueue <InteractorEventArgs> eventQueue, CancellationToken token)
 {
     _eventQueue      = eventQueue;
     _token           = token;
     _distributorRole = distributorRole;
     _endPoint        = endPoint;
 }
Exemple #2
0
        public static Interactor Create(
            TcpClient tcpClient,
            X509Certificate2?certificate,
            IAuthenticator authenticator,
            DistributorRole distributorRole,
            EventQueue <InteractorEventArgs> eventQueue,
            ILoggerFactory loggerFactory,
            CancellationToken token)
        {
            var logger = loggerFactory.CreateLogger <Interactor>();

            var stream = GetStream(tcpClient, certificate, logger);

            var address  = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address;
            var hostName = address.Equals(IPAddress.Loopback) ? Dns.GetHostName() : Dns.GetHostEntry(address).HostName;

            var authenticationResponse = authenticator.Authenticate(stream);

            logger.LogInformation("Authenticated with {Type} as {Name}", authenticationResponse.Method, authenticationResponse.User);
            var roleManager = new RoleManager(
                distributorRole,
                hostName,
                authenticationResponse.User,
                authenticationResponse.Impersonating,
                authenticationResponse.ForwardedFor);

            return(new Interactor(
                       stream,
                       authenticationResponse.Application ?? "unspecified",
                       roleManager,
                       eventQueue,
                       logger,
                       token));
        }
Exemple #3
0
 private Interactor(Stream stream, string name, IPAddress address, DistributorRole distributorRole, EventQueue <InteractorEventArgs> eventQueue, CancellationToken token)
 {
     _stream      = stream;
     Id           = Guid.NewGuid();
     User         = name;
     Address      = address;
     _token       = token;
     _eventQueue  = eventQueue;
     _roleManager = new RoleManager(distributorRole, address, name);
 }
Exemple #4
0
        public Server(IPEndPoint endPoint, DistributorRole distributorRole)
        {
            DistributorRole = distributorRole;

            _eventQueue = new EventQueue <InteractorEventArgs>(_cancellationTokenSource.Token);
            _eventQueue.OnItemDequeued += OnInteractorEvent;

            _heartbeatTimer = new Timer(HeartbeatCallback);

            _acceptor = new Acceptor(endPoint, distributorRole, _eventQueue, _cancellationTokenSource.Token);

            _interactorManager = new InteractorManager(distributorRole);

            _notificationManager = new NotificationManager(_interactorManager);

            _subscriptionManager = new SubscriptionManager(_interactorManager, _notificationManager);
        }
Exemple #5
0
 public Acceptor(
     IPEndPoint endPoint,
     X509Certificate2?certificate,
     IAuthenticator authenticator,
     DistributorRole distributorRole,
     EventQueue <InteractorEventArgs> eventQueue,
     ILoggerFactory loggerFactory,
     CancellationToken token)
 {
     _endPoint        = endPoint;
     _certificate     = certificate;
     _authenticator   = authenticator;
     _distributorRole = distributorRole;
     _eventQueue      = eventQueue;
     _loggerFactory   = loggerFactory;
     _logger          = loggerFactory.CreateLogger <Acceptor>();
     _token           = token;
 }
Exemple #6
0
        public static IInteractor Create(TcpClient tcpClient, DistributorRole distributorRole, EventQueue <InteractorEventArgs> eventQueue, CancellationToken token)
        {
            var stream = new NegotiateStream(tcpClient.GetStream());

            try
            {
                stream.AuthenticateAsServer();
            }
            catch (Exception error)
            {
                Log.Warn("Failed to negotiate stream", error);
                return(null);
            }

            var interactor = new Interactor(stream, stream.RemoteIdentity.Name, ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address, distributorRole, eventQueue, token);

            return(interactor);
        }
        public Server(
            IPEndPoint endPoint,
            IAuthenticator authenticator,
            X509Certificate2?certificate,
            DistributorRole distributorRole,
            ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger <Server>();

            _eventQueue = new EventQueue <InteractorEventArgs>(loggerFactory, _tokenSource.Token);
            _eventQueue.OnItemDequeued += OnInteractorEvent;

            _heartbeatTimer = new Timer(HeartbeatCallback);

            _acceptor = new Acceptor(
                endPoint,
                certificate,
                authenticator,
                distributorRole,
                _eventQueue,
                loggerFactory,
                _tokenSource.Token);

            _interactorManager = new InteractorManager(distributorRole, loggerFactory);

            _notificationManager = new NotificationManager(_interactorManager, loggerFactory);

            _subscriptionManager = new SubscriptionManager(
                _interactorManager,
                _notificationManager,
                loggerFactory);

            _heartbeatInteractor = new Interactor(
                new MemoryStream(),
                "Heartbeat",
                new RoleManager(new DistributorRole(Role.Publish, Role.Authorize | Role.Notify | Role.Subscribe, false, null), "localhost", "admin", null, null),
                _eventQueue,
                loggerFactory.CreateLogger <Interactor>(),
                _tokenSource.Token);
        }
 internal InteractorRepository(DistributorRole distributorRole)
 {
     DistributorRole = distributorRole;
 }
 internal InteractorManager(DistributorRole distributorRole)
 {
     _repository = new InteractorRepository(distributorRole);
 }
 public InteractorManager(DistributorRole distributorRole, ILoggerFactory loggerFactory)
 {
     _logger     = loggerFactory.CreateLogger <InteractorManager>();
     _repository = new InteractorRepository(distributorRole);
 }