Exemplo n.º 1
0
 public void SendMulticastData(Interactor publisher, MulticastData multicastData)
 {
     _publisherManager.SendMulticastData(
         publisher,
         _repository.GetSubscribersToFeedAndTopic(multicastData.Feed, multicastData.Topic),
         multicastData);
 }
        private void OnStaleTopic(FeedTopic staleFeedTopic)
        {
            var staleMessage = new MulticastData(staleFeedTopic.Feed, staleFeedTopic.Topic, true, null);

            foreach (var subscriber in _repository.GetSubscribersToFeedAndTopic(staleFeedTopic.Feed, staleFeedTopic.Topic))
            {
                subscriber.SendMessage(staleMessage);
            }
        }
Exemplo n.º 3
0
 private void RaiseOnDataOrHeartbeat(MulticastData message)
 {
     if (message.Feed == "__admin__" && message.Topic == "heartbeat")
     {
         RaiseOnHeartbeat();
     }
     else
     {
         RaiseOnData(message.Feed, message.Topic, message.Data, message.IsImage);
     }
 }
 public void TestHeartbeat()
 {
     using (var stream = new MemoryStream())
     {
         var source = new MulticastData(
             "__admin__",
             "heartbeat",
             true,
             null);
         source.Write(new DataWriter(stream));
         stream.Seek(0, SeekOrigin.Begin);
         var dest = Message.Read(new DataReader(stream));
         Assert.AreEqual(source, dest);
     }
 }
        public void TestPayload()
        {
            using (var stream = new MemoryStream())
            {
                var source = new MulticastData(
                    "__admin__",
                    "heartbeat",
                    true,
                    new DataPacket[]
                {
                    new DataPacket(
                        new HashSet <int> {
                        1
                    },
                        new byte[] { 1, 2, 3, 4, 5, 6 })
                });

                source.Write(new DataWriter(stream));
                stream.Seek(0, SeekOrigin.Begin);
                var dest = Message.Read(new DataReader(stream));
                Assert.AreEqual(source, dest);
            }
        }
 private void SendMulticastData(IInteractor publisher, IInteractor subscriber, MulticastData multicastData)
 {
     if (publisher != null)
     {
         _repository.AddPublisher(publisher, multicastData.Feed, multicastData.Topic);
     }
     subscriber.SendMessage(multicastData);
 }
 public void SendMulticastData(IInteractor publisher, IEnumerable <IInteractor> subscribers, MulticastData multicastData)
 {
     foreach (var subscriber in subscribers)
     {
         SendMulticastData(publisher, subscriber, multicastData);
     }
 }
        public void SendMulticastData(Interactor?publisher, IEnumerable <KeyValuePair <Interactor, AuthorizationInfo> > subscribers, MulticastData multicastData)
        {
            if (!(publisher == null || publisher.HasRole(multicastData.Feed, Role.Publish)))
            {
                _logger.LogWarning("Rejected request from {Publisher} to publish to Feed {Feed}", publisher, multicastData.Feed);
                return;
            }

            if (publisher != null)
            {
                publisher.Metrics.MulticastMessages[multicastData.Feed].Inc();
            }

            foreach (var subscriberAndAuthorizationInfo in subscribers)
            {
                var subscriber    = subscriberAndAuthorizationInfo.Key;
                var authorization = subscriberAndAuthorizationInfo.Value;

                var subscriberMulticastData = new ForwardedMulticastData(
                    publisher?.UserForFeed(multicastData.Feed) ?? "internal",
                    publisher?.HostForFeed(multicastData.Feed) ?? "localhost",
                    multicastData.Feed,
                    multicastData.Topic,
                    multicastData.IsImage,
                    GetAuthorizedData(multicastData.DataPackets, authorization));

                _logger.LogDebug("Sending multicast data from {Publisher} to {Subscriber}: {Message}", publisher, subscriber, subscriberMulticastData);

                if (publisher != null)
                {
                    _repository.AddPublisher(publisher, subscriberMulticastData.Feed, subscriberMulticastData.Topic);
                }

                try
                {
                    subscriber.SendMessage(subscriberMulticastData);
                }
                catch (Exception error)
                {
                    _logger.LogDebug(error, "Failed to send to subscriber {Subscriber} multicast data {Message}", subscriber, subscriberMulticastData);
                }
            }
        }
Exemplo n.º 9
0
        public void SendMulticastData(IInteractor publisher, IEnumerable <KeyValuePair <IInteractor, AuthorizationInfo> > subscribers, MulticastData multicastData)
        {
            if (!(publisher == null || publisher.HasRole(multicastData.Feed, Role.Publish)))
            {
                Log.Warn($"Rejected request from {publisher} to publish to Feed {multicastData.Feed}");
                return;
            }

            foreach (var subscriberAndAuthorizationInfo in subscribers)
            {
                var subscriber        = subscriberAndAuthorizationInfo.Key;
                var authorizationInfo = subscriberAndAuthorizationInfo.Value;

                var subscriberMulticastData =
                    subscriberAndAuthorizationInfo.Value.IsAuthorizationRequired
                        ? new ForwardedMulticastData(publisher?.User ?? "internal", publisher?.Address ?? IPAddress.None, multicastData.Feed, multicastData.Topic, multicastData.IsImage, FilterDataPackets(authorizationInfo.Entitlements, multicastData.Data))
                        : new ForwardedMulticastData(publisher?.User ?? "internal", publisher?.Address ?? IPAddress.None, multicastData.Feed, multicastData.Topic, multicastData.IsImage, multicastData.Data);

                Log.Debug($"Sending multicast data from {publisher} to {subscriber}: {subscriberMulticastData}");

                if (publisher != null)
                {
                    _repository.AddPublisher(publisher, subscriberMulticastData.Feed, subscriberMulticastData.Topic);
                }

                try
                {
                    subscriber.SendMessage(subscriberMulticastData);
                }
                catch (Exception exception)
                {
                    Log.Debug($"Failed to send to subscriber {subscriber} multicast data {subscriberMulticastData}", exception);
                }
            }
        }