diff options
author | Gabor X Toth <*@tg-x.net> | 2016-05-05 11:33:40 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2016-05-05 11:33:40 +0000 |
commit | 78edac9543fa364868e9570080b46a153ec5fad4 (patch) | |
tree | 2d4bf8e2d41e4ab0c789ef6f0553f3c3a22d0f2c /src | |
parent | 2b987c3684cbf1d15b9ed44bbce911653bd6f330 (diff) | |
download | gnunet-78edac9543fa364868e9570080b46a153ec5fad4.tar.gz gnunet-78edac9543fa364868e9570080b46a153ec5fad4.zip |
social: app connected callback
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_protocols.h | 8 | ||||
-rw-r--r-- | src/include/gnunet_social_service.h | 8 | ||||
-rw-r--r-- | src/social/gnunet-service-social.c | 36 | ||||
-rw-r--r-- | src/social/social_api.c | 40 | ||||
-rw-r--r-- | src/social/test_social.c | 11 |
5 files changed, 97 insertions, 6 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index a492e4dd7..8a429ba41 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -2643,8 +2643,14 @@ extern "C" | |||
2643 | /** S->C: notify about an existing ego */ | 2643 | /** S->C: notify about an existing ego */ |
2644 | #define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 853 | 2644 | #define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 853 |
2645 | 2645 | ||
2646 | /** S->C: end of ego list */ | ||
2647 | #define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END 854 | ||
2648 | |||
2646 | /** S->C: notify about an existing place */ | 2649 | /** S->C: notify about an existing place */ |
2647 | #define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 854 | 2650 | #define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 855 |
2651 | |||
2652 | /** S->C: end of place list */ | ||
2653 | #define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END 856 | ||
2648 | 2654 | ||
2649 | /** C->S: set message processing flags */ | 2655 | /** C->S: set message processing flags */ |
2650 | #define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 860 | 2656 | #define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 860 |
diff --git a/src/include/gnunet_social_service.h b/src/include/gnunet_social_service.h index 88ebc3dad..e93436e96 100644 --- a/src/include/gnunet_social_service.h +++ b/src/include/gnunet_social_service.h | |||
@@ -334,6 +334,13 @@ enum GNUNET_SOCIAL_AppPlaceState | |||
334 | 334 | ||
335 | 335 | ||
336 | /** | 336 | /** |
337 | * Called after receiving initial list of egos and places. | ||
338 | */ | ||
339 | typedef void | ||
340 | (*GNUNET_SOCIAL_AppConnectedCallback) (void *cls); | ||
341 | |||
342 | |||
343 | /** | ||
337 | * Notification about a home. | 344 | * Notification about a home. |
338 | * | 345 | * |
339 | * @param cls | 346 | * @param cls |
@@ -402,6 +409,7 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
402 | GNUNET_SOCIAL_AppEgoCallback ego_cb, | 409 | GNUNET_SOCIAL_AppEgoCallback ego_cb, |
403 | GNUNET_SOCIAL_AppHostPlaceCallback host_cb, | 410 | GNUNET_SOCIAL_AppHostPlaceCallback host_cb, |
404 | GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb, | 411 | GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb, |
412 | GNUNET_SOCIAL_AppConnectedCallback connected_cb, | ||
405 | void *cls); | 413 | void *cls); |
406 | 414 | ||
407 | 415 | ||
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 03a113d7e..e2d6544c1 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c | |||
@@ -432,7 +432,7 @@ place_entry_cleanup (void *cls, | |||
432 | void *value) | 432 | void *value) |
433 | { | 433 | { |
434 | struct Place *plc = value; | 434 | struct Place *plc = value; |
435 | 435 | ||
436 | cleanup_place (plc); | 436 | cleanup_place (plc); |
437 | return GNUNET_YES; | 437 | return GNUNET_YES; |
438 | } | 438 | } |
@@ -538,7 +538,7 @@ static void | |||
538 | cleanup_place (void *cls) | 538 | cleanup_place (void *cls) |
539 | { | 539 | { |
540 | struct Place *plc = cls; | 540 | struct Place *plc = cls; |
541 | 541 | ||
542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
543 | "%p Cleaning up place %s\n", | 543 | "%p Cleaning up place %s\n", |
544 | plc, GNUNET_h2s (&plc->pub_key_hash)); | 544 | plc, GNUNET_h2s (&plc->pub_key_hash)); |
@@ -1945,6 +1945,21 @@ app_notify_place (struct GNUNET_MessageHeader *msg, | |||
1945 | 1945 | ||
1946 | 1946 | ||
1947 | void | 1947 | void |
1948 | app_notify_place_end (struct GNUNET_SERVER_Client *client) | ||
1949 | { | ||
1950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1951 | "%p Sending end of place list notification to client\n", | ||
1952 | client); | ||
1953 | |||
1954 | struct GNUNET_MessageHeader msg; | ||
1955 | msg.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END); | ||
1956 | msg.size = htons (sizeof (msg)); | ||
1957 | |||
1958 | client_send_msg (client, &msg); | ||
1959 | } | ||
1960 | |||
1961 | |||
1962 | void | ||
1948 | app_notify_ego (struct Ego *ego, struct GNUNET_SERVER_Client *client) | 1963 | app_notify_ego (struct Ego *ego, struct GNUNET_SERVER_Client *client) |
1949 | { | 1964 | { |
1950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1965 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1964,6 +1979,21 @@ app_notify_ego (struct Ego *ego, struct GNUNET_SERVER_Client *client) | |||
1964 | } | 1979 | } |
1965 | 1980 | ||
1966 | 1981 | ||
1982 | void | ||
1983 | app_notify_ego_end (struct GNUNET_SERVER_Client *client) | ||
1984 | { | ||
1985 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1986 | "%p Sending end of ego list notification to client\n", | ||
1987 | client); | ||
1988 | |||
1989 | struct GNUNET_MessageHeader msg; | ||
1990 | msg.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END); | ||
1991 | msg.size = htons (sizeof (msg)); | ||
1992 | |||
1993 | client_send_msg (client, &msg); | ||
1994 | } | ||
1995 | |||
1996 | |||
1967 | int | 1997 | int |
1968 | app_place_entry_notify (void *cls, const struct GNUNET_HashCode *key, void *value) | 1998 | app_place_entry_notify (void *cls, const struct GNUNET_HashCode *key, void *value) |
1969 | { | 1999 | { |
@@ -2008,11 +2038,13 @@ client_recv_app_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
2008 | GNUNET_CRYPTO_hash (app_id, app_id_size, &app_id_hash); | 2038 | GNUNET_CRYPTO_hash (app_id, app_id_size, &app_id_hash); |
2009 | 2039 | ||
2010 | GNUNET_CONTAINER_multihashmap_iterate (egos, ego_entry, client); | 2040 | GNUNET_CONTAINER_multihashmap_iterate (egos, ego_entry, client); |
2041 | app_notify_ego_end (client); | ||
2011 | 2042 | ||
2012 | struct GNUNET_CONTAINER_MultiHashMap * | 2043 | struct GNUNET_CONTAINER_MultiHashMap * |
2013 | app_places = GNUNET_CONTAINER_multihashmap_get (apps_places, &app_id_hash); | 2044 | app_places = GNUNET_CONTAINER_multihashmap_get (apps_places, &app_id_hash); |
2014 | if (NULL != app_places) | 2045 | if (NULL != app_places) |
2015 | GNUNET_CONTAINER_multihashmap_iterate (app_places, app_place_entry_notify, client); | 2046 | GNUNET_CONTAINER_multihashmap_iterate (app_places, app_place_entry_notify, client); |
2047 | app_notify_place_end (client); | ||
2016 | 2048 | ||
2017 | struct ClientListItem *cli = GNUNET_new (struct ClientListItem); | 2049 | struct ClientListItem *cli = GNUNET_new (struct ClientListItem); |
2018 | cli->client = client; | 2050 | cli->client = client; |
diff --git a/src/social/social_api.c b/src/social/social_api.c index edda0203e..d2428893d 100644 --- a/src/social/social_api.c +++ b/src/social/social_api.c | |||
@@ -102,6 +102,7 @@ struct GNUNET_SOCIAL_App | |||
102 | GNUNET_SOCIAL_AppEgoCallback ego_cb; | 102 | GNUNET_SOCIAL_AppEgoCallback ego_cb; |
103 | GNUNET_SOCIAL_AppHostPlaceCallback host_cb; | 103 | GNUNET_SOCIAL_AppHostPlaceCallback host_cb; |
104 | GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb; | 104 | GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb; |
105 | GNUNET_SOCIAL_AppConnectedCallback connected_cb; | ||
105 | void *cb_cls; | 106 | void *cb_cls; |
106 | }; | 107 | }; |
107 | 108 | ||
@@ -925,6 +926,16 @@ app_recv_ego (void *cls, | |||
925 | 926 | ||
926 | 927 | ||
927 | static void | 928 | static void |
929 | app_recv_ego_end (void *cls, | ||
930 | struct GNUNET_CLIENT_MANAGER_Connection *client, | ||
931 | const struct GNUNET_MessageHeader *msg) | ||
932 | { | ||
933 | struct GNUNET_SOCIAL_App * | ||
934 | app = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*app)); | ||
935 | } | ||
936 | |||
937 | |||
938 | static void | ||
928 | app_recv_place (void *cls, | 939 | app_recv_place (void *cls, |
929 | struct GNUNET_CLIENT_MANAGER_Connection *client, | 940 | struct GNUNET_CLIENT_MANAGER_Connection *client, |
930 | const struct GNUNET_MessageHeader *msg) | 941 | const struct GNUNET_MessageHeader *msg) |
@@ -955,18 +966,33 @@ app_recv_place (void *cls, | |||
955 | struct GNUNET_SOCIAL_HostConnection *hconn = GNUNET_malloc (sizeof (*hconn)); | 966 | struct GNUNET_SOCIAL_HostConnection *hconn = GNUNET_malloc (sizeof (*hconn)); |
956 | hconn->app = app; | 967 | hconn->app = app; |
957 | hconn->plc_msg = *pmsg; | 968 | hconn->plc_msg = *pmsg; |
958 | app->host_cb (app->cb_cls, hconn, ego, &pmsg->place_pub_key, pmsg->place_state); | 969 | if (NULL != app->host_cb) |
970 | app->host_cb (app->cb_cls, hconn, ego, &pmsg->place_pub_key, pmsg->place_state); | ||
959 | } | 971 | } |
960 | else | 972 | else |
961 | { | 973 | { |
962 | struct GNUNET_SOCIAL_GuestConnection *gconn = GNUNET_malloc (sizeof (*gconn)); | 974 | struct GNUNET_SOCIAL_GuestConnection *gconn = GNUNET_malloc (sizeof (*gconn)); |
963 | gconn->app = app; | 975 | gconn->app = app; |
964 | gconn->plc_msg = *pmsg; | 976 | gconn->plc_msg = *pmsg; |
965 | app->guest_cb (app->cb_cls, gconn, ego, &pmsg->place_pub_key, pmsg->place_state); | 977 | if (NULL != app->guest_cb) |
978 | app->guest_cb (app->cb_cls, gconn, ego, &pmsg->place_pub_key, pmsg->place_state); | ||
966 | } | 979 | } |
967 | } | 980 | } |
968 | 981 | ||
969 | 982 | ||
983 | static void | ||
984 | app_recv_place_end (void *cls, | ||
985 | struct GNUNET_CLIENT_MANAGER_Connection *client, | ||
986 | const struct GNUNET_MessageHeader *msg) | ||
987 | { | ||
988 | struct GNUNET_SOCIAL_App * | ||
989 | app = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*app)); | ||
990 | |||
991 | if (NULL != app->connected_cb) | ||
992 | app->connected_cb (app->cb_cls); | ||
993 | } | ||
994 | |||
995 | |||
970 | static struct GNUNET_CLIENT_MANAGER_MessageHandler host_handlers[] = | 996 | static struct GNUNET_CLIENT_MANAGER_MessageHandler host_handlers[] = |
971 | { | 997 | { |
972 | { host_recv_enter_ack, NULL, | 998 | { host_recv_enter_ack, NULL, |
@@ -1049,10 +1075,18 @@ static struct GNUNET_CLIENT_MANAGER_MessageHandler app_handlers[] = | |||
1049 | GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO, | 1075 | GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO, |
1050 | sizeof (struct AppEgoMessage), GNUNET_YES }, | 1076 | sizeof (struct AppEgoMessage), GNUNET_YES }, |
1051 | 1077 | ||
1078 | { app_recv_ego_end, NULL, | ||
1079 | GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END, | ||
1080 | sizeof (struct GNUNET_MessageHeader), GNUNET_NO }, | ||
1081 | |||
1052 | { app_recv_place, NULL, | 1082 | { app_recv_place, NULL, |
1053 | GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE, | 1083 | GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE, |
1054 | sizeof (struct AppPlaceMessage), GNUNET_NO }, | 1084 | sizeof (struct AppPlaceMessage), GNUNET_NO }, |
1055 | 1085 | ||
1086 | { app_recv_place_end, NULL, | ||
1087 | GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END, | ||
1088 | sizeof (struct GNUNET_MessageHeader), GNUNET_NO }, | ||
1089 | |||
1056 | { app_recv_result, NULL, | 1090 | { app_recv_result, NULL, |
1057 | GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE, | 1091 | GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE, |
1058 | sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES }, | 1092 | sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES }, |
@@ -2426,6 +2460,7 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2426 | GNUNET_SOCIAL_AppEgoCallback ego_cb, | 2460 | GNUNET_SOCIAL_AppEgoCallback ego_cb, |
2427 | GNUNET_SOCIAL_AppHostPlaceCallback host_cb, | 2461 | GNUNET_SOCIAL_AppHostPlaceCallback host_cb, |
2428 | GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb, | 2462 | GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb, |
2463 | GNUNET_SOCIAL_AppConnectedCallback connected_cb, | ||
2429 | void *cls) | 2464 | void *cls) |
2430 | { | 2465 | { |
2431 | uint16_t app_id_size = strnlen (id, GNUNET_SOCIAL_APP_MAX_ID_SIZE); | 2466 | uint16_t app_id_size = strnlen (id, GNUNET_SOCIAL_APP_MAX_ID_SIZE); |
@@ -2438,6 +2473,7 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2438 | app->ego_cb = ego_cb; | 2473 | app->ego_cb = ego_cb; |
2439 | app->host_cb = host_cb; | 2474 | app->host_cb = host_cb; |
2440 | app->guest_cb = guest_cb; | 2475 | app->guest_cb = guest_cb; |
2476 | app->connected_cb = connected_cb; | ||
2441 | app->cb_cls = cls; | 2477 | app->cb_cls = cls; |
2442 | app->egos = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 2478 | app->egos = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
2443 | app->client = GNUNET_CLIENT_MANAGER_connect (cfg, "social", | 2479 | app->client = GNUNET_CLIENT_MANAGER_connect (cfg, "social", |
diff --git a/src/social/test_social.c b/src/social/test_social.c index d781561e5..9c07a7be6 100644 --- a/src/social/test_social.c +++ b/src/social/test_social.c | |||
@@ -50,7 +50,7 @@ const char *app_id = "test"; | |||
50 | /** | 50 | /** |
51 | * Handle for task for timeout termination. | 51 | * Handle for task for timeout termination. |
52 | */ | 52 | */ |
53 | struct GNUNET_SCHEDULER_Task * end_badly_task; | 53 | struct GNUNET_SCHEDULER_Task *end_badly_task; |
54 | 54 | ||
55 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 55 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
56 | 56 | ||
@@ -400,6 +400,14 @@ guest_reconnected (void *cls, int result, | |||
400 | 400 | ||
401 | 401 | ||
402 | static void | 402 | static void |
403 | app_connected (void *cls) | ||
404 | { | ||
405 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
406 | "App connected: %p\n", cls); | ||
407 | } | ||
408 | |||
409 | |||
410 | static void | ||
403 | app_recv_host (void *cls, | 411 | app_recv_host (void *cls, |
404 | struct GNUNET_SOCIAL_HostConnection *hconn, | 412 | struct GNUNET_SOCIAL_HostConnection *hconn, |
405 | struct GNUNET_SOCIAL_Ego *ego, | 413 | struct GNUNET_SOCIAL_Ego *ego, |
@@ -492,6 +500,7 @@ schedule_reconnect (void *cls) | |||
492 | app_recv_ego, | 500 | app_recv_ego, |
493 | app_recv_host, | 501 | app_recv_host, |
494 | app_recv_guest, | 502 | app_recv_guest, |
503 | app_connected, | ||
495 | NULL); | 504 | NULL); |
496 | } | 505 | } |
497 | 506 | ||