Esempio n. 1
0
        static async Task UpdateHostnameAsync()
        {
            try
            {
                _remote = await ResolveRemoteAddressAsync();
            }
            catch (Exception ex)
            {
                E($"resolve remote hostname failed: {ex}");
            }

            while (!_cts.IsCancellationRequested)
            {
                try
                {
                    using (var req = new HttpRequestMessage(HttpMethod.Get, string.Format(HOSTNAME_UPDATE_URL, _hostname, _remote)))
                    {
                        req.Headers.TryAddWithoutValidation("User-Agent", USER_AGENT);
                        req.Headers.TryAddWithoutValidation("Authorization", $"Basic {GetAuthorizationHeader(_username, _password)}");

                        using (var res = await _client.SendAsync(req))
                        {
                            var result = await res.Content.ReadAsStringAsync();

                            switch (result.Replace("\r\n", "\n").Replace("\n", ""))
                            {
                            case "nohost": E("Hostname supplied does not exist under specified account."); break;

                            case "badauth": E("Invalid username password combination."); break;

                            case "badagent": E("Client disabled. Client should exit and not perform any more updates without user intervention."); break;

                            case "!donator":
                            case "donator": E("An update request was sent including a feature that is not available to that particular user such as offline options."); break;

                            case "abuse": E("Username is blocked due to abuse."); break;

                            case "911":
                            {
                                M("A fatal error on our side such as a database outage. Retry the update no sooner than 30 minutes.");
                                _flags |= LoopFlags.Outage;
                            }
                            break;

                            default:
                            {
                                if (result.StartsWith("good") || result.StartsWith("nochg"))
                                {
                                    var op = result.Split(' ')[0];

                                    if (op == "good")
                                    {
                                        M("[Success] DNS hostname update successful.");
                                        _flags = LoopFlags.None;
                                    }

                                    if (op == "nochg")
                                    {
                                        M("[Success] IP address is current, no update performed.");
                                        _flags = LoopFlags.None;
                                    }
                                }
                                else
                                {
                                    M("[Warning] Unknown response: " + result + ".");
                                    _flags = LoopFlags.Unknown;
                                }
                            }
                            break;
                            }
                        }
                    }

                    if ((_flags & LoopFlags.Outage) != 0)
                    {
                        var ts = TimeSpan.FromMinutes(30d);
                        _expirationTime = DateTime.UtcNow.Add(ts);
                        await Task.Delay(ts);
                    }
                    else if ((_flags & LoopFlags.Unknown) != 0)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(5d));
                    }
                    else
                    {
                        _expirationTime = DateTime.UtcNow.Add(HOSTNAME_UPDATE_INTERVAL);
                        await Task.Delay(HOSTNAME_UPDATE_INTERVAL);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Update hostname failed: " + ex.Message);
                }
            }
        }
Esempio n. 2
0
 public Block(BinaryReader reader)
 {
     DecodingCoeff = reader.ReadByte();
     LoopFlags     = (LoopFlags)reader.ReadByte();
     Data          = reader.ReadBytes(14);
 }