aboutsummaryrefslogtreecommitdiff
path: root/src/service/messenger/messenger_api_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/messenger/messenger_api_util.c')
-rw-r--r--src/service/messenger/messenger_api_util.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/src/service/messenger/messenger_api_util.c b/src/service/messenger/messenger_api_util.c
index 9d23e2262..c098ae3d9 100644
--- a/src/service/messenger/messenger_api_util.c
+++ b/src/service/messenger/messenger_api_util.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2020--2021 GNUnet e.V. 3 Copyright (C) 2020--2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -35,29 +35,34 @@ callback_close_channel (void *cls)
35 GNUNET_CADET_channel_destroy (channel); 35 GNUNET_CADET_channel_destroy (channel);
36} 36}
37 37
38
38void 39void
39delayed_disconnect_channel (struct GNUNET_CADET_Channel *channel) 40delayed_disconnect_channel (struct GNUNET_CADET_Channel *channel)
40{ 41{
41 GNUNET_assert(channel); 42 GNUNET_assert (channel);
42 43
43 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), 44 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (),
44 GNUNET_SCHEDULER_PRIORITY_URGENT, 45 GNUNET_SCHEDULER_PRIORITY_URGENT,
45 callback_close_channel, channel); 46 callback_close_channel, channel);
46} 47}
47 48
49
48int 50int
49generate_free_member_id (struct GNUNET_ShortHashCode *id, 51generate_free_member_id (struct GNUNET_ShortHashCode *id,
50 const struct GNUNET_CONTAINER_MultiShortmap *members) 52 const struct GNUNET_CONTAINER_MultiShortmap *members)
51{ 53{
52 GNUNET_assert(id); 54 GNUNET_assert (id);
53 55
54 size_t counter = 1 + (members ? GNUNET_CONTAINER_multishortmap_size (members) : 0); 56 size_t counter = 1 + (members ? GNUNET_CONTAINER_multishortmap_size (
57 members) : 0);
55 58
56 do 59 do
57 { 60 {
58 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, id, sizeof(struct GNUNET_ShortHashCode)); 61 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, id, sizeof(struct
62 GNUNET_ShortHashCode));
59 63
60 if ((members) && (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (members, id))) 64 if ((members) && (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
65 members, id)))
61 counter--; 66 counter--;
62 else 67 else
63 break; 68 break;
@@ -70,34 +75,53 @@ generate_free_member_id (struct GNUNET_ShortHashCode *id,
70 return GNUNET_NO; 75 return GNUNET_NO;
71} 76}
72 77
78
79const struct GNUNET_CRYPTO_PrivateKey*
80get_anonymous_private_key ()
81{
82 const struct GNUNET_IDENTITY_Ego *ego = GNUNET_IDENTITY_ego_get_anonymous ();
83 return GNUNET_IDENTITY_ego_get_private_key (ego);
84}
85
86
73const struct GNUNET_CRYPTO_PublicKey* 87const struct GNUNET_CRYPTO_PublicKey*
74get_anonymous_public_key () 88get_anonymous_public_key ()
75{ 89{
76 static struct GNUNET_CRYPTO_PublicKey public_key; 90 static struct GNUNET_CRYPTO_PublicKey public_key;
77 static struct GNUNET_IDENTITY_Ego* ego = NULL; 91 static struct GNUNET_IDENTITY_Ego *ego = NULL;
78 92
79 if (!ego) 93 if (! ego)
80 { 94 {
81 ego = GNUNET_IDENTITY_ego_get_anonymous(); 95 ego = GNUNET_IDENTITY_ego_get_anonymous ();
82 GNUNET_IDENTITY_ego_get_public_key(ego, &public_key); 96 GNUNET_IDENTITY_ego_get_public_key (ego, &public_key);
83 } 97 }
84 98
85 return &public_key; 99 return &public_key;
86} 100}
87 101
102
88void 103void
89convert_messenger_key_to_port(const struct GNUNET_HashCode *key, 104convert_messenger_key_to_port (const struct GNUNET_HashCode *key,
90 struct GNUNET_HashCode *port) 105 struct GNUNET_HashCode *port)
91{ 106{
92 static uint32_t version_value = 0; 107 static uint32_t version_value = 0;
93 static struct GNUNET_HashCode version; 108 static struct GNUNET_HashCode version;
94 109
95 if (!version_value) { 110 if (! version_value)
111 {
96 version_value = (uint32_t) (GNUNET_MESSENGER_VERSION); 112 version_value = (uint32_t) (GNUNET_MESSENGER_VERSION);
97 version_value = ((version_value >> 16) & 0xFFFF); 113 version_value = ((version_value >> 16) & 0xFFFF);
98 version_value = GNUNET_htole32(version_value); 114 version_value = GNUNET_htole32 (version_value);
99 GNUNET_CRYPTO_hash(&version_value, sizeof(version_value), &version); 115 GNUNET_CRYPTO_hash (&version_value, sizeof(version_value), &version);
100 } 116 }
101 117
102 GNUNET_CRYPTO_hash_sum(key, &version, port); 118 GNUNET_CRYPTO_hash_sum (key, &version, port);
119}
120
121
122void
123convert_peer_identity_to_id (const struct GNUNET_PeerIdentity *identity,
124 struct GNUNET_ShortHashCode *id)
125{
126 GNUNET_memcpy (id, identity, sizeof(struct GNUNET_ShortHashCode));
103} 127}