static void hsep_sanity_check(void) { const pslist_t *sl; hsep_triple sum[N_ITEMS(hsep_global_table)]; unsigned int i, j; ZERO(&sum); g_assert(1 == hsep_own[HSEP_IDX_NODES]); /* * Iterate over all HSEP-capable nodes, and for each triple index * sum up all the connections' triple values. */ PSLIST_FOREACH(node_all_gnet_nodes(), sl) { gnutella_node_t *n = sl->data; /* also consider unestablished connections here */ if (!(n->attrs & NODE_A_CAN_HSEP)) continue; g_assert(0 == n->hsep->table[0][HSEP_IDX_NODES]); /* check nodes */ g_assert(0 == n->hsep->table[0][HSEP_IDX_FILES]); /* check files */ g_assert(0 == n->hsep->table[0][HSEP_IDX_KIB]); /* check KiB */ g_assert(1 == n->hsep->table[1][HSEP_IDX_NODES]); /* check nodes */ /* check if values are monotonously increasing (skip first) */ g_assert( hsep_check_monotony(cast_to_pointer(n->hsep->table[1]), N_ITEMS(n->hsep->table[1]) - 1) ); /* sum up the values */ for (i = 0; i < N_ITEMS(sum); i++) { for (j = 0; j < N_ITEMS(sum[0]); j++) sum[i][j] += n->hsep->table[i][j]; } }
/** * Displays horizon size information. */ enum shell_reply shell_exec_horizon(struct gnutella_shell *sh, int argc, const char *argv[]) { const char *all; const option_t options[] = { { "a", &all }, }; char buf[200]; hsep_triple globaltable[HSEP_N_MAX + 1]; hsep_triple non_hsep[1]; int parsed; unsigned num_hsep, num_total; 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; shell_write(sh, "100~\n"); hsep_get_global_table(globaltable, G_N_ELEMENTS(globaltable)); hsep_get_non_hsep_triple(non_hsep); num_hsep = globaltable[1][HSEP_IDX_NODES]; num_total = globaltable[1][HSEP_IDX_NODES] + non_hsep[0][HSEP_IDX_NODES]; str_bprintf(buf, sizeof buf, _("Total horizon size (%u/%u nodes support HSEP):"), num_hsep, num_total); shell_write(sh, buf); shell_write(sh, "\n\n"); print_hsep_table(sh, globaltable, HSEP_N_MAX, non_hsep); if (all) { const pslist_t *sl; hsep_triple table[HSEP_N_MAX + 1]; PSLIST_FOREACH(node_all_gnet_nodes(), sl) { const gnutella_node_t *n = sl->data; if ((!NODE_IS_ESTABLISHED(n)) || !(n->attrs & NODE_A_CAN_HSEP)) continue; shell_write(sh, "\n"); str_bprintf(buf, sizeof buf, _("Horizon size via HSEP node %s (%s):"), node_addr(n), node_peermode_to_string(n->peermode)); shell_write(sh, buf); shell_write(sh, "\n\n"); hsep_get_connection_table(n, table, G_N_ELEMENTS(table)); print_hsep_table(sh, table, NODE_IS_LEAF(n) ? 1 : HSEP_N_MAX, NULL); } } shell_write(sh, ".\n"); return REPLY_READY; }