aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet_peer.c')
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c103
1 files changed, 86 insertions, 17 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 05555e693..b375d51ca 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2017 GNUnet e.V. 3 Copyright (C) 2001-2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -242,12 +240,25 @@ struct CadetPeer
242const char * 240const char *
243GCP_2s (const struct CadetPeer *cp) 241GCP_2s (const struct CadetPeer *cp)
244{ 242{
245 static char buf[32]; 243 static char buf[5];
246 244 char *ret;
247 GNUNET_snprintf (buf, 245
248 sizeof (buf), 246 if ((NULL == cp) ||
249 "P(%s)", 247 (NULL == &cp->pid.public_key))
250 GNUNET_i2s (&cp->pid)); 248 return "NULL";
249
250
251 ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&cp->pid.public_key);
252
253 if (NULL == ret)
254 return "NULL";
255
256
257 strncpy (buf,
258 ret,
259 sizeof (buf) - 1);
260 GNUNET_free (ret);
261 buf[4] = '\0';
251 return buf; 262 return buf;
252} 263}
253 264
@@ -649,6 +660,27 @@ mqm_execute (struct GCP_MessageQueueManager *mqm)
649 } 660 }
650 else 661 else
651 { 662 {
663 {
664 const struct GNUNET_MessageHeader *mh;
665
666 mh = GNUNET_MQ_env_get_msg (mqm->env);
667 switch (ntohs (mh->type))
668 {
669 case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX:
670 {
671 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg
672 = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *) mh;
673 LOG (GNUNET_ERROR_TYPE_DEBUG,
674 "P2P forwarding KX with ephemeral %s to %s on CID %s\n",
675 GNUNET_e2s (&msg->ephemeral_key),
676 GCP_2s (cp),
677 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
678 }
679 break;
680 default:
681 break;
682 }
683 }
652 LOG (GNUNET_ERROR_TYPE_DEBUG, 684 LOG (GNUNET_ERROR_TYPE_DEBUG,
653 "Sending to peer %s from MQM %p\n", 685 "Sending to peer %s from MQM %p\n",
654 GCP_2s (cp), 686 GCP_2s (cp),
@@ -1044,7 +1076,7 @@ GCP_add_connection (struct CadetPeer *cp,
1044 struct CadetConnection *cc) 1076 struct CadetConnection *cc)
1045{ 1077{
1046 LOG (GNUNET_ERROR_TYPE_DEBUG, 1078 LOG (GNUNET_ERROR_TYPE_DEBUG,
1047 "Adding connection %s to peer %s\n", 1079 "Adding %s to peer %s\n",
1048 GCC_2s (cc), 1080 GCC_2s (cc),
1049 GCP_2s (cp)); 1081 GCP_2s (cp));
1050 GNUNET_assert (GNUNET_OK == 1082 GNUNET_assert (GNUNET_OK ==
@@ -1185,6 +1217,8 @@ GCP_iterate_paths (struct CadetPeer *cp,
1185 (NULL == cp->core_mq) ? "" : " including direct link"); 1217 (NULL == cp->core_mq) ? "" : " including direct link");
1186 if (NULL != cp->core_mq) 1218 if (NULL != cp->core_mq)
1187 { 1219 {
1220 /* FIXME: this branch seems to duplicate the
1221 i=0 case below (direct link). Leave out!??? -CG */
1188 struct CadetPeerPath *path; 1222 struct CadetPeerPath *path;
1189 1223
1190 path = GCPP_get_path_from_route (1, 1224 path = GCPP_get_path_from_route (1,
@@ -1213,6 +1247,41 @@ GCP_iterate_paths (struct CadetPeer *cp,
1213 return ret; 1247 return ret;
1214} 1248}
1215 1249
1250/**
1251 * Iterate over the paths to a peer without direct link.
1252 *
1253 * @param cp Peer to get path info.
1254 * @param callback Function to call for every path.
1255 * @param callback_cls Closure for @a callback.
1256 * @return Number of iterated paths.
1257 */
1258unsigned int
1259GCP_iterate_indirect_paths (struct CadetPeer *cp,
1260 GCP_PathIterator callback,
1261 void *callback_cls)
1262{
1263 unsigned int ret = 0;
1264
1265 LOG (GNUNET_ERROR_TYPE_DEBUG,
1266 "Iterating over paths to peer %s without direct link\n",
1267 GCP_2s (cp));
1268 for (unsigned int i=1;i<cp->path_dll_length;i++)
1269 {
1270 for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
1271 NULL != pe;
1272 pe = pe->next)
1273 {
1274 ret++;
1275 if (GNUNET_NO ==
1276 callback (callback_cls,
1277 pe->path,
1278 i))
1279 return ret;
1280 }
1281 }
1282 return ret;
1283}
1284
1216 1285
1217/** 1286/**
1218 * Iterate over the paths to @a cp where 1287 * Iterate over the paths to @a cp where