aboutsummaryrefslogtreecommitdiff
path: root/src/dv/gnunet-service-dv.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-03-11 12:45:52 +0000
committerNathan S. Evans <evans@in.tum.de>2010-03-11 12:45:52 +0000
commit9c923d1ef6752f40535124439fed299ee4150795 (patch)
treee912eb27f4d0c0a94e55a7bb61d52b82af09dc38 /src/dv/gnunet-service-dv.c
parent566fa39ac965c18fe9392ec607cbed99f0860eb9 (diff)
downloadgnunet-9c923d1ef6752f40535124439fed299ee4150795.tar.gz
gnunet-9c923d1ef6752f40535124439fed299ee4150795.zip
dv config files and fixes
Diffstat (limited to 'src/dv/gnunet-service-dv.c')
-rw-r--r--src/dv/gnunet-service-dv.c82
1 files changed, 61 insertions, 21 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 92f5c96aa..3c483746e 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -41,13 +41,33 @@
41/** 41/**
42 * DV Service Context stuff goes here... 42 * DV Service Context stuff goes here...
43 */ 43 */
44
45/**
46 * Handle to the core service api.
47 */
44static struct GNUNET_CORE_Handle *coreAPI; 48static struct GNUNET_CORE_Handle *coreAPI;
45 49
50/**
51 * The identity of our peer.
52 */
46static struct GNUNET_PeerIdentity *my_identity; 53static struct GNUNET_PeerIdentity *my_identity;
47 54
55/**
56 * The configuration for this service.
57 */
48const struct GNUNET_CONFIGURATION_Handle *cfg; 58const struct GNUNET_CONFIGURATION_Handle *cfg;
49 59
50struct GNUNET_SCHEDULER_Handle *sched; 60/**
61 * The scheduler for this service.
62 */
63static struct GNUNET_SCHEDULER_Handle *sched;
64
65/**
66 * The client, should be the DV plugin connected to us. Hopefully
67 * this client will never change, although if the plugin dies
68 * and returns for some reason it may happen.
69 */
70static struct GNUNET_SERVER_Client * client_handle;
51 71
52GNUNET_SCHEDULER_TaskIdentifier cleanup_task; 72GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
53 73
@@ -61,17 +81,20 @@ GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
61 * @param client identification of the client 81 * @param client identification of the client
62 * @param message the actual message 82 * @param message the actual message
63 */ 83 */
64void handle_dv_data_message (void *cls, 84static void handle_dv_data_message (void *cls,
65 struct GNUNET_SERVER_Client * 85 struct GNUNET_PeerIdentity *
66 client, 86 peer,
67 const struct 87 const struct
68 GNUNET_MessageHeader * 88 GNUNET_MessageHeader *
69 message) 89 message,
90 struct GNUNET_TIME_Relative latency,
91 uint32_t distance)
70{ 92{
71#if DEBUG_DV 93#if DEBUG_DV
72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
73 "%s: Receives %s message!\n", "dv", "DV DATA"); 95 "%s: Receives %s message!\n", "dv", "DV DATA");
74#endif 96#endif
97
75} 98}
76 99
77/** 100/**
@@ -85,16 +108,17 @@ void handle_dv_data_message (void *cls,
85 * @param client identification of the client 108 * @param client identification of the client
86 * @param message the actual message 109 * @param message the actual message
87 */ 110 */
88void handle_dv_gossip_message (void *cls, 111static void handle_dv_gossip_message (void *cls,
89 struct GNUNET_SERVER_Client * 112 struct GNUNET_PeerIdentity * peer,
90 client, 113 const struct GNUNET_MessageHeader * message,
91 const struct GNUNET_MessageHeader * 114 struct GNUNET_TIME_Relative latency,
92 message) 115 uint32_t distance)
93{ 116{
94#if DEBUG_DV 117#if DEBUG_DV
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
96 "%s: Receives %s message!\n", "dv", "DV GOSSIP"); 119 "%s: Receives %s message!\n", "dv", "DV GOSSIP");
97#endif 120#endif
121
98} 122}
99 123
100 124
@@ -114,6 +138,21 @@ void send_dv_message (void *cls,
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
115 "%s: Receives %s message!\n", "dv", "SEND"); 139 "%s: Receives %s message!\n", "dv", "SEND");
116#endif 140#endif
141 if (client_handle == NULL)
142 {
143 client_handle = client;
144#if DEBUG_DV
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
146 "%s: Setting initial client handle!\n", "dv");
147#endif
148 }
149 else if (client_handle != client)
150 {
151 client_handle = client;
152 /* What should we do in this case, assert fail or just log the warning? */
153 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
154 "%s: Setting client handle (was a different client!)!\n", "dv");
155 }
117} 156}
118 157
119/** 158/**
@@ -126,10 +165,10 @@ void send_dv_message (void *cls,
126 * transport) and then our server should be getting messages 165 * transport) and then our server should be getting messages
127 * from the dv_plugin, right? 166 * from the dv_plugin, right?
128 */ 167 */
129static struct GNUNET_SERVER_MessageHandler core_handlers[] = { 168static struct GNUNET_CORE_MessageHandler core_handlers[] = {
130 {&handle_dv_data_message, NULL, GNUNET_MESSAGE_TYPE_DV_DATA, 0}, 169 {&handle_dv_data_message, GNUNET_MESSAGE_TYPE_DV_DATA, 0},
131 {&handle_dv_gossip_message, NULL, GNUNET_MESSAGE_TYPE_DV_GOSSIP, 0}, 170 {&handle_dv_gossip_message, GNUNET_MESSAGE_TYPE_DV_GOSSIP, 0},
132 {NULL, NULL, 0, 0} 171 {NULL, 0, 0}
133}; 172};
134 173
135static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { 174static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
@@ -165,10 +204,11 @@ void core_init (void *cls,
165 { 204 {
166 GNUNET_SCHEDULER_cancel(sched, cleanup_task); 205 GNUNET_SCHEDULER_cancel(sched, cleanup_task);
167 GNUNET_SCHEDULER_add_now(sched, &shutdown_task, NULL); 206 GNUNET_SCHEDULER_add_now(sched, &shutdown_task, NULL);
207 return;
168 } 208 }
169#if DEBUG_DV 209#if DEBUG_DV
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "%s: Core initialized, I am peer: %s\n", "dv", GNUNET_i2s(my_identity)); 211 "%s: Core connection initialized, I am peer: %s\n", "dv", GNUNET_i2s(my_identity));
172#endif 212#endif
173 coreAPI = server; 213 coreAPI = server;
174} 214}
@@ -202,13 +242,11 @@ void handle_core_connect (void *cls,
202 * @param distance reported distance (DV) to 'other' 242 * @param distance reported distance (DV) to 'other'
203 */ 243 */
204void handle_core_disconnect (void *cls, 244void handle_core_disconnect (void *cls,
205 const struct GNUNET_PeerIdentity * peer, 245 const struct GNUNET_PeerIdentity * peer)
206 struct GNUNET_TIME_Relative latency,
207 uint32_t distance)
208{ 246{
209#if DEBUG_DV 247#if DEBUG_DV
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
211 "%s: Receives core disconnect message!\n", "dv"); 249 "%s: Receives core peer disconnect message!\n", "dv");
212#endif 250#endif
213} 251}
214 252
@@ -228,6 +266,8 @@ run (void *cls,
228 const struct GNUNET_CONFIGURATION_Handle *c) 266 const struct GNUNET_CONFIGURATION_Handle *c)
229{ 267{
230 struct GNUNET_TIME_Relative timeout; 268 struct GNUNET_TIME_Relative timeout;
269
270 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5);
231 sched = scheduler; 271 sched = scheduler;
232 cfg = c; 272 cfg = c;
233 GNUNET_SERVER_add_handlers (server, plugin_handlers); 273 GNUNET_SERVER_add_handlers (server, plugin_handlers);
@@ -241,9 +281,9 @@ run (void *cls,
241 &handle_core_connect, 281 &handle_core_connect,
242 &handle_core_disconnect, 282 &handle_core_disconnect,
243 NULL, 283 NULL,
284 GNUNET_NO,
244 NULL, 285 NULL,
245 NULL, 286 GNUNET_NO,
246 NULL,
247 core_handlers); 287 core_handlers);
248 288
249 if (coreAPI == NULL) 289 if (coreAPI == NULL)