public virtual void VisitInterfaceCollection(InterfaceCollection interfaces)
 {
     foreach (TypeReference interfaceType in interfaces)
     {
         VisitInterface(interfaceType);
     }
 }
Exemple #2
0
        public async Task <object> InvokeInterfaceAsync(ClientRequestMessage clientMessage)
        {
            var invokeInfos = InterfaceCollection.GetInvokeInformation(clientMessage.Method);

            var authentication = new SignalARRRAuthentication(_serviceProvider);
            var result         = await authentication.Authorize(ClientContext, clientMessage.Authorization, invokeInfos.MethodInfo);

            if (!result.Succeeded)
            {
                throw new UnauthorizedException();
            }

            object instance;

            if (invokeInfos.MethodInfo.DeclaringType == HARRR.GetType())
            {
                instance = ActivatorUtilities.CreateInstance(_serviceProvider, HARRR.GetType());
            }
            else
            {
                instance = invokeInfos.Factory.DynamicInvoke(_serviceProvider);
            }



            return(await InvokeMethodInfoAsync(instance, invokeInfos.MethodInfo, clientMessage.Arguments, clientMessage.GenericArguments));
        }
Exemple #3
0
        private void OnShimReady(object sender, NetMQSocketEventArgs e)
        {
            // new actor command
            string command = m_shim.ReceiveFrameString();

            // check if we received end shim command
            if (command == NetMQActor.EndShimMessage)
            {
                // we cancel the socket which dispose and exist the shim
                m_poller.Stop();
            }
            else if (command == PublishCommand)
            {
                // it is a publish command
                // we just forward everything to the publisher until end of message
                NetMQMessage message = m_shim.ReceiveMultipartMessage();
                m_publisher.SendMultipartMessage(message);
            }
            else if (command == GetHostAddressCommand)
            {
                var interfaceCollection = new InterfaceCollection();
                var bindTo  = interfaceCollection.Select(x => x.Address).First();
                var address = bindTo + ":" + m_randomPort;
                m_shim.SendFrame(address);
            }
        }
Exemple #4
0
        public override void VisitInterfaceCollection(InterfaceCollection interfaces)
        {
            for (int i = 0; i < interfaces.Count; i++)
            {
                interfaces [i] = GetTypeReference(interfaces [i]);
            }

            foreach (TypeReference interf in interfaces)
            {
                VisitInterface(interf);
            }
        }
Exemple #5
0
        static bool Contains(this InterfaceCollection interfaces, TypeReference itfTypeRef)
        {
            foreach (TypeReference typeRef in interfaces)
            {
                if (typeRef.IsEqual(itfTypeRef))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #6
0
        public async Task <IAsyncEnumerable <object> > InvokeInterfaceStreamAsync(ClientRequestMessage clientMessage, CancellationToken cancellationToken)
        {
            var invokeInfos = InterfaceCollection.GetInvokeInformation(clientMessage.Method);

            var authentication = new SignalARRRAuthentication(_serviceProvider);
            var result         = await authentication.Authorize(ClientContext, clientMessage.Authorization, invokeInfos.MethodInfo);

            if (!result.Succeeded)
            {
                throw new UnauthorizedException();
            }

            var instance = invokeInfos.Factory.DynamicInvoke(_serviceProvider);


            return(await InvokeStreamMethodInfoAsync(instance, invokeInfos.MethodInfo, clientMessage.Arguments,
                                                     cancellationToken));
        }
        /// <summary>
        /// Start node. Use beacon discovery
        /// </summary>
        /// <returns>true if OK, false if not possible</returns>
        public bool Start()
        {
            if (IsRunning)
            {
                throw new InvalidOperationException("ZreNode is already running");
            }
            Debug.Assert(_beacon == null);
            _beacon = new NetMQBeacon();

            _beacon.Configure(ZreDiscoveryPort);

            // listen to incoming beacons
            _beacon.ReceiveReady += OnBeaconReady;


            IPAddress bindTo = null; // TODO change this once this property comes thru from NuGet = _beacon.BoundTo;
            var interfaceCollection = new InterfaceCollection();
            foreach (var @interface in interfaceCollection)
            {
                    bindTo = @interface.Address;
                    break;
            }

            // Bind our router port to the host
            var address = string.Format("tcp://{0}", bindTo);
            _port = _inbox.BindRandomPort(address);
            if (_port <= 0)
            {
                // Die on bad interface or port exhaustion
                return false;
            }
            _endpoint = _inbox.Options.LastEndpoint;

            //  Set broadcast/listen beacon
            PublishBeacon(_port);
            _beacon.Subscribe("ZRE");
            _poller.Add(_beacon);

            // Start polling on inbox
            _inbox.ReceiveReady += OnInboxReady;
            _poller.Add(_inbox);
            IsRunning = true;
            return true;
        }
Exemple #8
0
            private void Configure([NotNull] string interfaceName, int port)
            {
                // In case the beacon was configured twice
                if (m_udpSocket != null)
                {
                    m_poller.RemovePollInSocket(m_udpSocket);
                    m_udpSocket.Close();
                }

                m_udpPort = port;
                m_udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                m_poller.AddPollInSocket(m_udpSocket, OnUdpReady);

                // Ask operating system for broadcast permissions on socket
                m_udpSocket.EnableBroadcast = true;

                // Allow multiple owners to bind to socket; incoming
                // messages will replicate to each owner
                m_udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

                IPAddress bindTo = null;
                IPAddress sendTo = null;

                if (interfaceName == "*")
                {
                    bindTo = IPAddress.Any;
                    sendTo = IPAddress.Broadcast;
                }
                else
                {
                    var interfaceCollection = new InterfaceCollection();

                    var interfaceAddress = !string.IsNullOrEmpty(interfaceName)
                        ? IPAddress.Parse(interfaceName)
                        : null;

                    foreach (var @interface in interfaceCollection)
                    {
                        if (interfaceAddress == null || @interface.Address.Equals(interfaceAddress))
                        {
                            sendTo = @interface.BroadcastAddress;
                            bindTo = @interface.Address;
                            break;
                        }
                    }
                }

                if (bindTo != null)
                {
                    m_broadcastAddress = new IPEndPoint(sendTo, m_udpPort);
                    m_udpSocket.Bind(new IPEndPoint(bindTo, m_udpPort));

                    string hostname = "";

                    try
                    {
                        if (!IPAddress.Any.Equals(bindTo) && !IPAddress.IPv6Any.Equals(bindTo))
                        {
                            var host = Dns.GetHostEntry(bindTo);
                            hostname = host != null ? host.HostName : "";
                        }
                    }
                    catch (Exception)
                    {}

                    m_pipe.Send(hostname);
                }
            }
Exemple #9
0
 public void VisitInterfaceCollection(InterfaceCollection interfaces)
 {
 }
Exemple #10
0
        private void OnShimReady(object sender, NetMQSocketEventArgs e)
        {
            // new actor command
            string command = m_shim.ReceiveFrameString();

            // check if we received end shim command
            if (command == NetMQActor.EndShimMessage)
            {
                // we cancel the socket which dispose and exist the shim
                m_poller.Stop();
            }
            else if (command == PublishCommand)
            {
                // it is a publish command
                // we just forward everything to the publisher until end of message
                NetMQMessage message = m_shim.ReceiveMultipartMessage();
                m_publisher.SendMultipartMessage(message);
            }
            else if (command == GetHostAddressCommand)
            {
                var interfaceCollection = new InterfaceCollection();
                var bindTo = interfaceCollection.Select(x => x.Address).First();
                var address = bindTo + ":" + m_randomPort;
                m_shim.SendFrame(address);
            }
        }
Exemple #11
0
 public override void VisitInterfaceCollection(InterfaceCollection interfaces)
 {
     VisitCollection(interfaces);
 }
Exemple #12
0
            private void Configure([NotNull] string interfaceName, int port)
            {
                // In case the beacon was configured twice
                if (m_udpSocket != null)
                {
                    m_poller.Remove(m_udpSocket);

                #if NET35
                    m_udpSocket.Close();
                #else
                    m_udpSocket.Dispose();
                #endif
                }

                m_udpPort = port;
                m_udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                m_poller.Add(m_udpSocket, OnUdpReady);

                // Ask operating system for broadcast permissions on socket
                m_udpSocket.EnableBroadcast = true;

                // Allow multiple owners to bind to socket; incoming
                // messages will replicate to each owner
                m_udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

                IPAddress bindTo = null;
                IPAddress sendTo = null;

                if (interfaceName == "*")
                {
                    bindTo = IPAddress.Any;
                    sendTo = IPAddress.Broadcast;
                }
                else if (interfaceName == "loopback")
                {
                    bindTo = IPAddress.Loopback;
                    sendTo = IPAddress.Broadcast;
                }
                else
                {
                    var interfaceCollection = new InterfaceCollection();

                    var interfaceAddress = !string.IsNullOrEmpty(interfaceName)
                        ? IPAddress.Parse(interfaceName)
                        : null;

                    foreach (var @interface in interfaceCollection)
                    {
                        if (interfaceAddress == null || @interface.Address.Equals(interfaceAddress))
                        {
                            sendTo = @interface.BroadcastAddress;
                            bindTo = @interface.Address;
                            break;
                        }
                    }
                }

                if (bindTo != null)
                {
                    m_broadcastAddress = new IPEndPoint(sendTo, m_udpPort);
                    m_udpSocket.Bind(new IPEndPoint(bindTo, m_udpPort));
                }

                m_pipe.SendFrame(bindTo?.ToString() ?? "");
            }