aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-25 14:35:47 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-25 14:35:47 +0000
commited7ff13ae92bbe0b10e35fc5be68611611ff87f9 (patch)
tree753b21102cb4bb0b3f0d056c3001b6d8a441cc90 /src
parent52d396bb08d5621f7c0af2920a373d87d321cb63 (diff)
downloadgnunet-ed7ff13ae92bbe0b10e35fc5be68611611ff87f9.tar.gz
gnunet-ed7ff13ae92bbe0b10e35fc5be68611611ff87f9.zip
-adding missing API functions to WLAN, skeleton for monitoring support
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_http_server.c6
-rw-r--r--src/transport/plugin_transport_wlan.c400
2 files changed, 279 insertions, 127 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index ab6b0d1da..30a209a6b 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -3228,8 +3228,8 @@ http_server_plugin_address_to_string (void *cls,
3228 * @return the network type in HBO or #GNUNET_SYSERR 3228 * @return the network type in HBO or #GNUNET_SYSERR
3229 */ 3229 */
3230static enum GNUNET_ATS_Network_Type 3230static enum GNUNET_ATS_Network_Type
3231http_server_get_network (void *cls, 3231http_server_plugin_get_network (void *cls,
3232 struct Session *session) 3232 struct Session *session)
3233{ 3233{
3234 return ntohl (session->ats_address_network_type); 3234 return ntohl (session->ats_address_network_type);
3235} 3235}
@@ -3363,7 +3363,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3363 api->address_to_string = &http_server_plugin_address_to_string; 3363 api->address_to_string = &http_server_plugin_address_to_string;
3364 api->string_to_address = &http_common_plugin_string_to_address; 3364 api->string_to_address = &http_common_plugin_string_to_address;
3365 api->address_pretty_printer = &http_common_plugin_address_pretty_printer; 3365 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
3366 api->get_network = &http_server_get_network; 3366 api->get_network = &http_server_plugin_get_network;
3367 api->update_session_timeout = &http_server_plugin_update_session_timeout; 3367 api->update_session_timeout = &http_server_plugin_update_session_timeout;
3368 api->update_inbound_delay = &http_server_plugin_update_inbound_delay; 3368 api->update_inbound_delay = &http_server_plugin_update_inbound_delay;
3369 api->setup_monitor = &http_server_plugin_setup_monitor; 3369 api->setup_monitor = &http_server_plugin_setup_monitor;
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 3647f1ea9..5aaa66c1e 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -107,10 +107,19 @@ struct WlanHeader
107}; 107};
108 108
109 109
110/**
111 * Address format for WLAN.
112 */
110struct WlanAddress 113struct WlanAddress
111{ 114{
115 /**
116 * Options set for the WLAN, in NBO.
117 */
112 uint32_t options GNUNET_PACKED; 118 uint32_t options GNUNET_PACKED;
113 119
120 /**
121 * WLAN addresses using MACs.
122 */
114 struct GNUNET_TRANSPORT_WLAN_MacAddress mac; 123 struct GNUNET_TRANSPORT_WLAN_MacAddress mac;
115}; 124};
116 125
@@ -147,7 +156,7 @@ struct PendingMessage
147 GNUNET_TRANSPORT_TransmitContinuation transmit_cont; 156 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
148 157
149 /** 158 /**
150 * Cls for transmit_cont 159 * Cls for @e transmit_cont
151 */ 160 */
152 void *transmit_cont_cls; 161 void *transmit_cont_cls;
153 162
@@ -211,6 +220,17 @@ struct Session
211 * Timeout task (for the session). 220 * Timeout task (for the session).
212 */ 221 */
213 GNUNET_SCHEDULER_TaskIdentifier timeout_task; 222 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
223
224 /**
225 * Number of bytes waiting for transmission to this peer.
226 */
227 unsigned long long bytes_in_queue;
228
229 /**
230 * Number of messages waiting for transmission to this peer.
231 */
232 unsigned int msgs_in_queue;
233
214}; 234};
215 235
216 236
@@ -394,10 +414,20 @@ struct Plugin
394 struct GNUNET_HELPER_Handle *suid_helper; 414 struct GNUNET_HELPER_Handle *suid_helper;
395 415
396 /** 416 /**
417 * Function to call about session status changes.
418 */
419 GNUNET_TRANSPORT_SessionInfoCallback sic;
420
421 /**
422 * Closure for @e sic.
423 */
424 void *sic_cls;
425
426 /**
397 * ARGV-vector for the helper (all helpers take only the binary 427 * ARGV-vector for the helper (all helpers take only the binary
398 * name, one actual argument, plus the NULL terminator for 'argv'). 428 * name, one actual argument, plus the NULL terminator for 'argv').
399 */ 429 */
400 char * helper_argv[3]; 430 char *helper_argv[3];
401 431
402 /** 432 /**
403 * The interface of the wlan card given to us by the user. 433 * The interface of the wlan card given to us by the user.
@@ -430,11 +460,6 @@ struct Plugin
430 struct MacEndpoint *mac_tail; 460 struct MacEndpoint *mac_tail;
431 461
432 /** 462 /**
433 * Number of connections
434 */
435 unsigned int mac_count;
436
437 /**
438 * Task that periodically sends a HELLO beacon via the helper. 463 * Task that periodically sends a HELLO beacon via the helper.
439 */ 464 */
440 GNUNET_SCHEDULER_TaskIdentifier beacon_task; 465 GNUNET_SCHEDULER_TaskIdentifier beacon_task;
@@ -455,6 +480,11 @@ struct Plugin
455 int have_mac; 480 int have_mac;
456 481
457 /** 482 /**
483 * Number of connections
484 */
485 unsigned int mac_count;
486
487 /**
458 * Options for addresses 488 * Options for addresses
459 */ 489 */
460 uint32_t options; 490 uint32_t options;
@@ -480,6 +510,28 @@ struct MacAndSession
480 struct MacEndpoint *endpoint; 510 struct MacEndpoint *endpoint;
481}; 511};
482 512
513
514/**
515 * Print MAC addresses nicely.
516 *
517 * @param mac the mac address
518 * @return string to a static buffer with the human-readable mac, will be overwritten during the next call to this function
519 */
520static const char *
521mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac)
522{
523 static char macstr[20];
524
525 GNUNET_snprintf (macstr,
526 sizeof (macstr),
527 "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
528 mac->mac[0], mac->mac[1],
529 mac->mac[2], mac->mac[3],
530 mac->mac[4], mac->mac[5]);
531 return macstr;
532}
533
534
483/** 535/**
484 * Function called for a quick conversion of the binary address to 536 * Function called for a quick conversion of the binary address to
485 * a numeric address. Note that the caller must not free the 537 * a numeric address. Note that the caller must not free the
@@ -492,23 +544,57 @@ struct MacAndSession
492 * @return string representing the same address 544 * @return string representing the same address
493 */ 545 */
494static const char * 546static const char *
495wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen); 547wlan_plugin_address_to_string (void *cls,
548 const void *addr,
549 size_t addrlen)
550{
551 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
552 static char macstr[36];
553
554 if (sizeof (struct WlanAddress) != addrlen)
555 {
556 GNUNET_break (0);
557 return NULL;
558 }
559 mac = &((struct WlanAddress *) addr)->mac;
560 GNUNET_snprintf (macstr,
561 sizeof (macstr),
562 "%s.%u.%s",
563 PLUGIN_NAME,
564 ntohl (((struct WlanAddress *) addr)->options),
565 mac_to_string (mac));
566 return macstr;
567}
568
496 569
497/** 570/**
498 * Print MAC addresses nicely. 571 * If a session monitor is attached, notify it about the new
572 * session state.
499 * 573 *
500 * @param mac the mac address 574 * @param plugin our plugin
501 * @return string to a static buffer with the human-readable mac, will be overwritten during the next call to this function 575 * @param session session that changed state
576 * @param state new state of the session
502 */ 577 */
503static const char * 578static void
504mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac) 579notify_session_monitor (struct Plugin *plugin,
580 struct Session *session,
581 enum GNUNET_TRANSPORT_SessionState state)
505{ 582{
506 static char macstr[20]; 583 struct GNUNET_TRANSPORT_SessionInfo info;
507 584
508 GNUNET_snprintf (macstr, sizeof (macstr), "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 585 if (NULL == plugin->sic)
509 mac->mac[0], mac->mac[1], 586 return;
510 mac->mac[2], mac->mac[3], mac->mac[4], mac->mac[5]); 587 memset (&info, 0, sizeof (info));
511 return macstr; 588 info.state = state;
589 info.is_inbound = GNUNET_SYSERR; /* hard to say */
590 // info.num_msg_pending = session->msgs_in_queue; // FIXME
591 // info.num_bytes_pending = session->bytes_in_queue; // FIXME
592 info.receive_delay = GNUNET_TIME_UNIT_ZERO_ABS;
593 info.session_timeout = session->timeout;
594 info.address = session->address; // ?
595 plugin->sic (plugin->sic_cls,
596 session,
597 &info);
512} 598}
513 599
514 600
@@ -573,7 +659,7 @@ get_wlan_header (struct Plugin *plugin,
573/** 659/**
574 * Send an ACK for a fragment we received. 660 * Send an ACK for a fragment we received.
575 * 661 *
576 * @param cls the 'struct MacEndpoint' the ACK must be sent to 662 * @param cls the `struct MacEndpoint *` the ACK must be sent to
577 * @param msg_id id of the message 663 * @param msg_id id of the message
578 * @param hdr pointer to the hdr where the ack is stored 664 * @param hdr pointer to the hdr where the ack is stored
579 */ 665 */
@@ -612,7 +698,8 @@ send_ack (void *cls, uint32_t msg_id,
612 &radio_header->header, 698 &radio_header->header,
613 GNUNET_NO /* dropping ACKs is bad */, 699 GNUNET_NO /* dropping ACKs is bad */,
614 NULL, NULL)) 700 NULL, NULL))
615 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN ACKs sent"), 701 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
702 _("# WLAN ACKs sent"),
616 1, GNUNET_NO); 703 1, GNUNET_NO);
617} 704}
618 705
@@ -624,7 +711,8 @@ send_ack (void *cls, uint32_t msg_id,
624 * @param hdr pointer to the data 711 * @param hdr pointer to the data
625 */ 712 */
626static void 713static void
627wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr) 714wlan_data_message_handler (void *cls,
715 const struct GNUNET_MessageHeader *hdr)
628{ 716{
629 struct MacEndpoint *endpoint = cls; 717 struct MacEndpoint *endpoint = cls;
630 struct Plugin *plugin = endpoint->plugin; 718 struct Plugin *plugin = endpoint->plugin;
@@ -662,7 +750,8 @@ wlan_plugin_disconnect_session (void *cls,
662 while (NULL != (pm = session->pending_message_head)) 750 while (NULL != (pm = session->pending_message_head))
663 { 751 {
664 GNUNET_CONTAINER_DLL_remove (session->pending_message_head, 752 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
665 session->pending_message_tail, pm); 753 session->pending_message_tail,
754 pm);
666 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task) 755 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task)
667 { 756 {
668 GNUNET_SCHEDULER_cancel (pm->timeout_task); 757 GNUNET_SCHEDULER_cancel (pm->timeout_task);
@@ -690,7 +779,7 @@ wlan_plugin_disconnect_session (void *cls,
690 779
691/** 780/**
692 * Function that is called to get the keepalive factor. 781 * Function that is called to get the keepalive factor.
693 * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to 782 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
694 * calculate the interval between keepalive packets. 783 * calculate the interval between keepalive packets.
695 * 784 *
696 * @param cls closure with the `struct Plugin` 785 * @param cls closure with the `struct Plugin`
@@ -710,21 +799,24 @@ wlan_plugin_query_keepalive_factor (void *cls)
710 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext 799 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
711 */ 800 */
712static void 801static void
713session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 802session_timeout (void *cls,
803 const struct GNUNET_SCHEDULER_TaskContext *tc)
714{ 804{
715 struct Session *session = cls; 805 struct Session *session = cls;
716 struct GNUNET_TIME_Relative timeout; 806 struct GNUNET_TIME_Relative left;
717 807
718 session->timeout_task = GNUNET_SCHEDULER_NO_TASK; 808 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
719 timeout = GNUNET_TIME_absolute_get_remaining (session->timeout); 809 left = GNUNET_TIME_absolute_get_remaining (session->timeout);
720 if (0 == timeout.rel_value_us) 810 if (0 != left.rel_value_us)
721 { 811 {
722 wlan_plugin_disconnect_session (session->mac->plugin, 812 session->timeout_task =
813 GNUNET_SCHEDULER_add_delayed (left,
814 &session_timeout,
723 session); 815 session);
724 return; 816 return;
725 } 817 }
726 session->timeout_task = 818 wlan_plugin_disconnect_session (session->mac->plugin,
727 GNUNET_SCHEDULER_add_delayed (timeout, &session_timeout, session); 819 session);
728} 820}
729 821
730 822
@@ -744,13 +836,11 @@ lookup_session (struct MacEndpoint *endpoint,
744 836
745 for (session = endpoint->sessions_head; NULL != session; session = session->next) 837 for (session = endpoint->sessions_head; NULL != session; session = session->next)
746 if (0 == memcmp (peer, &session->target, sizeof (struct GNUNET_PeerIdentity))) 838 if (0 == memcmp (peer, &session->target, sizeof (struct GNUNET_PeerIdentity)))
747 {
748 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
749 return session; 839 return session;
750 }
751 return NULL; 840 return NULL;
752} 841}
753 842
843
754/** 844/**
755 * Create a new session 845 * Create a new session
756 * 846 *
@@ -764,20 +854,25 @@ create_session (struct MacEndpoint *endpoint,
764{ 854{
765 struct Session *session; 855 struct Session *session;
766 856
767 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), 1, 857 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
858 _("# WLAN sessions allocated"),
859 1,
768 GNUNET_NO); 860 GNUNET_NO);
769 session = GNUNET_new (struct Session); 861 session = GNUNET_new (struct Session);
770 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head, 862 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
771 endpoint->sessions_tail, 863 endpoint->sessions_tail,
772 session); 864 session);
773 session->address = GNUNET_HELLO_address_allocate (peer, PLUGIN_NAME, 865 session->address = GNUNET_HELLO_address_allocate (peer,
774 &endpoint->wlan_addr, sizeof (endpoint->wlan_addr), 866 PLUGIN_NAME,
775 GNUNET_HELLO_ADDRESS_INFO_NONE); 867 &endpoint->wlan_addr,
868 sizeof (endpoint->wlan_addr),
869 GNUNET_HELLO_ADDRESS_INFO_NONE);
776 session->mac = endpoint; 870 session->mac = endpoint;
777 session->target = *peer; 871 session->target = *peer;
778 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 872 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
779 session->timeout_task = 873 session->timeout_task =
780 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); 874 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout,
875 session);
781 LOG (GNUNET_ERROR_TYPE_DEBUG, 876 LOG (GNUNET_ERROR_TYPE_DEBUG,
782 "Created new session %p for peer `%s' with endpoint %s\n", 877 "Created new session %p for peer `%s' with endpoint %s\n",
783 session, 878 session,
@@ -797,11 +892,12 @@ create_session (struct MacEndpoint *endpoint,
797 */ 892 */
798static struct Session * 893static struct Session *
799get_session (struct MacEndpoint *endpoint, 894get_session (struct MacEndpoint *endpoint,
800 const struct GNUNET_PeerIdentity *peer) 895 const struct GNUNET_PeerIdentity *peer)
801{ 896{
802 struct Session *session; 897 struct Session *session;
898
803 if (NULL != (session = lookup_session (endpoint, peer))) 899 if (NULL != (session = lookup_session (endpoint, peer)))
804 return session; 900 return session;
805 return create_session (endpoint, peer); 901 return create_session (endpoint, peer);
806} 902}
807 903
@@ -811,7 +907,7 @@ get_session (struct MacEndpoint *endpoint,
811 * message to the SUID helper process and we are thus ready for 907 * message to the SUID helper process and we are thus ready for
812 * the next fragment. 908 * the next fragment.
813 * 909 *
814 * @param cls the 'struct FragmentMessage' 910 * @param cls the `struct FragmentMessage *`
815 * @param result result of the operation (#GNUNET_OK on success, #GNUNET_NO if the helper died, #GNUNET_SYSERR 911 * @param result result of the operation (#GNUNET_OK on success, #GNUNET_NO if the helper died, #GNUNET_SYSERR
816 * if the helper was stopped) 912 * if the helper was stopped)
817 */ 913 */
@@ -830,7 +926,7 @@ fragment_transmission_done (void *cls,
830/** 926/**
831 * Transmit a fragment of a message. 927 * Transmit a fragment of a message.
832 * 928 *
833 * @param cls 'struct FragmentMessage' this fragment message belongs to 929 * @param cls `struct FragmentMessage *` this fragment message belongs to
834 * @param hdr pointer to the start of the fragment message 930 * @param hdr pointer to the start of the fragment message
835 */ 931 */
836static void 932static void
@@ -928,7 +1024,11 @@ fragmentmessage_timeout (void *cls,
928 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1024 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
929 if (NULL != fm->cont) 1025 if (NULL != fm->cont)
930 { 1026 {
931 fm->cont (fm->cont_cls, &fm->target, GNUNET_SYSERR, fm->size_payload, fm->size_on_wire); 1027 fm->cont (fm->cont_cls,
1028 &fm->target,
1029 GNUNET_SYSERR,
1030 fm->size_payload,
1031 fm->size_on_wire);
932 fm->cont = NULL; 1032 fm->cont = NULL;
933 } 1033 }
934 free_fragment_message (fm); 1034 free_fragment_message (fm);
@@ -947,7 +1047,7 @@ fragmentmessage_timeout (void *cls,
947 * been transmitted (or if the transport is ready 1047 * been transmitted (or if the transport is ready
948 * for the next transmission call; or if the 1048 * for the next transmission call; or if the
949 * peer disconnected...); can be NULL 1049 * peer disconnected...); can be NULL
950 * @param cont_cls closure for cont 1050 * @param cont_cls closure for @a cont
951 */ 1051 */
952static void 1052static void
953send_with_fragmentation (struct MacEndpoint *endpoint, 1053send_with_fragmentation (struct MacEndpoint *endpoint,
@@ -955,7 +1055,8 @@ send_with_fragmentation (struct MacEndpoint *endpoint,
955 const struct GNUNET_PeerIdentity *target, 1055 const struct GNUNET_PeerIdentity *target,
956 const struct GNUNET_MessageHeader *msg, 1056 const struct GNUNET_MessageHeader *msg,
957 size_t payload_size, 1057 size_t payload_size,
958 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 1058 GNUNET_TRANSPORT_TransmitContinuation cont,
1059 void *cont_cls)
959 1060
960{ 1061{
961 struct FragmentMessage *fm; 1062 struct FragmentMessage *fm;
@@ -1000,7 +1101,9 @@ free_macendpoint (struct MacEndpoint *endpoint)
1000 struct Session *session; 1101 struct Session *session;
1001 1102
1002 GNUNET_STATISTICS_update (plugin->env->stats, 1103 GNUNET_STATISTICS_update (plugin->env->stats,
1003 _("# WLAN MAC endpoints allocated"), -1, GNUNET_NO); 1104 _("# WLAN MAC endpoints allocated"),
1105 -1,
1106 GNUNET_NO);
1004 while (NULL != (session = endpoint->sessions_head)) 1107 while (NULL != (session = endpoint->sessions_head))
1005 wlan_plugin_disconnect_session (plugin, 1108 wlan_plugin_disconnect_session (plugin,
1006 session); 1109 session);
@@ -1029,11 +1132,12 @@ free_macendpoint (struct MacEndpoint *endpoint)
1029/** 1132/**
1030 * A MAC endpoint is timing out. Clean up. 1133 * A MAC endpoint is timing out. Clean up.
1031 * 1134 *
1032 * @param cls pointer to the MacEndpoint 1135 * @param cls pointer to the `struct MacEndpoint`
1033 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext 1136 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
1034 */ 1137 */
1035static void 1138static void
1036macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1139macendpoint_timeout (void *cls,
1140 const struct GNUNET_SCHEDULER_TaskContext *tc)
1037{ 1141{
1038 struct MacEndpoint *endpoint = cls; 1142 struct MacEndpoint *endpoint = cls;
1039 struct GNUNET_TIME_Relative timeout; 1143 struct GNUNET_TIME_Relative timeout;
@@ -1046,7 +1150,8 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1046 return; 1150 return;
1047 } 1151 }
1048 endpoint->timeout_task = 1152 endpoint->timeout_task =
1049 GNUNET_SCHEDULER_add_delayed (timeout, &macendpoint_timeout, 1153 GNUNET_SCHEDULER_add_delayed (timeout,
1154 &macendpoint_timeout,
1050 endpoint); 1155 endpoint);
1051} 1156}
1052 1157
@@ -1059,7 +1164,8 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1059 * @return handle to our data structure for this MAC 1164 * @return handle to our data structure for this MAC
1060 */ 1165 */
1061static struct MacEndpoint * 1166static struct MacEndpoint *
1062create_macendpoint (struct Plugin *plugin, struct WlanAddress *mac) 1167create_macendpoint (struct Plugin *plugin,
1168 struct WlanAddress *mac)
1063{ 1169{
1064 struct MacEndpoint *pos; 1170 struct MacEndpoint *pos;
1065 1171
@@ -1106,24 +1212,23 @@ create_macendpoint (struct Plugin *plugin, struct WlanAddress *mac)
1106/** 1212/**
1107 * Function obtain the network type for a session 1213 * Function obtain the network type for a session
1108 * 1214 *
1109 * @param cls closure ('struct Plugin*') 1215 * @param cls closure (`struct Plugin*`)
1110 * @param session the session 1216 * @param session the session
1111 * @return the network type in HBO or GNUNET_SYSERR 1217 * @return the network type in HBO or #GNUNET_SYSERR
1112 */ 1218 */
1113static enum GNUNET_ATS_Network_Type 1219static enum GNUNET_ATS_Network_Type
1114wlan_get_network (void *cls, 1220wlan_plugin_get_network (void *cls,
1115 struct Session *session) 1221 struct Session *session)
1116{ 1222{
1117 GNUNET_assert (NULL != session);
1118 return GNUNET_ATS_NET_WLAN; 1223 return GNUNET_ATS_NET_WLAN;
1119} 1224}
1120 1225
1121 1226
1122/** 1227/**
1123 * Creates a new outbound session the transport service will use to send data to the 1228 * Creates a new outbound session the transport service will use to
1124 * peer 1229 * send data to the peer
1125 * 1230 *
1126 * @param cls the plugin 1231 * @param cls the `struct Plugin *`
1127 * @param address the address 1232 * @param address the address
1128 * @return the session or NULL of max connections exceeded 1233 * @return the session or NULL of max connections exceeded
1129 */ 1234 */
@@ -1190,7 +1295,7 @@ wlan_plugin_disconnect_peer (void *cls,
1190 * @param cls closure 1295 * @param cls closure
1191 * @param session which session must be used 1296 * @param session which session must be used
1192 * @param msgbuf the message to transmit 1297 * @param msgbuf the message to transmit
1193 * @param msgbuf_size number of bytes in 'msgbuf' 1298 * @param msgbuf_size number of bytes in @a msgbuf
1194 * @param priority how important is the message (most plugins will 1299 * @param priority how important is the message (most plugins will
1195 * ignore message priority and just FIFO) 1300 * ignore message priority and just FIFO)
1196 * @param to how long to wait at most for the transmission (does not 1301 * @param to how long to wait at most for the transmission (does not
@@ -1201,7 +1306,7 @@ wlan_plugin_disconnect_peer (void *cls,
1201 * been transmitted (or if the transport is ready 1306 * been transmitted (or if the transport is ready
1202 * for the next transmission call; or if the 1307 * for the next transmission call; or if the
1203 * peer disconnected...); can be NULL 1308 * peer disconnected...); can be NULL
1204 * @param cont_cls closure for cont 1309 * @param cont_cls closure for @a cont
1205 * @return number of bytes used (on the physical network, with overheads); 1310 * @return number of bytes used (on the physical network, with overheads);
1206 * -1 on hard errors (i.e. address invalid); 0 is a legal value 1311 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1207 * and does NOT mean that the message was not transmitted (DV) 1312 * and does NOT mean that the message was not transmitted (DV)
@@ -1256,7 +1361,9 @@ wlan_plugin_send (void *cls,
1256 * @param hdr start of the message 1361 * @param hdr start of the message
1257 */ 1362 */
1258static int 1363static int
1259process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) 1364process_data (void *cls,
1365 void *client,
1366 const struct GNUNET_MessageHeader *hdr)
1260{ 1367{
1261 struct Plugin *plugin = cls; 1368 struct Plugin *plugin = cls;
1262 struct GNUNET_HELLO_Address *address; 1369 struct GNUNET_HELLO_Address *address;
@@ -1405,27 +1512,32 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1405 break; 1512 break;
1406 } 1513 }
1407 xmas.endpoint = mas->endpoint; 1514 xmas.endpoint = mas->endpoint;
1408 if (NULL == (xmas.session = lookup_session (mas->endpoint, &wlanheader->sender))) 1515 if (NULL == (xmas.session = lookup_session (mas->endpoint,
1516 &wlanheader->sender)))
1409 { 1517 {
1410 xmas.session = create_session (mas->endpoint, &wlanheader->sender); 1518 xmas.session = create_session (mas->endpoint, &wlanheader->sender);
1411 address = GNUNET_HELLO_address_allocate (&wlanheader->sender, PLUGIN_NAME, 1519 address = GNUNET_HELLO_address_allocate (&wlanheader->sender,
1412 &mas->endpoint->wlan_addr, sizeof (struct WlanAddress), 1520 PLUGIN_NAME,
1413 GNUNET_HELLO_ADDRESS_INFO_NONE); 1521 &mas->endpoint->wlan_addr,
1522 sizeof (struct WlanAddress),
1523 GNUNET_HELLO_ADDRESS_INFO_NONE);
1414 plugin->env->session_start (NULL, address, xmas.session, NULL, 0); 1524 plugin->env->session_start (NULL, address, xmas.session, NULL, 0);
1415 LOG (GNUNET_ERROR_TYPE_DEBUG, 1525 LOG (GNUNET_ERROR_TYPE_DEBUG,
1416 "Notifying transport about peer `%s''s new session %p \n", 1526 "Notifying transport about peer `%s''s new session %p \n",
1417 GNUNET_i2s (&wlanheader->sender), xmas.session); 1527 GNUNET_i2s (&wlanheader->sender), xmas.session);
1418 GNUNET_HELLO_address_free (address); 1528 GNUNET_HELLO_address_free (address);
1419 } 1529 }
1420 LOG (GNUNET_ERROR_TYPE_DEBUG, 1530 LOG (GNUNET_ERROR_TYPE_DEBUG,
1421 "Processing %u bytes of WLAN DATA from peer `%s'\n", 1531 "Processing %u bytes of WLAN DATA from peer `%s'\n",
1422 (unsigned int) msize, 1532 (unsigned int) msize,
1423 GNUNET_i2s (&wlanheader->sender)); 1533 GNUNET_i2s (&wlanheader->sender));
1534 xmas.session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1424 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer, 1535 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer,
1425 &xmas, 1536 &xmas,
1426 (const char *) &wlanheader[1], 1537 (const char *) &wlanheader[1],
1427 msize - sizeof (struct WlanHeader), 1538 msize - sizeof (struct WlanHeader),
1428 GNUNET_YES, GNUNET_NO); 1539 GNUNET_YES,
1540 GNUNET_NO);
1429 break; 1541 break;
1430 default: 1542 default:
1431 if (NULL == mas->endpoint) 1543 if (NULL == mas->endpoint)
@@ -1646,7 +1758,9 @@ send_hello_beacon (void *cls,
1646 * and transport 1758 * and transport
1647 */ 1759 */
1648static int 1760static int
1649wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) 1761wlan_plugin_address_suggested (void *cls,
1762 const void *addr,
1763 size_t addrlen)
1650{ 1764{
1651 struct Plugin *plugin = cls; 1765 struct Plugin *plugin = cls;
1652 struct WlanAddress *wa = (struct WlanAddress *) addr; 1766 struct WlanAddress *wa = (struct WlanAddress *) addr;
@@ -1677,41 +1791,6 @@ wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
1677 1791
1678 1792
1679/** 1793/**
1680 * Function called for a quick conversion of the binary address to
1681 * a numeric address. Note that the caller must not free the
1682 * address and that the next call to this function is allowed
1683 * to override the address again.
1684 *
1685 * @param cls closure
1686 * @param addr binary address
1687 * @param addrlen length of the address
1688 * @return string representing the same address
1689 */
1690static const char *
1691wlan_plugin_address_to_string (void *cls,
1692 const void *addr,
1693 size_t addrlen)
1694{
1695 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1696 static char macstr[36];
1697
1698 if (sizeof (struct WlanAddress) != addrlen)
1699 {
1700 GNUNET_break (0);
1701 return NULL;
1702 }
1703 mac = &((struct WlanAddress *) addr)->mac;
1704 GNUNET_snprintf (macstr,
1705 sizeof (macstr),
1706 "%s.%u.%s",
1707 PLUGIN_NAME,
1708 ntohl (((struct WlanAddress *) addr)->options),
1709 mac_to_string (mac));
1710 return macstr;
1711}
1712
1713
1714/**
1715 * Convert the transports address to a nice, human-readable format. 1794 * Convert the transports address to a nice, human-readable format.
1716 * 1795 *
1717 * @param cls closure 1796 * @param cls closure
@@ -1836,8 +1915,11 @@ libgnunet_plugin_transport_wlan_done (void *cls)
1836 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1915 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1837 */ 1916 */
1838static int 1917static int
1839wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen, 1918wlan_plugin_string_to_address (void *cls,
1840 void **buf, size_t *added) 1919 const char *addr,
1920 uint16_t addrlen,
1921 void **buf,
1922 size_t *added)
1841{ 1923{
1842 struct WlanAddress *wa; 1924 struct WlanAddress *wa;
1843 unsigned int a[6]; 1925 unsigned int a[6];
@@ -1879,23 +1961,86 @@ wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen,
1879} 1961}
1880 1962
1881 1963
1964/**
1965 * Begin monitoring sessions of a plugin. There can only
1966 * be one active monitor per plugin (i.e. if there are
1967 * multiple monitors, the transport service needs to
1968 * multiplex the generated events over all of them).
1969 *
1970 * @param cls closure of the plugin
1971 * @param sic callback to invoke, NULL to disable monitor;
1972 * plugin will being by iterating over all active
1973 * sessions immediately and then enter monitor mode
1974 * @param sic_cls closure for @a sic
1975 */
1976static void
1977wlan_plugin_setup_monitor (void *cls,
1978 GNUNET_TRANSPORT_SessionInfoCallback sic,
1979 void *sic_cls)
1980{
1981 struct Plugin *plugin = cls;
1982 struct MacEndpoint *mac;
1983 struct Session *session;
1984
1985 plugin->sic = sic;
1986 plugin->sic_cls = sic_cls;
1987 if (NULL != sic)
1988 {
1989 for (mac = plugin->mac_head; NULL != mac; mac = mac->next)
1990 for (session = mac->sessions_head; NULL != session; session = session->next)
1991 notify_session_monitor (plugin,
1992 session,
1993 GNUNET_TRANSPORT_SS_UP);
1994 sic (sic_cls, NULL, NULL);
1995 }
1996}
1997
1998
1999
2000/**
2001 * Function that will be called whenever the transport service wants to
2002 * notify the plugin that a session is still active and in use and
2003 * therefore the session timeout for this session has to be updated
2004 *
2005 * @param cls closure
2006 * @param peer which peer was the session for
2007 * @param session which session is being updated
2008 */
1882static void 2009static void
1883wlan_plugin_update_session_timeout (void *cls, 2010wlan_plugin_update_session_timeout (void *cls,
1884 const struct GNUNET_PeerIdentity *peer, 2011 const struct GNUNET_PeerIdentity *peer,
1885 struct Session *session) 2012 struct Session *session)
1886{ 2013{
1887 if (session->timeout_task != GNUNET_SCHEDULER_NO_TASK) 2014 GNUNET_assert (session->timeout_task != GNUNET_SCHEDULER_NO_TASK);
1888 GNUNET_SCHEDULER_cancel (session->timeout_task); 2015 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2016}
2017
1889 2018
1890 session->timeout_task = GNUNET_SCHEDULER_add_delayed ( 2019/**
1891 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); 2020 * Function that will be called whenever the transport service wants to
2021 * notify the plugin that the inbound quota changed and that the plugin
2022 * should update it's delay for the next receive value
2023 *
2024 * @param cls closure
2025 * @param peer which peer was the session for
2026 * @param session which session is being updated
2027 * @param delay new delay to use for receiving
2028 */
2029static void
2030wlan_plugin_update_inbound_delay (void *cls,
2031 const struct GNUNET_PeerIdentity *peer,
2032 struct Session *session,
2033 struct GNUNET_TIME_Relative delay)
2034{
2035 /* does nothing, as inbound delay is not supported by WLAN */
1892} 2036}
1893 2037
2038
1894/** 2039/**
1895 * Entry point for the plugin. 2040 * Entry point for the plugin.
1896 * 2041 *
1897 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*' 2042 * @param cls closure, the `struct GNUNET_TRANSPORT_PluginEnvironment *`
1898 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error 2043 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error
1899 */ 2044 */
1900void * 2045void *
1901libgnunet_plugin_transport_wlan_init (void *cls) 2046libgnunet_plugin_transport_wlan_init (void *cls)
@@ -1916,7 +2061,7 @@ libgnunet_plugin_transport_wlan_init (void *cls)
1916 api->cls = NULL; 2061 api->cls = NULL;
1917 api->address_pretty_printer = &wlan_plugin_address_pretty_printer; 2062 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
1918 api->address_to_string = &wlan_plugin_address_to_string; 2063 api->address_to_string = &wlan_plugin_address_to_string;
1919 api->string_to_address = &wlan_string_to_address; 2064 api->string_to_address = &wlan_plugin_string_to_address;
1920 return api; 2065 return api;
1921 } 2066 }
1922 2067
@@ -1935,7 +2080,8 @@ libgnunet_plugin_transport_wlan_init (void *cls)
1935 } 2080 }
1936 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-transport-wlan"); 2081 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-transport-wlan");
1937 if ( (0 == testmode) && 2082 if ( (0 == testmode) &&
1938 (GNUNET_YES != GNUNET_OS_check_helper_binary (binary, GNUNET_YES, NULL)) ) 2083 (GNUNET_YES !=
2084 GNUNET_OS_check_helper_binary (binary, GNUNET_YES, NULL)) )
1939 { 2085 {
1940 LOG (GNUNET_ERROR_TYPE_ERROR, 2086 LOG (GNUNET_ERROR_TYPE_ERROR,
1941 _("Helper binary `%s' not SUID, cannot run WLAN transport\n"), 2087 _("Helper binary `%s' not SUID, cannot run WLAN transport\n"),
@@ -1945,9 +2091,10 @@ libgnunet_plugin_transport_wlan_init (void *cls)
1945 } 2091 }
1946 GNUNET_free (binary); 2092 GNUNET_free (binary);
1947 if (GNUNET_YES != 2093 if (GNUNET_YES !=
1948 GNUNET_CONFIGURATION_get_value_string 2094 GNUNET_CONFIGURATION_get_value_string (env->cfg,
1949 (env->cfg, "transport-wlan", "INTERFACE", 2095 "transport-wlan",
1950 &interface)) 2096 "INTERFACE",
2097 &interface))
1951 { 2098 {
1952 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2099 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1953 "transport-wlan", "INTERFACE"); 2100 "transport-wlan", "INTERFACE");
@@ -1957,13 +2104,16 @@ libgnunet_plugin_transport_wlan_init (void *cls)
1957 plugin = GNUNET_new (struct Plugin); 2104 plugin = GNUNET_new (struct Plugin);
1958 plugin->interface = interface; 2105 plugin->interface = interface;
1959 plugin->env = env; 2106 plugin->env = env;
1960 GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN sessions allocated"), 2107 GNUNET_STATISTICS_set (plugin->env->stats,
2108 _("# WLAN sessions allocated"),
1961 0, GNUNET_NO); 2109 0, GNUNET_NO);
1962 GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN MAC endpoints allocated"), 2110 GNUNET_STATISTICS_set (plugin->env->stats,
2111 _("# WLAN MAC endpoints allocated"),
1963 0, 0); 2112 0, 0);
1964 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, NULL, NULL, 2113 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, NULL, NULL,
1965 GNUNET_BANDWIDTH_value_init (100 * 1024 * 2114 GNUNET_BANDWIDTH_value_init (100 * 1024 *
1966 1024 / 8), 100); 2115 1024 / 8),
2116 100);
1967 plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); 2117 plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1968 plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); 2118 plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1969 plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); 2119 plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
@@ -2022,9 +2172,11 @@ libgnunet_plugin_transport_wlan_init (void *cls)
2022 api->address_pretty_printer = &wlan_plugin_address_pretty_printer; 2172 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
2023 api->check_address = &wlan_plugin_address_suggested; 2173 api->check_address = &wlan_plugin_address_suggested;
2024 api->address_to_string = &wlan_plugin_address_to_string; 2174 api->address_to_string = &wlan_plugin_address_to_string;
2025 api->string_to_address = &wlan_string_to_address; 2175 api->string_to_address = &wlan_plugin_string_to_address;
2026 api->get_network = &wlan_get_network; 2176 api->get_network = &wlan_plugin_get_network;
2027 api->update_session_timeout = &wlan_plugin_update_session_timeout; 2177 api->update_session_timeout = &wlan_plugin_update_session_timeout;
2178 api->update_inbound_delay = &wlan_plugin_update_inbound_delay;
2179 api->setup_monitor = &wlan_plugin_setup_monitor;
2028 return api; 2180 return api;
2029} 2181}
2030 2182