aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api_scheduling.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-06-14 12:50:27 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-06-14 12:50:27 +0000
commitc18fcd88d8897d0645900a1b6f527232d0153f88 (patch)
tree445441c0ac27a28e747757d7d347c8f44e1df72f /src/ats/ats_api_scheduling.c
parent21f92c1b07d8361c270fa08f9f41d78a3e8e18b3 (diff)
downloadgnunet-c18fcd88d8897d0645900a1b6f527232d0153f88.tar.gz
gnunet-c18fcd88d8897d0645900a1b6f527232d0153f88.zip
- adding GNUNET_ATS_address_add functionality .. no changes to scheduling API yet
Diffstat (limited to 'src/ats/ats_api_scheduling.c')
-rw-r--r--src/ats/ats_api_scheduling.c115
1 files changed, 113 insertions, 2 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index 0e67a8628..cdf948291 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -1049,6 +1049,101 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
1049 1049
1050 1050
1051/** 1051/**
1052 * We have a new address ATS should know. Addresses have to be added with this
1053 * function before they can be: updated, set in use and destroyed
1054 *
1055 * @param sh handle
1056 * @param address the address
1057 * @param session session handle (if available)
1058 * @param ats performance data for the address
1059 * @param ats_count number of performance records in 'ats'
1060 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1061 */
1062int
1063GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
1064 const struct GNUNET_HELLO_Address *address,
1065 struct Session *session,
1066 const struct GNUNET_ATS_Information *ats,
1067 uint32_t ats_count)
1068{
1069
1070 struct PendingMessage *p;
1071 struct AddressUpdateMessage *m;
1072 struct GNUNET_ATS_Information *am;
1073 char *pm;
1074 size_t namelen;
1075 size_t msize;
1076 uint32_t s = 0;
1077
1078 if (address == NULL)
1079 {
1080 GNUNET_break (0);
1081 return GNUNET_SYSERR;
1082 }
1083 if ((address == NULL) && (session == NULL))
1084 {
1085 GNUNET_break (0);
1086 return GNUNET_SYSERR;
1087 }
1088
1089 namelen =
1090 (address->transport_name ==
1091 NULL) ? 0 : strlen (address->transport_name) + 1;
1092 msize =
1093 sizeof (struct AddressUpdateMessage) + address->address_length +
1094 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
1095 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
1096 (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
1097 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
1098 (ats_count >=
1099 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)))
1100 {
1101 GNUNET_break (0);
1102 return GNUNET_SYSERR;
1103 }
1104
1105 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1106 p->size = msize;
1107 p->is_init = GNUNET_NO;
1108 m = (struct AddressUpdateMessage *) &p[1];
1109 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
1110 m->header.size = htons (msize);
1111 m->ats_count = htonl (ats_count);
1112 m->peer = address->peer;
1113 m->address_length = htons (address->address_length);
1114 m->plugin_name_length = htons (namelen);
1115 if (NULL != session)
1116 {
1117 s = find_session_id (sh, session, &address->peer);
1118 if (NOT_FOUND != s)
1119 {
1120 /* Already existing */
1121 GNUNET_break (0);
1122 return GNUNET_SYSERR;
1123 }
1124 s = find_empty_session_slot (sh, session, &address->peer);
1125 GNUNET_break (NOT_FOUND != s);
1126 }
1127 m->session_id = htonl (s);
1128
1129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1130 "Adding address for peer `%s', plugin `%s', session %p id %u\n",
1131 GNUNET_i2s (&address->peer),
1132 address->transport_name, session, s);
1133
1134 am = (struct GNUNET_ATS_Information *) &m[1];
1135 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
1136 pm = (char *) &am[ats_count];
1137 memcpy (pm, address->address, address->address_length);
1138 memcpy (&pm[address->address_length], address->transport_name, namelen);
1139 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
1140 do_transmit (sh);
1141 return GNUNET_OK;
1142
1143}
1144
1145
1146/**
1052 * We have updated performance statistics for a given address. Note 1147 * We have updated performance statistics for a given address. Note
1053 * that this function can be called for addresses that are currently 1148 * that this function can be called for addresses that are currently
1054 * in use as well as addresses that are valid but not actively in use. 1149 * in use as well as addresses that are valid but not actively in use.
@@ -1127,6 +1222,11 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
1127 } 1222 }
1128 m->session_id = htonl (s); 1223 m->session_id = htonl (s);
1129 1224
1225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1226 "Trying to update address for peer `%s', plugin `%s', session %p id %u\n",
1227 GNUNET_i2s (&address->peer),
1228 address->transport_name, session, s);
1229
1130 am = (struct GNUNET_ATS_Information *) &m[1]; 1230 am = (struct GNUNET_ATS_Information *) &m[1];
1131 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 1231 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
1132 pm = (char *) &am[ats_count]; 1232 pm = (char *) &am[ats_count];
@@ -1172,6 +1272,12 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
1172 return; 1272 return;
1173 } 1273 }
1174 1274
1275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1276 "Trying to set address to %s for peer `%s', plugin `%s', session %p\n",
1277 GNUNET_i2s (&address->peer),
1278 (GNUNET_NO == in_use) ? "NO" : "YES",
1279 address->transport_name, session);
1280
1175 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 1281 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1176 p->size = msize; 1282 p->size = msize;
1177 p->is_init = GNUNET_NO; 1283 p->is_init = GNUNET_NO;
@@ -1260,12 +1366,17 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
1260 if ((NULL != session) && (NOT_FOUND == s)) 1366 if ((NULL != session) && (NOT_FOUND == s))
1261 { 1367 {
1262 /* trying to delete unknown address */ 1368 /* trying to delete unknown address */
1263 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1264 "Trying to delete unknown address for peer `%s', plugin `%s', session %p\n", 1370 "Trying to delete unknown address for peer `%s', plugin `%s', session %p\n",
1265 GNUNET_i2s (&address->peer), address->transport_name, session); 1371 GNUNET_i2s (&address->peer), address->transport_name, session);
1266 GNUNET_break (0);
1267 return; 1372 return;
1268 } 1373 }
1374 else
1375 {
1376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1377 "Deleting address for peer `%s', plugin `%s', session %p\n",
1378 GNUNET_i2s (&address->peer), address->transport_name, session);
1379 }
1269 1380
1270 m->session_id = htonl (s); 1381 m->session_id = htonl (s);
1271 pm = (char *) &m[1]; 1382 pm = (char *) &m[1];