Beispiel #1
0
        private void uplink_OnDisconnect(Uplink s)
        {
            //A remote overlord has disconnected, notify local clients of all associated peering going offline.
            lock (sync)
            {
                logger.Debug("Server had uplink disconnect to {0}", s.Destination.ID);
                extOverlordServers.Remove(s);
                var verb = new UpdateVerb();
                foreach (Node node in externalNodes.ToList())
                {
                    if (node.OverlordID == s.Destination.ID || node.ID == s.Destination.ID)
                    {
                        //Check the node isnt now logged on locally
                        if (connectedClientNodes.Where(n => n.Node.ID == node.ID).Count() > 0)
                            continue;
                        verb.Nodes.Add(new Node {ID = node.ID, Online = false});
                    }
                    externalNodes.Remove(node);
                }
                verb.Nodes.Add(new Node {ID = s.Destination.ID, Online = false});
                NetworkRequest req = verb.CreateRequest();
                req.OverlordID = serverNode.ID;
                SendToStandardClients(req);

                //Remove the overlord itself
                if (extOverlordServers.Contains(s))
                {
                    extOverlordServers.Remove(s);
                }
            }
        }
Beispiel #2
0
        private void ProcessLanConnections(object no)
        {
            while (run)
            {
                List<DetectedNode> localNodes = peerFinder.Peers.ToList();

                foreach (DetectedNode peer in localNodes)
                {
                    if (peer.Address == serverNode.Location)
                        continue;

                    //If not already connected to that peer then connect
                    if (extOverlordServers.ToList().Where(o => o.Destination.Location == peer.Address).Count() == 0)
                    {
                        logger.Debug("Server connecting as client to external overlord at {0}", peer.Address);
                        var verb = new ConnectVerb();
                        verb.Address = serverNode.Location;
                        verb.ClientType = ClientType.Overlord;
                        verb.Secret = IDService.CreateID();

                        var uplink = new Uplink(model.LocalNode,
                                                new Node
                                                    {
                                                        ID = peer.OverlordID,
                                                        Location = peer.Address,
                                                        NodeType = ClientType.Overlord,
                                                        Secret = verb.Secret
                                                    });
                        extOverlordServers.Add(uplink);


                        var client = new Client(serverNode);
                        if (client.Execute(verb, peer.Address, 5000))
                        {
                            //Connected as client on an external overlord

                            uplink.OnDisconnect += uplink_OnDisconnect;

                            uplink.Start();
                            logger.Debug("Server connected to client to external overlord at {0}", peer.Address);
                            break;
                        }
                        else
                        {
                            //Failed to connect ot the external overlord
                            logger.Debug("Server failed to connect to external overlord at {0}", peer.Address);
                            peerFinder.RemovePeer(peer);
                            extOverlordServers.Remove(uplink);
                        }
                    }
                }
                Thread.Sleep(3000);
            }
        }