/* * GUC array: one invalid guc + non-userset guc * return ArrayType contain non-userset guc, ignore invalid guc */ void test__GUCArrayReset__invalid_guc(void **state) { ArrayType *in; ArrayType *out; Datum d; List *guc_list; int elems; build_guc_variables(); will_return(superuser, false); /* construct text array */ elems = 2; guc_list = list_make2("invalid_guc=true", "gp_log_format=text"); in = create_guc_array(guc_list, elems); out = GUCArrayReset(in); assert_not_null(out); assert_int_equal(ARR_DIMS(out)[0], 1); d = PointerGetDatum(ARR_DATA_PTR(out)); assert_int_equal(strlen("gp_log_format=text"), VARLEN(d)); assert_memory_equal(VARDATA(d), "gp_log_format=text", VARLEN(d)); list_free(guc_list); pfree(in); pfree(out); }
static void gnet_stats_flowc_internal(uint t, uint8 function, uint8 ttl, uint8 hops, size_t size) { uint i; g_assert(t < MSG_TOTAL); i = MIN(hops, STATS_FLOWC_COLUMNS - 1); gnet_stats.pkg.flowc_hops[i][t]++; gnet_stats.pkg.flowc_hops[i][MSG_TOTAL]++; gnet_stats.byte.flowc_hops[i][t] += size; gnet_stats.byte.flowc_hops[i][MSG_TOTAL] += size; i = MIN(ttl, STATS_FLOWC_COLUMNS - 1); /* Cannot send a message with TTL=0 (DHT messages are not Gnutella) */ g_assert(function == GTA_MSG_DHT || i != 0); gnet_stats.pkg.flowc_ttl[i][t]++; gnet_stats.pkg.flowc_ttl[i][MSG_TOTAL]++; gnet_stats.byte.flowc_ttl[i][t] += size; gnet_stats.byte.flowc_ttl[i][MSG_TOTAL] += size; entropy_harvest_small(VARLEN(t), VARLEN(function), VARLEN(size), NULL); }
/* * GUC array: mix of PGC_USERSET, PGC_POSTMASTER, PGC_SUSET * return ArrayType contains non-PGC_USERSET */ void test__GUCArrayReset__mix_guc(void **state) { ArrayType *in; ArrayType *out; Datum d; List *guc_list; int elems; build_guc_variables(); will_return(superuser, false); /* construct text array */ elems = 4; guc_list = list_make4("password_encryption=on", "log_error_verbosity=verbose", "application_name=mixtest", "allow_system_table_mods=dml"); in = create_guc_array(guc_list, elems); out = GUCArrayReset(in); assert_not_null(out); assert_int_equal(ARR_DIMS(out)[0], 1); d = PointerGetDatum(ARR_DATA_PTR(out)); assert_int_equal(strlen("log_error_verbosity=verbose"), VARLEN(d)); assert_memory_equal(VARDATA(d), "log_error_verbosity=verbose", VARLEN(d)); list_free(guc_list); pfree(in); pfree(out); }
void gnet_stats_count_dropped(gnutella_node_t *n, msg_drop_reason_t reason) { uint32 size; uint type; gnet_stats_t *stats; g_assert(UNSIGNED(reason) < MSG_DROP_REASON_COUNT); g_assert(thread_is_main()); stats = NODE_USES_UDP(n) ? &gnet_udp_stats : &gnet_tcp_stats; if (NODE_TALKS_G2(n)) { int f = g2_msg_type(n->data, n->size); if (f != G2_MSG_MAX) { f += MSG_G2_BASE; } else { f = G_N_ELEMENTS(stats_lut) - 1; /* Last, holds MSG_UNKNOWN */ } type = stats_lut[f]; size = n->size; } else { type = stats_lut[gnutella_header_get_function(&n->header)]; size = n->size + sizeof(n->header); } entropy_harvest_small( VARLEN(n->addr), VARLEN(n->port), VARLEN(reason), VARLEN(type), VARLEN(size), NULL); DROP_STATS(stats, type, size); node_inc_rxdrop(n); switch (reason) { case MSG_DROP_HOSTILE_IP: n->n_hostile++; break; case MSG_DROP_SPAM: n->n_spam++; break; case MSG_DROP_EVIL: n->n_evil++; break; default: ; } if (NODE_TALKS_G2(n)) { if (GNET_PROPERTY(log_dropped_g2)) { g2_msg_log_dropped_data(n->data, n->size, "from %s: %s", node_infostr(n), gnet_stats_drop_reason_to_string(reason)); } } else { if (GNET_PROPERTY(log_dropped_gnutella)) { gmsg_log_split_dropped(&n->header, n->data, n->size, "from %s: %s", node_infostr(n), gnet_stats_drop_reason_to_string(reason)); } } }
void gnet_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)); }
/** * Account for dropped Kademlia message of specified opcode from node ``n''. */ void gnet_dht_stats_count_dropped(gnutella_node_t *n, kda_msg_t opcode, msg_drop_reason_t reason) { uint32 size; uint type; gnet_stats_t *stats; g_assert(UNSIGNED(reason) < MSG_DROP_REASON_COUNT); g_assert(opcode <= KDA_MSG_MAX_ID); g_assert(UNSIGNED(opcode + MSG_DHT_BASE) < G_N_ELEMENTS(stats_lut)); g_assert(thread_is_main()); size = n->size + sizeof(n->header); type = stats_lut[opcode + MSG_DHT_BASE]; stats = NODE_USES_UDP(n) ? &gnet_udp_stats : &gnet_tcp_stats; entropy_harvest_small( VARLEN(n->addr), VARLEN(n->port), VARLEN(reason), VARLEN(type), VARLEN(size), NULL); DROP_STATS(stats, type, size); node_inc_rxdrop(n); }
static void on_notebook_downloads_info_switch_page(GtkNotebook *unused_notebook, GtkNotebookPage *unused_page, int page_num, void *unused_udata) { (void) unused_notebook; (void) unused_page; (void) unused_udata; g_return_if_fail(UNSIGNED(page_num) < NUM_DOWNLOADS_INFO_NB_PAGES); entropy_harvest_single(VARLEN(page_num)); notebook_downloads_info_current_page = page_num; gui_prop_set_guint32_val(PROP_DOWNLOADS_INFO_NOTEBOOK_TAB, page_num); }
/* * GUC array: all non-PGC_USERSET, return the same array */ void test__GUCArrayReset__all_non_userset_guc(void **state) { ArrayType *in; ArrayType *out; Datum d; List *guc_list; bool isnull; int i; int elems; build_guc_variables(); will_return(superuser, false); /* construct text array */ elems = 3; guc_list = list_make3("log_error_verbosity=terse", "gp_log_format=csv", "maintenance_mode=true"); in = create_guc_array(guc_list, elems); out = GUCArrayReset(in); assert_not_null(out); assert_int_equal(ARR_DIMS(out)[0], elems); /* check element 1 */ i = 1; d = array_ref(out, 1, &i, -1, TEXT_TYPLEN, TEXT_TYPBYVAL, TEXT_TYPALIGN, &isnull); assert_false(isnull); assert_int_equal(strlen("log_error_verbosity=terse"), VARLEN(d)); assert_memory_equal(VARDATA(d), "log_error_verbosity=terse", VARLEN(d)); /* check element 2 */ i = 2; d = array_ref(out, 1, &i, -1, TEXT_TYPLEN, TEXT_TYPBYVAL, TEXT_TYPALIGN, &isnull); assert_false(isnull); assert_int_equal(strlen("gp_log_format=csv"), VARLEN(d)); assert_memory_equal(VARDATA(d), "gp_log_format=csv", VARLEN(d)); /* check element 3 */ i = 3; d = array_ref(out, 1, &i, -1, TEXT_TYPLEN, TEXT_TYPBYVAL, TEXT_TYPALIGN, &isnull); assert_false(isnull); assert_int_equal(strlen("maintenance_mode=true"), VARLEN(d)); assert_memory_equal(VARDATA(d), "maintenance_mode=true", VARLEN(d)); list_free(guc_list); pfree(in); pfree(out); }
/** * Use unpredictable events to collect random data. */ static void gnet_stats_randomness(const gnutella_node_t *n, uint8 type, uint32 val) { entropy_harvest_small( VARLEN(n->addr), VARLEN(n->port), VARLEN(type), VARLEN(val), NULL); }