aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-05 15:20:49 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-05 15:20:49 +0000
commitdcfa706003e24e7893a8db3d94d5597a4c4829c9 (patch)
tree004d196b7ae72ccc96515b7a696fc25c34aa8fea /src/namestore/gnunet-service-namestore.c
parentf9aec0367413408e654a455ad703f44d352cf476 (diff)
downloadgnunet-dcfa706003e24e7893a8db3d94d5597a4c4829c9.tar.gz
gnunet-dcfa706003e24e7893a8db3d94d5597a4c4829c9.zip
- changes
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 600965e8a..a3f77dabb 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1062,6 +1062,146 @@ send:
1062 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1062 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1063} 1063}
1064 1064
1065
1066struct ZoneToNameCtx
1067{
1068 struct GNUNET_NAMESTORE_Client *nc;
1069 uint32_t rid;
1070};
1071
1072static void
1073handle_zone_to_name_it (void *cls,
1074 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
1075 struct GNUNET_TIME_Absolute expire,
1076 const char *name,
1077 unsigned int rd_count,
1078 const struct GNUNET_NAMESTORE_RecordData *rd,
1079 const struct GNUNET_CRYPTO_RsaSignature *signature)
1080{
1081 struct ZoneToNameCtx * ztn_ctx = cls;
1082 struct ZoneToNameResponseMessage *ztnr_msg;
1083 int16_t res = GNUNET_SYSERR;
1084 uint16_t name_len = 0;
1085 uint16_t rd_ser_len = 0 ;
1086 int32_t contains_sig = 0;
1087 size_t msg_size = 0;
1088
1089 char *rd_ser;
1090 char *name_tmp;
1091 char *rd_tmp;
1092 char *sig_tmp;
1093
1094 if ((zone_key != NULL) && (name != NULL))
1095 {
1096 /* found result */
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name ist \n");
1098 res = GNUNET_YES;
1099 name_len = strlen (name);
1100 }
1101 else
1102 {
1103 /* no result found */
1104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found no results\n");
1105 res = GNUNET_NO;
1106 name_len = 0;
1107 }
1108
1109 if (rd_count > 0)
1110 {
1111 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1112 char rd_ser[rd_ser_len];
1113 GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1114 }
1115 else
1116 rd_ser_len = 0;
1117
1118 if (signature != NULL)
1119 contains_sig = GNUNET_YES;
1120 else
1121 contains_sig = GNUNET_NO;
1122
1123 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len + contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature);
1124 ztnr_msg = GNUNET_malloc (msg_size);
1125
1126 name_tmp = (char *) &ztnr_msg[1];
1127 rd_tmp = &name_tmp[name_len];
1128 sig_tmp = &rd_tmp[rd_ser_len];
1129
1130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_TO_NAME_RESPONSE");
1131 ztnr_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1132 ztnr_msg->gns_header.header.size = htons (msg_size);
1133 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid);
1134 ztnr_msg->res = htons (res);
1135 ztnr_msg->rd_len = htons (rd_ser_len);
1136 ztnr_msg->rd_count = htons (rd_count);
1137 ztnr_msg->name_len = htons (name_len);
1138 ztnr_msg->contains_sig = htons (contains_sig);
1139 if (zone_key != NULL)
1140 ztnr_msg->zone_key = *zone_key;
1141 else
1142 memset (&ztnr_msg->zone_key, '\0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1143
1144 memcpy (&name_tmp, name, name_len);
1145 memcpy (&rd_tmp, &rd_ser, rd_ser_len);
1146 memcpy (&sig_tmp, signature, contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature));
1147
1148 GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, (const struct GNUNET_MessageHeader *) ztnr_msg, GNUNET_NO);
1149 GNUNET_free (ztnr_msg);
1150}
1151
1152
1153static void handle_zone_to_name (void *cls,
1154 struct GNUNET_SERVER_Client * client,
1155 const struct GNUNET_MessageHeader * message)
1156{
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_TO_NAME");
1158 struct GNUNET_NAMESTORE_Client *nc;
1159 struct ZoneToNameCtx ztn_ctx;
1160 size_t msg_size = 0;
1161 uint32_t rid = 0;
1162 int res;
1163
1164
1165 if (ntohs (message->size) != sizeof (struct ZoneToNameMessage))
1166 {
1167 GNUNET_break_op (0);
1168 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1169 return;
1170 }
1171
1172 nc = client_lookup(client);
1173 if (nc == NULL)
1174 {
1175 GNUNET_break_op (0);
1176 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1177 return;
1178 }
1179
1180 struct ZoneToNameMessage *ztn_msg = (struct ZoneToNameMessage *) message;
1181
1182 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
1183 {
1184 GNUNET_break_op (0);
1185 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1186 return;
1187 }
1188
1189 rid = ntohl (ztn_msg->gns_header.r_id);
1190
1191 ztn_ctx.rid = rid;
1192 ztn_ctx.nc = nc;
1193
1194 char * z_tmp = strdup (GNUNET_h2s (&ztn_msg->zone));
1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone `%s''\n",
1196 z_tmp,
1197 GNUNET_h2s (&ztn_msg->value_zone));
1198 GNUNET_free (z_tmp);
1199
1200 res = GSN_database->zone_to_name (GSN_database->cls, &ztn_msg->zone, &ztn_msg->value_zone, &handle_zone_to_name_it, &ztn_ctx);
1201
1202 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1203}
1204
1065struct ZoneIterationProcResult 1205struct ZoneIterationProcResult
1066{ 1206{
1067 int have_zone_key; 1207 int have_zone_key;
@@ -1289,6 +1429,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1289 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0}, 1429 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
1290 {&handle_record_remove, NULL, 1430 {&handle_record_remove, NULL,
1291 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0}, 1431 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
1432 {&handle_zone_to_name, NULL,
1433 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 0},
1292 {&handle_iteration_start, NULL, 1434 {&handle_iteration_start, NULL,
1293 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)}, 1435 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)},
1294 {&handle_iteration_stop, NULL, 1436 {&handle_iteration_stop, NULL,