public void SendUnicastData(IInteractor publisher, IInteractor subscriber, AuthorizationInfo authorization, UnicastData unicastData) { if (!publisher.HasRole(unicastData.Feed, Role.Publish)) { Log.Warn($"Rejected request from {publisher} to publish on feed {unicastData.Feed}"); return; } var clientUnicastData = authorization.IsAuthorizationRequired ? new ForwardedUnicastData(publisher.User, publisher.Address, unicastData.ClientId, unicastData.Feed, unicastData.Topic, unicastData.IsImage, unicastData.Data.Where(x => authorization.Entitlements.Contains(x.Header)).ToArray()) : new ForwardedUnicastData(publisher.User, publisher.Address, unicastData.ClientId, unicastData.Feed, unicastData.Topic, unicastData.IsImage, unicastData.Data); Log.Debug($"Sending unicast data from {publisher} to {subscriber}: {clientUnicastData}"); _repository.AddPublisher(publisher, clientUnicastData.Feed, clientUnicastData.Topic); try { subscriber.SendMessage(clientUnicastData); } catch (Exception exception) { Log.Debug($"Failed to send to subscriber {subscriber} unicast data {clientUnicastData}", exception); } }
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); } } }
internal void RequestSubscription(IInteractor subscriber, SubscriptionRequest subscriptionRequest) { if (!subscriber.HasRole(subscriptionRequest.Feed, Role.Subscribe)) { Log.Warn($"Rejected request from {subscriber} to subscribe to feed \"{subscriptionRequest.Feed}\""); return; } Log.Debug($"Received subscription from {subscriber} on \"{subscriptionRequest}\""); if (subscriptionRequest.IsAdd) { _interactorManager.RequestAuthorisation(subscriber, subscriptionRequest.Feed, subscriptionRequest.Topic); } else { _repository.RemoveSubscription(subscriber, subscriptionRequest.Feed, subscriptionRequest.Topic, false); _notificationManager.ForwardSubscription(subscriber, subscriptionRequest); } }