aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-08 21:12:26 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-08 21:12:26 +0000
commit35174cafe6f286e9773ed449bc8e3e610c40e1f4 (patch)
treed0dd79bcaa3158f3e7ec405b04ab1e4dae5d4fa5 /src/set
parentd7991f895b89b39d06d60a6f71859616d2b71819 (diff)
downloadgnunet-35174cafe6f286e9773ed449bc8e3e610c40e1f4.tar.gz
gnunet-35174cafe6f286e9773ed449bc8e3e610c40e1f4.zip
-doxygen and formatting and style fixes
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c125
1 files changed, 72 insertions, 53 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index 96c16325f..e5dec36c3 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -336,10 +336,10 @@ _GSS_operation_destroy (struct Operation *op)
336 * 336 *
337 * @param cls closure 337 * @param cls closure
338 * @param key current key code 338 * @param key current key code
339 * @param value value in the hash map 339 * @param value a `struct ElementEntry *` to be free'd
340 * @return GNUNET_YES if we should continue to 340 * @return #GNUNET_YES if we should continue to
341 * iterate, 341 * iterate,
342 * GNUNET_NO if not. 342 * #GNUNET_NO if not.
343 */ 343 */
344static int 344static int
345destroy_elements_iterator (void *cls, 345destroy_elements_iterator (void *cls,
@@ -412,21 +412,23 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
412 struct Set *set; 412 struct Set *set;
413 struct Listener *listener; 413 struct Listener *listener;
414 414
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected, cleaning up\n"); 415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
416 416 "client disconnected, cleaning up\n");
417 set = set_get (client); 417 set = set_get (client);
418 if (NULL != set) 418 if (NULL != set)
419 { 419 {
420 set->client = NULL; 420 set->client = NULL;
421 set_destroy (set); 421 set_destroy (set);
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(client's set destroyed)\n"); 422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 "(client's set destroyed)\n");
423 } 424 }
424 listener = listener_get (client); 425 listener = listener_get (client);
425 if (NULL != listener) 426 if (NULL != listener)
426 { 427 {
427 listener->client = NULL; 428 listener->client = NULL;
428 listener_destroy (listener); 429 listener_destroy (listener);
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(client's listener destroyed)\n"); 430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "(client's listener destroyed)\n");
430 } 432 }
431} 433}
432 434
@@ -448,12 +450,12 @@ incoming_destroy (struct Operation *incoming)
448 GNUNET_free (incoming->state); 450 GNUNET_free (incoming->state);
449} 451}
450 452
453
451/** 454/**
452 * remove & free state of the operation from the incoming list 455 * remove & free state of the operation from the incoming list
453 * 456 *
454 * @param incoming the element to remove 457 * @param incoming the element to remove
455 */ 458 */
456
457static void 459static void
458incoming_retire (struct Operation *incoming) 460incoming_retire (struct Operation *incoming)
459{ 461{
@@ -533,8 +535,8 @@ incoming_suggest (struct Operation *incoming, struct Listener *listener)
533 * 535 *
534 * @param op the operation state 536 * @param op the operation state
535 * @param mh the received message 537 * @param mh the received message
536 * @return GNUNET_OK if the channel should be kept alive, 538 * @return #GNUNET_OK if the channel should be kept alive,
537 * GNUNET_SYSERR to destroy the channel 539 * #GNUNET_SYSERR to destroy the channel
538 */ 540 */
539static int 541static int
540handle_incoming_msg (struct Operation *op, 542handle_incoming_msg (struct Operation *op,
@@ -679,10 +681,12 @@ handle_client_create_set (void *cls,
679 struct GNUNET_SERVER_Client *client, 681 struct GNUNET_SERVER_Client *client,
680 const struct GNUNET_MessageHeader *m) 682 const struct GNUNET_MessageHeader *m)
681{ 683{
682 struct GNUNET_SET_CreateMessage *msg = (struct GNUNET_SET_CreateMessage *) m; 684 const struct GNUNET_SET_CreateMessage *msg;
683 struct Set *set; 685 struct Set *set;
684 686
685 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client created new set (operation %u)\n", 687 msg = (const struct GNUNET_SET_CreateMessage *) m;
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
689 "client created new set (operation %u)\n",
686 ntohs (msg->operation)); 690 ntohs (msg->operation));
687 691
688 // max. one set per client! 692 // max. one set per client!
@@ -732,11 +736,12 @@ handle_client_listen (void *cls,
732 struct GNUNET_SERVER_Client *client, 736 struct GNUNET_SERVER_Client *client,
733 const struct GNUNET_MessageHeader *m) 737 const struct GNUNET_MessageHeader *m)
734{ 738{
735 struct GNUNET_SET_ListenMessage *msg = (struct GNUNET_SET_ListenMessage *) m; 739 const struct GNUNET_SET_ListenMessage *msg;
736 struct Listener *listener; 740 struct Listener *listener;
737 struct Operation *op; 741 struct Operation *op;
738 742
739 // max. one per client! 743 msg = (const struct GNUNET_SET_ListenMessage *) m;
744 /* max. one per client! */
740 if (NULL != listener_get (client)) 745 if (NULL != listener_get (client))
741 { 746 {
742 GNUNET_break (0); 747 GNUNET_break (0);
@@ -750,19 +755,25 @@ handle_client_listen (void *cls,
750 listener->app_id = msg->app_id; 755 listener->app_id = msg->app_id;
751 listener->operation = ntohl (msg->operation); 756 listener->operation = ntohl (msg->operation);
752 GNUNET_CONTAINER_DLL_insert_tail (listeners_head, listeners_tail, listener); 757 GNUNET_CONTAINER_DLL_insert_tail (listeners_head, listeners_tail, listener);
753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new listener created (op %u, app %s)\n", 758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
754 listener->operation, GNUNET_h2s (&listener->app_id)); 759 "new listener created (op %u, app %s)\n",
760 listener->operation,
761 GNUNET_h2s (&listener->app_id));
755 762
756 /* check for incoming requests the listener is interested in */ 763 /* check for incoming requests the listener is interested in */
757 for (op = incoming_head; NULL != op; op = op->next) 764 for (op = incoming_head; NULL != op; op = op->next)
758 { 765 {
759 if (NULL == op->spec) 766 if (NULL == op->spec)
760 { 767 {
761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "request has no spec yet\n"); 768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
769 "request has no spec yet\n");
762 continue; 770 continue;
763 } 771 }
764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "considering (op: %u, app: %s, suggest: %u)\n", 772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
765 op->spec->operation, GNUNET_h2s (&op->spec->app_id), op->state->suggest_id); 773 "considering (op: %u, app: %s, suggest: %u)\n",
774 op->spec->operation,
775 GNUNET_h2s (&op->spec->app_id),
776 op->state->suggest_id);
766 777
767 /* don't consider the incoming request if it has been already suggested to a listener */ 778 /* don't consider the incoming request if it has been already suggested to a listener */
768 if (0 != op->state->suggest_id) 779 if (0 != op->state->suggest_id)
@@ -771,10 +782,12 @@ handle_client_listen (void *cls,
771 continue; 782 continue;
772 if (0 != GNUNET_CRYPTO_hash_cmp (&listener->app_id, &op->spec->app_id)) 783 if (0 != GNUNET_CRYPTO_hash_cmp (&listener->app_id, &op->spec->app_id))
773 continue; 784 continue;
774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "request suggested\n"); 785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
786 "request suggested\n");
775 incoming_suggest (op, listener); 787 incoming_suggest (op, listener);
776 } 788 }
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "considered all incoming requests\n"); 789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
790 "considered all incoming requests\n");
778 GNUNET_SERVER_receive_done (client, GNUNET_OK); 791 GNUNET_SERVER_receive_done (client, GNUNET_OK);
779} 792}
780 793
@@ -805,7 +818,8 @@ handle_client_reject (void *cls,
805 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 818 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
806 return; 819 return;
807 } 820 }
808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer request rejected by client\n"); 821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
822 "peer request rejected by client\n");
809 823
810 GNUNET_MESH_channel_destroy (incoming->channel); 824 GNUNET_MESH_channel_destroy (incoming->channel);
811 //channel destruction handler called immediately upon destruction 825 //channel destruction handler called immediately upon destruction
@@ -853,12 +867,14 @@ handle_client_add_remove (void *cls,
853 ee = GNUNET_CONTAINER_multihashmap_get (set->elements, &hash); 867 ee = GNUNET_CONTAINER_multihashmap_get (set->elements, &hash);
854 if (NULL == ee) 868 if (NULL == ee)
855 { 869 {
856 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "client tried to remove non-existing element\n"); 870 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
871 "client tried to remove non-existing element\n");
857 return; 872 return;
858 } 873 }
859 if (GNUNET_YES == ee->removed) 874 if (GNUNET_YES == ee->removed)
860 { 875 {
861 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "client tried to remove element twice\n"); 876 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
877 "client tried to remove element twice\n");
862 return; 878 return;
863 } 879 }
864 ee->removed = GNUNET_YES; 880 ee->removed = GNUNET_YES;
@@ -880,7 +896,8 @@ handle_client_add_remove (void *cls,
880 &ee->element_hash); 896 &ee->element_hash);
881 if (NULL != ee_dup) 897 if (NULL != ee_dup)
882 { 898 {
883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "element inserted twice, ignoring\n"); 899 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
900 "element inserted twice, ignoring\n");
884 GNUNET_free (ee); 901 GNUNET_free (ee);
885 return; 902 return;
886 } 903 }
@@ -904,7 +921,7 @@ handle_client_evaluate (void *cls,
904 const struct GNUNET_MessageHeader *m) 921 const struct GNUNET_MessageHeader *m)
905{ 922{
906 struct Set *set; 923 struct Set *set;
907 struct GNUNET_SET_EvaluateMessage *msg; 924 const struct GNUNET_SET_EvaluateMessage *msg;
908 struct OperationSpecification *spec; 925 struct OperationSpecification *spec;
909 struct Operation *op; 926 struct Operation *op;
910 927
@@ -916,7 +933,7 @@ handle_client_evaluate (void *cls,
916 return; 933 return;
917 } 934 }
918 935
919 msg = (struct GNUNET_SET_EvaluateMessage *) m; 936 msg = (const struct GNUNET_SET_EvaluateMessage *) m;
920 spec = GNUNET_new (struct OperationSpecification); 937 spec = GNUNET_new (struct OperationSpecification);
921 spec->operation = set->operation; 938 spec->operation = set->operation;
922 spec->app_id = msg->app_id; 939 spec->app_id = msg->app_id;
@@ -1047,9 +1064,10 @@ handle_client_accept (void *cls,
1047 const struct GNUNET_MessageHeader *mh) 1064 const struct GNUNET_MessageHeader *mh)
1048{ 1065{
1049 struct Set *set; 1066 struct Set *set;
1050 struct GNUNET_SET_AcceptRejectMessage *msg = (struct GNUNET_SET_AcceptRejectMessage *) mh; 1067 const struct GNUNET_SET_AcceptRejectMessage *msg;
1051 struct Operation *op; 1068 struct Operation *op;
1052 1069
1070 msg = (const struct GNUNET_SET_AcceptRejectMessage *) mh;
1053 op = get_incoming (ntohl (msg->accept_reject_id)); 1071 op = get_incoming (ntohl (msg->accept_reject_id));
1054 1072
1055 // incoming operation does not exist 1073 // incoming operation does not exist
@@ -1060,7 +1078,9 @@ handle_client_accept (void *cls,
1060 return; 1078 return;
1061 } 1079 }
1062 1080
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client accepting %u\n", ntohl (msg->accept_reject_id)); 1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1082 "client accepting %u\n",
1083 ntohl (msg->accept_reject_id));
1064 1084
1065 GNUNET_assert (GNUNET_YES == op->is_incoming); 1085 GNUNET_assert (GNUNET_YES == op->is_incoming);
1066 1086
@@ -1119,8 +1139,8 @@ shutdown_task (void *cls,
1119 GNUNET_MESH_disconnect (mesh); 1139 GNUNET_MESH_disconnect (mesh);
1120 mesh = NULL; 1140 mesh = NULL;
1121 } 1141 }
1122 1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n"); 1143 "handled shutdown request\n");
1124} 1144}
1125 1145
1126 1146
@@ -1128,7 +1148,7 @@ shutdown_task (void *cls,
1128 * Timeout happens iff: 1148 * Timeout happens iff:
1129 * - we suggested an operation to our listener, 1149 * - we suggested an operation to our listener,
1130 * but did not receive a response in time 1150 * but did not receive a response in time
1131 * - we got the channel from a peer but no GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST 1151 * - we got the channel from a peer but no #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST
1132 * - shutdown (obviously) 1152 * - shutdown (obviously)
1133 * 1153 *
1134 * @param cls channel context 1154 * @param cls channel context
@@ -1160,10 +1180,8 @@ static void
1160handle_incoming_disconnect (struct Operation *op) 1180handle_incoming_disconnect (struct Operation *op)
1161{ 1181{
1162 GNUNET_assert (GNUNET_YES == op->is_incoming); 1182 GNUNET_assert (GNUNET_YES == op->is_incoming);
1163
1164 if (NULL == op->channel) 1183 if (NULL == op->channel)
1165 return; 1184 return;
1166
1167 incoming_destroy (op); 1185 incoming_destroy (op);
1168} 1186}
1169 1187
@@ -1172,7 +1190,7 @@ handle_incoming_disconnect (struct Operation *op)
1172 * Method called whenever another peer has added us to a channel 1190 * Method called whenever another peer has added us to a channel
1173 * the other peer initiated. 1191 * the other peer initiated.
1174 * Only called (once) upon reception of data with a message type which was 1192 * Only called (once) upon reception of data with a message type which was
1175 * subscribed to in GNUNET_MESH_connect. 1193 * subscribed to in GNUNET_MESH_connect().
1176 * 1194 *
1177 * The channel context represents the operation itself and gets added to a DLL, 1195 * The channel context represents the operation itself and gets added to a DLL,
1178 * from where it gets looked up when our local listener client responds 1196 * from where it gets looked up when our local listener client responds
@@ -1198,7 +1216,8 @@ channel_new_cb (void *cls,
1198 .peer_disconnect = handle_incoming_disconnect 1216 .peer_disconnect = handle_incoming_disconnect
1199 }; 1217 };
1200 1218
1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new incoming channel\n"); 1219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1220 "new incoming channel\n");
1202 1221
1203 if (GNUNET_APPLICATION_TYPE_SET != port) 1222 if (GNUNET_APPLICATION_TYPE_SET != port)
1204 { 1223 {
@@ -1225,9 +1244,8 @@ channel_new_cb (void *cls,
1225 1244
1226/** 1245/**
1227 * Function called whenever a channel is destroyed. Should clean up 1246 * Function called whenever a channel is destroyed. Should clean up
1228 * any associated state. 1247 * any associated state. It must NOT call
1229 * GNUNET_MESH_channel_destroy. It must NOT call GNUNET_MESH_channel_destroy on 1248 * GNUNET_MESH_channel_destroy() on the channel.
1230 * the channel.
1231 * 1249 *
1232 * The peer_disconnect function is part of a a virtual table set initially either 1250 * The peer_disconnect function is part of a a virtual table set initially either
1233 * when a peer creates a new channel with us (channel_new_cb), or once we create 1251 * when a peer creates a new channel with us (channel_new_cb), or once we create
@@ -1236,7 +1254,7 @@ channel_new_cb (void *cls,
1236 * Once we know the exact type of operation (union/intersection), the vt is 1254 * Once we know the exact type of operation (union/intersection), the vt is
1237 * replaced with an operation specific instance (_GSS_[op]_vt). 1255 * replaced with an operation specific instance (_GSS_[op]_vt).
1238 * 1256 *
1239 * @param cls closure (set from GNUNET_MESH_connect) 1257 * @param cls closure (set from GNUNET_MESH_connect())
1240 * @param channel connection to the other end (henceforth invalid) 1258 * @param channel connection to the other end (henceforth invalid)
1241 * @param channel_ctx place where local state associated 1259 * @param channel_ctx place where local state associated
1242 * with the channel is stored 1260 * with the channel is stored
@@ -1247,10 +1265,9 @@ channel_end_cb (void *cls,
1247{ 1265{
1248 struct Operation *op = channel_ctx; 1266 struct Operation *op = channel_ctx;
1249 1267
1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel end cb called\n"); 1268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1251 1269 "channel end cb called\n");
1252 op->channel = NULL; 1270 op->channel = NULL;
1253
1254 if (NULL != op->vt) 1271 if (NULL != op->vt)
1255 op->vt->peer_disconnect (op); 1272 op->vt->peer_disconnect (op);
1256 /* mesh will never call us with the context again! */ 1273 /* mesh will never call us with the context again! */
@@ -1269,13 +1286,12 @@ channel_end_cb (void *cls,
1269 * Once we know the exact type of operation (union/intersection), the vt is 1286 * Once we know the exact type of operation (union/intersection), the vt is
1270 * replaced with an operation specific instance (_GSS_[op]_vt). 1287 * replaced with an operation specific instance (_GSS_[op]_vt).
1271 * 1288 *
1272 * @param cls Closure (set from GNUNET_MESH_connect). 1289 * @param cls Closure (set from GNUNET_MESH_connect()).
1273 * @param channel Connection to the other end. 1290 * @param channel Connection to the other end.
1274 * @param channel_ctx Place to store local state associated with the channel. 1291 * @param channel_ctx Place to store local state associated with the channel.
1275 * @param message The actual message. 1292 * @param message The actual message.
1276 * 1293 * @return #GNUNET_OK to keep the channel open,
1277 * @return GNUNET_OK to keep the channel open, 1294 * #GNUNET_SYSERR to close it (signal serious error).
1278 * GNUNET_SYSERR to close it (signal serious error).
1279 */ 1295 */
1280static int 1296static int
1281dispatch_p2p_message (void *cls, 1297dispatch_p2p_message (void *cls,
@@ -1286,12 +1302,14 @@ dispatch_p2p_message (void *cls,
1286 struct Operation *op = *channel_ctx; 1302 struct Operation *op = *channel_ctx;
1287 int ret; 1303 int ret;
1288 1304
1289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dispatching mesh message (type: %u)\n", 1305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1306 "dispatching mesh message (type: %u)\n",
1290 ntohs (message->type)); 1307 ntohs (message->type));
1291 /* do this before the handler, as the handler might kill the channel */ 1308 /* do this before the handler, as the handler might kill the channel */
1292 GNUNET_MESH_receive_done (channel); 1309 GNUNET_MESH_receive_done (channel);
1293 ret = op->vt->msg_handler (op, message); 1310 ret = op->vt->msg_handler (op, message);
1294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled mesh message (type: %u)\n", 1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1312 "handled mesh message (type: %u)\n",
1295 ntohs (message->type)); 1313 ntohs (message->type));
1296 return ret; 1314 return ret;
1297} 1315}
@@ -1351,11 +1369,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1351 mesh_handlers, mesh_ports); 1369 mesh_handlers, mesh_ports);
1352 if (NULL == mesh) 1370 if (NULL == mesh)
1353 { 1371 {
1354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not connect to mesh\n"); 1372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1373 _("Could not connect to mesh service\n"));
1355 return; 1374 return;
1356 } 1375 }
1357
1358 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "started\n");
1359} 1376}
1360 1377
1361 1378
@@ -1370,9 +1387,11 @@ int
1370main (int argc, char *const *argv) 1387main (int argc, char *const *argv)
1371{ 1388{
1372 int ret; 1389 int ret;
1390
1373 ret = GNUNET_SERVICE_run (argc, argv, "set", 1391 ret = GNUNET_SERVICE_run (argc, argv, "set",
1374 GNUNET_SERVICE_OPTION_NONE, &run, NULL); 1392 GNUNET_SERVICE_OPTION_NONE, &run, NULL);
1375 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exit (%d)\n", GNUNET_OK != ret);
1376 return (GNUNET_OK == ret) ? 0 : 1; 1393 return (GNUNET_OK == ret) ? 0 : 1;
1377} 1394}
1378 1395
1396/* end of gnunet-service-set.c */
1397