summaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-service-conversation-new.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversation/gnunet-service-conversation-new.c')
-rw-r--r--src/conversation/gnunet-service-conversation-new.c96
1 files changed, 84 insertions, 12 deletions
diff --git a/src/conversation/gnunet-service-conversation-new.c b/src/conversation/gnunet-service-conversation-new.c
index b02c9094e..d28d214ab 100644
--- a/src/conversation/gnunet-service-conversation-new.c
+++ b/src/conversation/gnunet-service-conversation-new.c
@@ -112,14 +112,29 @@ struct Line
112 struct GNUNET_MESH_TransmitHandle *unreliable_mth; 112 struct GNUNET_MESH_TransmitHandle *unreliable_mth;
113 113
114 /** 114 /**
115 * Transmit handle for pending audio messages 115 * Message queue for control messages
116 */ 116 */
117 struct GNUNET_MQ_Handle *reliable_mq; 117 struct GNUNET_MQ_Handle *reliable_mq;
118 118
119 /** 119 /**
120 * Handle to the line client.
121 */
122 struct GNUNET_SERVER_Client *client;
123
124 /**
125 * Target of the line, if we are the caller.
126 */
127 struct GNUNET_PeerIdentity target;
128
129 /**
120 * Our line number. 130 * Our line number.
121 */ 131 */
122 uint32_t line; 132 uint32_t local_line;
133
134 /**
135 * Remote line number.
136 */
137 uint32_t remote_line;
123 138
124 /** 139 /**
125 * Current status of this line. 140 * Current status of this line.
@@ -159,6 +174,13 @@ static struct Line *lines_head;
159 */ 174 */
160static struct Line *lines_tail; 175static struct Line *lines_tail;
161 176
177/**
178 * Counter for generating local line numbers.
179 * FIXME: randomize generation in the future
180 * to eliminate information leakage.
181 */
182static uint32_t local_line_cnt;
183
162 184
163/** 185/**
164 * Function to register a phone. 186 * Function to register a phone.
@@ -183,10 +205,12 @@ handle_client_register_message (void *cls,
183 return; 205 return;
184 } 206 }
185 line = GNUNET_new (struct Line); 207 line = GNUNET_new (struct Line);
208 line->client = client;
209 GNUNET_SERVER_notification_context_add (nc, client);
186 GNUNET_CONTAINER_DLL_insert (lines_head, 210 GNUNET_CONTAINER_DLL_insert (lines_head,
187 lines_tail, 211 lines_tail,
188 line); 212 line);
189 line->line = ntohl (msg->line); 213 line->local_line = ntohl (msg->line);
190 GNUNET_SERVER_client_set_user_context (client, line); 214 GNUNET_SERVER_client_set_user_context (client, line);
191 GNUNET_SERVER_receive_done (client, GNUNET_OK); 215 GNUNET_SERVER_receive_done (client, GNUNET_OK);
192} 216}
@@ -257,10 +281,11 @@ handle_client_call_message (void *cls,
257 return; 281 return;
258 } 282 }
259 line = GNUNET_new (struct Line); 283 line = GNUNET_new (struct Line);
284 line->target = msg->target;
260 GNUNET_CONTAINER_DLL_insert (lines_head, 285 GNUNET_CONTAINER_DLL_insert (lines_head,
261 lines_tail, 286 lines_tail,
262 line); 287 line);
263 line->line = ntohl (msg->line); 288 line->remote_line = ntohl (msg->line);
264 line->status = LS_CALLER_CALLING; 289 line->status = LS_CALLER_CALLING;
265 line->tunnel_reliable = GNUNET_MESH_tunnel_create (mesh, 290 line->tunnel_reliable = GNUNET_MESH_tunnel_create (mesh,
266 line, 291 line,
@@ -268,13 +293,8 @@ handle_client_call_message (void *cls,
268 GNUNET_APPLICATION_TYPE_CONVERSATION_CONTROL, 293 GNUNET_APPLICATION_TYPE_CONVERSATION_CONTROL,
269 GNUNET_NO, 294 GNUNET_NO,
270 GNUNET_YES); 295 GNUNET_YES);
271 line->tunnel_unreliable = GNUNET_MESH_tunnel_create (mesh,
272 line,
273 &msg->target,
274 GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO,
275 GNUNET_YES,
276 GNUNET_NO);
277 line->reliable_mq = GNUNET_MESH_mq_create (line->tunnel_reliable); 296 line->reliable_mq = GNUNET_MESH_mq_create (line->tunnel_reliable);
297 line->local_line = local_line_cnt++;
278 e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_RING); 298 e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_RING);
279 ring->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); 299 ring->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING);
280 ring->purpose.size = htonl (sizeof (struct GNUNET_PeerIdentity) * 2 + 300 ring->purpose.size = htonl (sizeof (struct GNUNET_PeerIdentity) * 2 +
@@ -283,7 +303,8 @@ handle_client_call_message (void *cls,
283 sizeof (struct GNUNET_CRYPTO_EccPublicSignKey)); 303 sizeof (struct GNUNET_CRYPTO_EccPublicSignKey));
284 GNUNET_CRYPTO_ecc_key_get_public_for_signature (&msg->caller_id, 304 GNUNET_CRYPTO_ecc_key_get_public_for_signature (&msg->caller_id,
285 &ring->caller_id); 305 &ring->caller_id);
286 ring->line = msg->line; 306 ring->remote_line = msg->line;
307 ring->source_line = line->local_line;
287 ring->target = msg->target; 308 ring->target = msg->target;
288 ring->source = my_identity; 309 ring->source = my_identity;
289 ring->expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT)); 310 ring->expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT));
@@ -332,9 +353,49 @@ handle_mesh_ring_message (void *cls,
332 const struct GNUNET_MessageHeader *message) 353 const struct GNUNET_MessageHeader *message)
333{ 354{
334 const struct MeshPhoneRingMessage *msg; 355 const struct MeshPhoneRingMessage *msg;
356 struct Line *line;
357 struct GNUNET_MQ_Envelope *e;
358 struct MeshPhoneBusyMessage *busy;
359 struct ClientPhoneRingMessage cring;
335 360
336 msg = (const struct MeshPhoneRingMessage *) message; 361 msg = (const struct MeshPhoneRingMessage *) message;
337 GNUNET_break (0); // FIXME 362 if ( (msg->purpose.size != htonl (sizeof (struct GNUNET_PeerIdentity) * 2 +
363 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
364 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
365 sizeof (struct GNUNET_CRYPTO_EccPublicSignKey))) ||
366 (GNUNET_OK !=
367 GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING,
368 &msg->purpose,
369 &msg->signature,
370 &msg->caller_id)) )
371 {
372 GNUNET_break_op (0);
373 return GNUNET_SYSERR;
374 }
375 for (line = lines_head; NULL != line; line = line->next)
376 if ( (line->local_line == ntohl (msg->remote_line)) &&
377 (LS_CALLEE_LISTEN == line->status) )
378 break;
379 if (NULL == line)
380 {
381 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
382 _("No available phone for incoming call on line %u, sending BUSY signal\n"),
383 ntohl (msg->remote_line));
384 e = GNUNET_MQ_msg (busy, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_BUSY);
385 GNUNET_MQ_send (line->reliable_mq, e);
386 return GNUNET_OK;
387 }
388 line->status = LS_CALLEE_RINGING;
389 line->remote_line = ntohl (msg->source_line);
390 line->tunnel_reliable = tunnel;
391 cring.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING);
392 cring.header.size = htons (sizeof (cring));
393 cring.reserved = htonl (0);
394 cring.caller_id = msg->caller_id;
395 GNUNET_SERVER_notification_context_unicast (nc,
396 line->client,
397 &cring.header,
398 GNUNET_NO);
338 return GNUNET_OK; 399 return GNUNET_OK;
339} 400}
340 401
@@ -378,9 +439,20 @@ handle_mesh_pickup_message (void *cls,
378 const struct GNUNET_MessageHeader *message) 439 const struct GNUNET_MessageHeader *message)
379{ 440{
380 const struct MeshPhonePickupMessage *msg; 441 const struct MeshPhonePickupMessage *msg;
442 struct Line *line = *tunnel_ctx;
381 443
382 msg = (const struct MeshPhonePickupMessage *) message; 444 msg = (const struct MeshPhonePickupMessage *) message;
383 GNUNET_break (0); // FIXME 445 GNUNET_break (0); // FIXME
446
447
448 line->tunnel_unreliable = GNUNET_MESH_tunnel_create (mesh,
449 line,
450 &line->target,
451 GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO,
452 GNUNET_YES,
453 GNUNET_NO);
454
455
384 return GNUNET_OK; 456 return GNUNET_OK;
385} 457}
386 458