diff options
author | Bart Polot <bart@net.in.tum.de> | 2015-07-31 06:58:55 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2015-07-31 06:58:55 +0000 |
commit | c14ff64b5c9ca4cfc5004e30622499cc782694c5 (patch) | |
tree | 85f5f098c4054fccffcf56159e3543cf1d252c48 /src/cadet/cadet_api.c | |
parent | 5eb722ace41a4cccf9d65bf408cfd3c45756cf2f (diff) | |
download | gnunet-c14ff64b5c9ca4cfc5004e30622499cc782694c5.tar.gz gnunet-c14ff64b5c9ca4cfc5004e30622499cc782694c5.zip |
- refactor GCP_get_peer, fix get peer info
Diffstat (limited to 'src/cadet/cadet_api.c')
-rw-r--r-- | src/cadet/cadet_api.c | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 055682d40..aaec91ede 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -1058,11 +1058,17 @@ static void | |||
1058 | process_get_peer (struct GNUNET_CADET_Handle *h, | 1058 | process_get_peer (struct GNUNET_CADET_Handle *h, |
1059 | const struct GNUNET_MessageHeader *message) | 1059 | const struct GNUNET_MessageHeader *message) |
1060 | { | 1060 | { |
1061 | struct GNUNET_CADET_LocalInfoTunnel *msg; | 1061 | struct GNUNET_CADET_LocalInfoPeer *msg; |
1062 | struct GNUNET_PeerIdentity *id; | ||
1063 | unsigned int epaths; | ||
1064 | unsigned int paths; | ||
1065 | unsigned int path_length; | ||
1066 | unsigned int i; | ||
1067 | int neighbor; | ||
1062 | size_t esize; | 1068 | size_t esize; |
1063 | size_t msize; | 1069 | size_t msize; |
1064 | 1070 | ||
1065 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n"); | 1071 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Info Peer messasge received\n"); |
1066 | if (NULL == h->info_cb.peer_cb) | 1072 | if (NULL == h->info_cb.peer_cb) |
1067 | { | 1073 | { |
1068 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); | 1074 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); |
@@ -1070,17 +1076,34 @@ process_get_peer (struct GNUNET_CADET_Handle *h, | |||
1070 | } | 1076 | } |
1071 | 1077 | ||
1072 | /* Verify message sanity */ | 1078 | /* Verify message sanity */ |
1073 | msg = (struct GNUNET_CADET_LocalInfoTunnel *) message; | 1079 | msg = (struct GNUNET_CADET_LocalInfoPeer *) message; |
1074 | msize = ntohs (message->size); | 1080 | esize = ntohs (message->size); |
1075 | esize = sizeof (struct GNUNET_CADET_LocalInfoPeer); | 1081 | msize = sizeof (struct GNUNET_CADET_LocalInfoPeer); |
1076 | if (esize > msize) | 1082 | if (esize < msize) |
1077 | { | 1083 | { |
1078 | GNUNET_break_op (0); | 1084 | GNUNET_break_op (0); |
1079 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); | 1085 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); |
1080 | goto clean_cls; | 1086 | goto clean_cls; |
1081 | } | 1087 | } |
1082 | // esize += ch_n * sizeof (CADET_ChannelNumber); | 1088 | epaths = (unsigned int) ntohs (msg->paths); |
1083 | // esize += c_n * sizeof (struct GNUNET_CADET_Hash); | 1089 | paths = 0; |
1090 | path_length = 0; | ||
1091 | neighbor = GNUNET_NO; | ||
1092 | id = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
1093 | for (i = 0; msize < esize; i++) | ||
1094 | { | ||
1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (&id[i])); | ||
1096 | msize += sizeof (struct GNUNET_PeerIdentity); | ||
1097 | path_length++; | ||
1098 | if (0 == memcmp (&id[i], &msg->destination, | ||
1099 | sizeof (struct GNUNET_PeerIdentity))) | ||
1100 | { | ||
1101 | if (1 == path_length) | ||
1102 | neighbor = GNUNET_YES; | ||
1103 | path_length = 0; | ||
1104 | paths++; | ||
1105 | } | ||
1106 | } | ||
1084 | if (msize != esize) | 1107 | if (msize != esize) |
1085 | { | 1108 | { |
1086 | GNUNET_break_op (0); | 1109 | GNUNET_break_op (0); |
@@ -1088,9 +1111,22 @@ process_get_peer (struct GNUNET_CADET_Handle *h, | |||
1088 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); | 1111 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); |
1089 | goto clean_cls; | 1112 | goto clean_cls; |
1090 | } | 1113 | } |
1114 | if (paths != epaths) | ||
1115 | { | ||
1116 | GNUNET_break_op (0); | ||
1117 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "p:%u, e: %u\n", paths, epaths); | ||
1118 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); | ||
1119 | goto clean_cls; | ||
1120 | } | ||
1091 | 1121 | ||
1092 | /* Call Callback with tunnel info. */ | 1122 | /* Call Callback with tunnel info. */ |
1093 | h->info_cb.peer_cb (h->info_cls, &msg->destination, 0, 0, 0, NULL); | 1123 | id = (struct GNUNET_PeerIdentity *) &msg[1]; |
1124 | h->info_cb.peer_cb (h->info_cls, | ||
1125 | &msg->destination, | ||
1126 | (int) ntohs (msg->tunnel), | ||
1127 | neighbor, | ||
1128 | paths, | ||
1129 | id); | ||
1094 | 1130 | ||
1095 | clean_cls: | 1131 | clean_cls: |
1096 | h->info_cb.peer_cb = NULL; | 1132 | h->info_cb.peer_cb = NULL; |