diff options
-rw-r--r-- | src/include/gnunet_multicast_service.h | 67 | ||||
-rw-r--r-- | src/include/gnunet_psyc_service.h | 119 | ||||
-rw-r--r-- | src/multicast/Makefile.am | 2 | ||||
-rw-r--r-- | src/multicast/gnunet-service-multicast.c | 160 | ||||
-rw-r--r-- | src/multicast/multicast.h | 51 | ||||
-rw-r--r-- | src/multicast/multicast_api.c | 120 | ||||
-rw-r--r-- | src/psyc/gnunet-service-psyc.c | 261 | ||||
-rw-r--r-- | src/psyc/psyc.h | 19 | ||||
-rw-r--r-- | src/psyc/psyc_api.c | 147 | ||||
-rw-r--r-- | src/psyc/test_psyc.c | 86 |
10 files changed, 665 insertions, 367 deletions
diff --git a/src/include/gnunet_multicast_service.h b/src/include/gnunet_multicast_service.h index 7ceb2e352c..5079a087b6 100644 --- a/src/include/gnunet_multicast_service.h +++ b/src/include/gnunet_multicast_service.h @@ -230,7 +230,7 @@ GNUNET_NETWORK_STRUCT_END /** * Handle that identifies a join request. * - * Used to match calls to #GNUNET_MULTICAST_JoinCallback to the + * Used to match calls to #GNUNET_MULTICAST_JoinRequestCallback to the * corresponding calls to #GNUNET_MULTICAST_join_decision(). */ struct GNUNET_MULTICAST_JoinHandle; @@ -240,11 +240,12 @@ struct GNUNET_MULTICAST_JoinHandle; * Function to call with the decision made for a join request. * * Must be called once and only once in response to an invocation of the - * #GNUNET_MULTICAST_JoinCallback. + * #GNUNET_MULTICAST_JoinRequestCallback. * * @param jh Join request handle. - * @param is_admitted #GNUNET_YES if joining is approved, - * #GNUNET_NO if it is disapproved + * @param is_admitted #GNUNET_YES if the join is approved, + * #GNUNET_NO if it is disapproved, + * #GNUNET_SYSERR if we cannot answer the request. * @param relay_count Number of relays given. * @param relays Array of suggested peers that might be useful relays to use * when joining the multicast group (essentially a list of peers that @@ -261,7 +262,7 @@ struct GNUNET_MULTICAST_JoinHandle; struct GNUNET_MULTICAST_ReplayHandle * GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh, int is_admitted, - unsigned int relay_count, + uint16_t relay_count, const struct GNUNET_PeerIdentity *relays, const struct GNUNET_MessageHeader *join_resp); @@ -273,16 +274,40 @@ GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh, * with the decision. * * @param cls Closure. - * @param peer Identity of the member that wants to join. - * @param member_key Requesting member's public key. + * @param member_key Public key of the member requesting join. * @param join_msg Application-dependent join message from the new member. * @param jh Join handle to pass to GNUNET_MULTICAST_join_decison(). */ typedef void -(*GNUNET_MULTICAST_JoinCallback) (void *cls, - const struct GNUNET_CRYPTO_EddsaPublicKey *member_key, - const struct GNUNET_MessageHeader *join_msg, - struct GNUNET_MULTICAST_JoinHandle *jh); +(*GNUNET_MULTICAST_JoinRequestCallback) (void *cls, + const struct GNUNET_CRYPTO_EddsaPublicKey *member_key, + const struct GNUNET_MessageHeader *join_msg, + struct GNUNET_MULTICAST_JoinHandle *jh); + + +/** + * Method called to inform about the decision in response to a join request. + * + * If @a is_admitted is not #GNUNET_YES, then the multicast service disconnects + * the client and the multicast member handle returned by + * GNUNET_MULTICAST_member_join() is invalidated. + * + * @param cls Closure. + * @param is_admitted #GNUNET_YES or #GNUNET_NO or #GNUNET_SYSERR + * @param peer The peer we are connected to and the join decision is from. + * @param relay_count Number of peers in the @a relays array. + * @param relays Peer identities of members of the group, which serve as relays + * and can be used to join the group at. If empty, only the origin can + * be used to connect to the group. + * @param join_msg Application-dependent join message from the origin. + */ +typedef void +(*GNUNET_MULTICAST_JoinDecisionCallback) (void *cls, + int is_admitted, + const struct GNUNET_PeerIdentity *peer, + uint16_t relay_count, + const struct GNUNET_PeerIdentity *relays, + const struct GNUNET_MessageHeader *join_msg); /** @@ -542,9 +567,9 @@ GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh, * @param cfg Configuration to use. * @param priv_key ECC key that will be used to sign messages for this * multicast session; public key is used to identify the multicast group; - * @param next_fragment_id Next fragment ID to continue counting fragments from - * when restarting the origin. 1 for a new group. - * @param join_cb Function called to approve / disapprove joining of a peer. + * @param max_fragment_id Maximum fragment ID already sent to the group. + * 0 for a new group. + * @param join_request_cb Function called to approve / disapprove joining of a peer. * @param member_test_cb Function multicast can use to test group membership. * @param replay_frag_cb Function that can be called to replay a message fragment. * @param replay_msg_cb Function that can be called to replay a message. @@ -558,8 +583,8 @@ GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh, struct GNUNET_MULTICAST_Origin * GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key, - uint64_t next_fragment_id, - GNUNET_MULTICAST_JoinCallback join_cb, + uint64_t max_fragment_id, + GNUNET_MULTICAST_JoinRequestCallback join_request_cb, GNUNET_MULTICAST_MembershipTestCallback member_test_cb, GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, @@ -667,11 +692,12 @@ GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin); * of multicast messages. * @param relay_count Number of peers in the @a relays array. * @param relays Peer identities of members of the group, which serve as relays - * and can be used to join the group at. and send the @a join_request to. + * and can be used to join the group at and send the @a join_request to. * If empty, the @a join_request is sent directly to the @a origin. * @param join_msg Application-dependent join message to be passed to the * @a origin. - * @param join_cb Function called to approve / disapprove joining of a peer. + * @param join_request_cb Function called to approve / disapprove joining of a peer. + * @param join_decision_cb Function called to inform about the join decision. * @param mem_test_cb Function multicast can use to test group membership. * @param replay_frag_cb Function that can be called to replay message fragments * this peer already knows from this group. NULL if this @@ -690,10 +716,11 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EddsaPublicKey *group_key, const struct GNUNET_CRYPTO_EddsaPrivateKey *member_key, const struct GNUNET_PeerIdentity *origin, - uint32_t relay_count, + uint16_t relay_count, const struct GNUNET_PeerIdentity *relays, const struct GNUNET_MessageHeader *join_request, - GNUNET_MULTICAST_JoinCallback join_cb, + GNUNET_MULTICAST_JoinRequestCallback join_request_cb, + GNUNET_MULTICAST_JoinDecisionCallback join_decision_cb, GNUNET_MULTICAST_MembershipTestCallback mem_test_cb, GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, diff --git a/src/include/gnunet_psyc_service.h b/src/include/gnunet_psyc_service.h index 2ae20adc57..4f4c99c1f9 100644 --- a/src/include/gnunet_psyc_service.h +++ b/src/include/gnunet_psyc_service.h @@ -325,17 +325,18 @@ typedef void /** * Method called from PSYC upon receiving a join request. * - * @param cls Closure. - * @param slave requesting to join. + * @param cls Closure. + * @param slave_key Public key of the slave requesting join. * @param join_msg Join message sent along with the request. - * @param jh Join handle to use with GNUNET_PSYC_join_decision() + * @param jh Join handle to use with GNUNET_PSYC_join_decision() */ typedef void -(*GNUNET_PSYC_JoinCallback) (void *cls, - const struct GNUNET_CRYPTO_EddsaPublicKey - *slave_key, - const struct GNUNET_PSYC_MessageHeader *join_msg, - struct GNUNET_PSYC_JoinHandle *jh); +(*GNUNET_PSYC_JoinRequestCallback) (void *cls, + const struct + GNUNET_CRYPTO_EddsaPublicKey *slave_key, + const struct + GNUNET_PSYC_MessageHeader *join_msg, + struct GNUNET_PSYC_JoinHandle *jh); /** @@ -344,32 +345,30 @@ typedef void * Must be called once and only once in response to an invocation of the * #GNUNET_PSYC_JoinCallback. * - * @param jh Join request handle. - * @param is_admitted #GNUNET_YES if joining is approved, - * #GNUNET_NO if it is disapproved. - * @param relay_count Number of relays given. - * @param relays Array of suggested peers that might be useful relays to use + * @param jh Join request handle. + * @param is_admitted #GNUNET_YES if the join is approved, + * #GNUNET_NO if it is disapproved, + * #GNUNET_SYSERR if we cannot answer the request. + * @param relay_count Number of relays given. + * @param relays Array of suggested peers that might be useful relays to use * when joining the multicast group (essentially a list of peers that * are already part of the multicast group and might thus be willing * to help with routing). If empty, only this local peer (which must * be the multicast origin) is a good candidate for building the * multicast tree. Note that it is unnecessary to specify our own * peer identity in this array. - * @param method_name Method name for the message transmitted with the response. - * @param env Environment containing transient variables for the message, - * or NULL. - * @param data Data of the message. - * @param data_size Size of @a data. + * @param join_resp Application-dependent join response message to send along + * with the decision. + * + * @return #GNUNET_OK on success, + * #GNUNET_SYSERR if @a join_resp is too large. */ -void +int GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh, int is_admitted, uint32_t relay_count, const struct GNUNET_PeerIdentity *relays, - const char *method_name, - const struct GNUNET_ENV_Environment *env, - const void *data, - size_t data_size); + const struct GNUNET_PSYC_MessageHeader *join_resp); /** @@ -400,29 +399,31 @@ typedef void * or part messages, the respective methods must call other PSYC functions to * inform PSYC about the meaning of the respective events. * - * @param cfg Configuration to use (to connect to PSYC service). - * @param channel_key ECC key that will be used to sign messages for this + * @param cfg Configuration to use (to connect to PSYC service). + * @param channel_key ECC key that will be used to sign messages for this * PSYC session. The public key is used to identify the PSYC channel. * Note that end-users will usually not use the private key directly, but * rather look it up in GNS for places managed by other users, or select * a file with the private key(s) when setting up their own channels * FIXME: we'll likely want to use NOT the p521 curve here, but a cheaper * one in the future. - * @param policy Channel policy specifying join and history restrictions. + * @param policy Channel policy specifying join and history restrictions. * Used to automate join decisions. - * @param message_cb Function to invoke on message parts received from slaves. - * @param join_cb Function to invoke when a peer wants to join. - * @param master_started_cb Function to invoke after the channel master started. - * @param cls Closure for @a method and @a join_cb. + * @param master_start_cb Function to invoke after the channel master started. + * @param join_request_cb Function to invoke when a slave wants to join. + * @param message_cb Function to invoke on message parts sent to the channel + * and received from slaves + * @param cls Closure for @a method and @a join_cb. + * * @return Handle for the channel master, NULL on error. */ struct GNUNET_PSYC_Master * GNUNET_PSYC_master_start (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key, enum GNUNET_PSYC_Policy policy, + GNUNET_PSYC_MasterStartCallback master_start_cb, + GNUNET_PSYC_JoinRequestCallback join_request_cb, GNUNET_PSYC_MessageCallback message_cb, - GNUNET_PSYC_JoinCallback join_cb, - GNUNET_PSYC_MasterStartCallback master_started_cb, void *cls); @@ -580,13 +581,30 @@ struct GNUNET_PSYC_Slave; /** - * Function called after the slave joined. + * Function called after the slave connected to the PSYC service. * * @param cls Closure. * @param max_message_id Last message ID sent to the channel. */ typedef void -(*GNUNET_PSYC_SlaveJoinCallback) (void *cls, uint64_t max_message_id); +(*GNUNET_PSYC_SlaveConnectCallback) (void *cls, uint64_t max_message_id); + + +/** + * Method called to inform about the decision in response to a join request. + * + * If @a is_admitted is not #GNUNET_YES, then sending messages to the channel is + * not possible, but earlier history can be still queried. + * + * @param cls Closure. + * @param is_admitted #GNUNET_YES or #GNUNET_NO or #GNUNET_SYSERR + * @param join_msg Application-dependent join message from the origin. + */ +typedef void +(*GNUNET_PSYC_JoinDecisionCallback) (void *cls, + int is_admitted, + const struct + GNUNET_PSYC_MessageHeader *join_msg); /** @@ -599,24 +617,28 @@ typedef void * notification on failure (as the channel may simply take days to approve, * and disapproval is simply being ignored). * - * @param cfg Configuration to use. - * @param channel_key ECC public key that identifies the channel we wish to join. - * @param slave_key ECC private-public key pair that identifies the slave, and + * @param cfg Configuration to use. + * @param channel_key ECC public key that identifies the channel we wish to join. + * @param slave_key ECC private-public key pair that identifies the slave, and * used by multicast to sign the join request and subsequent unicast * requests sent to the master. - * @param origin Peer identity of the origin. - * @param relay_count Number of peers in the @a relays array. - * @param relays Peer identities of members of the multicast group, which serve + * @param origin Peer identity of the origin. + * @param relay_count Number of peers in the @a relays array. + * @param relays Peer identities of members of the multicast group, which serve * as relays and used to join the group at. - * @param message_cb Function to invoke on message parts received from the + * @param message_cb Function to invoke on message parts received from the * channel, typically at least contains method handlers for @e join and * @e part. - * @param slave_joined_cb Function invoked once we have joined the channel. - * @param cls Closure for @a message_cb and @a slave_joined_cb. - * @param method_name Method name for the join request. - * @param env Environment containing transient variables for the request, or NULL. - * @param data Payload for the join message. - * @param data_size Number of bytes in @a data. + * @param slave_connect_cb Function invoked once we have connected to the + * PSYC service. + * @param join_decision_cb Function invoked once we have received a join + * decision. + * @param cls Closure for @a message_cb and @a slave_joined_cb. + * @param method_name Method name for the join request. + * @param env Environment containing transient variables for the request, or NULL. + * @param data Payload for the join message. + * @param data_size Number of bytes in @a data. + * * @return Handle for the slave, NULL on error. */ struct GNUNET_PSYC_Slave * @@ -627,7 +649,8 @@ GNUNET_PSYC_slave_join (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t relay_count, const struct GNUNET_PeerIdentity *relays, GNUNET_PSYC_MessageCallback message_cb, - GNUNET_PSYC_SlaveJoinCallback slave_joined_cb, + GNUNET_PSYC_SlaveConnectCallback slave_connect_cb, + GNUNET_PSYC_JoinDecisionCallback join_decision_cb, void *cls, const char *method_name, const struct GNUNET_ENV_Environment *env, diff --git a/src/multicast/Makefile.am b/src/multicast/Makefile.am index b2c1702e46..8ccc7b88a6 100644 --- a/src/multicast/Makefile.am +++ b/src/multicast/Makefile.am @@ -46,10 +46,12 @@ gnunet_service_multicast_SOURCES = \ gnunet-service-multicast.c gnunet_service_multicast_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(GN_LIBINTL) gnunet_service_multicast_DEPENDENCIES = \ $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c index d412d3f8ed..5421c1b2b0 100644 --- a/src/multicast/gnunet-service-multicast.c +++ b/src/multicast/gnunet-service-multicast.c @@ -27,6 +27,7 @@ #include "gnunet_util_lib.h" #include "gnunet_signatures.h" #include "gnunet_statistics_service.h" +#include "gnunet_core_service.h" #include "gnunet_multicast_service.h" #include "multicast.h" @@ -36,6 +37,22 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; /** + * Server handle. + */ +static struct GNUNET_SERVER_Handle *server; + +/** + * Core handle. + * Only used during initialization. + */ +static struct GNUNET_CORE_Handle *core; + +/** + * Identity of this peer. + */ +static struct GNUNET_PeerIdentity this_peer; + +/** * Handle to the statistics service. */ static struct GNUNET_STATISTICS_Handle *stats; @@ -62,7 +79,6 @@ static struct GNUNET_CONTAINER_MultiHashMap *members; */ static struct GNUNET_CONTAINER_MultiHashMap *group_members; - /** * List of connected clients. */ @@ -147,7 +163,7 @@ struct Member /** * Join request sent to the origin / members. */ - struct MulticastJoinRequestMessage *join_request; + struct MulticastJoinRequestMessage *join_req; /** * Join decision sent in reply to our request. @@ -155,7 +171,7 @@ struct Member * Only a positive decision is stored here, in case of a negative decision the * client is disconnected. */ - struct MulticastJoinDecisionMessage *join_decision; + struct MulticastJoinDecisionMessageHeader *join_dcsn; /** * Last request fragment ID sent to the origin. @@ -171,9 +187,19 @@ struct Member * @param tc unused */ static void -cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - /* FIXME: do clean up here */ + if (NULL != core) + { + GNUNET_CORE_disconnect (core); + core = NULL; + } + if (NULL != stats) + { + GNUNET_STATISTICS_destroy (stats, GNUNET_YES); + stats = NULL; + } + /* FIXME: do more clean up here */ } /** @@ -206,8 +232,11 @@ cleanup_member (struct Member *mem) grp_mem); GNUNET_CONTAINER_multihashmap_destroy (grp_mem); } - if (NULL != mem->join_decision) - GNUNET_free (mem->join_decision); + if (NULL != mem->join_dcsn) + { + GNUNET_free (mem->join_dcsn); + mem->join_dcsn = NULL; + } GNUNET_CONTAINER_multihashmap_remove (members, &grp->pub_key_hash, mem); } @@ -329,7 +358,7 @@ member_message_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, const struct GNUNET_MessageHeader *msg = cls; struct Member *mem = member; - if (NULL != mem->join_decision) + if (NULL != mem->join_dcsn) { /* Only send message to admitted members */ message_to_clients (&mem->grp, msg); } @@ -374,7 +403,7 @@ message_to_origin (struct Group *grp, const struct GNUNET_MessageHeader *msg) * Handle a connecting client starting an origin. */ static void -handle_origin_start (void *cls, struct GNUNET_SERVER_Client *client, +client_origin_start (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *m) { const struct MulticastOriginStartMessage * @@ -424,8 +453,8 @@ handle_origin_start (void *cls, struct GNUNET_SERVER_Client *client, * Handle a connecting client joining a group. */ static void -handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *m) +client_member_join (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *m) { const struct MulticastMemberJoinMessage * msg = (const struct MulticastMemberJoinMessage *) m; @@ -487,16 +516,16 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_client_set_user_context (client, grp); - if (NULL != mem->join_decision) + if (NULL != mem->join_dcsn) { /* Already got a join decision, send it to client. */ GNUNET_SERVER_notification_context_add (nc, client); GNUNET_SERVER_notification_context_unicast (nc, client, (struct GNUNET_MessageHeader *) - mem->join_decision, + mem->join_dcsn, GNUNET_NO); } else if (grp->clients_head == grp->clients_tail) - { /* First client, send join request. */ + { /* First client of the group, send join request. */ struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1]; uint32_t relay_count = ntohs (msg->relay_count); uint16_t relay_size = relay_count * sizeof (*relays); @@ -515,6 +544,7 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, req->header.size = htons (sizeof (*req) + join_msg_size); req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST); req->group_key = grp->pub_key; + req->member_peer = this_peer; GNUNET_CRYPTO_eddsa_key_get_public (&mem->priv_key, &req->member_key); if (0 < join_msg_size) memcpy (&req[1], join_msg, join_msg_size); @@ -531,14 +561,14 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_assert (0); } - if (NULL != mem->join_request) - GNUNET_free (mem->join_request); - mem->join_request = req; + if (NULL != mem->join_req) + GNUNET_free (mem->join_req); + mem->join_req = req; if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (origins, &grp->pub_key_hash)) { /* Local origin */ - message_to_origin (grp, (struct GNUNET_MessageHeader *) mem->join_request); + message_to_origin (grp, (struct GNUNET_MessageHeader *) mem->join_req); } else { @@ -553,34 +583,15 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, * Join decision from client. */ static void -handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client, +client_join_decision (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *m) { struct Group * grp = GNUNET_SERVER_client_get_user_context (client, struct Group); - const struct MulticastClientJoinDecisionMessage * - cl_dcsn = (const struct MulticastClientJoinDecisionMessage *) m; - - struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &cl_dcsn[1]; - uint32_t relay_count = ntohs (cl_dcsn->relay_count); - uint16_t relay_size = relay_count * sizeof (*relays); - - struct GNUNET_MessageHeader *join_msg = NULL; - uint16_t join_msg_size = 0; - if (sizeof (*cl_dcsn) + relay_size + sizeof (*m) <= ntohs (m->size)) - { - join_msg = (struct GNUNET_MessageHeader *) - (((char *) &cl_dcsn[1]) + relay_size); - join_msg_size = ntohs (join_msg->size); - } - - int keep_dcsn = GNUNET_NO; - struct MulticastJoinDecisionMessage * - dcsn = GNUNET_malloc (sizeof (*dcsn) + join_msg_size); - dcsn->header.size = htons (sizeof (*dcsn) + join_msg_size); - dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION); - dcsn->is_admitted = cl_dcsn->is_admitted; - memcpy (&dcsn[1], join_msg, join_msg_size); + const struct MulticastJoinDecisionMessageHeader * + hdcsn = (const struct MulticastJoinDecisionMessageHeader *) m; + const struct MulticastJoinDecisionMessage * + dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%p Got join decision from client for group %s..\n", @@ -595,7 +606,7 @@ handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client, if (NULL != grp_mem) { struct GNUNET_HashCode member_key_hash; - GNUNET_CRYPTO_hash (&cl_dcsn->member_key, sizeof (cl_dcsn->member_key), + GNUNET_CRYPTO_hash (&hdcsn->member_key, sizeof (hdcsn->member_key), &member_key_hash); struct Member * mem = GNUNET_CONTAINER_multihashmap_get (grp_mem, &member_key_hash); @@ -604,19 +615,21 @@ handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client, grp, GNUNET_h2s (&member_key_hash), mem); if (NULL != mem) { - message_to_clients (grp, (struct GNUNET_MessageHeader *) dcsn); - if (GNUNET_YES == dcsn->is_admitted) + message_to_clients (&mem->grp, (struct GNUNET_MessageHeader *) hdcsn); + if (GNUNET_YES == ntohl (dcsn->is_admitted)) { /* Member admitted, store join_decision. */ - mem->join_decision = dcsn; - keep_dcsn = GNUNET_YES; + uint16_t dcsn_size = ntohs (dcsn->header.size); + mem->join_dcsn = GNUNET_malloc (dcsn_size); + memcpy (mem->join_dcsn, dcsn, dcsn_size); } else { /* Refused entry, disconnect clients. */ struct ClientList *cl = mem->grp.clients_head; while (NULL != cl) { - GNUNET_SERVER_client_disconnect (cl->client); + struct GNUNET_SERVER_Client *client = cl->client; cl = cl->next; + GNUNET_SERVER_client_disconnect (client); } } } @@ -624,10 +637,8 @@ handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client, } else { - /* FIXME: send join decision to remote peers */ + /* FIXME: send join decision to hdcsn->peer */ } - if (GNUNET_NO == keep_dcsn) - GNUNET_free (dcsn); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -635,7 +646,7 @@ handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client, * Incoming message from a client. */ static void -handle_multicast_message (void *cls, struct GNUNET_SERVER_Client *client, +client_multicast_message (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *m) { struct Group * @@ -670,7 +681,7 @@ handle_multicast_message (void *cls, struct GNUNET_SERVER_Client *client, * Incoming request from a client. */ static void -handle_multicast_request (void *cls, struct GNUNET_SERVER_Client *client, +client_multicast_request (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *m) { struct Group * @@ -708,37 +719,34 @@ handle_multicast_request (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_OK); } + /** - * Process multicast requests. - * - * @param cls closure - * @param server the initialized server - * @param cfg configuration to use + * Core connected. */ static void -run (void *cls, struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *c) +core_connected_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) { + this_peer = *my_identity; + static const struct GNUNET_SERVER_MessageHandler handlers[] = { - { &handle_origin_start, NULL, + { &client_origin_start, NULL, GNUNET_MESSAGE_TYPE_MULTICAST_ORIGIN_START, 0 }, - { &handle_member_join, NULL, + { &client_member_join, NULL, GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN, 0 }, - { &handle_join_decision, NULL, + { &client_join_decision, NULL, GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 0 }, - { &handle_multicast_message, NULL, + { &client_multicast_message, NULL, GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 0 }, - { &handle_multicast_request, NULL, + { &client_multicast_request, NULL, GNUNET_MESSAGE_TYPE_MULTICAST_REQUEST, 0 }, {NULL, NULL, 0, 0} }; - cfg = c; stats = GNUNET_STATISTICS_create ("multicast", cfg); origins = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); members = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); @@ -747,12 +755,30 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); } /** + * Service started. + * + * @param cls closure + * @param server the initialized server + * @param cfg configuration to use + */ +static void +run (void *cls, struct GNUNET_SERVER_Handle *srv, + const struct GNUNET_CONFIGURATION_Handle *c) +{ + cfg = c; + server = srv; + core = GNUNET_CORE_connect (cfg, NULL, core_connected_cb, NULL, NULL, + NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); +} + + +/** * The main function for the multicast service. * * @param argc number of arguments from the command line diff --git a/src/multicast/multicast.h b/src/multicast/multicast.h index 85c5714e6e..76492e868e 100644 --- a/src/multicast/multicast.h +++ b/src/multicast/multicast.h @@ -77,7 +77,7 @@ struct MulticastJoinRequestMessage /** - * Header of a join decision sent to a remote peer. + * Header of a join decision message sent to a peer requesting join. */ struct MulticastJoinDecisionMessage { @@ -87,19 +87,28 @@ struct MulticastJoinDecisionMessage struct GNUNET_MessageHeader header; /** - * #GNUNET_YES if the peer was admitted. + * #GNUNET_YES if the peer was admitted + * #GNUNET_NO if entry was refused, + * #GNUNET_SYSERR if the request could not be answered. */ - uint8_t is_admitted; + int32_t is_admitted; + + /** + * Number of relays given. + */ + uint32_t relay_count; + + /* Followed by relay_count peer identities */ /* Followed by the join response message */ }; /** - * Message sent from the client to the service to notify the service - * about a join decision. + * Header added to a struct MulticastJoinDecisionMessage + * when sent between the client and service. */ -struct MulticastClientJoinDecisionMessage +struct MulticastJoinDecisionMessageHeader { /** * Type: GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION @@ -107,29 +116,18 @@ struct MulticastClientJoinDecisionMessage struct GNUNET_MessageHeader header; /** - * Number of relays given. + * C->S: Peer to send the join decision to. + * S->C: Peer we received the join decision from. */ - uint32_t relay_count; + struct GNUNET_PeerIdentity peer; /** - * Public key of the joining member. + * C->S: Public key of the member requesting join. + * S->C: Unused. */ struct GNUNET_CRYPTO_EddsaPublicKey member_key; - /** - * Peer identity of the joining member. - */ - struct GNUNET_PeerIdentity member_peer; - - /** - * #GNUNET_YES if the peer was admitted. - */ - uint8_t is_admitted; - - /* Followed by relay_count peer identities */ - - /* Followed by the join response message */ - + /* Followed by struct MulticastJoinDecisionMessage */ }; @@ -139,7 +137,6 @@ struct MulticastClientJoinDecisionMessage */ struct MulticastMembershipTestResultMessage { - /** * Type: GNUNET_MESSAGE_TYPE_MULTICAST_MEMBERSHIP_TEST_RESULT */ @@ -151,11 +148,11 @@ struct MulticastMembershipTestResultMessage uint32_t uid; /** - * #GNUNET_YES if the peer is a member, #GNUNET_NO if peer was not a member, - * #GNUNET_SYSERR if we cannot answer the test. + * #GNUNET_YES if the peer is a member + * #GNUNET_NO if peer is not a member, + * #GNUNET_SYSERR if the test could not be answered. */ int32_t is_admitted; - }; diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c index 501ff4b701..e568e77ee1 100644 --- a/src/multicast/multicast_api.c +++ b/src/multicast/multicast_api.c @@ -132,7 +132,7 @@ struct GNUNET_MULTICAST_Group struct GNUNET_CRYPTO_EddsaPublicKey pub_key; struct GNUNET_HashCode pub_key_hash; - GNUNET_MULTICAST_JoinCallback join_cb; + GNUNET_MULTICAST_JoinRequestCallback join_req_cb; GNUNET_MULTICAST_MembershipTestCallback member_test_cb; GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb; GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb; @@ -177,10 +177,7 @@ struct GNUNET_MULTICAST_Member struct GNUNET_MULTICAST_Group grp; struct GNUNET_MULTICAST_MemberTransmitHandle tmit; - struct GNUNET_CRYPTO_EddsaPrivateKey priv_key; - struct GNUNET_PeerIdentity origin; - struct GNUNET_PeerIdentity relays; - uint32_t relay_count; + GNUNET_MULTICAST_JoinDecisionCallback join_dcsn_cb; uint64_t next_fragment_id; }; @@ -197,12 +194,12 @@ struct GNUNET_MULTICAST_JoinHandle struct GNUNET_MULTICAST_Group *group; /** - * Public key of the joining member. + * Public key of the member requesting join. */ struct GNUNET_CRYPTO_EddsaPublicKey member_key; /** - * Peer identity of the joining member. + * Peer identity of the member requesting join. */ struct GNUNET_PeerIdentity member_peer; }; @@ -476,8 +473,9 @@ request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, void *origin) "Calling request callback for a request of type %u and size %u.\n", ntohs (req->header.type), ntohs (req->header.size)); - orig->request_cb (orig->grp.cb_cls, &req->member_key, - (const struct GNUNET_MessageHeader *) req, 0); + if (NULL != orig->request_cb) + orig->request_cb (orig->grp.cb_cls, &req->member_key, + (const struct GNUNET_MessageHeader *) req, 0); return |