aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-26 18:53:28 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-26 18:53:28 +0000
commit60ff113fe4e7bb71d5696063b9a9b81eba60a108 (patch)
tree8f3ed8cc47be49299a01d8ce1385f012bf19043b /src/dht/gnunet-service-dht.c
parent808e4a55f8ac3516a766873502b9bb020ef3d066 (diff)
downloadgnunet-60ff113fe4e7bb71d5696063b9a9b81eba60a108.tar.gz
gnunet-60ff113fe4e7bb71d5696063b9a9b81eba60a108.zip
refactor DHT for new service API
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c61
1 files changed, 25 insertions, 36 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 1e3dd339d..a2ba2e8b0 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -33,7 +33,6 @@
33#include "gnunet_dht_service.h" 33#include "gnunet_dht_service.h"
34#include "gnunet_statistics_service.h" 34#include "gnunet_statistics_service.h"
35#include "gnunet-service-dht.h" 35#include "gnunet-service-dht.h"
36#include "gnunet-service-dht_clients.h"
37#include "gnunet-service-dht_datacache.h" 36#include "gnunet-service-dht_datacache.h"
38#include "gnunet-service-dht_hello.h" 37#include "gnunet-service-dht_hello.h"
39#include "gnunet-service-dht_neighbours.h" 38#include "gnunet-service-dht_neighbours.h"
@@ -47,6 +46,11 @@
47struct GNUNET_STATISTICS_Handle *GDS_stats; 46struct GNUNET_STATISTICS_Handle *GDS_stats;
48 47
49/** 48/**
49 * Handle for the service.
50 */
51struct GNUNET_SERVICE_Handle *GDS_service;
52
53/**
50 * Our handle to the BLOCK library. 54 * Our handle to the BLOCK library.
51 */ 55 */
52struct GNUNET_BLOCK_Context *GDS_block_context; 56struct GNUNET_BLOCK_Context *GDS_block_context;
@@ -57,11 +61,6 @@ struct GNUNET_BLOCK_Context *GDS_block_context;
57const struct GNUNET_CONFIGURATION_Handle *GDS_cfg; 61const struct GNUNET_CONFIGURATION_Handle *GDS_cfg;
58 62
59/** 63/**
60 * Handle to our server.
61 */
62struct GNUNET_SERVER_Handle *GDS_server;
63
64/**
65 * Our HELLO 64 * Our HELLO
66 */ 65 */
67struct GNUNET_MessageHeader *GDS_my_hello; 66struct GNUNET_MessageHeader *GDS_my_hello;
@@ -77,6 +76,10 @@ static struct GNUNET_TRANSPORT_HelloGetHandle *ghh;
77struct GNUNET_TIME_Relative hello_expiration; 76struct GNUNET_TIME_Relative hello_expiration;
78 77
79 78
79/* Code shared between different DHT implementations */
80#include "gnunet-service-dht_clients.c"
81
82
80/** 83/**
81 * Receive the HELLO from transport service, free current and replace 84 * Receive the HELLO from transport service, free current and replace
82 * if necessary. 85 * if necessary.
@@ -90,7 +93,9 @@ process_hello (void *cls,
90{ 93{
91 GNUNET_free_non_null (GDS_my_hello); 94 GNUNET_free_non_null (GDS_my_hello);
92 GDS_my_hello = GNUNET_malloc (ntohs (message->size)); 95 GDS_my_hello = GNUNET_malloc (ntohs (message->size));
93 GNUNET_memcpy (GDS_my_hello, message, ntohs (message->size)); 96 GNUNET_memcpy (GDS_my_hello,
97 message,
98 ntohs (message->size));
94} 99}
95 100
96 101
@@ -133,17 +138,16 @@ shutdown_task (void *cls)
133 * Process dht requests. 138 * Process dht requests.
134 * 139 *
135 * @param cls closure 140 * @param cls closure
136 * @param server the initialized server
137 * @param c configuration to use 141 * @param c configuration to use
142 * @param service the initialized service
138 */ 143 */
139static void 144static void
140run (void *cls, 145run (void *cls,
141 struct GNUNET_SERVER_Handle *server, 146 const struct GNUNET_CONFIGURATION_Handle *c,
142 const struct GNUNET_CONFIGURATION_Handle *c) 147 struct GNUNET_SERVICE_Handle *service)
143{ 148{
144 GDS_cfg = c; 149 GDS_cfg = c;
145 GDS_server = server; 150 GDS_service = service;
146 GNUNET_SERVER_suspend (server);
147 if (GNUNET_OK != 151 if (GNUNET_OK !=
148 GNUNET_CONFIGURATION_get_value_time (c, 152 GNUNET_CONFIGURATION_get_value_time (c,
149 "transport", 153 "transport",
@@ -153,7 +157,10 @@ run (void *cls,
153 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; 157 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
154 } 158 }
155 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg); 159 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg);
156 GDS_stats = GNUNET_STATISTICS_create ("dht", GDS_cfg); 160 GDS_stats = GNUNET_STATISTICS_create ("dht",
161 GDS_cfg);
162 GNUNET_SERVICE_suspend (GDS_service);
163 GDS_CLIENTS_init ();
157 GDS_ROUTING_init (); 164 GDS_ROUTING_init ();
158 GDS_NSE_init (); 165 GDS_NSE_init ();
159 GDS_DATACACHE_init (); 166 GDS_DATACACHE_init ();
@@ -172,28 +179,10 @@ run (void *cls,
172} 179}
173 180
174 181
175/** 182/* Finally, define the main method */
176 * The main function for the dht service. 183GDS_DHT_SERVICE_INIT(&run);
177 * 184
178 * @param argc number of arguments from the command line 185
179 * @param argv command line arguments 186
180 * @return 0 ok, 1 on error
181 */
182int
183main (int argc,
184 char *const *argv)
185{
186 int ret;
187
188 ret = (GNUNET_OK ==
189 GNUNET_SERVICE_run (argc,
190 argv,
191 "dht",
192 GNUNET_SERVICE_OPTION_NONE,
193 &run,
194 NULL)) ? 0 : 1;
195 GDS_CLIENTS_done ();
196 return ret;
197}
198 187
199/* end of gnunet-service-dht.c */ 188/* end of gnunet-service-dht.c */