summaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_dht.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/cadet/gnunet-service-cadet_dht.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
uncrustify as demanded.
Diffstat (limited to 'src/cadet/gnunet-service-cadet_dht.c')
-rw-r--r--src/cadet/gnunet-service-cadet_dht.c308
1 files changed, 153 insertions, 155 deletions
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c
index 0b87eeab7..c208c7f29 100644
--- a/src/cadet/gnunet-service-cadet_dht.c
+++ b/src/cadet/gnunet-service-cadet_dht.c
@@ -11,12 +11,12 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
/**
* @file cadet/gnunet-service-cadet_dht.c
* @brief Information we track per peer.
@@ -40,29 +40,27 @@
* notifications when our HELLO is ready, so this is just the maximum
* we wait for the first notification.
*/
-#define STARTUP_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
+#define STARTUP_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)
/**
* How long do we wait after we get an updated HELLO before publishing?
* Allows for the HELLO to be updated again quickly, for example in
* case multiple addresses changed and we got a partial update.
*/
-#define CHANGE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100)
+#define CHANGE_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
-#define LOG(level, ...) GNUNET_log_from (level,"cadet-dht",__VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from(level, "cadet-dht", __VA_ARGS__)
/**
* Handle for DHT searches.
*/
-struct GCD_search_handle
-{
+struct GCD_search_handle {
/**
* DHT_GET handle.
*/
struct GNUNET_DHT_GetHandle *dhtget;
-
};
@@ -109,35 +107,35 @@ static struct GNUNET_TIME_Relative announce_delay;
* @param data pointer to the result data
*/
static void
-dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
- const struct GNUNET_HashCode *key,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+dht_get_id_handler(void *cls, struct GNUNET_TIME_Absolute exp,
+ const struct GNUNET_HashCode *key,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length,
+ enum GNUNET_BLOCK_Type type,
+ size_t size,
+ const void *data)
{
const struct GNUNET_HELLO_Message *hello = data;
struct CadetPeer *peer;
- GCPP_try_path_from_dht (get_path,
- get_path_length,
- put_path,
- put_path_length);
- if ( (size >= sizeof (struct GNUNET_HELLO_Message)) &&
- (ntohs (hello->header.size) == size) &&
- (size == GNUNET_HELLO_size (hello)) )
- {
- peer = GCP_get (&put_path[0],
- GNUNET_YES);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Got HELLO for %s\n",
- GCP_2s (peer));
- GCP_set_hello (peer,
- hello);
- }
+ GCPP_try_path_from_dht(get_path,
+ get_path_length,
+ put_path,
+ put_path_length);
+ if ((size >= sizeof(struct GNUNET_HELLO_Message)) &&
+ (ntohs(hello->header.size) == size) &&
+ (size == GNUNET_HELLO_size(hello)))
+ {
+ peer = GCP_get(&put_path[0],
+ GNUNET_YES);
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Got HELLO for %s\n",
+ GCP_2s(peer));
+ GCP_set_hello(peer,
+ hello);
+ }
}
@@ -147,7 +145,7 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
* @param cls closure
*/
static void
-announce_id (void *cls)
+announce_id(void *cls)
{
struct GNUNET_HashCode phash;
const struct GNUNET_HELLO_Message *hello;
@@ -155,58 +153,58 @@ announce_id (void *cls)
struct GNUNET_TIME_Absolute expiration;
struct GNUNET_TIME_Relative next_put;
- hello = GCH_get_mine ();
- size = (NULL != hello) ? GNUNET_HELLO_size (hello) : 0;
+ hello = GCH_get_mine();
+ size = (NULL != hello) ? GNUNET_HELLO_size(hello) : 0;
if (0 == size)
- {
- expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
- announce_delay);
- announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay);
- }
+ {
+ expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
+ announce_delay);
+ announce_delay = GNUNET_TIME_STD_BACKOFF(announce_delay);
+ }
else
- {
- expiration = GNUNET_HELLO_get_last_expiration (hello);
- announce_delay = GNUNET_TIME_UNIT_SECONDS;
- }
+ {
+ expiration = GNUNET_HELLO_get_last_expiration(hello);
+ announce_delay = GNUNET_TIME_UNIT_SECONDS;
+ }
/* Call again in id_announce_time, unless HELLO expires first,
* but wait at least 1s. */
next_put
- = GNUNET_TIME_absolute_get_remaining (expiration);
+ = GNUNET_TIME_absolute_get_remaining(expiration);
next_put
- = GNUNET_TIME_relative_min (next_put,
- id_announce_time);
+ = GNUNET_TIME_relative_min(next_put,
+ id_announce_time);
next_put
- = GNUNET_TIME_relative_max (next_put,
- GNUNET_TIME_UNIT_SECONDS);
+ = GNUNET_TIME_relative_max(next_put,
+ GNUNET_TIME_UNIT_SECONDS);
announce_id_task
- = GNUNET_SCHEDULER_add_delayed (next_put,
- &announce_id,
- cls);
- GNUNET_STATISTICS_update (stats,
- "# DHT announce",
- 1,
- GNUNET_NO);
- memset (&phash,
- 0,
- sizeof (phash));
- GNUNET_memcpy (&phash,
- &my_full_id,
- sizeof (my_full_id));
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Announcing my HELLO (%u bytes) in the DHT\n",
- size);
- GNUNET_DHT_put (dht_handle, /* DHT handle */
- &phash, /* Key to use */
- dht_replication_level, /* Replication level */
- GNUNET_DHT_RO_RECORD_ROUTE
- | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
- GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */
- size, /* Size of the data */
- (const char *) hello, /* Data itself */
- expiration, /* Data expiration */
- NULL, /* Continuation */
- NULL); /* Continuation closure */
+ = GNUNET_SCHEDULER_add_delayed(next_put,
+ &announce_id,
+ cls);
+ GNUNET_STATISTICS_update(stats,
+ "# DHT announce",
+ 1,
+ GNUNET_NO);
+ memset(&phash,
+ 0,
+ sizeof(phash));
+ GNUNET_memcpy(&phash,
+ &my_full_id,
+ sizeof(my_full_id));
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Announcing my HELLO (%u bytes) in the DHT\n",
+ size);
+ GNUNET_DHT_put(dht_handle, /* DHT handle */
+ &phash, /* Key to use */
+ dht_replication_level, /* Replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE
+ | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
+ GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */
+ size, /* Size of the data */
+ (const char *)hello, /* Data itself */
+ expiration, /* Data expiration */
+ NULL, /* Continuation */
+ NULL); /* Continuation closure */
}
@@ -215,15 +213,15 @@ announce_id (void *cls)
* changes. Re-triggers the DHT PUT immediately.
*/
void
-GCD_hello_update ()
+GCD_hello_update()
{
if (NULL == announce_id_task)
return; /* too early */
- GNUNET_SCHEDULER_cancel (announce_id_task);
+ GNUNET_SCHEDULER_cancel(announce_id_task);
announce_id_task
- = GNUNET_SCHEDULER_add_delayed (CHANGE_DELAY,
- &announce_id,
- NULL);
+ = GNUNET_SCHEDULER_add_delayed(CHANGE_DELAY,
+ &announce_id,
+ NULL);
}
@@ -233,42 +231,42 @@ GCD_hello_update ()
* @param c Configuration.
*/
void
-GCD_init (const struct GNUNET_CONFIGURATION_Handle *c)
+GCD_init(const struct GNUNET_CONFIGURATION_Handle *c)
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (c,
- "CADET",
- "DHT_REPLICATION_LEVEL",
- &dht_replication_level))
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
- "CADET",
- "DHT_REPLICATION_LEVEL",
- "USING DEFAULT");
- dht_replication_level = 3;
- }
+ GNUNET_CONFIGURATION_get_value_number(c,
+ "CADET",
+ "DHT_REPLICATION_LEVEL",
+ &dht_replication_level))
+ {
+ GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING,
+ "CADET",
+ "DHT_REPLICATION_LEVEL",
+ "USING DEFAULT");
+ dht_replication_level = 3;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (c,
- "CADET",
- "ID_ANNOUNCE_TIME",
- &id_announce_time))
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "CADET",
- "ID_ANNOUNCE_TIME",
- "MISSING");
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
-
- dht_handle = GNUNET_DHT_connect (c,
- 64);
- GNUNET_break (NULL != dht_handle);
+ GNUNET_CONFIGURATION_get_value_time(c,
+ "CADET",
+ "ID_ANNOUNCE_TIME",
+ &id_announce_time))
+ {
+ GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
+ "CADET",
+ "ID_ANNOUNCE_TIME",
+ "MISSING");
+ GNUNET_SCHEDULER_shutdown();
+ return;
+ }
+
+ dht_handle = GNUNET_DHT_connect(c,
+ 64);
+ GNUNET_break(NULL != dht_handle);
announce_delay = GNUNET_TIME_UNIT_SECONDS;
- announce_id_task = GNUNET_SCHEDULER_add_delayed (STARTUP_DELAY,
- &announce_id,
- NULL);
+ announce_id_task = GNUNET_SCHEDULER_add_delayed(STARTUP_DELAY,
+ &announce_id,
+ NULL);
}
@@ -276,18 +274,18 @@ GCD_init (const struct GNUNET_CONFIGURATION_Handle *c)
* Shut down the DHT subsystem.
*/
void
-GCD_shutdown (void)
+GCD_shutdown(void)
{
if (NULL != dht_handle)
- {
- GNUNET_DHT_disconnect (dht_handle);
- dht_handle = NULL;
- }
+ {
+ GNUNET_DHT_disconnect(dht_handle);
+ dht_handle = NULL;
+ }
if (NULL != announce_id_task)
- {
- GNUNET_SCHEDULER_cancel (announce_id_task);
- announce_id_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel(announce_id_task);
+ announce_id_task = NULL;
+ }
}
@@ -298,37 +296,37 @@ GCD_shutdown (void)
* @return handle to abort search
*/
struct GCD_search_handle *
-GCD_search (const struct GNUNET_PeerIdentity *peer_id)
+GCD_search(const struct GNUNET_PeerIdentity *peer_id)
{
struct GNUNET_HashCode phash;
struct GCD_search_handle *h;
- GNUNET_STATISTICS_update (stats,
- "# DHT search",
- 1,
- GNUNET_NO);
- memset (&phash,
- 0,
- sizeof (phash));
- GNUNET_memcpy (&phash,
- peer_id,
- sizeof (*peer_id));
-
- h = GNUNET_new (struct GCD_search_handle);
- h->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
- GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */
- &phash, /* key to search */
- dht_replication_level, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, /* xquery */
- 0, /* xquery bits */
- &dht_get_id_handler,
- h);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Starting DHT GET for peer %s (%p)\n",
- GNUNET_i2s (peer_id),
- h);
+ GNUNET_STATISTICS_update(stats,
+ "# DHT search",
+ 1,
+ GNUNET_NO);
+ memset(&phash,
+ 0,
+ sizeof(phash));
+ GNUNET_memcpy(&phash,
+ peer_id,
+ sizeof(*peer_id));
+
+ h = GNUNET_new(struct GCD_search_handle);
+ h->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */
+ GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */
+ &phash, /* key to search */
+ dht_replication_level, /* replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE |
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ NULL, /* xquery */
+ 0, /* xquery bits */
+ &dht_get_id_handler,
+ h);
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Starting DHT GET for peer %s (%p)\n",
+ GNUNET_i2s(peer_id),
+ h);
return h;
}
@@ -339,13 +337,13 @@ GCD_search (const struct GNUNET_PeerIdentity *peer_id)
* @param h handle to search to stop
*/
void
-GCD_search_stop (struct GCD_search_handle *h)
+GCD_search_stop(struct GCD_search_handle *h)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping DHT GET %p\n",
- h);
- GNUNET_DHT_get_stop (h->dhtget);
- GNUNET_free (h);
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping DHT GET %p\n",
+ h);
+ GNUNET_DHT_get_stop(h->dhtget);
+ GNUNET_free(h);
}
/* end of gnunet-service-cadet_dht.c */