aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-05-19 14:13:50 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-05-19 14:13:50 +0000
commitc7a70aa21e0f0a0325f8b2c743713d6fb1f2fc0a (patch)
tree92e585084faca5c0a9b0523874e4b7d839a4b6f3 /src/transport
parent819dd2547e8d11d094fe83a39667559e54e181c6 (diff)
downloadgnunet-c7a70aa21e0f0a0325f8b2c743713d6fb1f2fc0a.tar.gz
gnunet-c7a70aa21e0f0a0325f8b2c743713d6fb1f2fc0a.zip
new api
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_clients.c39
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c20
-rw-r--r--src/transport/gnunet-transport.c17
-rw-r--r--src/transport/transport.h26
-rw-r--r--src/transport/transport_api_address_to_string.c59
5 files changed, 135 insertions, 26 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index d9a750e29..171644123 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -863,17 +863,39 @@ static void
863transmit_address_to_client (void *cls, const char *buf) 863transmit_address_to_client (void *cls, const char *buf)
864{ 864{
865 struct AddressToStringContext *actx = cls; 865 struct AddressToStringContext *actx = cls;
866 struct AddressToStringResultMessage *atsm;
867 size_t len;
868
869 if (NULL != buf)
870 {
871 len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1;
872 atsm = GNUNET_malloc (len);
873 atsm->header.size = ntohs (len);
874 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
875 atsm->res = htonl (GNUNET_YES);
876 atsm->addr_len = htonl (strlen (buf) + 1);
877 memcpy (&atsm[1], buf, strlen (buf) + 1);
878 }
879 else
880 {
881 len = sizeof (struct AddressToStringResultMessage);
882 atsm = GNUNET_malloc (len);
883 atsm->header.size = ntohs (len);
884 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
885 atsm->res = htonl (GNUNET_NO);
886 atsm->addr_len = htonl (0);
887 }
888
866 if (NULL == buf) 889 if (NULL == buf)
867 { 890 {
868 GNUNET_SERVER_transmit_context_append_data (actx->tc, NULL, 0, 891 /* Address could not be converted */
869 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 892 GNUNET_SERVER_transmit_context_append_message (actx->tc, (const struct GNUNET_MessageHeader *)atsm);
870 GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL); 893 GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL);
871 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx); 894 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
872 GNUNET_free (actx); 895 GNUNET_free (actx);
873 return; 896 return;
874 } 897 }
875 GNUNET_SERVER_transmit_context_append_data (actx->tc, buf, strlen (buf) + 1, 898 GNUNET_SERVER_transmit_context_append_message (actx->tc, (const struct GNUNET_MessageHeader *) atsm);
876 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
877} 899}
878 900
879 901
@@ -897,6 +919,7 @@ clients_handle_address_to_string (void *cls,
897 uint16_t size; 919 uint16_t size;
898 struct GNUNET_SERVER_TransmitContext *tc; 920 struct GNUNET_SERVER_TransmitContext *tc;
899 struct AddressToStringContext *actx; 921 struct AddressToStringContext *actx;
922 struct AddressToStringResultMessage atsm;
900 struct GNUNET_TIME_Relative rtimeout; 923 struct GNUNET_TIME_Relative rtimeout;
901 int32_t numeric; 924 int32_t numeric;
902 925
@@ -929,8 +952,12 @@ clients_handle_address_to_string (void *cls,
929 papi = GST_plugins_printer_find (plugin_name); 952 papi = GST_plugins_printer_find (plugin_name);
930 if (NULL == papi) 953 if (NULL == papi)
931 { 954 {
932 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 955 atsm.header.size = ntohs (sizeof (struct AddressToStringResultMessage));
933 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 956 atsm.header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
957 atsm.res = htonl (GNUNET_NO);
958 atsm.addr_len = htonl (0);
959 GNUNET_SERVER_transmit_context_append_message (tc,
960 (const struct GNUNET_MessageHeader *) &atsm);
934 GNUNET_SERVER_transmit_context_run (tc, rtimeout); 961 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
935 return; 962 return;
936 } 963 }
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index d2dd2e752..7993bf2f4 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -1229,10 +1229,11 @@ transmit_send_continuation (void *cls,
1229 gettext_noop 1229 gettext_noop
1230 ("# transmission failures for messages to other peers"), 1230 ("# transmission failures for messages to other peers"),
1231 1, GNUNET_NO); 1231 1, GNUNET_NO);
1232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1233 "Sending message to `%s' of type %u was a %s\n", 1233 "Sending message to `%s' of type %u with %u bytes was a %s\n",
1234 GNUNET_i2s (receiver), 1234 GNUNET_i2s (receiver),
1235 ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type), 1235 ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type),
1236 mq->message_buf_size,
1236 (success == GNUNET_OK) ? "success" : "FAILURE"); 1237 (success == GNUNET_OK) ? "success" : "FAILURE");
1237 if (NULL != mq->cont) 1238 if (NULL != mq->cont)
1238 mq->cont (mq->cont_cls, success, size_payload, physical); 1239 mq->cont (mq->cont_cls, success, size_payload, physical);
@@ -1296,6 +1297,11 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1296 return; /* no more messages */ 1297 return; /* no more messages */
1297 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); 1298 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
1298 n->is_active = mq; 1299 n->is_active = mq;
1300
1301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1302 "Giving message with %u bytes to plugin session %p\n",
1303 mq->message_buf_size, n->primary_address.session);
1304
1299 (void) send_with_session (n, 1305 (void) send_with_session (n,
1300 mq->message_buf, mq->message_buf_size, 1306 mq->message_buf, mq->message_buf_size,
1301 0 /* priority */, timeout, GNUNET_NO, 1307 0 /* priority */, timeout, GNUNET_NO,
@@ -1635,10 +1641,11 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1635 mq->message_buf = (const char *) &mq[1]; 1641 mq->message_buf = (const char *) &mq[1];
1636 mq->message_buf_size = msg_size; 1642 mq->message_buf_size = msg_size;
1637 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1643 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1644
1645 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Enqueueing %u bytes to send to peer %s\n",
1646 msg_size, GNUNET_i2s (target));
1647
1638 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq); 1648 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq);
1639 if ( (NULL != n->is_active) ||
1640 ( (NULL == n->primary_address.session) && (NULL == n->primary_address.address)) )
1641 return;
1642 if (GNUNET_SCHEDULER_NO_TASK != n->task) 1649 if (GNUNET_SCHEDULER_NO_TASK != n->task)
1643 GNUNET_SCHEDULER_cancel (n->task); 1650 GNUNET_SCHEDULER_cancel (n->task);
1644 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 1651 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
@@ -2073,8 +2080,7 @@ notification_cb(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2073 return GNUNET_OK; 2080 return GNUNET_OK;
2074} 2081}
2075 2082
2076static 2083static int
2077int
2078free_notification_cb(void *cls, const struct GNUNET_PeerIdentity *key, 2084free_notification_cb(void *cls, const struct GNUNET_PeerIdentity *key,
2079 void *value) 2085 void *value)
2080{ 2086{
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 4487fc0e7..d4e16face 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -579,7 +579,7 @@ resolve_validation_address (const struct GNUNET_PeerIdentity *id,
579 579
580 580
581static void 581static void
582process_validation_string (void *cls, const char *address) 582process_validation_string (void *cls, const char *address, int res)
583{ 583{
584 struct ValidationResolutionContext *vc = cls; 584 struct ValidationResolutionContext *vc = cls;
585 char *s_valid; 585 char *s_valid;
@@ -588,6 +588,13 @@ process_validation_string (void *cls, const char *address)
588 588
589 if (address != NULL ) 589 if (address != NULL )
590 { 590 {
591 if (GNUNET_SYSERR == res)
592 {
593 FPRINTF (stderr, "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n",
594 GNUNET_i2s (&vc->id),
595 vc->addrcp->transport_name,
596 vc->addrcp->address_length);
597 }
591 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us) 598 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us)
592 s_valid = GNUNET_strdup("never"); 599 s_valid = GNUNET_strdup("never");
593 else 600 else
@@ -605,7 +612,8 @@ process_validation_string (void *cls, const char *address)
605 612
606 FPRINTF (stdout, 613 FPRINTF (stdout,
607 _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"), 614 _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"),
608 GNUNET_i2s (&vc->id), address, 615 GNUNET_i2s (&vc->id),
616 (GNUNET_OK == res) ? address : "<invalid address>",
609 (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "", 617 (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "",
610 "Valid until : ", s_valid, 618 "Valid until : ", s_valid,
611 "Last validation: ",s_last, 619 "Last validation: ",s_last,
@@ -618,9 +626,10 @@ process_validation_string (void *cls, const char *address)
618 else 626 else
619 { 627 {
620 /* done */ 628 /* done */
629
621 GNUNET_assert(address_resolutions > 0); 630 GNUNET_assert(address_resolutions > 0);
622 address_resolutions--; 631 address_resolutions--;
623 if (GNUNET_NO == vc->printed) 632 if ((GNUNET_SYSERR == res) && (GNUNET_NO == vc->printed))
624 { 633 {
625 if (numeric == GNUNET_NO) 634 if (numeric == GNUNET_NO)
626 { 635 {
@@ -1066,7 +1075,7 @@ print_info (const struct GNUNET_PeerIdentity *id,
1066 1075
1067 1076
1068static void 1077static void
1069process_peer_string (void *cls, const char *address) 1078process_peer_string (void *cls, const char *address, int res)
1070{ 1079{
1071 struct PeerResolutionContext *rc = cls; 1080 struct PeerResolutionContext *rc = cls;
1072 1081
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 7aa6c06a9..68c685c29 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -276,6 +276,32 @@ struct SendOkMessage
276 276
277}; 277};
278 278
279/**
280 * Message used to notify the transport API about an address to string
281 * conversion. Message is followed by the string with length strlen
282 */
283struct AddressToStringResultMessage
284{
285
286 /**
287 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
288 */
289 struct GNUNET_MessageHeader header;
290
291 /**
292 * GNUNET_OK if the conversion succeeded,
293 * GNUNET_SYSERR if it failed
294 */
295 uint32_t res GNUNET_PACKED;
296
297 /**
298 * Length of the following string
299 */
300 uint32_t addr_len GNUNET_PACKED;
301};
302
303
304
279 305
280/** 306/**
281 * Message used to notify the transport service about a message 307 * Message used to notify the transport service about a message
diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c
index 0cf0111b3..8a0db240f 100644
--- a/src/transport/transport_api_address_to_string.c
+++ b/src/transport/transport_api_address_to_string.c
@@ -55,7 +55,7 @@ struct GNUNET_TRANSPORT_AddressToStringContext
55/** 55/**
56 * Function called with responses from the service. 56 * Function called with responses from the service.
57 * 57 *
58 * @param cls our 'struct GNUNET_TRANSPORT_AddressLookupContext*' 58 * @param cls our 'struct GNUNET_TRANSPORT_AddressToStringContext*'
59 * @param msg NULL on timeout or error, otherwise presumably a 59 * @param msg NULL on timeout or error, otherwise presumably a
60 * message with the human-readable address 60 * message with the human-readable address
61 */ 61 */
@@ -63,41 +63,82 @@ static void
63address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) 63address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
64{ 64{
65 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; 65 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
66 struct AddressToStringResultMessage *atsm;
66 const char *address; 67 const char *address;
67 uint16_t size; 68 uint16_t size;
69 uint32_t result;
70 uint32_t addr_len;
71 char *empty_str = "";
68 72
69 if (msg == NULL) 73 if (msg == NULL)
70 { 74 {
71 alucb->cb (alucb->cb_cls, NULL); 75 alucb->cb (alucb->cb_cls, NULL, GNUNET_OK);
72 GNUNET_CLIENT_disconnect (alucb->client); 76 GNUNET_CLIENT_disconnect (alucb->client);
73 GNUNET_free (alucb); 77 GNUNET_free (alucb);
74 return; 78 return;
75 } 79 }
76 GNUNET_break (ntohs (msg->type) == 80 GNUNET_break (ntohs (msg->type) ==
77 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 81 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
82
78 size = ntohs (msg->size); 83 size = ntohs (msg->size);
79 if (size == sizeof (struct GNUNET_MessageHeader)) 84 if (size < sizeof (struct AddressToStringResultMessage))
80 { 85 {
81 /* done! */ 86 alucb->cb (alucb->cb_cls, NULL, GNUNET_OK);
82 alucb->cb (alucb->cb_cls, NULL);
83 GNUNET_CLIENT_disconnect (alucb->client); 87 GNUNET_CLIENT_disconnect (alucb->client);
84 GNUNET_free (alucb); 88 GNUNET_free (alucb);
85 return; 89 return;
86 } 90 }
87 address = (const char *) &msg[1]; 91 atsm = (struct AddressToStringResultMessage *) msg;
88 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') 92
93 result = ntohl (atsm->res);
94 addr_len = ntohl (atsm->addr_len);
95
96 if (size == (sizeof (struct AddressToStringResultMessage)))
97 {
98 /* done, success depends on result */
99 alucb->cb (alucb->cb_cls, NULL, result);
100 GNUNET_CLIENT_disconnect (alucb->client);
101 GNUNET_free (alucb);
102 return;
103 }
104
105 if (GNUNET_NO == result)
106 {
107 alucb->cb (alucb->cb_cls, NULL, GNUNET_SYSERR);
108
109 /* expect more replies */
110 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb,
111 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
112 return;
113 }
114
115
116 address = (const char *) &atsm[1];
117 if ( (addr_len > (size - (sizeof (struct AddressToStringResultMessage)))) ||
118 (address[addr_len -1] != '\0') )
89 { 119 {
90 /* invalid reply */ 120 /* invalid reply */
91 GNUNET_break (0); 121 GNUNET_break (0);
92 alucb->cb (alucb->cb_cls, NULL); 122 alucb->cb (alucb->cb_cls, NULL, GNUNET_SYSERR);
93 GNUNET_CLIENT_disconnect (alucb->client); 123 GNUNET_CLIENT_disconnect (alucb->client);
94 GNUNET_free (alucb); 124 GNUNET_free (alucb);
95 return; 125 return;
96 } 126 }
127
128 result = GNUNET_NO;
129
97 /* expect more replies */ 130 /* expect more replies */
98 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, 131 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb,
99 GNUNET_TIME_absolute_get_remaining (alucb->timeout)); 132 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
100 alucb->cb (alucb->cb_cls, address); 133
134 if (GNUNET_NO == result)
135 {
136 alucb->cb (alucb->cb_cls, empty_str, GNUNET_SYSERR);
137 }
138 else
139 {
140 alucb->cb (alucb->cb_cls, address, GNUNET_OK);
141 }
101} 142}
102 143
103 144