/** * Process a given reply to the lookup request * * @param qe a queue entry * @param msg the lookup message received */ static void process_lookup_reply (struct GNUNET_GNS_LookupRequest *qe, const struct GNUNET_GNS_ClientLookupResultMessage *msg) { struct GNUNET_GNS_Handle *handle = qe->gns_handle; struct PendingMessage *p = (struct PendingMessage *) &qe[1]; uint32_t rd_count = ntohl (msg->rd_count); struct GNUNET_NAMESTORE_RecordData rd[rd_count]; size_t mlen; if (GNUNET_YES != p->transmitted) { /* service send reply to query we never managed to send!? */ GNUNET_break (0); force_reconnect (handle); return; } mlen = ntohs (msg->header.size); mlen -= sizeof (struct GNUNET_GNS_ClientLookupResultMessage); if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (mlen, (const char*) &msg[1], rd_count, rd)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to serialize lookup reply from GNS service!\n")); qe->lookup_proc (qe->proc_cls, 0, NULL); } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received lookup reply from GNS service (%u records)\n", (unsigned int) rd_count); qe->lookup_proc (qe->proc_cls, rd_count, rd); } GNUNET_CONTAINER_DLL_remove (handle->lookup_head, handle->lookup_tail, qe); GNUNET_free (qe); }
static void handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze, struct ZoneIterationResponseMessage *msg, size_t size) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", "ZONE_ITERATION_RESPONSE"); struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubdummy; size_t msg_len = 0; size_t exp_msg_len = 0; size_t name_len = 0; size_t rd_len = 0; unsigned rd_count = 0; char *name_tmp; char *rd_ser_tmp; struct GNUNET_TIME_Absolute expire; msg_len = ntohs (msg->gns_header.header.size); rd_len = ntohs (msg->rd_len); rd_count = ntohs (msg->rd_count); name_len = ntohs (msg->name_len); expire = GNUNET_TIME_absolute_ntoh (msg->expire); exp_msg_len = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_len; if (msg_len != exp_msg_len) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message size describes with `%u' bytes but calculated size is %u bytes \n", msg_len, exp_msg_len); GNUNET_break_op (0); return; } if (0 != ntohs (msg->reserved)) { GNUNET_break_op (0); return; } memset (&pubdummy, '\0', sizeof (pubdummy)); if ((0 == name_len) && (0 == (memcmp (&msg->public_key, &pubdummy, sizeof (pubdummy))))) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration is completed!\n"); GNUNET_CONTAINER_DLL_remove(ze->h->z_head, ze->h->z_tail, ze); if (ze->proc != NULL) ze->proc(ze->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL , 0, NULL, NULL); GNUNET_free (ze); return; } name_tmp = (char *) &msg[1]; if ((name_tmp[name_len -1] != '\0') || (name_len > 256)) { GNUNET_break_op (0); return; } rd_ser_tmp = (char *) &name_tmp[name_len]; struct GNUNET_NAMESTORE_RecordData rd[rd_count]; if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)) { GNUNET_break_op (0); return; } if (ze->proc != NULL) ze->proc(ze->proc_cls, &msg->public_key, expire, name_tmp, rd_count, rd, &msg->signature); }
static void handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, struct ZoneToNameResponseMessage* msg, size_t size) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", "ZONE_TO_NAME_RESPONSE"); struct GNUNET_NAMESTORE_Handle *h = qe->nsh; /* Operation done, remove */ GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); int res = ntohs (msg->res); struct GNUNET_TIME_Absolute expire; size_t name_len; size_t rd_ser_len; unsigned int rd_count; char * name_tmp; char * rd_tmp; if (res == GNUNET_SYSERR) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "An error occured during zone to name operation\n"); if (qe->proc != NULL) qe->proc (qe->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL); } else if (res == GNUNET_NO) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone to name mapping \n"); if (qe->proc != NULL) qe->proc (qe->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL); } else if (res == GNUNET_YES) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore has result for zone to name mapping \n"); name_len = ntohs (msg->name_len); rd_count = ntohs (msg->rd_count); rd_ser_len = ntohs (msg->rd_len); expire = GNUNET_TIME_absolute_ntoh(msg->expire); name_tmp = (char *) &msg[1]; if (name_len > 0) { GNUNET_assert ('\0' == name_tmp[name_len -1]); GNUNET_assert (name_len -1 == strlen(name_tmp)); } rd_tmp = &name_tmp[name_len]; struct GNUNET_NAMESTORE_RecordData rd[rd_count]; if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_tmp, rd_count, rd)) { GNUNET_break_op (0); return; } if (qe->proc != NULL) qe->proc (qe->proc_cls, &msg->zone_key, expire, name_tmp, rd_count, rd, &msg->signature); } else GNUNET_break_op (0); GNUNET_free (qe); }
static void handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, struct LookupNameResponseMessage * msg, size_t size) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", "LOOKUP_NAME_RESPONSE"); struct GNUNET_NAMESTORE_Handle *h = qe->nsh; /* Operation done, remove */ GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); char *name; char * rd_tmp; struct GNUNET_CRYPTO_RsaSignature *signature = NULL; struct GNUNET_TIME_Absolute expire; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key_tmp; size_t exp_msg_len; size_t msg_len = 0; size_t name_len = 0; size_t rd_len = 0; int contains_sig = GNUNET_NO; int rd_count = 0; rd_len = ntohs (msg->rd_len); rd_count = ntohs (msg->rd_count); msg_len = ntohs (msg->gns_header.header.size); name_len = ntohs (msg->name_len); contains_sig = ntohs (msg->contains_sig); expire = GNUNET_TIME_absolute_ntoh(msg->expire); exp_msg_len = sizeof (struct LookupNameResponseMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len + rd_len; if (msg_len != exp_msg_len) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message size describes with `%u' bytes but calculated size is %u bytes \n", msg_len, exp_msg_len); GNUNET_break_op (0); return; } name = (char *) &msg[1]; if (name_len > 0) { GNUNET_assert ('\0' == name[name_len -1]); GNUNET_assert ((name_len - 1) == strlen(name)); } rd_tmp = &name[name_len]; /* deserialize records */ struct GNUNET_NAMESTORE_RecordData rd[rd_count]; if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_len, rd_tmp, rd_count, rd)) { GNUNET_break_op (0); return; } /* reset values if values not contained */ if (contains_sig == GNUNET_NO) signature = NULL; else signature = &msg->signature; if (name_len == 0) name = NULL; if (name != NULL) public_key_tmp = &msg->public_key; else public_key_tmp = NULL; if (qe->proc != NULL) { qe->proc (qe->proc_cls, public_key_tmp, expire, name, rd_count, (rd_count > 0) ? rd : NULL, signature); } GNUNET_free (qe); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { size_t len; int c; int rd_count = 3; size_t data_len; struct GNUNET_NAMESTORE_RecordData src[rd_count]; memset(src, '\0', rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); data_len = 0; for (c = 0; c < rd_count; c++) { src[c].record_type = c+1; src[c].data_size = data_len; src[c].data = GNUNET_malloc (data_len); /* Setting data to data_len * record_type */ memset ((char *) src[c].data, 'a', data_len); data_len += 10; } res = 0; len = GNUNET_NAMESTORE_records_get_size(rd_count, src); char rd_ser[len]; GNUNET_assert (len == GNUNET_NAMESTORE_records_serialize(rd_count, src, len, rd_ser)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Serialized data len: %u\n",len); GNUNET_assert (rd_ser != NULL); struct GNUNET_NAMESTORE_RecordData dst[rd_count]; GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_records_deserialize (len, rd_ser, rd_count, dst)); GNUNET_assert (dst != NULL); for (c = 0; c < rd_count; c++) { if (src[c].data_size != dst[c].data_size) { GNUNET_break (0); res = 1; } if (0 != GNUNET_TIME_absolute_get_difference(src[c].expiration, dst[c].expiration).rel_value) { GNUNET_break (0); res = 1; } if (src[c].flags != dst[c].flags) { GNUNET_break (0); res = 1; } if (src[c].record_type != dst[c].record_type) { GNUNET_break (0); res = 1; } size_t data_size = src[c].data_size; char data[data_size]; memset (data, 'a', data_size); if (0 != memcmp (data, dst[c].data, data_size)) { GNUNET_break (0); res = 1; } if (0 != memcmp (data, src[c].data, data_size)) { GNUNET_break (0); res = 1; } if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size)) { GNUNET_break (0); res = 1; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c); } for (c = 0; c < rd_count; c++) { GNUNET_free ((void *)src[c].data); } }