[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34563 - in gnunet/src: fs include
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34563 - in gnunet/src: fs include |
Date: |
Sun, 14 Dec 2014 23:15:56 +0100 |
Author: grothoff
Date: 2014-12-14 23:15:55 +0100 (Sun, 14 Dec 2014)
New Revision: 34563
Removed:
gnunet/src/fs/test_fs_uri_data.conf
Modified:
gnunet/src/fs/Makefile.am
gnunet/src/fs/fs.h
gnunet/src/fs/fs_api.h
gnunet/src/fs/fs_publish.c
gnunet/src/fs/fs_uri.c
gnunet/src/fs/gnunet-service-fs.c
gnunet/src/fs/gnunet-service-fs_lc.c
gnunet/src/fs/test_fs_uri.c
gnunet/src/include/gnunet_fs_service.h
gnunet/src/include/gnunet_protocols.h
Log:
fix key management issue with LOC signing identified in #3559
Modified: gnunet/src/fs/Makefile.am
===================================================================
--- gnunet/src/fs/Makefile.am 2014-12-14 22:15:06 UTC (rev 34562)
+++ gnunet/src/fs/Makefile.am 2014-12-14 22:15:55 UTC (rev 34563)
@@ -380,7 +380,7 @@
test_fs_search_with_and_LDADD = \
$(top_builddir)/src/testing/libgnunettesting.la \
libgnunetfs.la \
- $(top_builddir)/src/util/libgnunetutil.la
+ $(top_builddir)/src/util/libgnunetutil.la
test_fs_search_probes_SOURCES = \
test_fs_search_probes.c
@@ -525,7 +525,6 @@
test_fs_publish_data.conf \
test_fs_search_data.conf \
test_fs_unindex_data.conf \
- test_fs_uri_data.conf \
test_gnunet_service_fs_migration_data.conf \
test_gnunet_service_fs_p2p_cadet.conf \
test_gnunet_fs_idx_data.conf \
Modified: gnunet/src/fs/fs.h
===================================================================
--- gnunet/src/fs/fs.h 2014-12-14 22:15:06 UTC (rev 34562)
+++ gnunet/src/fs/fs.h 2014-12-14 22:15:55 UTC (rev 34563)
@@ -66,7 +66,78 @@
GNUNET_NETWORK_STRUCT_BEGIN
+
/**
+ * Message sent from a GNUnet (fs) publishing activity to sign
+ * a LOC URI.
+ */
+struct RequestLocSignatureMessage
+{
+
+ /**
+ * Message type will be #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Requested signature purpose. For now, always
+ * #GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT.
+ */
+ uint32_t purpose GNUNET_PACKED;
+
+ /**
+ * Requested expiration time.
+ */
+ struct GNUNET_TIME_AbsoluteNBO expiration_time;
+
+ /**
+ * Information about the shared file (to be signed).
+ */
+ struct ContentHashKey chk;
+
+ /**
+ * Size of the shared file (to be signed).
+ */
+ uint64_t file_length;
+};
+
+
+/**
+ * Message sent from the service with the signed LOC URI.
+ */
+struct ResponseLocSignatureMessage
+{
+
+ /**
+ * Message type will be
+ * #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Purpose of the generated signature. For now, always
+ * #GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT.
+ */
+ uint32_t purpose GNUNET_PACKED;
+
+ /**
+ * Expiration time that was actually used (rounded!).
+ */
+ struct GNUNET_TIME_AbsoluteNBO expiration_time;
+
+ /**
+ * The requested signature.
+ */
+ struct GNUNET_CRYPTO_EddsaSignature signature;
+
+ /**
+ * Identity of the peer sharing the file.
+ */
+ struct GNUNET_PeerIdentity peer;
+};
+
+
+/**
* Message sent from a GNUnet (fs) publishing activity to the
* gnunet-fs-service to initiate indexing of a file. The service is
* supposed to check if the specified file is available and has the
Modified: gnunet/src/fs/fs_api.h
===================================================================
--- gnunet/src/fs/fs_api.h 2014-12-14 22:15:06 UTC (rev 34562)
+++ gnunet/src/fs/fs_api.h 2014-12-14 22:15:55 UTC (rev 34563)
@@ -416,15 +416,17 @@
* @param cls closure
* @param client handle to use for FS communication
*/
-typedef void (*GNUNET_FS_QueueStart) (void *cls,
- struct GNUNET_CLIENT_Connection *
client);
+typedef void
+(*GNUNET_FS_QueueStart) (void *cls,
+ struct GNUNET_CLIENT_Connection *client);
/**
* The job must now stop to run and should destry the client handle as
* soon as possible (ideally prior to returning).
*/
-typedef void (*GNUNET_FS_QueueStop) (void *cls);
+typedef void
+(*GNUNET_FS_QueueStop) (void *cls);
@@ -680,7 +682,7 @@
* that the caller might need to go backwards
* a bit at times
* @param max maximum number of bytes that should be
- * copied to buf; readers are not allowed
+ * copied to @a buf; readers are not allowed
* to provide less data unless there is an error;
* a value of "0" will be used at the end to allow
* the reader to clean up its internal state
@@ -689,12 +691,15 @@
* @return number of bytes written, usually "max", 0 on error
*/
size_t
-GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf,
+GNUNET_FS_data_reader_file_ (void *cls,
+ uint64_t offset,
+ size_t max,
+ void *buf,
char **emsg);
/**
- * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
+ * Create the closure for the #GNUNET_FS_data_reader_file_() callback.
*
* @param filename file to read
* @return closure to use
@@ -712,23 +717,26 @@
* that the caller might need to go backwards
* a bit at times
* @param max maximum number of bytes that should be
- * copied to buf; readers are not allowed
+ * copied to @a buf; readers are not allowed
* to provide less data unless there is an error;
* a value of "0" will be used at the end to allow
* the reader to clean up its internal state
* @param buf where the reader should write the data
* @param emsg location for the reader to store an error message
- * @return number of bytes written, usually "max", 0 on error
+ * @return number of bytes written, usually @a max, 0 on error
*/
size_t
-GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
+GNUNET_FS_data_reader_copy_ (void *cls,
+ uint64_t offset,
+ size_t max,
+ void *buf,
char **emsg);
/**
* Notification of FS that a search probe has made progress.
* This function is used INSTEAD of the client's event handler
- * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
+ * for downloads where the #GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
*
* @param cls closure, always NULL (!), actual closure
* is in the client-context of the info struct
@@ -738,7 +746,7 @@
* for this operation; should be set to NULL for
* SUSPEND and STOPPED events). The value returned
* will be passed to future callbacks in the respective
- * field in the GNUNET_FS_ProgressInfo struct.
+ * field in the `struct GNUNET_FS_ProgressInfo`.
*/
void *
GNUNET_FS_search_probe_progress_ (void *cls,
@@ -764,7 +772,8 @@
* @param file_id computed hash, NULL on error
*/
void
-GNUNET_FS_unindex_process_hash_ (void *cls, const struct GNUNET_HashCode *
file_id);
+GNUNET_FS_unindex_process_hash_ (void *cls,
+ const struct GNUNET_HashCode *file_id);
/**
@@ -890,6 +899,7 @@
void
GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
+
/**
* Remove serialization/deserialization file from disk.
*
@@ -898,7 +908,8 @@
* @param ent entity identifier
*/
void
-GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
+GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
+ const char *ext,
const char *ent);
@@ -991,7 +1002,7 @@
* Create SUSPEND event for the given publish operation
* and then clean up our state (without stop signal).
*
- * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
+ * @param cls the `struct GNUNET_FS_PublishContext` to signal for
*/
void
GNUNET_FS_publish_signal_suspend_ (void *cls);
@@ -1021,7 +1032,7 @@
* Create SUSPEND event for the given unindex operation
* and then clean up our state (without stop signal).
*
- * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
+ * @param cls the `struct GNUNET_FS_UnindexContext` to signal for
*/
void
GNUNET_FS_unindex_signal_suspend_ (void *cls);
@@ -1212,6 +1223,11 @@
struct GNUNET_FS_Handle *h;
/**
+ * Connection to FS service (only used for LOC URI signing).
+ */
+ struct GNUNET_CLIENT_Handle *fs_client;
+
+ /**
* Our top-level activity entry (if we are top-level, otherwise NULL).
*/
struct TopLevelActivity *top;
Modified: gnunet/src/fs/fs_publish.c
===================================================================
--- gnunet/src/fs/fs_publish.c 2014-12-14 22:15:06 UTC (rev 34562)
+++ gnunet/src/fs/fs_publish.c 2014-12-14 22:15:55 UTC (rev 34563)
@@ -823,6 +823,116 @@
/**
+ * We've computed the CHK/LOC URI, now publish the KSKs (if applicable).
+ *
+ * @param pc publishing context to do this for
+ */
+static void
+publish_kblocks (struct GNUNET_FS_PublishContext *pc)
+{
+ struct GNUNET_FS_FileInformation *p;
+
+ p = pc->fi_pos;
+ /* upload of "p" complete, publish KBlocks! */
+ if (NULL != p->keywords)
+ {
+ pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h,
+ p->keywords,
+ p->meta,
+ p->chk_uri,
+ &p->bo,
+ pc->options,
+ &publish_kblocks_cont, pc);
+ }
+ else
+ {
+ publish_kblocks_cont (pc, p->chk_uri, NULL);
+ }
+}
+
+
+/**
+ * Process the response (or lack thereof) from
+ * the "fs" service to our LOC sign request.
+ *
+ * @param cls closure (of type `struct GNUNET_FS_PublishContext *`)
+ * @param msg the response we got
+ */
+static void
+process_signature_response (void *cls,
+ const struct GNUNET_MessageHeader *msg)
+{
+ struct GNUNET_FS_PublishContext *pc = cls;
+ const struct ResponseLocSignatureMessage *sig;
+ struct GNUNET_FS_FileInformation *p;
+
+ p = pc->fi_pos;
+ if (NULL == msg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Can not create LOC URI. Will continue with CHK
instead.\n"));
+ publish_kblocks (pc);
+ return;
+ }
+ if (sizeof (struct ResponseLocSignatureMessage) !=
+ ntohs (msg->size))
+ {
+ GNUNET_break (0);
+ publish_kblocks (pc);
+ return;
+ }
+ sig = (const struct ResponseLocSignatureMessage *) msg;
+ p->chk_uri->type = GNUNET_FS_URI_LOC;
+ /* p->data.loc.fi kept from CHK before */
+ p->chk_uri->data.loc.peer = sig->peer;
+ p->chk_uri->data.loc.expirationTime = GNUNET_TIME_absolute_ntoh
(sig->expiration_time);
+ p->chk_uri->data.loc.contentSignature = sig->signature;
+ GNUNET_FS_file_information_sync_ (p);
+ GNUNET_FS_publish_sync_ (pc);
+ publish_kblocks (pc);
+}
+
+
+/**
+ * We're publishing without anonymity. Contact the FS service
+ * to create a signed LOC URI for further processing, then
+ * continue with KSKs.
+ *
+ * @param pc the publishing context do to this for
+ */
+static void
+create_loc_uri (struct GNUNET_FS_PublishContext *pc)
+{
+ struct RequestLocSignatureMessage req;
+ struct GNUNET_FS_FileInformation *p;
+
+ if (NULL == pc->client)
+ pc->client = GNUNET_CLIENT_connect ("fs", pc->h->cfg);
+ if (NULL == pc->client)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Can not create LOC URI. Will continue with CHK
instead.\n"));
+ publish_kblocks (pc);
+ return;
+ }
+ p = pc->fi_pos;
+ req.header.size = htons (sizeof (struct RequestLocSignatureMessage));
+ req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN);
+ req.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
+ req.expiration_time = GNUNET_TIME_absolute_hton (p->bo.expiration_time);
+ req.chk = p->chk_uri->data.chk.chk;
+ req.file_length = GNUNET_htonll (p->chk_uri->data.chk.file_length);
+ GNUNET_break (GNUNET_YES ==
+ GNUNET_CLIENT_transmit_and_get_response (pc->client,
+ &req.header,
+
GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+
&process_signature_response,
+ pc));
+}
+
+
+/**
* Main function that performs the upload.
*
* @param cls `struct GNUNET_FS_PublishContext *` identifies the upload
@@ -835,7 +945,6 @@
struct GNUNET_FS_PublishContext *pc = cls;
struct GNUNET_FS_ProgressInfo pi;
struct GNUNET_FS_FileInformation *p;
- struct GNUNET_FS_Uri *loc;
char *fn;
pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
@@ -875,13 +984,17 @@
p = p->dir;
if (fn != NULL)
{
- GNUNET_asprintf (&p->emsg, _("Recursive upload failed at `%s': %s"),
fn,
+ GNUNET_asprintf (&p->emsg,
+ _("Recursive upload failed at `%s': %s"),
+ fn,
p->emsg);
GNUNET_free (fn);
}
else
{
- GNUNET_asprintf (&p->emsg, _("Recursive upload failed: %s"), p->emsg);
+ GNUNET_asprintf (&p->emsg,
+ _("Recursive upload failed: %s"),
+ p->emsg);
}
pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -897,31 +1010,18 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"File upload complete, now publishing KSK blocks.\n");
- if (0 == p->bo.anonymity_level)
+ GNUNET_FS_publish_sync_ (pc);
+
+ if ( (0 == p->bo.anonymity_level) &&
+ (GNUNET_YES !=
+ GNUNET_FS_uri_test_loc (p->chk_uri)) )
{
/* zero anonymity, box CHK URI in LOC URI */
- loc = GNUNET_FS_uri_loc_create (p->chk_uri,
- pc->h->cfg,
- p->bo.expiration_time);
- GNUNET_FS_uri_destroy (p->chk_uri);
- p->chk_uri = loc;
- GNUNET_FS_file_information_sync_ (p);
+ create_loc_uri (pc);
}
- GNUNET_FS_publish_sync_ (pc);
- /* upload of "p" complete, publish KBlocks! */
- if (NULL != p->keywords)
- {
- pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h,
- p->keywords,
- p->meta,
- p->chk_uri,
- &p->bo,
- pc->options,
- &publish_kblocks_cont, pc);
- }
else
{
- publish_kblocks_cont (pc, p->chk_uri, NULL);
+ publish_kblocks (pc);
}
return;
}
@@ -1320,7 +1420,7 @@
pc->skip_next_fi_callback = GNUNET_YES;
GNUNET_FS_file_information_inspect (fi, &fip_signal_stop, pc);
}
- if (fi->serialization != NULL)
+ if (NULL != fi->serialization)
{
GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
fi->serialization);
Modified: gnunet/src/fs/fs_uri.c
===================================================================
--- gnunet/src/fs/fs_uri.c 2014-12-14 22:15:06 UTC (rev 34562)
+++ gnunet/src/fs/fs_uri.c 2014-12-14 22:15:55 UTC (rev 34563)
@@ -837,61 +837,46 @@
/**
* Construct a location URI (this peer will be used for the location).
+ * This function should only be called from within gnunet-service-fs,
+ * as it requires the peer's private key which is generally unavailable
+ * to processes directly under the user's control. However, for
+ * testing and as it logically fits under URIs, it is in this API.
*
- * @param baseUri content offered by the sender
- * @param cfg configuration information (used to find our hostkey)
+ * @param base_uri content offered by the sender
+ * @param sign_key private key of the peer
* @param expiration_time how long will the content be offered?
* @return the location URI, NULL on error
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
+GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
+ const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key,
struct GNUNET_TIME_Absolute expiration_time)
{
struct GNUNET_FS_Uri *uri;
- struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
struct GNUNET_CRYPTO_EddsaPublicKey my_public_key;
- char *keyfile;
struct LocUriAssembly ass;
struct GNUNET_TIME_Absolute et;
- if (baseUri->type != GNUNET_FS_URI_CHK)
+ if (GNUNET_FS_URI_CHK != base_uri->type)
return NULL;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "PEER", "PRIVATE_KEY",
- &keyfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Lacking key configuration settings.\n"));
- return NULL;
- }
- if (NULL ==
- (my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access hostkey file `%s'.\n"), keyfile);
- GNUNET_free (keyfile);
- return NULL;
- }
- GNUNET_free (keyfile);
/* we round expiration time to full seconds for SKS URIs */
et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL;
- GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_public_key);
+ GNUNET_CRYPTO_eddsa_key_get_public (sign_key,
+ &my_public_key);
ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
ass.exptime = GNUNET_TIME_absolute_hton (et);
- ass.fi = baseUri->data.chk;
+ ass.fi = base_uri->data.chk;
ass.peer.public_key = my_public_key;
uri = GNUNET_new (struct GNUNET_FS_Uri);
uri->type = GNUNET_FS_URI_LOC;
- uri->data.loc.fi = baseUri->data.chk;
+ uri->data.loc.fi = base_uri->data.chk;
uri->data.loc.expirationTime = et;
uri->data.loc.peer.public_key = my_public_key;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign (my_private_key, &ass.purpose,
+ GNUNET_CRYPTO_eddsa_sign (sign_key,
+ &ass.purpose,
&uri->data.loc.contentSignature));
- GNUNET_free (my_private_key);
return uri;
}
Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c 2014-12-14 22:15:06 UTC (rev 34562)
+++ gnunet/src/fs/gnunet-service-fs.c 2014-12-14 22:15:55 UTC (rev 34563)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+ (C) 2009-2014 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -45,6 +45,7 @@
#include "gnunet-service-fs_put.h"
#include "gnunet-service-fs_cadet.h"
#include "fs.h"
+#include "fs_api.h"
/**
* Size for the hash map for DHT requests from the FS
@@ -159,6 +160,11 @@
static struct GNUNET_CONFIGURATION_Handle *block_cfg;
/**
+ * Private key of this peer. Used to sign LOC URI requests.
+ */
+static struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+
+/**
* ID of our task that we use to age the cover counters.
*/
static GNUNET_SCHEDULER_TaskIdentifier cover_age_task;
@@ -173,6 +179,7 @@
*/
static struct GNUNET_PeerIdentity my_id;
+
/**
* Task that periodically ages our cover traffic statistics.
*
@@ -180,7 +187,8 @@
* @param tc task context
*/
static void
-age_cover_counters (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+age_cover_counters (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
@@ -288,11 +296,12 @@
* @param other the other peer involved (sender or receiver, NULL
* for loopback messages where we are both sender and receiver)
* @param message the actual message
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ * #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
+handle_p2p_put (void *cls,
+ const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message)
{
struct GSF_ConnectedPeer *cp;
@@ -349,7 +358,8 @@
* @param result final datastore lookup result
*/
static void
-consider_forwarding (void *cls, struct GSF_PendingRequest *pr,
+consider_forwarding (void *cls,
+ struct GSF_PendingRequest *pr,
enum GNUNET_BLOCK_EvaluationResult result)
{
if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
@@ -365,11 +375,12 @@
* @param other the other peer involved (sender or receiver, NULL
* for loopback messages where we are both sender and receiver)
* @param message the actual message
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ * #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
+handle_p2p_get (void *cls,
+ const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message)
{
struct GSF_PendingRequest *pr;
@@ -378,7 +389,8 @@
if (NULL == pr)
return GNUNET_SYSERR;
GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
- GSF_local_lookup_ (pr, &consider_forwarding, NULL);
+ GSF_local_lookup_ (pr,
+ &consider_forwarding, NULL);
return GNUNET_OK;
}
@@ -389,18 +401,20 @@
* result status). Also signal that we can now
* receive more request information from the client.
*
- * @param cls the client doing the request ('struct GNUNET_SERVER_Client')
+ * @param cls the client doing the request (`struct GNUNET_SERVER_Client`)
* @param pr the pending request we were processing
* @param result final datastore lookup result
*/
static void
-start_p2p_processing (void *cls, struct GSF_PendingRequest *pr,
+start_p2p_processing (void *cls,
+ struct GSF_PendingRequest *pr,
enum GNUNET_BLOCK_EvaluationResult result)
{
struct GNUNET_SERVER_Client *client = cls;
struct GSF_PendingRequestData *prd;
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
return; /* we're done, 'pr' was already destroyed... */
prd = GSF_pending_request_get_data_ (pr);
@@ -441,25 +455,32 @@
* @param message the actual message
*/
static void
-handle_start_search (void *cls, struct GNUNET_SERVER_Client *client,
+handle_start_search (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
struct GSF_PendingRequest *pr;
int ret;
pr = NULL;
- ret = GSF_local_client_start_search_handler_ (client, message, &pr);
+ ret = GSF_local_client_start_search_handler_ (client,
+ message,
+ &pr);
switch (ret)
{
case GNUNET_SYSERR:
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
break;
case GNUNET_NO:
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
break;
case GNUNET_YES:
GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
- GSF_local_lookup_ (pr, &start_p2p_processing, client);
+ GSF_local_lookup_ (pr,
+ &start_p2p_processing,
+ client);
break;
default:
GNUNET_assert (0);
@@ -468,13 +489,56 @@
/**
+ * Handle request to sign a LOC URI (from client).
+ *
+ * @param cls closure (NULL)
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_loc_sign (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ const struct RequestLocSignatureMessage *msg;
+ struct GNUNET_FS_Uri base;
+ struct GNUNET_FS_Uri *loc;
+ struct ResponseLocSignatureMessage resp;
+ struct GSF_LocalClient *lc;
+
+ msg = (const struct RequestLocSignatureMessage *) message;
+ GNUNET_break (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT ==
+ ntohl (msg->purpose));
+ base.type = GNUNET_FS_URI_CHK;
+ base.data.chk.chk = msg->chk;
+ base.data.chk.file_length = GNUNET_ntohll (msg->file_length);
+ loc = GNUNET_FS_uri_loc_create (&base,
+ pk,
+ GNUNET_TIME_absolute_ntoh
(msg->expiration_time));
+ resp.header.size = htons (sizeof (struct ResponseLocSignatureMessage));
+ resp.header.type = htons (GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE);
+ resp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
+ resp.expiration_time = GNUNET_TIME_absolute_hton
(loc->data.loc.expirationTime);
+ resp.signature = loc->data.loc.contentSignature;
+ resp.peer = loc->data.loc.peer;
+ GNUNET_FS_uri_destroy (loc);
+ lc = GSF_local_client_lookup_ (client);
+ GSF_local_client_transmit_ (lc,
+ &resp.header);
+ GNUNET_free (loc);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
+/**
* Task run during shutdown.
*
* @param cls unused
* @param tc unused
*/
static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GSF_cadet_stop_client ();
GSF_cadet_stop_server ();
@@ -524,10 +588,11 @@
* @param cls the 'struct GSF_ConnectedPeer' of the new peer
* @param key query for the request
* @param pr handle to the pending request
- * @return GNUNET_YES to continue to iterate
+ * @return #GNUNET_YES to continue to iterate
*/
static int
-consider_peer_for_forwarding (void *cls, const struct GNUNET_HashCode * key,
+consider_peer_for_forwarding (void *cls,
+ const struct GNUNET_HashCode *key,
struct GSF_PendingRequest *pr)
{
struct GSF_ConnectedPeer *cp = cls;
@@ -568,11 +633,15 @@
* @param peer peer identity this notification is about
*/
static void
-peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
+peer_connect_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
- if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
+ if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_id,
+ peer))
return;
- GSF_peer_connect_handler_ (peer, &connected_peer_cb, NULL);
+ GSF_peer_connect_handler_ (peer,
+ &connected_peer_cb,
+ NULL);
}
@@ -590,7 +659,13 @@
peer_init_handler (void *cls,
const struct GNUNET_PeerIdentity *my_identity)
{
- my_id = *my_identity;
+ if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_id,
+ my_identity))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Peer identity missmatch, refusing to start!\n");
+ GNUNET_SCHEDULER_shutdown ();
+ }
}
@@ -605,31 +680,36 @@
const struct GNUNET_CONFIGURATION_Handle *c)
{
static const struct GNUNET_CORE_MessageHandler no_p2p_handlers[] = {
- {NULL, 0, 0}
+ { NULL, 0, 0 }
};
static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
- {&handle_p2p_get,
- GNUNET_MESSAGE_TYPE_FS_GET, 0},
- {&handle_p2p_put,
- GNUNET_MESSAGE_TYPE_FS_PUT, 0},
- {&GSF_handle_p2p_migration_stop_,
- GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
- sizeof (struct MigrationStopMessage)},
- {NULL, 0, 0}
+ { &handle_p2p_get,
+ GNUNET_MESSAGE_TYPE_FS_GET, 0 },
+ { &handle_p2p_put,
+ GNUNET_MESSAGE_TYPE_FS_PUT, 0 },
+ { &GSF_handle_p2p_migration_stop_,
+ GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
+ sizeof (struct MigrationStopMessage) },
+ { NULL, 0, 0 }
};
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
- {&GNUNET_FS_handle_index_start, NULL,
- GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
- {&GNUNET_FS_handle_index_list_get, NULL,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
- sizeof (struct GNUNET_MessageHeader)},
- {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
- sizeof (struct UnindexMessage)},
- {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
- 0},
+ { &GNUNET_FS_handle_index_start, NULL,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0 },
+ { &GNUNET_FS_handle_index_list_get, NULL,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
+ sizeof (struct GNUNET_MessageHeader) },
+ { &GNUNET_FS_handle_unindex, NULL,
+ GNUNET_MESSAGE_TYPE_FS_UNINDEX,
+ sizeof (struct UnindexMessage) },
+ { &handle_start_search, NULL,
+ GNUNET_MESSAGE_TYPE_FS_START_SEARCH, 0 },
+ { &handle_loc_sign, NULL,
+ GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN,
+ sizeof (struct RequestLocSignatureMessage) },
{NULL, NULL, 0, 0}
};
int anon_p2p_off;
+ char *keyfile;
/* this option is really only for testcases that need to disable
_anonymous_ file-sharing for some reason */
@@ -637,10 +717,31 @@
GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
"fs",
"DISABLE_ANON_TRANSFER"));
- GSF_core =
- GNUNET_CORE_connect (GSF_cfg, NULL, &peer_init_handler,
- &peer_connect_handler,
&GSF_peer_disconnect_handler_,
- NULL, GNUNET_NO, NULL, GNUNET_NO,
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (GSF_cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &keyfile))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("FS service is lacking HOSTKEY configuration setting.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return GNUNET_SYSERR;
+ }
+ pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
+ GNUNET_free (keyfile);
+ GNUNET_assert (NULL != pk);
+ GNUNET_CRYPTO_eddsa_key_get_public (pk,
+ &my_id.public_key);
+
+ GSF_core
+ = GNUNET_CORE_connect (GSF_cfg, NULL,
+ &peer_init_handler,
+ &peer_connect_handler,
+ &GSF_peer_disconnect_handler_,
+ NULL, GNUNET_NO,
+ NULL, GNUNET_NO,
(GNUNET_YES == anon_p2p_off)
? no_p2p_handlers
: p2p_handlers);
Modified: gnunet/src/fs/gnunet-service-fs_lc.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_lc.c 2014-12-14 22:15:06 UTC (rev
34562)
+++ gnunet/src/fs/gnunet-service-fs_lc.c 2014-12-14 22:15:55 UTC (rev
34563)
@@ -17,13 +17,11 @@
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
-
/**
* @file fs/gnunet-service-fs_lc.c
* @brief API to handle 'local clients'
* @author Christian Grothoff
*/
-
#include "platform.h"
#include "gnunet-service-fs.h"
#include "gnunet-service-fs_lc.h"
@@ -150,7 +148,6 @@
*/
static struct GSF_LocalClient *client_head;
-
/**
* Head of linked list of our local clients.
*/
@@ -176,7 +173,9 @@
return pos;
pos = GNUNET_new (struct GSF_LocalClient);
pos->client = client;
- GNUNET_CONTAINER_DLL_insert (client_head, client_tail, pos);
+ GNUNET_CONTAINER_DLL_insert (client_head,
+ client_tail,
+ pos);
return pos;
}
@@ -209,7 +208,7 @@
* Handle a reply to a pending request. Also called if a request
* expires (then with data == NULL). The handler may be called
* many times (depending on the request type), but will not be
- * called during or after a call to GSF_pending_request_cancel
+ * called during or after a call to #GSF_pending_request_cancel()
* and will also not be called anymore after a call signalling
* expiration.
*
@@ -217,19 +216,21 @@
* @param eval evaluation of the result
* @param pr handle to the original pending request
* @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for
"unknown"
- * @param expiration when does 'data' expire?
+ * @param expiration when does @a data expire?
* @param last_transmission when was the last time we've tried to download
this block? (FOREVER if unknown)
* @param type type of the block
* @param data response data, NULL on request expiration
- * @param data_len number of bytes in @e data
+ * @param data_len number of bytes in @a data
*/
static void
-client_response_handler (void *cls, enum GNUNET_BLOCK_EvaluationResult eval,
+client_response_handler (void *cls,
+ enum GNUNET_BLOCK_EvaluationResult eval,
struct GSF_PendingRequest *pr,
uint32_t reply_anonymity_level,
struct GNUNET_TIME_Absolute expiration,
struct GNUNET_TIME_Absolute last_transmission,
- enum GNUNET_BLOCK_Type type, const void *data,
+ enum GNUNET_BLOCK_Type type,
+ const void *data,
size_t data_len)
{
struct ClientRequest *cr = cls;
@@ -405,13 +406,15 @@
* If we were able to transmit messages and there are still more
* pending, ask core again for further calls to this function.
*
- * @param cls closure, pointer to the 'struct GSF_LocalClient'
- * @param size number of bytes available in buf
+ * @param cls closure, pointer to the `struct GSF_LocalClient`
+ * @param size number of bytes available in @a buf
* @param buf where the callee should write the message
- * @return number of bytes written to buf
+ * @return number of bytes written to @a buf
*/
static size_t
-transmit_to_client (void *cls, size_t size, void *buf)
+transmit_to_client (void *cls,
+ size_t size,
+ void *buf)
{
struct GSF_LocalClient *lc = cls;
char *cbuf = buf;
@@ -458,8 +461,12 @@
res = GNUNET_malloc (sizeof (struct ClientResponse) + msize);
res->lc = lc;
res->msize = msize;
- memcpy (&res[1], msg, msize);
- GNUNET_CONTAINER_DLL_insert_tail (lc->res_head, lc->res_tail, res);
+ memcpy (&res[1],
+ msg,
+ msize);
+ GNUNET_CONTAINER_DLL_insert_tail (lc->res_head,
+ lc->res_tail,
+ res);
if (NULL == lc->th)
lc->th =
GNUNET_SERVER_notify_transmit_ready (lc->client, msize,
@@ -476,7 +483,8 @@
* @param client handle of the client
*/
void
-GSF_client_disconnect_handler_ (void *cls, struct GNUNET_SERVER_Client *client)
+GSF_client_disconnect_handler_ (void *cls,
+ struct GNUNET_SERVER_Client *client)
{
struct GSF_LocalClient *pos;
struct ClientRequest *cr;
Modified: gnunet/src/fs/test_fs_uri.c
===================================================================
--- gnunet/src/fs/test_fs_uri.c 2014-12-14 22:15:06 UTC (rev 34562)
+++ gnunet/src/fs/test_fs_uri.c 2014-12-14 22:15:55 UTC (rev 34563)
@@ -42,12 +42,12 @@
}
GNUNET_free (emsg);
ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg);
- if (ret == NULL)
+ if (NULL == ret)
{
GNUNET_free (emsg);
GNUNET_assert (0);
}
- if (!GNUNET_FS_uri_test_ksk (ret))
+ if (! GNUNET_FS_uri_test_ksk (ret))
{
GNUNET_FS_uri_destroy (ret);
GNUNET_assert (0);
@@ -81,7 +81,7 @@
struct GNUNET_FS_Uri *uri2;
struct GNUNET_FS_Uri *baseURI;
char *emsg;
- struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
baseURI =
GNUNET_FS_uri_parse
@@ -89,38 +89,31 @@
&emsg);
GNUNET_assert (baseURI != NULL);
GNUNET_assert (emsg == NULL);
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, "test_fs_uri_data.conf"))
+ pk = GNUNET_CRYPTO_eddsa_key_create ();
+ uri = GNUNET_FS_uri_loc_create (baseURI,
+ pk,
+ GNUNET_TIME_absolute_get ());
+ GNUNET_free (pk);
+ if (NULL == uri)
{
- FPRINTF (stderr, "%s", "Failed to parse configuration file\n");
- GNUNET_FS_uri_destroy (baseURI);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
- uri = GNUNET_FS_uri_loc_create (baseURI, cfg, GNUNET_TIME_absolute_get ());
- if (uri == NULL)
- {
GNUNET_break (0);
GNUNET_FS_uri_destroy (baseURI);
- GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
- if (!GNUNET_FS_uri_test_loc (uri))
+ if (! GNUNET_FS_uri_test_loc (uri))
{
GNUNET_break (0);
GNUNET_FS_uri_destroy (uri);
GNUNET_FS_uri_destroy (baseURI);
- GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
uri2 = GNUNET_FS_uri_loc_get_uri (uri);
- if (!GNUNET_FS_uri_test_equal (baseURI, uri2))
+ if (! GNUNET_FS_uri_test_equal (baseURI, uri2))
{
GNUNET_break (0);
GNUNET_FS_uri_destroy (uri);
GNUNET_FS_uri_destroy (uri2);
GNUNET_FS_uri_destroy (baseURI);
- GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
GNUNET_FS_uri_destroy (uri2);
@@ -137,7 +130,6 @@
fprintf (stderr, "URI parsing failed: %s\n", emsg);
GNUNET_break (0);
GNUNET_FS_uri_destroy (uri);
- GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (emsg);
return 1;
}
@@ -147,12 +139,10 @@
GNUNET_break (0);
GNUNET_FS_uri_destroy (uri);
GNUNET_FS_uri_destroy (uri2);
- GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
GNUNET_FS_uri_destroy (uri2);
GNUNET_FS_uri_destroy (uri);
- GNUNET_CONFIGURATION_destroy (cfg);
return 0;
}
Deleted: gnunet/src/fs/test_fs_uri_data.conf
===================================================================
--- gnunet/src/fs/test_fs_uri_data.conf 2014-12-14 22:15:06 UTC (rev 34562)
+++ gnunet/src/fs/test_fs_uri_data.conf 2014-12-14 22:15:55 UTC (rev 34563)
@@ -1,5 +0,0 @@
address@hidden@ test_fs_defaults.conf
-[PATHS]
-GNUNET_TEST_HOME = /tmp/gnunet-test-fs-uri/
-
-
Modified: gnunet/src/include/gnunet_fs_service.h
===================================================================
--- gnunet/src/include/gnunet_fs_service.h 2014-12-14 22:15:06 UTC (rev
34562)
+++ gnunet/src/include/gnunet_fs_service.h 2014-12-14 22:15:55 UTC (rev
34563)
@@ -162,7 +162,8 @@
* @return NULL on error
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_parse (const char *uri, char **emsg);
+GNUNET_FS_uri_parse (const char *uri,
+ char **emsg);
/**
@@ -233,15 +234,19 @@
/**
* Construct a location URI (this peer will be used for the location).
+ * This function should only be called from within gnunet-service-fs,
+ * as it requires the peer's private key which is generally unavailable
+ * to processes directly under the user's control. However, for
+ * testing and as it logically fits under URIs, it is in this API.
*
- * @param baseUri content offered by the sender
- * @param cfg configuration information (used to find our hostkey)
+ * @param base_uri content offered by the sender
+ * @param sign_key private key of the peer
* @param expiration_time how long will the content be offered?
* @return the location URI, NULL on error
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
+GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
+ const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key,
struct GNUNET_TIME_Absolute expiration_time);
@@ -285,7 +290,8 @@
* if keywords is not legal (i.e. empty).
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg);
+GNUNET_FS_uri_ksk_create (const char *keywords,
+ char **emsg);
/**
@@ -436,8 +442,9 @@
* @return #GNUNET_OK on success
*/
int
-GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
- *ctx, void *scls, const char *option,
+GNUNET_FS_getopt_set_keywords (struct
GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+ void *scls,
+ const char *option,
const char *value);
@@ -454,8 +461,9 @@
* @return #GNUNET_OK on success
*/
int
-GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
- *ctx, void *scls, const char *option,
+GNUNET_FS_getopt_set_metadata (struct
GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+ void *scls,
+ const char *option,
const char *value);
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2014-12-14 22:15:06 UTC (rev
34562)
+++ gnunet/src/include/gnunet_protocols.h 2014-12-14 22:15:55 UTC (rev
34563)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001-2013 Christian Grothoff (and other contributing authors)
+ (C) 2001-2014 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -459,6 +459,16 @@
******************************************************************************/
/**
+ * Message sent by fs client to request LOC signature.
+ */
+#define GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN 126
+
+/**
+ * Reply sent by fs service with LOC signature.
+ */
+#define GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE 127
+
+/**
* Message sent by fs client to start indexing.
*/
#define GNUNET_MESSAGE_TYPE_FS_INDEX_START 128
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34563 - in gnunet/src: fs include,
gnunet <=