diff options
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r-- | src/namestore/namestore_api.c | 87 |
1 files changed, 72 insertions, 15 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index ab356838b..55745d83d 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010-2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2010-2013, 2016 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 | /** |
@@ -40,6 +38,11 @@ | |||
40 | 38 | ||
41 | #define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__) | 39 | #define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__) |
42 | 40 | ||
41 | /** | ||
42 | * We grant the namestore up to 1 minute of latency, if it is slower than | ||
43 | * that, store queries will fail. | ||
44 | */ | ||
45 | #define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES | ||
43 | 46 | ||
44 | /** | 47 | /** |
45 | * An QueueEntry used to store information for a pending | 48 | * An QueueEntry used to store information for a pending |
@@ -100,6 +103,11 @@ struct GNUNET_NAMESTORE_QueueEntry | |||
100 | struct GNUNET_MQ_Envelope *env; | 103 | struct GNUNET_MQ_Envelope *env; |
101 | 104 | ||
102 | /** | 105 | /** |
106 | * Task scheduled to warn us if the namestore is way too slow. | ||
107 | */ | ||
108 | struct GNUNET_SCHEDULER_Task *timeout_task; | ||
109 | |||
110 | /** | ||
103 | * The operation id this zone iteration operation has | 111 | * The operation id this zone iteration operation has |
104 | */ | 112 | */ |
105 | uint32_t op_id; | 113 | uint32_t op_id; |
@@ -300,6 +308,8 @@ free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe) | |||
300 | qe); | 308 | qe); |
301 | if (NULL != qe->env) | 309 | if (NULL != qe->env) |
302 | GNUNET_MQ_discard (qe->env); | 310 | GNUNET_MQ_discard (qe->env); |
311 | if (NULL != qe->timeout_task) | ||
312 | GNUNET_SCHEDULER_cancel (qe->timeout_task); | ||
303 | GNUNET_free (qe); | 313 | GNUNET_free (qe); |
304 | } | 314 | } |
305 | 315 | ||
@@ -968,6 +978,33 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) | |||
968 | 978 | ||
969 | 979 | ||
970 | /** | 980 | /** |
981 | * Task launched to warn the user that the namestore is | ||
982 | * excessively slow and that a query was thus dropped. | ||
983 | * | ||
984 | * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *` | ||
985 | */ | ||
986 | static void | ||
987 | warn_delay (void *cls) | ||
988 | { | ||
989 | struct GNUNET_NAMESTORE_QueueEntry *qe = cls; | ||
990 | |||
991 | qe->timeout_task = NULL; | ||
992 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
993 | "Did not receive response from namestore after %s!\n", | ||
994 | GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE, | ||
995 | GNUNET_YES)); | ||
996 | if (NULL != qe->cont) | ||
997 | { | ||
998 | qe->cont (qe->cont_cls, | ||
999 | GNUNET_SYSERR, | ||
1000 | "timeout"); | ||
1001 | qe->cont = NULL; | ||
1002 | } | ||
1003 | GNUNET_NAMESTORE_cancel (qe); | ||
1004 | } | ||
1005 | |||
1006 | |||
1007 | /** | ||
971 | * Store an item in the namestore. If the item is already present, | 1008 | * Store an item in the namestore. If the item is already present, |
972 | * it is replaced with the new record. Use an empty array to | 1009 | * it is replaced with the new record. Use an empty array to |
973 | * remove all records under the given name. | 1010 | * remove all records under the given name. |
@@ -994,7 +1031,7 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
994 | struct GNUNET_MQ_Envelope *env; | 1031 | struct GNUNET_MQ_Envelope *env; |
995 | char *name_tmp; | 1032 | char *name_tmp; |
996 | char *rd_ser; | 1033 | char *rd_ser; |
997 | size_t rd_ser_len; | 1034 | ssize_t rd_ser_len; |
998 | size_t name_len; | 1035 | size_t name_len; |
999 | uint32_t rid; | 1036 | uint32_t rid; |
1000 | struct RecordStoreMessage *msg; | 1037 | struct RecordStoreMessage *msg; |
@@ -1006,6 +1043,18 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1006 | GNUNET_break (0); | 1043 | GNUNET_break (0); |
1007 | return NULL; | 1044 | return NULL; |
1008 | } | 1045 | } |
1046 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
1047 | rd); | ||
1048 | if (rd_ser_len < 0) | ||
1049 | { | ||
1050 | GNUNET_break (0); | ||
1051 | return NULL; | ||
1052 | } | ||
1053 | if (rd_ser_len > UINT16_MAX) | ||
1054 | { | ||
1055 | GNUNET_break (0); | ||
1056 | return NULL; | ||
1057 | } | ||
1009 | rid = get_op_id (h); | 1058 | rid = get_op_id (h); |
1010 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | 1059 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1011 | qe->h = h; | 1060 | qe->h = h; |
@@ -1017,8 +1066,6 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1017 | qe); | 1066 | qe); |
1018 | 1067 | ||
1019 | /* setup msg */ | 1068 | /* setup msg */ |
1020 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
1021 | rd); | ||
1022 | env = GNUNET_MQ_msg_extra (msg, | 1069 | env = GNUNET_MQ_msg_extra (msg, |
1023 | name_len + rd_ser_len, | 1070 | name_len + rd_ser_len, |
1024 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); | 1071 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); |
@@ -1038,8 +1085,10 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1038 | rd, | 1085 | rd, |
1039 | rd_ser_len, | 1086 | rd_ser_len, |
1040 | rd_ser); | 1087 | rd_ser); |
1041 | if (0 > sret) | 1088 | if ( (0 > sret) || |
1089 | (sret != rd_ser_len) ) | ||
1042 | { | 1090 | { |
1091 | GNUNET_break (0); | ||
1043 | GNUNET_free (env); | 1092 | GNUNET_free (env); |
1044 | return NULL; | 1093 | return NULL; |
1045 | } | 1094 | } |
@@ -1048,12 +1097,20 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1048 | "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", | 1097 | "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", |
1049 | label, | 1098 | label, |
1050 | rd_count); | 1099 | rd_count); |
1051 | 1100 | qe->timeout_task = GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, | |
1101 | &warn_delay, | ||
1102 | qe); | ||
1052 | if (NULL == h->mq) | 1103 | if (NULL == h->mq) |
1104 | { | ||
1053 | qe->env = env; | 1105 | qe->env = env; |
1106 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1107 | "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n"); | ||
1108 | } | ||
1054 | else | 1109 | else |
1110 | { | ||
1055 | GNUNET_MQ_send (h->mq, | 1111 | GNUNET_MQ_send (h->mq, |
1056 | env); | 1112 | env); |
1113 | } | ||
1057 | return qe; | 1114 | return qe; |
1058 | } | 1115 | } |
1059 | 1116 | ||