aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_namespace.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-05 13:07:27 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-05 13:07:27 +0000
commitacd08b65a860450488d5e6b5403e43bed3748dc9 (patch)
tree20fc809a1d307b07993c4b2d80f14594e53938e1 /src/fs/fs_namespace.c
parent4a8a0bbb94a087d697092bad031261c0ee51a8cc (diff)
downloadgnunet-acd08b65a860450488d5e6b5403e43bed3748dc9.tar.gz
gnunet-acd08b65a860450488d5e6b5403e43bed3748dc9.zip
nblock support done
Diffstat (limited to 'src/fs/fs_namespace.c')
-rw-r--r--src/fs/fs_namespace.c179
1 files changed, 138 insertions, 41 deletions
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c
index 873494c4f..96e1f4f3f 100644
--- a/src/fs/fs_namespace.c
+++ b/src/fs/fs_namespace.c
@@ -79,9 +79,49 @@ struct AdvertisementContext
79 struct GNUNET_DATASTORE_Handle *dsh; 79 struct GNUNET_DATASTORE_Handle *dsh;
80 80
81 /** 81 /**
82 * URI that was created. 82 * Our KSK URI.
83 */ 83 */
84 struct GNUNET_FS_Uri *uri; 84 struct GNUNET_FS_Uri *ksk_uri;
85
86 /**
87 * Plaintext.
88 */
89 char *pt;
90
91 /**
92 * NBlock to sign and store.
93 */
94 struct NBlock *nb;
95
96 /**
97 * The namespace.
98 */
99 struct GNUNET_FS_Namespace *ns;
100
101 /**
102 * Expiration time.
103 */
104 struct GNUNET_TIME_Absolute expiration;
105
106 /**
107 * Number of bytes of plaintext.
108 */
109 size_t pt_size;
110
111 /**
112 * Anonymity level.
113 */
114 uint32_t anonymity;
115
116 /**
117 * Content priority.
118 */
119 uint32_t priority;
120
121 /**
122 * Current keyword offset.
123 */
124 unsigned int pos;
85}; 125};
86 126
87 127
@@ -99,14 +139,74 @@ advertisement_cont (void *cls,
99 const char *msg) 139 const char *msg)
100{ 140{
101 struct AdvertisementContext *ac = cls; 141 struct AdvertisementContext *ac = cls;
142 const char *keyword;
143 GNUNET_HashCode key;
144 GNUNET_HashCode query;
145 struct GNUNET_CRYPTO_AesSessionKey skey;
146 struct GNUNET_CRYPTO_AesInitializationVector iv;
147 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
102 148
103 if (GNUNET_OK != success) 149 if (GNUNET_OK != success)
104 ac->cont (ac->cont_cls, NULL, msg); 150 {
105 else 151 /* error! */
106 ac->cont (ac->cont_cls, ac->uri, NULL); 152 GNUNET_DATASTORE_disconnect (ac->dsh, GNUNET_NO);
107 GNUNET_DATASTORE_disconnect (ac->dsh, GNUNET_NO); 153 ac->cont (ac->cont_cls, NULL, msg);
108 GNUNET_FS_uri_destroy (ac->uri); 154 GNUNET_FS_uri_destroy (ac->ksk_uri);
109 GNUNET_free (ac); 155 GNUNET_free (ac->pt);
156 GNUNET_free (ac->nb);
157 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
158 GNUNET_free (ac);
159 return;
160 }
161 if (ac->pos == ac->ksk_uri->data.ksk.keywordCount)
162 {
163 /* done! */
164 GNUNET_DATASTORE_disconnect (ac->dsh, GNUNET_NO);
165 ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
166 GNUNET_FS_uri_destroy (ac->ksk_uri);
167 GNUNET_free (ac->pt);
168 GNUNET_free (ac->nb);
169 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
170 GNUNET_free (ac);
171 return;
172 }
173
174 keyword = ac->ksk_uri->data.ksk.keywords[ac->pos++];
175 /* first character of keyword indicates if it is
176 mandatory or not -- ignore for hashing */
177 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
178 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
179 GNUNET_CRYPTO_aes_encrypt (ac->pt,
180 ac->pt_size,
181 &skey,
182 &iv,
183 &ac->nb[1]);
184 GNUNET_break (GNUNET_OK ==
185 GNUNET_CRYPTO_rsa_sign (ac->ns->key,
186 &ac->nb->ns_purpose,
187 &ac->nb->ns_signature));
188 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
189 GNUNET_CRYPTO_rsa_key_get_public (pk, &ac->nb->keyspace);
190 GNUNET_CRYPTO_hash (&ac->nb->keyspace,
191 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
192 &query);
193 GNUNET_break (GNUNET_OK ==
194 GNUNET_CRYPTO_rsa_sign (pk,
195 &ac->nb->ksk_purpose,
196 &ac->nb->ksk_signature));
197 GNUNET_CRYPTO_rsa_key_free (pk);
198 GNUNET_DATASTORE_put (ac->dsh,
199 0 /* no reservation */,
200 &query,
201 ac->pt_size + sizeof (struct NBlock),
202 ac->nb,
203 GNUNET_DATASTORE_BLOCKTYPE_NBLOCK,
204 ac->priority,
205 ac->anonymity,
206 ac->expiration,
207 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
208 &advertisement_cont,
209 ac);
110} 210}
111 211
112 212
@@ -114,6 +214,7 @@ advertisement_cont (void *cls,
114 * Publish an advertismement for a namespace. 214 * Publish an advertismement for a namespace.
115 * 215 *
116 * @param h handle to the file sharing subsystem 216 * @param h handle to the file sharing subsystem
217 * @param ksk_uri keywords to use for advertisment
117 * @param namespace handle for the namespace that should be advertised 218 * @param namespace handle for the namespace that should be advertised
118 * @param meta meta-data for the namespace advertisement 219 * @param meta meta-data for the namespace advertisement
119 * @param anonymity for the namespace advertismement 220 * @param anonymity for the namespace advertismement
@@ -125,6 +226,7 @@ advertisement_cont (void *cls,
125 */ 226 */
126void 227void
127GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h, 228GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
229 struct GNUNET_FS_Uri *ksk_uri,
128 struct GNUNET_FS_Namespace *namespace, 230 struct GNUNET_FS_Namespace *namespace,
129 const struct GNUNET_CONTAINER_MetaData *meta, 231 const struct GNUNET_CONTAINER_MetaData *meta,
130 uint32_t anonymity, 232 uint32_t anonymity,
@@ -138,10 +240,10 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
138 size_t size; 240 size_t size;
139 ssize_t mdsize; 241 ssize_t mdsize;
140 struct NBlock *nb; 242 struct NBlock *nb;
141 char *rtgt;
142 char *mdst; 243 char *mdst;
143 struct GNUNET_DATASTORE_Handle *dsh; 244 struct GNUNET_DATASTORE_Handle *dsh;
144 struct AdvertisementContext *ctx; 245 struct AdvertisementContext *ctx;
246 char *pt;
145 247
146 /* create advertisements */ 248 /* create advertisements */
147 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); 249 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
@@ -157,11 +259,10 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
157 size = MAX_NBLOCK_SIZE; 259 size = MAX_NBLOCK_SIZE;
158 mdsize = size - sizeof (struct NBlock) - reslen; 260 mdsize = size - sizeof (struct NBlock) - reslen;
159 } 261 }
160 nb = GNUNET_malloc (size); 262
161 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &nb->subspace); 263 pt = GNUNET_malloc (mdsize + reslen);
162 rtgt = (char *) &nb[1]; 264 memcpy (pt, rootEntry, reslen);
163 memcpy (rtgt, rootEntry, reslen); 265 mdst = &pt[reslen];
164 mdst = &rtgt[reslen];
165 mdsize = GNUNET_CONTAINER_meta_data_serialize (meta, 266 mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
166 &mdst, 267 &mdst,
167 mdsize, 268 mdsize,
@@ -169,46 +270,42 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
169 if (mdsize == -1) 270 if (mdsize == -1)
170 { 271 {
171 GNUNET_break (0); 272 GNUNET_break (0);
172 GNUNET_free (nb); 273 GNUNET_free (pt);
173 cont (cont_cls, NULL, _("Failed to serialize meta data")); 274 cont (cont_cls, NULL, _("Failed to serialize meta data"));
174 return; 275 return;
175 } 276 }
176 size = mdsize + sizeof (struct NBlock) + reslen; 277 size = mdsize + sizeof (struct NBlock) + reslen;
177 nb->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature)); 278 nb = GNUNET_malloc (size);
178 nb->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK); 279 GNUNET_CRYPTO_rsa_key_get_public (namespace->key,
179 GNUNET_break (GNUNET_OK == 280 &nb->subspace);
180 GNUNET_CRYPTO_rsa_sign (namespace->key, 281 nb->ns_purpose.size = htonl (mdsize + reslen +
181 &nb->purpose, 282 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
182 &nb->signature)); 283 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
284 nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK);
285 nb->ksk_purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
286 nb->ksk_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG);
183 dsh = GNUNET_DATASTORE_connect (h->cfg, h->sched); 287 dsh = GNUNET_DATASTORE_connect (h->cfg, h->sched);
184 if (NULL == dsh) 288 if (NULL == dsh)
185 { 289 {
186 GNUNET_free (nb); 290 GNUNET_free (nb);
291 GNUNET_free (pt);
187 cont (cont_cls, NULL, _("Failed to connect to datastore service")); 292 cont (cont_cls, NULL, _("Failed to connect to datastore service"));
188 return; 293 return;
189 } 294 }
190 ctx = GNUNET_malloc (sizeof (struct AdvertisementContext)); 295 ctx = GNUNET_malloc (sizeof (struct AdvertisementContext));
191 ctx->cont = cont; 296 ctx->cont = cont;
192 ctx->cont_cls = cont_cls; 297 ctx->cont_cls = cont_cls;
193 ctx->dsh = dsh; 298 ctx->dsh = dsh;
194 ctx->uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 299 ctx->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
195 ctx->uri->type = sks; 300 ctx->nb = nb;
196 ctx->uri->data.sks.identifier = GNUNET_strdup (""); 301 ctx->pt = pt;
197 GNUNET_CRYPTO_hash (&nb->subspace, 302 ctx->pt_size = mdsize + reslen;
198 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 303 ctx->ns = namespace;
199 &ctx->uri->data.sks.namespace); 304 ctx->ns->rc++;
200 GNUNET_DATASTORE_put (dsh, 305 ctx->anonymity = anonymity;
201 0, 306 ctx->priority = priority;
202 &ctx->uri->data.sks.namespace, 307 ctx->expiration = expiration;
203 size, 308 advertisement_cont (ctx, GNUNET_OK, NULL);
204 nb,
205 GNUNET_DATASTORE_BLOCKTYPE_NBLOCK,
206 priority,
207 anonymity,
208 expiration,
209 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
210 &advertisement_cont,
211 ctx);
212} 309}
213 310
214 311