diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-04 16:22:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-04 16:22:28 +0000 |
commit | 84fafd05402d39d86ee385b4410b06afcfbd6671 (patch) | |
tree | 803e180d203c054075da4a7b91529e5ddad92b28 /src/conversation | |
parent | cd6d3eb43c67e99bd21f2c7a5735422d135a5e5e (diff) | |
download | gnunet-84fafd05402d39d86ee385b4410b06afcfbd6671.tar.gz gnunet-84fafd05402d39d86ee385b4410b06afcfbd6671.zip |
-sending RING signal
Diffstat (limited to 'src/conversation')
-rw-r--r-- | src/conversation/conversation.h | 14 | ||||
-rw-r--r-- | src/conversation/gnunet-service-conversation-new.c | 96 |
2 files changed, 96 insertions, 14 deletions
diff --git a/src/conversation/conversation.h b/src/conversation/conversation.h index 05fdc326b..dceb9b9e4 100644 --- a/src/conversation/conversation.h +++ b/src/conversation/conversation.h | |||
@@ -433,7 +433,7 @@ struct ClientPhoneRingMessage | |||
433 | 433 | ||
434 | /** | 434 | /** |
435 | * Always zero. | 435 | * Always zero. |
436 | p */ | 436 | */ |
437 | uint32_t reserved GNUNET_PACKED; | 437 | uint32_t reserved GNUNET_PACKED; |
438 | 438 | ||
439 | /** | 439 | /** |
@@ -559,7 +559,7 @@ struct MeshPhoneRingMessage | |||
559 | /** | 559 | /** |
560 | * Desired target line. | 560 | * Desired target line. |
561 | */ | 561 | */ |
562 | uint32_t line GNUNET_PACKED; | 562 | uint32_t remote_line GNUNET_PACKED; |
563 | 563 | ||
564 | /** | 564 | /** |
565 | * Purpose for the signature. | 565 | * Purpose for the signature. |
@@ -591,6 +591,11 @@ struct MeshPhoneRingMessage | |||
591 | */ | 591 | */ |
592 | struct GNUNET_CRYPTO_EccSignature signature; | 592 | struct GNUNET_CRYPTO_EccSignature signature; |
593 | 593 | ||
594 | /** | ||
595 | * Source line for audio data in the other direction. | ||
596 | */ | ||
597 | uint32_t source_line GNUNET_PACKED; | ||
598 | |||
594 | }; | 599 | }; |
595 | 600 | ||
596 | 601 | ||
@@ -645,6 +650,11 @@ struct MeshAudioMessage | |||
645 | */ | 650 | */ |
646 | struct GNUNET_MessageHeader header; | 651 | struct GNUNET_MessageHeader header; |
647 | 652 | ||
653 | /** | ||
654 | * Target line on the receiving end. | ||
655 | */ | ||
656 | uint32_t remote_line; | ||
657 | |||
648 | /* followed by audio data */ | 658 | /* followed by audio data */ |
649 | 659 | ||
650 | }; | 660 | }; |
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 | */ |
160 | static struct Line *lines_tail; | 175 | static 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 | */ | ||
182 | static 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 | ||