message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE);
memcpy (&message->key, key, sizeof (GNUNET_HashCode));
message->options = htonl (options);
- message->desired_replication_level = htonl (options);
+ message->desired_replication_level = htonl (desired_replication_level);
message->unique_id = GNUNET_htonll (route_handle->uid);
memcpy (&message[1], enc, ntohs (enc->size));
pending = GNUNET_malloc (sizeof (struct PendingMessage));
#define DEFAULT_PUT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
/* Timeout for waiting for puts to be sent to the service */
-#define DEFAULT_FIND_PEER_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 40)
+#define DEFAULT_FIND_PEER_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
#define DEFAULT_SECONDS_PER_PEER_START GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 45)
#define DEFAULT_MAX_OUTSTANDING_PUTS 10
-#define DEFAULT_MAX_OUTSTANDING_FIND_PEERS 10
+#define DEFAULT_MAX_OUTSTANDING_FIND_PEERS 5
#define DEFAULT_FIND_PEER_OFFSET GNUNET_TIME_relative_divide (DEFAULT_FIND_PEER_DELAY, DEFAULT_MAX_OUTSTANDING_FIND_PEERS)
/**
* Default replication parameter for find peer messages sent by the dht service.
*/
-#define DHT_DEFAULT_FIND_PEER_REPLICATION 1
+#define DHT_DEFAULT_FIND_PEER_REPLICATION 2
/**
* Default options for find peer requests sent by the dht service.
* Real maximum number of hops, at which point we refuse
* to forward the message.
*/
-#define MAX_HOPS 20
+#define MAX_HOPS 10
/**
* How many time differences between requesting a core send and
};
-
/**
* Per-peer information.
*/
remove_recent_find_peer(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_HashCode *key = cls;
- GNUNET_CONTAINER_multihashmap_remove(recent_find_peer_requests, key, key);
+ if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(recent_find_peer_requests, key, key))
+ {
+ GNUNET_free(key);
+ }
}
/**
size_t hello_size;
size_t tsize;
GNUNET_HashCode *recent_hash;
+#if RESTRICT_FIND_PEER
+ struct GNUNET_PeerIdentity peer_id;
+#endif
find_peer_message = (struct GNUNET_DHT_FindPeerMessage *)find_msg;
#if DEBUG_DHT
increment_stats("# dht find peer requests ignored (recently seen!)");
return;
}
+
+#if RESTRICT_FIND_PEER
+ /**
+ * Use this check to only allow the peer to respond to find peer requests if
+ * it would be beneficial to have the requesting peer in this peers routing
+ * table. Can be used to thwart peers flooding the network with find peer
+ * requests that we don't care about. However, if a new peer is joining
+ * the network and has no other peers this is a problem (assume all buckets
+ * full, no one will respond!).
+ */
+ memcpy(&peer_id.hashPubKey, &message_context->key, sizeof(GNUNET_HashCode));
+ if (GNUNET_NO == consider_peer(&peer_id))
+ {
+ increment_stats("# dht find peer requests ignored (do not need!)");
+ return;
+ }
+#endif
+
recent_hash = GNUNET_malloc(sizeof(GNUNET_HashCode));
memcpy(recent_hash, &message_context->key, sizeof(GNUNET_HashCode));
GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, &message_context->key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), &remove_recent_find_peer, &message_context->key);
+ GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), &remove_recent_find_peer, &recent_hash);
/* Simplistic find_peer functionality, always return our hello */
hello_size = ntohs(my_hello->size);
static unsigned int
get_forward_count (unsigned int hop_count, size_t target_replication)
{
+#if DOUBLE
double target_count;
+ double random_probability;
+#else
+ uint32_t random_value;
+#endif
unsigned int target_value;
unsigned int diameter;
#endif
return 0;
}
+
+#if DOUBLE
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Replication %d, hop_count %u, diameter %u\n", target_replication, hop_count, diameter);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Numerator %f, denominator %f\n", (double)target_replication, ((double)target_replication * (hop_count + 1) + diameter));
target_count = /* target_count is ALWAYS < 1 unless replication is < 1 */
(double)target_replication / ((double)target_replication * (hop_count + 1) + diameter);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Target count is %f\n", target_count);
+ random_probability = ((double)GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ RAND_MAX)) / RAND_MAX;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Random is %f\n", random_probability);
target_value = 0;
- while (target_value < target_count)
+ //while (target_value < target_count)
+ if (target_value < target_count)
target_value++; /* target_value is ALWAYS 1 after this "loop", right? Because target_count is always > 0, right? Or does it become 0.00000... at some point because the hop count is so high? */
- if ((target_count + 1 - target_value) >
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- RAND_MAX) / RAND_MAX)
+
+ //if ((target_count + 1 - (double)target_value) > random_probability)
+ if ((target_count) > random_probability)
target_value++;
+#endif
+
+ random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, target_replication * (hop_count + 1) + diameter) + 1;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "replication %u, at hop %d, will split with probability %f\n", target_replication, hop_count, target_replication / (double)((target_replication * (hop_count + 1) + diameter) + 1));
+ target_value = 1;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "random %u, target %u, max %u\n", random_value, target_replication, target_replication * (hop_count + 1) + diameter);
+ if (random_value < target_replication)
+ target_value++;
+
return target_value;
}
if (message_context->bloom == NULL)
message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
- if ((stop_on_closest == GNUNET_YES) && (message_context->closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT))
+ if ((stop_on_closest == GNUNET_YES) && (global_closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT))
forward_count = 0;
-
#if DEBUG_DHT_ROUTING
if (forward_count == 0)
ret = GNUNET_SYSERR;
break;
case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. FIXME: thresholding to reduce complexity?*/
increment_stats(STAT_PUTS);
+ message_context->closest = global_closest;
handle_dht_put (cls, msg, message_context);
break;
case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */
*dhtkeyuid = curr_dhtkeyuid;
return GNUNET_OK;
}
+ else if (ret == GNUNET_SYSERR)
+ return GNUNET_SYSERR;
if (GNUNET_OK !=
(ret = prepared_statement_run (insert_dhtkey,
return GNUNET_SYSERR;
ret = fprintf(outfile, "execute insert_topology using "
"@date, @num;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
ret = fprintf(outfile, "execute select_topology;\n");
"@m_gets, @m_puts, @m_drops,"
"@m_g_f, @m_p_f, @s_c, @s_f,"
"@s_k, @g_s, @message;\n");
-
+ if (ret < 0)
+ return GNUNET_SYSERR;
ret = fprintf(outfile, "execute select_trial;\n");
if (ret >= 0)
else
ret = fprintf(outfile, "set @temp_node = 0;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
ret = fprintf(outfile, "set @temp_section = \"%s\", @temp_stat = \"%s\", @temp_value = %llu;\n",
section, name, (unsigned long long)value);
ret = fprintf(outfile, "execute insert_generic_stat;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
return GNUNET_OK;
}
ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&peer->hashPubKey));
else
ret = fprintf(outfile, "set @temp_node = 0;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
ret = fprintf(outfile, "set @r_r = %u, @r_f = %u, @res_r = %u, @c_r = %u, "
"@res_f = %u, @gets = %u, @puts = %u, @d_i = %u, "
"@res_f, @gets, @puts, @d_i, "
"@f_p_r, @f_p_s, @g_s, @p_s, "
"@f_p_r_r, @g_r_r, @f_p_r_s, @g_r_s;\n");
-
+ if (ret < 0)
+ return GNUNET_SYSERR;
return GNUNET_OK;
}
/*
else
ret = fprintf(outfile, "set @temp_dhtkey = 0;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
if (node != NULL)
ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&node->hashPubKey));
else
ret = fprintf(outfile, "set @temp_node = 0;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n", queryid, type, hops, succeeded);
if (ret < 0)
else
ret = fprintf(outfile, "set @temp_dhtkey = 0;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
if (node != NULL)
ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&node->hashPubKey));
else
ret = fprintf(outfile, "set @temp_node = 0;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
if (from_node != NULL)
ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_from_node;\n", GNUNET_h2s_full(&from_node->hashPubKey));
else
ret = fprintf(outfile, "set @temp_from_node = 0;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
if (to_node != NULL)
ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_to_node;\n", GNUNET_h2s_full(&to_node->hashPubKey));
else
ret = fprintf(outfile, "set @temp_to_node = 0;\n");
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n", queryid, type, hops, succeeded);
if (ret < 0)
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
outfile = FOPEN (fn, "w");
return GNUNET_SYSERR;
ret = fprintf(outfile, "insert into topology (trialuid, date, connections) values (@temp_trial, \"%s\", %d);\n", get_sql_time(), num_connections);
+ if (ret < 0)
+ return GNUNET_SYSERR;
ret = fprintf(outfile, "select max(topology_uid) from topology into @temp_topology;\n");
if (ret >= 0)
return GNUNET_OK;
return GNUNET_SYSERR;
ret = fprintf(extended_topology_outfile, "insert into extended_topology (topology_uid, uid_first, uid_second) values (%u, %s,", topology_count, GNUNET_h2s_full(&first->hashPubKey));
+ if (ret < 0)
+ return GNUNET_SYSERR;
ret = fprintf(extended_topology_outfile, "%s);\n", GNUNET_h2s_full(&second->hashPubKey));
if (ret >= 0)
malicious_droppers, malicious_get_frequency, malicious_put_frequency,
stop_closest, stop_found, strict_kademlia, gets_succeeded, message);
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
ret = fprintf(outfile, "SELECT MAX( trialuid ) FROM trials into @temp_trial;\n");
if (ret >= 0)
return GNUNET_OK;
- return GNUNET_SYSERR;
+ else
+ return GNUNET_SYSERR;
}
get_responses_received, find_peer_responses_sent,
get_responses_sent);
- if (ret < 0)
+ else
return GNUNET_SYSERR;
- return GNUNET_OK;
+ if (ret >= 0)
+ return GNUNET_OK;
+ else
+ return GNUNET_SYSERR;
}
/*
* Inserts the specified dhtkey into the dhttests.dhtkeys table,
if (dhtkeyuid != NULL)
*dhtkeyuid = 0;
- if (dhtkey_outfile == NULL)
+ if ((dhtkey_outfile == NULL) || (dhtkey == NULL))
return GNUNET_SYSERR;
- if (dhtkey != NULL)
- ret = fprintf(dhtkey_outfile, "TRIALUID\t%s\n", GNUNET_h2s_full(dhtkey));
+ ret = fprintf(dhtkey_outfile, "TRIALUID\t%s\n", GNUNET_h2s_full(dhtkey));
if (ret >= 0)
return GNUNET_OK;
- return GNUNET_SYSERR;
+ else
+ return GNUNET_SYSERR;
}
/*
*sqlqueryuid = 0;
ret = fprintf(query_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full(key));
+
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
ret = fprintf(query_outfile, "%s\t%llu\t%u\t%u\t%u\n", GNUNET_h2s_full(&node->hashPubKey), queryid, type, hops, succeeded);
if (ret >= 0)
*sqlqueryuid = 0;
ret = fprintf(route_outfile, "TRIALUID\t%s\t", GNUNET_h2s_full(key));
+ if (ret < 0)
+ return GNUNET_SYSERR;
+
ret = fprintf(route_outfile, "%s\t", GNUNET_h2s_full(&node->hashPubKey));
+ if (ret < 0)
+ return GNUNET_SYSERR;
if (from_node == NULL)
ret = fprintf(route_outfile, "0\t");
else
ret = fprintf(route_outfile, "%s\t", GNUNET_h2s_full(&from_node->hashPubKey));
+ if (ret < 0)
+ return GNUNET_SYSERR;
if (to_node == NULL)
ret = fprintf(route_outfile, "0\t%llu\t%u\t%u\t%d\n", queryid, type, hops, succeeded);
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
outfile = FOPEN (fn, "w");
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
node_outfile = FOPEN (fn, "w");
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
route_outfile = FOPEN (fn, "w");
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
query_outfile = FOPEN (fn, "w");
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
stat_outfile = FOPEN (fn, "w");
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
generic_stat_outfile = FOPEN (fn, "w");
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
dhtkey_outfile = FOPEN (fn, "w");
fn = GNUNET_STRINGS_filename_expand (outfile_name);
+ if (fn == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
+ GNUNET_free(outfile_path);
+ GNUNET_free(outfile_name);
+ return NULL;
+ }
+
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
extended_topology_outfile = FOPEN (fn, "w");
ret = api->insert_topology(500);
CHECK(ret);
ret = api->insert_node (&nodeuid, &p1);
+ CHECK(ret);
ret = api->insert_node (&nodeuid, &p2);
+ CHECK(ret);
ret = api->insert_node (&nodeuid, &p3);
+ CHECK(ret);
ret = api->insert_node (&nodeuid, &p4);
+ CHECK(ret);
ret = api->set_malicious(&p1);
CHECK(ret);
ret = api->insert_topology(0);
+ CHECK(ret);
ret = api->insert_extended_topology(&p1, &p2);
+ CHECK(ret);
ret = api->insert_extended_topology(&p3, &p4);
+ CHECK(ret);
ret = api->update_topology(101);
CHECK(ret);
ret = api->insert_dhtkey (&dhtkeyuid, &k1);
+ CHECK(ret);
ret = api->insert_dhtkey (&dhtkeyuid, &k2);
CHECK(ret);
ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1);
+ CHECK(ret);
ret =
api->insert_route (&sqlrouteuid, sqlqueryuid, 1, 1, DHTLOG_GET, &p1, &k2,
&p4, &p3);
+ CHECK(ret);
ret =
api->insert_route (&sqlrouteuid, sqlqueryuid, 2, 0, DHTLOG_PUT, &p3, &k1,
&p4, &p2);
+ CHECK(ret);
ret =
api->insert_route (&sqlrouteuid, sqlqueryuid, 3, 1, DHTLOG_ROUTE, &p3, &k2,
&p2, NULL);
+ CHECK(ret);
ret =
api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3, &k2,
NULL, NULL);
+ CHECK(ret);
sleep (1);
ret = api->insert_stat(&p1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
+ CHECK(ret);
ret = api->insert_stat(&p2, 12, 23, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
CHECK(ret);
ret = api->update_trial (trialuid, 787);
+ CHECK(ret);
ret = api->add_generic_stat (&p2, "nonsense", "section", 77765);
CHECK(ret);
return 0;