[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r21368 - in gnunet/src: gns include
From: |
gnunet |
Subject: |
[GNUnet-SVN] r21368 - in gnunet/src: gns include |
Date: |
Wed, 9 May 2012 11:50:13 +0200 |
Author: schanzen
Date: 2012-05-09 11:50:13 +0200 (Wed, 09 May 2012)
New Revision: 21368
Modified:
gnunet/src/gns/gns.h
gnunet/src/gns/gns_api.c
gnunet/src/gns/gnunet-service-gns.c
gnunet/src/include/gnunet_gns_service.h
Log:
-new per zone api
Modified: gnunet/src/gns/gns.h
===================================================================
--- gnunet/src/gns/gns.h 2012-05-09 08:29:17 UTC (rev 21367)
+++ gnunet/src/gns/gns.h 2012-05-09 09:50:13 UTC (rev 21368)
@@ -53,9 +53,18 @@
uint32_t id GNUNET_PACKED;
/**
+ * Should we look up in the default zone?
+ */
+ uint32_t use_default_zone GNUNET_PACKED;
+
+ /**
+ * If use_default_zone is empty this zone is used for lookup
+ */
+ struct GNUNET_CRYPTO_ShortHashCode zone;
+
+ /**
* the type of record to look up
*/
- // FIXME: bad type - should be of GNUNET_GNS_RecordType
enum GNUNET_GNS_RecordType type;
/* Followed by the name to look up */
@@ -102,6 +111,16 @@
*/
uint32_t id GNUNET_PACKED;
+ /**
+ * Should we look up in the default zone?
+ */
+ uint32_t use_default_zone GNUNET_PACKED;
+
+ /**
+ * If use_default_zone is empty this zone is used for lookup
+ */
+ struct GNUNET_CRYPTO_ShortHashCode zone;
+
/* Followed by the name to shorten up */
};
Modified: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c 2012-05-09 08:29:17 UTC (rev 21367)
+++ gnunet/src/gns/gns_api.c 2012-05-09 09:50:13 UTC (rev 21368)
@@ -639,14 +639,16 @@
*
* @param handle handle to the GNS service
* @param name the name to look up
+ * @param zone the zone to start the resolution in
* @param type the record type to look up
* @param proc processor to call on result
* @param proc_cls closure for processor
* @return handle to the get
*/
struct GNUNET_GNS_QueueEntry *
-GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
+GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
const char * name,
+ struct GNUNET_CRYPTO_ShortHashCode *zone,
enum GNUNET_GNS_RecordType type,
GNUNET_GNS_LookupResultProcessor proc,
void *proc_cls)
@@ -682,6 +684,18 @@
lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
lookup_msg->header.size = htons (msize);
lookup_msg->id = htonl(qe->r_id);
+
+ if (NULL != zone)
+ {
+ lookup_msg->use_default_zone = htonl(0);
+ memcpy(&lookup_msg->zone, zone, sizeof(struct
GNUNET_CRYPTO_ShortHashCode));
+ }
+ else
+ {
+ lookup_msg->use_default_zone = htonl(1);
+ memset(&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
+ }
+
lookup_msg->type = htonl(type);
memcpy(&lookup_msg[1], name, strlen(name));
@@ -693,19 +707,40 @@
return qe;
}
+/**
+ * Perform an asynchronous Lookup operation on the GNS.
+ *
+ * @param handle handle to the GNS service
+ * @param name the name to look up
+ * @param type the record type to look up
+ * @param proc processor to call on result
+ * @param proc_cls closure for processor
+ * @return handle to the get
+ */
+struct GNUNET_GNS_QueueEntry *
+GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
+ const char * name,
+ enum GNUNET_GNS_RecordType type,
+ GNUNET_GNS_LookupResultProcessor proc,
+ void *proc_cls)
+{
+ return GNUNET_GNS_lookup_zone (handle, name, NULL, type, proc, proc_cls);
+}
/**
* Perform a name shortening operation on the GNS.
*
* @param handle handle to the GNS service
* @param name the name to look up
+ * @param zone the zone to start the resolution in
* @param proc function to call on result
* @param proc_cls closure for processor
* @return handle to the operation
*/
struct GNUNET_GNS_QueueEntry *
-GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
+GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
const char * name,
+ struct GNUNET_CRYPTO_ShortHashCode *zone,
GNUNET_GNS_ShortenResultProcessor proc,
void *proc_cls)
{
@@ -740,6 +775,18 @@
shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN);
shorten_msg->header.size = htons (msize);
shorten_msg->id = htonl(qe->r_id);
+
+ if (NULL != zone)
+ {
+ shorten_msg->use_default_zone = htonl(0);
+ memcpy(&shorten_msg->zone, zone,
+ sizeof(struct GNUNET_CRYPTO_ShortHashCode));
+ }
+ else
+ {
+ shorten_msg->use_default_zone = htonl(1);
+ memset(&shorten_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
+ }
memcpy(&shorten_msg[1], name, strlen(name));
@@ -750,8 +797,24 @@
return qe;
}
-
/**
+ * Perform a name shortening operation on the GNS.
+ *
+ * @param handle handle to the GNS service
+ * @param name the name to look up
+ * @param proc function to call on result
+ * @param proc_cls closure for processor
+ * @return handle to the operation
+ */
+struct GNUNET_GNS_QueueEntry *
+GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
+ const char * name,
+ GNUNET_GNS_ShortenResultProcessor proc,
+ void *proc_cls)
+{
+ return GNUNET_GNS_shorten_zone (handle, name, NULL, proc, proc_cls);
+}
+/**
* Perform an authority lookup for a given name.
*
* @param handle handle to the GNS service
Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-05-09 08:29:17 UTC (rev 21367)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-05-09 09:50:13 UTC (rev 21368)
@@ -60,6 +60,9 @@
/* request type */
enum GNUNET_GNS_RecordType type;
+ /* optional zone private key used for lookup */
+ struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
+
/* name to shorten */
char* name;
@@ -97,6 +100,9 @@
/* request type */
enum GNUNET_GNS_RecordType type;
+ /* optional zone private key used for lookup */
+ struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
+
/* the name to look up */
char* name; //Needed?
};
@@ -416,7 +422,44 @@
NULL);
}
+/**
+ * Lookup the private key for the zone
+ *
+ * @param zone the zone we want a private key for
+ * @return NULL of not found else the key
+ */
+struct GNUNET_CRYPTO_RsaPrivateKey*
+lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone)
+{
+ char* keydir;
+ struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
+ char* location;
+ struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GNS_cfg,
+ "namestore",
+ "ZONEFILE_DIRECTORY", &keydir))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No zonefile directory!\n");
+ return NULL;
+ }
+
+ GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
+
+ GNUNET_asprintf(&location, "%s%s%s.zkey", keydir,
+ DIR_SEPARATOR_STR, zonename);
+
+ if (GNUNET_YES == GNUNET_DISK_file_test (location))
+ key = GNUNET_CRYPTO_rsa_key_create_from_file (location);
+
+ GNUNET_free(location);
+ GNUNET_free(keydir);
+
+ return key;
+
+}
+
/* END DHT ZONE PROPAGATION */
/**
@@ -456,6 +499,7 @@
GNUNET_free(rmsg);
GNUNET_free_non_null(csh->name);
+ GNUNET_free_non_null(csh->zone_key);
GNUNET_free(csh);
}
@@ -477,6 +521,8 @@
struct ClientShortenHandle *csh;
char name[MAX_DNS_NAME_LENGTH];
char* nameptr = name;
+ struct GNUNET_CRYPTO_ShortHashCode zone;
+ struct GNUNET_CRYPTO_RsaPrivateKey *key;
if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
{
@@ -501,6 +547,7 @@
csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
csh->client = client;
csh->unique_id = sh_msg->id;
+ csh->zone_key = NULL;
GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
@@ -531,12 +578,26 @@
GNUNET_SERVER_notification_context_add (nc, client);
+ if (1 == ntohl(sh_msg->use_default_zone))
+ zone = zone_hash; //Default zone
+ else
+ zone = sh_msg->zone;
+
/* Start shortening */
if (GNUNET_YES == auto_import_pkey)
- gns_resolver_shorten_name(zone_hash, name, zone_key,
+ {
+ if (1 == ntohl(sh_msg->use_default_zone))
+ key = zone_key;
+ else
+ {
+ key = lookup_private_key(&sh_msg->zone);
+ csh->zone_key = key;
+ }
+ gns_resolver_shorten_name(zone, name, key,
&send_shorten_response, csh);
+ }
else
- gns_resolver_shorten_name(zone_hash, name, NULL,
+ gns_resolver_shorten_name(zone, name, NULL,
&send_shorten_response, csh);
}
@@ -682,6 +743,7 @@
}
+
/**
* Reply to client with the result from our lookup.
*
@@ -719,6 +781,10 @@
GNUNET_free(rmsg);
GNUNET_free(clh->name);
+
+ if (NULL != clh->zone_key)
+ GNUNET_free(clh->zone_key);
+
GNUNET_free(clh);
}
@@ -743,6 +809,8 @@
char name[MAX_DNS_NAME_LENGTH];
struct ClientLookupHandle *clh;
char* nameptr = name;
+ struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
+ struct GNUNET_CRYPTO_ShortHashCode zone;
if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
{
@@ -773,6 +841,7 @@
strcpy(clh->name, name);
clh->unique_id = sh_msg->id;
clh->type = ntohl(sh_msg->type);
+ clh->zone_key = NULL;
if (strlen (name) > MAX_DNS_NAME_LENGTH) {
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -781,17 +850,30 @@
send_lookup_response(clh, 0, NULL);
return;
}
+
+ if (1 == ntohl(sh_msg->use_default_zone))
+ zone = zone_hash; //Default zone
+ else
+ zone = sh_msg->zone;
if (GNUNET_YES == auto_import_pkey)
{
- gns_resolver_lookup_record(zone_hash, clh->type, name,
- zone_key,
+ if (1 == ntohl(sh_msg->use_default_zone))
+ key = zone_key;
+ else
+ {
+ key = lookup_private_key(&sh_msg->zone);
+ clh->zone_key = key;
+ }
+
+ gns_resolver_lookup_record(zone, clh->type, name,
+ key,
default_lookup_timeout,
&send_lookup_response, clh);
}
else
{
- gns_resolver_lookup_record(zone_hash, clh->type, name,
+ gns_resolver_lookup_record(zone, clh->type, name,
NULL,
default_lookup_timeout,
&send_lookup_response, clh);
@@ -826,6 +908,8 @@
{&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
};
+ GNS_cfg = c;
+
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
"ZONEKEY", &keyfile))
{
Modified: gnunet/src/include/gnunet_gns_service.h
===================================================================
--- gnunet/src/include/gnunet_gns_service.h 2012-05-09 08:29:17 UTC (rev
21367)
+++ gnunet/src/include/gnunet_gns_service.h 2012-05-09 09:50:13 UTC (rev
21368)
@@ -120,7 +120,8 @@
/**
- * Perform an asynchronous lookup operation on the GNS.
+ * Perform an asynchronous lookup operation on the GNS
+ * in the default zone.
*
* @param handle handle to the GNS service
* @param name the name to look up
@@ -137,6 +138,26 @@
GNUNET_GNS_LookupResultProcessor proc,
void *proc_cls);
+/**
+ * Perform an asynchronous lookup operation on the GNS
+ * in the zone specified by 'zone'.
+ *
+ * @param handle handle to the GNS service
+ * @param name the name to look up
+ * @param zone the zone to start the resolution in
+ * @param type the GNUNET_GNS_RecordType to look for
+ * @param proc function to call on result
+ * @param proc_cls closure for processor
+ *
+ * @return handle to the queued request
+ */
+struct GNUNET_GNS_QueueEntry *
+GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
+ const char * name,
+ struct GNUNET_CRYPTO_ShortHashCode *zone,
+ enum GNUNET_GNS_RecordType type,
+ GNUNET_GNS_LookupResultProcessor proc,
+ void *proc_cls);
/* *************** Standard API: shorten ******************* */
@@ -168,6 +189,23 @@
void *proc_cls);
+/**
+ * Perform a name shortening operation on the GNS.
+ *
+ * @param handle handle to the GNS service
+ * @param name the name to look up
+ * @param zone the zone to start the resolution in
+ * @param proc function to call on result
+ * @param proc_cls closure for processor
+ * @return handle to the operation
+ */
+struct GNUNET_GNS_QueueEntry *
+GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
+ const char * name,
+ struct GNUNET_CRYPTO_ShortHashCode *zone,
+ GNUNET_GNS_ShortenResultProcessor proc,
+ void *proc_cls);
+
/* *************** Standard API: get authority ******************* */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r21368 - in gnunet/src: gns include,
gnunet <=