public void TestValidUpstream() { UpstreamOptions upstreamOptions = ConfigurationHelper.CreateUpstreamOptions(); bool result = DnsApi.Instance.TestUpstream(upstreamOptions); Assert.IsTrue(result); }
internal static AGDnsApi.ag_upstream_options ToNativeObject( UpstreamOptions upstreamOptions, Queue <IntPtr> allocatedPointers) { AGDnsApi.ag_list bootstrapC = MarshalUtils.ListToAgList( upstreamOptions.Bootstrap, MarshalUtils.StringToPtr, allocatedPointers); byte[] addressBytes = null; if (upstreamOptions.ResolvedIpAddress != null) { addressBytes = upstreamOptions.ResolvedIpAddress.GetAddressBytes(); } AGDnsApi.ag_buffer addressC = MarshalUtils.BytesToAgBuffer(addressBytes, allocatedPointers); AGDnsApi.ag_upstream_options upstreamOptionsC = new AGDnsApi.ag_upstream_options { bootstrap = bootstrapC, resolved_ip_address = addressC }; MarshalUtils.CopyPropertiesToFields(upstreamOptions, ref upstreamOptionsC); MarshalUtils.AllStringsToPtrs(upstreamOptions, ref upstreamOptionsC, allocatedPointers); return(upstreamOptionsC); }
public Task SetUpstreamOptions(UpstreamOptions options) { options.Timestamp = systemClock.UtcNow.UtcDateTime; StorageService.Repo.Upsert(options); logger.Swallow(() => messageHub.Publish(options)); return(Task.CompletedTask); }
public void TestInvalidUpstream() { UpstreamOptions upstreamOptions = ConfigurationHelper.CreateUpstreamOptions(); upstreamOptions.Address = "huemoe"; bool result = DnsApi.Instance.TestUpstream(upstreamOptions); Assert.IsFalse(result); }
private static UpstreamOptions CreateUpstreamOptions() { UpstreamOptions upstreamOptions = new UpstreamOptions { Address = "94.140.14.14", Bootstrap = new List <string>(), TimeoutMs = 5000, Id = 42, OutboundInterfaceIndex = 0 }; return(upstreamOptions); }
internal static UpstreamOptions CreateUpstreamOptions() { UpstreamOptions upstreamOptions = new UpstreamOptions { Address = "8.8.8.8:53", Bootstrap = new List <string>(), TimeoutMs = 500, ResolvedIpAddress = null, Id = 42, OutboundInterfaceIndex = 0 }; return(upstreamOptions); }
private static UpstreamOptions FromNativeObject(AGDnsApi.ag_upstream_options upstreamOptionsC) { List <string> bootstrap = MarshalUtils.AgListToList <IntPtr, string>( upstreamOptionsC.bootstrap, MarshalUtils.PtrToString); IPAddress serverAddress = CreateIpAddress(upstreamOptionsC.resolved_ip_address); UpstreamOptions upstreamOptions = new UpstreamOptions { Bootstrap = bootstrap, ResolvedIpAddress = serverAddress }; MarshalUtils.CopyFieldsToProperties(upstreamOptionsC, upstreamOptions); MarshalUtils.AllPtrsToStrings(upstreamOptionsC, upstreamOptions); return(upstreamOptions); }
/// <summary> /// Checks if upstream is valid and available /// </summary> /// <param name="upstreamOptions">Upstream options /// (<seealso cref="UpstreamOptions"/>)</param> /// <exception cref="InvalidOperationException"></exception> /// <returns>True, if test has completed successfully, /// otherwise false</returns> public bool TestUpstream(UpstreamOptions upstreamOptions) { lock (SYNC_ROOT) { try { LOG.InfoFormat("Testing upstream"); bool result = DnsUtils.TestUpstream(upstreamOptions); LOG.InfoFormat("Testing upstream has been successfully completed"); return(result); } catch (Exception ex) { LOG.ErrorFormat("Testing upstream failed with an error", ex); return(false); } } }
/// <summary> /// Checks if upstream is valid and available /// </summary> /// <param name="upstreamOptions">Upstream options /// (<seealso cref="UpstreamOptions"/>)</param> /// <param name="ipv6Available">Whether IPv6 is available (i.e., bootstrapper is allowed to make AAAA queries)</param> /// <param name="offline">Don't perform online upstream check</param> public static bool TestUpstream(UpstreamOptions upstreamOptions, bool ipv6Available, bool offline) { IntPtr pUpstreamOptionsC = IntPtr.Zero; Queue <IntPtr> allocatedPointers = new Queue <IntPtr>(); IntPtr pError = IntPtr.Zero; try { Logger.Info("Start testing upstream {0}", upstreamOptions); CertificateVerificationCallback certificateVerificationCallback = new CertificateVerificationCallback(); AGDnsApi.ag_upstream_options upstreamOptionsC = DnsApiConverter.ToNativeObject(upstreamOptions, allocatedPointers); AGDnsApi.cbd_onCertificateVerification testUpstreamCallbackC = DnsApiConverter.ToNativeObject(certificateVerificationCallback); pUpstreamOptionsC = MarshalUtils.StructureToPtr(upstreamOptionsC); pError = AGDnsApi.ag_test_upstream(pUpstreamOptionsC, ipv6Available, testUpstreamCallbackC, offline); string error = MarshalUtils.PtrToString(pError); if (string.IsNullOrEmpty(error)) { Logger.Info("Testing upstream has been completed successfully"); return(true); } Logger.Info("Testing upstream failed with an error {0}", error); return(false); } catch (Exception ex) { Logger.Info("Testing upstream failed with an error {0}", ex); return(false); } finally { AGDnsApi.ag_str_free(pError); MarshalUtils.SafeFreeHGlobal(allocatedPointers); MarshalUtils.SafeFreeHGlobal(pUpstreamOptionsC); } }
public async Task Put([FromBody] UpstreamOptions options) { await upstreamOptionsStorage.SetUpstreamOptions(options); }