Пример #1
0
 internal void UpdateNodeServers(NodeServerList nodeServers)
 {
     IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
     foreach (var nodeServer in nodeServers)
     {
         if (IPAddress.IsLoopback(nodeServer.Value.EndPoint.Address))
         {
             continue;
         }
         if (localIPs.Contains(nodeServer.Value.EndPoint.Address))
         {
             continue;
         }
         if (ContainsKey(nodeServer.Value.ToString()))
         {
             continue;
         }
         if (nodeServer.Value.Port != Node.NetParams.Port)
         {
             continue;
         }
         TryAddNew(nodeServer.Value.ToString(), nodeServer.Value);
     }
     if (Count <= 100)
     {
         return;
     }
     foreach (var l in nodeServers)
     {
         TryRemove(l.Key, out NodeServer n);
     }
 }
Пример #2
0
        internal static NodeServerList LoadFromStream(Stream stream, ushort serverPort)
        {
            NodeServerList ns = new NodeServerList();

            using (BinaryReader br = new BinaryReader(stream, Encoding.ASCII, true))
            {
                uint serverCount = br.ReadUInt32();
                for (int i = 0; i < serverCount; i++)
                {
                    NodeServer server = new NodeServer();
                    ushort     iplen  = br.ReadUInt16();
                    server.IP             = br.ReadBytes(iplen);
                    server.Port           = br.ReadUInt16();
                    server.LastConnection = br.ReadUInt32();
                    server.ServerPort     = serverPort;
                    ns.TryAdd(server.ToString(), server);
                }
            }
            return(ns);
        }