aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api_handle.c')
-rw-r--r--src/messenger/messenger_api_handle.c80
1 files changed, 50 insertions, 30 deletions
diff --git a/src/messenger/messenger_api_handle.c b/src/messenger/messenger_api_handle.c
index abede8e21..7d5b55a06 100644
--- a/src/messenger/messenger_api_handle.c
+++ b/src/messenger/messenger_api_handle.c
@@ -34,9 +34,10 @@ create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg,
34 GNUNET_MESSENGER_MessageCallback msg_callback, 34 GNUNET_MESSENGER_MessageCallback msg_callback,
35 void *msg_cls) 35 void *msg_cls)
36{ 36{
37 GNUNET_assert(cfg); 37 GNUNET_assert (cfg);
38 38
39 struct GNUNET_MESSENGER_Handle *handle = GNUNET_new(struct GNUNET_MESSENGER_Handle); 39 struct GNUNET_MESSENGER_Handle *handle = GNUNET_new (struct
40 GNUNET_MESSENGER_Handle);
40 41
41 handle->cfg = cfg; 42 handle->cfg = cfg;
42 handle->mq = NULL; 43 handle->mq = NULL;
@@ -53,11 +54,12 @@ create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg,
53 54
54 handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); 55 handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
55 56
56 init_contact_store(get_handle_contact_store(handle)); 57 init_contact_store (get_handle_contact_store (handle));
57 58
58 return handle; 59 return handle;
59} 60}
60 61
62
61static int 63static int
62iterate_destroy_room (void *cls, 64iterate_destroy_room (void *cls,
63 const struct GNUNET_HashCode *key, 65 const struct GNUNET_HashCode *key,
@@ -70,10 +72,11 @@ iterate_destroy_room (void *cls,
70 return GNUNET_YES; 72 return GNUNET_YES;
71} 73}
72 74
75
73void 76void
74destroy_handle (struct GNUNET_MESSENGER_Handle *handle) 77destroy_handle (struct GNUNET_MESSENGER_Handle *handle)
75{ 78{
76 GNUNET_assert(handle); 79 GNUNET_assert (handle);
77 80
78 if (handle->reconnect_task) 81 if (handle->reconnect_task)
79 GNUNET_SCHEDULER_cancel (handle->reconnect_task); 82 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
@@ -82,26 +85,28 @@ destroy_handle (struct GNUNET_MESSENGER_Handle *handle)
82 GNUNET_MQ_destroy (handle->mq); 85 GNUNET_MQ_destroy (handle->mq);
83 86
84 if (handle->name) 87 if (handle->name)
85 GNUNET_free(handle->name); 88 GNUNET_free (handle->name);
86 89
87 if (handle->key) 90 if (handle->key)
88 GNUNET_free(handle->key); 91 GNUNET_free (handle->key);
89 92
90 if (handle->pubkey) 93 if (handle->pubkey)
91 GNUNET_free(handle->pubkey); 94 GNUNET_free (handle->pubkey);
92 95
93 if (handle->rooms) 96 if (handle->rooms)
94 { 97 {
95 GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_destroy_room, NULL); 98 GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_destroy_room,
99 NULL);
96 100
97 GNUNET_CONTAINER_multihashmap_destroy (handle->rooms); 101 GNUNET_CONTAINER_multihashmap_destroy (handle->rooms);
98 } 102 }
99 103
100 clear_contact_store(get_handle_contact_store(handle)); 104 clear_contact_store (get_handle_contact_store (handle));
101 105
102 GNUNET_free(handle); 106 GNUNET_free (handle);
103} 107}
104 108
109
105void 110void
106set_handle_name (struct GNUNET_MESSENGER_Handle *handle, 111set_handle_name (struct GNUNET_MESSENGER_Handle *handle,
107 const char *name) 112 const char *name)
@@ -114,21 +119,23 @@ set_handle_name (struct GNUNET_MESSENGER_Handle *handle,
114 handle->name = name ? GNUNET_strdup (name) : NULL; 119 handle->name = name ? GNUNET_strdup (name) : NULL;
115} 120}
116 121
122
117const char* 123const char*
118get_handle_name (const struct GNUNET_MESSENGER_Handle *handle) 124get_handle_name (const struct GNUNET_MESSENGER_Handle *handle)
119{ 125{
120 GNUNET_assert(handle); 126 GNUNET_assert (handle);
121 127
122 return handle->name; 128 return handle->name;
123} 129}
124 130
131
125void 132void
126set_handle_key (struct GNUNET_MESSENGER_Handle *handle, 133set_handle_key (struct GNUNET_MESSENGER_Handle *handle,
127 const struct GNUNET_IDENTITY_PrivateKey *key) 134 const struct GNUNET_IDENTITY_PrivateKey *key)
128{ 135{
129 GNUNET_assert (handle); 136 GNUNET_assert (handle);
130 137
131 if (!key) 138 if (! key)
132 { 139 {
133 if (handle->key) 140 if (handle->key)
134 GNUNET_free (handle->key); 141 GNUNET_free (handle->key);
@@ -141,31 +148,33 @@ set_handle_key (struct GNUNET_MESSENGER_Handle *handle,
141 return; 148 return;
142 } 149 }
143 150
144 if (!handle->key) 151 if (! handle->key)
145 handle->key = GNUNET_new (struct GNUNET_IDENTITY_PrivateKey); 152 handle->key = GNUNET_new (struct GNUNET_IDENTITY_PrivateKey);
146 153
147 if (!handle->pubkey) 154 if (! handle->pubkey)
148 handle->pubkey = GNUNET_new (struct GNUNET_IDENTITY_PublicKey); 155 handle->pubkey = GNUNET_new (struct GNUNET_IDENTITY_PublicKey);
149 156
150 GNUNET_memcpy (handle->key, key, sizeof(*key)); 157 GNUNET_memcpy (handle->key, key, sizeof(*key));
151 GNUNET_IDENTITY_key_get_public (key, handle->pubkey); 158 GNUNET_IDENTITY_key_get_public (key, handle->pubkey);
152} 159}
153 160
161
154const struct GNUNET_IDENTITY_PrivateKey* 162const struct GNUNET_IDENTITY_PrivateKey*
155get_handle_key (const struct GNUNET_MESSENGER_Handle *handle) 163get_handle_key (const struct GNUNET_MESSENGER_Handle *handle)
156{ 164{
157 GNUNET_assert(handle); 165 GNUNET_assert (handle);
158 166
159 if (handle->key) 167 if (handle->key)
160 return handle->key; 168 return handle->key;
161 169
162 return get_anonymous_private_key(); 170 return get_anonymous_private_key ();
163} 171}
164 172
173
165const struct GNUNET_IDENTITY_PublicKey* 174const struct GNUNET_IDENTITY_PublicKey*
166get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle) 175get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle)
167{ 176{
168 GNUNET_assert(handle); 177 GNUNET_assert (handle);
169 178
170 if (handle->pubkey) 179 if (handle->pubkey)
171 return handle->pubkey; 180 return handle->pubkey;
@@ -173,28 +182,31 @@ get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle)
173 return get_anonymous_public_key (); 182 return get_anonymous_public_key ();
174} 183}
175 184
185
176struct GNUNET_MESSENGER_ContactStore* 186struct GNUNET_MESSENGER_ContactStore*
177get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle) 187get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle)
178{ 188{
179 GNUNET_assert(handle); 189 GNUNET_assert (handle);
180 190
181 return &(handle->contact_store); 191 return &(handle->contact_store);
182} 192}
183 193
194
184struct GNUNET_MESSENGER_Contact* 195struct GNUNET_MESSENGER_Contact*
185get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, 196get_handle_contact (struct GNUNET_MESSENGER_Handle *handle,
186 const struct GNUNET_HashCode *key) 197 const struct GNUNET_HashCode *key)
187{ 198{
188 GNUNET_assert((handle) && (key)); 199 GNUNET_assert ((handle) && (key));
189 200
190 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 201 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
202 handle->rooms, key);
191 203
192 if (!room) 204 if (! room)
193 return NULL; 205 return NULL;
194 206
195 const struct GNUNET_ShortHashCode *contact_id = get_room_sender_id (room); 207 const struct GNUNET_ShortHashCode *contact_id = get_room_sender_id (room);
196 208
197 if (!contact_id) 209 if (! contact_id)
198 return NULL; 210 return NULL;
199 211
200 struct GNUNET_HashCode context; 212 struct GNUNET_HashCode context;
@@ -204,48 +216,56 @@ get_handle_contact (struct GNUNET_MESSENGER_Handle *handle,
204 get_handle_pubkey (handle)); 216 get_handle_pubkey (handle));
205} 217}
206 218
219
207void 220void
208open_handle_room (struct GNUNET_MESSENGER_Handle *handle, 221open_handle_room (struct GNUNET_MESSENGER_Handle *handle,
209 const struct GNUNET_HashCode *key) 222 const struct GNUNET_HashCode *key)
210{ 223{
211 GNUNET_assert((handle) && (key)); 224 GNUNET_assert ((handle) && (key));
212 225
213 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 226 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
227 handle->rooms, key);
214 228
215 if (room) 229 if (room)
216 room->opened = GNUNET_YES; 230 room->opened = GNUNET_YES;
217} 231}
218 232
233
219void 234void
220entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, 235entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle,
221 const struct GNUNET_PeerIdentity *door, 236 const struct GNUNET_PeerIdentity *door,
222 const struct GNUNET_HashCode *key) 237 const struct GNUNET_HashCode *key)
223{ 238{
224 GNUNET_assert((handle) && (door) && (key)); 239 GNUNET_assert ((handle) && (door) && (key));
225 240
226 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 241 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
242 handle->rooms, key);
227 243
228 if (room) 244 if (room)
229 add_to_list_tunnels (&(room->entries), door, NULL); 245 add_to_list_tunnels (&(room->entries), door, NULL);
230} 246}
231 247
248
232void 249void
233close_handle_room (struct GNUNET_MESSENGER_Handle *handle, 250close_handle_room (struct GNUNET_MESSENGER_Handle *handle,
234 const struct GNUNET_HashCode *key) 251 const struct GNUNET_HashCode *key)
235{ 252{
236 GNUNET_assert((handle) && (key)); 253 GNUNET_assert ((handle) && (key));
237 254
238 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 255 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
256 handle->rooms, key);
239 257
240 if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room))) 258 if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (
259 handle->rooms, key, room)))
241 destroy_room (room); 260 destroy_room (room);
242} 261}
243 262
263
244struct GNUNET_MESSENGER_Room* 264struct GNUNET_MESSENGER_Room*
245get_handle_room (struct GNUNET_MESSENGER_Handle *handle, 265get_handle_room (struct GNUNET_MESSENGER_Handle *handle,
246 const struct GNUNET_HashCode *key) 266 const struct GNUNET_HashCode *key)
247{ 267{
248 GNUNET_assert((handle) && (key)); 268 GNUNET_assert ((handle) && (key));
249 269
250 return GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 270 return GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
251} 271}