[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29750 - gnunet/src/experimentation
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29750 - gnunet/src/experimentation |
Date: |
Tue, 1 Oct 2013 11:25:06 +0200 |
Author: grothoff
Date: 2013-10-01 11:25:06 +0200 (Tue, 01 Oct 2013)
New Revision: 29750
Modified:
gnunet/src/experimentation/gnunet-daemon-experimentation.h
gnunet/src/experimentation/gnunet-daemon-experimentation_experiments.c
gnunet/src/experimentation/gnunet-daemon-experimentation_nodes.c
Log:
-messing up experimentation some more, towards using egos instead of peer
identities
Modified: gnunet/src/experimentation/gnunet-daemon-experimentation.h
===================================================================
--- gnunet/src/experimentation/gnunet-daemon-experimentation.h 2013-10-01
08:29:32 UTC (rev 29749)
+++ gnunet/src/experimentation/gnunet-daemon-experimentation.h 2013-10-01
09:25:06 UTC (rev 29750)
@@ -51,39 +51,33 @@
*/
extern struct GNUNET_STATISTICS_Handle *GED_stats;
-
/**
* Configuration handle shared between components
*/
extern struct GNUNET_CONFIGURATION_Handle *GED_cfg;
-
/**
* Capability value shared between components
*/
extern uint32_t GSE_node_capabilities;
-extern uint32_t GSE_my_issuer_count;
-
-extern struct Experimentation_Issuer *GSE_my_issuer;
-
/**
* Capabilities a node has or an experiment requires
*/
enum GNUNET_EXPERIMENTATION_capabilities
{
- NONE = 0,
- PLUGIN_TCP = 1,
- PLUGIN_UDP = 2,
- PLUGIN_UNIX = 4,
- PLUGIN_HTTP_CLIENT = 8,
- PLUGIN_HTTP_SERVER = 16,
- PLUGIN_HTTPS_CLIENT = 32,
- PLUGIN_HTTPS_SERVER = 64,
- PLUGIN_WLAN = 128,
- HAVE_IPV6 = 256,
- BEHIND_NAT = 512
+ NONE = 0,
+ PLUGIN_TCP = 1,
+ PLUGIN_UDP = 2,
+ PLUGIN_UNIX = 4,
+ PLUGIN_HTTP_CLIENT = 8,
+ PLUGIN_HTTP_SERVER = 16,
+ PLUGIN_HTTPS_CLIENT = 32,
+ PLUGIN_HTTPS_SERVER = 64,
+ PLUGIN_WLAN = 128,
+ HAVE_IPV6 = 256,
+ BEHIND_NAT = 512
};
@@ -92,42 +86,58 @@
*/
struct Experiment
{
- /* Header */
- /* ----------------- */
- char *name;
-
- /* Experiment issuer */
- struct GNUNET_PeerIdentity issuer;
-
- /* Experiment version as timestamp of creation */
- struct GNUNET_TIME_Absolute version;
-
- /* Description */
- char *description;
-
- /* Required capabilities */
- uint32_t required_capabilities;
-
- /* Experiment timing */
- /* ----------------- */
-
- /* When to start experiment */
- struct GNUNET_TIME_Absolute start;
-
- /* When to end experiment */
- struct GNUNET_TIME_Absolute stop;
-
- /* How often to run experiment */
- struct GNUNET_TIME_Relative frequency;
-
- /* How long to run each execution */
- struct GNUNET_TIME_Relative duration;
-
-
- /* Experiment itself */
- /* ----------------- */
-
- /* TBD */
+ /* Header */
+ /* ----------------- */
+ char *name;
+
+ /**
+ * Experiment issuer
+ */
+ struct GNUNET_CRYPTO_EccPublicSignKey issuer;
+
+ /**
+ * Experiment version as timestamp of creation
+ */
+ struct GNUNET_TIME_Absolute version;
+
+ /**
+ * Description
+ */
+ char *description;
+
+ /**
+ * Required capabilities
+ */
+ uint32_t required_capabilities;
+
+ /* Experiment timing */
+ /* ----------------- */
+
+ /**
+ * When to start experiment
+ */
+ struct GNUNET_TIME_Absolute start;
+
+ /**
+ * When to end experiment
+ */
+ struct GNUNET_TIME_Absolute stop;
+
+ /**
+ * How often to run experiment
+ */
+ struct GNUNET_TIME_Relative frequency;
+
+ /**
+ * How long to run each execution
+ */
+ struct GNUNET_TIME_Relative duration;
+
+
+ /* Experiment itself */
+ /* ----------------- */
+
+ /* TBD */
};
@@ -136,44 +146,36 @@
*/
struct Node
{
- /**
- * Peer id
- */
- struct GNUNET_PeerIdentity id;
+ /**
+ * Peer id
+ */
+ struct GNUNET_PeerIdentity id;
+
+ /**
+ * Task for response timeout
+ */
+ GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+
+ /**
+ * Core transmission handle
+ */
+ struct GNUNET_CORE_TransmitHandle *cth;
+
+ /**
+ * Node capabilities
+ */
+ uint32_t capabilities;
+
+ /**
+ * Experiment version as timestamp of creation
+ */
+ struct GNUNET_TIME_Absolute version;
+
+ struct NodeComCtx *e_req_head;
- /**
- * Task for response timeout
- */
- GNUNET_SCHEDULER_TaskIdentifier timeout_task;
-
- /**
- * Core transmission handle
- */
- struct GNUNET_CORE_TransmitHandle *cth;
-
- /**
- * Node capabilities
- */
- uint32_t capabilities;
-
- /* Experiment version as timestamp of creation */
- struct GNUNET_TIME_Absolute version;
-
- uint32_t issuer_count;
-
- /**
- * Array of fssuer ids
- */
- struct GNUNET_PeerIdentity *issuer_id;
-
- struct NodeComCtx *e_req_head;
- struct NodeComCtx *e_req_tail;
+ struct NodeComCtx *e_req_tail;
};
-struct Experimentation_Issuer
-{
- struct GNUNET_PeerIdentity issuer_id;
-};
GNUNET_NETWORK_STRUCT_BEGIN
@@ -182,86 +184,117 @@
* Used to detect experimentation capability
*
* This struct is followed by issuer identities:
- * (issuer_count * struct Experimentation_Request_Issuer)
+ * (issuer_count * struct GNUNET_CRYPTO_EccPublicSignKey)
*
*/
struct Experimentation_Request
{
- struct GNUNET_MessageHeader msg;
+ struct GNUNET_MessageHeader msg;
+
+ uint32_t capabilities GNUNET_PACKED;
+
+ uint32_t issuer_count GNUNET_PACKED;
+};
- uint32_t capabilities;
- uint32_t issuer_count;
-};
-
/**
* Experimentation response message
* Sent if peer is running the daemon
*
* This struct is followed by issuer identities:
- * (issuer_count * struct Experimentation_Request_Issuer)
+ * (issuer_count * struct GNUNET_CRYPTO_EccPublicSignKey)
*/
struct Experimentation_Response
{
- struct GNUNET_MessageHeader msg;
+ struct GNUNET_MessageHeader msg;
+
+ uint32_t capabilities GNUNET_PACKED;
+
+ uint32_t issuer_count GNUNET_PACKED;
+};
- uint32_t capabilities;
- uint32_t issuer_count;
+/**
+ * Struct to store information about an experiment issuer
+ */
+struct Issuer
+{
+ struct GNUNET_CRYPTO_EccPublicSignKey pubkey;
};
/**
+ * Hashmap containing valid experiment issuers
+ * (the key is the hash of the respective public key,
+ * the values are of type `struct Issuer').
+ */
+struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
+
+/**
* Experiment start message
*
* struct is followed by string with length len_name
*/
struct GED_start_message
{
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * String length of experiment name following the struct
+ */
+ uint32_t len_name GNUNET_PACKED;
+
+ /**
+ * Experiment issuer
+ */
+ struct GNUNET_CRYPTO_EccPublicSignKey issuer;
+
+ /**
+ * Experiment version as timestamp of creation
+ */
+ struct GNUNET_TIME_AbsoluteNBO version_nbo;
+};
- /**
- * String length of experiment name following the struct
- */
- uint32_t len_name;
- /* Experiment issuer */
- struct GNUNET_PeerIdentity issuer;
-
- /* Experiment version as timestamp of creation */
- struct GNUNET_TIME_AbsoluteNBO version_nbo;
-};
-
struct GED_start_ack_message
{
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * String length of experiment name following the struct
+ */
+ uint32_t len_name GNUNET_PACKED;
+
+ /**
+ * Experiment issuer
+ */
+ struct GNUNET_CRYPTO_EccPublicSignKey issuer;
- /**
- * String length of experiment name following the struct
- */
- uint32_t len_name;
+ /**
+ * Experiment version as timestamp of creation
+ */
+ struct GNUNET_TIME_AbsoluteNBO version_nbo;
+};
- /* Experiment issuer */
- struct GNUNET_PeerIdentity issuer;
- /* Experiment version as timestamp of creation */
- struct GNUNET_TIME_AbsoluteNBO version_nbo;
-};
-
struct GED_stop_message
{
- struct GNUNET_MessageHeader header;
-
- /**
- * String length of experiment name following the struct
- */
- uint32_t len_name;
-
- /* Experiment issuer */
- struct GNUNET_PeerIdentity issuer;
-
- /* Experiment version as timestamp of creation */
- struct GNUNET_TIME_AbsoluteNBO version_nbo;
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * String length of experiment name following the struct
+ */
+ uint32_t len_name GNUNET_PACKED;
+
+ /**
+ * Experiment issuer
+ */
+ struct GNUNET_CRYPTO_EccPublicSignKey issuer;
+
+ /**
+ * Experiment version as timestamp of creation
+ */
+ struct GNUNET_TIME_AbsoluteNBO version_nbo;
};
GNUNET_NETWORK_STRUCT_END
@@ -270,13 +303,15 @@
int
GED_nodes_rts (struct Node *n);
+
int
GED_nodes_send_start (struct Node *n, struct Experiment *e);
+
/**
* Confirm a experiment START with a node
*
- * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
+ * @return #GNUNET_NO if core was busy with sending, #GNUNET_OK otherwise
*/
int
GED_nodes_send_start_ack (struct Node *n, struct Experiment *e);
@@ -285,14 +320,14 @@
* Start the nodes management
*/
void
-GED_nodes_start ();
+GED_nodes_start (void);
/**
* Stop the nodes management
*/
void
-GED_nodes_stop ();
+GED_nodes_stop (void);
/**
@@ -310,7 +345,7 @@
*
* @param have bitstring containing the provided capabilities
* @param desired bitstring containing the desired capabilities\
- * @return GNUNET_YES or GNUNET_NO
+ * @return #GNUNET_YES or #GNUNET_NO
*/
int
GED_capabilities_have (uint32_t have, uint32_t desired);
@@ -320,23 +355,23 @@
* Start the detecting capabilities
*/
void
-GED_capabilities_start ();
+GED_capabilities_start (void);
/**
* Stop the detecting capabilities
*/
void
-GED_capabilities_stop ();
+GED_capabilities_stop (void);
/**
* Start experiments management
*
- * @return GNUNET_YES or GNUNET_NO
+ * @return #GNUNET_YES or #GNUNET_NO
*/
int
-GED_experiments_issuer_accepted (struct GNUNET_PeerIdentity *issuer_ID);
+GED_experiments_issuer_accepted (const struct GNUNET_CRYPTO_EccPublicSignKey
*issuer_ID);
/*
@@ -348,34 +383,37 @@
* @return the experiment or NULL if not found
*/
struct Experiment *
-GED_experiments_find (const struct GNUNET_PeerIdentity *issuer,
-
const char *name,
-
const struct GNUNET_TIME_Absolute version);
+GED_experiments_find (const struct GNUNET_CRYPTO_EccPublicSignKey *issuer,
+ const char *name,
+ const struct GNUNET_TIME_Absolute version);
-typedef void (*GNUNET_EXPERIMENTATION_experiments_get_cb) (struct Node *n,
struct Experiment *e);
+typedef void (*GNUNET_EXPERIMENTATION_experiments_get_cb) (struct Node *n,
+ struct Experiment
*e);
void
GED_experiments_get (struct Node *n,
-
struct GNUNET_PeerIdentity *issuer,
-
GNUNET_EXPERIMENTATION_experiments_get_cb get_cb);
+ struct GNUNET_CRYPTO_EccPublicSignKey *issuer,
+ GNUNET_EXPERIMENTATION_experiments_get_cb get_cb);
+
/**
* Start experiments management
*
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GED_experiments_start ();
+GED_experiments_start (void);
/**
* Stop experiments management
*/
void
-GED_experiments_stop ();
+GED_experiments_stop (void);
+
/**
* Handle a START message from a remote node
*
@@ -395,6 +433,7 @@
void
GED_scheduler_handle_start_ack (struct Node *n, struct Experiment *e);
+
/**
* Handle a STOP message from a remote node
*
@@ -410,38 +449,40 @@
*
* @param n the node
* @param e the experiment
- * @param outbound are we initiator (GNUNET_YES) or client (GNUNET_NO)?
+ * @param outbound are we initiator (#GNUNET_YES) or client (#GNUNET_NO)?
*/
void
-GED_scheduler_add (struct Node *n, struct Experiment *e, int outbound);
+GED_scheduler_add (struct Node *n,
+ struct Experiment *e,
+ int outbound);
+
/**
* Start the scheduler component
*/
void
-GED_scheduler_start ();
+GED_scheduler_start (void);
/**
* Stop the scheduler component
*/
void
-GED_scheduler_stop ();
+GED_scheduler_stop (void);
/**
* Start the storage component
*/
void
-GED_storage_start ();
+GED_storage_start (void);
-
/**
* Stop the storage component
*/
void
-GED_storage_stop ();
+GED_storage_stop (void);
/* end of gnunet-daemon-experimentation.h */
Modified: gnunet/src/experimentation/gnunet-daemon-experimentation_experiments.c
===================================================================
--- gnunet/src/experimentation/gnunet-daemon-experimentation_experiments.c
2013-10-01 08:29:32 UTC (rev 29749)
+++ gnunet/src/experimentation/gnunet-daemon-experimentation_experiments.c
2013-10-01 09:25:06 UTC (rev 29750)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2009 Christian Grothoff (and other contributing authors)
+ (C) 2012,2013 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
@@ -32,41 +32,22 @@
/**
- * Struct to store information about an experiment issuer
+ * Hashmap containing valid experiment issuers.
*/
-struct Issuer
-{
- struct GNUNET_CRYPTO_EccPublicSignKey pubkey;
-};
+struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
-
/**
- * Hashmap containing valid experiment issuer
- */
-static struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
-
-/**
* Hashmap containing valid experiments
*/
static struct GNUNET_CONTAINER_MultiHashMap *experiments;
-static uint32_t GSE_my_issuer_count;
-
/**
- * Valid experiment issuer for this daemon
- *
- * Array Experimentation_Issuer with GSE_my_issuer_count elements
- */
-static struct Experimentation_Issuer *GSE_my_issuer;
-
-
-/**
* Verify experiment signature
*
* @param i issuer
* @param e experiment
- * @return GNUNET_OK or GNUNET_SYSERR
+ * @return #GNUNET_OK or #GNUNET_SYSERR
*/
static int
experiment_verify (struct Issuer *i, struct Experiment *e)
@@ -110,70 +91,51 @@
{
struct Issuer *i = value;
- GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (valid_issuers, key,
value));
+ GNUNET_break (0 == GNUNET_CONTAINER_multihashmap_remove (valid_issuers,
+ key,
+ i));
GNUNET_free (i);
return GNUNET_OK;
}
-static int
-create_issuer (void *cls,
- const struct GNUNET_HashCode * key,
- void *value)
-{
- static int i = 0;
-
- GNUNET_assert (i < GSE_my_issuer_count);
- GSE_my_issuer[i].issuer_id.hashPubKey = *key;
-
- i++;
- return GNUNET_OK;
-}
-
-
-
/**
* Is peer a valid issuer
*
- * @return GNUNET_YES or GNUNET_NO
+ * @return #GNUNET_YES or #GNUNET_NO
*/
int
-GED_experiments_issuer_accepted (struct GNUNET_PeerIdentity *issuer_ID)
+GED_experiments_issuer_accepted (struct GNUNET_PeerIdentity *issuer_id)
{
- if (GNUNET_CONTAINER_multihashmap_contains (valid_issuers,
&issuer_ID->hashPubKey))
+ struct GNUNET_HashCode hash;
+
+ GNUNET_CRYPTO_hash (issuer_id, sizeof (struct GNUNET_PeerIdentity), &hash);
+ if (GNUNET_CONTAINER_multihashmap_contains (valid_issuers, &hash))
return GNUNET_YES;
- else
- return GNUNET_NO;
+ return GNUNET_NO;
}
-struct FindCtx
+/**
+ * Get the key under which the given experiment is stored in the
+ * experiment map.
+ */
+static void
+get_experment_key (const struct GNUNET_PeerIdentity *issuer,
+ const char *name,
+ const struct GNUNET_TIME_Absolute version,
+ struct GNUNET_HashCode *key)
{
- const char *name;
- struct GNUNET_TIME_Absolute version;
- struct Experiment *res;
-};
-
-
-static int
-find_it (void *cls,
- const struct GNUNET_HashCode * key,
- void *value)
-{
- struct FindCtx *find_ctx = cls;
- struct Experiment *e = (struct Experiment *) value;
-
- if (0 != strcmp(e->name, find_ctx->name))
- return GNUNET_OK;
- if (e->version.abs_value_us != find_ctx->version.abs_value_us)
- return GNUNET_OK;
-
- find_ctx->res = e;
- return GNUNET_NO;
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CRYPTO_kdf (key, sizeof (struct GNUNET_HashCode),
+ issuer, sizeof (struct GNUNET_PeerIdentity),
+ name, strlen (name),
+ &version, sizeof (version),
+ NULL, 0));
}
-/*
+/**
* Find an experiment based on issuer name and version
*
* @param issuer the issuer
@@ -186,43 +148,46 @@
const char *name,
const struct GNUNET_TIME_Absolute version)
{
- struct FindCtx find_ctx;
+ struct GNUENT_HashCode hc;
- find_ctx.name = name;
- find_ctx.version = version;
- find_ctx.res = NULL;
-
- GNUNET_CONTAINER_multihashmap_get_multiple (experiments,
- &issuer->hashPubKey,
- &find_it, &find_ctx);
- return find_ctx.res;
+ get_experiment_key (issuer,
+ name,
+ version,
+ &hc);
+ return GNUNET_CONTAINER_multihashmap_get (experiments,
+ &hc);
}
struct GetCtx
{
struct Node *n;
+
GNUNET_EXPERIMENTATION_experiments_get_cb get_cb;
+
+ struct GNUNET_CRYPTO_EccPublicSignKey *issuer;
};
static int
get_it (void *cls,
- const struct GNUNET_HashCode * key,
+ const struct GNUNET_HashCode *key,
void *value)
{
struct GetCtx *get_ctx = cls;
struct Experiment *e = value;
- get_ctx->get_cb (get_ctx->n, e);
-
+ if (0 == memcmp (e->issuer,
+ get_ctx->issuer,
+ sizeof (struct GNUNET_CRYPTO_EccPublicSignKey))
+ get_ctx->get_cb (get_ctx->n, e);
return GNUNET_OK;
}
void
GED_experiments_get (struct Node *n,
- struct GNUNET_PeerIdentity *issuer,
+ struct GNUNET_CRYPTO_EccPublicSignKey *issuer,
GNUNET_EXPERIMENTATION_experiments_get_cb get_cb)
{
struct GetCtx get_ctx;
@@ -230,14 +195,12 @@
GNUNET_assert (NULL != n);
GNUNET_assert (NULL != experiments);
GNUNET_assert (NULL != get_cb);
-
get_ctx.n = n;
get_ctx.get_cb = get_cb;
-
- GNUNET_CONTAINER_multihashmap_get_multiple (experiments,
- &issuer->hashPubKey, &get_it,
&get_ctx);
-
- get_cb (n, NULL);
+ get_ctx.issuer = issuer;
+ GNUNET_CONTAINER_multihashmap_iterate (experiments,
+ &get_it, &get_ctx);
+ get_cb (n, NULL); // FIXME: ugly, end is easily signalled as we return:
synchronous API!
}
@@ -247,7 +210,7 @@
int
GNUNET_EXPERIMENTATION_experiments_add (struct Issuer *i,
const char *name,
- struct GNUNET_PeerIdentity issuer_id,
+ const struct GNUNET_CRYPTO_EccPublicKey
*issuer_id,
struct GNUNET_TIME_Absolute version,
char *description,
uint32_t required_capabilities,
@@ -440,10 +403,14 @@
/* Load valid issuer */
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_get_value_string (GED_cfg, "EXPERIMENTATION",
"ISSUERS", &issuers))
+ GNUNET_CONFIGURATION_get_value_string (GED_cfg,
+ "EXPERIMENTATION",
+ "ISSUERS",
+ &issuers))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No valid experiment issuers configured! Set value to peer id
of issuer! Exit...\n"));
+ _("No valid experiment issuers configured! Set value to public
keys of issuers! Exiting.\n"));
+ GED_experiments_stop ();
return GNUNET_SYSERR;
}
@@ -454,30 +421,26 @@
strlen
(pos),
&issuer_ID))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid value `%s'\n"),
- pos);
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "EXPERIMENTATION",
+ "ISSUERS"
+ _("Invalid value for public key\n"));
+ GED_experiments_stop ();
+ return GNUNET_SYSERR;
}
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' is a valid issuer \n",
- GNUNET_i2s (&issuer_ID));
- i = GNUNET_new (struct Issuer);
- i->pubkey = issuer_ID;
- GNUNET_CRYPTO_hash( &issuer_ID, sizeof (issuer_ID), &hash);
- GNUNET_CONTAINER_multihashmap_put (valid_issuers,
- &hash,
- i,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
- }
+ i = GNUNET_new (struct Issuer);
+ i->pubkey = issuer_ID;
+ GNUNET_CRYPTO_hash( &issuer_ID, sizeof (issuer_ID), &hash);
+ GNUNET_CONTAINER_multihashmap_put (valid_issuers,
+ &hash,
+ i,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
}
GNUNET_free (issuers);
-
if (0 == GNUNET_CONTAINER_multihashmap_size (valid_issuers))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No valid experiment issuers configured! Set value to peer id
of issuer! Exit...\n"));
+ _("No valid experiment issuers configured! Set value to public
keys of issuers! Exiting.\n"));
GED_experiments_stop ();
return GNUNET_SYSERR;
}
@@ -485,41 +448,7 @@
"# issuer",
GNUNET_CONTAINER_multihashmap_size (valid_issuers),
GNUNET_NO);
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (GED_cfg,
- "EXPERIMENTATION",
- "PUBKEY",
- &pubkey))
- {
- if (GNUNET_OK !=
- GNUNET_CRYPTO_ecc_public_sign_key_from_string (pubkey, strlen (pubkey),
&pub))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid public key `%s'\n"),
- pubkey);
- GED_experiments_stop ();
- return GNUNET_SYSERR;
- }
- GNUNET_CRYPTO_hash( &pub, sizeof (pub), &hash);
- if (NULL != (i = GNUNET_CONTAINER_multihashmap_get (valid_issuers, &hash)))
- {
- i->pubkey = pub;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Found issuer for public key
`%s'\n"), pubkey);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No issuer for public key `%s'\n"),
pubkey);
- }
- GNUNET_free (pubkey);
- }
-
- GSE_my_issuer_count = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
- GSE_my_issuer = GNUNET_malloc (GSE_my_issuer_count * sizeof (struct
Experimentation_Issuer));
- GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, &create_issuer,
GSE_my_issuer);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemon has %u issuers\n",
- GSE_my_issuer_count);
-
+
experiments = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
/* Load experiments from file */
if (GNUNET_SYSERR ==
@@ -548,12 +477,6 @@
void
GED_experiments_stop ()
{
- if (NULL != GSE_my_issuer)
- {
- GNUNET_free (GSE_my_issuer);
- GSE_my_issuer = NULL;
- GSE_my_issuer_count = 0;
- }
if (NULL != valid_issuers)
{
GNUNET_CONTAINER_multihashmap_iterate (valid_issuers, &free_issuer, NULL);
Modified: gnunet/src/experimentation/gnunet-daemon-experimentation_nodes.c
===================================================================
--- gnunet/src/experimentation/gnunet-daemon-experimentation_nodes.c
2013-10-01 08:29:32 UTC (rev 29749)
+++ gnunet/src/experimentation/gnunet-daemon-experimentation_nodes.c
2013-10-01 09:25:06 UTC (rev 29750)
@@ -62,15 +62,15 @@
struct NodeComCtx
{
- struct NodeComCtx *prev;
- struct NodeComCtx *next;
-
- struct Node *n;
- struct Experiment *e;
-
- size_t size;
- GNUNET_CONNECTION_TransmitReadyNotify notify;
- void *notify_cls;
+ struct NodeComCtx *prev;
+ struct NodeComCtx *next;
+
+ struct Node *n;
+ struct Experiment *e;
+
+ size_t size;
+ GNUNET_CONNECTION_TransmitReadyNotify notify;
+ void *notify_cls;
};
@@ -82,27 +82,26 @@
static void
update_stats (struct GNUNET_CONTAINER_MultiPeerMap *m)
{
- GNUNET_assert (NULL != m);
- GNUNET_assert (NULL != GED_stats);
+ GNUNET_assert (NULL != m);
+ GNUNET_assert (NULL != GED_stats);
- if (m == nodes_active)
- {
- GNUNET_STATISTICS_set (GED_stats, "# nodes active",
- GNUNET_CONTAINER_multipeermap_size(m),
GNUNET_NO);
- }
- else if (m == nodes_inactive)
- {
- GNUNET_STATISTICS_set (GED_stats, "# nodes inactive",
- GNUNET_CONTAINER_multipeermap_size(m),
GNUNET_NO);
- }
- else if (m == nodes_requested)
- {
- GNUNET_STATISTICS_set (GED_stats, "# nodes requested",
- GNUNET_CONTAINER_multipeermap_size(m),
GNUNET_NO);
- }
- else
- GNUNET_break (0);
-
+ if (m == nodes_active)
+ {
+ GNUNET_STATISTICS_set (GED_stats, "# nodes active",
+ GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO);
+ }
+ else if (m == nodes_inactive)
+ {
+ GNUNET_STATISTICS_set (GED_stats, "# nodes inactive",
+ GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO);
+ }
+ else if (m == nodes_requested)
+ {
+ GNUNET_STATISTICS_set (GED_stats, "# nodes requested",
+ GNUNET_CONTAINER_multipeermap_size(m), GNUNET_NO);
+ }
+ else
+ GNUNET_break (0);
}
@@ -119,36 +118,33 @@
const struct GNUNET_PeerIdentity * key,
void *value)
{
- struct Node *n;
- struct NodeComCtx *e_cur;
- struct NodeComCtx *e_next;
- struct GNUNET_CONTAINER_MultiPeerMap *cur = cls;
-
- n = value;
- if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (n->timeout_task);
- n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
-
- if (NULL != n->cth)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
- n->cth = NULL;
- }
- e_next = n->e_req_head;
- while (NULL != (e_cur = e_next))
- {
- e_next = e_cur->next;
- GNUNET_CONTAINER_DLL_remove (n->e_req_head, n->e_req_tail,
e_cur);
- GNUNET_free (e_cur);
- }
-
- GNUNET_free_non_null (n->issuer_id);
-
- GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (cur, key,
value));
- GNUNET_free (value);
- return GNUNET_OK;
+ struct Node *n;
+ struct NodeComCtx *e_cur;
+ struct NodeComCtx *e_next;
+ struct GNUNET_CONTAINER_MultiPeerMap *cur = cls;
+
+ n = value;
+ if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
+ n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
+ if (NULL != n->cth)
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (n->cth);
+ n->cth = NULL;
+ }
+ e_next = n->e_req_head;
+ while (NULL != (e_cur = e_next))
+ {
+ e_next = e_cur->next;
+ GNUNET_CONTAINER_DLL_remove (n->e_req_head, n->e_req_tail, e_cur);
+ GNUNET_free (e_cur);
+ }
+ GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (cur, key, value));
+ GNUNET_free (value);
+ return GNUNET_OK;
}
@@ -189,40 +185,41 @@
static size_t
transmit_read_wrapper (void *cls, size_t bufsize, void *buf)
{
- struct NodeComCtx *e_ctx = cls;
- struct NodeComCtx *next = NULL;
-
- size_t res = e_ctx->notify (e_ctx->notify_cls, bufsize, buf);
- e_ctx->n->cth = NULL;
-
- GNUNET_CONTAINER_DLL_remove (e_ctx->n->e_req_head,
e_ctx->n->e_req_tail, e_ctx);
- next = e_ctx->n->e_req_head;
- GNUNET_free (e_ctx);
-
- if (NULL != next)
- {
- /* Schedule next message */
- schedule_transmisson (next);
- }
- return res;
+ struct NodeComCtx *e_ctx = cls;
+ struct NodeComCtx *next;
+
+ size_t res = e_ctx->notify (e_ctx->notify_cls, bufsize, buf);
+ e_ctx->n->cth = NULL;
+
+ GNUNET_CONTAINER_DLL_remove (e_ctx->n->e_req_head, e_ctx->n->e_req_tail,
e_ctx);
+ next = e_ctx->n->e_req_head;
+ GNUNET_free (e_ctx);
+
+ if (NULL != next)
+ {
+ /* Schedule next message */
+ schedule_transmisson (next);
+ }
+ return res;
}
static void
schedule_transmisson (struct NodeComCtx *e_ctx)
{
- if (NULL != e_ctx->n->cth)
- return;
-
- e_ctx->n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO, 0,
FAST_TIMEOUT,
- &e_ctx->n->id, e_ctx->size, transmit_read_wrapper,
e_ctx);
- if (NULL == e_ctx->n->cth)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Cannot send message
to peer `%s' for experiment `%s'\n"),
- GNUNET_i2s(&e_ctx->n->id), e_ctx->e->name);
- GNUNET_free (e_ctx);
- }
-
+ if (NULL != e_ctx->n->cth)
+ return;
+
+ e_ctx->n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO, 0,
FAST_TIMEOUT,
+ &e_ctx->n->id,
e_ctx->size,
+ transmit_read_wrapper,
e_ctx);
+ if (NULL == e_ctx->n->cth)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Cannot send message to peer `%s' for experiment `%s'\n"),
+ GNUNET_i2s(&e_ctx->n->id), e_ctx->e->name);
+ GNUNET_free (e_ctx);
+ }
}
@@ -235,20 +232,34 @@
static void
remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct Node *n = cls;
+ struct Node *n = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Removing request for peer %s due to timeout\n",
+ GNUNET_i2s (&n->id));
+ if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_requested,
&n->id))
+ {
+ GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_requested,
&n->id, n));
+ update_stats (nodes_requested);
+ GNUNET_CONTAINER_multipeermap_put (nodes_inactive, &n->id, n,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ update_stats (nodes_inactive);
+ }
+ n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing request for peer %s due
to timeout\n",
- GNUNET_i2s (&n->id));
- if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains
(nodes_requested, &n->id))
- {
- GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove
(nodes_requested, &n->id, n));
- update_stats (nodes_requested);
- GNUNET_CONTAINER_multipeermap_put (nodes_inactive,
&n->id, n,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
- update_stats (nodes_inactive);
- }
- n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+static int
+append_public_key (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct GNUNET_CRYPTO_EccPublicSignKey **issuers = cls;
+ struct Issuer *issuer = value;
+
+ *issuers[0] = issuer->pubkey;
+ *issuers = &((*issuers)[1]);
+ return GNUNET_OK;
}
@@ -265,33 +276,37 @@
{
struct Node *n = cls;
struct Experimentation_Request msg;
+ unsigned int my_issuer_count = GNUNET_CONTAINER_multihashmap_size
(valid_issuers);
size_t msg_size = sizeof (msg);
- size_t ri_size = sizeof (struct Experimentation_Issuer) *
GSE_my_issuer_count;
+ size_t ri_size = sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) *
my_issuer_count;
size_t total_size = msg_size + ri_size;
+ struct GNUNET_CRYPTO_EccPublicSignKey *issuers;
n->cth = NULL;
if (NULL == buf)
{
/* client disconnected */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client disconnected\n");
if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
GNUNET_SCHEDULER_cancel (n->timeout_task);
GNUNET_SCHEDULER_add_now (&remove_request, n);
return 0;
}
- memset (buf, '\0', bufsize);
GNUNET_assert (bufsize >= total_size);
-
- msg.msg.size = htons (total_size);
- msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
- msg.capabilities = htonl (GSE_node_capabilities);
- msg.issuer_count = htonl (GSE_my_issuer_count);
- memcpy (buf, &msg, msg_size);
- memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending experimentation request
to peer %s\n"),
- GNUNET_i2s (&n->id));
- return total_size;
+ msg.msg.size = htons (total_size);
+ msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
+ msg.capabilities = htonl (GSE_node_capabilities);
+ msg.issuer_count = htonl (my_issuer_count);
+ memcpy (buf, &msg, msg_size);
+ issuers = (struct GNUNET_CRYPTO_EccPublicSignKey *) buf + msg_size;
+ GNUNET_CONTAINER_multihashmap_iterate (valid_issuers,
+ &append_public_key,
+ &issuers);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Sending experimentation request to peer %s\n"),
+ GNUNET_i2s (&n->id));
+ return total_size;
}
@@ -303,32 +318,33 @@
static void
send_experimentation_request (const struct GNUNET_PeerIdentity *peer)
{
- struct Node *n;
- struct NodeComCtx *e_ctx;
- size_t size;
- size_t c_issuers;
-
- c_issuers = GSE_my_issuer_count;
-
- size = sizeof (struct Experimentation_Request) +
- c_issuers * sizeof (struct
Experimentation_Issuer);
- n = GNUNET_malloc (sizeof (struct Node));
- n->id = *peer;
- n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT,
&remove_request, n);
- n->capabilities = NONE;
-
- e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
- e_ctx->n = n;
- e_ctx->e = NULL;
- e_ctx->size = size;
- e_ctx->notify = &send_experimentation_request_cb;
- e_ctx->notify_cls = n;
- GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
- schedule_transmisson (e_ctx);
-
- GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put
(nodes_requested,
- peer, n,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- update_stats (nodes_requested);
+ struct Node *n;
+ struct NodeComCtx *e_ctx;
+ size_t size;
+ size_t c_issuers;
+
+ c_issuers = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
+ size = sizeof (struct Experimentation_Request) +
+ c_issuers * sizeof (struct GNUNET_CRYPTO_EccPublicSignKey);
+ n = GNUNET_new (struct Node);
+ n->id = *peer;
+ n->timeout_task = GNUNET_SCHEDULER_add_delayed (EXP_RESPONSE_TIMEOUT,
&remove_request, n);
+ n->capabilities = NONE;
+
+ e_ctx = GNUNET_new (struct NodeComCtx);
+ e_ctx->n = n;
+ e_ctx->e = NULL;
+ e_ctx->size = size;
+ e_ctx->notify = &send_experimentation_request_cb;
+ e_ctx->notify_cls = n;
+ GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
+ schedule_transmisson (e_ctx);
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_put (nodes_requested,
+ peer, n,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ update_stats (nodes_requested);
}
@@ -340,73 +356,81 @@
* @param buf the buffer to copy to
* @return bytes passed
*/
-size_t send_response_cb (void *cls, size_t bufsize, void *buf)
+static size_t
+send_response_cb (void *cls, size_t bufsize, void *buf)
{
- struct Node *n = cls;
- struct Experimentation_Response msg;
- size_t ri_size = GSE_my_issuer_count * sizeof (struct
Experimentation_Issuer);
- size_t msg_size = sizeof (msg);
- size_t total_size = msg_size + ri_size;
-
- n->cth = NULL;
+ struct Node *n = cls;
+ struct Experimentation_Response msg;
+ size_t c_issuers = GNUNET_CONTAINER_multihashmap_size (valid_issuers);
+ size_t ri_size = c_issuers * sizeof (struct GNUNET_CRYPTO_EccPublicSignKey);
+ size_t msg_size = sizeof (msg);
+ size_t total_size = msg_size + ri_size;
+ struct GNUNET_CRYPTO_EccPublicSignKey *issuers;
+
+ n->cth = NULL;
if (buf == NULL)
{
/* client disconnected */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client disconnected\n");
return 0;
}
GNUNET_assert (bufsize >= total_size);
- msg.msg.size = htons (total_size);
- msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
- msg.capabilities = htonl (GSE_node_capabilities);
- msg.issuer_count = htonl (GSE_my_issuer_count);
- memcpy (buf, &msg, msg_size);
- memcpy (&((char *) buf)[msg_size], GSE_my_issuer, ri_size);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response to peer %s\n",
- GNUNET_i2s (&n->id));
- return total_size;
+ msg.msg.size = htons (total_size);
+ msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
+ msg.capabilities = htonl (GSE_node_capabilities);
+ msg.issuer_count = htonl (c_issuers);
+ memcpy (buf, &msg, msg_size);
+ issuers = (struct GNUNET_CRYPTO_EccPublicSignKey *) buf + msg_size;
+ GNUNET_CONTAINER_multihashmap_iterate (valid_issuers,
+ &append_public_key,
+ &issuers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending response to peer %s\n",
+ GNUNET_i2s (&n->id));
+ return total_size;
}
static void
get_experiments_cb (struct Node *n, struct Experiment *e)
{
- static int counter = 0;
- if (NULL == e)
- return; /* Done */
-
- /* Tell the scheduler to add a node with an experiment */
- GED_scheduler_add (n, e, GNUNET_YES);
- counter ++;
+ static int counter = 0;
+ if (NULL == e)
+ return; /* Done */
+
+ /* Tell the scheduler to add a node with an experiment */
+ GED_scheduler_add (n, e, GNUNET_YES);
+ counter ++;
}
+
struct Node *
get_node (const struct GNUNET_PeerIdentity *id)
{
- struct Node * res;
- struct Node * tmp;
+ struct Node * res;
+ struct Node * tmp;
- res = NULL;
- tmp = NULL;
- tmp = GNUNET_CONTAINER_multipeermap_get (nodes_active, id);
- if (res == NULL)
- res = tmp;
-
- tmp = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, id);
- if (res == NULL)
- res = tmp;
- else
- GNUNET_break (0); /* Multiple instances */
-
- tmp = GNUNET_CONTAINER_multipeermap_get (nodes_requested, id);
- if (res == NULL)
- res = tmp;
- else
- GNUNET_break (0); /* Multiple instances */
-
- return res;
+ res = NULL;
+ tmp = NULL;
+ tmp = GNUNET_CONTAINER_multipeermap_get (nodes_active, id);
+ if (res == NULL)
+ res = tmp;
+
+ tmp = GNUNET_CONTAINER_multipeermap_get (nodes_inactive, id);
+ if (res == NULL)
+ res = tmp;
+ else
+ GNUNET_break (0); /* Multiple instances */
+
+ tmp = GNUNET_CONTAINER_multipeermap_get (nodes_requested, id);
+ if (res == NULL)
+ res = tmp;
+ else
+ GNUNET_break (0); /* Multiple instances */
+
+ return res;
}
@@ -415,20 +439,22 @@
*
* @param n the node
*/
-static void node_make_active (struct Node *n)
+static void
+node_make_active (struct Node *n)
{
- int c1;
+ int c1;
+
GNUNET_CONTAINER_multipeermap_put (nodes_active,
- &n->id, n,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
- update_stats (nodes_active);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' as active
node\n"),
- GNUNET_i2s (&n->id));
- /* Request experiments for this node to start them */
- for (c1 = 0; c1 < n->issuer_count; c1++)
- {
-
- GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
- }
+ &n->id, n,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ update_stats (nodes_active);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Added peer `%s' as active node\n"),
+ GNUNET_i2s (&n->id));
+ /* Request experiments for this node to start them */
+ for (c1 = 0; c1 < n->issuer_count; c1++)
+ {
+ GED_experiments_get (n, &n->issuer_id[c1], &get_experiments_cb);
+ }
}
@@ -438,100 +464,102 @@
* @param peer the source
* @param message the message
*/
-static void handle_request (const struct GNUNET_PeerIdentity *peer,
-
const struct GNUNET_MessageHeader *message)
+static void
+handle_request (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
{
- struct Node *n;
- struct NodeComCtx *e_ctx;
- struct Experimentation_Request *rm = (struct Experimentation_Request *)
message;
- struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *)
&rm[1];
- int c1;
- int c2;
- uint32_t ic;
- uint32_t ic_accepted;
- int make_active;
-
- if (ntohs (message->size) < sizeof (struct Experimentation_Request))
- {
- GNUNET_break (0);
- return;
- }
- ic = ntohl (rm->issuer_count);
- if (ntohs (message->size) != sizeof (struct Experimentation_Request) +
ic * sizeof (struct Experimentation_Issuer))
- {
- GNUNET_break (0);
- return;
- }
-
- make_active = GNUNET_NO;
- if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active,
peer)))
- {
- /* Nothing to do */
- }
- else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get
(nodes_requested, peer)))
- {
- GNUNET_CONTAINER_multipeermap_remove (nodes_requested,
peer, n);
- if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (n->timeout_task);
- n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
- update_stats (nodes_requested);
- make_active = GNUNET_YES;
- }
- else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get
(nodes_inactive, peer)))
- {
- GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove
(nodes_inactive, peer, n));
- update_stats (nodes_inactive);
- make_active = GNUNET_YES;
- }
- else
- {
- /* Create new node */
- n = GNUNET_malloc (sizeof (struct Node));
- n->id = *peer;
- n->capabilities = NONE;
- make_active = GNUNET_YES;
- }
-
- /* Update node */
- n->capabilities = ntohl (rm->capabilities);
-
- /* Filter accepted issuer */
- ic_accepted = 0;
- for (c1 = 0; c1 < ic; c1++)
- {
- if (GNUNET_YES ==
GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
- ic_accepted ++;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request from peer `%s' with %u
issuers, we accepted %u issuer \n",
- GNUNET_i2s (peer), ic, ic_accepted);
- GNUNET_free_non_null (n->issuer_id);
- n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct
GNUNET_PeerIdentity));
- c2 = 0;
- for (c1 = 0; c1 < ic; c1++)
- {
- if (GNUNET_YES ==
GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
- {
- n->issuer_id[c2] = rmi[c1].issuer_id;
- c2 ++;
- }
- }
- n->issuer_count = ic_accepted;
-
- if (GNUNET_YES == make_active)
- node_make_active (n);
-
- /* Send response */
- e_ctx = GNUNET_malloc (sizeof (struct NodeComCtx));
- e_ctx->n = n;
- e_ctx->e = NULL;
- e_ctx->size = sizeof (struct Experimentation_Response) +
GSE_my_issuer_count * sizeof (struct Experimentation_Issuer);
- e_ctx->notify = &send_response_cb;
- e_ctx->notify_cls = n;
-
- GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
- schedule_transmisson (e_ctx);
+ struct Node *n;
+ struct NodeComCtx *e_ctx;
+ const struct Experimentation_Request *rm = (const struct
Experimentation_Request *) message;
+ const struct Experimentation_Issuer *rmi = (const struct
Experimentation_Issuer *) &rm[1];
+ int c1;
+ int c2;
+ uint32_t ic;
+ uint32_t ic_accepted;
+ int make_active;
+
+ if (ntohs (message->size) < sizeof (struct Experimentation_Request))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ic = ntohl (rm->issuer_count);
+ if (ntohs (message->size) != sizeof (struct Experimentation_Request) + ic *
sizeof (struct Experimentation_Issuer))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ make_active = GNUNET_NO;
+ if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer)))
+ {
+ /* Nothing to do */
+ }
+ else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested,
peer)))
+ {
+ GNUNET_CONTAINER_multipeermap_remove (nodes_requested, peer, n);
+ if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
+ n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ update_stats (nodes_requested);
+ make_active = GNUNET_YES;
+ }
+ else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive,
peer)))
+ {
+ GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_inactive,
peer, n));
+ update_stats (nodes_inactive);
+ make_active = GNUNET_YES;
+ }
+ else
+ {
+ /* Create new node */
+ n = GNUNET_new (struct Node);
+ n->id = *peer;
+ n->capabilities = NONE;
+ make_active = GNUNET_YES;
+ }
+
+ /* Update node */
+ n->capabilities = ntohl (rm->capabilities);
+
+ /* Filter accepted issuer */
+ ic_accepted = 0;
+ for (c1 = 0; c1 < ic; c1++)
+ {
+ if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
+ ic_accepted ++;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Request from peer `%s' with %u issuers, we accepted %u issuer
\n",
+ GNUNET_i2s (peer), ic, ic_accepted);
+ GNUNET_free_non_null (n->issuer_id);
+ n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct
GNUNET_PeerIdentity));
+ c2 = 0;
+ for (c1 = 0; c1 < ic; c1++)
+ {
+ if (GNUNET_YES == GED_experiments_issuer_accepted (&rmi[c1].issuer_id))
+ {
+ n->issuer_id[c2] = rmi[c1].issuer_id;
+ c2 ++;
+ }
+ }
+ n->issuer_count = ic_accepted;
+
+ if (GNUNET_YES == make_active)
+ node_make_active (n);
+
+ /* Send response */
+ e_ctx = GNUNET_new (struct NodeComCtx);
+ e_ctx->n = n;
+ e_ctx->e = NULL;
+ e_ctx->size = sizeof (struct Experimentation_Response) + GSE_my_issuer_count
* sizeof (struct Experimentation_Issuer);
+ e_ctx->notify = &send_response_cb;
+ e_ctx->notify_cls = n;
+
+ GNUNET_CONTAINER_DLL_insert_tail(n->e_req_head, n->e_req_tail, e_ctx);
+ schedule_transmisson (e_ctx);
}
@@ -542,239 +570,244 @@
* @param message the message
*/
static void handle_response (const struct GNUNET_PeerIdentity *peer,
-
const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
- struct Node *n;
- struct Experimentation_Response *rm = (struct Experimentation_Response
*) message;
- struct Experimentation_Issuer *rmi = (struct Experimentation_Issuer *)
&rm[1];
- uint32_t ic;
- uint32_t ic_accepted;
- int make_active;
- unsigned int c1;
- unsigned int c2;
+ struct Node *n;
+ const struct Experimentation_Response *rm = (const struct
Experimentation_Response *) message;
+ const struct Experimentation_Issuer *rmi = (const struct
Experimentation_Issuer *) &rm[1];
+ uint32_t ic;
+ uint32_t ic_accepted;
+ int make_active;
+ unsigned int c1;
+ unsigned int c2;
+
+ if (ntohs (message->size) < sizeof (struct Experimentation_Response))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ic = ntohl (rm->issuer_count);
+ if (ntohs (message->size) != sizeof (struct Experimentation_Response) + ic *
sizeof (struct Experimentation_Issuer))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ make_active = GNUNET_NO;
+ if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active, peer)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %s from %s peer `%s'\n",
+ "RESPONSE", "active", GNUNET_i2s (peer));
+ }
+ else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_requested,
peer)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
+ "RESPONSE", "requested", GNUNET_i2s (peer));
+ GNUNET_CONTAINER_multipeermap_remove (nodes_requested, peer, n);
+ if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
+ n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ update_stats (nodes_requested);
+ make_active = GNUNET_YES;
+ }
+ else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_inactive,
peer)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %s from peer `%s'\n",
+ "RESPONSE", "inactive", GNUNET_i2s (peer));
+ GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (nodes_inactive,
peer, n));
+ update_stats (nodes_inactive);
+ make_active = GNUNET_YES;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from %s peer `%s'\n",
+ "RESPONSE", "unknown", GNUNET_i2s (peer));
+ return;
+ }
+
+ /* Update */
+ n->capabilities = ntohl (rm->capabilities);
+
+ /* Filter accepted issuer */
+ ic_accepted = 0;
+ for (c1 = 0; c1 < ic; c1++)
+ {
+ if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
+ ic_accepted ++;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Response from peer `%s' with %u issuers, we accepted %u issuer
\n",
+ GNUNET_i2s (peer), ic, ic_accepted);
+ GNUNET_free_non_null (n->issuer_id);
+ n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct
GNUNET_PeerIdentity));
+ c2 = 0;
+ for (c1 = 0; c1 < ic; c1++)
+ {
+ if (GNUNET_YES == GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
+ {
+ n->issuer_id[c2] = rmi[c1].issuer_id;
+ c2 ++;
+ }
+ }
+ n->issuer_count = ic_accepted;
+
+ if (GNUNET_YES == make_active)
+ node_make_active (n);
+}
- if (ntohs (message->size) < sizeof (struct Experimentation_Response))
- {
- GNUNET_break (0);
- return;
- }
- ic = ntohl (rm->issuer_count);
- if (ntohs (message->size) != sizeof (struct Experimentation_Response) +
ic * sizeof (struct Experimentation_Issuer))
- {
- GNUNET_break (0);
- return;
- }
- make_active = GNUNET_NO;
- if (NULL != (n = GNUNET_CONTAINER_multipeermap_get (nodes_active,
peer)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from
%s peer `%s'\n",
- "RESPONSE", "active", GNUNET_i2s
(peer));
- }
- else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get
(nodes_requested, peer)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from
%s peer `%s'\n",
- "RESPONSE", "requested", GNUNET_i2s
(peer));
- GNUNET_CONTAINER_multipeermap_remove (nodes_requested,
peer, n);
- if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (n->timeout_task);
- n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
- update_stats (nodes_requested);
- make_active = GNUNET_YES;
- }
- else if (NULL != (n = GNUNET_CONTAINER_multipeermap_get
(nodes_inactive, peer)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from
peer `%s'\n",
- "RESPONSE", "inactive", GNUNET_i2s
(peer));
- GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove
(nodes_inactive, peer, n));
- update_stats (nodes_inactive);
- make_active = GNUNET_YES;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s from
%s peer `%s'\n",
- "RESPONSE", "unknown", GNUNET_i2s
(peer));
- return;
- }
-
- /* Update */
- n->capabilities = ntohl (rm->capabilities);
-
- /* Filter accepted issuer */
- ic_accepted = 0;
- for (c1 = 0; c1 < ic; c1++)
- {
- if (GNUNET_YES ==
GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
- ic_accepted ++;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Response from peer `%s' with %u
issuers, we accepted %u issuer \n",
- GNUNET_i2s (peer), ic, ic_accepted);
- GNUNET_free_non_null (n->issuer_id);
- n->issuer_id = GNUNET_malloc (ic_accepted * sizeof (struct
GNUNET_PeerIdentity));
- c2 = 0;
- for (c1 = 0; c1 < ic; c1++)
- {
- if (GNUNET_YES ==
GED_experiments_issuer_accepted(&rmi[c1].issuer_id))
- {
- n->issuer_id[c2] = rmi[c1].issuer_id;
- c2 ++;
- }
- }
- n->issuer_count = ic_accepted;
-
- if (GNUNET_YES == make_active)
- node_make_active (n);
-}
-
/**
* Handle a response
*
* @param peer the source
* @param message the message
*/
-static void handle_start (const struct GNUNET_PeerIdentity *peer,
-
const struct GNUNET_MessageHeader *message)
+static void
+handle_start (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
{
- uint16_t size;
- uint32_t name_len;
- const struct GED_start_message *msg;
- const char *name;
- struct Node *n;
- struct Experiment *e;
+ uint16_t size;
+ uint32_t name_len;
+ const struct GED_start_message *msg;
+ const char *name;
+ struct Node *n;
+ struct Experiment *e;
+
+ if (NULL == peer)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (NULL == message)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ size = ntohs (message->size);
+ if (size < sizeof (struct GED_start_message))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ msg = (const struct GED_start_message *) message;
+ name_len = ntohl (msg->len_name);
+ if (size != sizeof (struct GED_start_message) + name_len)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ n = get_node (peer);
+ if (NULL == n)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ name = (const char *) &msg[1];
+ if (name[name_len-1] != '\0')
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (name_len != strlen (name) + 1)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ e = GED_experiments_find (&msg->issuer, name,
GNUNET_TIME_absolute_ntoh(msg->version_nbo));
+ if (NULL == e)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GED_scheduler_handle_start (n, e);
+}
- if (NULL == peer)
- {
- GNUNET_break (0);
- return;
- }
- if (NULL == message)
- {
- GNUNET_break (0);
- return;
- }
- size = ntohs (message->size);
- if (size < sizeof (struct GED_start_message))
- {
- GNUNET_break (0);
- return;
- }
- msg = (const struct GED_start_message *) message;
- name_len = ntohl (msg->len_name);
- if (size != sizeof (struct GED_start_message) + name_len)
- {
- GNUNET_break (0);
- return;
- }
-
- n = get_node (peer);
- if (NULL == n)
- {
- GNUNET_break (0);
- return;
- }
- name = (const char *) &msg[1];
- if (name[name_len-1] != '\0')
- {
- GNUNET_break (0);
- return;
- }
-
- if (name_len != strlen (name) + 1)
- {
- GNUNET_break (0);
- return;
- }
-
- e = GED_experiments_find (&msg->issuer, name,
GNUNET_TIME_absolute_ntoh(msg->version_nbo));
- if (NULL == e)
- {
- GNUNET_break (0);
- return;
- }
-
- GED_scheduler_handle_start (n, e);
-}
-
/**
* Handle a response
*
* @param peer the source
* @param message the message
*/
-static void handle_start_ack (const struct GNUNET_PeerIdentity *peer,
-
const struct GNUNET_MessageHeader *message)
+static void
+handle_start_ack (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
{
- uint16_t size;
- uint32_t name_len;
- const struct GED_start_ack_message *msg;
- const char *name;
- struct Node *n;
- struct Experiment *e;
+ uint16_t size;
+ uint32_t name_len;
+ const struct GED_start_ack_message *msg;
+ const char *name;
+ struct Node *n;
+ struct Experiment *e;
+
+ if (NULL == peer)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (NULL == message)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ size = ntohs (message->size);
+ if (size < sizeof (struct GED_start_ack_message))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ msg = (const struct GED_start_ack_message *) message;
+ name_len = ntohl (msg->len_name);
+ if (size != sizeof (struct GED_start_message) + name_len)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ n = get_node (peer);
+ if (NULL == n)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ name = (const char *) &msg[1];
+ if (name[name_len-1] != '\0')
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (name_len != strlen (name) + 1)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ e = GED_experiments_find (&msg->issuer, name,
GNUNET_TIME_absolute_ntoh(msg->version_nbo));
+ if (NULL == e)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GED_scheduler_handle_start_ack (n, e);
+}
- if (NULL == peer)
- {
- GNUNET_break (0);
- return;
- }
- if (NULL == message)
- {
- GNUNET_break (0);
- return;
- }
- size = ntohs (message->size);
- if (size < sizeof (struct GED_start_ack_message))
- {
- GNUNET_break (0);
- return;
- }
- msg = (const struct GED_start_ack_message *) message;
- name_len = ntohl (msg->len_name);
- if (size != sizeof (struct GED_start_message) + name_len)
- {
- GNUNET_break (0);
- return;
- }
-
- n = get_node (peer);
- if (NULL == n)
- {
- GNUNET_break (0);
- return;
- }
- name = (const char *) &msg[1];
- if (name[name_len-1] != '\0')
- {
- GNUNET_break (0);
- return;
- }
-
- if (name_len != strlen (name) + 1)
- {
- GNUNET_break (0);
- return;
- }
-
- e = GED_experiments_find (&msg->issuer, name,
GNUNET_TIME_absolute_ntoh(msg->version_nbo));
- if (NULL == e)
- {
- GNUNET_break (0);
- return;
- }
- GED_scheduler_handle_start_ack (n, e);
-}
-
/**
* Handle a response
*
* @param peer the source
* @param message the message
*/
-static void handle_stop (const struct GNUNET_PeerIdentity *peer,
-
const struct GNUNET_MessageHeader *message)
+static void
+handle_stop (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
{
uint16_t size;
uint32_t name_len;
@@ -836,31 +869,33 @@
GED_scheduler_handle_stop (n, e);
}
+
/**
* Method called whenever a given peer connects.
*
* @param cls closure
* @param peer peer identity this notification is about
*/
-void core_connect_handler (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+static void
+core_connect_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
- if (GNUNET_YES == is_me(peer))
- return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
- GNUNET_i2s (peer));
-
- if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains
(nodes_requested, peer))
- return; /* We already sent a request */
-
- if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_active,
peer))
- return; /* This peer is known as active */
-
- if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains
(nodes_inactive, peer))
- return; /* This peer is known as inactive */
-
- send_experimentation_request (peer);
+ if (GNUNET_YES == is_me(peer))
+ return;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connected to peer %s\n"),
+ GNUNET_i2s (peer));
+
+ if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_requested,
peer))
+ return; /* We already sent a request */
+
+ if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_active,
peer))
+ return; /* This peer is known as active */
+
+ if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (nodes_inactive,
peer))
+ return; /* This peer is known as inactive */
+
+ send_experimentation_request (peer);
}
@@ -870,8 +905,9 @@
* @param cls closure
* @param peer peer identity this notification is about
*/
-void core_disconnect_handler (void *cls,
- const struct GNUNET_PeerIdentity * peer)
+static void
+core_disconnect_handler (void *cls,
+ const struct GNUNET_PeerIdentity * peer)
{
struct Node *n;
if (GNUNET_YES == is_me(peer))
@@ -901,8 +937,8 @@
*/
static int
core_receive_handler (void *cls,
-
const struct GNUNET_PeerIdentity *other,
-
const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message)
{
if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
{
@@ -934,7 +970,8 @@
}
-size_t node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
+static size_t
+node_experiment_start_cb (void *cls, size_t bufsize, void *buf)
{
struct NodeComCtx *e_ctx = cls;
struct GED_start_message *msg;
@@ -960,7 +997,9 @@
return size;
}
-size_t node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
+
+static size_t
+node_experiment_start_ack_cb (void *cls, size_t bufsize, void *buf)
{
struct NodeComCtx *e_ctx = cls;
struct GED_start_ack_message *msg;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29750 - gnunet/src/experimentation,
gnunet <=