GNUnet  0.11.x
gnunet-service-messenger_service.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020 GNUnet e.V.
4 
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
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
27 
29 
32 
33 static void
35 {
36  struct GNUNET_MESSENGER_Service *service = cls;
37 
38  if (service)
39  {
40  service->shutdown = NULL;
41 
42  destroy_service (service);
43  }
44 }
45 
46 static void
48  struct GNUNET_IDENTITY_Ego *ego,
49  void **ctx,
50  const char *identifier)
51 {
52  if ((!ego) || (!identifier))
53  return;
54 
55  struct GNUNET_MESSENGER_Service *service = cls;
56 
58 }
59 
62 {
64 
65  service->config = config;
66  service->service = service_handle;
67 
69 
70  service->dir = NULL;
71 
74  "MESSENGER_DIR", &(service->dir)))
75  {
76  if (service->dir)
77  GNUNET_free(service->dir);
78 
79  service->dir = NULL;
80  }
81  else
82  {
84  != GNUNET_DISK_directory_create (service->dir)))
85  {
86  GNUNET_free(service->dir);
87 
88  service->dir = NULL;
89  }
90  }
91 
92  service->cadet = GNUNET_CADET_connect (service->config);
93  service->identity = GNUNET_IDENTITY_connect (service->config, &callback_update_ego, service);
94 
96 
97  init_list_handles (&(service->handles));
98 
101 
102  return service;
103 }
104 
105 static int
106 iterate_destroy_egos (void *cls, const struct GNUNET_HashCode *key, void *value)
107 {
108  struct GNUNET_MESSENGER_Ego *ego = value;
109  GNUNET_free(ego);
110  return GNUNET_YES;
111 }
112 
113 static int
114 iterate_destroy_rooms (void *cls, const struct GNUNET_HashCode *key, void *value)
115 {
116  struct GNUNET_MESSENGER_SrvRoom *room = value;
117  destroy_room (room);
118  return GNUNET_YES;
119 }
120 
121 static int
122 iterate_destroy_contacts (void *cls, const struct GNUNET_HashCode *key, void *value)
123 {
124  struct GNUNET_MESSENGER_SrvContact *contact = value;
125  destroy_contact (contact);
126  return GNUNET_YES;
127 }
128 
129 void
131 {
132  if (service->shutdown)
133  {
135 
136  service->shutdown = NULL;
137  }
138 
140 
141  clear_list_handles (&(service->handles));
142 
145 
149 
150  if (service->cadet)
151  {
152  GNUNET_CADET_disconnect (service->cadet);
153 
154  service->cadet = NULL;
155  }
156 
157  if (service->identity)
158  {
160 
161  service->identity = NULL;
162  }
163 
164  if (service->dir)
165  {
166  GNUNET_free(service->dir);
167 
168  service->dir = NULL;
169  }
170 
171  GNUNET_SERVICE_shutdown (service->service);
172 
173  GNUNET_free(service);
174 }
175 
176 struct GNUNET_MESSENGER_Ego*
177 lookup_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier)
178 {
179  GNUNET_assert(identifier);
180 
181  struct GNUNET_HashCode hash;
182 
183  GNUNET_CRYPTO_hash(identifier, strlen(identifier), &hash);
184  return GNUNET_CONTAINER_multihashmap_get(service->egos, &hash);
185 }
186 
187 void
188 update_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier,
189  const struct GNUNET_IDENTITY_PrivateKey* key)
190 {
191  GNUNET_assert((identifier) && (key));
192 
193  struct GNUNET_HashCode hash;
194 
195  GNUNET_CRYPTO_hash(identifier, strlen(identifier), &hash);
196 
197  struct GNUNET_MESSENGER_Ego* ego = GNUNET_CONTAINER_multihashmap_get(service->egos, &hash);
198 
199  if (!ego)
200  {
201  ego = GNUNET_new(struct GNUNET_MESSENGER_Ego);
203  }
204 
205  GNUNET_memcpy(&(ego->priv), key, sizeof(*key));
206 
207  if (GNUNET_OK != GNUNET_IDENTITY_key_get_public(key, &(ego->pub)))
208  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating invalid ego key failed!\n");
209 }
210 
213 {
214  struct GNUNET_MESSENGER_SrvHandle *handle = create_handle (service, mq);
215 
216  if (handle)
217  {
218  add_list_handle (&(service->handles), handle);
219  }
220 
221  return handle;
222 }
223 
224 void
226 {
227  if (!handle)
228  return;
229 
230  if (GNUNET_YES == remove_list_handle (&(service->handles), handle))
231  destroy_handle (handle);
232 }
233 
234 int
236 {
237  return GNUNET_CRYPTO_get_peer_identity (service->config, peer);
238 }
239 
242 {
243  struct GNUNET_HashCode hash;
244 
245  GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
246 
247  struct GNUNET_MESSENGER_SrvContact *contact = GNUNET_CONTAINER_multihashmap_get (service->contacts, &hash);
248 
249  if (contact)
250  return contact;
251 
252  contact = create_contact (pubkey);
253 
254  if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->contacts, &hash, contact,
256  return contact;
257 
258  destroy_contact (contact);
259  return NULL;
260 }
261 
262 void
264  const struct GNUNET_IDENTITY_PublicKey *pubkey)
265 {
266  const struct GNUNET_HashCode *hash = get_contact_id_from_key (contact);
267 
268  if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (service->contacts, hash, contact))
269  {
270  GNUNET_memcpy(&(contact->public_key), pubkey, sizeof(*pubkey));
271 
272  hash = get_contact_id_from_key (contact);
273 
274  GNUNET_CONTAINER_multihashmap_put (service->contacts, hash, contact,
276  }
277 }
278 
279 struct GNUNET_ShortHashCode*
281 {
282  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
283 
284  if (room)
285  {
286  return generate_room_member_id (room);
287  }
288  else
289  {
290  struct GNUNET_ShortHashCode *random_id = GNUNET_new(struct GNUNET_ShortHashCode);
291  generate_free_member_id (random_id, NULL);
292  return random_id;
293  }
294 }
295 
298 {
299  return GNUNET_CONTAINER_multihashmap_get (service->rooms, key);
300 }
301 
302 int
304  const struct GNUNET_HashCode *key)
305 {
306  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
307 
308  if (room)
309  return open_room (room, handle);
310 
311  room = create_room (handle, key);
312 
313  if ((GNUNET_YES == open_room (room, handle)) && (GNUNET_OK
315  return GNUNET_YES;
316 
317  destroy_room (room);
318  return GNUNET_NO;
319 }
320 
321 int
323  const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
324 {
325  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
326 
327  if (room)
328  {
329  if (GNUNET_YES == entry_room_at (room, handle, door))
330  return GNUNET_YES;
331  else
332  return GNUNET_NO;
333  }
334 
335  room = create_room (handle, key);
336 
337  if ((GNUNET_YES == entry_room_at (room, handle, door)) && (GNUNET_OK
339  {
340  return GNUNET_YES;
341  }
342  else
343  {
344  destroy_room (room);
345  return GNUNET_NO;
346  }
347 
348 }
349 
350 int
352  const struct GNUNET_HashCode *key)
353 {
354  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
355 
356  if (!room)
357  return GNUNET_NO;
358 
359  struct GNUNET_MESSENGER_Message *message = create_message_leave ();
360 
361  if (message)
362  {
363  struct GNUNET_HashCode hash;
364 
365  send_room_message (room, handle, message, &hash);
366  destroy_message (message);
367  }
368 
369  const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, key);
370 
371  GNUNET_assert(id);
372 
374  return GNUNET_NO;
375 
377  &(service->handles), key);
378 
379  if (!member_handle)
380  {
381  if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key, room))
382  {
383  destroy_room (room);
384  return GNUNET_YES;
385  }
386  else
387  return GNUNET_NO;
388  }
389 
390  if (room->host == handle)
391  room->host = member_handle;
392 
393  return GNUNET_YES;
394 }
395 
396 static void
398 {
399  GNUNET_asprintf (dir, "%s%s%c%s%c", service->dir, "rooms", DIR_SEPARATOR, GNUNET_h2s (&(room->key)), DIR_SEPARATOR);
400 }
401 
402 void
404 {
405  char *room_dir;
406  get_room_data_subdir (service, room, &room_dir);
407 
409  {
410  load_message_store (&room->store, room_dir);
411 
412  char *config_file;
413  GNUNET_asprintf (&config_file, "%s%s", room_dir, "room.cfg");
414 
416 
417  if ((GNUNET_YES == GNUNET_DISK_file_test (config_file)) && (GNUNET_OK
418  == GNUNET_CONFIGURATION_parse (cfg, config_file)))
419  {
420  unsigned long long access;
421 
422  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "room", "access-rule", &access))
423  room->strict_access = (int) (access);
424 
425  char *message_string;
426 
427  if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "room", "last-message", &message_string)) && (message_string))
428  {
429  struct GNUNET_HashCode hash;
430 
431  GNUNET_CRYPTO_hash_from_string(message_string, &hash);
432 
433  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, room->host, &hash, GNUNET_NO);
434 
435  if (message)
436  update_room_last_messages (room, message, &hash);
437 
438  GNUNET_free(message_string);
439  }
440  }
441 
443 
444  GNUNET_free(config_file);
445  }
446 
447  GNUNET_free(room_dir);
448 }
449 
450 void
452 {
453  if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (service->rooms, &(room->key)))
454  {
455  return;
456  }
457 
458  char *room_dir;
459  get_room_data_subdir (service, room, &room_dir);
460 
462  == GNUNET_DISK_directory_create (room_dir)))
463  {
464  save_message_store (&room->store, room_dir);
465 
466  char *config_file;
467  GNUNET_asprintf (&config_file, "%s%s", room_dir, "room.cfg");
468 
470 
471  GNUNET_CONFIGURATION_set_value_number (cfg, "room", "access-rule", room->strict_access);
472 
473  if (room->last_messages.head)
474  GNUNET_CONFIGURATION_set_value_string (cfg, "room", "last-message",
475  GNUNET_h2s_full (&(room->last_messages.head->hash)));
476 
477  GNUNET_CONFIGURATION_write (cfg, config_file);
479 
480  GNUNET_free(config_file);
481  }
482 
483  GNUNET_free(room_dir);
484 }
485 
486 void
488  const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
489 {
490  struct GNUNET_MESSENGER_ListHandle *element = service->handles.head;
491 
492  const uint16_t length = get_message_size (message);
493 
494  while (element)
495  {
497 
498  if ((handle->mq) && (get_handle_member_id (handle, &(room->key))))
499  {
501  struct GNUNET_MQ_Envelope *env;
502 
504 
505  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
506  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
507 
508  char *buffer = ((char*) msg) + sizeof(*msg);
509  encode_message (message, length, buffer);
510 
511  GNUNET_MQ_send (handle->mq, env);
512  }
513 
514  element = element->next;
515  }
516 }
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:610
int open_room(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
Tries to open a room for a given handle.
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:544
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:775
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
GNUnet MESSENGER service.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_MESSENGER_Ego * lookup_service_ego(struct GNUNET_MESSENGER_Service *service, const char *identifier)
Lookups an EGO which was registered to a service under a specific identifier.
int GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
struct GNUNET_CADET_Handle * cadet
struct GNUNET_MESSENGER_ListMessage * head
int entry_service_room(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Tries to enter a room using a given key for a service by a specific handle.
GNUnet MESSENGER service.
void save_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Saves messages from a message store into a directory.
Handle to a service.
Definition: service.c:116
int open_service_room(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Tries to open a room using a given key for a service by a specific handle.
struct GNUNET_MESSENGER_ListHandles handles
static void callback_update_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
int GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:589
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
void destroy_contact(struct GNUNET_MESSENGER_SrvContact *contact)
Destroys a contact and frees its memory fully.
int get_service_peer_identity(const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer)
Tries to write the peer identity of the peer running a service on to the peer parameter.
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void get_room_data_subdir(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, char **dir)
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
static void callback_shutdown_service(void *cls)
struct GNUNET_MESSENGER_SrvContact * create_contact(const struct GNUNET_IDENTITY_PublicKey *key)
Creates and allocates a new contact with a given public key from an EGO.
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
void update_room_last_messages(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Updates the last messages of a room by replacing them if the previous hash of a given message matches...
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message)
Returns the exact size in bytes to encode a given message.
struct GNUNET_ShortHashCode * generate_service_new_member_id(struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Tries to generate and allocate a new unique member id for a given room of a service identified by its...
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
Encodes a given message into a buffer of a maximal length in bytes.
void load_service_room_and_messages(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room)
Loads the local configuration for a given room of a service which contains the last messages hash and...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
int close_service_room(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Tries to close a room using a given key for a service by a specific handle.
int GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment...
void swap_service_contact_by_pubkey(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvContact *contact, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Changes the public key for a contact known to a service to a specific public key and updates local ma...
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
GNUnet MESSENGER service.
struct GNUNET_MESSENGER_SrvHandle * add_service_handle(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq)
Creates and adds a new handle to a service using a given message queue.
struct GNUNET_MESSENGER_ListHandle * next
void add_list_handle(struct GNUNET_MESSENGER_ListHandles *handles, void *handle)
Adds a specific handle to the end of the list.
void save_service_room_and_messages(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room)
Saves the configuration for a given room of a service which contains the last messages hash and the r...
struct GNUNET_SCHEDULER_Task * shutdown
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:910
A 256-bit hashcode.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
Handle for an ego.
Definition: identity.h:36
struct GNUNET_MESSENGER_ListMessages last_messages
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_ShortHashCode * generate_room_member_id(const struct GNUNET_MESSENGER_SrvRoom *room)
Tries to generate and allocate a new unique member id checking all current members for possible dupli...
static char * value
Value of the record to add/remove.
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_CONTAINER_MultiHashMap * rooms
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void load_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Loads messages from a directory into a message store.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static const struct GNUNET_CONFIGURATION_Handle * config
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:175
struct GNUNET_MESSENGER_SrvRoom * get_service_room(struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Returns the room identified by a given key for a service.
struct GNUNET_SERVICE_Handle * service
A 512-bit hashcode.
static int iterate_destroy_egos(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * egos
void update_service_ego(struct GNUNET_MESSENGER_Service *service, const char *identifier, const struct GNUNET_IDENTITY_PrivateKey *key)
Updates the registration of an EGO to a service under a specific identifier with a new key...
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
void clear_list_handles(struct GNUNET_MESSENGER_ListHandles *handles)
Destroys remaining handles and clears the list.
#define DIR_SEPARATOR
Definition: platform.h:170
static int iterate_destroy_contacts(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
void init_list_handles(struct GNUNET_MESSENGER_ListHandles *handles)
Initializes list of handles as empty list.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_MESSENGER_SrvHandle * host
void remove_service_handle(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle)
Removes a handle from a service and destroys it.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void destroy_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
void send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
Sends a message from a given handle into a room.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_MESSENGER_SrvContact * get_service_contact_by_pubkey(struct GNUNET_MESSENGER_Service *service, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Returns a contact of a service identified by a given public key.
struct GNUNET_MESSENGER_Message * create_message_leave()
Creates and allocates a new leave message.
#define GNUNET_MESSENGER_SERVICE_NAME
const struct GNUNET_HashCode * get_contact_id_from_key(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the resulting hashcode of the public key from a given contact.
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
Handle to a message queue.
Definition: mq.c:85
const struct GNUNET_CONFIGURATION_Handle * config
struct GNUNET_MESSENGER_SrvRoom * create_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key.
struct GNUNET_IDENTITY_PublicKey public_key
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CONTAINER_MultiHashMap * contacts
struct GNUNET_MESSENGER_SrvHandle * create_handle(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq)
Creates and allocates a new handle related to a service and using a given mq (message queue)...
An identity key as per LSD0001.
configuration data
Definition: configuration.c:84
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
static int iterate_destroy_rooms(void *cls, const struct GNUNET_HashCode *key, void *value)
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_CONTAINER_MultiHashMap * member_ids
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
struct GNUNET_IDENTITY_PrivateKey priv
int GNUNET_CRYPTO_get_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
Retrieve the identity of the host&#39;s peer.
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
struct GNUNET_MESSENGER_Service * create_service(const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle)
Creates and allocates a new service using a given config and a GNUnet service handle.
void destroy_service(struct GNUNET_MESSENGER_Service *service)
Destroys a service and frees its memory fully.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
struct GNUNET_MESSENGER_ListHandle * head
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Message to receive something from a room.
#define GNUNET_CRYPTO_hash_from_string(enc, result)
Convert ASCII encoding back to struct GNUNET_HashCode
int remove_list_handle(struct GNUNET_MESSENGER_ListHandles *handles, void *handle)
Removes the first entry matching with a specific handle from the list and returns GNUNET_YES on succe...
int generate_free_member_id(struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members)
Tries to generate an unused member id and store it into the id parameter.
int entry_room_at(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door)
Connects a tunnel to a hosting peer of a room through a so called door which is represented by a peer...
struct GNUNET_IDENTITY_Handle * identity
GNUnet MESSENGER service.
struct GNUNET_MESSENGER_MessageStore store
#define GNUNET_free(ptr)
Wrapper around free.
void handle_service_message(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Sends a received or sent message with a given hash to each handle of a service which is currently mem...
void GNUNET_SERVICE_shutdown(struct GNUNET_SERVICE_Handle *sh)
Explicitly stops the service.
Definition: service.c:2384
void * find_list_handle_by_member(struct GNUNET_MESSENGER_ListHandles *handles, const struct GNUNET_HashCode *key)
Searches linearly through the list of handles for members of a specific room which is identified by a...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972