aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_clients.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-12-29 20:16:01 +0100
committerChristian Grothoff <christian@grothoff.org>2021-12-29 20:16:01 +0100
commit9859314207ad10e37b73eacd5dfccac59ec8153e (patch)
tree4c32f5d5b5d00cf69855f29b1b9e26e51e787123 /src/dht/gnunet-service-dht_clients.c
parentdaa9284567865177279a692eb722e257ed06923e (diff)
downloadgnunet-9859314207ad10e37b73eacd5dfccac59ec8153e.tar.gz
gnunet-9859314207ad10e37b73eacd5dfccac59ec8153e.zip
-start to use new block API in DHT
Diffstat (limited to 'src/dht/gnunet-service-dht_clients.c')
-rw-r--r--src/dht/gnunet-service-dht_clients.c144
1 files changed, 66 insertions, 78 deletions
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c
index cfcb25336..feccde8a8 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -125,6 +125,8 @@ struct ClientQueryRecord
125 125
126 /** 126 /**
127 * Any message options for this request 127 * Any message options for this request
128 *
129 * FIXME: why uint32_t instead of enum?
128 */ 130 */
129 uint32_t msg_options; 131 uint32_t msg_options;
130 132
@@ -493,6 +495,7 @@ handle_dht_local_put (void *cls,
493 GNUNET_h2s (&dht_msg->key)); 495 GNUNET_h2s (&dht_msg->key));
494 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 496 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
495 &dht_msg->key, 497 &dht_msg->key,
498 &dht_msg->key,
496 0, 499 0,
497 NULL, 500 NULL,
498 0, 501 0,
@@ -585,6 +588,7 @@ handle_local_result (void *cls,
585 // possibly avoid even looking up the client! 588 // possibly avoid even looking up the client!
586 GDS_CLIENTS_handle_reply (expiration_time, 589 GDS_CLIENTS_handle_reply (expiration_time,
587 key, 590 key,
591 key,
588 0, NULL, 592 0, NULL,
589 put_path_length, put_path, 593 put_path_length, put_path,
590 type, 594 type,
@@ -967,6 +971,11 @@ struct ForwardReplyContext
967 const struct GNUNET_PeerIdentity *put_path; 971 const struct GNUNET_PeerIdentity *put_path;
968 972
969 /** 973 /**
974 * Hash under which the payload is stored.
975 */
976 const struct GNUNET_HashCode *query_hash;
977
978 /**
970 * Embedded payload. 979 * Embedded payload.
971 */ 980 */
972 const void *data; 981 const void *data;
@@ -1004,7 +1013,7 @@ struct ForwardReplyContext
1004 * @return #GNUNET_YES (we should continue to iterate), 1013 * @return #GNUNET_YES (we should continue to iterate),
1005 * if the result is mal-formed, #GNUNET_NO 1014 * if the result is mal-formed, #GNUNET_NO
1006 */ 1015 */
1007static int 1016static enum GNUNET_GenericReturnValue
1008forward_reply (void *cls, 1017forward_reply (void *cls,
1009 const struct GNUNET_HashCode *key, 1018 const struct GNUNET_HashCode *key,
1010 void *value) 1019 void *value)
@@ -1013,14 +1022,14 @@ forward_reply (void *cls,
1013 struct ClientQueryRecord *record = value; 1022 struct ClientQueryRecord *record = value;
1014 struct GNUNET_MQ_Envelope *env; 1023 struct GNUNET_MQ_Envelope *env;
1015 struct GNUNET_DHT_ClientResultMessage *reply; 1024 struct GNUNET_DHT_ClientResultMessage *reply;
1016 enum GNUNET_BLOCK_EvaluationResult eval; 1025 enum GNUNET_BLOCK_ReplyEvaluationResult eval;
1017 int do_free; 1026 bool do_free;
1018 struct GNUNET_HashCode ch; 1027 struct GNUNET_HashCode ch;
1019 struct GNUNET_PeerIdentity *paths; 1028 struct GNUNET_PeerIdentity *paths;
1020 1029
1021 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 1030 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
1022 "CLIENT-RESULT %s\n", 1031 "CLIENT-RESULT %s\n",
1023 GNUNET_h2s_full (key)); 1032 GNUNET_h2s_full (frc->query_hash));
1024 if ((record->type != GNUNET_BLOCK_TYPE_ANY) && 1033 if ((record->type != GNUNET_BLOCK_TYPE_ANY) &&
1025 (record->type != frc->type)) 1034 (record->type != frc->type))
1026 { 1035 {
@@ -1028,13 +1037,24 @@ forward_reply (void *cls,
1028 "Record type mismatch, not passing request for key %s to local client\n", 1037 "Record type mismatch, not passing request for key %s to local client\n",
1029 GNUNET_h2s (key)); 1038 GNUNET_h2s (key));
1030 GNUNET_STATISTICS_update (GDS_stats, 1039 GNUNET_STATISTICS_update (GDS_stats,
1031 gettext_noop 1040 "# Key match, type mismatches in REPLY to CLIENT",
1032 ( 1041 1,
1033 "# Key match, type mismatches in REPLY to CLIENT"), 1042 GNUNET_NO);
1034 1, GNUNET_NO);
1035 return GNUNET_YES; /* type mismatch */ 1043 return GNUNET_YES; /* type mismatch */
1036 } 1044 }
1037 GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch); 1045 if ( (0 == (record->msg_options & GNUNET_DHT_RO_FIND_PEER)) &&
1046 (0 != GNUNET_memcmp (key,
1047 frc->query_hash)) )
1048 {
1049 GNUNET_STATISTICS_update (GDS_stats,
1050 "# Inexact key match, but exact match required",
1051 1,
1052 GNUNET_NO);
1053 return GNUNET_YES; /* type mismatch */
1054 }
1055 GNUNET_CRYPTO_hash (frc->data,
1056 frc->data_size,
1057 &ch);
1038 for (unsigned int i = 0; i < record->seen_replies_count; i++) 1058 for (unsigned int i = 0; i < record->seen_replies_count; i++)
1039 if (0 == memcmp (&record->seen_replies[i], 1059 if (0 == memcmp (&record->seen_replies[i],
1040 &ch, 1060 &ch,
@@ -1051,63 +1071,45 @@ forward_reply (void *cls,
1051 return GNUNET_YES; /* duplicate */ 1071 return GNUNET_YES; /* duplicate */
1052 } 1072 }
1053 eval 1073 eval
1054 = GNUNET_BLOCK_evaluate (GDS_block_context, 1074 = GNUNET_BLOCK_check_reply (GDS_block_context,
1055 record->type, 1075 record->type,
1056 NULL, 1076 NULL,
1057 GNUNET_BLOCK_EO_NONE, 1077 key,
1058 key, 1078 record->xquery,
1059 record->xquery, 1079 record->xquery_size,
1060 record->xquery_size, 1080 frc->data,
1061 frc->data, 1081 frc->data_size);
1062 frc->data_size);
1063 LOG (GNUNET_ERROR_TYPE_DEBUG, 1082 LOG (GNUNET_ERROR_TYPE_DEBUG,
1064 "Evaluation result is %d for key %s for local client's query\n", 1083 "Evaluation result is %d for key %s for local client's query\n",
1065 (int) eval, 1084 (int) eval,
1066 GNUNET_h2s (key)); 1085 GNUNET_h2s (key));
1067 switch (eval) 1086 switch (eval)
1068 { 1087 {
1069 case GNUNET_BLOCK_EVALUATION_OK_LAST: 1088 case GNUNET_BLOCK_REPLY_OK_LAST:
1070 do_free = GNUNET_YES; 1089 do_free = true;
1071 break; 1090 break;
1072 1091 case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED:
1073 case GNUNET_BLOCK_EVALUATION_OK_MORE: 1092 case GNUNET_BLOCK_REPLY_OK_MORE:
1074 GNUNET_array_append (record->seen_replies, 1093 GNUNET_array_append (record->seen_replies,
1075 record->seen_replies_count, 1094 record->seen_replies_count,
1076 ch); 1095 ch);
1077 do_free = GNUNET_NO; 1096 do_free = false;
1078 break; 1097 break;
1079 1098 case GNUNET_BLOCK_REPLY_OK_DUPLICATE:
1080 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
1081 /* should be impossible to encounter here */ 1099 /* should be impossible to encounter here */
1082 GNUNET_break (0); 1100 GNUNET_break (0);
1083 return GNUNET_YES; 1101 return GNUNET_YES;
1084 1102 case GNUNET_BLOCK_REPLY_INVALID:
1085 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
1086 GNUNET_break_op (0); 1103 GNUNET_break_op (0);
1087 return GNUNET_NO; 1104 return GNUNET_NO;
1088 1105 case GNUNET_BLOCK_REPLY_IRRELEVANT:
1089 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
1090 GNUNET_break (0);
1091 return GNUNET_NO;
1092
1093 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
1094 GNUNET_break (0);
1095 return GNUNET_NO;
1096
1097 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
1098 return GNUNET_YES; 1106 return GNUNET_YES;
1099
1100 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
1101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1102 _ ("Unsupported block type (%u) in request!\n"), record->type);
1103 return GNUNET_NO;
1104
1105 default: 1107 default:
1106 GNUNET_break (0); 1108 GNUNET_break (0);
1107 return GNUNET_NO; 1109 return GNUNET_NO;
1108 } 1110 }
1109 GNUNET_STATISTICS_update (GDS_stats, 1111 GNUNET_STATISTICS_update (GDS_stats,
1110 gettext_noop ("# RESULTS queued for clients"), 1112 "# RESULTS queued for clients",
1111 1, 1113 1,
1112 GNUNET_NO); 1114 GNUNET_NO);
1113 env = GNUNET_MQ_msg_extra (reply, 1115 env = GNUNET_MQ_msg_extra (reply,
@@ -1149,7 +1151,8 @@ forward_reply (void *cls,
1149 * client(s). 1151 * client(s).
1150 * 1152 *
1151 * @param expiration when will the reply expire 1153 * @param expiration when will the reply expire
1152 * @param key the query this reply is for 1154 * @param key the key of the query that triggered the reply
1155 * @param query_hash the query hash of the response
1153 * @param get_path_length number of peers in @a get_path 1156 * @param get_path_length number of peers in @a get_path
1154 * @param get_path path the reply took on get 1157 * @param get_path path the reply took on get
1155 * @param put_path_length number of peers in @a put_path 1158 * @param put_path_length number of peers in @a put_path
@@ -1161,6 +1164,7 @@ forward_reply (void *cls,
1161void 1164void
1162GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, 1165GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1163 const struct GNUNET_HashCode *key, 1166 const struct GNUNET_HashCode *key,
1167 const struct GNUNET_HashCode *query_hash,
1164 unsigned int get_path_length, 1168 unsigned int get_path_length,
1165 const struct GNUNET_PeerIdentity *get_path, 1169 const struct GNUNET_PeerIdentity *get_path,
1166 unsigned int put_path_length, 1170 unsigned int put_path_length,
@@ -1173,27 +1177,15 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1173 size_t msize; 1177 size_t msize;
1174 1178
1175 msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size 1179 msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size
1176 + (get_path_length + put_path_length) * sizeof(struct 1180 + (get_path_length + put_path_length)
1177 GNUNET_PeerIdentity); 1181 * sizeof(struct GNUNET_PeerIdentity);
1178 if (msize >= GNUNET_MAX_MESSAGE_SIZE) 1182 if (msize >= GNUNET_MAX_MESSAGE_SIZE)
1179 { 1183 {
1180 GNUNET_break (0); 1184 GNUNET_break (0);
1181 return; 1185 return;
1182 } 1186 }
1183 if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map,
1184 key))
1185 {
1186 LOG (GNUNET_ERROR_TYPE_DEBUG,
1187 "No matching client for reply for key %s\n",
1188 GNUNET_h2s (key));
1189 GNUNET_STATISTICS_update (GDS_stats,
1190 gettext_noop (
1191 "# REPLIES ignored for CLIENTS (no match)"),
1192 1,
1193 GNUNET_NO);
1194 return; /* no matching request, fast exit! */
1195 }
1196 frc.expiration = expiration; 1187 frc.expiration = expiration;
1188 frc.query_hash = query_hash;
1197 frc.get_path = get_path; 1189 frc.get_path = get_path;
1198 frc.put_path = put_path; 1190 frc.put_path = put_path;
1199 frc.data = data; 1191 frc.data = data;
@@ -1204,10 +1196,20 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1204 LOG (GNUNET_ERROR_TYPE_DEBUG, 1196 LOG (GNUNET_ERROR_TYPE_DEBUG,
1205 "Forwarding reply for key %s to client\n", 1197 "Forwarding reply for key %s to client\n",
1206 GNUNET_h2s (key)); 1198 GNUNET_h2s (key));
1207 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 1199 if (0 ==
1208 key, 1200 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
1209 &forward_reply, 1201 key,
1210 &frc); 1202 &forward_reply,
1203 &frc))
1204 {
1205 LOG (GNUNET_ERROR_TYPE_DEBUG,
1206 "No matching client for reply for key %s\n",
1207 GNUNET_h2s (key));
1208 GNUNET_STATISTICS_update (GDS_stats,
1209 "# REPLIES ignored for CLIENTS (no match)",
1210 1,
1211 GNUNET_NO);
1212 }
1211} 1213}
1212 1214
1213 1215
@@ -1285,20 +1287,6 @@ GDS_CLIENTS_process_get (uint32_t options,
1285} 1287}
1286 1288
1287 1289
1288/**
1289 * Check if some client is monitoring GET RESP messages and notify
1290 * them in that case.
1291 *
1292 * @param type The type of data in the result.
1293 * @param get_path Peers on GET path (or NULL if not recorded).
1294 * @param get_path_length number of entries in get_path.
1295 * @param put_path peers on the PUT path (or NULL if not recorded).
1296 * @param put_path_length number of entries in get_path.
1297 * @param exp Expiration time of the data.
1298 * @param key Key of the data.
1299 * @param data Pointer to the result data.
1300 * @param size Number of bytes in @a data.
1301 */
1302void 1290void
1303GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type, 1291GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type,
1304 const struct GNUNET_PeerIdentity *get_path, 1292 const struct GNUNET_PeerIdentity *get_path,