Ejemplo n.º 1
0
    private async Task <string> GetHostAddress(CancellationToken stoppingToken)
    {
        if (!HostAddressNeedsUpdating())
        {
            return(_lastHostAddress);
        }

        _logger.LogInformation("Refreshing hosts IP Address ({url}) timeout = {timeout} ms",
                               _providerUrl,
                               _httpTimeoutMs);

        var request  = new HttpRequestMessage(HttpMethod.Get, _providerUrl);
        var response = await _httpService.SendAsync(request, _httpTimeoutMs, stoppingToken);

        var hostIpAddress = (await response.Content.ReadAsStringAsync(stoppingToken)).LowerTrim();

        if (!string.IsNullOrWhiteSpace(hostIpAddress))
        {
            _nextUpdate = _dateTime.Now.AddMinutes(_config.UpdateHostIpIntervalMin);
            return(hostIpAddress);
        }

        _logger.LogWarning("Got empty response, returning old IP Address to be safe");
        return(_lastHostAddress);
    }
Ejemplo n.º 2
0
    private async Task UpdateFreeDnsEntry(DnsUpdaterEntry entry, CancellationToken stoppingToken)
    {
        var updateUrl = entry.GetConfig(ConfigKeys.Url);
        var timeoutMs = entry.GetIntConfig(ConfigKeys.TimeoutMs, _config.DefaultHttpTimeoutMs);
        var request   = new HttpRequestMessage(HttpMethod.Get, updateUrl);
        var response  = await _httpService.SendAsync(request, timeoutMs, stoppingToken);

        var responseBody = await response.Content.ReadAsStringAsync(stoppingToken);

        _logger.LogInformation("Update response for {entryName}: ({code}) {body}",
                               entry.Name,
                               (int)response.StatusCode,
                               responseBody);
    }