diff options
Diffstat (limited to 'src/transport/plugin_transport_bluetooth.c')
-rw-r--r-- | src/transport/plugin_transport_bluetooth.c | 122 |
1 files changed, 88 insertions, 34 deletions
diff --git a/src/transport/plugin_transport_bluetooth.c b/src/transport/plugin_transport_bluetooth.c index f301d55b3..8d751f443 100644 --- a/src/transport/plugin_transport_bluetooth.c +++ b/src/transport/plugin_transport_bluetooth.c | |||
@@ -199,6 +199,11 @@ struct Session | |||
199 | struct MacEndpoint *mac; | 199 | struct MacEndpoint *mac; |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * The address for this session | ||
203 | */ | ||
204 | struct GNUNET_HELLO_Address *address; | ||
205 | |||
206 | /** | ||
202 | * Head of messages currently pending for transmission to this peer. | 207 | * Head of messages currently pending for transmission to this peer. |
203 | */ | 208 | */ |
204 | struct PendingMessage *pending_message_head; | 209 | struct PendingMessage *pending_message_head; |
@@ -355,9 +360,7 @@ struct MacEndpoint | |||
355 | /** | 360 | /** |
356 | * peer mac address | 361 | * peer mac address |
357 | */ | 362 | */ |
358 | //struct WlanAddress addr; | 363 | struct WlanAddress addr; |
359 | |||
360 | struct GNUNET_HELLO_Address *address; | ||
361 | 364 | ||
362 | /** | 365 | /** |
363 | * Message delay for fragmentation context | 366 | * Message delay for fragmentation context |
@@ -607,8 +610,8 @@ send_ack (void *cls, uint32_t msg_id, | |||
607 | get_radiotap_header (endpoint, radio_header, size); | 610 | get_radiotap_header (endpoint, radio_header, size); |
608 | get_wlan_header (endpoint->plugin, | 611 | get_wlan_header (endpoint->plugin, |
609 | &radio_header->frame, | 612 | &radio_header->frame, |
610 | endpoint->address->address, | 613 | &endpoint->addr.mac, |
611 | endpoint->address->address_length); | 614 | sizeof (endpoint->addr.mac)); |
612 | memcpy (&radio_header[1], hdr, msize); | 615 | memcpy (&radio_header[1], hdr, msize); |
613 | if (NULL != | 616 | if (NULL != |
614 | GNUNET_HELPER_send (endpoint->plugin->suid_helper, | 617 | GNUNET_HELPER_send (endpoint->plugin->suid_helper, |
@@ -682,6 +685,7 @@ free_session (struct Session *session) | |||
682 | } | 685 | } |
683 | GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# Bluetooth sessions allocated"), -1, | 686 | GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# Bluetooth sessions allocated"), -1, |
684 | GNUNET_NO); | 687 | GNUNET_NO); |
688 | GNUNET_HELLO_address_free (session->address); | ||
685 | GNUNET_free (session); | 689 | GNUNET_free (session); |
686 | } | 690 | } |
687 | 691 | ||
@@ -736,6 +740,8 @@ create_session (struct MacEndpoint *endpoint, | |||
736 | GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head, | 740 | GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head, |
737 | endpoint->sessions_tail, | 741 | endpoint->sessions_tail, |
738 | session); | 742 | session); |
743 | session->address = GNUNET_HELLO_address_allocate (peer, PLUGIN_NAME, | ||
744 | &endpoint->addr, sizeof (endpoint->addr), GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
739 | session->mac = endpoint; | 745 | session->mac = endpoint; |
740 | session->target = *peer; | 746 | session->target = *peer; |
741 | session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 747 | session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
@@ -744,12 +750,35 @@ create_session (struct MacEndpoint *endpoint, | |||
744 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 750 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
745 | "Created new session for peer `%s' with endpoint %s\n", | 751 | "Created new session for peer `%s' with endpoint %s\n", |
746 | GNUNET_i2s (peer), | 752 | GNUNET_i2s (peer), |
747 | mac_to_string (endpoint->address->address)); | 753 | mac_to_string (&endpoint->addr.mac)); |
748 | return session; | 754 | return session; |
749 | } | 755 | } |
750 | 756 | ||
751 | 757 | ||
752 | /** | 758 | /** |
759 | * Lookup a new session | ||
760 | * | ||
761 | * @param endpoint pointer to the mac endpoint of the peer | ||
762 | * @param peer peer identity to use for this session | ||
763 | * @return returns the session or NULL | ||
764 | */ | ||
765 | static struct Session * | ||
766 | lookup_session (struct MacEndpoint *endpoint, | ||
767 | const struct GNUNET_PeerIdentity *peer) | ||
768 | { | ||
769 | struct Session *session; | ||
770 | |||
771 | for (session = endpoint->sessions_head; NULL != session; session = session->next) | ||
772 | if (0 == memcmp (peer, &session->target, sizeof (struct GNUNET_PeerIdentity))) | ||
773 | { | ||
774 | session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
775 | return session; | ||
776 | } | ||
777 | return NULL; | ||
778 | } | ||
779 | |||
780 | |||
781 | /** | ||
753 | * Function called once we have successfully given the fragment | 782 | * Function called once we have successfully given the fragment |
754 | * message to the SUID helper process and we are thus ready for | 783 | * message to the SUID helper process and we are thus ready for |
755 | * the next fragment. | 784 | * the next fragment. |
@@ -795,8 +824,8 @@ transmit_fragment (void *cls, | |||
795 | get_radiotap_header (endpoint, radio_header, size); | 824 | get_radiotap_header (endpoint, radio_header, size); |
796 | get_wlan_header (endpoint->plugin, | 825 | get_wlan_header (endpoint->plugin, |
797 | &radio_header->frame, | 826 | &radio_header->frame, |
798 | endpoint->address->address, | 827 | &endpoint->addr.mac, |
799 | endpoint->address->address_length); | 828 | sizeof (endpoint->addr.mac)); |
800 | memcpy (&radio_header[1], hdr, msize); | 829 | memcpy (&radio_header[1], hdr, msize); |
801 | GNUNET_assert (NULL == fm->sh); | 830 | GNUNET_assert (NULL == fm->sh); |
802 | fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, | 831 | fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, |
@@ -996,16 +1025,15 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
996 | */ | 1025 | */ |
997 | static struct MacEndpoint * | 1026 | static struct MacEndpoint * |
998 | create_macendpoint (struct Plugin *plugin, | 1027 | create_macendpoint (struct Plugin *plugin, |
999 | const struct WlanAddress *addr) | 1028 | struct WlanAddress *addr) |
1000 | { | 1029 | { |
1001 | struct MacEndpoint *pos; | 1030 | struct MacEndpoint *pos; |
1002 | 1031 | ||
1003 | for (pos = plugin->mac_head; NULL != pos; pos = pos->next) | 1032 | for (pos = plugin->mac_head; NULL != pos; pos = pos->next) |
1004 | if (0 == memcmp (addr, &pos->address->address, sizeof (struct WlanAddress))) | 1033 | if (0 == memcmp (addr, &pos->addr, sizeof (struct WlanAddress))) |
1005 | return pos; | 1034 | return pos; |
1006 | pos = GNUNET_new (struct MacEndpoint); | 1035 | pos = GNUNET_new (struct MacEndpoint); |
1007 | pos->address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, addr, | 1036 | pos->addr = (*addr); |
1008 | sizeof (struct WlanAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1009 | pos->plugin = plugin; | 1037 | pos->plugin = plugin; |
1010 | pos->defrag = | 1038 | pos->defrag = |
1011 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, | 1039 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, |
@@ -1049,6 +1077,24 @@ bluetooth_get_network (void *cls, | |||
1049 | 1077 | ||
1050 | 1078 | ||
1051 | /** | 1079 | /** |
1080 | * Look up a session for a peer and create a new session if none is found | ||
1081 | * | ||
1082 | * @param endpoint pointer to the mac endpoint of the peer | ||
1083 | * @param peer peer identity to use for this session | ||
1084 | * @return returns the session | ||
1085 | */ | ||
1086 | static struct Session * | ||
1087 | get_session (struct MacEndpoint *endpoint, | ||
1088 | const struct GNUNET_PeerIdentity *peer) | ||
1089 | { | ||
1090 | struct Session *session; | ||
1091 | if (NULL != (session = lookup_session (endpoint, peer))) | ||
1092 | return session; | ||
1093 | return create_session (endpoint, peer); | ||
1094 | } | ||
1095 | |||
1096 | |||
1097 | /** | ||
1052 | * Creates a new outbound session the transport service will use to send data to the | 1098 | * Creates a new outbound session the transport service will use to send data to the |
1053 | * peer | 1099 | * peer |
1054 | * | 1100 | * |
@@ -1074,8 +1120,8 @@ bluetooth_plugin_get_session (void *cls, | |||
1074 | "Service asked to create session for peer `%s' with MAC `%s'\n", | 1120 | "Service asked to create session for peer `%s' with MAC `%s'\n", |
1075 | GNUNET_i2s (&address->peer), | 1121 | GNUNET_i2s (&address->peer), |
1076 | bluetooth_plugin_address_to_string(NULL, address->address, address->address_length)); | 1122 | bluetooth_plugin_address_to_string(NULL, address->address, address->address_length)); |
1077 | endpoint = create_macendpoint (plugin, address->address); | 1123 | endpoint = create_macendpoint (plugin, (struct WlanAddress *) address->address); |
1078 | return create_session (endpoint, &address->peer); | 1124 | return get_session (endpoint, &address->peer); |
1079 | } | 1125 | } |
1080 | 1126 | ||
1081 | 1127 | ||
@@ -1217,6 +1263,7 @@ static int | |||
1217 | process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 1263 | process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
1218 | { | 1264 | { |
1219 | struct Plugin *plugin = cls; | 1265 | struct Plugin *plugin = cls; |
1266 | struct GNUNET_HELLO_Address *address; | ||
1220 | struct MacAndSession *mas = client; | 1267 | struct MacAndSession *mas = client; |
1221 | struct MacAndSession xmas; | 1268 | struct MacAndSession xmas; |
1222 | struct GNUNET_ATS_Information ats; | 1269 | struct GNUNET_ATS_Information ats; |
@@ -1243,24 +1290,31 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1243 | GNUNET_break_op (0); | 1290 | GNUNET_break_op (0); |
1244 | break; | 1291 | break; |
1245 | } | 1292 | } |
1293 | if (NULL == mas->endpoint) | ||
1294 | { | ||
1295 | GNUNET_break (0); | ||
1296 | break; | ||
1297 | } | ||
1298 | |||
1246 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1299 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1247 | "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", | 1300 | "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", |
1248 | (unsigned int) msize, | 1301 | (unsigned int) msize, |
1249 | GNUNET_i2s (&tmpsource), | 1302 | GNUNET_i2s (&tmpsource), |
1250 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address, | 1303 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, |
1251 | mas->endpoint->address->address_length)); | 1304 | sizeof (mas->endpoint->addr))); |
1252 | 1305 | ||
1253 | GNUNET_STATISTICS_update (plugin->env->stats, | 1306 | GNUNET_STATISTICS_update (plugin->env->stats, |
1254 | _("# HELLO messages received via Bluetooth"), 1, | 1307 | _("# HELLO messages received via Bluetooth"), 1, |
1255 | GNUNET_NO); | 1308 | GNUNET_NO); |
1309 | |||
1310 | address = GNUNET_HELLO_address_allocate (&tmpsource, PLUGIN_NAME, | ||
1311 | &mas->endpoint->addr, sizeof (mas->endpoint->addr), | ||
1312 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | ||
1256 | plugin->env->receive (plugin->env->cls, | 1313 | plugin->env->receive (plugin->env->cls, |
1257 | mas->endpoint->address, | 1314 | address, mas->session, hdr); |
1258 | mas->session, | ||
1259 | hdr); | ||
1260 | plugin->env->update_address_metrics (plugin->env->cls, | 1315 | plugin->env->update_address_metrics (plugin->env->cls, |
1261 | mas->endpoint->address, | 1316 | address, mas->session, &ats, 1); |
1262 | mas->session, | 1317 | GNUNET_HELLO_address_free (address); |
1263 | &ats, 1); | ||
1264 | break; | 1318 | break; |
1265 | case GNUNET_MESSAGE_TYPE_FRAGMENT: | 1319 | case GNUNET_MESSAGE_TYPE_FRAGMENT: |
1266 | if (NULL == mas->endpoint) | 1320 | if (NULL == mas->endpoint) |
@@ -1271,8 +1325,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1271 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1325 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1272 | "Processing %u bytes of FRAGMENT from MAC %s\n", | 1326 | "Processing %u bytes of FRAGMENT from MAC %s\n", |
1273 | (unsigned int) msize, | 1327 | (unsigned int) msize, |
1274 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, | 1328 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, |
1275 | mas->endpoint->address->address_length)); | 1329 | sizeof (mas->endpoint->addr))); |
1276 | GNUNET_STATISTICS_update (plugin->env->stats, | 1330 | GNUNET_STATISTICS_update (plugin->env->stats, |
1277 | _("# fragments received via Bluetooth"), 1, GNUNET_NO); | 1331 | _("# fragments received via Bluetooth"), 1, GNUNET_NO); |
1278 | (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, | 1332 | (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, |
@@ -1293,8 +1347,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1293 | { | 1347 | { |
1294 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1348 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1295 | "Got last ACK, finished message transmission to `%s' (%p)\n", | 1349 | "Got last ACK, finished message transmission to `%s' (%p)\n", |
1296 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, | 1350 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, |
1297 | mas->endpoint->address->address_length), | 1351 | sizeof (mas->endpoint->addr)), |
1298 | fm); | 1352 | fm); |
1299 | mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); | 1353 | mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); |
1300 | if (NULL != fm->cont) | 1354 | if (NULL != fm->cont) |
@@ -1309,15 +1363,15 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1309 | { | 1363 | { |
1310 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1364 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1311 | "Got an ACK, message transmission to `%s' not yet finished\n", | 1365 | "Got an ACK, message transmission to `%s' not yet finished\n", |
1312 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, | 1366 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, |
1313 | mas->endpoint->address->address_length)); | 1367 | sizeof (mas->endpoint->addr))); |
1314 | break; | 1368 | break; |
1315 | } | 1369 | } |
1316 | } | 1370 | } |
1317 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1371 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1318 | "ACK not matched against any active fragmentation with MAC `%s'\n", | 1372 | "ACK not matched against any active fragmentation with MAC `%s'\n", |
1319 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, | 1373 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, |
1320 | mas->endpoint->address->address_length)); | 1374 | sizeof (mas->endpoint->addr))); |
1321 | break; | 1375 | break; |
1322 | case GNUNET_MESSAGE_TYPE_WLAN_DATA: | 1376 | case GNUNET_MESSAGE_TYPE_WLAN_DATA: |
1323 | if (NULL == mas->endpoint) | 1377 | if (NULL == mas->endpoint) |
@@ -1377,11 +1431,11 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1377 | (unsigned int) ntohs (hdr->type), | 1431 | (unsigned int) ntohs (hdr->type), |
1378 | GNUNET_i2s (&mas->session->target)); | 1432 | GNUNET_i2s (&mas->session->target)); |
1379 | plugin->env->receive (plugin->env->cls, | 1433 | plugin->env->receive (plugin->env->cls, |
1380 | mas->endpoint->address, | 1434 | mas->session->address, |
1381 | mas->session, | 1435 | mas->session, |
1382 | hdr); | 1436 | hdr); |
1383 | plugin->env->update_address_metrics (plugin->env->cls, | 1437 | plugin->env->update_address_metrics (plugin->env->cls, |
1384 | mas->endpoint->address, | 1438 | mas->session->address, |
1385 | mas->session, | 1439 | mas->session, |
1386 | &ats, 1); | 1440 | &ats, 1); |
1387 | break; | 1441 | break; |