GNUnet  0.19.4
gnunet-service-messenger_handle.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020--2022 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  */
26 #include "platform.h"
28 
31 
32 #include "messenger_api_util.h"
33 
36  struct GNUNET_MQ_Handle *mq)
37 {
38  GNUNET_assert((service) && (mq));
39 
41 
42  handle->service = service;
43  handle->mq = mq;
44 
45  handle->name = NULL;
46  handle->ego = NULL;
47 
49 
50  return handle;
51 }
52 
53 int
55  const struct GNUNET_HashCode *key,
56  void *value)
57 {
59 
60  return GNUNET_YES;
61 }
62 
63 void
65 {
67 
68  if (handle->service->dir)
70 
71  if (handle->name)
72  {
73  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
74 
75  unbind_store_ego(store, handle->name, handle);
76 
77  GNUNET_free(handle->name);
78  }
79 
82 
84 }
85 
86 void
88  const char *name,
89  char **dir)
90 {
91  GNUNET_assert((handle) && (dir));
92 
93  if (name)
94  GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities",
96  else
97  GNUNET_asprintf (dir, "%s%s%c", handle->service->dir, "anonymous",
99 }
100 
101 static int
103  const struct GNUNET_HashCode *key)
104 {
105  GNUNET_assert((handle) && (key));
106 
107  struct GNUNET_ShortHashCode *random_id = GNUNET_new(struct GNUNET_ShortHashCode);
108 
109  if (!random_id)
110  return GNUNET_NO;
111 
112  generate_free_member_id (random_id, NULL);
113 
114  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, random_id,
116  {
117  GNUNET_free(random_id);
118  return GNUNET_NO;
119  }
120 
121  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Created a new member id (%s) for room: %s\n", GNUNET_sh2s (random_id),
122  GNUNET_h2s (key));
123 
124  return GNUNET_YES;
125 }
126 
127 const struct GNUNET_ShortHashCode*
129  const struct GNUNET_HashCode *key)
130 {
131  GNUNET_assert((handle) && (key));
132 
133  return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key);
134 }
135 
136 int
138  const struct GNUNET_HashCode *key,
139  const struct GNUNET_ShortHashCode *unique_id)
140 {
141  GNUNET_assert((handle) && (key) && (unique_id));
142 
143  struct GNUNET_ShortHashCode *member_id = GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key);
144 
145  if (!member_id)
146  {
147  member_id = GNUNET_new(struct GNUNET_ShortHashCode);
148  GNUNET_memcpy(member_id, unique_id, sizeof(*member_id));
149 
150  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, member_id,
152  {
153  GNUNET_free(member_id);
154  return GNUNET_SYSERR;
155  }
156  }
157 
158  if (0 == GNUNET_memcmp(unique_id, member_id))
159  goto send_message_to_client;
160 
161  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Change a member id (%s) for room (%s).\n", GNUNET_sh2s (member_id),
162  GNUNET_h2s (key));
163 
164  GNUNET_memcpy(member_id, unique_id, sizeof(*unique_id));
165 
166  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member id changed to (%s).\n", GNUNET_sh2s (unique_id));
167 
169  struct GNUNET_MQ_Envelope *env;
170 
171 send_message_to_client:
172 
174 
175  GNUNET_memcpy(&(msg->key), key, sizeof(*key));
176  GNUNET_memcpy(&(msg->id), member_id, sizeof(*member_id));
177 
179  return GNUNET_OK;
180 }
181 
182 static void
184  const char *name)
185 {
187 
188  if (handle->name)
189  GNUNET_free(handle->name);
190 
191  handle->name = name ? GNUNET_strdup(name) : NULL;
192 
193  const uint16_t name_len = handle->name ? strlen (handle->name) : 0;
194 
196  struct GNUNET_MQ_Envelope *env;
197 
199 
200  char *extra = ((char*) msg) + sizeof(*msg);
201 
202  if (name_len)
203  GNUNET_memcpy(extra, handle->name, name_len);
204 
205  extra[name_len] = '\0';
206 
208 }
209 
210 static void
212  const struct GNUNET_MESSENGER_Ego *ego)
213 {
215 
216  handle->ego = ego;
217 
218  ego = get_srv_handle_ego (handle);
219 
220  const uint16_t length = GNUNET_IDENTITY_public_key_get_length(&(ego->pub));
221 
223  struct GNUNET_MQ_Envelope *env;
224 
226 
227  char *extra = ((char*) msg) + sizeof(*msg);
228 
229  if (GNUNET_IDENTITY_write_public_key_to_buffer(&(ego->pub), extra, length) < 0)
230  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Could not write key to buffer.\n");
231 
233 }
234 
236 {
239 };
240 
241 static int
243  const struct GNUNET_HashCode *key,
244  void *value)
245 {
246  struct GNUNET_MESSENGER_MessageHandle *msg_handle = cls;
247 
248  send_srv_handle_message (msg_handle->handle, key, msg_handle->message);
249 
250  return GNUNET_YES;
251 }
252 
253 void
255  const struct GNUNET_MESSENGER_Ego *ego)
256 {
257  GNUNET_assert((handle) && (ego));
258 
259  struct GNUNET_MESSENGER_MessageHandle msg_handle;
260 
261  msg_handle.handle = handle;
262  msg_handle.message = create_message_key (&(ego->priv));
263 
265 
266  destroy_message (msg_handle.message);
267 
268  change_handle_ego (handle, ego);
269 }
270 
271 const struct GNUNET_MESSENGER_Ego*
273 {
275 
276  static struct GNUNET_MESSENGER_Ego anonymous;
277  static int read_keys = 0;
278 
279  if (handle->ego)
280  return handle->ego;
281 
282  if (!read_keys)
283  {
285  GNUNET_memcpy(&(anonymous.priv), GNUNET_IDENTITY_ego_get_private_key (ego), sizeof(anonymous.priv));
286  GNUNET_IDENTITY_ego_get_public_key (ego, &(anonymous.pub));
287  read_keys = 1;
288  }
289 
290  return &anonymous;
291 }
292 
293 static void
295  const char *name,
296  const struct GNUNET_MESSENGER_Ego *ego)
297 {
298  struct GNUNET_MESSENGER_SrvHandle *handle = cls;
299 
300  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Setting up handle...\n");
301 
304 
305  if (handle->service->dir)
307 }
308 
309 void
311  const char *name)
312 {
314 
315  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
316 
318 }
319 
320 static void
322  const char *name,
323  const struct GNUNET_MESSENGER_Ego *ego)
324 {
325  struct GNUNET_MESSENGER_SrvHandle *handle = cls;
326 
327  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating handle...\n");
328 
329  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
330 
331  bind_store_ego(store, handle->name, handle);
332 
333  if (!ego)
334  create_store_ego (store, handle->name);
335  else
336  renew_store_ego (store, handle->name);
337 }
338 
339 void
341 {
343 
344  if (!handle->name)
345  {
346  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Updating handle failed: Name is required!\n");
347  return;
348  }
349 
350  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
351 
353 }
354 
355 static void
357  const char *name,
358  const struct GNUNET_MESSENGER_Ego *ego)
359 {
360  struct GNUNET_MESSENGER_SrvHandle *handle = cls;
361 
362  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Renaming handle...\n");
363 
364  if (ego)
365  {
366  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Renaming handle failed: Name is occupied! (%s)\n", name);
367  return;
368  }
369 
370  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
371 
372  char *old_dir;
373  get_srv_handle_data_subdir (handle, handle->name, &old_dir);
374 
375  char *new_dir;
377 
378  if ((GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO)) &&
380  goto free_dirs;
381 
383  {
385 
386  if (0 != rename (old_dir, new_dir))
387  goto free_dirs;
388  }
389 
390  if (handle->ego)
391  rename_store_ego(store, handle->name, name);
392 
393  struct GNUNET_MESSENGER_MessageHandle msg_handle;
394  msg_handle.handle = handle;
395  msg_handle.message = create_message_name (name);
396 
398  destroy_message (msg_handle.message);
400 
401 free_dirs:
402  GNUNET_free(old_dir);
403  GNUNET_free(new_dir);
404 }
405 
406 void
408  const char *name)
409 {
411 
412  if (!name)
413  {
414  if (handle->ego)
415  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Renaming handle failed: Name is required!\n");
416  else
418 
419  return;
420  }
421 
422  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
423 
425 }
426 
427 int
429  const struct GNUNET_HashCode *key)
430 {
431  GNUNET_assert((handle) && (key));
432 
434  return GNUNET_NO;
435 
436  return open_service_room (handle->service, handle, key);
437 }
438 
439 int
441  const struct GNUNET_PeerIdentity *door,
442  const struct GNUNET_HashCode *key)
443 {
444  GNUNET_assert((handle) && (door) && (key));
445 
447  return GNUNET_NO;
448 
449  return entry_service_room (handle->service, handle, door, key);
450 }
451 
452 int
454  const struct GNUNET_HashCode *key)
455 {
456  GNUNET_assert((handle) && (key));
457 
459  return GNUNET_NO;
460 
461  return close_service_room (handle->service, handle, key);
462 }
463 
464 int
466  const struct GNUNET_HashCode *key,
467  const struct GNUNET_MESSENGER_Message *message)
468 {
469  GNUNET_assert((handle) && (key) && (message));
470 
472 
473  if (!id)
474  {
475  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "It is required to be a member of a room to send messages!\n");
476  return GNUNET_NO;
477  }
478 
479  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, key);
480 
481  if (!room)
482  {
483  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n", GNUNET_h2s (key));
484  return GNUNET_NO;
485  }
486 
487  struct GNUNET_MESSENGER_Message *msg = copy_message(message);
488 
489  GNUNET_memcpy(&(msg->header.sender_id), id, sizeof(*id));
490 
491  return send_srv_room_message (room, handle, msg);
492 }
493 
494 static const struct GNUNET_HashCode*
496 {
497  if (session->next)
498  return get_next_member_session_contect (session->next);
499  else
500  return get_member_session_context(session);
501 }
502 
503 static const struct GNUNET_MESSENGER_MemberSession*
505  struct GNUNET_MESSENGER_SrvRoom *room,
506  const struct GNUNET_HashCode *key)
507 {
508  GNUNET_assert((handle) && (room) && (key) && (handle->service));
509 
511 
512  if (!id)
513  return NULL;
514 
516  struct GNUNET_MESSENGER_Member *member = get_store_member(store, id);
517 
518  const struct GNUNET_MESSENGER_Ego *ego = get_srv_handle_ego(handle);
519 
520  if (!ego)
521  return NULL;
522 
523  return get_member_session(member, &(ego->pub));
524 }
525 
526 void
528  struct GNUNET_MESSENGER_SrvRoom *room,
529  const struct GNUNET_MESSENGER_MemberSession *session,
530  const struct GNUNET_MESSENGER_Message *message,
531  const struct GNUNET_HashCode *hash)
532 {
533  GNUNET_assert((handle) && (room) && (session) && (message) && (hash));
534 
535  const struct GNUNET_HashCode *key = get_srv_room_key(room);
536 
537  if ((!handle->mq) || (!get_srv_handle_member_id (handle, key)))
538  {
539  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Notifying client about message requires membership!\n");
540  return;
541  }
542 
543  const struct GNUNET_IDENTITY_PublicKey *pubkey = get_contact_key(session->contact);
544 
545  struct GNUNET_HashCode sender;
546  GNUNET_CRYPTO_hash(pubkey, sizeof(*pubkey), &sender);
547 
548  const struct GNUNET_HashCode *context = get_next_member_session_contect (session);
549 
550  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Notifying client about message: %s\n", GNUNET_h2s (hash));
551 
552  struct GNUNET_MESSENGER_Message *private_message = NULL;
553 
554  if (GNUNET_MESSENGER_KIND_PRIVATE == message->header.kind)
555  {
556  private_message = copy_message(message);
557 
558  if (GNUNET_YES != decrypt_message(private_message, &(get_srv_handle_ego(handle)->priv)))
559  {
560  destroy_message(private_message);
561  private_message = NULL;
562  }
563  else
564  message = private_message;
565  }
566 
568  struct GNUNET_MQ_Envelope *env;
569 
570  uint16_t length = get_message_size (message, GNUNET_YES);
571 
573 
574  GNUNET_memcpy(&(msg->key), key, sizeof(msg->key));
575  GNUNET_memcpy(&(msg->sender), &sender, sizeof(msg->sender));
576  GNUNET_memcpy(&(msg->context), context, sizeof(msg->context));
577  GNUNET_memcpy(&(msg->hash), hash, sizeof(msg->hash));
578 
579  msg->flags = (uint32_t) GNUNET_MESSENGER_FLAG_NONE;
580 
581  if (get_handle_member_session(handle, room, key) == session)
582  msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_SENT;
583 
584  if (private_message)
585  msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_PRIVATE;
586 
587  char *buffer = ((char*) msg) + sizeof(*msg);
588  encode_message (message, length, buffer, GNUNET_YES);
589 
590  if (private_message)
591  destroy_message(private_message);
592 
594 }
595 
596 static int
598  const char *filename)
599 {
600  struct GNUNET_MESSENGER_SrvHandle *handle = cls;
601 
602  if ((strlen(filename) <= 4) || (0 != strcmp(filename + strlen(filename) - 4, ".cfg")))
603  return GNUNET_OK;
604 
605  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load room configuration of handle: %s\n", filename);
606 
608 
610  {
611  struct GNUNET_HashCode key;
612  struct GNUNET_ShortHashCode member_id;
613 
614  if ((GNUNET_OK == GNUNET_CONFIGURATION_get_data (cfg, "room", "key", &key, sizeof(key))) &&
615  (GNUNET_OK == GNUNET_CONFIGURATION_get_data (cfg, "room", "member_id", &member_id, sizeof(member_id))))
616  change_srv_handle_member_id (handle, &key, &member_id);
617  }
618 
620  return GNUNET_OK;
621 }
622 
623 void
625 {
627 
628  char *id_dir;
629  get_srv_handle_data_subdir (handle, handle->name, &id_dir);
630 
632  {
633  char *scan_dir;
634  GNUNET_asprintf (&scan_dir, "%s%s%c", id_dir, "rooms", DIR_SEPARATOR);
635 
638 
640  }
641 
642  GNUNET_free(id_dir);
643 }
644 
645 static int
647  const struct GNUNET_HashCode *key,
648  void *value)
649 {
650  struct GNUNET_MESSENGER_SrvHandle *handle = cls;
651  struct GNUNET_ShortHashCode *member_id = value;
652 
653  char *id_dir;
654  get_srv_handle_data_subdir (handle, handle->name, &id_dir);
655 
656  char *filename;
657  GNUNET_asprintf (&filename, "%s%s%c%s.cfg", id_dir, "rooms", DIR_SEPARATOR, GNUNET_h2s (key));
658  GNUNET_free(id_dir);
659 
660  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Save room configuration of handle: %s\n", filename);
661 
663 
664  char *key_data = GNUNET_STRINGS_data_to_string_alloc (key, sizeof(*key));
665 
666  if (key_data)
667  {
668  GNUNET_CONFIGURATION_set_value_string (cfg, "room", "key", key_data);
669 
670  GNUNET_free(key_data);
671  }
672 
673  char *member_id_data = GNUNET_STRINGS_data_to_string_alloc (member_id, sizeof(*member_id));
674 
675  if (member_id_data)
676  {
677  GNUNET_CONFIGURATION_set_value_string (cfg, "room", "member_id", member_id_data);
678 
679  GNUNET_free(member_id_data);
680  }
681 
684 
686 
687  return GNUNET_YES;
688 }
689 
690 void
692 {
694 
695  char *id_dir;
696  get_srv_handle_data_subdir (handle, handle->name, &id_dir);
697 
699  == GNUNET_DISK_directory_create (id_dir)))
700  {
701  char *save_dir;
702  GNUNET_asprintf (&save_dir, "%s%s%c", id_dir, "rooms", DIR_SEPARATOR);
703 
704  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
705  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
707 
708  GNUNET_free(save_dir);
709  }
710 
711  GNUNET_free(id_dir);
712 }
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static char * filename
static pa_context * context
Pulseaudio context.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
static char * value
Value of the record to add/remove.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
GNUnet MESSENGER service.
void renew_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier)
Replaces the registered EGO in a store under a specific identifier with a newly created one.
void bind_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, void *handle)
Binds an EGO which was registered to a store under a specific identifier to a given handle
void lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, GNUNET_MESSENGER_EgoLookupCallback lookup, void *cls)
Lookups an EGO which was registered to a store under a specific identifier.
void create_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier)
Creates a new EGO which will be registered to a store under a specific identifier.
void unbind_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, void *handle)
Binds an EGO which was registered to a store under a specific identifier to a given handle
void rename_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *old_identifier, const char *new_identifier)
Updates the location of a registered EGO in a store to a different one under a specific new_identifie...
int change_srv_handle_member_id(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *unique_id)
Changes the member id of a given handle in a specific room to match a unique_id and returns GNUNET_OK...
void save_srv_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle)
Saves member ids and other potential configuration from a given handle which depends on the given nam...
void notify_srv_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Notifies the handle that a new message was received or sent.
int close_srv_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Removes the membership of the room using a specific key and closes it if no other handle from this se...
void load_srv_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle)
Loads member ids and other potential configuration from a given handle which depends on the given nam...
static void callback_set_handle_name(void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego)
const struct GNUNET_ShortHashCode * get_srv_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.
void set_srv_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Ego *ego)
Sets the EGO used by a given handle.
static int create_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
int open_srv_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Makes a given handle a member of the room using a specific key and opens the room from the handles se...
void setup_srv_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
Tries to set the name and EGO key of a handle initially by looking up a specific name.
int entry_srv_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Makes a given handle a member of the room using a specific key and enters the room through a tunnel t...
int send_srv_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle to the room using a specific key.
static int iterate_send_message(void *cls, const struct GNUNET_HashCode *key, void *value)
int iterate_free_member_ids(void *cls, const struct GNUNET_HashCode *key, void *value)
void set_srv_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
Tries to rename the handle which implies renaming the EGO its using and moving all related data into ...
static const struct GNUNET_HashCode * get_next_member_session_contect(const struct GNUNET_MESSENGER_MemberSession *session)
const struct GNUNET_MESSENGER_Ego * get_srv_handle_ego(const struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.
static int callback_scan_for_rooms(void *cls, const char *filename)
static int iterate_save_rooms(void *cls, const struct GNUNET_HashCode *key, void *value)
void update_srv_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Tries to change the key pair of an EGO of a handle under the same name and informs all rooms about th...
static void change_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
static void callback_update_handle(void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego)
static void callback_setup_handle_name(void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego)
static void change_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Ego *ego)
void get_srv_handle_data_subdir(const struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir)
Writes the path of the directory for a given handle using a specific name to the parameter dir.
void destroy_srv_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
struct GNUNET_MESSENGER_SrvHandle * create_srv_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).
static const struct GNUNET_MESSENGER_MemberSession * get_handle_member_session(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *key)
GNUnet MESSENGER service.
struct GNUNET_MESSENGER_MemberSession * get_member_session(const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key)
Returns the member session of a member identified by a given public key.
const struct GNUNET_HashCode * get_member_session_context(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the member context of a given member session.
struct GNUNET_MESSENGER_Member * get_store_member(const struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Returns the member in a store identified by a given id.
struct GNUNET_MESSENGER_Message * create_message_name(const char *name)
Creates and allocates a new name message containing the name to change to.
struct GNUNET_MESSENGER_Message * create_message_key(const struct GNUNET_IDENTITY_PrivateKey *key)
Creates and allocates a new key message containing the public key to change to derived from its priva...
int send_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle into a room.
const struct GNUNET_HashCode * get_srv_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
struct GNUNET_MESSENGER_MemberStore * get_srv_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
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.
struct GNUNET_MESSENGER_SrvRoom * get_service_room(const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Returns the room identified by a given key for a service.
struct GNUNET_MESSENGER_EgoStore * get_service_ego_store(struct GNUNET_MESSENGER_Service *service)
Returns the used EGO-store of a given service.
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.
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
Get Crockford32-encoded fixed-size binary data from a configuration.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
enum GNUNET_GenericReturnValue 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:482
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1087
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:403
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue 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_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
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:560
ssize_t GNUNET_IDENTITY_write_public_key_to_buffer(const struct GNUNET_IDENTITY_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PublicKey to a compact buffer.
Definition: identity_api.c:890
ssize_t GNUNET_IDENTITY_public_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:830
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_IDENTITY_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:573
struct GNUNET_IDENTITY_Ego * GNUNET_IDENTITY_ego_get_anonymous()
Obtain the ego representing 'anonymous' users.
Definition: identity_api.c:157
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_FLAG_PRIVATE
The private flag.
@ GNUNET_MESSENGER_FLAG_SENT
The sent flag.
@ GNUNET_MESSENGER_FLAG_NONE
The none flag.
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:304
#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:62
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:77
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:763
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
int decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, int include_header)
Encodes a given message into a buffer of a maximal length in bytes.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, int include_header)
Returns the exact size in bytes to encode a given message.
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.
messenger api: client implementation of GNUnet MESSENGER service
#define DIR_SEPARATOR
Definition: platform.h:164
const char * name
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
A 512-bit hashcode.
Handle for an ego.
Definition: identity.h:37
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_IDENTITY_PrivateKey priv
Message to receive the current public key of a handle.
Message to receive the current member id of a handle in room.
struct GNUNET_MESSENGER_MemberSession * next
struct GNUNET_MESSENGER_MemberStore * store
struct GNUNET_MESSENGER_SrvHandle * handle
struct GNUNET_MESSENGER_Message * message
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
Message to receive the current name of a handle.
Message to receive something from a room.
const struct GNUNET_MESSENGER_Ego * ego
Handle to a message queue.
Definition: mq.c:87
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.