aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-25 03:35:18 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-25 03:35:18 +0100
commit50c57e0ffa957a9d3773844de9851ab2aadbbc82 (patch)
treef5a8e1dd32a81eed282583d332ff33056a0eea95 /src
parent0c1559b66e66be7c9536eb1bc6c850eb3c006377 (diff)
downloadgnunet-ext-50c57e0ffa957a9d3773844de9851ab2aadbbc82.tar.gz
gnunet-ext-50c57e0ffa957a9d3773844de9851ab2aadbbc82.zip
updating gnunet-ext to current standards
Diffstat (limited to 'src')
-rw-r--r--src/.gitignore2
-rw-r--r--src/ext/.gitignore5
-rw-r--r--src/ext/Makefile.am17
-rw-r--r--src/ext/ext.conf.in5
-rw-r--r--src/ext/ext_api.c4
-rw-r--r--src/ext/gnunet-ext.c5
-rw-r--r--src/ext/gnunet-service-ext.c135
-rw-r--r--src/include/.gitignore2
8 files changed, 117 insertions, 58 deletions
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..282522d
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,2 @@
1Makefile
2Makefile.in
diff --git a/src/ext/.gitignore b/src/ext/.gitignore
new file mode 100644
index 0000000..0694e74
--- /dev/null
+++ b/src/ext/.gitignore
@@ -0,0 +1,5 @@
1.deps/
2.libs/
3ext.conf
4gnunet-ext
5gnunet-service-ext
diff --git a/src/ext/Makefile.am b/src/ext/Makefile.am
index 977c3d2..b5c04e7 100644
--- a/src/ext/Makefile.am
+++ b/src/ext/Makefile.am
@@ -22,7 +22,7 @@ pkgcfgdir= $(prefix)/share/gnunet/config.d/
22libexecdir= $(prefix)/lib/gnunet/libexec/ 22libexecdir= $(prefix)/lib/gnunet/libexec/
23 23
24libgnunetext_la_SOURCES = \ 24libgnunetext_la_SOURCES = \
25 ext_api.c 25 ext_api.c
26libgnunetext_la_LIBADD = \ 26libgnunetext_la_LIBADD = \
27 -lgnunetutil 27 -lgnunetutil
28libgnunetext_la_LDFLAGS = \ 28libgnunetext_la_LDFLAGS = \
@@ -35,7 +35,7 @@ bin_PROGRAMS = gnunet-ext
35libexec_PROGRAMS = gnunet-service-ext 35libexec_PROGRAMS = gnunet-service-ext
36 36
37check_PROGRAMS = \ 37check_PROGRAMS = \
38 test_ext_api 38 test_ext_api
39 39
40TESTS = $(check_PROGRAMS) 40TESTS = $(check_PROGRAMS)
41 41
@@ -43,17 +43,17 @@ gnunet_service_ext_SOURCES = \
43 gnunet-service-ext.c 43 gnunet-service-ext.c
44gnunet_service_ext_LDADD = \ 44gnunet_service_ext_LDADD = \
45 -lgnunetutil -lgnunetcore -lgnunetdht\ 45 -lgnunetutil -lgnunetcore -lgnunetdht\
46 $(INTLLIBS) 46 $(INTLLIBS)
47gnunet_service_ext_LDFLAGS = \ 47gnunet_service_ext_LDFLAGS = \
48 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic 48 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic
49 49
50gnunet_ext_SOURCES = \ 50gnunet_ext_SOURCES = \
51 gnunet-ext.c 51 gnunet-ext.c
52gnunet_ext_LDADD = \ 52gnunet_ext_LDADD = \
53 -lgnunetutil \ 53 -lgnunetutil \
54 $(INTLLIBS) 54 $(INTLLIBS)
55gnunet_ext_LDFLAGS = \ 55gnunet_ext_LDFLAGS = \
56 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic 56 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic
57 57
58 58
59 59
@@ -64,6 +64,5 @@ test_ext_api_LDADD = \
64 -lgnunetutil 64 -lgnunetutil
65test_ext_api_LDFLAGS = \ 65test_ext_api_LDFLAGS = \
66 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic 66 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic
67 67
68 pkgcfg_DATA = ext.conf 68pkgcfg_DATA = ext.conf
69 \ No newline at end of file
diff --git a/src/ext/ext.conf.in b/src/ext/ext.conf.in
index 586e1f1..01a6f54 100644
--- a/src/ext/ext.conf.in
+++ b/src/ext/ext.conf.in
@@ -2,6 +2,5 @@
2BINARY = gnunet-service-ext 2BINARY = gnunet-service-ext
3UNIXPATH = /tmp/gnunet-service-ext.sock 3UNIXPATH = /tmp/gnunet-service-ext.sock
4HOME = $SERVICEHOME 4HOME = $SERVICEHOME
5# PORT = 2106 5# PORT = 2500
6@UNIXONLY@ PORT = 2087 6@UNIXONLY@ PORT = 2500
7
diff --git a/src/ext/ext_api.c b/src/ext/ext_api.c
index f4fe779..65637d5 100644
--- a/src/ext/ext_api.c
+++ b/src/ext/ext_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 3 Copyright (C) 20xx GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,7 +21,7 @@
21/** 21/**
22 * @file ext/ext_api.c 22 * @file ext/ext_api.c
23 * @brief API for ext 23 * @brief API for ext
24 * @author 24 * @author
25 */ 25 */
26#include <gnunet/platform.h> 26#include <gnunet/platform.h>
27#include <gnunet/gnunet_util_lib.h> 27#include <gnunet/gnunet_util_lib.h>
diff --git a/src/ext/gnunet-ext.c b/src/ext/gnunet-ext.c
index 51c7f80..36fc02b 100644
--- a/src/ext/gnunet-ext.c
+++ b/src/ext/gnunet-ext.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 3 Copyright (C) 20xx GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,7 +21,7 @@
21/** 21/**
22 * @file ext/gnunet-ext.c 22 * @file ext/gnunet-ext.c
23 * @brief ext tool 23 * @brief ext tool
24 * @author 24 * @author
25 */ 25 */
26#include <gnunet/platform.h> 26#include <gnunet/platform.h>
27#include <gnunet/gnunet_util_lib.h> 27#include <gnunet/gnunet_util_lib.h>
@@ -46,6 +46,7 @@ run (void *cls,
46 ret = 0; 46 ret = 0;
47} 47}
48 48
49
49/** 50/**
50 * The main function to ext. 51 * The main function to ext.
51 * 52 *
diff --git a/src/ext/gnunet-service-ext.c b/src/ext/gnunet-service-ext.c
index 7876047..d292eac 100644
--- a/src/ext/gnunet-service-ext.c
+++ b/src/ext/gnunet-service-ext.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 3 Copyright (C) 20xx GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -28,24 +28,55 @@
28#include "gnunet_protocols_ext.h" 28#include "gnunet_protocols_ext.h"
29 29
30/** 30/**
31 * Some state we track per client.
32 */
33struct ClientContext
34{
35 /**
36 * For telling service to continue processing more messages.
37 */
38 struct GNUNET_SERVICE_Client *c;
39
40 /**
41 * For sending messages to the client.
42 */
43 struct GNUNET_MQ_Handle *mq;
44
45 /**
46 * Sample state.
47 */
48 uint32_t state;
49};
50
51
52/**
31 * Our configuration. 53 * Our configuration.
32 */ 54 */
33static const struct GNUNET_CONFIGURATION_Handle *cfg; 55static const struct GNUNET_CONFIGURATION_Handle *cfg;
34 56
57
35/** 58/**
36 * Handle EXT-message. 59 * Handle EXT-message.
37 * 60 *
38 * @param cls closure 61 * @param cls identification of the client
39 * @param client identification of the client
40 * @param message the actual message 62 * @param message the actual message
41 */ 63 */
42static void 64static void
43handle_ext (void *cls, 65handle_ext (void *cls,
44 struct GNUNET_SERVER_Client *client,
45 const struct GNUNET_MessageHeader *message) 66 const struct GNUNET_MessageHeader *message)
46{ 67{
47 GNUNET_SERVER_receive_done (client, 68 struct ClientContext *cc = cls;
48 GNUNET_OK); 69 struct GNUNET_MQ_Envelope *env;
70 struct GNUNET_MessageHeader *response;
71
72 /* Send same type of message back... */
73 env = GNUNET_MQ_msg (response,
74 GNUNET_MESSAGE_TYPE_EXT);
75 GNUNET_MQ_send (cc->mq,
76 env);
77
78 /* Continue processing more messages from client */
79 GNUNET_SERVICE_client_continue (cc->c);
49} 80}
50 81
51 82
@@ -57,19 +88,7 @@ handle_ext (void *cls,
57static void 88static void
58shutdown_task (void *cls) 89shutdown_task (void *cls)
59{ 90{
60} 91 /* Clean up whatever #run() setup here. */
61
62
63/**
64 * A client disconnected. Remove all of its data structure entries.
65 *
66 * @param cls closure, NULL
67 * @param client identification of the client
68 */
69static void
70handle_client_disconnect (void *cls,
71 struct GNUNET_SERVER_Client * client)
72{
73} 92}
74 93
75 94
@@ -85,37 +104,69 @@ run (void *cls,
85 struct GNUNET_SERVER_Handle *server, 104 struct GNUNET_SERVER_Handle *server,
86 const struct GNUNET_CONFIGURATION_Handle *c) 105 const struct GNUNET_CONFIGURATION_Handle *c)
87{ 106{
88 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
89 {&handle_ext, NULL, GNUNET_MESSAGE_TYPE_EXT, 0},
90 {NULL, NULL, 0, 0}
91 };
92 cfg = c; 107 cfg = c;
93 GNUNET_SERVER_add_handlers (server, handlers); 108 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
94 GNUNET_SERVER_disconnect_notify (server, 109 NULL);
95 &handle_client_disconnect, 110}
96 NULL); 111
97 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 112
98 &shutdown_task, 113/**
99 NULL); 114 * Callback called when a client connects to the service.
115 *
116 * @param cls closure for the service
117 * @param c the new client that connected to the service
118 * @param mq the message queue used to send messages to the client
119 * @return @a c
120 */
121static void *
122client_connect_cb (void *cls,
123 struct GNUNET_SERVICE_Client *c,
124 struct GNUNET_MQ_Handle *mq)
125{
126 struct ClientContext *cc;
127
128 cc = GNUNET_new (struct ClientContext);
129 cc->c = c;
130 cc->mq = mq;
131 /* setup more for new client here */
132 return cc;
100} 133}
101 134
102 135
103/** 136/**
104 * The main function for the ext service. 137 * Callback called when a client disconnected from the service
105 * 138 *
106 * @param argc number of arguments from the command line 139 * @param cls closure for the service
107 * @param argv command line arguments 140 * @param c the client that disconnected
108 * @return 0 ok, 1 on error 141 * @param internal_cls our `struct ClientContext`
109 */ 142 */
110int 143static void
111main (int argc, char *const *argv) 144client_disconnect_cb (void *cls,
145 struct GNUNET_SERVICE_Client *c,
146 void *internal_cls)
112{ 147{
113 return (GNUNET_OK == 148 struct ClientContext *cc = internal_cls;
114 GNUNET_SERVICE_run (argc, 149
115 argv, 150 GNUNET_assert (cc->c == c);
116 "ext", 151 /* Tear down rest of client here */
117 GNUNET_SERVICE_OPTION_NONE, 152 GNUNET_free (cc);
118 &run, NULL)) ? 0 : 1;
119} 153}
120 154
155
156/**
157 * Define "main" method using service macro.
158 */
159GNUNET_SERVICE_MAIN
160("ext",
161 GNUNET_SERVICE_OPTION_NONE,
162 &run,
163 &client_connect_cb,
164 &client_disconnect_cb,
165 NULL,
166 GNUNET_MQ_hd_fixed_size (ext,
167 GNUNET_MESSAGE_TYPE_EXT,
168 struct GNUNET_MessageHeader,
169 NULL),
170 GNUNET_MQ_handler_end ());
171
121/* end of gnunet-service-ext.c */ 172/* end of gnunet-service-ext.c */
diff --git a/src/include/.gitignore b/src/include/.gitignore
new file mode 100644
index 0000000..282522d
--- /dev/null
+++ b/src/include/.gitignore
@@ -0,0 +1,2 @@
1Makefile
2Makefile.in