aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-11-30 14:01:31 +0000
committerChristian Grothoff <christian@grothoff.org>2010-11-30 14:01:31 +0000
commit28824d44aba065b4a0afe6c9ee8526d7d8082611 (patch)
tree8981b460d847f1e0892d23985775c84fdb808bd9 /src
parentffc69424a45eebbb3e720b66447eeac1a50ffaac (diff)
downloadgnunet-28824d44aba065b4a0afe6c9ee8526d7d8082611.tar.gz
gnunet-28824d44aba065b4a0afe6c9ee8526d7d8082611.zip
pass ATS data to clients
Diffstat (limited to 'src')
-rw-r--r--src/core/gnunet-service-core.c67
1 files changed, 53 insertions, 14 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index e6f0a1eed..5a2b03d5d 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -1188,7 +1188,10 @@ handle_client_init (void *cls,
1188 const uint16_t *types; 1188 const uint16_t *types;
1189 uint16_t *wtypes; 1189 uint16_t *wtypes;
1190 struct Neighbour *n; 1190 struct Neighbour *n;
1191 struct ConnectNotifyMessage cnm; 1191 struct ConnectNotifyMessage *cnm;
1192 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
1193 struct GNUNET_TRANSPORT_ATS_Information *ats;
1194 size_t size;
1192 unsigned int i; 1195 unsigned int i;
1193 1196
1194#if DEBUG_CORE_CLIENT 1197#if DEBUG_CORE_CLIENT
@@ -1250,22 +1253,39 @@ handle_client_init (void *cls,
1250 if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT)) 1253 if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT))
1251 { 1254 {
1252 /* notify new client about existing neighbours */ 1255 /* notify new client about existing neighbours */
1253 cnm.header.size = htons (sizeof (struct ConnectNotifyMessage));
1254 cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
1255 cnm.ats_count = htonl (0);
1256 cnm.ats.type = htonl (0);
1257 cnm.ats.value = htonl (0);
1258 n = neighbours; 1256 n = neighbours;
1259 while (n != NULL) 1257 while (n != NULL)
1260 { 1258 {
1259 size = sizeof (struct ConnectNotifyMessage) +
1260 (n->ats_count+1) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1261 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1262 {
1263 GNUNET_break (0);
1264 /* recovery strategy: throw away performance data */
1265 GNUNET_array_grow (n->ats,
1266 n->ats_count,
1267 0);
1268 size = sizeof (struct ConnectNotifyMessage) +
1269 (n->ats_count+1) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1270 }
1271 cnm = (struct ConnectNotifyMessage*) buf;
1272 cnm->header.size = htons (size);
1273 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
1274 cnm->ats_count = htonl (n->ats_count);
1275 ats = &cnm->ats;
1276 memcpy (ats,
1277 n->ats,
1278 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count);
1279 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1280 ats[n->ats_count].value = htonl (0);
1261 if (n->status == PEER_STATE_KEY_CONFIRMED) 1281 if (n->status == PEER_STATE_KEY_CONFIRMED)
1262 { 1282 {
1263#if DEBUG_CORE_CLIENT 1283#if DEBUG_CORE_CLIENT
1264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1265 "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); 1285 "Sending `%s' message to client.\n", "NOTIFY_CONNECT");
1266#endif 1286#endif
1267 cnm.peer = n->peer; 1287 cnm->peer = n->peer;
1268 send_to_client (c, &cnm.header, GNUNET_NO); 1288 send_to_client (c, &cnm->header, GNUNET_NO);
1269 } 1289 }
1270 n = n->next; 1290 n = n->next;
1271 } 1291 }
@@ -3673,9 +3693,22 @@ send_p2p_message_to_client (struct Neighbour *sender,
3673 struct Client *client, 3693 struct Client *client,
3674 const void *m, size_t msize) 3694 const void *m, size_t msize)
3675{ 3695{
3676 char buf[msize + sizeof (struct NotifyTrafficMessage)]; 3696 size_t size = msize + sizeof (struct NotifyTrafficMessage) +
3697 (sender->ats_count+1) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3698 char buf[size];
3677 struct NotifyTrafficMessage *ntm; 3699 struct NotifyTrafficMessage *ntm;
3700 struct GNUNET_TRANSPORT_ATS_Information *ats;
3678 3701
3702 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
3703 {
3704 GNUNET_break (0);
3705 /* recovery strategy: throw performance data away... */
3706 GNUNET_array_grow (sender->ats,
3707 sender->ats_count,
3708 0);
3709 size = msize + sizeof (struct NotifyTrafficMessage) +
3710 (sender->ats_count+1) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3711 }
3679#if DEBUG_CORE 3712#if DEBUG_CORE
3680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3681 "Core service passes message from `%4s' of type %u to client.\n", 3714 "Core service passes message from `%4s' of type %u to client.\n",
@@ -3683,13 +3716,19 @@ send_p2p_message_to_client (struct Neighbour *sender,
3683 (unsigned int) ntohs (((const struct GNUNET_MessageHeader *) m)->type)); 3716 (unsigned int) ntohs (((const struct GNUNET_MessageHeader *) m)->type));
3684#endif 3717#endif
3685 ntm = (struct NotifyTrafficMessage *) buf; 3718 ntm = (struct NotifyTrafficMessage *) buf;
3686 ntm->header.size = htons (msize + sizeof (struct NotifyTrafficMessage)); 3719 ntm->header.size = htons (size);
3687 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND); 3720 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND);
3688 ntm->ats_count = htonl (0); 3721 ntm->ats_count = htonl (sender->ats_count);
3689 ntm->ats.type = htonl (0);
3690 ntm->ats.value = htonl (0);
3691 ntm->peer = sender->peer; 3722 ntm->peer = sender->peer;
3692 memcpy (&ntm[1], m, msize); 3723 ats = &ntm->ats;
3724 memcpy (ats,
3725 sender->ats,
3726 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count);
3727 ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
3728 ats[sender->ats_count].value = htonl (0);
3729 memcpy (&ats[sender->ats_count+1],
3730 m,
3731 msize);
3693 send_to_client (client, &ntm->header, GNUNET_YES); 3732 send_to_client (client, &ntm->header, GNUNET_YES);
3694} 3733}
3695 3734