diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-29 09:37:54 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-29 09:37:54 +0000 |
commit | 623df97886da9ee06724b7860a1a2463737b750e (patch) | |
tree | a7638265a42b7b276d10403078411e4f4d8973d8 /src/transport | |
parent | 51b7d6d6e0d50e77a3fc948af68ae02f325684ac (diff) | |
download | gnunet-623df97886da9ee06724b7860a1a2463737b750e.tar.gz gnunet-623df97886da9ee06724b7860a1a2463737b750e.zip |
first steps to transport_api cleanup
compiles but no guarante to work!
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-transport.c | 14 | ||||
-rw-r--r-- | src/transport/transport_api_address_iterate.c | 29 | ||||
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 35 | ||||
-rw-r--r-- | src/transport/transport_api_peer_address_lookup.c | 25 |
4 files changed, 51 insertions, 52 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 4c9e8566c..1dc85a903 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -443,11 +443,15 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
443 | * @param addrlen number of bytes in addr | 443 | * @param addrlen number of bytes in addr |
444 | */ | 444 | */ |
445 | static void | 445 | static void |
446 | process_address (void *cls, const struct GNUNET_PeerIdentity *peer, | 446 | process_address (void *cls, const struct GNUNET_HELLO_Address *address) |
447 | const char *transport, const void *addr, size_t addrlen) | ||
448 | { | 447 | { |
449 | if ((peer != NULL) || (transport != NULL) || | 448 | if ((address->transport_name != NULL) || |
450 | ((addr != NULL) && (addrlen > 0))) | 449 | ((address->address != NULL) && (address->address_length > 0))) |
450 | { | ||
451 | /* Call GNUNET_TRANSPORT_address_to_string to convert to human readable */ | ||
452 | //GNUNET_TRANSPORT_address_to_string(cfg, address, GNUNET_NO) | ||
453 | |||
454 | #if 0 | ||
451 | fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"), | 455 | fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"), |
452 | (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>", | 456 | (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>", |
453 | (transport != NULL) ? transport : "<unknown>", ((addr != NULL) && | 457 | (transport != NULL) ? transport : "<unknown>", ((addr != NULL) && |
@@ -456,6 +460,8 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
456 | NULL)) ? | 460 | NULL)) ? |
457 | "how do i resolve the name without transport service?" : | 461 | "how do i resolve the name without transport service?" : |
458 | "<unknown>"); | 462 | "<unknown>"); |
463 | #endif | ||
464 | } | ||
459 | } | 465 | } |
460 | 466 | ||
461 | 467 | ||
diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c index 3c3f97c28..a79319163 100644 --- a/src/transport/transport_api_address_iterate.c +++ b/src/transport/transport_api_address_iterate.c | |||
@@ -47,7 +47,7 @@ struct AddressLookupCtx | |||
47 | /** | 47 | /** |
48 | * Function to call with the human-readable address. | 48 | * Function to call with the human-readable address. |
49 | */ | 49 | */ |
50 | GNUNET_TRANSPORT_AddressLookUpBinaryCallback cb; | 50 | GNUNET_TRANSPORT_AddressLookUpCallback cb; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Closure for cb. | 53 | * Closure for cb. |
@@ -78,17 +78,13 @@ peer_address_response_processor (void *cls, | |||
78 | const struct GNUNET_MessageHeader *msg) | 78 | const struct GNUNET_MessageHeader *msg) |
79 | { | 79 | { |
80 | struct AddressLookupCtx *alucb = cls; | 80 | struct AddressLookupCtx *alucb = cls; |
81 | struct AddressIterateResponseMessage *address; | 81 | struct AddressIterateResponseMessage *arm; |
82 | struct GNUNET_HELLO_Address * address; | ||
82 | uint16_t size; | 83 | uint16_t size; |
83 | char *transport; | ||
84 | |||
85 | //size_t transport_len; | ||
86 | //void * addr; | ||
87 | size_t addrlen; | ||
88 | 84 | ||
89 | if (msg == NULL) | 85 | if (msg == NULL) |
90 | { | 86 | { |
91 | alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); | 87 | alucb->cb (alucb->cb_cls, NULL); |
92 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 88 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
93 | GNUNET_free (alucb); | 89 | GNUNET_free (alucb); |
94 | return; | 90 | return; |
@@ -102,7 +98,7 @@ peer_address_response_processor (void *cls, | |||
102 | if (size == sizeof (struct GNUNET_MessageHeader)) | 98 | if (size == sizeof (struct GNUNET_MessageHeader)) |
103 | { | 99 | { |
104 | /* done! */ | 100 | /* done! */ |
105 | alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); | 101 | alucb->cb (alucb->cb_cls, NULL); |
106 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 102 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
107 | GNUNET_free (alucb); | 103 | GNUNET_free (alucb); |
108 | return; | 104 | return; |
@@ -111,22 +107,19 @@ peer_address_response_processor (void *cls, | |||
111 | { | 107 | { |
112 | /* invalid reply */ | 108 | /* invalid reply */ |
113 | GNUNET_break (0); | 109 | GNUNET_break (0); |
114 | alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); | 110 | alucb->cb (alucb->cb_cls, NULL); |
115 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 111 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
116 | GNUNET_free (alucb); | 112 | GNUNET_free (alucb); |
117 | return; | 113 | return; |
118 | } | 114 | } |
119 | 115 | ||
120 | address = (struct AddressIterateResponseMessage *) &msg[1]; | 116 | arm = (struct AddressIterateResponseMessage *) &msg[1]; |
121 | 117 | address = (struct GNUNET_HELLO_Address *) &arm[1]; | |
122 | transport = (char *) &address[0]; | ||
123 | //transport_len = ntohs(address->pluginlen); | ||
124 | addrlen = ntohs (address->addrlen); | ||
125 | 118 | ||
126 | /* expect more replies */ | 119 | /* expect more replies */ |
127 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | 120 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, |
128 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | 121 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); |
129 | alucb->cb (alucb->cb_cls, &address->peer, transport, NULL, addrlen); | 122 | alucb->cb (alucb->cb_cls, address); |
130 | } | 123 | } |
131 | 124 | ||
132 | 125 | ||
@@ -141,7 +134,7 @@ peer_address_response_processor (void *cls, | |||
141 | void | 134 | void |
142 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 135 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, |
143 | struct GNUNET_TIME_Relative timeout, | 136 | struct GNUNET_TIME_Relative timeout, |
144 | GNUNET_TRANSPORT_AddressLookUpBinaryCallback | 137 | GNUNET_TRANSPORT_AddressLookUpCallback |
145 | peer_address_callback, | 138 | peer_address_callback, |
146 | void *peer_address_callback_cls) | 139 | void *peer_address_callback_cls) |
147 | { | 140 | { |
@@ -153,7 +146,7 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
153 | client = GNUNET_CLIENT_connect ("transport", cfg); | 146 | client = GNUNET_CLIENT_connect ("transport", cfg); |
154 | if (client == NULL) | 147 | if (client == NULL) |
155 | { | 148 | { |
156 | peer_address_callback (peer_address_callback_cls, NULL, NULL, NULL, 0); | 149 | peer_address_callback (peer_address_callback_cls, NULL); |
157 | return; | 150 | return; |
158 | } | 151 | } |
159 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 152 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 968a4324f..259c77152 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -30,12 +30,12 @@ | |||
30 | /** | 30 | /** |
31 | * Context for the address lookup. | 31 | * Context for the address lookup. |
32 | */ | 32 | */ |
33 | struct GNUNET_TRANSPORT_AddressLookupContext | 33 | struct GNUNET_TRANSPORT_AddressToStringContext |
34 | { | 34 | { |
35 | /** | 35 | /** |
36 | * Function to call with the human-readable address. | 36 | * Function to call with the human-readable address. |
37 | */ | 37 | */ |
38 | GNUNET_TRANSPORT_AddressLookUpCallback cb; | 38 | GNUNET_TRANSPORT_AddressToStringCallback cb; |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Closure for cb. | 41 | * Closure for cb. |
@@ -64,7 +64,7 @@ struct GNUNET_TRANSPORT_AddressLookupContext | |||
64 | static void | 64 | static void |
65 | address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | 65 | address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) |
66 | { | 66 | { |
67 | struct GNUNET_TRANSPORT_AddressLookupContext *alucb = cls; | 67 | struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; |
68 | const char *address; | 68 | const char *address; |
69 | uint16_t size; | 69 | uint16_t size; |
70 | 70 | ||
@@ -117,23 +117,23 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | |||
117 | * @param aluc_cls closure for aluc | 117 | * @param aluc_cls closure for aluc |
118 | * @return handle to cancel the operation, NULL on error | 118 | * @return handle to cancel the operation, NULL on error |
119 | */ | 119 | */ |
120 | struct GNUNET_TRANSPORT_AddressLookupContext * | 120 | struct GNUNET_TRANSPORT_AddressToStringContext * |
121 | GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | 121 | GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, |
122 | const char *address, size_t addressLen, | 122 | const struct GNUNET_HELLO_Address *address, |
123 | int numeric, const char *nameTrans, | 123 | int numeric, |
124 | struct GNUNET_TIME_Relative timeout, | 124 | struct GNUNET_TIME_Relative timeout, |
125 | GNUNET_TRANSPORT_AddressLookUpCallback aluc, | 125 | GNUNET_TRANSPORT_AddressToStringCallback aluc, |
126 | void *aluc_cls) | 126 | void *aluc_cls) |
127 | { | 127 | { |
128 | size_t slen; | ||
129 | size_t len; | 128 | size_t len; |
129 | size_t alen; | ||
130 | struct AddressLookupMessage *msg; | 130 | struct AddressLookupMessage *msg; |
131 | struct GNUNET_TRANSPORT_AddressLookupContext *alc; | 131 | struct GNUNET_TRANSPORT_AddressToStringContext *alc; |
132 | struct GNUNET_CLIENT_Connection *client; | 132 | struct GNUNET_CLIENT_Connection *client; |
133 | char *addrbuf; | 133 | char *addrbuf; |
134 | 134 | ||
135 | slen = strlen (nameTrans) + 1; | 135 | alen = GNUNET_HELLO_address_get_size (address); |
136 | len = sizeof (struct AddressLookupMessage) + addressLen + slen; | 136 | len = sizeof (struct AddressLookupMessage) + alen; |
137 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 137 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
138 | { | 138 | { |
139 | GNUNET_break (0); | 139 | GNUNET_break (0); |
@@ -147,11 +147,10 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
147 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); | 147 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); |
148 | msg->numeric_only = htonl (numeric); | 148 | msg->numeric_only = htonl (numeric); |
149 | msg->timeout = GNUNET_TIME_relative_hton (timeout); | 149 | msg->timeout = GNUNET_TIME_relative_hton (timeout); |
150 | msg->addrlen = htonl (addressLen); | 150 | msg->addrlen = htonl (alen); |
151 | addrbuf = (char *) &msg[1]; | 151 | addrbuf = (char *) &msg[1]; |
152 | memcpy (addrbuf, address, addressLen); | 152 | memcpy (addrbuf, address, alen); |
153 | memcpy (&addrbuf[addressLen], nameTrans, slen); | 153 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext)); |
154 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressLookupContext)); | ||
155 | alc->cb = aluc; | 154 | alc->cb = aluc; |
156 | alc->cb_cls = aluc_cls; | 155 | alc->cb_cls = aluc_cls; |
157 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 156 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
@@ -172,8 +171,8 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
172 | * @param alc handle for the request to cancel | 171 | * @param alc handle for the request to cancel |
173 | */ | 172 | */ |
174 | void | 173 | void |
175 | GNUNET_TRANSPORT_address_lookup_cancel (struct | 174 | GNUNET_TRANSPORT_address_to_string_cancel (struct |
176 | GNUNET_TRANSPORT_AddressLookupContext | 175 | GNUNET_TRANSPORT_AddressToStringContext |
177 | *alc) | 176 | *alc) |
178 | { | 177 | { |
179 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); | 178 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); |
diff --git a/src/transport/transport_api_peer_address_lookup.c b/src/transport/transport_api_peer_address_lookup.c index 0df922085..66af497f5 100644 --- a/src/transport/transport_api_peer_address_lookup.c +++ b/src/transport/transport_api_peer_address_lookup.c | |||
@@ -78,7 +78,7 @@ peer_address_response_processor (void *cls, | |||
78 | const struct GNUNET_MessageHeader *msg) | 78 | const struct GNUNET_MessageHeader *msg) |
79 | { | 79 | { |
80 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; | 80 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; |
81 | const char *address; | 81 | const struct GNUNET_HELLO_Address *address; |
82 | uint16_t size; | 82 | uint16_t size; |
83 | 83 | ||
84 | if (msg == NULL) | 84 | if (msg == NULL) |
@@ -94,25 +94,29 @@ peer_address_response_processor (void *cls, | |||
94 | if (size == sizeof (struct GNUNET_MessageHeader)) | 94 | if (size == sizeof (struct GNUNET_MessageHeader)) |
95 | { | 95 | { |
96 | /* done! */ | 96 | /* done! */ |
97 | alucb->cb (alucb->cb_cls, NULL); | 97 | alucb->cb (alucb->cb_cls, NULL ); |
98 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 98 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
99 | GNUNET_free (alucb); | 99 | GNUNET_free (alucb); |
100 | return; | 100 | return; |
101 | } | 101 | } |
102 | address = (const char *) &msg[1]; | 102 | address = (const struct GNUNET_HELLO_Address *) &msg[1]; |
103 | #if 0 | ||
103 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | 104 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') |
104 | { | 105 | { |
105 | /* invalid reply */ | 106 | /* invalid reply */ |
106 | GNUNET_break (0); | 107 | GNUNET_break (0); |
107 | alucb->cb (alucb->cb_cls, NULL); | 108 | alucb->cb (alucb->cb_cls, NULL ); |
108 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 109 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
109 | GNUNET_free (alucb); | 110 | GNUNET_free (alucb); |
110 | return; | 111 | return; |
111 | } | 112 | } |
113 | #endif | ||
112 | /* expect more replies */ | 114 | /* expect more replies */ |
113 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | 115 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, |
114 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | 116 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); |
115 | alucb->cb (alucb->cb_cls, address); | 117 | |
118 | /* REFACTOR FIX THIS */ | ||
119 | alucb->cb (alucb->cb_cls, address ); | ||
116 | } | 120 | } |
117 | 121 | ||
118 | 122 | ||
@@ -127,12 +131,10 @@ peer_address_response_processor (void *cls, | |||
127 | * @return handle to cancel the operation, NULL on error | 131 | * @return handle to cancel the operation, NULL on error |
128 | */ | 132 | */ |
129 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * | 133 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * |
130 | GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle | 134 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, |
131 | *cfg, | ||
132 | const struct GNUNET_PeerIdentity *peer, | 135 | const struct GNUNET_PeerIdentity *peer, |
133 | struct GNUNET_TIME_Relative timeout, | 136 | struct GNUNET_TIME_Relative timeout, |
134 | GNUNET_TRANSPORT_AddressLookUpCallback | 137 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, |
135 | peer_address_callback, | ||
136 | void *peer_address_callback_cls) | 138 | void *peer_address_callback_cls) |
137 | { | 139 | { |
138 | struct PeerAddressLookupMessage msg; | 140 | struct PeerAddressLookupMessage msg; |
@@ -147,8 +149,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle | |||
147 | msg.reserved = htonl (0); | 149 | msg.reserved = htonl (0); |
148 | msg.timeout = GNUNET_TIME_relative_hton (timeout); | 150 | msg.timeout = GNUNET_TIME_relative_hton (timeout); |
149 | memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 151 | memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
150 | alc = | 152 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); |
151 | GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); | ||
152 | alc->cb = peer_address_callback; | 153 | alc->cb = peer_address_callback; |
153 | alc->cb_cls = peer_address_callback_cls; | 154 | alc->cb_cls = peer_address_callback_cls; |
154 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 155 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
@@ -168,7 +169,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle | |||
168 | * @param alc handle for the request to cancel | 169 | * @param alc handle for the request to cancel |
169 | */ | 170 | */ |
170 | void | 171 | void |
171 | GNUNET_TRANSPORT_peer_address_lookup_cancel (struct | 172 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct |
172 | GNUNET_TRANSPORT_PeerAddressLookupContext | 173 | GNUNET_TRANSPORT_PeerAddressLookupContext |
173 | *alc) | 174 | *alc) |
174 | { | 175 | { |