diff options
Diffstat (limited to 'src/transport/gnunet-communicator-unix.c')
-rw-r--r-- | src/transport/gnunet-communicator-unix.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index 58a144ecb..404bcfb7f 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c | |||
@@ -114,7 +114,7 @@ struct Queue | |||
114 | * Message currently scheduled for transmission, non-NULL if and only | 114 | * Message currently scheduled for transmission, non-NULL if and only |
115 | * if this queue is in the #queue_head DLL. | 115 | * if this queue is in the #queue_head DLL. |
116 | */ | 116 | */ |
117 | const struct GNUNET_MessageHeader *msg; | 117 | struct UNIXMessage *msg; |
118 | 118 | ||
119 | /** | 119 | /** |
120 | * Message queue we are providing for the #ch. | 120 | * Message queue we are providing for the #ch. |
@@ -142,6 +142,10 @@ struct Queue | |||
142 | struct GNUNET_SCHEDULER_Task *timeout_task; | 142 | struct GNUNET_SCHEDULER_Task *timeout_task; |
143 | }; | 143 | }; |
144 | 144 | ||
145 | /** | ||
146 | * My Peer Identity | ||
147 | */ | ||
148 | static struct GNUNET_PeerIdentity my_identity; | ||
145 | 149 | ||
146 | /** | 150 | /** |
147 | * ID of read task | 151 | * ID of read task |
@@ -357,7 +361,7 @@ lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
357 | struct LookupCtx *lctx = cls; | 361 | struct LookupCtx *lctx = cls; |
358 | struct Queue *queue = value; | 362 | struct Queue *queue = value; |
359 | 363 | ||
360 | if ((queue->address_len = lctx->un_len) && | 364 | if ((queue->address_len == lctx->un_len) && |
361 | (0 == memcmp (lctx->un, queue->address, queue->address_len))) | 365 | (0 == memcmp (lctx->un, queue->address, queue->address_len))) |
362 | { | 366 | { |
363 | lctx->res = queue; | 367 | lctx->res = queue; |
@@ -383,6 +387,7 @@ lookup_queue (const struct GNUNET_PeerIdentity *peer, | |||
383 | 387 | ||
384 | lctx.un = un; | 388 | lctx.un = un; |
385 | lctx.un_len = un_len; | 389 | lctx.un_len = un_len; |
390 | lctx.res = NULL; | ||
386 | GNUNET_CONTAINER_multipeermap_get_multiple (queue_map, | 391 | GNUNET_CONTAINER_multipeermap_get_multiple (queue_map, |
387 | peer, | 392 | peer, |
388 | &lookup_queue_it, | 393 | &lookup_queue_it, |
@@ -401,7 +406,7 @@ static void | |||
401 | select_write_cb (void *cls) | 406 | select_write_cb (void *cls) |
402 | { | 407 | { |
403 | struct Queue *queue = queue_tail; | 408 | struct Queue *queue = queue_tail; |
404 | const struct GNUNET_MessageHeader *msg = queue->msg; | 409 | const struct GNUNET_MessageHeader *msg = &queue->msg->header; |
405 | size_t msg_size = ntohs (msg->size); | 410 | size_t msg_size = ntohs (msg->size); |
406 | ssize_t sent; | 411 | ssize_t sent; |
407 | 412 | ||
@@ -514,10 +519,15 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
514 | void *impl_state) | 519 | void *impl_state) |
515 | { | 520 | { |
516 | struct Queue *queue = impl_state; | 521 | struct Queue *queue = impl_state; |
522 | size_t msize = ntohs (msg->size); | ||
517 | 523 | ||
518 | GNUNET_assert (mq == queue->mq); | 524 | GNUNET_assert (mq == queue->mq); |
519 | GNUNET_assert (NULL == queue->msg); | 525 | GNUNET_assert (NULL == queue->msg); |
520 | queue->msg = msg; | 526 | //Convert to UNIXMessage |
527 | queue->msg = GNUNET_malloc (msize + sizeof (struct UNIXMessage)); | ||
528 | queue->msg->header.size = htons(msize + sizeof (struct UNIXMessage)); | ||
529 | queue->msg->sender = my_identity; | ||
530 | memcpy (&queue->msg[1], msg, msize); | ||
521 | GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue); | 531 | GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue); |
522 | GNUNET_assert (NULL != unix_sock); | 532 | GNUNET_assert (NULL != unix_sock); |
523 | if (NULL == write_task) | 533 | if (NULL == write_task) |
@@ -747,6 +757,9 @@ select_read_cb (void *cls) | |||
747 | msize = ntohs (msg->header.size); | 757 | msize = ntohs (msg->header.size); |
748 | if ((msize < sizeof(struct UNIXMessage)) || (msize > ret)) | 758 | if ((msize < sizeof(struct UNIXMessage)) || (msize > ret)) |
749 | { | 759 | { |
760 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
761 | "Wrong message size: %d bytes\n", | ||
762 | msize); | ||
750 | GNUNET_break_op (0); | 763 | GNUNET_break_op (0); |
751 | return; | 764 | return; |
752 | } | 765 | } |
@@ -974,9 +987,22 @@ run (void *cls, | |||
974 | struct sockaddr_un *un; | 987 | struct sockaddr_un *un; |
975 | socklen_t un_len; | 988 | socklen_t un_len; |
976 | char *my_addr; | 989 | char *my_addr; |
990 | struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; | ||
977 | 991 | ||
978 | (void) cls; | 992 | (void) cls; |
979 | 993 | ||
994 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); | ||
995 | if (NULL == my_private_key) | ||
996 | { | ||
997 | GNUNET_log ( | ||
998 | GNUNET_ERROR_TYPE_ERROR, | ||
999 | _ ( | ||
1000 | "UNIX communicator is lacking key configuration settings. Exiting.\n")); | ||
1001 | GNUNET_SCHEDULER_shutdown (); | ||
1002 | return; | ||
1003 | } | ||
1004 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); | ||
1005 | |||
980 | if (GNUNET_OK != | 1006 | if (GNUNET_OK != |
981 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1007 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
982 | COMMUNICATOR_CONFIG_SECTION, | 1008 | COMMUNICATOR_CONFIG_SECTION, |