aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-08 23:20:42 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-08 23:20:42 +0000
commita983a0267109b1b6a8e16e476e2f2956a8771b94 (patch)
tree79bcae73cdb7b87b4f55d4396e79baea76ef53a6 /src/transport/gnunet-service-transport_neighbours.c
parenta3f8ef5b89dc44fc3acfb8f081a502f3409e4224 (diff)
downloadgnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.tar.gz
gnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.zip
refactoring how we handle peer addresses in peerinfo/ats/transport/hello subsystems -- use a struct instead of 3--4 arguments
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c337
1 files changed, 127 insertions, 210 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index e6b298f4f..a127209dd 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -234,19 +234,9 @@ struct NeighbourMapEntry
234 struct Session *session; 234 struct Session *session;
235 235
236 /** 236 /**
237 * Name of the plugin we currently use. 237 * Address we currently use.
238 */ 238 */
239 char *plugin_name; 239 struct GNUNET_HELLO_Address *address;
240
241 /**
242 * Address used for communicating with the peer, NULL for inbound connections.
243 */
244 void *addr;
245
246 /**
247 * Number of bytes in 'addr'.
248 */
249 size_t addrlen;
250 240
251 /** 241 /**
252 * Identity of this neighbour. 242 * Identity of this neighbour.
@@ -432,8 +422,7 @@ reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
432 */ 422 */
433 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 423 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
434 "Information for developers: Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n", 424 "Information for developers: Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n",
435 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, n->addr, 425 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address),
436 n->addrlen),
437 print_state (n->state)); 426 print_state (n->state));
438 427
439 GNUNET_STATISTICS_update (GST_stats, 428 GNUNET_STATISTICS_update (GST_stats,
@@ -445,8 +434,7 @@ reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
445 n->state = S_NOT_CONNECTED; 434 n->state = S_NOT_CONNECTED;
446 435
447 /* destroying address */ 436 /* destroying address */
448 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, 437 GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL);
449 n->addrlen, NULL);
450 438
451 /* request new address */ 439 /* request new address */
452 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 440 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
@@ -496,8 +484,7 @@ change (struct NeighbourMapEntry *n, int state, int line)
496#if DEBUG_TRANSPORT 484#if DEBUG_TRANSPORT
497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
498 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", 486 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
499 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, 487 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address),
500 n->addr, n->addrlen),
501 print_state (n->state), print_state (state)); 488 print_state (n->state), print_state (state));
502#endif 489#endif
503 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); 490 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK);
@@ -520,8 +507,7 @@ change (struct NeighbourMapEntry *n, int state, int line)
520#if DEBUG_TRANSPORT 507#if DEBUG_TRANSPORT
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", 509 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
523 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, 510 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address),
524 n->addr, n->addrlen),
525 print_state (n->state), print_state (state)); 511 print_state (n->state), print_state (state));
526#endif 512#endif
527 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); 513 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK);
@@ -580,7 +566,7 @@ static ssize_t
580send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf, 566send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
581 size_t msgbuf_size, uint32_t priority, 567 size_t msgbuf_size, uint32_t priority,
582 struct GNUNET_TIME_Relative timeout, struct Session *session, 568 struct GNUNET_TIME_Relative timeout, struct Session *session,
583 const char *plugin_name, const void *addr, size_t addrlen, 569 const struct GNUNET_HELLO_Address *address,
584 int force_address, GNUNET_TRANSPORT_TransmitContinuation cont, 570 int force_address, GNUNET_TRANSPORT_TransmitContinuation cont,
585 void *cont_cls) 571 void *cont_cls)
586{ 572{
@@ -588,21 +574,21 @@ send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
588 size_t ret = GNUNET_SYSERR; 574 size_t ret = GNUNET_SYSERR;
589 575
590 /* FIXME : ats returns an address with all values 0 */ 576 /* FIXME : ats returns an address with all values 0 */
591 if (plugin_name == NULL) 577 if (address == NULL)
592 { 578 {
593 if (cont != NULL) 579 if (cont != NULL)
594 cont (cont_cls, target, GNUNET_SYSERR); 580 cont (cont_cls, target, GNUNET_SYSERR);
595 return GNUNET_SYSERR; 581 return GNUNET_SYSERR;
596 } 582 }
597 583
598 if ((session == NULL) && (addr == NULL) && (addrlen == 0)) 584 if ((session == NULL) && (address == NULL))
599 { 585 {
600 if (cont != NULL) 586 if (cont != NULL)
601 cont (cont_cls, target, GNUNET_SYSERR); 587 cont (cont_cls, target, GNUNET_SYSERR);
602 return GNUNET_SYSERR; 588 return GNUNET_SYSERR;
603 } 589 }
604 590
605 papi = GST_plugins_find (plugin_name); 591 papi = GST_plugins_find (address->transport_name);
606 if (papi == NULL) 592 if (papi == NULL)
607 { 593 {
608 if (cont != NULL) 594 if (cont != NULL)
@@ -612,7 +598,8 @@ send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
612 598
613 ret = 599 ret =
614 papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session, 600 papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session,
615 addr, addrlen, GNUNET_YES, cont, cont_cls); 601 address->address,
602 address->address_length, GNUNET_YES, cont, cont_cls);
616 603
617 if (ret == -1) 604 if (ret == -1)
618 { 605 {
@@ -706,7 +693,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
706 if (NULL == mq) 693 if (NULL == mq)
707 return; /* no more messages */ 694 return; /* no more messages */
708 695
709 if (GST_plugins_find (n->plugin_name) == NULL) 696 if (GST_plugins_find (n->address->transport_name) == NULL)
710 { 697 {
711 GNUNET_break (0); 698 GNUNET_break (0);
712 return; 699 return;
@@ -715,9 +702,10 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
715 n->is_active = mq; 702 n->is_active = mq;
716 mq->n = n; 703 mq->n = n;
717 704
718 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) 705 if ( (n->session == NULL) && (NULL == n->address) )
719 { 706 {
720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n", 707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
708 "No address for peer `%s'\n",
721 GNUNET_i2s (&n->id)); 709 GNUNET_i2s (&n->id));
722 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); 710 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR);
723 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK); 711 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK);
@@ -727,8 +715,8 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
727 715
728 ret = 716 ret =
729 send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0, 717 send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0,
730 timeout, n->session, n->plugin_name, n->addr, 718 timeout, n->session, n->address,
731 n->addrlen, GNUNET_YES, &transmit_send_continuation, 719 GNUNET_YES, &transmit_send_continuation,
732 mq); 720 mq);
733 if (ret == -1) 721 if (ret == -1)
734 { 722 {
@@ -789,8 +777,8 @@ send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target,
789 777
790static int 778static int
791send_disconnect (const struct GNUNET_PeerIdentity *target, 779send_disconnect (const struct GNUNET_PeerIdentity *target,
792 const char *plugin_name, const char *sender_address, 780 const struct GNUNET_HELLO_Address *address,
793 uint16_t sender_address_len, struct Session *session) 781 struct Session *session)
794{ 782{
795 size_t ret; 783 size_t ret;
796 struct SessionDisconnectMessage disconnect_msg; 784 struct SessionDisconnectMessage disconnect_msg;
@@ -821,8 +809,8 @@ send_disconnect (const struct GNUNET_PeerIdentity *target,
821 ret = 809 ret =
822 send_with_plugin (target, (const char *) &disconnect_msg, 810 send_with_plugin (target, (const char *) &disconnect_msg,
823 sizeof (disconnect_msg), UINT32_MAX, 811 sizeof (disconnect_msg), UINT32_MAX,
824 GNUNET_TIME_UNIT_FOREVER_REL, session, plugin_name, 812 GNUNET_TIME_UNIT_FOREVER_REL, session, address,
825 sender_address, sender_address_len, GNUNET_YES, 813 GNUNET_YES,
826 &send_disconnect_cont, NULL); 814 &send_disconnect_cont, NULL);
827 815
828 if (ret == GNUNET_SYSERR) 816 if (ret == GNUNET_SYSERR)
@@ -850,7 +838,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
850 if (is_connected (n) || is_connecting (n)) 838 if (is_connected (n) || is_connecting (n))
851 { 839 {
852 if (GNUNET_OK == 840 if (GNUNET_OK ==
853 send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, 841 send_disconnect (&n->id, n->address,
854 n->session)) 842 n->session))
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", 843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n",
856 GNUNET_i2s (&n->id)); 844 GNUNET_i2s (&n->id));
@@ -862,8 +850,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
862 850
863 if (is_connected(n)) 851 if (is_connected(n))
864 { 852 {
865 GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, 853 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO);
866 n->addr, n->addrlen, n->session, GNUNET_NO);
867 } 854 }
868 855
869 856
@@ -871,16 +858,14 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
871 return; 858 return;
872 change_state (n, S_DISCONNECT); 859 change_state (n, S_DISCONNECT);
873 GST_validation_set_address_use (&n->id, 860 GST_validation_set_address_use (&n->id,
874 n->plugin_name, 861 n->address,
875 n->session, 862 n->session,
876 n->addr,
877 n->addrlen,
878 GNUNET_NO); 863 GNUNET_NO);
879 864
880 if (n->plugin_name != NULL) 865 if (n->address != NULL)
881 { 866 {
882 struct GNUNET_TRANSPORT_PluginFunctions *papi; 867 struct GNUNET_TRANSPORT_PluginFunctions *papi;
883 papi = GST_plugins_find (n->plugin_name); 868 papi = GST_plugins_find (n->address->transport_name);
884 if (papi != NULL) 869 if (papi != NULL)
885 papi->disconnect (papi->cls, &n->id); 870 papi->disconnect (papi->cls, &n->id);
886 } 871 }
@@ -926,16 +911,10 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
926 GNUNET_SCHEDULER_cancel (n->transmission_task); 911 GNUNET_SCHEDULER_cancel (n->transmission_task);
927 n->transmission_task = GNUNET_SCHEDULER_NO_TASK; 912 n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
928 } 913 }
929 if (NULL != n->plugin_name) 914 if (NULL != n->address)
930 {
931 GNUNET_free (n->plugin_name);
932 n->plugin_name = NULL;
933 }
934 if (NULL != n->addr)
935 { 915 {
936 GNUNET_free (n->addr); 916 GNUNET_HELLO_address_free (n->address);
937 n->addr = NULL; 917 n->address = NULL;
938 n->addrlen = 0;
939 } 918 }
940 n->session = NULL; 919 n->session = NULL;
941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting peer `%4s', %X\n", 920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting peer `%4s', %X\n",
@@ -990,8 +969,8 @@ neighbour_keepalive_task (void *cls,
990 969
991 send_with_plugin (&n->id, (const void *) &m, sizeof (m), 970 send_with_plugin (&n->id, (const void *) &m, sizeof (m),
992 UINT32_MAX /* priority */ , 971 UINT32_MAX /* priority */ ,
993 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, 972 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address,
994 n->addr, n->addrlen, GNUNET_YES, NULL, NULL); 973 GNUNET_YES, NULL, NULL);
995} 974}
996 975
997 976
@@ -1083,14 +1062,12 @@ send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target,
1083#if DEBUG_TRANSPORT 1062#if DEBUG_TRANSPORT
1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1085 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", 1064 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
1086 GNUNET_i2s (&n->id), n->plugin_name, 1065 GNUNET_i2s (&n->id), n->address->transport_name,
1087 (n->addrlen == 1066 (n->addrlen ==
1088 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr, 1067 0) ? "<inbound>" : GST_plugins_a2s (n->address), n->session);
1089 n->addrlen), n->session);
1090#endif 1068#endif
1091 1069
1092 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, 1070 GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL);
1093 n->addrlen, NULL);
1094 1071
1095 change_state (n, S_NOT_CONNECTED); 1072 change_state (n, S_NOT_CONNECTED);
1096 1073
@@ -1131,14 +1108,12 @@ send_switch_address_continuation (void *cls,
1131#if DEBUG_TRANSPORT 1108#if DEBUG_TRANSPORT
1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1133 "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n", 1110 "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n",
1134 GNUNET_i2s (&n->id), n->plugin_name, 1111 GNUNET_i2s (&n->id), n->address->transport_name,
1135 (n->addrlen == 1112 (n->addrlen ==
1136 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr, 1113 0) ? "<inbound>" : GST_plugins_a2s (n->address), n->session);
1137 n->addrlen), n->session);
1138#endif 1114#endif
1139 1115
1140 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, 1116 GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL);
1141 n->addrlen, NULL);
1142 1117
1143 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1118 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1144 GNUNET_SCHEDULER_cancel (n->ats_suggest); 1119 GNUNET_SCHEDULER_cancel (n->ats_suggest);
@@ -1149,8 +1124,7 @@ send_switch_address_continuation (void *cls,
1149 return; 1124 return;
1150 } 1125 }
1151 /* Tell ATS that switching addresses was successful */ 1126 /* Tell ATS that switching addresses was successful */
1152 GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, 1127 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES);
1153 n->addrlen, n->addr, GNUNET_YES);
1154} 1128}
1155 1129
1156/** 1130/**
@@ -1177,16 +1151,13 @@ send_connect_ack_continuation (void *cls,
1177#if DEBUG_TRANSPORT 1151#if DEBUG_TRANSPORT
1178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1179 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", 1153 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
1180 GNUNET_i2s (&n->id), n->plugin_name, 1154 GNUNET_i2s (&n->id), n->address->transport_name,
1181 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 1155 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->address),
1182 n->addr,
1183 n->addrlen),
1184 n->session); 1156 n->session);
1185#endif 1157#endif
1186 change_state (n, S_NOT_CONNECTED); 1158 change_state (n, S_NOT_CONNECTED);
1187 1159
1188 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, 1160 GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL);
1189 n->addrlen, NULL);
1190 1161
1191 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1162 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1192 GNUNET_SCHEDULER_cancel (n->ats_suggest); 1163 GNUNET_SCHEDULER_cancel (n->ats_suggest);
@@ -1201,10 +1172,8 @@ send_connect_ack_continuation (void *cls,
1201 * the given address. 1172 * the given address.
1202 * 1173 *
1203 * @param peer identity of the peer to switch the address for 1174 * @param peer identity of the peer to switch the address for
1204 * @param plugin_name name of transport that delivered the PONG
1205 * @param address address of the other peer, NULL if other peer 1175 * @param address address of the other peer, NULL if other peer
1206 * connected to us 1176 * connected to us
1207 * @param address_len number of bytes in address
1208 * @param session session to use (or NULL) 1177 * @param session session to use (or NULL)
1209 * @param ats performance data 1178 * @param ats performance data
1210 * @param ats_count number of entries in ats 1179 * @param ats_count number of entries in ats
@@ -1213,8 +1182,7 @@ send_connect_ack_continuation (void *cls,
1213 */ 1182 */
1214int 1183int
1215GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, 1184GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1216 const char *plugin_name, 1185 const struct GNUNET_HELLO_Address *address,
1217 const void *address, size_t address_len,
1218 struct Session *session, 1186 struct Session *session,
1219 const struct GNUNET_ATS_Information *ats, 1187 const struct GNUNET_ATS_Information *ats,
1220 uint32_t ats_count, 1188 uint32_t ats_count,
@@ -1237,14 +1205,14 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1237 1205
1238 checks_failed = GNUNET_NO; 1206 checks_failed = GNUNET_NO;
1239 1207
1240 if (plugin_name == NULL) 1208 if (address == NULL)
1241 { 1209 {
1242 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1210 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1243 "ATS offered suggested us empty address: plugin NULL"); 1211 "ATS offered suggested us empty address: plugin NULL");
1244 GNUNET_break_op (0); 1212 GNUNET_break_op (0);
1245 checks_failed = GNUNET_YES; 1213 checks_failed = GNUNET_YES;
1246 } 1214 }
1247 if ((address == NULL) && (address_len == 0) && (session == NULL)) 1215 if ( (session == NULL) && (address == NULL) )
1248 { 1216 {
1249 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1217 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1250 "ATS offered suggested us empty address: address NULL & session NULL"); 1218 "ATS offered suggested us empty address: address NULL & session NULL");
@@ -1258,8 +1226,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1258 1226
1259 if (checks_failed == GNUNET_YES) 1227 if (checks_failed == GNUNET_YES)
1260 { 1228 {
1261 GNUNET_ATS_address_destroyed (GST_ats, peer, plugin_name, address, 1229 GNUNET_ATS_address_destroyed (GST_ats, address, session);
1262 address_len, session);
1263 if (n != NULL) 1230 if (n != NULL)
1264 GNUNET_ATS_suggest_address (GST_ats, peer); 1231 GNUNET_ATS_suggest_address (GST_ats, peer);
1265 return GNUNET_NO; 1232 return GNUNET_NO;
@@ -1269,10 +1236,8 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1269#if DEBUG_TRANSPORT 1236#if DEBUG_TRANSPORT
1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1271 "ATS tells us to switch to plugin `%s' address '%s' session %X for %s peer `%s'\n", 1238 "ATS tells us to switch to plugin `%s' address '%s' session %X for %s peer `%s'\n",
1272 plugin_name, 1239 address->transport_name,
1273 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, 1240 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (address),
1274 address,
1275 address_len),
1276 session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"), 1241 session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"),
1277 GNUNET_i2s (peer)); 1242 GNUNET_i2s (peer));
1278#endif 1243#endif
@@ -1284,66 +1249,57 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1284 } 1249 }
1285 1250
1286 // do not switch addresses just update quotas 1251 // do not switch addresses just update quotas
1287 if ((is_connected (n)) && (address_len == n->addrlen)) 1252 if ( (is_connected (n)) &&
1253 (0 == GNUNET_HELLO_address_cmp (address,
1254 n->address)) &&
1255 (n->session == session) )
1288 { 1256 {
1289 if ((0 == memcmp (address, n->addr, address_len)) && 1257 struct QuotaSetMessage q_msg;
1290 (n->session == session)) 1258
1291 {
1292 struct QuotaSetMessage q_msg;
1293
1294#if DEBUG_TRANSPORT 1259#if DEBUG_TRANSPORT
1295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1296 "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n", 1261 "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n",
1297 ntohl (n->bandwidth_out.value__), 1262 ntohl (n->bandwidth_out.value__),
1298 ntohl (n->bandwidth_in.value__), GNUNET_i2s (peer)); 1263 ntohl (n->bandwidth_in.value__), GNUNET_i2s (peer));
1299#endif 1264#endif
1300 1265
1301 n->bandwidth_in = bandwidth_in; 1266 n->bandwidth_in = bandwidth_in;
1302 n->bandwidth_out = bandwidth_out; 1267 n->bandwidth_out = bandwidth_out;
1303 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); 1268 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
1304 1269
1305 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 1270 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
1306 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 1271 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
1307 q_msg.quota = n->bandwidth_out; 1272 q_msg.quota = n->bandwidth_out;
1308 q_msg.peer = (*peer); 1273 q_msg.peer = (*peer);
1309 GST_clients_broadcast (&q_msg.header, GNUNET_NO); 1274 GST_clients_broadcast (&q_msg.header, GNUNET_NO);
1310 return GNUNET_NO; 1275 return GNUNET_NO;
1311 }
1312 } 1276 }
1313 if (n->state == S_CONNECTED) 1277 if (n->state == S_CONNECTED)
1314 GST_validation_set_address_use (&n->id, 1278 GST_validation_set_address_use (&n->id,
1315 n->plugin_name, 1279 n->address,
1316 n->session, 1280 n->session,
1317 n->addr,
1318 n->addrlen,
1319 GNUNET_NO); 1281 GNUNET_NO);
1320 /* This will be a connection switch, tell ATS about it */ 1282 /* This will be a connection switch, tell ATS about it */
1321 if (n->state == S_CONNECTED) 1283 if (n->state == S_CONNECTED)
1322 { 1284 {
1323 GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, 1285 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO);
1324 n->addrlen, n->addr, GNUNET_NO);
1325 } 1286 }
1326 1287
1327 /* set new address */ 1288 /* set new address */
1328 GNUNET_free_non_null (n->addr); 1289 if (NULL != n->address)
1329 n->addr = GNUNET_malloc (address_len); 1290 GNUNET_HELLO_address_free (n->address);
1330 memcpy (n->addr, address, address_len); 1291 n->address = GNUNET_HELLO_address_copy (address);
1331 n->bandwidth_in = bandwidth_in; 1292 n->bandwidth_in = bandwidth_in;
1332 n->bandwidth_out = bandwidth_out; 1293 n->bandwidth_out = bandwidth_out;
1333 n->addrlen = address_len;
1334 n->session = session; 1294 n->session = session;
1335 GNUNET_free_non_null (n->plugin_name);
1336 n->plugin_name = GNUNET_strdup (plugin_name);
1337 GNUNET_SCHEDULER_cancel (n->timeout_task); 1295 GNUNET_SCHEDULER_cancel (n->timeout_task);
1338 n->timeout_task = 1296 n->timeout_task =
1339 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1297 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1340 &neighbour_timeout_task, n); 1298 &neighbour_timeout_task, n);
1341 if (n->state == S_CONNECTED) 1299 if (n->state == S_CONNECTED)
1342 GST_validation_set_address_use (&n->id, 1300 GST_validation_set_address_use (&n->id,
1343 n->plugin_name, 1301 n->address,
1344 n->session, 1302 n->session,
1345 n->addr,
1346 n->addrlen,
1347 GNUNET_YES); 1303 GNUNET_YES);
1348 1304
1349 1305
@@ -1368,7 +1324,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1368 ret = 1324 ret =
1369 send_with_plugin (peer, (const char *) &connect_msg, msg_len, 1325 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1370 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, 1326 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1371 plugin_name, address, address_len, GNUNET_YES, 1327 address, GNUNET_YES,
1372 &send_connect_continuation, n); 1328 &send_connect_continuation, n);
1373 1329
1374 1330
@@ -1388,7 +1344,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1388 ret = 1344 ret =
1389 send_with_plugin (&n->id, (const void *) &connect_msg, msg_len, 1345 send_with_plugin (&n->id, (const void *) &connect_msg, msg_len,
1390 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, 1346 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1391 plugin_name, address, address_len, GNUNET_YES, 1347 address, GNUNET_YES,
1392 &send_connect_ack_continuation, n); 1348 &send_connect_ack_continuation, n);
1393 return GNUNET_NO; 1349 return GNUNET_NO;
1394 } 1350 }
@@ -1406,16 +1362,14 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1406 ret = 1362 ret =
1407 send_with_plugin (peer, (const char *) &connect_msg, msg_len, 1363 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1408 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, 1364 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1409 plugin_name, address, address_len, GNUNET_YES, 1365 address, GNUNET_YES,
1410 &send_switch_address_continuation, n); 1366 &send_switch_address_continuation, n);
1411 if (ret == GNUNET_SYSERR) 1367 if (ret == GNUNET_SYSERR)
1412 { 1368 {
1413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1414 "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n", 1370 "Failed to send CONNECT_MESSAGE to `%4s' using address '%s' session %X\n",
1415 GNUNET_i2s (peer), plugin_name, 1371 GNUNET_i2s (peer),
1416 (address_len == 1372 GST_plugins_a2s (address), session);
1417 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, address,
1418 address_len), session);
1419 } 1373 }
1420 return GNUNET_NO; 1374 return GNUNET_NO;
1421 } 1375 }
@@ -1446,10 +1400,8 @@ GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer)
1446 if (NULL == n) 1400 if (NULL == n)
1447 return GNUNET_TIME_UNIT_FOREVER_REL; 1401 return GNUNET_TIME_UNIT_FOREVER_REL;
1448 return GST_validation_get_address_latency (peer, 1402 return GST_validation_get_address_latency (peer,
1449 n->plugin_name, 1403 n->address,
1450 n->session, 1404 n->session);
1451 n->addr,
1452 n->addrlen);
1453} 1405}
1454 1406
1455 1407
@@ -1587,9 +1539,11 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1587 return; /* doesn't affect us */ 1539 return; /* doesn't affect us */
1588 1540
1589 n->session = NULL; 1541 n->session = NULL;
1590 GNUNET_free (n->addr); 1542 if (NULL != n->address)
1591 n->addr = NULL; 1543 {
1592 n->addrlen = 0; 1544 GNUNET_HELLO_address_free (n->address);
1545 n->address = NULL;
1546 }
1593 1547
1594 /* not connected anymore anyway, shouldn't matter */ 1548 /* not connected anymore anyway, shouldn't matter */
1595 if ((!is_connected (n)) && (!is_connecting (n))) 1549 if ((!is_connected (n)) && (!is_connecting (n)))
@@ -1656,7 +1610,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1656 return; 1610 return;
1657 } 1611 }
1658 1612
1659 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) 1613 if ((n->session == NULL) && (n->address == NULL) )
1660 { 1614 {
1661 GNUNET_STATISTICS_update (GST_stats, 1615 GNUNET_STATISTICS_update (GST_stats,
1662 gettext_noop 1616 gettext_noop
@@ -1898,7 +1852,7 @@ neighbours_iterate (void *cls, const GNUNET_HashCode * key, void *value)
1898 if (!is_connected (n)) 1852 if (!is_connected (n))
1899 return GNUNET_OK; 1853 return GNUNET_OK;
1900 1854
1901 ic->cb (ic->cb_cls, &n->id, NULL, 0, n->plugin_name, n->addr, n->addrlen); 1855 ic->cb (ic->cb_cls, &n->id, NULL, 0, n->address);
1902 return GNUNET_OK; 1856 return GNUNET_OK;
1903} 1857}
1904 1858
@@ -1946,7 +1900,7 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
1946 return; /* not active */ 1900 return; /* not active */
1947 if (is_connected (n)) 1901 if (is_connected (n))
1948 { 1902 {
1949 send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, n->session); 1903 send_disconnect (&n->id, n->address, n->session);
1950 1904
1951 n = lookup_neighbour (target); 1905 n = lookup_neighbour (target);
1952 if (NULL == n) 1906 if (NULL == n)
@@ -2028,26 +1982,23 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
2028 GST_neighbours_force_disconnect (peer); 1982 GST_neighbours_force_disconnect (peer);
2029} 1983}
2030 1984
1985
2031/** 1986/**
2032 * We received a 'SESSION_CONNECT_ACK' message from the other peer. 1987 * We received a 'SESSION_CONNECT_ACK' message from the other peer.
2033 * Consider switching to it. 1988 * Consider switching to it.
2034 * 1989 *
2035 * @param message possibly a 'struct SessionConnectMessage' (check format) 1990 * @param message possibly a 'struct SessionConnectMessage' (check format)
2036 * @param peer identity of the peer to switch the address for 1991 * @param peer identity of the peer to switch the address for
2037 * @param plugin_name name of transport that delivered the PONG
2038 * @param address address of the other peer, NULL if other peer 1992 * @param address address of the other peer, NULL if other peer
2039 * connected to us 1993 * connected to us
2040 * @param address_len number of bytes in address
2041 * @param session session to use (or NULL) 1994 * @param session session to use (or NULL)
2042 * @param ats performance data 1995 * @param ats performance data
2043 * @param ats_count number of entries in ats 1996 * @param ats_count number of entries in ats
2044 */ 1997 */
2045void 1998void
2046GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, 1999GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2047 const struct GNUNET_PeerIdentity *peer, 2000 const struct GNUNET_PeerIdentity *peer,
2048 const char *plugin_name, 2001 const struct GNUNET_HELLO_Address *address,
2049 const char *sender_address,
2050 uint16_t sender_address_len,
2051 struct Session *session, 2002 struct Session *session,
2052 const struct GNUNET_ATS_Information *ats, 2003 const struct GNUNET_ATS_Information *ats,
2053 uint32_t ats_count) 2004 uint32_t ats_count)
@@ -2090,24 +2041,20 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2090 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2041 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2091 "transport-ats", 2042 "transport-ats",
2092 "Giving ATS session %p of plugin %s for peer %s\n", 2043 "Giving ATS session %p of plugin %s for peer %s\n",
2093 session, plugin_name, GNUNET_i2s (peer)); 2044 session, address->transport_name, GNUNET_i2s (peer));
2094 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, 2045 GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count);
2095 sender_address_len, session, ats, ats_count);
2096 2046
2097 was_connected = is_connected (n); 2047 was_connected = is_connected (n);
2098 if (!is_connected (n)) 2048 if (!is_connected (n))
2099 { 2049 {
2100 change_state (n, S_CONNECTED); 2050 change_state (n, S_CONNECTED);
2101 GST_validation_set_address_use (&n->id, 2051 GST_validation_set_address_use (&n->id,
2102 n->plugin_name, 2052 n->address,
2103 n->session, 2053 n->session,
2104 n->addr,
2105 n->addrlen,
2106 GNUNET_YES); 2054 GNUNET_YES);
2107 } 2055 }
2108 2056
2109 GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, 2057 GNUNET_ATS_address_in_use (GST_ats, n->address, NULL, GNUNET_YES);
2110 n->addrlen, n->addr, GNUNET_YES);
2111 2058
2112#if DEBUG_TRANSPORT 2059#if DEBUG_TRANSPORT
2113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2124,16 +2071,14 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2124 ret = 2071 ret =
2125 send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, 2072 send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX,
2126 GNUNET_TIME_UNIT_FOREVER_REL, n->session, 2073 GNUNET_TIME_UNIT_FOREVER_REL, n->session,
2127 n->plugin_name, n->addr, n->addrlen, GNUNET_YES, NULL, 2074 n->address, GNUNET_YES, NULL,
2128 NULL); 2075 NULL);
2129 2076
2130 if (ret == GNUNET_SYSERR) 2077 if (ret == GNUNET_SYSERR)
2131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2132 "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n", 2079 "Failed to send SESSION_ACK to `%4s' using address '%s' session %X\n",
2133 GNUNET_i2s (&n->id), n->plugin_name, 2080 GNUNET_i2s (&n->id),
2134 (n->addrlen == 2081 GST_plugins_a2s (n->address), n->session);
2135 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2136 n->addrlen), n->session);
2137 2082
2138 2083
2139 if (!was_connected) 2084 if (!was_connected)
@@ -2148,11 +2093,9 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2148 GNUNET_NO); 2093 GNUNET_NO);
2149#if DEBUG_TRANSPORT 2094#if DEBUG_TRANSPORT
2150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2151 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", 2096 "Notify about connect of `%4s' using address '%s' session %X LINE %u\n",
2152 GNUNET_i2s (&n->id), n->plugin_name, 2097 GNUNET_i2s (&n->id),
2153 (n->addrlen == 2098 GST_plugins_a2s (n->address), n->session,
2154 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2155 n->addrlen), n->session,
2156 __LINE__); 2099 __LINE__);
2157#endif 2100#endif
2158 connect_notify_cb (callback_cls, &n->id, ats, ats_count); 2101 connect_notify_cb (callback_cls, &n->id, ats, ats_count);
@@ -2174,8 +2117,8 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2174void 2117void
2175GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, 2118GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2176 const struct GNUNET_PeerIdentity *peer, 2119 const struct GNUNET_PeerIdentity *peer,
2177 const char *plugin_name, const char *sender_address, 2120 const struct GNUNET_HELLO_Address *address,
2178 uint16_t sender_address_len, struct Session *session, 2121 struct Session *session,
2179 const struct GNUNET_ATS_Information *ats, 2122 const struct GNUNET_ATS_Information *ats,
2180 uint32_t ats_count) 2123 uint32_t ats_count)
2181{ 2124{
@@ -2197,7 +2140,7 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2197 n = lookup_neighbour (peer); 2140 n = lookup_neighbour (peer);
2198 if (NULL == n) 2141 if (NULL == n)
2199 { 2142 {
2200 send_disconnect (peer, plugin_name, sender_address, sender_address_len, 2143 send_disconnect (peer, address,
2201 session); 2144 session);
2202 GNUNET_break (0); 2145 GNUNET_break (0);
2203 return; 2146 return;
@@ -2217,15 +2160,13 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2217 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2160 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2218 "transport-ats", 2161 "transport-ats",
2219 "Giving ATS session %p of plugin %s for peer %s\n", 2162 "Giving ATS session %p of plugin %s for peer %s\n",
2220 session, plugin_name, GNUNET_i2s (peer)); 2163 session, address->transport_name, GNUNET_i2s (peer));
2221 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, 2164 GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count);
2222 sender_address_len, session, ats, ats_count);
2223 2165
2224 was_connected = is_connected (n); 2166 was_connected = is_connected (n);
2225 change_state (n, S_CONNECTED); 2167 change_state (n, S_CONNECTED);
2226 2168
2227 GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, 2169 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES);
2228 n->addrlen, n->addr, GNUNET_YES);
2229 2170
2230 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); 2171 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
2231 2172
@@ -2237,10 +2178,8 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2237 if (!was_connected) 2178 if (!was_connected)
2238 { 2179 {
2239 GST_validation_set_address_use (&n->id, 2180 GST_validation_set_address_use (&n->id,
2240 n->plugin_name, 2181 n->address,
2241 n->session, 2182 n->session,
2242 n->addr,
2243 n->addrlen,
2244 GNUNET_YES); 2183 GNUNET_YES);
2245 neighbours_connected++; 2184 neighbours_connected++;
2246 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 2185 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
@@ -2248,11 +2187,9 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2248 2187
2249#if DEBUG_TRANSPORT 2188#if DEBUG_TRANSPORT
2250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2251 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", 2190 "Notify about connect of `%4s' using address '%s' session %X LINE %u\n",
2252 GNUNET_i2s (&n->id), n->plugin_name, 2191 GNUNET_i2s (&n->id),
2253 (n->addrlen == 2192 GST_plugins_a2s (n->address), n->session,
2254 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2255 n->addrlen), n->session,
2256 __LINE__); 2193 __LINE__);
2257#endif 2194#endif
2258 connect_notify_cb (callback_cls, &n->id, ats, ats_count); 2195 connect_notify_cb (callback_cls, &n->id, ats, ats_count);
@@ -2277,11 +2214,7 @@ struct BlackListCheckContext
2277 2214
2278 struct Session *session; 2215 struct Session *session;
2279 2216
2280 char *sender_address; 2217 struct GNUNET_HELLO_Address *address;
2281
2282 uint16_t sender_address_len;
2283
2284 char *plugin_name;
2285 2218
2286 struct GNUNET_TIME_Absolute ts; 2219 struct GNUNET_TIME_Absolute ts;
2287}; 2220};
@@ -2305,6 +2238,7 @@ handle_connect_blacklist_cont (void *cls,
2305 /* not allowed */ 2238 /* not allowed */
2306 if (GNUNET_OK != result) 2239 if (GNUNET_OK != result)
2307 { 2240 {
2241 GNUNET_HELLO_address_free (bcc->address);
2308 GNUNET_free (bcc); 2242 GNUNET_free (bcc);
2309 return; 2243 return;
2310 } 2244 }
@@ -2318,13 +2252,11 @@ handle_connect_blacklist_cont (void *cls,
2318 if (NULL != bcc->session) 2252 if (NULL != bcc->session)
2319 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2253 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2320 "transport-ats", 2254 "transport-ats",
2321 "Giving ATS session %p of plugin %s address `%s' for peer %s\n", 2255 "Giving ATS session %p of address `%s' for peer %s\n",
2322 bcc->session, bcc->plugin_name, 2256 bcc->session,
2323 GST_plugins_a2s (bcc->plugin_name, bcc->sender_address, 2257 GST_plugins_a2s (bcc->address),
2324 bcc->sender_address_len),
2325 GNUNET_i2s (peer)); 2258 GNUNET_i2s (peer));
2326 GNUNET_ATS_address_update (GST_ats, peer, bcc->plugin_name, 2259 GNUNET_ATS_address_update (GST_ats, bcc->address,
2327 bcc->sender_address, bcc->sender_address_len,
2328 bcc->session, bcc->ats, bcc->ats_count); 2260 bcc->session, bcc->ats, bcc->ats_count);
2329 n->connect_ts = bcc->ts; 2261 n->connect_ts = bcc->ts;
2330 } 2262 }
@@ -2349,20 +2281,16 @@ handle_connect_blacklist_cont (void *cls,
2349 * 2281 *
2350 * @param message possibly a 'struct SessionConnectMessage' (check format) 2282 * @param message possibly a 'struct SessionConnectMessage' (check format)
2351 * @param peer identity of the peer to switch the address for 2283 * @param peer identity of the peer to switch the address for
2352 * @param plugin_name name of transport that delivered the PONG
2353 * @param address address of the other peer, NULL if other peer 2284 * @param address address of the other peer, NULL if other peer
2354 * connected to us 2285 * connected to us
2355 * @param address_len number of bytes in address
2356 * @param session session to use (or NULL) 2286 * @param session session to use (or NULL)
2357 * @param ats performance data 2287 * @param ats performance data
2358 * @param ats_count number of entries in ats (excluding 0-termination) 2288 * @param ats_count number of entries in ats (excluding 0-termination)
2359 */ 2289 */
2360void 2290void
2361GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, 2291GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2362 const struct GNUNET_PeerIdentity *peer, 2292 const struct GNUNET_PeerIdentity *peer,
2363 const char *plugin_name, 2293 const struct GNUNET_HELLO_Address *address,
2364 const char *sender_address,
2365 uint16_t sender_address_len,
2366 struct Session *session, 2294 struct Session *session,
2367 const struct GNUNET_ATS_Information *ats, 2295 const struct GNUNET_ATS_Information *ats,
2368 uint32_t ats_count) 2296 uint32_t ats_count)
@@ -2391,8 +2319,7 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2391 /* connected peer switches addresses */ 2319 /* connected peer switches addresses */
2392 if (is_connected (n)) 2320 if (is_connected (n))
2393 { 2321 {
2394 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, 2322 GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count);
2395 sender_address_len, session, ats, ats_count);
2396 return; 2323 return;
2397 } 2324 }
2398 } 2325 }
@@ -2401,26 +2328,16 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2401 /* do blacklist check */ 2328 /* do blacklist check */
2402 bcc = 2329 bcc =
2403 GNUNET_malloc (sizeof (struct BlackListCheckContext) + 2330 GNUNET_malloc (sizeof (struct BlackListCheckContext) +
2404 sizeof (struct GNUNET_ATS_Information) * (ats_count + 1) + 2331 sizeof (struct GNUNET_ATS_Information) * (ats_count + 1));
2405 sender_address_len + strlen (plugin_name) + 1);
2406
2407 bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 2332 bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
2408
2409 bcc->ats_count = ats_count + 1; 2333 bcc->ats_count = ats_count + 1;
2410 bcc->sender_address_len = sender_address_len; 2334 bcc->address = GNUNET_HELLO_address_copy (address);
2411 bcc->session = session; 2335 bcc->session = session;
2412
2413 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1]; 2336 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1];
2414 memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count); 2337 memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count);
2415 bcc->ats[ats_count].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); 2338 bcc->ats[ats_count].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
2416 bcc->ats[ats_count].value = htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value); 2339 bcc->ats[ats_count].value = htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value);
2417 bcc->sender_address = (char *) &bcc->ats[ats_count + 1]; 2340 GST_blacklist_test_allowed (peer, address->transport_name, handle_connect_blacklist_cont,
2418 memcpy (bcc->sender_address, sender_address, sender_address_len);
2419
2420 bcc->plugin_name = &bcc->sender_address[sender_address_len];
2421 strcpy (bcc->plugin_name, plugin_name);
2422
2423 GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont,
2424 bcc); 2341 bcc);
2425} 2342}
2426 2343