/** * Attempt Gnutella host connection. * @return TRUE if OK, FALSE if attempt was throttled */ static gboolean host_gnutella_connect(host_addr_t addr, guint16 port) { if (aging_lookup(node_connects, &addr)) return FALSE; node_add_socket(NULL, addr, port, 0); aging_insert(node_connects, wcopy(&addr, sizeof addr), GUINT_TO_POINTER(1)); return TRUE; }
/** * Handle reception of a /PI */ static void g2_node_handle_ping(gnutella_node_t *n, const g2_tree_t *t) { g2_tree_t *c; /* * Throttle pings received from UDP. */ if (NODE_IS_UDP(n)) { if (aging_lookup(g2_udp_pings, &n->addr)) { gnet_stats_count_dropped(n, MSG_DROP_THROTTLE); return; } aging_insert(g2_udp_pings, WCOPY(&n->addr), uint_to_pointer(1)); /* FALL THROUGH */ } c = g2_tree_first_child(t); /* * If there is no payload, it's a keep-alive ping, send back a pong. */ if (NULL == c) { g2_node_send_pong(n); return; } /* * There are children. * * If there is a /PI/UDP present, drop the message: we're not a hub, * we don't have to relay this message to its UDP target (we're only * connected to hubs, and the hub which got it should only forward that * message it its neighbouring hubs, not to leaves). * * If there is a /PI/RELAY, the ping was relayed by a hub, but it made * a mistake because we are a leaf node. */ g2_node_drop(G_STRFUNC, n, t, "has children and we are a leaf"); }
/** * Send a Gnutella ping message to the specified host. * * @param m the Ping message to send * @param size size of the Ping message, in bytes * @param addr address to which ping should be sent * @param port port number * @param cb if non-NULL, callback to invoke on reply or timeout * @param arg additional callback argument * @param multiple whether multiple replies (Pongs) are expected * * @return TRUE if we sent the ping, FALSE it we throttled it. */ static bool udp_send_ping_with_callback( gnutella_msg_init_t *m, uint32 size, const host_addr_t addr, uint16 port, udp_ping_cb_t cb, void *arg, bool multiple) { struct gnutella_node *n = node_udp_get_addr_port(addr, port); if (n != NULL) { const guid_t *muid = gnutella_header_get_muid(m); if (udp_ping_register(muid, addr, port, cb, arg, multiple)) { aging_insert(udp_aging_pings, wcopy(&addr, sizeof addr), GUINT_TO_POINTER(1)); udp_send_msg(n, m, size); return TRUE; } } return FALSE; }