aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_block_gns.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-01 14:57:15 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-01 14:57:15 +0000
commit80270d3107822eebfdbdb3eaeb03be6f63d7c9da (patch)
tree7e225414dee5e3475452684b018a281ea59b2df9 /src/gns/plugin_block_gns.c
parent370ec6d2cd26fa31f134da67e2a6a9e0d8902d6f (diff)
downloadgnunet-80270d3107822eebfdbdb3eaeb03be6f63d7c9da.tar.gz
gnunet-80270d3107822eebfdbdb3eaeb03be6f63d7c9da.zip
-modified test
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r--src/gns/plugin_block_gns.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index e1677b35b..d1d8d4d6b 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -69,8 +69,9 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
69 GNUNET_HashCode mhash; 69 GNUNET_HashCode mhash;
70 GNUNET_HashCode chash; 70 GNUNET_HashCode chash;
71 struct GNSNameRecordBlock *nrb; 71 struct GNSNameRecordBlock *nrb;
72 struct GNSRecordBlock *rb;
73 uint32_t rd_count; 72 uint32_t rd_count;
73 char* rd_data = NULL;
74 int rd_len;
74 unsigned int record_match; 75 unsigned int record_match;
75 76
76 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) 77 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
@@ -94,53 +95,56 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
94 95
95 record_match = 0; 96 record_match = 0;
96 rd_count = ntohl(nrb->rd_count); 97 rd_count = ntohl(nrb->rd_count);
98 rd_data = (char*)&nrb[1];
99 rd_data += strlen(name) + 1;
100 rd_len = reply_block_size - (strlen(name) + 1
101 + sizeof(struct GNSNameRecordBlock));
97 { 102 {
98 struct GNUNET_NAMESTORE_RecordData rd[rd_count]; 103 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
99 unsigned int i; 104 unsigned int i;
100 uint32_t record_xquery = ntohl(*((uint32_t*)xquery)); 105 uint32_t record_xquery = ntohl(*((uint32_t*)xquery));
101 106
102 rb = (struct GNSRecordBlock*)(&name[strlen(name) + 1]); 107 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_len,
108 rd_data,
109 rd_count,
110 rd))
111 {
112 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
113 }
114
103 for (i=0; i<rd_count; i++) 115 for (i=0; i<rd_count; i++)
104 { 116 {
105 rd[i].record_type = ntohl(rb->type); 117 if (xquery_size < sizeof(uint32_t))
106 rd[i].expiration = 118 continue;
107 GNUNET_TIME_absolute_ntoh(rb->expiration);
108 rd[i].data_size = ntohl(rb->data_length);
109 rd[i].flags = ntohl(rb->flags);
110 rd[i].data = (char*)&rb[1];
111 rb = (struct GNSRecordBlock *)((char*)&rb[1] + rd[i].data_size);
112
113 if (xquery_size == 0)
114 continue;
115 119
116 if (rd[i].record_type == record_xquery) 120 if (rd[i].record_type == record_xquery)
117 record_match++; 121 record_match++;
118 } 122 }
119 }
120 123
121 /*if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, 124 if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key,
122 name, 125 name,
123 rd_count, 126 rd_count,
124 rd, 127 rd,
125 NULL)) 128 NULL))
126 { 129 {
127 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Signature invalid\n"); 130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n");
128 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 131 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
129 }*/ 132 }
133 }
130 134
131 //No record matches query 135 //No record matches query
132 if ((xquery_size > 0) && (record_match == 0)) 136 if ((xquery_size > 0) && (record_match == 0))
133 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 137 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
134 138
135 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Records match\n"); 139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Records match\n");
136 //FIXME do bf check before or after crypto?? 140
137 if (NULL != bf) 141 if (NULL != bf)
138 { 142 {
139 GNUNET_CRYPTO_hash(reply_block, reply_block_size, &chash); 143 GNUNET_CRYPTO_hash(reply_block, reply_block_size, &chash);
140 GNUNET_BLOCK_mingle_hash(&chash, bf_mutator, &mhash); 144 GNUNET_BLOCK_mingle_hash(&chash, bf_mutator, &mhash);
141 if (NULL != *bf) 145 if (NULL != *bf)
142 { 146 {
143 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Check BF\n"); 147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Check BF\n");
144 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(*bf, &mhash)) 148 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(*bf, &mhash))
145 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 149 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
146 } 150 }
@@ -150,7 +154,6 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
150 } 154 }
151 GNUNET_CONTAINER_bloomfilter_add(*bf, &mhash); 155 GNUNET_CONTAINER_bloomfilter_add(*bf, &mhash);
152 } 156 }
153 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "No dup\n");
154 return GNUNET_BLOCK_EVALUATION_OK_MORE; 157 return GNUNET_BLOCK_EVALUATION_OK_MORE;
155} 158}
156 159