GNUnet  0.19.2
gnunet-service-messenger_room.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 
35 
37 
41 #include "messenger_api_util.h"
42 
43 static void
44 idle_request_room_messages (void *cls);
45 
48  const struct GNUNET_HashCode *key)
49 {
50  GNUNET_assert((handle) && (key));
51 
53 
54  room->service = handle->service;
55  room->host = handle;
56  room->port = NULL;
57 
58  GNUNET_memcpy(&(room->key), key, sizeof(struct GNUNET_HashCode));
59 
61 
65 
66  init_list_tunnels (&(room->basement));
67  init_message_state(&(room->state));
68 
69  room->peer_message = NULL;
70 
71  init_list_messages (&(room->handling));
72  room->idle = NULL;
73 
74  if (room->service->dir)
75  load_srv_room (room);
76 
78 
79  return room;
80 }
81 
82 static int
84  const struct GNUNET_PeerIdentity *key,
85  void *value)
86 {
87  struct GNUNET_MESSENGER_SrvTunnel *tunnel = value;
88  destroy_tunnel (tunnel);
89  return GNUNET_YES;
90 }
91 
92 static void
94 
95 void
97  int deletion)
98 {
100 
101  if (room->idle)
102  {
104  room->idle = NULL;
105  }
106 
107  if (room->port)
109 
112 
113  if (!(room->service->dir))
114  goto skip_saving;
115 
116  if (GNUNET_YES == deletion)
118  else
120 
121 skip_saving:
125 
129 
130  if (room->peer_message)
132 
133  GNUNET_free(room);
134 }
135 
138 {
140 
141  return &(room->member_store);
142 }
143 
146 {
147  GNUNET_assert(room);
148 
149  return &(room->message_store);
150 }
151 
154 {
156 
157  return &(room->operation_store);
158 }
159 
160 static int
163  struct GNUNET_MESSENGER_SrvTunnel *tunnel)
164 {
165  if ((!handle) || (!is_tunnel_connected (tunnel)))
166  return GNUNET_NO;
167 
169 }
170 
171 static void*
173  struct GNUNET_CADET_Channel *channel,
174  const struct GNUNET_PeerIdentity *source)
175 {
176  struct GNUNET_MESSENGER_SrvRoom *room = cls;
177 
179 
180  if ((tunnel) &&
183  {
184  destroy_tunnel (tunnel);
185  tunnel = NULL;
186  }
187 
188  if (!tunnel)
189  {
191  return NULL;
192  }
193 
194  bind_tunnel(tunnel, channel);
195 
196  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "New tunnel in room (%s) established to peer: %s\n",
198 
199  if (GNUNET_YES == send_room_info (room, room->host, tunnel))
200  return tunnel;
201 
202  disconnect_tunnel (tunnel);
203 
205  destroy_tunnel (tunnel);
206 
207  return NULL;
208 }
209 
210 static int
213  struct GNUNET_MESSENGER_Member *member)
214 {
215  GNUNET_assert((room) && (handle) && (member));
216 
217  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Joining room: %s (%s)\n", GNUNET_h2s (get_srv_room_key (room)),
218  GNUNET_sh2s (get_member_id(member)));
219 
220  const struct GNUNET_ShortHashCode *member_id = get_member_id(member);
221 
223  return GNUNET_NO;
224 
226 
227  if (!message)
228  {
229  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Your join message could not be created!\n");
230 
231  return GNUNET_NO;
232  }
233 
234  GNUNET_memcpy(&(message->header.sender_id), member_id, sizeof(*member_id));
235  return send_srv_room_message (room, handle, message);
236 }
237 
239 {
243 };
244 
245 static void
247  struct GNUNET_MESSENGER_MemberSession *session,
249  int check_permission)
250 {
251  if (session->prev)
253 
254  struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(notify->room);
255  struct GNUNET_MESSENGER_ListMessage *element;
256 
257  for (element = session->messages.head; element; element = element->next)
258  {
260  continue;
261 
262  if ((GNUNET_YES == check_permission) &&
263  (GNUNET_YES != check_member_session_history(notify->session, &(element->hash), GNUNET_NO)))
264  continue;
265 
266  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(map, &(element->hash), NULL,
268  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Notification of session message could be duplicated!\n");
269 
270  const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, &(element->hash));
271 
272  if (message)
273  notify_srv_handle_message (notify->handle, notify->room, session, message, &(element->hash));
274  }
275 }
276 
277 static int
279  const struct GNUNET_IDENTITY_PublicKey *public_key,
280  struct GNUNET_MESSENGER_MemberSession *session)
281 {
283 
284  if ((notify->session == session) || (GNUNET_YES == is_member_session_completed(session)))
285  return GNUNET_YES;
286 
288 
290 
292  return GNUNET_YES;
293 }
294 
295 static int
298 {
299  const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id (handle, get_srv_room_key(room));
300 
302  struct GNUNET_MESSENGER_Member *member = add_store_member(member_store, member_id);
303 
304  if (GNUNET_NO == join_room (room, handle, member))
305  return GNUNET_NO;
306 
307  const struct GNUNET_MESSENGER_Ego *ego = get_srv_handle_ego(handle);
308  struct GNUNET_MESSENGER_MemberSession *session = get_member_session (member, &(ego->pub));
309 
310  if (!session)
311  {
312  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "A valid session is required to join a room!\n");
313  return GNUNET_NO;
314  }
315 
317 
318  notify.room = room;
319  notify.handle = handle;
320  notify.session = session;
321 
323 
324  return GNUNET_YES;
325 }
326 
327 extern int
328 check_tunnel_message (void *cls,
329  const struct GNUNET_MessageHeader *header);
330 
331 extern void
332 handle_tunnel_message (void *cls,
333  const struct GNUNET_MessageHeader *header);
334 
335 extern void
336 callback_tunnel_disconnect (void *cls,
337  const struct GNUNET_CADET_Channel *channel);
338 
339 int
342 {
343  GNUNET_assert((room) && (handle));
344 
345  if (room->port)
346  return join_room_locally (room, handle);
347 
349  const struct GNUNET_HashCode *key = get_srv_room_key (room);
350 
352  struct GNUNET_MessageHeader, NULL),
354 
355  struct GNUNET_HashCode port;
358  handlers);
359 
360  if (room->port)
361  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Port of room (%s) was opened!\n",
363  else
364  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Port of room (%s) could not be opened!\n",
366 
367  const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id (handle, get_srv_room_key(room));
368 
370  struct GNUNET_MESSENGER_Member *member = add_store_member(member_store, member_id);
371 
372  if ((GNUNET_NO == join_room (room, handle, member)) && (room->port))
373  {
374  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not join the room, therefore it keeps closed!\n");
375 
377  room->port = NULL;
378 
379  return GNUNET_NO;
380  }
381 
382  struct GNUNET_MESSENGER_Message *peer_msg = create_message_peer (room->service);
383  GNUNET_memcpy(&(peer_msg->header.sender_id), member_id, sizeof(*member_id));
384  return (room->port ? send_srv_room_message (room, handle, peer_msg) : GNUNET_NO);
385 }
386 
387 int
390  const struct GNUNET_PeerIdentity *door)
391 {
392  GNUNET_assert((room) && (handle) && (door));
393 
394  struct GNUNET_PeerIdentity peer;
395 
396  if ((GNUNET_OK == get_service_peer_identity (room->service, &peer)) &&
397  (0 == GNUNET_memcmp(&peer, door)))
398  return join_room_locally (room, handle);
399 
401 
402  if (!tunnel)
403  {
404  tunnel = create_tunnel (room, door);
405 
408  {
409  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not connect to that door!\n");
410  destroy_tunnel (tunnel);
411  return GNUNET_NO;
412  }
413  }
414 
415  if (GNUNET_SYSERR == connect_tunnel (tunnel))
416  {
417  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Connection failure during entrance!\n");
419  destroy_tunnel (tunnel);
420  return GNUNET_NO;
421  }
422 
423  return join_room_locally (room, handle);
424 }
425 
426 struct GNUNET_MQ_Envelope*
428  const struct GNUNET_MESSENGER_SrvHandle *handle,
429  struct GNUNET_MESSENGER_Message *message,
430  struct GNUNET_HashCode *hash,
431  int mode)
432 {
433  GNUNET_assert((room) && (handle) && (message) && (hash));
434 
436 
438 
439  GNUNET_assert(id);
440 
441  GNUNET_memcpy(&(message->header.sender_id), id, sizeof(struct GNUNET_ShortHashCode));
442  get_message_state_chain_hash (&(room->state), &(message->header.previous));
443 
444  return pack_message (message, hash, get_srv_handle_ego (handle), mode);
445 }
446 
448 {
454  int packed;
455 };
456 
457 static int
459  const struct GNUNET_PeerIdentity *key,
460  void *value)
461 {
462  struct GNUNET_MESSENGER_SrvTunnel *tunnel = value;
463 
464  if ((!is_tunnel_connected (tunnel)) ||
466  return GNUNET_YES;
467 
468  struct GNUNET_MESSENGER_ClosureSendRoom *closure = cls;
469 
470  if (tunnel == closure->exclude)
471  return GNUNET_YES;
472 
473  struct GNUNET_MQ_Envelope *env = NULL;
474 
475  if (closure->packed == GNUNET_NO)
476  {
477  env = pack_srv_room_message (closure->room, closure->handle, closure->message, closure->hash,
479 
480  if (env)
481  closure->packed = GNUNET_YES;
482  }
483  else
485 
486  if (env)
487  send_tunnel_envelope (tunnel, env, closure->hash);
488 
489  return GNUNET_YES;
490 }
491 
492 int
494  struct GNUNET_MESSENGER_Message *message,
495  const struct GNUNET_HashCode *hash);
496 
497 void
500  const struct GNUNET_MESSENGER_Message *message,
501  const struct GNUNET_HashCode *hash);
502 
503 int
506  struct GNUNET_MESSENGER_Message *message)
507 {
508  GNUNET_assert((room) && (handle));
509 
510  if (!message)
511  return GNUNET_NO;
512 
513  if (GNUNET_YES == is_message_session_bound(message))
515 
516  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sending message from handle with member id: %s\n",
518 
519  struct GNUNET_HashCode hash;
520  struct GNUNET_MESSENGER_ClosureSendRoom closure;
521 
522  closure.room = room;
523  closure.handle = handle;
524  closure.exclude = NULL;
525  closure.message = message;
526  closure.hash = &hash;
527  closure.packed = GNUNET_NO;
528 
530 
531  if (GNUNET_NO == closure.packed)
533 
534  const int new_message = update_room_message (room, message, &hash);
535 
536  if (GNUNET_YES != new_message)
537  return GNUNET_SYSERR;
538 
539  switch (message->header.kind)
540  {
543  break;
546  break;
549  break;
552  break;
553  default:
554  break;
555  }
556 
558  return GNUNET_YES;
559 }
560 
561 void
563  struct GNUNET_MESSENGER_SrvTunnel *tunnel,
565  const struct GNUNET_HashCode *hash)
566 {
567  GNUNET_assert((room) && (tunnel));
568 
569  if (!message)
570  return;
571 
572  struct GNUNET_MESSENGER_ClosureSendRoom closure;
573  struct GNUNET_HashCode message_hash;
574 
575  GNUNET_memcpy(&message_hash, hash, sizeof(struct GNUNET_HashCode));
576 
577  closure.room = room;
578  closure.handle = NULL;
579  closure.exclude = tunnel;
580  closure.message = message;
581  closure.hash = &message_hash;
582  closure.packed = GNUNET_YES;
583 
585 }
586 
587 void
589  struct GNUNET_MESSENGER_SrvTunnel *tunnel)
590 {
591  if (!room->peer_message)
592  return;
593 
594  struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room);
595 
596  const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, room->peer_message);
597 
598  if (!message)
599  {
600  GNUNET_free(room->peer_message);
601  room->peer_message = NULL;
602  return;
603  }
604 
606  struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
607 
608  if (!member)
609  goto resend_peer_message;
610 
611  struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, room->peer_message);
612 
613  if (GNUNET_YES == is_member_session_closed(session))
614  goto resend_peer_message;
615 
616  if (tunnel)
617  forward_tunnel_message(tunnel, message, room->peer_message);
618 
619  return;
620 
621 resend_peer_message:
622  if (room->host)
623  send_srv_room_message (room, room->host, create_message_peer (room->service));
624 }
625 
626 void
629 {
630  GNUNET_assert(room);
631 
632  if (!handle)
633  return;
634 
635  const struct GNUNET_HashCode *hash;
636 
637 merge_next:
638  hash = get_message_state_merge_hash (&(room->state));
639 
640  if (!hash)
641  return;
642 
644  goto merge_next;
645 }
646 
647 void
649  const struct GNUNET_HashCode *hash)
650 {
652  {
653  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Deletion of message failed! (%s)\n", GNUNET_h2s(hash));
654  return;
655  }
656 }
657 
658 void
660  const struct GNUNET_HashCode *hash)
661 {
662  if (!room->host)
663  return;
664 
665  send_srv_room_message (room, room->host, create_message_merge (hash));
666 }
667 
668 int
670  struct GNUNET_MESSENGER_MemberSession *session,
671  const struct GNUNET_HashCode *hash,
672  const struct GNUNET_TIME_Relative delay)
673 {
674  GNUNET_assert((room) && (session) && (hash));
675 
677 
678  if (0 == GNUNET_memcmp(&forever, &delay))
679  {
680  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Deletion is delayed forever: operation is impossible!\n");
681  return GNUNET_SYSERR;
682  }
683 
684  struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room);
685 
686  const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, hash);
687 
688  if (!message)
689  return GNUNET_YES;
690 
691  if (GNUNET_YES != check_member_session_history(session, hash, GNUNET_YES))
692  {
693  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unpermitted request for deletion by member (%s) of message (%s)!\n",
694  GNUNET_sh2s(get_member_session_id(session)), GNUNET_h2s(hash));
695 
696  return GNUNET_NO;
697  }
698 
700 
701  if (GNUNET_OK != use_store_operation(operation_store, hash, GNUNET_MESSENGER_OP_DELETE, delay))
702  {
703  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Deletion has failed: operation denied!\n");
704  return GNUNET_SYSERR;
705  }
706 
707  return GNUNET_YES;
708 }
709 
710 struct GNUNET_CADET_Handle*
712 {
713  GNUNET_assert(room);
714 
715  return room->service->cadet;
716 }
717 
718 const struct GNUNET_HashCode*
720 {
721  GNUNET_assert(room);
722 
723  return &(room->key);
724 }
725 
726 const struct GNUNET_MESSENGER_SrvTunnel*
728  const struct GNUNET_PeerIdentity *peer)
729 {
730  GNUNET_assert((room) && (peer));
731 
733 }
734 
735 static int
737  const struct GNUNET_HashCode *hash,
738  const struct GNUNET_MESSENGER_MemberSession *session,
740  void* cls)
741 {
742  struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room);
743 
745  message_store, hash, GNUNET_YES
746  );
747 
748  if (!link)
749  goto forward;
750 
751  int result = request_room_message_step(room, &(link->first), session, callback, cls);
752 
753  if ((GNUNET_YES == link->multiple) &&
754  (GNUNET_YES == request_room_message_step(room, &(link->second), session, callback, cls)))
755  return GNUNET_YES;
756  else
757  return result;
758 
759 forward:
760  if (GNUNET_YES != check_member_session_history(session, hash, GNUNET_NO))
761  return GNUNET_YES;
762 
763  const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, hash);
764 
765  if (!message)
766  return GNUNET_NO;
767 
768  if (callback)
769  callback (cls, room, message, hash);
770 
771  return GNUNET_YES;
772 }
773 
774 int
776  const struct GNUNET_HashCode *hash,
777  const struct GNUNET_MESSENGER_MemberSession *session,
779  void* cls)
780 {
781  GNUNET_assert((room) && (hash));
782 
783  int result = request_room_message_step (room, hash, session, callback, cls);
784 
785  if ((GNUNET_NO == result) && (callback))
786  callback (cls, room, NULL, hash);
787 
788  return result;
789 }
790 
791 void
793  void *cls)
794 {
795  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
796 
797  if (!room->host)
798  return;
799 
802 
805  return;
806 
809 }
810 
811 int
813  void *cls,
814  struct GNUNET_MESSENGER_Message *message,
815  struct GNUNET_HashCode *hash)
816 {
817  if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind)
818  {
819  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Message error: Kind is unknown! (%d)\n", message->header.kind);
820  return GNUNET_SYSERR;
821  }
822 
823  struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room);
824 
825  const struct GNUNET_MESSENGER_Message *previous = get_store_message(message_store, &(message->header.previous));
826 
827  if (!previous)
828  goto skip_time_comparison;
829 
830  struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_ntoh(message->header.timestamp);
832 
833  if (GNUNET_TIME_relative_get_zero_().rel_value_us != GNUNET_TIME_absolute_get_difference(timestamp, last).rel_value_us)
834  {
835  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Message error: Timestamp does not check out!\n");
836  return GNUNET_SYSERR;
837  }
838 
839 skip_time_comparison:
840  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Receiving message of kind: %s!\n",
842 
843  return GNUNET_OK;
844 }
845 
846 static void
848 {
849  struct GNUNET_MESSENGER_SrvRoom *room = cls;
850 
851  room->idle = NULL;
852 
854  const struct GNUNET_HashCode *hash = get_message_state_merge_hash(&(room->state));
855 
856  if ((hash) &&
857  (GNUNET_MESSENGER_OP_UNKNOWN == get_store_operation_type(operation_store, hash)))
859  operation_store,
860  hash,
863  );
864 
869  cls
870  );
871 }
872 
873 void
875  const struct GNUNET_IDENTITY_PublicKey *public_key,
876  const struct GNUNET_ShortHashCode *member_id,
877  struct GNUNET_TIME_Absolute timestamp)
878 {
879  GNUNET_assert ((room) && (public_key) && (member_id));
880 
882  struct GNUNET_MESSENGER_Member *member = get_store_member(member_store, member_id);
883 
884  if ((!member) || (1 >= GNUNET_CONTAINER_multihashmap_size(member->sessions)))
885  return;
886 
887  struct GNUNET_MESSENGER_ListHandles *handles = &(room->service->handles);
888  struct GNUNET_MESSENGER_ListHandle* element;
889 
890  for (element = handles->head; element; element = element->next)
891  {
892  if (0 != GNUNET_memcmp(member_id, get_srv_handle_member_id(element->handle, get_srv_room_key(room))))
893  continue;
894 
895  if (0 == GNUNET_memcmp(public_key, &(get_srv_handle_ego(element->handle)->pub)))
896  continue;
897 
899 
900  if (!session)
901  continue;
902 
904 
905  if (GNUNET_TIME_relative_get_zero_().rel_value_us != GNUNET_TIME_absolute_get_difference(start, timestamp).rel_value_us)
906  continue;
907 
908  struct GNUNET_ShortHashCode random_id;
909  generate_free_member_id (&random_id, member_store->members);
910 
911  send_srv_room_message(room, element->handle, create_message_id(&random_id));
912  }
913 }
914 
915 void
917 {
918  GNUNET_assert(room);
919 
920  struct GNUNET_PeerIdentity peer;
921  size_t src;
922 
923  if ((GNUNET_OK != get_service_peer_identity (room->service, &peer)) ||
924  (!find_list_tunnels (&(room->basement), &peer, &src)))
925  return;
926 
927  size_t count = count_of_tunnels (&(room->basement));
928 
929  struct GNUNET_MESSENGER_ListTunnel *element = room->basement.head;
930  struct GNUNET_MESSENGER_SrvTunnel *tunnel;
931 
932  size_t dst = 0;
933 
934  while (element)
935  {
936  GNUNET_PEER_resolve (element->peer, &peer);
937 
939 
940  if (!tunnel)
941  {
942  element = remove_from_list_tunnels (&(room->basement), element);
943  continue;
944  }
945 
946  if (GNUNET_YES == required_connection_between (count, src, dst))
947  {
948  if (GNUNET_SYSERR == connect_tunnel (tunnel))
949  {
950  element = remove_from_list_tunnels (&(room->basement), element);
951  continue;
952  }
953  }
954  else
955  disconnect_tunnel (tunnel);
956 
957  element = element->next;
958  dst++;
959  }
960 }
961 
962 static void
964 {
965  struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room);
967 
968  while (room->handling.head)
969  {
970  struct GNUNET_MESSENGER_ListMessage *element = room->handling.head;
971 
972  const struct GNUNET_MESSENGER_Message *message = get_store_message (message_store, &(element->hash));
973 
974  if (!message)
975  goto finish_handling;
976 
977  struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
978 
979  if (!member)
980  goto finish_handling;
981 
982  struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, &(element->hash));
983 
984  if (session)
985  handle_service_message (room->service, room, session, message, &(element->hash));
986 
987 finish_handling:
988  GNUNET_CONTAINER_DLL_remove(room->handling.head, room->handling.tail, element);
989  GNUNET_free(element);
990  }
991 }
992 
993 int
995  struct GNUNET_MESSENGER_Message *message,
996  const struct GNUNET_HashCode *hash)
997 {
998  GNUNET_assert((room) && (message) && (hash));
999 
1001 
1002  const int requested = (GNUNET_MESSENGER_OP_REQUEST == get_store_operation_type(operation_store, hash)?
1004  );
1005 
1006  if (GNUNET_YES == requested)
1007  cancel_store_operation(operation_store, hash);
1008 
1009  struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room);
1010 
1011  const struct GNUNET_MESSENGER_Message *old_message = get_store_message (message_store, hash);
1012 
1013  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Handle a message in room (%s).\n", GNUNET_h2s (get_srv_room_key(room)));
1014 
1015  if ((old_message) || (GNUNET_OK != put_store_message (message_store, hash, message)))
1016  {
1017  if (old_message != message)
1018  destroy_message(message);
1019 
1020  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Duplicate message got dropped!\n");
1021  return GNUNET_NO;
1022  }
1023 
1024  update_message_state(&(room->state), requested, message, hash);
1025 
1026  if ((GNUNET_YES == requested) ||
1027  (GNUNET_MESSENGER_KIND_INFO == message->header.kind) ||
1029  return GNUNET_YES;
1030 
1031  if ((GNUNET_MESSENGER_KIND_MERGE == message->header.kind) &&
1032  (GNUNET_MESSENGER_OP_MERGE == get_store_operation_type(operation_store, &(message->body.merge.previous))))
1033  cancel_store_operation(operation_store, &(message->body.merge.previous));
1034 
1035  if (GNUNET_MESSENGER_OP_MERGE == get_store_operation_type(operation_store, &(message->header.previous)))
1036  cancel_store_operation(operation_store, &(message->header.previous));
1037 
1038  return GNUNET_YES;
1039 }
1040 
1042 {
1045 
1047 };
1048 
1050 {
1052  const struct GNUNET_HashCode *hash;
1053 
1056 };
1057 
1058 static int
1060  const struct GNUNET_IDENTITY_PublicKey *public_key,
1062 {
1063  struct GNUNET_MESSENGER_MemberUpdate *update = cls;
1064 
1065  update_member_session_history(session, update->message, update->hash);
1066 
1067  if (GNUNET_YES == is_member_session_completed(session))
1068  {
1071  );
1072 
1073  element->session = session;
1074 
1075  GNUNET_CONTAINER_DLL_insert_tail(update->head, update->tail, element);
1076  }
1077 
1078  return GNUNET_YES;
1079 }
1080 
1081 static void
1084 
1085 void
1088  const struct GNUNET_MESSENGER_Message *message,
1089  const struct GNUNET_HashCode *hash)
1090 {
1092  struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
1093 
1094  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Callback for message (%s)\n", GNUNET_h2s (hash));
1095 
1096  if (!member)
1097  {
1098  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Message handling dropped: Member is missing!\n");
1099  return;
1100  }
1101 
1102  struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, hash);
1103 
1104  if (!session)
1105  {
1106  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Message handling dropped: Session is missing!\n");
1107  return;
1108  }
1109 
1110  struct GNUNET_MESSENGER_MemberUpdate update;
1111  update.message = message;
1112  update.hash = hash;
1113 
1114  update.head = NULL;
1115  update.tail = NULL;
1116 
1117  iterate_store_members(member_store, iterate_update_member_sessions, &update);
1118 
1119  while (update.head)
1120  {
1121  struct GNUNET_MESSENGER_MemberSessionCompletion *element = update.head;
1122 
1123  remove_room_member_session (room, element->session);
1124 
1125  GNUNET_CONTAINER_DLL_remove(update.head, update.tail, element);
1126  GNUNET_free (element);
1127  }
1128 
1129  const int start_handle = room->handling.head ? GNUNET_NO : GNUNET_YES;
1130 
1131  add_to_list_messages (&(room->handling), hash);
1132 
1133  switch (message->header.kind)
1134  {
1136  handle_message_join (room, session, message, hash);
1137  break;
1139  handle_message_leave (room, session, message, hash);
1140  break;
1142  handle_message_name (room, session, message, hash);
1143  break;
1145  handle_message_key (room, session, message, hash);
1146  break;
1148  handle_message_peer (room, session, message, hash);
1149  break;
1151  handle_message_id (room, session, message, hash);
1152  break;
1154  handle_message_miss (room, session, message, hash);
1155  break;
1157  handle_message_delete (room, session, message, hash);
1158  break;
1159  default:
1160  break;
1161  }
1162 
1163  if (GNUNET_YES == start_handle)
1164  handle_room_messages (room);
1165 }
1166 
1167 static void
1169  char **dir)
1170 {
1171  GNUNET_assert((room) && (dir));
1172 
1173  GNUNET_asprintf (dir, "%s%s%c%s%c", room->service->dir, "rooms", DIR_SEPARATOR, GNUNET_h2s (get_srv_room_key(room)), DIR_SEPARATOR);
1174 }
1175 
1176 void
1178 {
1179  GNUNET_assert(room);
1180 
1181  char *room_dir;
1182  get_room_data_subdir (room, &room_dir);
1183 
1185  {
1186  load_member_store (get_srv_room_member_store(room), room_dir);
1189 
1190  char *basement_file;
1191  GNUNET_asprintf (&basement_file, "%s%s", room_dir, "basement.list");
1192 
1193  load_list_tunnels(&(room->basement), basement_file);
1194  GNUNET_free(basement_file);
1195 
1196  load_message_state(&(room->state), room_dir);
1197  }
1198 
1199  GNUNET_free(room_dir);
1200 }
1201 
1202 void
1204 {
1205  GNUNET_assert(room);
1206 
1207  char *room_dir;
1208  get_room_data_subdir (room, &room_dir);
1209 
1210  if ((GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_NO)) ||
1211  (GNUNET_OK == GNUNET_DISK_directory_create (room_dir)))
1212  {
1216 
1217  char *basement_file;
1218  GNUNET_asprintf (&basement_file, "%s%s", room_dir, "basement.list");
1219 
1220  save_list_tunnels(&(room->basement), basement_file);
1221  GNUNET_free(basement_file);
1222 
1223  save_message_state(&(room->state), room_dir);
1224  }
1225 
1226  GNUNET_free(room_dir);
1227 }
1228 
1229 void
1231 {
1232  GNUNET_assert(room);
1233 
1234  char *room_dir;
1235  get_room_data_subdir (room, &room_dir);
1236 
1238  GNUNET_DISK_directory_remove(room_dir);
1239 
1240  GNUNET_free(room_dir);
1241 }
1242 
1243 static void
1246 {
1247  GNUNET_assert ((room) && (session));
1248 
1250 
1251  const struct GNUNET_IDENTITY_PublicKey *public_key = get_member_session_public_key(session);
1252 
1253  struct GNUNET_HashCode hash;
1254  GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
1255 
1256  char *room_dir;
1257  get_room_data_subdir (room, &room_dir);
1258 
1259  char* session_dir;
1260  GNUNET_asprintf (
1261  &session_dir, "%s%s%c%s%c%s%c%s%c", room_dir,
1262  "members", DIR_SEPARATOR,
1264  "sessions", DIR_SEPARATOR,
1265  GNUNET_h2s(&hash), DIR_SEPARATOR
1266  );
1267 
1268  GNUNET_free (room_dir);
1269 
1270  GNUNET_DISK_directory_remove(session_dir);
1271  GNUNET_free (session_dir);
1272 
1273  destroy_member_session(session);
1274 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static int forward
Search direction: forward.
Definition: gnunet-abd.c:162
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we've connected to it).
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static GstElement * source
Appsrc instance into which we write data for the pipeline.
static char * value
Value of the record to add/remove.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static int result
Global testing status.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
static struct GNUNET_CADET_Handle * cadet
Handle for cadet.
GNUnet MESSENGER service.
int required_connection_between(size_t count, size_t src, size_t dst)
Returns GNUNET_YES or GNUNET_NO to determine if the peers of index src and index dst should be connec...
size_t count_of_tunnels(const struct GNUNET_MESSENGER_ListTunnels *tunnels)
Returns the count of peers in a list (typically from the basement of a room).
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 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.
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.
const struct GNUNET_MESSENGER_Ego * get_srv_handle_ego(const struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
void remove_member_session(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
Removes a given member session from its member.
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_ShortHashCode * get_member_id(const struct GNUNET_MESSENGER_Member *member)
Returns the current id of a given member.
struct GNUNET_MESSENGER_MemberSession * get_member_session_of(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Returns the member session of a member using a public key which can verify the signature of a given m...
GNUnet MESSENGER service.
const struct GNUNET_ShortHashCode * get_member_session_id(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the member id of a given member session.
void destroy_member_session(struct GNUNET_MESSENGER_MemberSession *session)
Destroys a member session and frees its memory fully.
int check_member_session_history(const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, int ownership)
Checks the history of a session for a specific message which is identified by its hash and if the own...
struct GNUNET_TIME_Absolute get_member_session_start(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the timestamp of the member session's start.
void update_member_session_history(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Adds a given message to the history of a session using the messages hash.
int is_member_session_completed(const struct GNUNET_MESSENGER_MemberSession *session)
Returns if the given member session has been completed.
const struct GNUNET_IDENTITY_PublicKey * get_member_session_public_key(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the public key from an EGO of a given member session.
int is_member_session_closed(const struct GNUNET_MESSENGER_MemberSession *session)
Returns if the given member session has been closed.
struct GNUNET_MESSENGER_Member * get_store_member_of(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_MESSENGER_Message *message)
Returns the member of a store using a sender id of a given message.
int iterate_store_members(struct GNUNET_MESSENGER_MemberStore *store, GNUNET_MESSENGER_MemberIteratorCallback it, void *cls)
Iterate through all member sessions currently connected to the members of the given member store and ...
void save_member_store(struct GNUNET_MESSENGER_MemberStore *store, const char *directory)
Saves members from a member store into a directory.
void load_member_store(struct GNUNET_MESSENGER_MemberStore *store, const char *directory)
Loads members from a directory into a member store.
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.
void init_member_store(struct GNUNET_MESSENGER_MemberStore *store, struct GNUNET_MESSENGER_SrvRoom *room)
Initializes a member store as fully empty connected to a room.
struct GNUNET_MESSENGER_Member * add_store_member(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Adds a member to a store under a specific id and returns it on success.
void clear_member_store(struct GNUNET_MESSENGER_MemberStore *store)
Clears a member store, wipes its content and deallocates its memory.
void handle_message_key(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent key message to change the key of a member and rearrange the contacts accor...
void handle_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent peer message to make changes of the basement in the room.
void handle_message_join(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent join message to make changes of current member information.
void handle_message_miss(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent miss message to drop a peer from the basement in the room.
void handle_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent id message to change a members id.
void handle_message_name(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent name message to rename a current member.
void handle_message_leave(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent leave message to make changes of current member information.
void handle_message_delete(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent delete message to delete a specific message from the store.
struct GNUNET_MESSENGER_Message * create_message_merge(const struct GNUNET_HashCode *previous)
Creates and allocates a new merge message containing the hash of a second previous message besides th...
struct GNUNET_MESSENGER_Message * create_message_info(const struct GNUNET_MESSENGER_Ego *ego)
Creates and allocates a new info message containing the hosts EGO public key and a newly generated un...
struct GNUNET_MESSENGER_Message * create_message_miss(const struct GNUNET_PeerIdentity *peer)
Creates and allocates a new miss message containing the missing peer identity.
struct GNUNET_MESSENGER_Message * create_message_peer(const struct GNUNET_MESSENGER_Service *service)
Creates and allocates a new peer message containing a services peer identity.
struct GNUNET_MESSENGER_Message * create_message_id(const struct GNUNET_ShortHashCode *unique_id)
Creates and allocates a new id message containing the unique member id to change to.
struct GNUNET_MESSENGER_Message * create_message_join(const struct GNUNET_MESSENGER_Ego *ego)
Creates and allocates a new join message containing the clients EGO public key.
void send_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent id message to update the handles member id in the room.
void send_message_request(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent request message to trigger the request operation for this service.
void send_message_join(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent join message to ensure growth of the decentralized room structure.
void send_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent peer message to update the rooms peer message of this service.
void save_message_state(const struct GNUNET_MESSENGER_MessageState *state, const char *path)
void update_message_state(struct GNUNET_MESSENGER_MessageState *state, int requested, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
void clear_message_state(struct GNUNET_MESSENGER_MessageState *state)
void get_message_state_chain_hash(const struct GNUNET_MESSENGER_MessageState *state, struct GNUNET_HashCode *hash)
void init_message_state(struct GNUNET_MESSENGER_MessageState *state)
void load_message_state(struct GNUNET_MESSENGER_MessageState *state, const char *path)
const struct GNUNET_HashCode * get_message_state_merge_hash(const struct GNUNET_MESSENGER_MessageState *state)
void save_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Saves messages from a message store into a directory.
const struct GNUNET_MESSENGER_Message * get_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Returns the message from a message store matching a given hash.
void clear_message_store(struct GNUNET_MESSENGER_MessageStore *store)
Clears a message store, wipes its content and deallocates its memory.
void init_message_store(struct GNUNET_MESSENGER_MessageStore *store)
Initializes a message store as fully empty.
int delete_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Deletes a message in the message store.
void load_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Loads messages from a directory into a message store.
int put_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, struct GNUNET_MESSENGER_Message *message)
Stores a message into the message store.
const struct GNUNET_MESSENGER_MessageLink * get_store_message_link(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, int deleted_only)
Returns the message link from a message store matching a given hash.
GNUnet MESSENGER service.
void cancel_store_operation(struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash)
Stops any active operation under a given hash in a specific operation store.
void save_operation_store(const struct GNUNET_MESSENGER_OperationStore *store, const char *directory)
Saves operations from an operation store into a directory.
void clear_operation_store(struct GNUNET_MESSENGER_OperationStore *store)
Clears an operation store, stops all operations and deallocates its memory.
void load_operation_store(struct GNUNET_MESSENGER_OperationStore *store, const char *directory)
Loads operations from a directory into an operation store.
enum GNUNET_MESSENGER_OperationType get_store_operation_type(const struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash)
Returns the type of the active operation under a given hash in a specific operation store.
void init_operation_store(struct GNUNET_MESSENGER_OperationStore *store, struct GNUNET_MESSENGER_SrvRoom *room)
Initializes an operation store as fully empty with a given room.
int use_store_operation(struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_OperationType type, struct GNUNET_TIME_Relative delay)
Tries to use an operation under a given hash in a specific operation store.
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.
static void notify_about_members(struct GNUNET_MESSENGER_MemberNotify *notify, struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_CONTAINER_MultiHashMap *map, int check_permission)
static int join_room(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Member *member)
int open_srv_room(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
Tries to open a room for a given handle.
static void get_room_data_subdir(struct GNUNET_MESSENGER_SrvRoom *room, char **dir)
struct GNUNET_MESSENGER_OperationStore * get_srv_room_operation_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used operation store of a given room.
void save_srv_room(struct GNUNET_MESSENGER_SrvRoom *room)
Saves the configuration for a given room of a service which contains the last messages hash and the r...
void rebuild_srv_room_basement_structure(struct GNUNET_MESSENGER_SrvRoom *room)
Rebuilds the decentralized structure for a room by ensuring all required connections are made dependi...
static int iterate_notify_about_members(void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session)
static void remove_room_member_session(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session)
const struct GNUNET_MESSENGER_SrvTunnel * get_srv_room_tunnel(const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *peer)
Returns a tunnel inside of a room leading towards a given peer if such a tunnel exists,...
void handle_tunnel_message(void *cls, const struct GNUNET_MessageHeader *header)
void solve_srv_room_member_collisions(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_IDENTITY_PublicKey *public_key, const struct GNUNET_ShortHashCode *member_id, struct GNUNET_TIME_Absolute timestamp)
Checks for potential collisions with member ids and solves them changing active handles ids if they u...
static int send_room_info(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
static void idle_request_room_messages(void *cls)
int enter_srv_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...
void merge_srv_room_last_messages(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
Reduces all current forks inside of the message history of a room to one remaining last message by me...
void check_srv_room_peer_status(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Checks the current state of opening a given room from this peer and re-publishes it if necessary to a...
void remove_srv_room(struct GNUNET_MESSENGER_SrvRoom *room)
Removes the configuration for a given room of a service.
struct GNUNET_MQ_Envelope * pack_srv_room_message(const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode)
Packs a message depending on the selected mode into a newly allocated envelope.
static int iterate_destroy_tunnels(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
void forward_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Forwards a message with a given hash to a specific tunnel inside of a room.
int delete_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
Deletes a message from the room with a given hash in a specific delay if the provided member by its s...
struct GNUNET_CADET_Handle * get_srv_room_cadet(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the CADET handle from a rooms service.
int callback_verify_room_message(struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
static int join_room_locally(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
static void * callback_room_connect(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source)
static void handle_room_messages(struct GNUNET_MESSENGER_SrvRoom *room)
static int request_room_message_step(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, GNUNET_MESSENGER_MessageRequestCallback callback, void *cls)
struct GNUNET_MESSENGER_SrvRoom * create_srv_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key.
void callback_room_handle_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
int check_tunnel_message(void *cls, const struct GNUNET_MessageHeader *header)
static int iterate_update_member_sessions(void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session)
void callback_tunnel_disconnect(void *cls, const struct GNUNET_CADET_Channel *channel)
int update_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
void destroy_srv_room(struct GNUNET_MESSENGER_SrvRoom *room, int deletion)
Destroys a room and frees its memory fully.
void callback_room_deletion(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash)
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.
struct GNUNET_MESSENGER_MessageStore * get_srv_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.
void callback_room_disconnect(struct GNUNET_MESSENGER_SrvRoom *room, void *cls)
static int iterate_send_room_message(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
int request_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, GNUNET_MESSENGER_MessageRequestCallback callback, void *cls)
Requests a message from a room identified by a given hash.
void callback_room_merge(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash)
void load_srv_room(struct GNUNET_MESSENGER_SrvRoom *room)
Loads the local configuration for a given room of a service which contains the last messages hash and...
GNUnet MESSENGER service.
#define GNUNET_MESSENGER_MERGE_DELAY
#define GNUNET_MESSENGER_IDLE_DELAY
void() GNUNET_MESSENGER_MessageRequestCallback(void *cls, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Method called whenever a message is found during a request in a room.
void handle_service_message(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_MemberSession *session, 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...
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.
GNUnet MESSENGER service.
int send_tunnel_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message by packing it automatically into an envelope and passing it through the tunnel.
void forward_tunnel_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Forwards a given message with a known hash through a tunnel.
void send_tunnel_envelope(struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *env, const struct GNUNET_HashCode *hash)
Sends an envelope containing a message with a given hash through a tunnel.
int connect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Tries to connect a tunnel by creating a new CADET channel and binding it.
int is_tunnel_connected(const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Returns the status of a currently bound channel of a tunnel.
struct GNUNET_MESSENGER_SrvTunnel * create_tunnel(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *door)
Creates and allocates a tunnel of a room to a specific peer identity (called door).
void bind_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel)
Binds a CADET channel to a tunnel and replaces its channel the tunnel is currently bound to if necess...
uint32_t get_tunnel_messenger_version(const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Returns the current messenger version the peer connected via a given tunnel has reported to be using ...
void get_tunnel_peer_identity(const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer)
Writes the peer identity of the peer connected via tunnel to this peer into the peer parameter.
void disconnect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Disconnects and unbinds a channel from a tunnel.
GNUnet MESSENGER service.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port.
Definition: cadet_api.c:801
struct GNUNET_CADET_Port * GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Open a port to receive incoming MQ-based channels.
Definition: cadet_api.c:954
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1084
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(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:495
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
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
enum GNUNET_GenericReturnValue 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).
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL).
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator 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.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#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_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#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_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSENGER_VERSION
Version number of GNUnet Messenger API.
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:36
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_DELETE
The delete kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:220
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1171
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1195
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:944
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition: time.c:133
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_(void)
Return "forever".
Definition: time.c:196
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:421
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
void load_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path)
Loads the list of tunnels peer identities from a file under a given path.
void init_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Initializes list of tunnels peer identities as empty list.
void save_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path)
Saves the list of tunnels peer identities to a file under a given path.
struct GNUNET_MESSENGER_ListTunnel * remove_from_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element)
Removes a specific element from the list of tunnels peer identities and returns the next element in t...
struct GNUNET_MESSENGER_ListTunnel * find_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index)
Searches linearly through the list of tunnels peer identities for matching a specific peer identity a...
void clear_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Clears the list of tunnels peer identities.
int contains_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
Tests linearly if the list of tunnels peer identities contains a specific peer identity and returns G...
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego, int mode)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
int is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
#define GNUNET_MESSENGER_PACK_MODE_UNKNOWN
#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE
void convert_messenger_key_to_port(const struct GNUNET_HashCode *key, struct GNUNET_HashCode *port)
Converts a Messenger service key of a room to the specific port which gets used for the CADET channel...
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.
void delayed_disconnect_channel(struct GNUNET_CADET_Channel *channel)
Starts an urgent task to close a CADET channel asynchronously.
messenger api: client implementation of GNUnet MESSENGER service
#define DIR_SEPARATOR
Definition: platform.h:164
Opaque handle to a channel.
Definition: cadet.h:116
Opaque handle to the service.
Definition: cadet_api.c:39
Internal representation of the hash map.
A 512-bit hashcode.
An identity key as per LSD0001.
struct GNUNET_MESSENGER_SrvHandle * handle
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_SrvTunnel * exclude
struct GNUNET_MESSENGER_SrvRoom * room
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_MESSENGER_ListHandle * next
struct GNUNET_MESSENGER_SrvHandle * handle
struct GNUNET_MESSENGER_ListHandle * head
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_ListMessage * head
struct GNUNET_MESSENGER_ListMessage * tail
struct GNUNET_MESSENGER_ListTunnel * next
struct GNUNET_MESSENGER_ListTunnel * head
struct GNUNET_MESSENGER_MemberSession * session
struct GNUNET_MESSENGER_SrvRoom * room
struct GNUNET_MESSENGER_SrvHandle * handle
struct GNUNET_MESSENGER_MemberSessionCompletion * prev
struct GNUNET_MESSENGER_MemberSession * session
struct GNUNET_MESSENGER_MemberSessionCompletion * next
struct GNUNET_MESSENGER_MemberSession * prev
struct GNUNET_MESSENGER_ListMessages messages
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_MESSENGER_MemberSessionCompletion * head
const struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_MemberSessionCompletion * tail
struct GNUNET_CONTAINER_MultiHashMap * sessions
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_CADET_Handle * cadet
struct GNUNET_MESSENGER_ListHandles handles
struct GNUNET_HashCode * peer_message
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
struct GNUNET_MESSENGER_MemberStore member_store
struct GNUNET_MESSENGER_Service * service
struct GNUNET_CADET_Port * port
struct GNUNET_MESSENGER_ListTunnels basement
struct GNUNET_SCHEDULER_Task * idle
struct GNUNET_MESSENGER_MessageStore message_store
struct GNUNET_MESSENGER_MessageState state
struct GNUNET_MESSENGER_ListMessages handling
struct GNUNET_MESSENGER_OperationStore operation_store
struct GNUNET_MESSENGER_SrvHandle * host
struct GNUNET_CADET_Channel * channel
struct GNUNET_MESSENGER_SrvRoom * room
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.