static struct magnet_source * magnet_parse_push_source(const char *uri, const char **error_str) { struct magnet_source *ms; const char *p, *endptr; struct guid guid; clear_error_str(&error_str); g_return_val_if_fail(uri, NULL); p = is_strprefix(uri, "push://"); g_return_val_if_fail(p, NULL); endptr = strchr(p, ':'); /* First push-proxy host */ if (NULL == endptr || GUID_HEX_SIZE != (endptr - p)) endptr = strchr(p, '/'); /* No push-proxy host */ if ( NULL == endptr || GUID_HEX_SIZE != (endptr - p) || !hex_to_guid(p, &guid) ) { *error_str = "Bad GUID in push source"; return NULL; } ms = magnet_parse_proxy_location(endptr, error_str); if (ms) { ms->guid = atom_guid_get(&guid); } return ms; }
/** * Create new record for query hits for specified MUID. * New record is registered in the current table. */ static dqhit_t * dh_create(const struct guid *muid) { dqhit_t *dh; const struct guid *key; WALLOC0(dh); key = atom_guid_get(muid); htable_insert(by_muid, key, dh); return dh; }
/** * Generate a new GUID atom that is not already conflicting with any other * GUID recorded in the supplied hikset (hash set with values pointing to * the GUID key). * * @attention * It is up to the caller to later insert the value referencing this GUID in * the hikset to prevent further duplicates. To avoid race conditions between * the checking of the hiset and the insertion, the hikset should be locked * if it is shared by multiple threads. * * @param hik the hikset against which we need to check for duplicates * @param gtkg whether to flag the GUID as being generated by GTKG. * * @return a new unique GUID atom. */ const guid_t * guid_unique_atom(const hikset_t *hik, bool gtkg) { int i; guid_t guid; entropy_harvest_time(); for (i = 0; i < 100; i++) { guid_random_fill(&guid); if (gtkg) guid_flag_gtkg(&guid); /* Mark as being from GTKG */ if (NULL == hikset_lookup(hik, &guid)) return atom_guid_get(&guid); } g_error("%s(): no luck with random number generator", G_STRFUNC); }
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); }