aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api_util.c')
-rw-r--r--src/messenger/messenger_api_util.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/messenger/messenger_api_util.c b/src/messenger/messenger_api_util.c
index 2fc58ed75..bac9d0a05 100644
--- a/src/messenger/messenger_api_util.c
+++ b/src/messenger/messenger_api_util.c
@@ -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,48 +75,53 @@ generate_free_member_id (struct GNUNET_ShortHashCode *id,
70 return GNUNET_NO; 75 return GNUNET_NO;
71} 76}
72 77
78
73const struct GNUNET_IDENTITY_PrivateKey* 79const struct GNUNET_IDENTITY_PrivateKey*
74get_anonymous_private_key () 80get_anonymous_private_key ()
75{ 81{
76 const struct GNUNET_IDENTITY_Ego* ego = GNUNET_IDENTITY_ego_get_anonymous(); 82 const struct GNUNET_IDENTITY_Ego *ego = GNUNET_IDENTITY_ego_get_anonymous ();
77 return GNUNET_IDENTITY_ego_get_private_key(ego); 83 return GNUNET_IDENTITY_ego_get_private_key (ego);
78} 84}
79 85
86
80const struct GNUNET_IDENTITY_PublicKey* 87const struct GNUNET_IDENTITY_PublicKey*
81get_anonymous_public_key () 88get_anonymous_public_key ()
82{ 89{
83 static struct GNUNET_IDENTITY_PublicKey public_key; 90 static struct GNUNET_IDENTITY_PublicKey public_key;
84 static struct GNUNET_IDENTITY_Ego* ego = NULL; 91 static struct GNUNET_IDENTITY_Ego *ego = NULL;
85 92
86 if (!ego) 93 if (! ego)
87 { 94 {
88 ego = GNUNET_IDENTITY_ego_get_anonymous(); 95 ego = GNUNET_IDENTITY_ego_get_anonymous ();
89 GNUNET_IDENTITY_ego_get_public_key(ego, &public_key); 96 GNUNET_IDENTITY_ego_get_public_key (ego, &public_key);
90 } 97 }
91 98
92 return &public_key; 99 return &public_key;
93} 100}
94 101
102
95void 103void
96convert_messenger_key_to_port(const struct GNUNET_HashCode *key, 104convert_messenger_key_to_port (const struct GNUNET_HashCode *key,
97 struct GNUNET_HashCode *port) 105 struct GNUNET_HashCode *port)
98{ 106{
99 static uint32_t version_value = 0; 107 static uint32_t version_value = 0;
100 static struct GNUNET_HashCode version; 108 static struct GNUNET_HashCode version;
101 109
102 if (!version_value) { 110 if (! version_value)
111 {
103 version_value = (uint32_t) (GNUNET_MESSENGER_VERSION); 112 version_value = (uint32_t) (GNUNET_MESSENGER_VERSION);
104 version_value = ((version_value >> 16) & 0xFFFF); 113 version_value = ((version_value >> 16) & 0xFFFF);
105 version_value = GNUNET_htole32(version_value); 114 version_value = GNUNET_htole32 (version_value);
106 GNUNET_CRYPTO_hash(&version_value, sizeof(version_value), &version); 115 GNUNET_CRYPTO_hash (&version_value, sizeof(version_value), &version);
107 } 116 }
108 117
109 GNUNET_CRYPTO_hash_sum(key, &version, port); 118 GNUNET_CRYPTO_hash_sum (key, &version, port);
110} 119}
111 120
121
112void 122void
113convert_peer_identity_to_id(const struct GNUNET_PeerIdentity *identity, 123convert_peer_identity_to_id (const struct GNUNET_PeerIdentity *identity,
114 struct GNUNET_ShortHashCode *id) 124 struct GNUNET_ShortHashCode *id)
115{ 125{
116 GNUNET_memcpy(id, identity, sizeof(struct GNUNET_ShortHashCode)); 126 GNUNET_memcpy (id, identity, sizeof(struct GNUNET_ShortHashCode));
117} 127}