Example #1
0
        public async Task <bool> AddRecord(DNSEntry entry)
        {
            ShamanDomain domain = new ShamanDomain();

            domain.domain  = entry.Domain;
            domain.records = new List <Record>();
            domain.records.Add(new Record()
            {
                address = entry.Value,
                type    = entry.Type,
                _class  = "IN"
            });


            var contentRequest = new StringContent(domain.ToJson());

            contentRequest.Headers.Add("X-AUTH-TOKEN", "xxx");
            var result = await client.PostAsync($"{this.domain}/records", contentRequest);

            if (result.StatusCode == HttpStatusCode.OK)
            {
                return(true);
            }
            return(false);
        }
Example #2
0
 internal void Register(string name, string guid, int addr)
 {
     nameMap[name] = new DNSEntry
     {
         Name           = name,
         CurrentAddress = addr,
         GUID           = guid
     };
 }
Example #3
0
        private void Loop()
        {
            Log("Starting DNS Server. Thead ID: " + Thread.CurrentThread.ManagedThreadId);
            NetworkPortListener listener = OpenPort(DNS_SERVER_PORT);

            if (m_DefaultName != null)
            {
                nameMap[m_DefaultName] = new DNSEntry
                {
                    Name           = m_DefaultName,
                    CurrentAddress = NetworkAddress,
                    GUID           = GUID
                };
            }

            while (true)
            {
                if (m_Exit)
                {
                    break;
                }

                while (listener.PacketCount != 0)
                {
                    NetworkPacket packet = listener.ReadPacket();

                    if (packet.Data.Length == 0)
                    {
                        continue; //Drop Packet
                    }

                    uint cmd = packet.Data[0];

                    if (cmd == DNS_CMD_REGISTER && packet.Data.Length > 1)
                    {
                        string data = new string( packet.Data.Skip(1).Select(x => ( char )x).ToArray());
                        string name = data.Remove(0, 36);   //Remove GUID
                        string guid = data.Remove(36);      //Remove Name

                        if (nameMap.TryGetValue(name, out DNSEntry e))
                        {
                            if (guid == e.GUID)   //Update the Address.
                            {
                                e.CurrentAddress = packet.Sender.NetworkAddress;
                                packet.Respond(this, new[] { 1u });
                            }
                            else
                            {
                                packet.Respond(this, new[] { 0u });
                            }
                        }
                        else
                        {
                            packet.Respond(this, new[] { 1u });

                            nameMap[name] = new DNSEntry
                            {
                                Name           = name,
                                CurrentAddress = packet.Sender.NetworkAddress,
                                GUID           = guid
                            };
                        }
                    }
                    else if (cmd == DNS_CMD_RESOLVE)
                    {
                        string name = new string( packet.Data.Skip(1).Select(x => ( char )x).ToArray());

                        if (nameMap.ContainsKey(name))
                        {
                            packet.Respond(this, new[] { ( uint )nameMap[name].CurrentAddress });
                        }
                        else
                        {
                            packet.Respond(this, new[] { 0u });
                        }
                    }
                }

                Thread.Sleep(NetworkSettings.DNSServerThreadSleep);
            }

            m_Exit = false;
        }
Example #4
0
 public bool TryResolve(string name, out DNSEntry entry)
 {
     return(nameMap.TryGetValue(name, out entry));
 }