aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-08-04 12:51:41 +0000
committerNathan S. Evans <evans@in.tum.de>2010-08-04 12:51:41 +0000
commit6b4149fb0535be361e5345eccf5a488582f14842 (patch)
tree433e139f790d3b6f031f778dee325df149445184
parent65d153a8d31b17d92663d6c4bc098c62ec3295f1 (diff)
downloadgnunet-6b4149fb0535be361e5345eccf5a488582f14842.tar.gz
gnunet-6b4149fb0535be361e5345eccf5a488582f14842.zip
add topology table creation, insert, update, get, etc. to the mysql dhtlog plugin, also added to test case
-rw-r--r--src/dht/dhtlog.h122
-rw-r--r--src/dht/plugin_dhtlog_dummy.c45
-rw-r--r--src/dht/plugin_dhtlog_mysql.c323
-rw-r--r--src/dht/plugin_dhtlog_mysql_dump.c38
-rw-r--r--src/dht/test_dhtlog.c31
5 files changed, 445 insertions, 114 deletions
diff --git a/src/dht/dhtlog.h b/src/dht/dhtlog.h
index b2ba1c96f..36c81181b 100644
--- a/src/dht/dhtlog.h
+++ b/src/dht/dhtlog.h
@@ -72,16 +72,17 @@ struct GNUNET_DHTLOG_Handle
72{ 72{
73 73
74 /* 74 /*
75 * Insert the result of a query into the database 75 * Inserts the specified query into the dhttests.queries table
76 * 76 *
77 * @param sqlqueryuid return value for the sql uid for this query 77 * @param sqlqueruid inserted query uid
78 * @param queryid gnunet internal query id (doesn't exist) 78 * @param queryid dht query id
79 * @param type the type of query (DHTLOG_GET, DHTLOG_PUT, DHTLOG_RESULT) 79 * @param type type of the query
80 * @param hops the hops the query has traveled 80 * @param hops number of hops query traveled
81 * @param succeeded is successful or not (GNUNET_YES or GNUNET_NO) 81 * @param succeeded whether or not query was successful
82 * @param GNUNET_PeerIdentity of the node the query is at now 82 * @param node the node the query hit
83 * @param key the GNUNET_HashCode of this query 83 * @param key the key of the query
84 * 84 *
85 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
85 */ 86 */
86 int (*insert_query) (unsigned long long *sqlqueryuid, 87 int (*insert_query) (unsigned long long *sqlqueryuid,
87 unsigned long long queryid, DHTLOG_MESSAGE_TYPES type, 88 unsigned long long queryid, DHTLOG_MESSAGE_TYPES type,
@@ -91,7 +92,28 @@ struct GNUNET_DHTLOG_Handle
91 const GNUNET_HashCode * key); 92 const GNUNET_HashCode * key);
92 93
93 /* 94 /*
94 * Inserts the trial information into the database 95 * Inserts the specified trial into the dhttests.trials table
96 *
97 * @param trialuid return the trialuid of the newly inserted trial
98 * @param num_nodes how many nodes are in the trial
99 * @param topology integer representing topology for this trial
100 * @param blacklist_topology integer representing blacklist topology for this trial
101 * @param connect_topology integer representing connect topology for this trial
102 * @param connect_topology_option integer representing connect topology option
103 * @param connect_topology_option_modifier float to modify connect option
104 * @param topology_percentage percentage modifier for certain topologies
105 * @param topology_probability probability modifier for certain topologies
106 * @param puts number of puts to perform
107 * @param gets number of gets to perform
108 * @param concurrent number of concurrent requests
109 * @param settle_time time to wait between creating topology and starting testing
110 * @param num_rounds number of times to repeat the trial
111 * @param malicious_getters number of malicious GET peers in the trial
112 * @param malicious_putters number of malicious PUT peers in the trial
113 * @param malicious_droppers number of malicious DROP peers in the trial
114 * @param message string to put into DB for this trial
115 *
116 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
95 */ 117 */
96 int (*insert_trial) (unsigned long long *trialuid, int num_nodes, int topology, 118 int (*insert_trial) (unsigned long long *trialuid, int num_nodes, int topology,
97 int blacklist_topology, int connect_topology, 119 int blacklist_topology, int connect_topology,
@@ -103,7 +125,14 @@ struct GNUNET_DHTLOG_Handle
103 char *message); 125 char *message);
104 126
105 /* 127 /*
106 * Update the trial information with the ending time and dropped message stats 128 * Update dhttests.trials table with current server time as end time
129 *
130 * @param trialuid trial to update
131 * @param totalMessagesDropped stats value for messages dropped
132 * @param totalBytesDropped stats value for total bytes dropped
133 * @param unknownPeers stats value for unknown peers
134 *
135 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
107 */ 136 */
108 int (*update_trial) (unsigned long long trialuid, 137 int (*update_trial) (unsigned long long trialuid,
109 unsigned long long totalMessagesDropped, 138 unsigned long long totalMessagesDropped,
@@ -111,26 +140,58 @@ struct GNUNET_DHTLOG_Handle
111 unsigned long long unknownPeers); 140 unsigned long long unknownPeers);
112 141
113 /* 142 /*
114 * Update the trial information with the total connections 143 * Records the current topology (number of connections, time, trial)
144 *
145 * @param num_connections how many connections are in the topology
146 *
147 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
148 */
149 int (*insert_topology) (int num_connections);
150
151 /*
152 * Records a connection between two peers in the current topology
153 *
154 * @param first one side of the connection
155 * @param second other side of the connection
156 *
157 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
158 */
159 int (*insert_extended_topology) (struct GNUNET_PeerIdentity *first, struct GNUNET_PeerIdentity *second);
160
161 /*
162 * Update dhttests.trials table with total connections information
163 *
164 * @param trialuid the trialuid to update
165 * @param totalConnections the number of connections
166 *
167 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
115 */ 168 */
116 int (*update_connections) (unsigned long long trialuid, 169 int (*update_connections) (unsigned long long trialuid,
117 unsigned int totalConnections); 170 unsigned int totalConnections);
118 171
119 /* 172 /*
120 * Insert the query information from a single hop into the database 173 * Update dhttests.trials table with total connections information
121 * 174 *
122 * @param sqlqueryuid return value for the sql uid for this query 175 * @param connections the number of connections
123 * @param queryid gnunet internal query id (doesn't exist)
124 * @param type the type of query (DHTLOG_GET, DHTLOG_PUT, DHTLOG_RESULT)
125 * @param hops the hops the query has traveled
126 * @param succeeded query is successful or not (GNUNET_YES or GNUNET_NO)
127 * @param node GNUNET_PeerIdentity of the node the query is at now
128 * @param key the GNUNET_HashCode of this query
129 * @param from_node GNUNET_PeerIdentity of the node the query was
130 * received from (NULL if origin)
131 * @param to_node GNUNET_PeerIdentity of the node this node will forward
132 * to (NULL if none)
133 * 176 *
177 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
178 */
179 int (*update_topology) (unsigned int connections);
180
181 /*
182 * Inserts the specified route information into the dhttests.routes table
183 *
184 * @param sqlqueruid inserted query uid
185 * @param queryid dht query id
186 * @param type type of the query
187 * @param hops number of hops query traveled
188 * @param succeeded whether or not query was successful
189 * @param node the node the query hit
190 * @param key the key of the query
191 * @param from_node the node that sent the message to node
192 * @param to_node next node to forward message to
193 *
194 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
134 */ 195 */
135 int (*insert_route) (unsigned long long *sqlqueryuid, 196 int (*insert_route) (unsigned long long *sqlqueryuid,
136 unsigned long long queryid, 197 unsigned long long queryid,
@@ -144,12 +205,23 @@ struct GNUNET_DHTLOG_Handle
144 205
145 /* 206 /*
146 * Inserts the specified node into the dhttests.nodes table 207 * Inserts the specified node into the dhttests.nodes table
208 *
209 * @param nodeuid the inserted node uid
210 * @param node the node to insert
211 *
212 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
147 */ 213 */
148 int (*insert_node) (unsigned long long *nodeuid, 214 int (*insert_node) (unsigned long long *nodeuid,
149 struct GNUNET_PeerIdentity * node); 215 struct GNUNET_PeerIdentity * node);
150 216
151 /* 217 /*
152 * Inserts a dhtkey into the database 218 * Inserts the specified dhtkey into the dhttests.dhtkeys table,
219 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
220 *
221 * @param dhtkeyuid return value
222 * @param dhtkey hashcode of key to insert
223 *
224 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
153 */ 225 */
154 int (*insert_dhtkey) (unsigned long long *dhtkeyuid, 226 int (*insert_dhtkey) (unsigned long long *dhtkeyuid,
155 const GNUNET_HashCode * dhtkey); 227 const GNUNET_HashCode * dhtkey);
diff --git a/src/dht/plugin_dhtlog_dummy.c b/src/dht/plugin_dhtlog_dummy.c
index 55939ea9c..c90cc424b 100644
--- a/src/dht/plugin_dhtlog_dummy.c
+++ b/src/dht/plugin_dhtlog_dummy.c
@@ -183,6 +183,48 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
183 return GNUNET_OK; 183 return GNUNET_OK;
184} 184}
185 185
186
187/*
188 * Records the current topology (number of connections, time, trial)
189 *
190 * @param num_connections how many connections are in the topology
191 *
192 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
193 */
194int
195add_topology (int num_connections)
196{
197 return GNUNET_OK;
198}
199
200/*
201 * Records a connection between two peers in the current topology
202 *
203 * @param first one side of the connection
204 * @param second other side of the connection
205 *
206 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
207 */
208int
209add_extended_topology (struct GNUNET_PeerIdentity *first, struct GNUNET_PeerIdentity *second)
210{
211 return GNUNET_OK;
212}
213
214/*
215 * Update dhttests.topology table with total connections information
216 *
217 * @param totalConnections the number of connections
218 *
219 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
220 */
221int
222update_topology (unsigned int connections)
223{
224 return GNUNET_OK;
225}
226
227
186/* 228/*
187 * Provides the dhtlog api 229 * Provides the dhtlog api
188 * 230 *
@@ -206,6 +248,9 @@ libgnunet_plugin_dhtlog_dummy_init (void * cls)
206 plugin->dhtlog_api->insert_node = &add_node; 248 plugin->dhtlog_api->insert_node = &add_node;
207 plugin->dhtlog_api->insert_dhtkey = &add_dhtkey; 249 plugin->dhtlog_api->insert_dhtkey = &add_dhtkey;
208 plugin->dhtlog_api->update_connections = &add_connections; 250 plugin->dhtlog_api->update_connections = &add_connections;
251 plugin->dhtlog_api->insert_topology = &add_topology;
252 plugin->dhtlog_api->update_topology = &update_topology;
253 plugin->dhtlog_api->insert_extended_topology = &add_extended_topology;
209 return NULL; 254 return NULL;
210} 255}
211 256
diff --git a/src/dht/plugin_dhtlog_mysql.c b/src/dht/plugin_dhtlog_mysql.c
index f93935717..7798263c4 100644
--- a/src/dht/plugin_dhtlog_mysql.c
+++ b/src/dht/plugin_dhtlog_mysql.c
@@ -137,12 +137,26 @@ static struct StatementHandle *update_connection;
137#define GET_TRIAL_STMT "SELECT MAX( trialuid ) FROM trials" 137#define GET_TRIAL_STMT "SELECT MAX( trialuid ) FROM trials"
138static struct StatementHandle *get_trial; 138static struct StatementHandle *get_trial;
139 139
140#define GET_TOPOLOGY_STMT "SELECT MAX( topology_uid ) FROM topology"
141static struct StatementHandle *get_topology;
142
140#define GET_DHTKEYUID_STMT "SELECT dhtkeyuid FROM dhtkeys where dhtkey = ? and trialuid = ?" 143#define GET_DHTKEYUID_STMT "SELECT dhtkeyuid FROM dhtkeys where dhtkey = ? and trialuid = ?"
141static struct StatementHandle *get_dhtkeyuid; 144static struct StatementHandle *get_dhtkeyuid;
142 145
143#define GET_NODEUID_STMT "SELECT nodeuid FROM nodes where trialuid = ? and nodeid = ?" 146#define GET_NODEUID_STMT "SELECT nodeuid FROM nodes where trialuid = ? and nodeid = ?"
144static struct StatementHandle *get_nodeuid; 147static struct StatementHandle *get_nodeuid;
145 148
149#define INSERT_TOPOLOGY_STMT "INSERT INTO topology (trialuid, date, connections) "\
150 "VALUES (?, NOW(), ?)"
151static struct StatementHandle *insert_topology;
152
153#define EXTEND_TOPOLOGY_STMT "INSERT INTO extended_topology (topology_uid, uid_first, uid_second) "\
154 "VALUES (?, ?, ?)"
155static struct StatementHandle *extend_topology;
156
157#define UPDATE_TOPOLOGY_STMT "update topology set connections = ? where topology_uid = ?"
158static struct StatementHandle *update_topology;
159
146/** 160/**
147 * Run a query (not a select statement) 161 * Run a query (not a select statement)
148 * 162 *
@@ -244,6 +258,23 @@ itable ()
244 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1")) 258 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
245 return GNUNET_SYSERR; 259 return GNUNET_SYSERR;
246 260
261 if (MRUNS ("CREATE TABLE IF NOT EXISTS `topology` ("
262 "`topology_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
263 "`trialuid` int(10) unsigned NOT NULL,"
264 "`date` datetime NOT NULL,"
265 "`connections` int(10) unsigned NOT NULL,"
266 "PRIMARY KEY (`topology_uid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
267 return GNUNET_SYSERR;
268
269 if (MRUNS ("CREATE TABLE IF NOT EXISTS `extended_topology` ("
270 "`extended_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
271 "`topology_uid` int(10) unsigned NOT NULL,"
272 "`uid_first` int(10) unsigned NOT NULL,"
273 "`uid_second` int(10) unsigned NOT NULL,"
274 "PRIMARY KEY (`extended_uid`)"
275 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
276 return GNUNET_SYSERR;
277
247 if (MRUNS ("SET AUTOCOMMIT = 1")) 278 if (MRUNS ("SET AUTOCOMMIT = 1"))
248 return GNUNET_SYSERR; 279 return GNUNET_SYSERR;
249 280
@@ -327,7 +358,11 @@ iopen ()
327 PINIT (get_dhtkeyuid, GET_DHTKEYUID_STMT) || 358 PINIT (get_dhtkeyuid, GET_DHTKEYUID_STMT) ||
328 PINIT (get_nodeuid, GET_NODEUID_STMT) || 359 PINIT (get_nodeuid, GET_NODEUID_STMT) ||
329 PINIT (update_connection, UPDATE_CONNECTIONS_STMT) || 360 PINIT (update_connection, UPDATE_CONNECTIONS_STMT) ||
330 PINIT (get_trial, GET_TRIAL_STMT)) 361 PINIT (get_trial, GET_TRIAL_STMT) ||
362 PINIT (get_topology, GET_TOPOLOGY_STMT) ||
363 PINIT (insert_topology, INSERT_TOPOLOGY_STMT)||
364 PINIT (update_topology, UPDATE_TOPOLOGY_STMT)||
365 PINIT (extend_topology, EXTEND_TOPOLOGY_STMT))
331 { 366 {
332 return GNUNET_SYSERR; 367 return GNUNET_SYSERR;
333 } 368 }
@@ -530,6 +565,44 @@ prepared_statement_run_select (struct StatementHandle
530 return total; 565 return total;
531} 566}
532 567
568
569static int
570get_node_uid (unsigned long long *nodeuid, const GNUNET_HashCode * peerHash)
571{
572 MYSQL_BIND rbind[1];
573 struct GNUNET_CRYPTO_HashAsciiEncoded encPeer;
574 unsigned long long p_len;
575
576 int ret;
577 memset (rbind, 0, sizeof (rbind));
578 rbind[0].buffer_type = MYSQL_TYPE_LONG;
579 rbind[0].buffer = nodeuid;
580 rbind[0].is_unsigned = GNUNET_YES;
581
582 GNUNET_CRYPTO_hash_to_enc (peerHash, &encPeer);
583 p_len = strlen ((char *) &encPeer);
584
585 if (1 != (ret = prepared_statement_run_select (get_nodeuid,
586 1,
587 rbind,
588 return_ok,
589 NULL,
590 MYSQL_TYPE_LONG,
591 &current_trial,
592 GNUNET_YES,
593 MYSQL_TYPE_VAR_STRING,
594 &encPeer,
595 max_varchar_len,
596 &p_len, -1)))
597 {
598#if DEBUG_DHTLOG
599 fprintf (stderr, "FAILED\n");
600#endif
601 return GNUNET_SYSERR;
602 }
603 return GNUNET_OK;
604}
605
533static int 606static int
534get_current_trial (unsigned long long *trialuid) 607get_current_trial (unsigned long long *trialuid)
535{ 608{
@@ -552,6 +625,59 @@ get_current_trial (unsigned long long *trialuid)
552 return GNUNET_OK; 625 return GNUNET_OK;
553} 626}
554 627
628static int
629get_current_topology (unsigned long long *topologyuid)
630{
631 MYSQL_BIND rbind[1];
632
633 memset (rbind, 0, sizeof (rbind));
634 rbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
635 rbind[0].is_unsigned = 1;
636 rbind[0].buffer = topologyuid;
637
638 if ((GNUNET_OK !=
639 prepared_statement_run_select (get_topology,
640 1,
641 rbind,
642 return_ok, NULL, -1)))
643 {
644 return GNUNET_SYSERR;
645 }
646
647 return GNUNET_OK;
648}
649
650static int
651get_dhtkey_uid (unsigned long long *dhtkeyuid, const GNUNET_HashCode * key)
652{
653 MYSQL_BIND rbind[1];
654 struct GNUNET_CRYPTO_HashAsciiEncoded encKey;
655 unsigned long long k_len;
656 memset (rbind, 0, sizeof (rbind));
657 rbind[0].buffer_type = MYSQL_TYPE_LONG;
658 rbind[0].is_unsigned = 1;
659 rbind[0].buffer = dhtkeyuid;
660 GNUNET_CRYPTO_hash_to_enc (key, &encKey);
661 k_len = strlen ((char *) &encKey);
662
663 if ((GNUNET_OK !=
664 prepared_statement_run_select (get_dhtkeyuid,
665 1,
666 rbind,
667 return_ok, NULL,
668 MYSQL_TYPE_VAR_STRING,
669 &encKey,
670 max_varchar_len,
671 &k_len,
672 MYSQL_TYPE_LONGLONG,
673 &current_trial,
674 GNUNET_YES, -1)))
675 {
676 return GNUNET_SYSERR;
677 }
678
679 return GNUNET_OK;
680}
555 681
556/** 682/**
557 * Run a prepared statement that does NOT produce results. 683 * Run a prepared statement that does NOT produce results.
@@ -711,38 +837,6 @@ add_trial (unsigned long long *trialuid, int num_nodes, int topology,
711 return GNUNET_OK; 837 return GNUNET_OK;
712} 838}
713 839
714static int
715get_dhtkey_uid (unsigned long long *dhtkeyuid, const GNUNET_HashCode * key)
716{
717 MYSQL_BIND rbind[1];
718 struct GNUNET_CRYPTO_HashAsciiEncoded encKey;
719 unsigned long long k_len;
720 memset (rbind, 0, sizeof (rbind));
721 rbind[0].buffer_type = MYSQL_TYPE_LONG;
722 rbind[0].is_unsigned = 1;
723 rbind[0].buffer = dhtkeyuid;
724 GNUNET_CRYPTO_hash_to_enc (key, &encKey);
725 k_len = strlen ((char *) &encKey);
726
727 if ((GNUNET_OK !=
728 prepared_statement_run_select (get_dhtkeyuid,
729 1,
730 rbind,
731 return_ok, NULL,
732 MYSQL_TYPE_VAR_STRING,
733 &encKey,
734 max_varchar_len,
735 &k_len,
736 MYSQL_TYPE_LONGLONG,
737 &current_trial,
738 GNUNET_YES, -1)))
739 {
740 return GNUNET_SYSERR;
741 }
742
743 return GNUNET_OK;
744}
745
746/* 840/*
747 * Inserts the specified dhtkey into the dhttests.dhtkeys table, 841 * Inserts the specified dhtkey into the dhttests.dhtkeys table,
748 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid 842 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
@@ -798,43 +892,6 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
798} 892}
799 893
800 894
801static int
802get_node_uid (unsigned long long *nodeuid, const GNUNET_HashCode * peerHash)
803{
804 MYSQL_BIND rbind[1];
805 struct GNUNET_CRYPTO_HashAsciiEncoded encPeer;
806 unsigned long long p_len;
807
808 int ret;
809 memset (rbind, 0, sizeof (rbind));
810 rbind[0].buffer_type = MYSQL_TYPE_LONG;
811 rbind[0].buffer = nodeuid;
812 rbind[0].is_unsigned = GNUNET_YES;
813
814 GNUNET_CRYPTO_hash_to_enc (peerHash, &encPeer);
815 p_len = strlen ((char *) &encPeer);
816
817 if (1 != (ret = prepared_statement_run_select (get_nodeuid,
818 1,
819 rbind,
820 return_ok,
821 NULL,
822 MYSQL_TYPE_LONG,
823 &current_trial,
824 GNUNET_YES,
825 MYSQL_TYPE_VAR_STRING,
826 &encPeer,
827 max_varchar_len,
828 &p_len, -1)))
829 {
830#if DEBUG_DHTLOG
831 fprintf (stderr, "FAILED\n");
832#endif
833 return GNUNET_SYSERR;
834 }
835 return GNUNET_OK;
836}
837
838 895
839/* 896/*
840 * Inserts the specified node into the dhttests.nodes table 897 * Inserts the specified node into the dhttests.nodes table
@@ -1152,6 +1209,125 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
1152} 1209}
1153 1210
1154/* 1211/*
1212 * Update dhttests.topology table with total connections information
1213 *
1214 * @param totalConnections the number of connections
1215 *
1216 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
1217 */
1218int
1219update_current_topology (unsigned int connections)
1220{
1221 int ret;
1222 unsigned long long topologyuid;
1223
1224 get_current_topology(&topologyuid);
1225
1226 if (GNUNET_OK !=
1227 (ret = prepared_statement_run (update_topology,
1228 NULL,
1229 MYSQL_TYPE_LONG,
1230 &connections,
1231 GNUNET_YES,
1232 MYSQL_TYPE_LONGLONG,
1233 &topologyuid, GNUNET_YES, -1)))
1234 {
1235 if (ret == GNUNET_SYSERR)
1236 {
1237 return GNUNET_SYSERR;
1238 }
1239 }
1240 if (ret > 0)
1241 return GNUNET_OK;
1242 else
1243 return GNUNET_SYSERR;
1244 return GNUNET_OK;
1245}
1246
1247/*
1248 * Records the current topology (number of connections, time, trial)
1249 *
1250 * @param num_connections how many connections are in the topology
1251 *
1252 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1253 */
1254int
1255add_topology (int num_connections)
1256{
1257 int ret;
1258
1259 if (GNUNET_OK !=
1260 (ret = prepared_statement_run (insert_topology,
1261 NULL,
1262 MYSQL_TYPE_LONGLONG,
1263 &current_trial,
1264 GNUNET_YES,
1265 MYSQL_TYPE_LONG,
1266 &num_connections,
1267 GNUNET_YES, -1)))
1268 {
1269 if (ret == GNUNET_SYSERR)
1270 {
1271 return GNUNET_SYSERR;
1272 }
1273 }
1274 if (ret > 0)
1275 return GNUNET_OK;
1276 else
1277 return GNUNET_SYSERR;
1278 return GNUNET_OK;
1279}
1280
1281/*
1282 * Records a connection between two peers in the current topology
1283 *
1284 * @param first one side of the connection
1285 * @param second other side of the connection
1286 *
1287 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1288 */
1289int
1290add_extended_topology (struct GNUNET_PeerIdentity *first, struct GNUNET_PeerIdentity *second)
1291{
1292 int ret;
1293 unsigned long long first_uid;
1294 unsigned long long second_uid;
1295 unsigned long long topologyuid;
1296
1297 if (GNUNET_OK != get_current_topology(&topologyuid))
1298 return GNUNET_SYSERR;
1299 if (GNUNET_OK != get_node_uid(&first_uid, &first->hashPubKey))
1300 return GNUNET_SYSERR;
1301 if (GNUNET_OK != get_node_uid(&second_uid, &second->hashPubKey))
1302 return GNUNET_SYSERR;
1303
1304 if (GNUNET_OK !=
1305 (ret = prepared_statement_run (extend_topology,
1306 NULL,
1307 MYSQL_TYPE_LONGLONG,
1308 &topologyuid,
1309 GNUNET_YES,
1310 MYSQL_TYPE_LONGLONG,
1311 &first_uid,
1312 GNUNET_YES,
1313 MYSQL_TYPE_LONGLONG,
1314 &second_uid,
1315 GNUNET_YES,-1)))
1316 {
1317 if (ret == GNUNET_SYSERR)
1318 {
1319 return GNUNET_SYSERR;
1320 }
1321 }
1322 if (ret > 0)
1323 return GNUNET_OK;
1324 else
1325 return GNUNET_SYSERR;
1326 return GNUNET_OK;
1327}
1328
1329
1330/*
1155 * Provides the dhtlog api 1331 * Provides the dhtlog api
1156 * 1332 *
1157 * @param c the configuration to use to connect to a server 1333 * @param c the configuration to use to connect to a server
@@ -1215,6 +1391,9 @@ libgnunet_plugin_dhtlog_mysql_init (void * cls)
1215 plugin->dhtlog_api->insert_node = &add_node; 1391 plugin->dhtlog_api->insert_node = &add_node;
1216 plugin->dhtlog_api->insert_dhtkey = &add_dhtkey; 1392 plugin->dhtlog_api->insert_dhtkey = &add_dhtkey;
1217 plugin->dhtlog_api->update_connections = &add_connections; 1393 plugin->dhtlog_api->update_connections = &add_connections;
1394 plugin->dhtlog_api->insert_topology = &add_topology;
1395 plugin->dhtlog_api->update_topology = &update_current_topology;
1396 plugin->dhtlog_api->insert_extended_topology = &add_extended_topology;
1218 get_current_trial (&current_trial); 1397 get_current_trial (&current_trial);
1219 1398
1220 return NULL; 1399 return NULL;
@@ -1242,6 +1421,10 @@ libgnunet_plugin_dhtlog_mysql_done (void * cls)
1242 prepared_statement_close(get_nodeuid); 1421 prepared_statement_close(get_nodeuid);
1243 prepared_statement_close(update_connection); 1422 prepared_statement_close(update_connection);
1244 prepared_statement_close(get_trial); 1423 prepared_statement_close(get_trial);
1424 prepared_statement_close(get_topology);
1425 prepared_statement_close(insert_topology);
1426 prepared_statement_close(update_topology);
1427 prepared_statement_close(extend_topology);
1245 1428
1246 if (conn != NULL) 1429 if (conn != NULL)
1247 mysql_close (conn); 1430 mysql_close (conn);
diff --git a/src/dht/plugin_dhtlog_mysql_dump.c b/src/dht/plugin_dhtlog_mysql_dump.c
index 188807e4e..603e592e7 100644
--- a/src/dht/plugin_dhtlog_mysql_dump.c
+++ b/src/dht/plugin_dhtlog_mysql_dump.c
@@ -66,6 +66,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
66#define EXTEND_TOPOLOGY_STMT "prepare extend_topology from 'INSERT INTO extended_topology (topology_uid, uid_first, uid_second) "\ 66#define EXTEND_TOPOLOGY_STMT "prepare extend_topology from 'INSERT INTO extended_topology (topology_uid, uid_first, uid_second) "\
67 "VALUES (@temp_topology, ?, ?)'" 67 "VALUES (@temp_topology, ?, ?)'"
68 68
69#define UPDATE_TOPOLOGY_STMT "prepare update_topology from 'update topology set connections = ? where topology_uid = @temp_topology'"
69 70
70#define INSERT_TRIALS_STMT "prepare insert_trial from 'INSERT INTO trials"\ 71#define INSERT_TRIALS_STMT "prepare insert_trial from 'INSERT INTO trials"\
71 "(starttime, numnodes, topology,"\ 72 "(starttime, numnodes, topology,"\
@@ -147,7 +148,11 @@ iopen ()
147 PINIT (GET_DHTKEYUID_STMT) || 148 PINIT (GET_DHTKEYUID_STMT) ||
148 PINIT (GET_NODEUID_STMT) || 149 PINIT (GET_NODEUID_STMT) ||
149 PINIT (UPDATE_CONNECTIONS_STMT) || 150 PINIT (UPDATE_CONNECTIONS_STMT) ||
150 PINIT (GET_TRIAL_STMT)) 151 PINIT (INSERT_TOPOLOGY_STMT) ||
152 PINIT (EXTEND_TOPOLOGY_STMT) ||
153 PINIT (UPDATE_TOPOLOGY_STMT) ||
154 PINIT (GET_TRIAL_STMT) ||
155 PINIT (GET_TOPOLOGY_STMT))
151 { 156 {
152 return GNUNET_SYSERR; 157 return GNUNET_SYSERR;
153 } 158 }
@@ -440,6 +445,34 @@ add_connections (unsigned long long trialuid, unsigned int totalConnections)
440 return GNUNET_SYSERR; 445 return GNUNET_SYSERR;
441} 446}
442 447
448
449/*
450 * Update dhttests.topology table with total connections information
451 *
452 * @param totalConnections the number of connections
453 *
454 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
455 */
456int
457update_topology (unsigned int connections)
458{
459 int ret;
460 if (outfile == NULL)
461 return GNUNET_SYSERR;
462
463 ret = fprintf(outfile, "set @temp_conns = %u;\n", connections);
464
465 if (ret < 0)
466 return GNUNET_SYSERR;
467
468 ret = fprintf(outfile, "execute update_topology using @temp_conns;\n");
469
470 if (ret >= 0)
471 return GNUNET_OK;
472 else
473 return GNUNET_SYSERR;
474}
475
443/* 476/*
444 * Inserts the specified query into the dhttests.queries table 477 * Inserts the specified query into the dhttests.queries table
445 * 478 *
@@ -625,6 +658,9 @@ libgnunet_plugin_dhtlog_mysql_dump_init (void * cls)
625 plugin->dhtlog_api->insert_node = &add_node; 658 plugin->dhtlog_api->insert_node = &add_node;
626 plugin->dhtlog_api->insert_dhtkey = &add_dhtkey; 659 plugin->dhtlog_api->insert_dhtkey = &add_dhtkey;
627 plugin->dhtlog_api->update_connections = &add_connections; 660 plugin->dhtlog_api->update_connections = &add_connections;
661 plugin->dhtlog_api->insert_topology = &add_topology;
662 plugin->dhtlog_api->insert_extended_topology = &add_extended_topology;
663 plugin->dhtlog_api->update_topology = &update_topology;
628 664
629 return NULL; 665 return NULL;
630} 666}
diff --git a/src/dht/test_dhtlog.c b/src/dht/test_dhtlog.c
index 39404983c..26332bf5b 100644
--- a/src/dht/test_dhtlog.c
+++ b/src/dht/test_dhtlog.c
@@ -32,6 +32,7 @@
32 32
33static int ok; 33static int ok;
34 34
35#define CHECK(a) if (a != GNUNET_OK) return a
35/** 36/**
36 * Actual test of the service operations 37 * Actual test of the service operations
37 */ 38 */
@@ -67,11 +68,11 @@ test (struct GNUNET_DHTLOG_Handle * api)
67 .75, .25, .5, 42, 14, 68 .75, .25, .5, 42, 14,
68 5, 1, 12, 0, 0, 0, 69 5, 1, 12, 0, 0, 0,
69 "TEST INSERT TRIAL"); 70 "TEST INSERT TRIAL");
71 CHECK(ret);
70 72
71 if (ret != GNUNET_OK) 73 ret = api->insert_topology(500);
72 { 74
73 return ret; 75 CHECK(ret);
74 }
75 76
76 fprintf (stderr, "Trial uid is %llu\n", trialuid); 77 fprintf (stderr, "Trial uid is %llu\n", trialuid);
77 78
@@ -80,20 +81,17 @@ test (struct GNUNET_DHTLOG_Handle * api)
80 ret = api->insert_node (&nodeuid, &p3); 81 ret = api->insert_node (&nodeuid, &p3);
81 ret = api->insert_node (&nodeuid, &p4); 82 ret = api->insert_node (&nodeuid, &p4);
82 83
83 if (ret != GNUNET_OK) 84 CHECK(ret);
84 {
85 fprintf (stderr, "received ret value of %d\n", ret);
86 return ret;
87 }
88 85
86 ret = api->insert_topology(0);
87 ret = api->insert_extended_topology(&p1, &p2);
88 ret = api->insert_extended_topology(&p3, &p4);
89 ret = api->update_topology(101);
90 CHECK(ret);
89 ret = api->insert_dhtkey (&dhtkeyuid, &k1); 91 ret = api->insert_dhtkey (&dhtkeyuid, &k1);
90 ret = api->insert_dhtkey (&dhtkeyuid, &k2); 92 ret = api->insert_dhtkey (&dhtkeyuid, &k2);
91 93
92 if (ret != GNUNET_OK) 94 CHECK(ret);
93 {
94 fprintf (stderr, "received ret value of %d\n", ret);
95 return ret;
96 }
97 95
98 ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1); 96 ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1);
99 97
@@ -119,10 +117,7 @@ test (struct GNUNET_DHTLOG_Handle * api)
119 fprintf (stderr, "Updating trial %llu with endtime of now\n", trialuid); 117 fprintf (stderr, "Updating trial %llu with endtime of now\n", trialuid);
120 ret = api->update_trial (trialuid, 0, 0, 0); 118 ret = api->update_trial (trialuid, 0, 0, 0);
121 119
122 if (ret != GNUNET_OK) 120 CHECK(ret);
123 {
124 return ret;
125 }
126 121
127 return 0; 122 return 0;
128} 123}