From cf4608196bc02093409dbf6b7a24e6ed08c36f76 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Wed, 27 May 2020 15:01:30 +0200 Subject: Make REQUEST_AGPL messages configurable and add handler by default This makes two changes: * Add a field to `struct GNUNET_OS_ProjectData' containing a URL (as a string) pointing to the source code of the application. * If the field is not NULL, add a handler for the REQUEST_AGPL messages sending the specified URL to the client. The handler is added both in client-service communications (i.e. local services that don't make requests to other peers in the network) and in peer-peer communications (CADET.) This way, any client (local or remote with CADET) can request the source code location using a standardized mechanism instead of writing ad-hoc solutions (unless the service/peer explicitly specifies a NULL pointer.) Signed-off-by: Christian Grothoff --- src/cadet/cadet_api.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/cadet') diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 68bd4c290..3a75266b7 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c @@ -994,6 +994,32 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) } +/** + * Function to return link to AGPL source upon request. + * + * @param cls closure with the identification of the client + * @param msg AGPL request + */ +static void +return_agpl (void *cls, const struct GNUNET_MessageHeader *msg) +{ + struct GNUNET_SERVICE_Client *client = cls; + struct GNUNET_MQ_Handle *mq; + struct GNUNET_MQ_Envelope *env; + struct GNUNET_MessageHeader *res; + size_t slen; + const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); + + (void) msg; + slen = strlen (pd->agpl_url) + 1; + env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen); + memcpy (&res[1], GNUNET_AGPL_URL, slen); + mq = GNUNET_SERVICE_client_get_mq (client); + GNUNET_MQ_send (mq, env); + GNUNET_SERVICE_client_continue (client); +} + + /** * Open a port to receive incomming MQ-based channels. * @@ -1016,6 +1042,7 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, const struct GNUNET_MQ_MessageHandler *handlers) { struct GNUNET_CADET_Port *p; + const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); GNUNET_assert (NULL != connects); GNUNET_assert (NULL != disconnects); @@ -1039,7 +1066,9 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, p->cls = connects_cls; p->window_changes = window_changes; p->disconnects = disconnects; - p->handlers = GNUNET_MQ_copy_handlers (handlers); + p->handlers = (NULL == pd->agpl_url) + ? GNUNET_MQ_copy_handlers (handlers) + : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL); GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p)); return p; -- cgit v1.2.3