Ejemplo n.º 1
0
void
magnet_add_sha1_source(struct magnet_resource *res, const struct sha1 *sha1,
	const host_addr_t addr, const uint16 port, const struct guid *guid,
	const gnet_host_vec_t *proxies)
{
	struct magnet_source *s;

	g_return_if_fail(res);
	g_return_if_fail(sha1);
	g_return_if_fail(!res->sha1 || sha1_eq(res->sha1, sha1));
	g_return_if_fail(guid != NULL || port_is_valid(port));

	if (!res->sha1) {
		magnet_set_sha1(res, sha1);
	}

	s = magnet_source_new();
	s->addr = addr;
	s->port = port;
	s->sha1 = atom_sha1_get(sha1);
	s->guid = guid ? atom_guid_get(guid) : NULL;

	if (proxies != NULL) {
		int i, n;
		GSList *sl = NULL;

		n = gnet_host_vec_count(proxies);
		for (i = 0; i < n; i++) {
			gnet_host_t host;

			host = gnet_host_vec_get(proxies, i);
			sl = g_slist_prepend(sl, gnet_host_dup(&host));
		}

		s->proxies = sl;
	}

	magnet_add_source(res, s);
}
Ejemplo n.º 2
0
/*
 * @return stringified host vector as newly allocated string via halloc()
 */
char *
gnet_host_vec_to_string(const gnet_host_vec_t *hvec)
{
	str_t *s;
	uint i, n;

	g_return_val_if_fail(hvec, NULL);

	s = str_new(0);
	n = gnet_host_vec_count(hvec);
	for (i = 0; i < n; i++) {
		gnet_host_t host;
		gchar buf[128];

		if (i > 0) {
			STR_CAT(s, ", ");
		}
		host = gnet_host_vec_get(hvec, i);
		host_addr_port_to_string_buf(gnet_host_get_addr(&host),
			gnet_host_get_port(&host), buf, sizeof buf);
		str_cat(s, buf);
	}
	return str_s2c_null(&s);
}