summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Vanni <vannilla@firemail.cc>2020-05-27 15:01:30 +0200
committerChristian Grothoff <christian@grothoff.org>2020-05-27 22:37:08 +0200
commitcf4608196bc02093409dbf6b7a24e6ed08c36f76 (patch)
tree46c2ecc852810e35d9d5eabcfcb52620e06aaa3f
parent3a966c83d32db67d0e9cb23675f28b7233280aeb (diff)
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 <christian@grothoff.org>
-rw-r--r--src/cadet/cadet_api.c31
-rw-r--r--src/include/gnunet_os_lib.h8
-rw-r--r--src/include/gnunet_protocols.h30
-rw-r--r--src/util/os_installation.c1
-rw-r--r--src/util/service.c7
5 files changed, 61 insertions, 16 deletions
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
@@ -995,6 +995,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.
*
* @param h CADET handle.
@@ -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;
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index a6188c1ca..b583cc493 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -287,6 +287,14 @@ struct GNUNET_OS_ProjectData
* If this field is NULL, the path is automatically inferred.
*/
char *gettext_path;
+
+ /**
+ * URL pointing to the source code of the application. Required for AGPL.
+ * Setting this to NULL disables the built-in mechanism, but you must
+ * provide it in some other way. If non-NULL, message type 1 and 2 are
+ * reserved.
+ */
+ char *agpl_url;
};
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 3b05fb8bb..282bb53d1 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -50,25 +50,29 @@ extern "C" {
#endif
/*******************************************************************************
- * UTIL message types
- ******************************************************************************/
+* Deprecated
+* *****************************************************************************/
/**
* Test if service is online.
*
* @deprecated!
*/
-#define GNUNET_MESSAGE_TYPE_TEST 1
+#define GNUNET_MESSAGE_TYPE_TEST 0
+
+/*******************************************************************************
+* AGPL source code download
+* *****************************************************************************/
/**
- * Dummy messages for testing / benchmarking.
+ * Message to request source code link.
*/
-#define GNUNET_MESSAGE_TYPE_DUMMY 2
+#define GNUNET_MESSAGE_TYPE_REQUEST_AGPL 1
/**
- * Another dummy messages for testing / benchmarking.
+ * Source code link.
*/
-#define GNUNET_MESSAGE_TYPE_DUMMY2 3
+#define GNUNET_MESSAGE_TYPE_RESPONSE_AGPL 2
/*******************************************************************************
* RESOLVER message types
@@ -85,18 +89,18 @@ extern "C" {
#define GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE 5
/*******************************************************************************
-* AGPL source code download
-* *****************************************************************************/
+ * UTIL message types
+ ******************************************************************************/
/**
- * Message to request source code link.
+ * Dummy messages for testing / benchmarking.
*/
-#define GNUNET_MESSAGE_TYPE_REQUEST_AGPL 6
+#define GNUNET_MESSAGE_TYPE_DUMMY 6
/**
- * Source code link.
+ * Another dummy messages for testing / benchmarking.
*/
-#define GNUNET_MESSAGE_TYPE_RESPONSE_AGPL 7
+#define GNUNET_MESSAGE_TYPE_DUMMY2 7
/*******************************************************************************
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index dcd31dc2c..714df6957 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -70,6 +70,7 @@ static const struct GNUNET_OS_ProjectData default_pd = {
.is_gnu = 1,
.gettext_domain = PACKAGE,
.gettext_path = NULL,
+ .agpl_url = GNUNET_AGPL_URL,
};
/**
diff --git a/src/util/service.c b/src/util/service.c
index 9dc14eba9..ea078b19b 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1823,9 +1823,10 @@ return_agpl (void *cls, const struct GNUNET_MessageHeader *msg)
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 (GNUNET_AGPL_URL) + 1;
+ 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);
@@ -2019,7 +2020,9 @@ GNUNET_SERVICE_run_ (int argc,
sh.connect_cb = connect_cb;
sh.disconnect_cb = disconnect_cb;
sh.cb_cls = cls;
- sh.handlers = GNUNET_MQ_copy_handlers (handlers);
+ sh.handlers = (NULL == pd->agpl_url)
+ ? GNUNET_MQ_copy_handlers (handlers)
+ : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
sh.service_name = service_name;
sh.ret = 0;
/* setup subsystems */