示例#1
0
/**
 * Request asynchronous DNS resolution for item, prior to inserting to
 * the whitelist or updating the existing host address (when revalidating).
 */
static void
whitelist_dns_resolve(struct whitelist *item, bool revalidate)
{
	struct whitelist_dns *ctx;
	char *host;

	g_assert(item != NULL);
	g_assert(revalidate || !is_host_addr(item->addr));
	g_assert(item->host != NULL);

	/*
	 * Since resolution is normally going to happen asynchronously, we must
	 * keep track of the generation at which the resolution was requested.
	 */

	WALLOC(ctx);
	ctx->item = item;
	ctx->generation = whitelist_generation;
	ctx->revalidate = revalidate;

	host = item->host->name;

	if (adns_resolve(host, settings_dns_net(), whitelist_dns_cb, ctx)) {
		/* Asynchronous resolution */
		if (GNET_PROPERTY(whitelist_debug) > 1)
			log_whitelist_item(item, "asynchronously resolving");
	} else {
		/* Synchronous resolution, whitelist_dns_cb() already called */
	}
}
示例#2
0
/**
 * Try with next host in the (already shuffled) list.
 */
static void
uhc_try_next(void)
{
	host_addr_t addr;

	g_assert(uhc_connecting);
	g_assert(uhc_ctx.timeout_ev == NULL);

	if (!uhc_pick()) {
		uhc_connecting = FALSE;
		return;
	}

	/*
	 * The following may recurse if resolution is synchronous, but
	 * we're protected by the `attempts' counter.
	 */

	if (string_to_host_addr(uhc_ctx.host, NULL, &addr)) {
		uhc_ctx.addr = addr;

		if (GNET_PROPERTY(bootstrap_debug))
			g_debug("BOOT UDP host cache \"%s\"", uhc_ctx.host);

		uhc_send_ping();
	} else {
		(void) adns_resolve(uhc_ctx.host, settings_dns_net(),
					uhc_host_resolved, NULL);
	}
}
示例#3
0
文件: ui2c.c 项目: Haxe/gtk-gnutella
/*	adns interface functions (UI -> Core)*/
gboolean
guc_adns_resolve(const char *hostname,
                 adns_callback_t user_callback, gpointer user_data)
{
    return adns_resolve(hostname, settings_dns_net(), user_callback, user_data);
}