/**
* Front page. (/)
*/
-#define MAIN_PAGE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"/S\" method=\"post\">What is your desired domain name? <input type=\"text\" name=\"domain\" /> <p> What is your public key? <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /></body></html>"
+#define MAIN_PAGE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"S\" method=\"post\">What is your desired domain name? <input type=\"text\" name=\"domain\" /> <p> What is your public key? <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /></body></html>"
/**
* Second page (/S)
/**
* Public key submitted via form.
*/
- char public_key[1024];
+ char public_key[64];
};
/**
* Hash of the public key of the fcfsd zone.
*/
-static GNUNET_HashCode fcfsd_zone;
+static struct GNUNET_CRYPTO_ShortHashCode fcfsd_zone;
/**
* Private key for the fcfsd zone.
(void *) reply,
MHD_RESPMEM_MUST_FREE);
MHD_add_response_header (response,
- MHD_HTTP_HEADER_CONTENT_ENCODING,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
MIME_HTML);
ret = MHD_queue_response (connection,
MHD_HTTP_OK,
/**
- * Process a record that was stored in the namestore.
+ * Test if a name mapping was found, if so, refuse. If not, initiate storing of the record.
*
* @param cls closure
* @param zone_key public key of the zone
* because the user queried for a particular record type only)
*/
static void
-lookup_result_processor (void *cls,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_RsaSignature *signature)
+zone_to_name_cb (void *cls,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature *signature)
{
struct Request *request = cls;
struct GNUNET_NAMESTORE_RecordData r;
- GNUNET_HashCode pub;
+ struct GNUNET_CRYPTO_ShortHashCode pub;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_hash_from_string2 (request->public_key,
- strlen (request->public_key),
- &pub));
request->qe = NULL;
- if (0 != rd_count)
+ if (NULL != name)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Found %u existing records for domain `%s'\n"),
- rd_count,
- request->domain_name);
+ _("Found existing name `%s' for the given key\n"),
+ name);
request->phase = RP_FAIL;
run_httpd_now ();
return;
}
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_short_hash_from_string2 (request->public_key,
+ strlen (request->public_key),
+ &pub));
r.data = &pub;
r.data_size = sizeof (pub);
r.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
}
+/**
+ * Process a record that was stored in the namestore. Used to check if
+ * the requested name already exists in the namestore. If not,
+ * proceed to check if the requested key already exists.
+ *
+ * @param cls closure
+ * @param zone_key public key of the zone
+ * @param expire when does the corresponding block in the DHT expire (until
+ * when should we never do a DHT lookup for the same name again)?;
+ * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
+ * or the expiration time of the block in the namestore (even if there are zero
+ * records matching the desired record type)
+ * @param name name that is being mapped (at most 255 characters long)
+ * @param rd_count number of entries in 'rd' array
+ * @param rd array of records with data to store
+ * @param signature signature of the record block, NULL if signature is unavailable (i.e.
+ * because the user queried for a particular record type only)
+ */
+static void
+lookup_result_processor (void *cls,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature *signature)
+{
+ struct Request *request = cls;
+ struct GNUNET_CRYPTO_ShortHashCode pub;
+
+ request->qe = NULL;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_short_hash_from_string2 (request->public_key,
+ strlen (request->public_key),
+ &pub));
+ if (0 != rd_count)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Found %u existing records for domain `%s'\n"),
+ rd_count,
+ request->domain_name);
+ request->phase = RP_FAIL;
+ run_httpd_now ();
+ return;
+ }
+ request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
+ &fcfsd_zone,
+ &pub,
+ &zone_to_name_cb,
+ request);
+}
+
+
/**
* Main MHD callback for handling requests.
*
struct MHD_Response *response;
struct Request *request;
int ret;
- GNUNET_HashCode pub;
+ struct GNUNET_CRYPTO_ShortHashCode pub;
if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) ||
(0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) )
request->pp = NULL;
}
if (GNUNET_OK !=
- GNUNET_CRYPTO_hash_from_string2 (request->public_key,
- strlen (request->public_key),
- &pub))
+ GNUNET_CRYPTO_short_hash_from_string2 (request->public_key,
+ strlen (request->public_key),
+ &pub))
{
/* parse error */
return fill_s_reply ("Failed to parse given public key",
}
GNUNET_CRYPTO_rsa_key_get_public (fcfs_zone_pkey,
&pub);
- GNUNET_CRYPTO_hash (&pub, sizeof (pub), &fcfsd_zone);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Managing `%s' as FCFS zone on port %llu\n"),
- GNUNET_h2s_full (&fcfsd_zone),
- port);
+ GNUNET_CRYPTO_short_hash (&pub, sizeof (pub), &fcfsd_zone);
ns = GNUNET_NAMESTORE_connect (cfg);
if (NULL == ns)
{