aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_tcp.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-26 11:01:28 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-26 11:01:28 +0000
commit1d47d5af1a4b114cf3e56b7f4e174cb5878ba30d (patch)
tree1cd906c5996f35f72d8c28fa6a62920db06e9e65 /src/transport/plugin_transport_tcp.c
parent9d6a89fda9f5a24032087e6030006e55bc7091ce (diff)
downloadgnunet-1d47d5af1a4b114cf3e56b7f4e174cb5878ba30d.tar.gz
gnunet-1d47d5af1a4b114cf3e56b7f4e174cb5878ba30d.zip
- new get_session functions
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r--src/transport/plugin_transport_tcp.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index a51a5bff3..19bf8d304 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1231,16 +1231,11 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1231 */ 1231 */
1232static ssize_t 1232static ssize_t
1233tcp_plugin_send_new (void *cls, 1233tcp_plugin_send_new (void *cls,
1234 const struct 1234 struct Session *session,
1235 GNUNET_PeerIdentity * 1235 const char *msgbuf, size_t msgbuf_size,
1236 target, 1236 unsigned int priority,
1237 const char *msg, 1237 struct GNUNET_TIME_Relative to,
1238 size_t msgbuf_size, 1238 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1239 uint32_t priority,
1240 struct GNUNET_TIME_Relative timeout,
1241 struct Session * session,
1242 GNUNET_TRANSPORT_TransmitContinuation
1243 cont, void *cont_cls)
1244{ 1239{
1245 struct Plugin * plugin = cls; 1240 struct Plugin * plugin = cls;
1246 struct PendingMessage *pm; 1241 struct PendingMessage *pm;
@@ -1256,9 +1251,9 @@ tcp_plugin_send_new (void *cls,
1256 /* create new message entry */ 1251 /* create new message entry */
1257 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size); 1252 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
1258 pm->msg = (const char *) &pm[1]; 1253 pm->msg = (const char *) &pm[1];
1259 memcpy (&pm[1], msg, msgbuf_size); 1254 memcpy (&pm[1], msgbuf, msgbuf_size);
1260 pm->message_size = msgbuf_size; 1255 pm->message_size = msgbuf_size;
1261 pm->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1256 pm->timeout = GNUNET_TIME_relative_to_absolute (to);
1262 pm->transmit_cont = cont; 1257 pm->transmit_cont = cont;
1263 pm->transmit_cont_cls = cont_cls; 1258 pm->transmit_cont_cls = cont_cls;
1264 1259
@@ -1310,10 +1305,8 @@ int session_it (void *cls,
1310 * @param addrlen length of addr 1305 * @param addrlen length of addr
1311 * @return the session if the address is valid, NULL otherwise 1306 * @return the session if the address is valid, NULL otherwise
1312 */ 1307 */
1313const void * tcp_plugin_create_session (void *cls, 1308const const struct Session * tcp_plugin_create_session (void *cls,
1314 const struct GNUNET_PeerIdentity *target, 1309 const struct GNUNET_HELLO_Address *address)
1315 const void *addr,
1316 size_t addrlen)
1317{ 1310{
1318 struct Plugin * plugin = cls; 1311 struct Plugin * plugin = cls;
1319 struct Session * session = NULL; 1312 struct Session * session = NULL;
@@ -1327,11 +1320,15 @@ const void * tcp_plugin_create_session (void *cls,
1327 const struct IPv4TcpAddress *t4; 1320 const struct IPv4TcpAddress *t4;
1328 const struct IPv6TcpAddress *t6; 1321 const struct IPv6TcpAddress *t6;
1329 unsigned int is_natd = GNUNET_NO; 1322 unsigned int is_natd = GNUNET_NO;
1323 size_t addrlen = address->address_length;
1324
1325 GNUNET_assert (plugin != NULL);
1326 GNUNET_assert (address != NULL);
1330 1327
1331 if (addrlen == sizeof (struct IPv6TcpAddress)) 1328 if (addrlen == sizeof (struct IPv6TcpAddress))
1332 { 1329 {
1333 GNUNET_assert (NULL != addr); /* make static analysis happy */ 1330 GNUNET_assert (NULL != address->address); /* make static analysis happy */
1334 t6 = addr; 1331 t6 = address->address;
1335 af = AF_INET6; 1332 af = AF_INET6;
1336 memset (&a6, 0, sizeof (a6)); 1333 memset (&a6, 0, sizeof (a6));
1337#if HAVE_SOCKADDR_IN_SIN_LEN 1334#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -1347,8 +1344,8 @@ const void * tcp_plugin_create_session (void *cls,
1347 } 1344 }
1348 else if (addrlen == sizeof (struct IPv4TcpAddress)) 1345 else if (addrlen == sizeof (struct IPv4TcpAddress))
1349 { 1346 {
1350 GNUNET_assert (NULL != addr); /* make static analysis happy */ 1347 GNUNET_assert (NULL != address->address); /* make static analysis happy */
1351 t4 = addr; 1348 t4 = address->address;
1352 af = AF_INET; 1349 af = AF_INET;
1353 memset (&a4, 0, sizeof (a4)); 1350 memset (&a4, 0, sizeof (a4));
1354#if HAVE_SOCKADDR_IN_SIN_LEN 1351#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -1371,12 +1368,12 @@ const void * tcp_plugin_create_session (void *cls,
1371 } 1368 }
1372 1369
1373 /* look for existing session */ 1370 /* look for existing session */
1374 if (GNUNET_CONTAINER_multihashmap_contains(plugin->sessionmap, &target->hashPubKey)) 1371 if (GNUNET_CONTAINER_multihashmap_contains(plugin->sessionmap, &address->peer.hashPubKey))
1375 { 1372 {
1376 struct SessionItCtx si_ctx; 1373 struct SessionItCtx si_ctx;
1377 si_ctx.addr = &sbs; 1374 si_ctx.addr = &sbs;
1378 si_ctx.addrlen = sbs; 1375 si_ctx.addrlen = sbs;
1379 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->sessionmap, &target->hashPubKey, &session_it, &si_ctx); 1376 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->sessionmap, &address->peer.hashPubKey, &session_it, &si_ctx);
1380 if (si_ctx.result != NULL) 1377 if (si_ctx.result != NULL)
1381 session = si_ctx.result; 1378 session = si_ctx.result;
1382 return session; 1379 return session;
@@ -1391,23 +1388,23 @@ const void * tcp_plugin_create_session (void *cls,
1391 if ((is_natd == GNUNET_YES) && 1388 if ((is_natd == GNUNET_YES) &&
1392 (GNUNET_YES == 1389 (GNUNET_YES ==
1393 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns, 1390 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1394 &target->hashPubKey))) 1391 &address->peer.hashPubKey)))
1395 return NULL; /* Only do one NAT punch attempt per peer identity */ 1392 return NULL; /* Only do one NAT punch attempt per peer identity */
1396 1393
1397 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && 1394 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
1398 (GNUNET_NO == 1395 (GNUNET_NO ==
1399 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns, 1396 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1400 &target->hashPubKey))) 1397 &address->peer.hashPubKey)))
1401 { 1398 {
1402#if DEBUG_TCP_NAT 1399#if DEBUG_TCP_NAT
1403 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1400 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1404 _("Found valid IPv4 NAT address (creating session)!\n")); 1401 _("Found valid IPv4 NAT address (creating session)!\n"));
1405#endif 1402#endif
1406 session = create_session (plugin, target, NULL, GNUNET_YES); 1403 session = create_session (plugin, &address->peer, NULL, GNUNET_YES);
1407 GNUNET_assert (session != NULL); 1404 GNUNET_assert (session != NULL);
1408 1405
1409 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put 1406 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put
1410 (plugin->nat_wait_conns, &target->hashPubKey, session, 1407 (plugin->nat_wait_conns, &address->peer.hashPubKey, session,
1411 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK); 1408 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK);
1412#if DEBUG_TCP_NAT 1409#if DEBUG_TCP_NAT
1413 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1410 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
@@ -1437,11 +1434,11 @@ const void * tcp_plugin_create_session (void *cls,
1437 GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); 1434 GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
1438#endif 1435#endif
1439 session = create_session (plugin, 1436 session = create_session (plugin,
1440 target, 1437 &address->peer,
1441 GNUNET_SERVER_connect_socket (plugin->server, sa), 1438 GNUNET_SERVER_connect_socket (plugin->server, sa),
1442 GNUNET_NO); 1439 GNUNET_NO);
1443 session->connect_addr = GNUNET_malloc (addrlen); 1440 session->connect_addr = GNUNET_malloc (addrlen);
1444 memcpy (session->connect_addr, addr, addrlen); 1441 memcpy (session->connect_addr, address->address, addrlen);
1445 session->connect_alen = addrlen; 1442 session->connect_alen = addrlen;
1446 if (addrlen != 0) 1443 if (addrlen != 0)
1447 { 1444 {
@@ -1452,7 +1449,7 @@ const void * tcp_plugin_create_session (void *cls,
1452 else 1449 else
1453 GNUNET_break (0); 1450 GNUNET_break (0);
1454 1451
1455 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &target->hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1452 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &address->peer.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1456 1453
1457 /* Send TCP Welcome */ 1454 /* Send TCP Welcome */
1458 process_pending_messages (session); 1455 process_pending_messages (session);
@@ -2286,7 +2283,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2286 api->send = &tcp_plugin_send; 2283 api->send = &tcp_plugin_send;
2287 2284
2288 api->send_with_session = &tcp_plugin_send_new; 2285 api->send_with_session = &tcp_plugin_send_new;
2289 api->create_session = &tcp_plugin_create_session; 2286 api->get_session = &tcp_plugin_create_session;
2290 2287
2291 api->disconnect = &tcp_plugin_disconnect; 2288 api->disconnect = &tcp_plugin_disconnect;
2292 api->address_pretty_printer = &tcp_plugin_address_pretty_printer; 2289 api->address_pretty_printer = &tcp_plugin_address_pretty_printer;