aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_wlan.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-07-11 12:56:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-07-11 12:56:53 +0000
commit285181f04d096dd675a3b7538779f0ba7ceb63c6 (patch)
treefb0c141241f42f502a2d97aeb8cadd0e1e87f967 /src/transport/plugin_transport_wlan.c
parent72ef45e25d24e73e0548d3cffcea35f1cd98f13a (diff)
downloadgnunet-285181f04d096dd675a3b7538779f0ba7ceb63c6.tar.gz
gnunet-285181f04d096dd675a3b7538779f0ba7ceb63c6.zip
notification for inbound sessions
Diffstat (limited to 'src/transport/plugin_transport_wlan.c')
-rw-r--r--src/transport/plugin_transport_wlan.c59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 438396081..298d55653 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -702,15 +702,16 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
702} 702}
703 703
704 704
705
705/** 706/**
706 * Create a new session 707 * Lookup a new session
707 * 708 *
708 * @param endpoint pointer to the mac endpoint of the peer 709 * @param endpoint pointer to the mac endpoint of the peer
709 * @param peer peer identity to use for this session 710 * @param peer peer identity to use for this session
710 * @return returns the session 711 * @return returns the session or NULL
711 */ 712 */
712static struct Session * 713static struct Session *
713create_session (struct MacEndpoint *endpoint, 714lookup_session (struct MacEndpoint *endpoint,
714 const struct GNUNET_PeerIdentity *peer) 715 const struct GNUNET_PeerIdentity *peer)
715{ 716{
716 struct Session *session; 717 struct Session *session;
@@ -722,6 +723,22 @@ create_session (struct MacEndpoint *endpoint,
722 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 723 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
723 return session; 724 return session;
724 } 725 }
726 return NULL;
727}
728
729/**
730 * Create a new session
731 *
732 * @param endpoint pointer to the mac endpoint of the peer
733 * @param peer peer identity to use for this session
734 * @return returns the session or NULL
735 */
736static struct Session *
737create_session (struct MacEndpoint *endpoint,
738 const struct GNUNET_PeerIdentity *peer)
739{
740 struct Session *session;
741
725 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), 1, 742 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), 1,
726 GNUNET_NO); 743 GNUNET_NO);
727 session = GNUNET_malloc (sizeof (struct Session)); 744 session = GNUNET_malloc (sizeof (struct Session));
@@ -733,7 +750,7 @@ create_session (struct MacEndpoint *endpoint,
733 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 750 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
734 session->timeout_task = 751 session->timeout_task =
735 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); 752 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session);
736 LOG (GNUNET_ERROR_TYPE_DEBUG, 753 LOG (GNUNET_ERROR_TYPE_DEBUG,
737 "Created new session for peer `%s' with endpoint %s\n", 754 "Created new session for peer `%s' with endpoint %s\n",
738 GNUNET_i2s (peer), 755 GNUNET_i2s (peer),
739 mac_to_string (&endpoint->addr.mac)); 756 mac_to_string (&endpoint->addr.mac));
@@ -742,6 +759,24 @@ create_session (struct MacEndpoint *endpoint,
742 759
743 760
744/** 761/**
762 * Look up a session for a peer and create a new session if none is found
763 *
764 * @param endpoint pointer to the mac endpoint of the peer
765 * @param peer peer identity to use for this session
766 * @return returns the session
767 */
768static struct Session *
769get_session (struct MacEndpoint *endpoint,
770 const struct GNUNET_PeerIdentity *peer)
771{
772 struct Session *session;
773 if (NULL != (session = lookup_session (endpoint, peer)))
774 return session;
775 return create_session (endpoint, peer);
776}
777
778
779/**
745 * Function called once we have successfully given the fragment 780 * Function called once we have successfully given the fragment
746 * message to the SUID helper process and we are thus ready for 781 * message to the SUID helper process and we are thus ready for
747 * the next fragment. 782 * the next fragment.
@@ -1063,7 +1098,7 @@ wlan_plugin_get_session (void *cls,
1063 GNUNET_i2s (&address->peer), 1098 GNUNET_i2s (&address->peer),
1064 wlan_plugin_address_to_string(NULL, address->address, address->address_length)); 1099 wlan_plugin_address_to_string(NULL, address->address, address->address_length));
1065 endpoint = create_macendpoint (plugin, address->address); 1100 endpoint = create_macendpoint (plugin, address->address);
1066 return create_session (endpoint, &address->peer); 1101 return get_session (endpoint, &address->peer);
1067} 1102}
1068 1103
1069 1104
@@ -1304,9 +1339,17 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1304 break; 1339 break;
1305 } 1340 }
1306 xmas.endpoint = mas->endpoint; 1341 xmas.endpoint = mas->endpoint;
1307 xmas.session = create_session (mas->endpoint, &wlanheader->sender); 1342 if (NULL == (xmas.session = lookup_session (mas->endpoint, &wlanheader->sender)))
1308 LOG (GNUNET_ERROR_TYPE_DEBUG, 1343 {
1309 "Processing %u bytes of WLAN DATA from peer `%s'\n", 1344 xmas.session = create_session (mas->endpoint, &wlanheader->sender);
1345 plugin->env->session_start (NULL, &wlanheader->sender,
1346 PLUGIN_NAME, NULL, 0, xmas.session, NULL, 0);
1347 LOG (GNUNET_ERROR_TYPE_DEBUG,
1348 "Notifying transport about peer `%s''s new inbound session %p \n",
1349 GNUNET_i2s (&wlanheader->sender), xmas.session);
1350 }
1351 LOG (GNUNET_ERROR_TYPE_DEBUG,
1352 "Processing %u bytes of WLAN DATA from peer `%s'\n",
1310 (unsigned int) msize, 1353 (unsigned int) msize,
1311 GNUNET_i2s (&wlanheader->sender)); 1354 GNUNET_i2s (&wlanheader->sender));
1312 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer, 1355 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer,