diff options
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r-- | src/namestore/namestore_api.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 901ad9053..cf2247d18 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -1096,10 +1096,11 @@ GNUNET_NAMESTORE_records_store ( | |||
1096 | void *cont_cls) | 1096 | void *cont_cls) |
1097 | { | 1097 | { |
1098 | struct GNUNET_NAMESTORE_RecordInfo ri; | 1098 | struct GNUNET_NAMESTORE_RecordInfo ri; |
1099 | unsigned int rds_sent; | ||
1099 | ri.a_label = label; | 1100 | ri.a_label = label; |
1100 | ri.a_rd_count = rd_count; | 1101 | ri.a_rd_count = rd_count; |
1101 | ri.a_rd = (struct GNUNET_GNSRECORD_Data *) rd; | 1102 | ri.a_rd = (struct GNUNET_GNSRECORD_Data *) rd; |
1102 | return GNUNET_NAMESTORE_records_store2 (h, pkey, 1, &ri, | 1103 | return GNUNET_NAMESTORE_records_store2 (h, pkey, 1, &ri, &rds_sent, |
1103 | cont, cont_cls); | 1104 | cont, cont_cls); |
1104 | } | 1105 | } |
1105 | 1106 | ||
@@ -1109,6 +1110,7 @@ GNUNET_NAMESTORE_records_store2 ( | |||
1109 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | 1110 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1110 | unsigned int rd_set_count, | 1111 | unsigned int rd_set_count, |
1111 | const struct GNUNET_NAMESTORE_RecordInfo *record_info, | 1112 | const struct GNUNET_NAMESTORE_RecordInfo *record_info, |
1113 | unsigned int *rds_sent, | ||
1112 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 1114 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
1113 | void *cont_cls) | 1115 | void *cont_cls) |
1114 | { | 1116 | { |
@@ -1127,7 +1129,9 @@ GNUNET_NAMESTORE_records_store2 ( | |||
1127 | ssize_t sret; | 1129 | ssize_t sret; |
1128 | int i; | 1130 | int i; |
1129 | size_t rd_set_len = 0; | 1131 | size_t rd_set_len = 0; |
1132 | size_t max_len = UINT16_MAX - sizeof (struct RecordStoreMessage); | ||
1130 | 1133 | ||
1134 | *rds_sent = 0; | ||
1131 | for (i = 0; i < rd_set_count; i++) | 1135 | for (i = 0; i < rd_set_count; i++) |
1132 | { | 1136 | { |
1133 | label = record_info[i].a_label; | 1137 | label = record_info[i].a_label; |
@@ -1137,21 +1141,30 @@ GNUNET_NAMESTORE_records_store2 ( | |||
1137 | if (name_len > MAX_NAME_LEN) | 1141 | if (name_len > MAX_NAME_LEN) |
1138 | { | 1142 | { |
1139 | GNUNET_break (0); | 1143 | GNUNET_break (0); |
1144 | *rds_sent = 0; | ||
1140 | return NULL; | 1145 | return NULL; |
1141 | } | 1146 | } |
1142 | rd_ser_len[i] = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 1147 | rd_ser_len[i] = GNUNET_GNSRECORD_records_get_size (rd_count, rd); |
1143 | if (rd_ser_len[i] < 0) | 1148 | if (rd_ser_len[i] < 0) |
1144 | { | 1149 | { |
1145 | GNUNET_break (0); | 1150 | GNUNET_break (0); |
1151 | *rds_sent = 0; | ||
1146 | return NULL; | 1152 | return NULL; |
1147 | } | 1153 | } |
1148 | if (rd_ser_len[i] > UINT16_MAX) | 1154 | if (rd_ser_len[i] > max_len) |
1149 | { | 1155 | { |
1150 | GNUNET_break (0); | 1156 | GNUNET_break (0); |
1157 | *rds_sent = 0; | ||
1151 | return NULL; | 1158 | return NULL; |
1152 | } | 1159 | } |
1160 | if ((rd_set_len + sizeof (struct RecordSet) + name_len + rd_ser_len[i]) > | ||
1161 | max_len) | ||
1162 | break; | ||
1153 | rd_set_len += sizeof (struct RecordSet) + name_len + rd_ser_len[i]; | 1163 | rd_set_len += sizeof (struct RecordSet) + name_len + rd_ser_len[i]; |
1154 | } | 1164 | } |
1165 | *rds_sent = i; | ||
1166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1167 | "Sending %u of %u records!\n", *rds_sent, rd_count); | ||
1155 | rid = get_op_id (h); | 1168 | rid = get_op_id (h); |
1156 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | 1169 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1157 | qe->h = h; | 1170 | qe->h = h; |
@@ -1164,11 +1177,13 @@ GNUNET_NAMESTORE_records_store2 ( | |||
1164 | env = GNUNET_MQ_msg_extra (msg, | 1177 | env = GNUNET_MQ_msg_extra (msg, |
1165 | rd_set_len, | 1178 | rd_set_len, |
1166 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); | 1179 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); |
1180 | GNUNET_assert (NULL != msg); | ||
1181 | GNUNET_assert (NULL != env); | ||
1167 | msg->gns_header.r_id = htonl (rid); | 1182 | msg->gns_header.r_id = htonl (rid); |
1168 | msg->rd_set_count = htons (rd_set_count); | 1183 | msg->rd_set_count = htons ((uint16_t) (*rds_sent)); |
1169 | msg->private_key = *pkey; | 1184 | msg->private_key = *pkey; |
1170 | rd_set = (struct RecordSet*) &msg[1]; | 1185 | rd_set = (struct RecordSet*) &msg[1]; |
1171 | for (int i = 0; i < rd_set_count; i++) | 1186 | for (int i = 0; i < *rds_sent; i++) |
1172 | { | 1187 | { |
1173 | label = record_info[i].a_label; | 1188 | label = record_info[i].a_label; |
1174 | rd = record_info[i].a_rd; | 1189 | rd = record_info[i].a_rd; |
@@ -1193,7 +1208,7 @@ GNUNET_NAMESTORE_records_store2 ( | |||
1193 | } | 1208 | } |
1194 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1209 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1195 | "Sending NAMESTORE_RECORD_STORE message for name %u record sets\n", | 1210 | "Sending NAMESTORE_RECORD_STORE message for name %u record sets\n", |
1196 | rd_set_count); | 1211 | *rds_sent); |
1197 | qe->timeout_task = | 1212 | qe->timeout_task = |
1198 | GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe); | 1213 | GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe); |
1199 | if (NULL == h->mq) | 1214 | if (NULL == h->mq) |