[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20172 - gnunet/src/gns
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20172 - gnunet/src/gns |
Date: |
Thu, 1 Mar 2012 15:57:15 +0100 |
Author: schanzen
Date: 2012-03-01 15:57:15 +0100 (Thu, 01 Mar 2012)
New Revision: 20172
Modified:
gnunet/src/gns/Makefile.am
gnunet/src/gns/plugin_block_gns.c
gnunet/src/gns/test_gns_twopeer.c
Log:
-modified test
Modified: gnunet/src/gns/Makefile.am
===================================================================
--- gnunet/src/gns/Makefile.am 2012-03-01 13:59:23 UTC (rev 20171)
+++ gnunet/src/gns/Makefile.am 2012-03-01 14:57:15 UTC (rev 20172)
@@ -38,9 +38,11 @@
test_gns_twopeer.c
test_gns_twopeer_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la \
$(top_builddir)/src/testing/libgnunettesting.la
test_gns_twopeer_DEPENDENCIES = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la \
$(top_builddir)/src/testing/libgnunettesting.la
#gnunet_gns_lookup_SOURCES = \
@@ -62,7 +64,7 @@
$(top_builddir)/src/dns/libgnunetdns.la \
$(top_builddir)/src/dns/libgnunetdnsparser.la \
$(top_builddir)/src/dht/libgnunetdht.la \
- $(top_builddir)/src/gns/libgnunetnamestore.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la \
$(GN_LIBINTL)
gnunet_service_gns_DEPENDENCIES = \
$(top_builddir)/src/tun/libgnunettun.la \
Modified: gnunet/src/gns/plugin_block_gns.c
===================================================================
--- gnunet/src/gns/plugin_block_gns.c 2012-03-01 13:59:23 UTC (rev 20171)
+++ gnunet/src/gns/plugin_block_gns.c 2012-03-01 14:57:15 UTC (rev 20172)
@@ -69,8 +69,9 @@
GNUNET_HashCode mhash;
GNUNET_HashCode chash;
struct GNSNameRecordBlock *nrb;
- struct GNSRecordBlock *rb;
uint32_t rd_count;
+ char* rd_data = NULL;
+ int rd_len;
unsigned int record_match;
if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
@@ -94,53 +95,56 @@
record_match = 0;
rd_count = ntohl(nrb->rd_count);
+ rd_data = (char*)&nrb[1];
+ rd_data += strlen(name) + 1;
+ rd_len = reply_block_size - (strlen(name) + 1
+ + sizeof(struct GNSNameRecordBlock));
{
struct GNUNET_NAMESTORE_RecordData rd[rd_count];
unsigned int i;
uint32_t record_xquery = ntohl(*((uint32_t*)xquery));
-
- rb = (struct GNSRecordBlock*)(&name[strlen(name) + 1]);
+
+ if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_len,
+ rd_data,
+ rd_count,
+ rd))
+ {
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ }
+
for (i=0; i<rd_count; i++)
{
- rd[i].record_type = ntohl(rb->type);
- rd[i].expiration =
- GNUNET_TIME_absolute_ntoh(rb->expiration);
- rd[i].data_size = ntohl(rb->data_length);
- rd[i].flags = ntohl(rb->flags);
- rd[i].data = (char*)&rb[1];
- rb = (struct GNSRecordBlock *)((char*)&rb[1] + rd[i].data_size);
+ if (xquery_size < sizeof(uint32_t))
+ continue;
- if (xquery_size == 0)
- continue;
-
if (rd[i].record_type == record_xquery)
- record_match++;
+ record_match++;
}
- }
- /*if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key,
- name,
- rd_count,
- rd,
- NULL))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Signature invalid\n");
- return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
- }*/
+ if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key,
+ name,
+ rd_count,
+ rd,
+ NULL))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n");
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ }
+ }
//No record matches query
if ((xquery_size > 0) && (record_match == 0))
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Records match\n");
- //FIXME do bf check before or after crypto??
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Records match\n");
+
if (NULL != bf)
{
GNUNET_CRYPTO_hash(reply_block, reply_block_size, &chash);
GNUNET_BLOCK_mingle_hash(&chash, bf_mutator, &mhash);
if (NULL != *bf)
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Check BF\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Check BF\n");
if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(*bf, &mhash))
return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
}
@@ -150,7 +154,6 @@
}
GNUNET_CONTAINER_bloomfilter_add(*bf, &mhash);
}
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "No dup\n");
return GNUNET_BLOCK_EVALUATION_OK_MORE;
}
Modified: gnunet/src/gns/test_gns_twopeer.c
===================================================================
--- gnunet/src/gns/test_gns_twopeer.c 2012-03-01 13:59:23 UTC (rev 20171)
+++ gnunet/src/gns/test_gns_twopeer.c 2012-03-01 14:57:15 UTC (rev 20172)
@@ -42,12 +42,15 @@
#include "gnunet_dht_service.h"
#include "block_dns.h"
#include "gnunet_signatures.h"
+#include "gnunet_namestore_service.h"
+#include "gnunet_dnsparser_lib.h"
+#include "gnunet_gns_service.h"
/* DEFINES */
#define VERBOSE GNUNET_YES
/* Timeout for entire testcase */
-#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 40)
+#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80)
/* If number of peers not in config file, use this number */
#define DEFAULT_NUM_PEERS 2
@@ -349,6 +352,12 @@
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ struct GNUNET_NAMESTORE_Handle* namestore_handle;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey, bob_pkey;
+ struct GNUNET_CRYPTO_RsaPrivateKey *alice_key, *bob_key;
+ char* bob_keyfile;
+ char* alice_keyfile;
+
/* Get path from configuration file */
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
@@ -366,26 +375,12 @@
/* Set peers_left so we know when all peers started */
peers_left = num_peers;
-
- /* Set up a task to end testing if peer start fails */
- die_task =
- GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
- "didn't start all daemons in reasonable
amount of time!!!");
- alice_online = 0;
- bob_online = 0;
- expected_connections = 1;
-
- /* Start alice */
- d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
- NULL, NULL, NULL, &alice_started, NULL);
-
/* Somebody care to explain? */
uint16_t port = 6000;
uint32_t upnum = 23;
uint32_t fdnum = 42;
-
/**
* Modify some config options for bob
* namely swap keys and disable dns hijacking
@@ -400,9 +395,90 @@
"NO");
GNUNET_CONFIGURATION_set_value_string (cfg2, "gns", "ZONEKEY",
"/tmp/bobkey");
- GNUNET_CONFIGURATION_set_value_string (cfg2, "gns", "TRUSTED",
- "alice:/tmp/alicekey");
+ /* put records into namestore */
+ namestore_handle = GNUNET_NAMESTORE_connect(cfg);
+ if (NULL == namestore_handle)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
+ ok = -1;
+ return;
+ }
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns",
+ "ZONEKEY",
+ &alice_keyfile))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get alice's key from
cfg\n");
+ ok = -1;
+ return;
+ }
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg2, "gns",
+ "ZONEKEY",
+ &bob_keyfile))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get bob's key from cfg\n");
+ ok = -1;
+ return;
+ }
+
+ alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile);
+ bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (bob_keyfile);
+
+ GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
+ GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
+
+ struct GNUNET_NAMESTORE_RecordData rd;
+ rd.data = &bob_pkey;
+ rd.expiration = GNUNET_TIME_absolute_get_forever ();
+ rd.data_size = sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);
+ rd.record_type = GNUNET_GNS_RECORD_PKEY;
+
+ GNUNET_NAMESTORE_record_create (namestore_handle,
+ alice_key,
+ "bob",
+ &rd,
+ NULL,
+ NULL);
+
+ rd.data = &alice_pkey;
+ GNUNET_NAMESTORE_record_create (namestore_handle,
+ bob_key,
+ "alice",
+ &rd,
+ NULL,
+ NULL);
+
+ char* ip = "127.0.0.1";
+ struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
+ GNUNET_assert(1 == inet_pton (AF_INET, ip, web));
+
+ rd.data_size = sizeof(struct in_addr);
+ rd.data = web;
+ rd.record_type = GNUNET_DNSPARSER_TYPE_A;
+
+ GNUNET_NAMESTORE_record_create (namestore_handle,
+ bob_key,
+ "www",
+ &rd,
+ NULL,
+ NULL);
+
+ /* Set up a task to end testing if peer start fails */
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+ "didn't start all daemons in reasonable
amount of time!!!");
+
+ alice_online = 0;
+ bob_online = 0;
+ expected_connections = 1;
+
+ /* Start alice */
+ d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
+ NULL, NULL, NULL, &alice_started, NULL);
+
+
//Start bob
d2 = GNUNET_TESTING_daemon_start(cfg2, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
NULL, NULL, NULL, &bob_started, NULL);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20172 - gnunet/src/gns,
gnunet <=