public void Process(BaseMessage message, ProtocolType Protocol, IPEndPoint EP = null, TcpClient Client = null)
        {
            ReqMessage msg     = (ReqMessage)message;
            HubInfo    hubInfo = connections.GetConnection(msg.RecipientId);

            if (hubInfo != null)
            {
                hub.Publish(new ConnectionStartingEvent()
                {
                    Data = hubInfo
                });

                IPEndPoint ResponsiveEP = manager.FindReachableEndpoint(hubInfo);

                if (ResponsiveEP != null)
                {
                    hub.Publish(new ConnectionStartedEvent()
                    {
                        Data = hubInfo, Endpoint = ResponsiveEP
                    });
                    hub.Publish(new ConnectionUpdatedEvent()
                    {
                        Data = hubInfo
                    });
                }
            }
        }
        public void Process(BaseMessage message, ProtocolType Protocol, IPEndPoint EP = null, TcpClient Client = null)
        {
            var msg = (HubInfoMessage)message;

            // We need this lock as we're checking for null and during an initial handshake messages will come almost simultaneously.
            //lock (manager.Connections)
            lock (connections)
            {
                HubInfo hubInfo = connections.GetConnection(msg.Id);

                if (hubInfo == null)
                {
                    hubInfo = new HubInfo(msg);
                    connections.AddConnection(hubInfo);

                    hub.Publish(new ConnectionAddedEvent()
                    {
                        Data = hubInfo
                    });
                }
                else
                {
                    hubInfo.Update(msg);

                    hub.Publish(new ConnectionUpdatedEvent()
                    {
                        Data = hubInfo
                    });
                }
            }
        }
Exemple #3
0
        public void Process(BaseMessage message, ProtocolType Protocol, IPEndPoint EP = null, TcpClient Client = null)
        {
            AckMessage msg = (AckMessage)message;

            if (msg.Response)
            {
                manager.AckResponces.Add(new Ack(msg));
            }
            else
            {
                HubInfo CI = connections.GetConnection(msg.Id);

                if (CI.ExternalEndpoint.Address.Equals(EP.Address) & CI.ExternalEndpoint.Port != EP.Port)
                {
                    log.LogInformation("Received Ack on Different Port (" + EP.Port + "). Updating ...");

                    CI.ExternalEndpoint.Port = EP.Port;

                    hub.Publish(new ConnectionUpdatedEvent()
                    {
                        Data = CI
                    });
                }

                List <string> IPs = new List <string>();
                CI.InternalAddresses.ForEach(new Action <IPAddress>(delegate(IPAddress IP) { IPs.Add(IP.ToString()); }));

                if (!CI.ExternalEndpoint.Address.Equals(EP.Address) & !IPs.Contains(EP.Address.ToString()))
                {
                    log.LogInformation("Received Ack on New Address (" + EP.Address + "). Updating ...");

                    CI.InternalAddresses.Add(EP.Address);
                }

                msg.Response    = true;
                msg.RecipientId = manager.LocalHubInfo.Id;
                manager.SendMessageUDP(new Ack(msg), EP);
            }
        }
        public void Process(BaseMessage message, ProtocolType Protocol, IPEndPoint EP = null, TcpClient Client = null)
        {
            NotificationMessage item = (NotificationMessage)message;

            if (item.Type == NotificationsTypes.Disconnected)
            {
                Entities.HubInfo hubInfo = connections.GetConnection(item.Tag.ToString());

                if (hubInfo != null)
                {
                    connections.RemoveConnection(hubInfo);
                    hub.Publish(new ConnectionRemovedEvent()
                    {
                        Data = hubInfo
                    });
                }
            }
            else if (item.Type == NotificationsTypes.ServerShutdown)
            {
                manager.DisconnectedGateway();
                hub.Publish(new GatewayShutdownEvent());
            }
        }