这篇教程C++ GNET_PROPERTY函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中GNET_PROPERTY函数的典型用法代码示例。如果您正苦于以下问题:C++ GNET_PROPERTY函数的具体用法?C++ GNET_PROPERTY怎么用?C++ GNET_PROPERTY使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了GNET_PROPERTY函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: knode_change_vendor/** * Change node's vendor code. */voidknode_change_vendor(knode_t *kn, vendor_code_t vcode){ knode_check(kn); if (GNET_PROPERTY(dht_debug)) { char vc_old[VENDOR_CODE_BUFLEN]; char vc_new[VENDOR_CODE_BUFLEN]; vendor_code_to_string_buf(kn->vcode.u32, vc_old, sizeof vc_old); vendor_code_to_string_buf(vcode.u32, vc_new, sizeof vc_new); g_warning("DHT node %s at %s changed vendor from %s to %s", kuid_to_hex_string(kn->id), host_addr_port_to_string(kn->addr, kn->port), vc_old, vc_new); } kn->vcode = vcode;}
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:23,
示例2: huge_need_sha1/** * Look whether we still need to compute the SHA1 of the given shared file * by looking into our in-core cache to see whether the entry we have is * up-to-date. * * @param sf the shared file for which we want to compute the SHA1 * * @return TRUE if the file need SHA1 recomputation. */static boolhuge_need_sha1(shared_file_t *sf){ struct sha1_cache_entry *cached; shared_file_check(sf); /* * After a rescan, there might be files in the queue which are * no longer shared. */ if (!shared_file_indexed(sf)) return FALSE; if G_UNLIKELY(NULL == sha1_cache) return FALSE; /* Shutdown occurred (processing TEQ event?) */ cached = hikset_lookup(sha1_cache, shared_file_path(sf)); if (cached != NULL) { filestat_t sb; if (-1 == stat(shared_file_path(sf), &sb)) { g_warning("ignoring SHA1 recomputation request for /"%s/": %m", shared_file_path(sf)); return FALSE; } if ( cached->size + (fileoffset_t) 0 == sb.st_size + (filesize_t) 0 && cached->mtime == sb.st_mtime ) { if (GNET_PROPERTY(share_debug) > 1) { g_warning("ignoring duplicate SHA1 work for /"%s/"", shared_file_path(sf)); } return FALSE; } } return TRUE;}
开发者ID:lucab,项目名称:gtk-gnutella,代码行数:50,
示例3: keys_reclaim/** * Reclaim key info and data. * * @param ki the keyinfo to reclaim * @param can_remove whether to remove from the `keys' set */static voidkeys_reclaim(struct keyinfo *ki, bool can_remove){ g_assert(ki); g_assert(0 == ki->values); if (GNET_PROPERTY(dht_storage_debug) > 2) g_debug("DHT STORE key %s reclaimed", kuid_to_hex_string(ki->kuid)); dbmw_delete(db_keydata, ki->kuid); if (can_remove) hikset_remove(keys, &ki->kuid); gnet_stats_dec_general(GNR_DHT_KEYS_HELD); if (ki->flags & DHT_KEY_F_CACHED) gnet_stats_dec_general(GNR_DHT_CACHED_KEYS_HELD); kuid_atom_free_null(&ki->kuid); ki->magic = 0; WFREE(ki);}
开发者ID:lucab,项目名称:gtk-gnutella,代码行数:27,
示例4: keys_periodic_load/** * Callout queue periodic event for request load updates. * Also reclaims dead keys holding no values. */static boolkeys_periodic_load(void *unused_obj){ struct load_ctx ctx; (void) unused_obj; ctx.values = 0; ctx.now = tm_time(); hikset_foreach_remove(keys, keys_update_load, &ctx); g_assert(values_count() == ctx.values); if (GNET_PROPERTY(dht_storage_debug)) { size_t keys_count = hikset_count(keys); g_debug("DHT holding %zu value%s spread over %zu key%s", ctx.values, plural(ctx.values), keys_count, plural(keys_count)); } return TRUE; /* Keep calling */}
开发者ID:lucab,项目名称:gtk-gnutella,代码行数:25,
示例5: sq_clear/** * Clear all queued searches. */voidsq_clear(squeue_t *sq){ GList *l; g_assert(sq); if (GNET_PROPERTY(sq_debug) > 3) g_debug("clearing sq node %s (sent=%d, dropped=%d)", sq->node ? node_addr(sq->node) : "GLOBAL", sq->n_sent, sq->n_dropped); for (l = sq->searches; l; l = g_list_next(l)) { smsg_t *sb = l->data; smsg_discard(sb); } gm_list_free_null(&sq->searches); sq->count = 0;}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:24,
示例6: natpmp_update/** * Update internal information about the NAT-PMP gateway upon reception * of an RPC reply. */static voidnatpmp_update(natpmp_t *np, unsigned sssoe){ time_delta_t d; unsigned conservative_sssoe; natpmp_check(np); d = delta_time(tm_time(), np->last_update); conservative_sssoe = uint_saturate_add(np->sssoe, 7 * d / 8); if (sssoe < conservative_sssoe && conservative_sssoe - sssoe > 1) { np->rebooted = TRUE; if (GNET_PROPERTY(natpmp_debug) > 1) { g_debug("NATPMP new SSSOE=%u < conservative SSSOE=%u, %s rebooted", sssoe, conservative_sssoe, host_addr_to_string(np->gateway)); } } np->last_update = tm_time(); np->sssoe = sssoe;}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:26,
示例7: guid_add_banned/** * Add GUID to the banned list or refresh the fact that we are still seeing * it as being worth banning. */voidguid_add_banned(const struct guid *guid){ struct guiddata *gd; struct guiddata new_gd; gd = get_guiddata(guid); if (NULL == gd) { gd = &new_gd; gd->create_time = gd->last_time = tm_time(); gnet_stats_inc_general(GNR_BANNED_GUID_HELD); if (GNET_PROPERTY(guid_debug)) { g_debug("GUID banning %s", guid_hex_str(guid)); } } else { gd->last_time = tm_time(); } dbmw_write(db_guid, guid, gd, sizeof *gd);}
开发者ID:qgewfg,项目名称:gtk-gnutella,代码行数:26,
示例8: dump_tx_udp_packet/** * Dump locally-emitted message block sent via UDP. */voiddump_tx_udp_packet(const gnet_host_t *to, const pmsg_t *mb){ if (GNET_PROPERTY(dump_transmitted_gnutella_packets)) { struct gnutella_node udp; g_assert(to != NULL); g_assert(mb != NULL); /* * Fill only the fields which will be perused by * dump_packet_from_to(). */ udp.peermode = NODE_P_UDP; udp.addr = gnet_host_get_addr(to); udp.port = gnet_host_get_port(to); dump_packet_from_to(&dump_tx, NULL, &udp, mb); } else if (dump_tx.initialized) { dump_disable(&dump_tx); }}
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:26,
示例9: host_cache_allow_bypass/* * Avoid nodes being stuck helplessly due to completely stale caches. * @return TRUE if an UHC may be contact, FALSE if it's not permissable. */static gbooleanhost_cache_allow_bypass(void){ static time_t last_try; if (node_count() > 0) return FALSE; /* Wait at least 2 minutes after starting up */ if (delta_time(tm_time(), GNET_PROPERTY(start_stamp)) < 2 * 60) return FALSE; /* * Allow again after 12 hours, useful after unexpected network outage * or downtime. */ if (last_try && delta_time(tm_time(), last_try) < 12 * 3600) return FALSE; last_try = tm_time(); return TRUE;}
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:27,
示例10: ctl_limit/** * Are specified flags all set for the country to which the IP address belongs? */boolctl_limit(const host_addr_t ha, unsigned flags){ uint16 code; unsigned cflags; /* * Early optimization to avoid paying the price of gip_country_safe(): * If no flags are given, or the set of flags requested is not a subset * of all the flags ever specified for all countries, we can return. */ if (0 == flags) return FALSE; if ((flags & ctl_all_flags) != flags) return FALSE; code = gip_country_safe(ha); if (ISO3166_INVALID == code) return FALSE; if (GNET_PROPERTY(ancient_version)) return FALSE; cflags = pointer_to_uint( htable_lookup(ctl_by_country, uint_to_pointer(code))); if ((cflags & flags) != flags) return FALSE; if ((cflags & CTL_D_WHITELIST) && whitelist_check(ha)) return FALSE; return TRUE;}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:40,
示例11: hsep_notify_sharedvoidhsep_notify_shared(uint64 own_files, uint64 own_kibibytes){ /* check for change */ if ( own_files != hsep_own[HSEP_IDX_FILES] || own_kibibytes != hsep_own[HSEP_IDX_KIB] ) { if (GNET_PROPERTY(hsep_debug)) { g_debug("HSEP: Shared files changed to %s (%s KiB)", uint64_to_string(own_files), uint64_to_string2(own_kibibytes)); } hsep_own[HSEP_IDX_FILES] = own_files; hsep_own[HSEP_IDX_KIB] = own_kibibytes; /* * We could send a HSEP message to all nodes now, but these changes * will propagate within at most HSEP_MSG_INTERVAL + HSEP_MSG_SKEW * seconds anyway. */ }}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:24,
示例12: tls_socket_evt_change/** * Change the monitoring condition on the socket. */static voidtls_socket_evt_change(struct gnutella_socket *s, inputevt_cond_t cond){ socket_check(s); g_assert(socket_with_tls(s)); /* No USES yet, may not have handshaked */ g_assert(INPUT_EVENT_EXCEPTION != cond); if (0 == s->gdk_tag) return; if (cond != s->tls.cb_cond) { int saved_errno = errno; if (GNET_PROPERTY(tls_debug) > 1) { int fd = socket_evt_fd(s); g_debug("tls_socket_evt_change: fd=%d, cond=%s -> %s", fd, inputevt_cond_to_string(s->tls.cb_cond), inputevt_cond_to_string(cond)); } inputevt_remove(&s->gdk_tag); socket_evt_set(s, cond, s->tls.cb_handler, s->tls.cb_data); errno = saved_errno; }}
开发者ID:Longdengyu,项目名称:gtk-gnutella,代码行数:27,
示例13: stable_init/** * Initialize node stability caching. */G_GNUC_COLD voidstable_init(void){ dbstore_kv_t kv = { KUID_RAW_SIZE, NULL, sizeof(struct lifedata), 0 }; dbstore_packing_t packing = { serialize_lifedata, deserialize_lifedata, NULL }; g_assert(NULL == db_lifedata); g_assert(NULL == stable_sync_ev); g_assert(NULL == stable_prune_ev); db_lifedata = dbstore_open(db_stable_what, settings_dht_db_dir(), db_stable_base, kv, packing, STABLE_DB_CACHE_SIZE, kuid_hash, kuid_eq, GNET_PROPERTY(dht_storage_in_memory)); dbmw_set_map_cache(db_lifedata, STABLE_MAP_CACHE_SIZE); stable_prune_old(); stable_sync_ev = cq_periodic_main_add(STABLE_SYNC_PERIOD, stable_sync, NULL); stable_prune_ev = cq_periodic_main_add(STABLE_PRUNE_PERIOD, stable_periodic_prune, NULL);}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:27,
示例14: gnet_stats_count_dropped_nosizevoidgnet_stats_count_dropped_nosize( const gnutella_node_t *n, msg_drop_reason_t reason){ uint type; gnet_stats_t *stats; g_assert(UNSIGNED(reason) < MSG_DROP_REASON_COUNT); g_assert(thread_is_main()); g_assert(!NODE_TALKS_G2(n)); type = stats_lut[gnutella_header_get_function(&n->header)]; stats = NODE_USES_UDP(n) ? &gnet_udp_stats : &gnet_tcp_stats; entropy_harvest_small(VARLEN(n->addr), VARLEN(n->port), NULL); /* Data part of message not read */ DROP_STATS(stats, type, sizeof(n->header)); if (GNET_PROPERTY(log_dropped_gnutella)) gmsg_log_split_dropped(&n->header, n->data, 0, "from %s: %s", node_infostr(n), gnet_stats_drop_reason_to_string(reason));}
开发者ID:Longdengyu,项目名称:gtk-gnutella,代码行数:24,
示例15: sq_puthere/** * Enqueue query message in specified queue. */static voidsq_puthere(squeue_t *sq, gnet_search_t sh, pmsg_t *mb, query_hashvec_t *qhv){ smsg_t *sb; g_assert(sq); g_assert(mb); if (sqh_exists(sq, sh)) { pmsg_free(mb); if (qhv) qhvec_free(qhv); return; /* Search already in queue */ } sb = smsg_alloc(sh, mb, qhv); sqh_put(sq, sh); sq->searches = g_list_prepend(sq->searches, sb); sq->count++; if (sq->count > GNET_PROPERTY(search_queue_size)) cap_queue(sq);}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:27,
示例16: mq_udp_putq/** * Enqueue message, which becomes owned by the queue. * * The data held in `to' is copied, so the structure can be reclaimed * immediately by the caller. */voidmq_udp_putq(mqueue_t *q, pmsg_t *mb, const gnet_host_t *to){ size_t size; char *mbs; uint8 function; pmsg_t *mbe = NULL; /* Extended message with destination info */ bool error = FALSE; mq_check_consistency(q); dump_tx_udp_packet(to, mb);again: mq_check_consistency(q); g_assert(mb); g_assert(!pmsg_was_sent(mb)); g_assert(pmsg_is_unread(mb)); g_assert(q->ops == &mq_udp_ops); /* Is an UDP queue */ /* * Trap messages enqueued whilst in the middle of an mq_clear() operation * by marking them as sent and dropping them. Idem if queue was * put in "discard" mode. */ if (q->flags & (MQ_CLEAR | MQ_DISCARD)) { pmsg_mark_sent(mb); /* Let them think it was sent */ pmsg_free(mb); /* Drop message */ return; } mq_check(q, 0); size = pmsg_size(mb); if (size == 0) { g_carp("%s: called with empty message", G_STRFUNC); goto cleanup; } /* * Protect against recursion: we must not invoke puthere() whilst in * the middle of another putq() or we would corrupt the qlink array: * Messages received during recursion are inserted into the qwait list * and will be stuffed back into the queue when the initial putq() ends. * --RAM, 2006-12-29 */ if (q->putq_entered > 0) { pmsg_t *extended; if (debugging(20)) g_warning("%s: %s recursion detected (%u already pending)", G_STRFUNC, mq_info(q), slist_length(q->qwait)); /* * We insert extended messages into the waiting queue since we need * the destination information as well. */ extended = mq_udp_attach_metadata(mb, to); slist_append(q->qwait, extended); return; } q->putq_entered++; mbs = pmsg_start(mb); function = gmsg_function(mbs); gnet_stats_count_queued(q->node, function, mbs, size); /* * If queue is empty, attempt a write immediatly. */ if (q->qhead == NULL) { ssize_t written; if (pmsg_check(mb, q)) { written = tx_sendto(q->tx_drv, mb, to); } else { gnet_stats_count_flowc(mbs, FALSE); node_inc_txdrop(q->node); /* Dropped during TX */ written = (ssize_t) -1; } if ((ssize_t) -1 == written) goto cleanup; node_add_tx_given(q->node, written); if ((size_t) written == size) { if (GNET_PROPERTY(mq_udp_debug) > 5)//.........这里部分代码省略.........
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:101,
示例17: udp_received//.........这里部分代码省略......... bws_udp_count_read(len, FALSE); /* We know it's not DHT traffic */ rx = udp_get_rx_semi_reliable(utp, s->addr, len); if (rx != NULL) { gnet_host_t from; gnet_host_set(&from, s->addr, s->port); ut_got_message(rx, data, len, &from); } return; }unknown: /* * Discriminate between Gnutella UDP and DHT messages, so that we * can account received data with the proper bandwidth scheduler. */ if (len >= GTA_HEADER_SIZE) dht = GTA_MSG_DHT == gnutella_header_get_function(data); /* FALL THROUGH */unreliable: /* * Account for Gnutella / DHT incoming UDP traffic. */ bws_udp_count_read(len, dht); /* FALL THROUGH */rudp: /* * The RUDP layer is used to implement firewalled-to-firewalled transfers * via a mini TCP-like layer built on top of UDP. Therefore, it is used * as the basis for higher-level connections (HTTP) and will have to be * accounted for once the type of traffic is known, by upper layers, as * part of the upload/download traffic. * * Of course, the higher levels will never see all the bytes that pass * through, such as acknowledgments or retransmissions, but that is also * the case for TCP-based sockets. * --RAM, 2012-11-02. */ /* * If we get traffic from a bogus IP (unroutable), warn, for now. */ if (bogons_check(s->addr)) { bogus = TRUE; if (GNET_PROPERTY(udp_debug)) { g_warning("UDP %sdatagram (%zu byte%s) received from bogus IP %s", truncated ? "truncated " : "", len, 1 == len ? "" : "s", host_addr_to_string(s->addr)); } gnet_stats_inc_general(GNR_UDP_BOGUS_SOURCE_IP); } /* * Get proper pseudo-node. * * These routines can return NULL if the address/port combination is * not correct, but this will be handled by udp_is_valid_gnet(). */ n = dht ? node_dht_get_addr_port(s->addr, s->port) : node_udp_get_addr_port(s->addr, s->port); if (!udp_is_valid_gnet(n, s, truncated, data, len)) return; /* * RUDP traffic does not go to the upper Gnutella processing layers. */ if (rudp) { /* Not ready for prime time */#if 0 rudp_handle_packet(s->addr, s->port. data, len);#endif return; } /* * Process message as if it had been received from regular Gnet by * another node, only we'll use a special "pseudo UDP node" as origin. */ if (GNET_PROPERTY(udp_debug) > 19 || (bogus && GNET_PROPERTY(udp_debug))) g_debug("UDP got %s from %s%s", gmsg_infostr_full(data, len), bogus ? "BOGUS " : "", host_addr_port_to_string(s->addr, s->port)); node_udp_process(n, s, data, len);}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:101,
示例18: udp_intuit_traffic_type/** * Identify the traffic type received on the UDP socket. * * This routine uses simple heuristics that ensure we're properly discriminating * incoming traffic on the UDP socket between regular Gnutella traffic and * semi-reliable UDP traffic (which adds a small header before its actual * payload). * * Most messages will be un-ambiguous, and the probabilty of misclassifying * an ambiguous message (one that look like valid for both types, based on * header inspections) is brought down to less than 1 in a billion, making * it perfectly safe in practice. * * @return intuited type */static enum udp_trafficudp_intuit_traffic_type(const gnutella_socket_t *s, const void *data, size_t len){ enum udp_traffic utp; utp = udp_check_semi_reliable(data, len); if (len >= GTA_HEADER_SIZE) { uint16 size; /* Payload size, from the Gnutella message */ gmsg_valid_t valid; valid = gmsg_size_valid(data, &size); switch (valid) { case GMSG_VALID: case GMSG_VALID_MARKED: if ((size_t) size + GTA_HEADER_SIZE == len) { uint8 function, hops, ttl; function = gnutella_header_get_function(data); /* * If the header cannot be that of a known semi-reliable * UDP protocol, there is no ambiguity. */ if (UNKNOWN == utp) { return GTA_MSG_DHT == function ? DHT : GTA_MSG_RUDP == function ? RUDP : GNUTELLA; } /* * Message is ambiguous: its leading header appears to be * both a legitimate Gnutella message and a semi-reliable UDP * header. * * We have to apply some heuristics to decide whether to handle * the message as a Gnutella one or as a semi-reliable UDP one, * knowing that if we improperly classify it, the message will * not be handled correctly. * * Note that this is highly unlikely. There is about 1 chance * in 10 millions (1 / 2^23 exactly) to mis-interpret a random * Gnutella MUID as the start of one of the semi-reliable * protocols we support. Our discriminating logic probes a * few more bytes (say 2 at least) which are going to let us * decide with about 99% certainety. So mis-classification * will occur only once per billion -- a ratio which is OK. * * We could also mistakenely handle a semi-reliable UDP message * as a Gnutella one. For that to happen, the payload must * contain a field that will be exactly the message size, * a 1 / 2^32 event (since the size is 4 bytes in Gnutella). * However, if message flags are put to use for Gnutella UDP, * this ratio could lower to 1 / 2^16 and that is too large * a chance (about 1.5 in 100,000). * * So when we think an ambiguous message could be a valid * Gnutella message, we also check whether the message could * not be interpreted as a valid semi-reliable UDP one, and * we give priority to that classification if we have a match: * correct sequence number, consistent count and emitting host. * This checks roughly 3 more bytes in the message, yielding * a misclassification for about 1 / 2^(16+24) random cases. */ hops = gnutella_header_get_hops(data); ttl = gnutella_header_get_ttl(data); gnet_stats_inc_general(GNR_UDP_AMBIGUOUS); if (GNET_PROPERTY(udp_debug)) { g_debug("UDP ambiguous datagram from %s: " "%zu bytes (%u-byte payload), " "function=%u, hops=%u, TTL=%u, size=%u", host_addr_port_to_string(s->addr, s->port), len, size, function, hops, ttl, gnutella_header_get_size(data)); dump_hex(stderr, "UDP ambiguous datagram", data, len); } switch (function) { case GTA_MSG_DHT://.........这里部分代码省略.........
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:101,
示例19: udp_is_valid_gnet_split//.........这里部分代码省略......... * size mismatch, but we want to flag truncated messages as being * "too large" because this is mainly why we reject them. They may * be legitimate Gnutella packets, too bad. */ if (truncated) { msg = "Truncated (too large?)"; goto too_large; } /* * Message sizes are architecturally limited to 64K bytes. * * We don't ensure the leading bits are zero in the size field because * this constraint we put allows us to use those bits for flags in * future extensions. * * The downside is that we have only 3 bytes (2 bytes for the size and * 1 byte for the function type) to identify a valid Gnutella packet. */ switch (gmsg_size_valid(header, &size)) { case GMSG_VALID: case GMSG_VALID_MARKED: break; case GMSG_VALID_NO_PROCESS: msg = "Header flags undefined for now"; goto drop; case GMSG_INVALID: msg = "Invalid size (greater than 64 KiB without flags)"; goto not; /* Probably just garbage */ } if ((size_t) size + GTA_HEADER_SIZE != len) { msg = "Size mismatch"; goto not; } /* * We only support a subset of Gnutella message from UDP. In particular, * messages like HSEP data, BYE or QRP are not expected! */ switch (gnutella_header_get_function(header)) { case GTA_MSG_INIT: case GTA_MSG_INIT_RESPONSE: case GTA_MSG_VENDOR: case GTA_MSG_STANDARD: case GTA_MSG_PUSH_REQUEST: case GTA_MSG_SEARCH_RESULTS: case GTA_MSG_RUDP: case GTA_MSG_DHT: return TRUE; case GTA_MSG_SEARCH: if (settings_is_ultra() && GNET_PROPERTY(enable_guess)) { return TRUE; /* GUESS query accepted */ } msg = "Query from UDP refused"; goto drop; } msg = "Gnutella message not processed from UDP";drop: gnet_stats_count_dropped(n, MSG_DROP_UNEXPECTED); gnet_stats_inc_general(GNR_UDP_UNPROCESSED_MESSAGE); goto log;too_large: gnet_stats_count_dropped(n, MSG_DROP_TOO_LARGE); gnet_stats_inc_general(GNR_UDP_UNPROCESSED_MESSAGE); goto log;not: gnet_stats_inc_general(GNR_UDP_ALIEN_MESSAGE); /* FALL THROUGH */log: if (GNET_PROPERTY(udp_debug)) { g_warning("UDP got invalid %sGnutella packet (%zu byte%s) " "/"%s/" %sfrom %s: %s", socket_udp_is_old(s) ? "OLD " : "", len, 1 == len ? "" : "s", len >= GTA_HEADER_SIZE ? gmsg_infostr_full_split(header, payload, len - GTA_HEADER_SIZE) : "<incomplete Gnutella header>", truncated ? "(truncated) " : "", NULL == n ? host_addr_port_to_string(s->addr, s->port) : node_infostr(n), msg); if (len != 0) { iovec_t iov[2]; iovec_set(&iov[0], header, GTA_HEADER_SIZE); iovec_set(&iov[1], payload, len - GTA_HEADER_SIZE); dump_hex_vec(stderr, "UDP datagram", iov, G_N_ELEMENTS(iov)); } } return FALSE; /* Dropped */}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:101,
示例20: hsep_send_msgvoidhsep_send_msg(struct gnutella_node *n, time_t now){ hsep_triple tmp[G_N_ELEMENTS(n->hsep->sent_table)], other; unsigned int i, j, msglen, msgsize, triples, opttriples; gnutella_msg_hsep_t *msg; hsep_ctx_t *hsep; g_assert(n); g_assert(n->hsep); hsep = n->hsep; ZERO(&other); /* * If we are a leaf, we just need to send one triple, * which contains our own data (this triple is expanded * to the needed number of triples on the peer's side). * As the 0'th global and 0'th connection triple are zero, * it contains only our own triple, which is correct. */ triples = settings_is_leaf() ? 1 : G_N_ELEMENTS(tmp); /* * Allocate and initialize message to send. */ msgsize = GTA_HEADER_SIZE + triples * (sizeof *msg - GTA_HEADER_SIZE); msg = walloc(msgsize); { gnutella_header_t *header; header = gnutella_msg_hsep_header(msg); message_set_muid(header, GTA_MSG_HSEP_DATA); gnutella_header_set_function(header, GTA_MSG_HSEP_DATA); gnutella_header_set_ttl(header, 1); gnutella_header_set_hops(header, 0); } /* * Collect HSEP data to send and convert the data to * little endian byte order. */ if (triples > 1) { /* determine what we know about non-HSEP nodes in 1 hop distance */ hsep_get_non_hsep_triple(&other); } for (i = 0; i < triples; i++) { for (j = 0; j < G_N_ELEMENTS(other); j++) { uint64 val; val = hsep_own[j] + (0 == i ? 0 : other[j]) + hsep_global_table[i][j] - hsep->table[i][j]; poke_le64(&tmp[i][j], val); } } STATIC_ASSERT(sizeof hsep->sent_table == sizeof tmp); /* check if the table differs from the previously sent table */ if ( 0 == memcmp(tmp, hsep->sent_table, sizeof tmp) ) { WFREE_NULL(msg, msgsize); goto charge_timer; } memcpy(cast_to_char_ptr(msg) + GTA_HEADER_SIZE, tmp, triples * sizeof tmp[0]); /* store the table for later comparison */ memcpy(hsep->sent_table, tmp, triples * sizeof tmp[0]); /* * Note that on big endian architectures the message data is now in * the wrong byte order. Nevertheless, we can use hsep_triples_to_send() * with that data. */ /* optimize number of triples to send */ opttriples = hsep_triples_to_send(cast_to_pointer(tmp), triples); if (GNET_PROPERTY(hsep_debug) > 1) { printf("HSEP: Sending %d %s to node %s (msg #%u): ", opttriples, opttriples == 1 ? "triple" : "triples", host_addr_port_to_string(n->addr, n->port), hsep->msgs_sent + 1); } for (i = 0; i < opttriples; i++) { if (GNET_PROPERTY(hsep_debug) > 1) { char buf[G_N_ELEMENTS(hsep_own)][32]; for (j = 0; j < G_N_ELEMENTS(buf); j++) { uint64 v; v = hsep_own[j] + hsep_global_table[i][j] - hsep->table[i][j];//.........这里部分代码省略.........
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:101,
示例21: host_timer/** * Periodic host heartbeat timer. */voidhost_timer(void){ guint count; int missing; host_addr_t addr; guint16 port; host_type_t htype; guint max_nodes; gboolean empty_cache = FALSE; if (in_shutdown || !GNET_PROPERTY(online_mode)) return; max_nodes = settings_is_leaf() ? GNET_PROPERTY(max_ultrapeers) : GNET_PROPERTY(max_connections); count = node_count(); /* Established + connecting */ missing = node_keep_missing(); if (GNET_PROPERTY(host_debug) > 1) g_debug("host_timer - count %u, missing %u", count, missing); /* * If we are not connected to the Internet, apparently, make sure to * connect to at most one host, to avoid using all our hostcache. * Also, we don't connect each time we are called. */ if (!GNET_PROPERTY(is_inet_connected)) { static time_t last_try; if (last_try && delta_time(tm_time(), last_try) < 20) return; last_try = tm_time(); if (GNET_PROPERTY(host_debug)) g_debug("host_timer - not connected, trying to connect"); } /* * Allow more outgoing connections than the maximum amount of * established Gnet connection we can maintain, but not more * than quick_connect_pool_size This is the "greedy mode". */ if (count >= GNET_PROPERTY(quick_connect_pool_size)) { if (GNET_PROPERTY(host_debug) > 1) g_debug("host_timer - count %u >= pool size %u", count, GNET_PROPERTY(quick_connect_pool_size)); return; } if (count < max_nodes) missing -= whitelist_connect(); /* * If we are under the number of connections wanted, we add hosts * to the connection list */ htype = HOST_ULTRA; if ( settings_is_ultra() && GNET_PROPERTY(node_normal_count) < GNET_PROPERTY(normal_connections) && GNET_PROPERTY(node_ultra_count) >= (GNET_PROPERTY(up_connections) - GNET_PROPERTY(normal_connections)) ) { htype = HOST_ANY; } if (hcache_size(htype) == 0) htype = HOST_ANY; if (hcache_size(htype) == 0) empty_cache = TRUE; if (GNET_PROPERTY(host_debug) && missing > 0) g_debug("host_timer - missing %d host%s%s", missing, missing == 1 ? "" : "s", empty_cache ? " [empty caches]" : ""); if (!GNET_PROPERTY(stop_host_get)) { if (missing > 0) { static time_t last_try; unsigned fan, max_pool, to_add; max_pool = MAX(GNET_PROPERTY(quick_connect_pool_size), max_nodes); fan = (missing * GNET_PROPERTY(quick_connect_pool_size))/ max_pool; fan = MAX(1, fan); to_add = GNET_PROPERTY(is_inet_connected) ? fan : (guint) missing; /* * Every so many calls, attempt to ping all our neighbours to * get fresh pongs, in case our host cache is not containing * sufficiently fresh hosts and we keep getting connection failures. *///.........这里部分代码省略.........
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:101,
示例22: browse_host_read_html/** * Writes the browse host data of the context ``ctx'' to the buffer * ``dest''. This must be called multiple times to retrieve the complete * data until zero is returned i.e., the end of file is reached. * * This routine deals with HTML data generation. * * @param ctx an initialized browse host context. * @param dest the destination buffer. * @param size the amount of bytes ``dest'' can hold. * * @return -1 on failure, zero at the end-of-file condition or if size * was zero. On success, the amount of bytes copied to ``dest'' * is returned. */static ssize_tbrowse_host_read_html(struct special_upload *ctx, void *const dest, size_t size){ static const char header[] = "<!DOCTYPE html PUBLIC /"-//W3C//DTD HTML 4.01//EN/">/r/n" "<html>/r/n" "<head>/r/n" "<title>Browse Host</title>/r/n" "</head>/r/n" "<body>/r/n"; static const char trailer[] = "</ul>/r/n</body>/r/n</html>/r/n"; struct browse_host_upload *bh = cast_to_browse_host_upload(ctx); char *p = dest; g_assert(NULL != bh); g_assert(NULL != dest); g_assert(size <= INT_MAX); g_assert(UNSIGNED(bh->state) < NUM_BH_STATES); g_assert(bh->b_size <= INT_MAX); g_assert(bh->b_offset <= bh->b_size); do { switch (bh->state) { case BH_STATE_HEADER: if (!bh->b_data) { bh->b_data = header; bh->b_size = CONST_STRLEN(header); } p += browse_host_read_data(bh, p, &size); if (bh->b_size == bh->b_offset) browse_host_next_state(bh, BH_STATE_LIBRARY_INFO); break; case BH_STATE_LIBRARY_INFO: if (!bh->b_data) { bh->w_buf_size = w_concat_strings(&bh->w_buf, "<h1>", product_get_name(), "</h1>/r/n" "<h3>", version_get_string(), " sharing ", uint64_to_string(shared_files_scanned()), " file", shared_files_scanned() == 1 ? "" : "s", " ", short_kb_size(shared_kbytes_scanned(), GNET_PROPERTY(display_metric_units)), " total</h3>/r/n" "<ul>/r/n", (void *) 0); bh->b_data = bh->w_buf; bh->b_size = bh->w_buf_size - 1; /* minus trailing NUL */ bh->b_offset = 0; } p += browse_host_read_data(bh, p, &size); if (bh->b_size == bh->b_offset) browse_host_next_state(bh, BH_STATE_FILES); break; case BH_STATE_TRAILER: if (!bh->b_data) { bh->b_data = trailer; bh->b_size = CONST_STRLEN(trailer); } p += browse_host_read_data(bh, p, &size); if (bh->b_size == bh->b_offset) browse_host_next_state(bh, BH_STATE_EOF); break; case BH_STATE_FILES: if (bh->b_data && bh->b_size == bh->b_offset) { g_assert(bh->w_buf == bh->b_data); wfree(bh->w_buf, bh->w_buf_size); bh->w_buf = NULL; bh->w_buf_size = 0; bh->b_data = NULL; } if (!bh->b_data) { const shared_file_t *sf; bh->file_index++; sf = shared_file_sorted(bh->file_index); if (!sf) { if (bh->file_index > shared_files_scanned()) browse_host_next_state(bh, BH_STATE_TRAILER);//.........这里部分代码省略.........
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:101,
示例23: shell_exec_status/** * Displays assorted status information */enum shell_replyshell_exec_status(struct gnutella_shell *sh, int argc, const char *argv[]){ const char *cur; const option_t options[] = { { "i", &cur }, }; int parsed; char buf[2048]; time_t now; shell_check(sh); g_assert(argv); g_assert(argc > 0); parsed = shell_options_parse(sh, argv, options, G_N_ELEMENTS(options)); if (parsed < 0) return REPLY_ERROR; argv += parsed; /* args[0] is first command argument */ argc -= parsed; /* counts only command arguments now */ now = tm_time(); /* Leading flags */ { char flags[47]; const char *fw; const char *fd; const char *pmp; const char *dht; /* * The flags are displayed as followed: * * UMP port mapping configured via UPnP * NMP port mapping configured via NAT-PMP * pmp port mapping available (UPnP or NAT-PMP), un-configured * CLK clock, GTKG expired * !FD or FD red or yellow bombs for fd shortage * STL upload stalls * gUL/yUL/rUL green, yellow or red upload early stalling levels * CPU cpu overloaded * MOV file moving * SHA SHA-1 rebuilding or verifying * TTH TTH rebuilding or verifying * LIB library rescan * :FW or FW indicates whether hole punching is possible * udp or UDP indicates UDP firewalling (lowercased for hole punching) * TCP indicates TCP-firewalled * - the happy face: no firewall * sDH/lDH/bDH seeded, own KUID looking or bootstrapping DHT * A or P active or passive DHT mode * UP or LF ultrapeer or leaf mode */ pmp = (GNET_PROPERTY(upnp_possible) || GNET_PROPERTY(natpmp_possible)) ? "pmp " : empty; if ( (GNET_PROPERTY(enable_upnp) || GNET_PROPERTY(enable_natpmp)) && GNET_PROPERTY(port_mapping_successful) ) { pmp = GNET_PROPERTY(enable_natpmp) ? "NMP " : "UMP "; } if (dht_enabled()) { dht = empty; switch ((enum dht_bootsteps) GNET_PROPERTY(dht_boot_status)) { case DHT_BOOT_NONE: case DHT_BOOT_SHUTDOWN: break; case DHT_BOOT_SEEDED: dht = "sDH "; break; case DHT_BOOT_OWN: dht = "lDH "; break; case DHT_BOOT_COMPLETING: dht = "bDH "; break; case DHT_BOOT_COMPLETED: dht = dht_is_active() ? "A " : "P "; break; case DHT_BOOT_MAX_VALUE: g_assert_not_reached(); } } else { dht = empty; } if (GNET_PROPERTY(is_firewalled) && GNET_PROPERTY(is_udp_firewalled)) { fw = GNET_PROPERTY(recv_solicited_udp) ? ":FW " : "FW "; } else if (GNET_PROPERTY(is_firewalled)) { fw = "TCP "; } else if (GNET_PROPERTY(is_udp_firewalled)) { fw = GNET_PROPERTY(recv_solicited_udp) ? "udp " : "UDP "; } else {//.........这里部分代码省略.........
开发者ID:qgewfg,项目名称:gtk-gnutella,代码行数:101,
示例24: g2_build_q2/* * Build a Query. * * @param muid the MUID to use for the search message * @param query the query string * @param mtype media type filtering (0 if none wanted) * @param query_key the GUESS query key to use * @param length length of query key * * @return a /Q2 message. */pmsg_t *g2_build_q2(const guid_t *muid, const char *query, unsigned mtype, const void *query_key, uint8 length){ g2_tree_t *t, *c; pmsg_t *mb; static const char interest[] = "URL/0PFS/0DN/0A"; t = g2_tree_alloc_copy(G2_NAME(Q2), muid, sizeof *muid); c = g2_build_add_listening_address(t, "UDP"); g2_tree_append_payload(c, query_key, length); c = g2_tree_alloc_copy("DN", query, strlen(query)); g2_tree_add_child(t, c); /* * Due to an important Shareaza parsing bug in versions <= 2.7.1.0, * we're including the trailing NUL in the interest[] string. * Otherwise, that simply blocks Shareaza in a looong parsing loop. * Hence the use of "sizeof" below instead of CONST_STRLEN(). * --RAM, 2014-02-28 */ c = g2_tree_alloc("I", interest, sizeof interest); g2_tree_add_child(t, c); if (mtype != 0) { /* * Don't know how we can combine these flags on G2, hence only * emit for simple flags. */ c = NULL; if (SEARCH_AUDIO_TYPE == (mtype & SEARCH_AUDIO_TYPE)) { static const char audio[] = "<audio/>"; c = g2_tree_alloc("MD", audio, CONST_STRLEN(audio)); } else if (SEARCH_VIDEO_TYPE == (mtype & SEARCH_VIDEO_TYPE)) { static const char video[] = "<video/>"; c = g2_tree_alloc("MD", video, CONST_STRLEN(video)); } else if (SEARCH_IMG_TYPE == (mtype & SEARCH_IMG_TYPE)) { static const char image[] = "<image/>"; c = g2_tree_alloc("MD", image, CONST_STRLEN(image)); } else if (SEARCH_DOC_TYPE == (mtype & SEARCH_DOC_TYPE)) { static const char doc[] = "<document/>"; c = g2_tree_alloc("MD", doc, CONST_STRLEN(doc)); } else if (mtype & (SEARCH_WIN_TYPE | SEARCH_UNIX_TYPE)) { static const char archive[] = "<archive/>"; c = g2_tree_alloc("MD", archive, CONST_STRLEN(archive)); } if (c != NULL) g2_tree_add_child(t, c); } if (GNET_PROPERTY(is_firewalled) || GNET_PROPERTY(is_udp_firewalled)) { /* * Shareaza uses /Q2/NAT to indicate that the querying node is * firewalled. Why didn't they choose /Q2/FW for consistency? */ c = g2_tree_alloc_empty("NAT"); g2_tree_add_child(t, c); } g2_tree_reverse_children(t); mb = g2_build_pmsg(t); g2_tree_free_null(&t); return mb;}
开发者ID:Eppo791906066,项目名称:gtk-gnutella,代码行数:87,
示例25: g2_node_handle/** * Handle message coming from G2 node. */voidg2_node_handle(gnutella_node_t *n){ g2_tree_t *t; size_t plen; enum g2_msg type; node_check(n); g_assert(NODE_TALKS_G2(n)); t = g2_frame_deserialize(n->data, n->size, &plen, FALSE); if (NULL == t) { if (GNET_PROPERTY(g2_debug) > 0 || GNET_PROPERTY(log_bad_g2)) { g_warning("%s(): cannot deserialize /%s from %s", G_STRFUNC, g2_msg_raw_name(n->data, n->size), node_infostr(n)); } if (GNET_PROPERTY(log_bad_g2)) dump_hex(stderr, "G2 Packet", n->data, n->size); return; } else if (plen != n->size) { if (GNET_PROPERTY(g2_debug) > 0 || GNET_PROPERTY(log_bad_g2)) { g_warning("%s(): consumed %zu bytes but /%s from %s had %u", G_STRFUNC, plen, g2_msg_raw_name(n->data, n->size), node_infostr(n), n->size); } if (GNET_PROPERTY(log_bad_g2)) dump_hex(stderr, "G2 Packet", n->data, n->size); hostiles_dynamic_add(n->addr, "cannot parse incoming messages", HSTL_GIBBERISH); goto done; } else if (GNET_PROPERTY(g2_debug) > 19) { g_debug("%s(): received packet from %s", G_STRFUNC, node_infostr(n)); g2_tfmt_tree_dump(t, stderr, G2FMT_O_PAYLEN); } type = g2_msg_name_type(g2_tree_name(t)); switch (type) { case G2_MSG_PI: g2_node_handle_ping(n, t); break; case G2_MSG_PO: g2_node_handle_pong(n, t); break; case G2_MSG_LNI: g2_node_handle_lni(n, t); break; case G2_MSG_KHL: g2_node_handle_khl(t); break; case G2_MSG_PUSH: handle_push_request(n, t); break; case G2_MSG_Q2: g2_node_handle_q2(n, t); break; case G2_MSG_QA: case G2_MSG_QKA: g2_node_handle_rpc_answer(n, t, type); break; case G2_MSG_QH2: search_g2_results(n, t); break; default: g2_node_drop(G_STRFUNC, n, t, "default"); break; }done: g2_tree_free_null(&t);}
开发者ID:graaff,项目名称:gtk-gnutella,代码行数:74,
示例26: parse_dispatch_lines/** * Analyze the data we have received, and give each line to the supplied * dispatcher callback `cb', after having chomped it. On EOF, call `eof' * to finalize parsing. */static voidparse_dispatch_lines(void *handle, const char *buf, size_t len, parse_dispatch_t cb, parse_eof_t eofile){ struct parse_context *ctx; const char *p = buf; size_t remain = len; /* * Retrieve parsing context, stored as an opaque attribute in the * asynchronous HTTP request handle. */ ctx = http_async_get_opaque(handle); g_assert(ctx->handle == handle); /* Make sure it's the right context */ if (len == 0) { /* Nothing to parse, got EOF */ if (eofile != NULL) (*eofile)(ctx); return; } /* * Read a line at a time. */ for (;;) { char *line; bool error; size_t line_len; size_t parsed; switch (getline_read(ctx->getline, p, remain, &parsed)) { case READ_OVERFLOW: http_async_cancel(handle); ghc_connecting = FALSE; return; case READ_DONE: p += parsed; remain -= parsed; break; case READ_MORE: /* ok, but needs more data */ g_assert(parsed == remain); return; } /* * We come here everytime we get a full line. */ line = h_strdup(getline_str(ctx->getline)); line_len = getline_length(ctx->getline); line_len = strchomp(line, line_len); error = !(*cb)(ctx, line, line_len); /* An ERROR was reported */ HFREE_NULL(line); if (error) { ghc_ctx.ha = NULL; ghc_connecting = FALSE; return; } /* * Make sure we don't process lines ad infinitum. */ ctx->lines++; if (ctx->lines >= ctx->maxlines) { const char *req; const char *url = http_async_info(handle, &req, NULL, NULL, NULL); if (GNET_PROPERTY(bootstrap_debug)) g_warning("BOOT GHC got %u+ lines from /"%s %s/", stopping", ctx->lines, req, url); http_async_close(handle); ghc_connecting = FALSE; return; } getline_reset(ctx->getline); }}
开发者ID:graaff,项目名称:gtk-gnutella,代码行数:88,
示例27: tcache_debugging_changed/** * Debugging variables changed. */voidtcache_debugging_changed(void){ tcache_dbmw_dbg.level = GNET_PROPERTY(dht_tcache_debug); tcache_dbmw_dbg.flags = GNET_PROPERTY(dht_tcache_debug_flags);}
开发者ID:qgewfg,项目名称:gtk-gnutella,代码行数:9,
示例28: ctl_parse_list_entry/** * Parse a list entry. * @return TRUE when done with input. */static boolctl_parse_list_entry(struct ctl_string *s){ struct ctl_tok *tok = ctl_next_token(s); GSList *countries = NULL; GSList *sl; char *opt = NULL; unsigned flags; bool done = FALSE; switch (tok->type) { case CTL_TOK_EOF: done = TRUE; goto out; case CTL_TOK_ID: countries = ctl_parse_country(s, tok); break; case CTL_TOK_LBRACE: countries = ctl_parse_countries(s); break; default: ctl_error(s, tok, "'{' or country"); goto out; } if (NULL == countries) goto out; /* * Check presence of options */ ctl_token_free_null(&tok); tok = ctl_next_token(s); switch (tok->type) { case CTL_TOK_EOF: case CTL_TOK_COMMA: ctl_unread(s, &tok); break; case CTL_TOK_COLON: opt = ctl_parse_options(s); break; default: ctl_error(s, tok, "',' or ':' or EOF"); goto out; } /* * Compute flags. */ if (NULL == opt) { flags = ctl_get_flags('a'); } else { char *p = opt; char c; flags = 0; while ((c = *p++)) { unsigned f = ctl_get_flags(c); if (0 == f) g_warning("CTL ignoring unknown option '%c'", c); flags |= f; } } /* * Handle the country list in countries with options in opt. * Nevermind superseding, the latest parsed is the winner. */ GM_SLIST_FOREACH(countries, sl) { unsigned code = pointer_to_uint(sl->data); htable_insert(ctl_by_country, uint_to_pointer(code), uint_to_pointer(flags)); ctl_all_flags |= flags; if (GNET_PROPERTY(ctl_debug)) { g_debug("CTL %s => '%s' (%s)", iso3166_country_cc(code), ctl_flags2str(flags), iso3166_country_name(code)); } }
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:82,
注:本文中的GNET_PROPERTY函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ GNIX_WARN函数代码示例 C++ GM_CHECK_NUM_PARAMS函数代码示例 |