GNUnet  0.11.x
Data Structures | Functions
gnunet-service-messenger_room.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger_room.h"
#include "gnunet-service-messenger_message_kind.h"
#include "gnunet-service-messenger_service.h"
#include "gnunet-service-messenger_util.h"
#include "gnunet-service-messenger_message_recv.h"
#include "gnunet-service-messenger_message_send.h"
Include dependency graph for gnunet-service-messenger_room.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_SrvTunnelFinder
 
struct  GNUNET_MESSENGER_ClosureSendRoom
 

Functions

static void idle_request_room_messages (void *cls)
 
struct GNUNET_MESSENGER_SrvRoomcreate_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
 Creates and allocates a new room for a handle with a given key. More...
 
static int iterate_destroy_tunnels (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 
static int iterate_clear_members (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static int iterate_destroy_member_infos (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
void destroy_room (struct GNUNET_MESSENGER_SrvRoom *room)
 Destroys a room and frees its memory fully. More...
 
struct GNUNET_MESSENGER_SrvContactget_room_contact (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id)
 Returns the contact of a member in a room identified by a given id. More...
 
void add_room_contact (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id, const struct GNUNET_IDENTITY_PublicKey *pubkey)
 Adds a contact from the service to a room under a specific id with a given public key. More...
 
struct GNUNET_MESSENGER_MemberInfoget_room_member_info (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id)
 Returns the member information of a member in a room identified by a given id. More...
 
struct GNUNET_ShortHashCodegenerate_room_member_id (const struct GNUNET_MESSENGER_SrvRoom *room)
 Tries to generate and allocate a new unique member id checking all current members for possible duplicates. More...
 
const struct GNUNET_ShortHashCodeget_room_host_id (const struct GNUNET_MESSENGER_SrvRoom *room)
 Returns the member id of the member representing the handle currently hosting this room. More...
 
void change_room_host_id (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *unique_id)
 Changes the member id of the member representing the handle currently hosting this room. More...
 
static int send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 
static void * callback_room_connect (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source)
 
static int join_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_ShortHashCode *member_id)
 
static int join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
 
int check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header)
 
void handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header)
 
void callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel)
 
int open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
 Tries to open a room for a given handle. More...
 
int entry_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door)
 Connects a tunnel to a hosting peer of a room through a so called door which is represented by a peer identity of a hosting peer. More...
 
static int iterate_find_tunnel (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 
struct GNUNET_MESSENGER_SrvTunnelfind_room_tunnel_to (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *contact_id)
 Returns a tunnel granting a direct connection to a specific member in a room. More...
 
struct GNUNET_MQ_Envelopepack_room_message (struct GNUNET_MESSENGER_SrvRoom *room, 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. More...
 
static int iterate_send_room_message (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 
void callback_room_sent (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, void *cls, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
void send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
 Sends a message from a given handle into a room. More...
 
void send_room_message_ext (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Sends a message from a given handle into a room excluding one specific tunnel. More...
 
void forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, const 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. More...
 
void merge_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 merging them down. More...
 
struct GNUNET_CADET_Handleget_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room)
 Returns the CADET handle from a rooms service. More...
 
struct GNUNET_HashCodeget_room_key (struct GNUNET_MESSENGER_SrvRoom *room)
 Returns the shared secret you need to access a room. More...
 
const struct GNUNET_MESSENGER_SrvTunnelget_room_tunnel (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, otherwise NULL. More...
 
const struct GNUNET_MESSENGER_Messageget_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
 Returns a message from a room identified by a given hash. More...
 
void callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls)
 
int callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
 
static void search_room_for_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash)
 
void update_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Updates the last messages of a room by replacing them if the previous hash of a given message matches with one of the latest messages. More...
 
void switch_room_member_id (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *old_id, const struct GNUNET_ShortHashCode *new_id, const struct GNUNET_HashCode *hash)
 Changes an id of a current member from an old id to a new one and adds optionally the hash of an id message to the members information. More...
 
void rebuild_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room)
 Rebuilds the decentralized structure for a room by ensuring all required connections are made depending on the amount of peers and this peers index in the list of them. More...
 
void handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room)
 Handles all queued up messages of a room to handle in correct order. More...
 
void callback_room_recv (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_room.c.

Function Documentation

◆ idle_request_room_messages()

static void idle_request_room_messages ( void *  cls)
static

Definition at line 782 of file gnunet-service-messenger_room.c.

References GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_TIME_relative_get_second_(), GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_SrvRoom::host, GNUNET_MESSENGER_SrvRoom::idle, GNUNET_MESSENGER_SrvRoom::last_messages, merge_room_last_messages(), GNUNET_MESSENGER_ListMessage::next, and search_room_for_message().

Referenced by create_room().

783 {
784  struct GNUNET_MESSENGER_SrvRoom *room = cls;
785 
786  room->idle = NULL;
787 
788  struct GNUNET_MESSENGER_ListMessage *element = room->last_messages.head;
789 
790  while (element)
791  {
792  search_room_for_message (room, &(element->hash));
793 
794  element = element->next;
795  }
796 
797  merge_room_last_messages (room, room->host);
798 
801  cls);
802 }
struct GNUNET_MESSENGER_ListMessage * next
static void idle_request_room_messages(void *cls)
struct GNUNET_MESSENGER_ListMessage * head
static void search_room_for_message(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash)
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:1199
struct GNUNET_SCHEDULER_Task * idle
struct GNUNET_MESSENGER_ListMessages last_messages
void merge_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...
Run when otherwise idle.
struct GNUNET_MESSENGER_SrvHandle * host
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_(void)
Return relative time of 1s.
Definition: time.c:183
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_room()

struct GNUNET_MESSENGER_SrvRoom* create_room ( struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_HashCode key 
)

Creates and allocates a new room for a handle with a given key.

Parameters
handleHandle
keyKey of room
Returns
New room

Definition at line 37 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_SrvRoom::basement, GNUNET_MESSENGER_Service::dir, GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CONTAINER_multishortmap_create(), GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, handle, GNUNET_MESSENGER_SrvRoom::handling, GNUNET_MESSENGER_SrvRoom::host, GNUNET_MESSENGER_SrvRoom::idle, idle_request_room_messages(), init_list_messages(), init_list_tunnels(), init_message_store(), GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_SrvRoom::last_messages, load_service_room_and_messages(), GNUNET_MESSENGER_SrvRoom::member_infos, GNUNET_MESSENGER_SrvRoom::members, GNUNET_MESSENGER_SrvRoom::peer_message, GNUNET_MESSENGER_SrvRoom::port, GNUNET_MESSENGER_SrvRoom::requested, GNUNET_MESSENGER_SrvHandle::service, GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_SrvRoom::store, GNUNET_MESSENGER_SrvRoom::strict_access, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by entry_service_room(), GNUNET_MESSENGER_entry_room(), GNUNET_MESSENGER_open_room(), and open_service_room().

38 {
39  GNUNET_assert((handle) && (key));
40 
42 
43  room->service = handle->service;
44  room->host = handle;
45  room->port = NULL;
46 
47  GNUNET_memcpy(&(room->key), key, sizeof(struct GNUNET_HashCode));
48 
52 
53  init_message_store (&(room->store));
55 
56  init_list_tunnels (&(room->basement));
58 
59  room->peer_message = NULL;
60 
61  init_list_messages (&(room->handling));
62  room->idle = NULL;
63 
64  room->strict_access = GNUNET_NO;
65 
66  if (room->service->dir)
68 
70 
71  return room;
72 }
static void idle_request_room_messages(void *cls)
struct GNUNET_MESSENGER_Service * service
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void load_service_room_and_messages(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room)
Loads the local configuration for a given room of a service which contains the last messages hash and...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CADET_Port * port
struct GNUNET_CONTAINER_MultiShortmap * member_infos
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).
struct GNUNET_SCHEDULER_Task * idle
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:1223
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
struct GNUNET_MESSENGER_ListMessages last_messages
struct GNUNET_MESSENGER_Service * service
struct GNUNET_HashCode * peer_message
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
struct GNUNET_MESSENGER_ListMessages handling
A 512-bit hashcode.
Run when otherwise idle.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_MESSENGER_SrvHandle * host
void init_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Initializes list of tunnels peer identities as empty list.
struct GNUNET_MESSENGER_ListTunnels basement
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void init_message_store(struct GNUNET_MESSENGER_MessageStore *store)
Initializes a message store as fully empty.
struct GNUNET_CONTAINER_MultiHashMap * requested
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
struct GNUNET_MESSENGER_MessageStore store
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_destroy_tunnels()

static int iterate_destroy_tunnels ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Definition at line 75 of file gnunet-service-messenger_room.c.

References destroy_tunnel(), GNUNET_YES, and value.

Referenced by destroy_room().

76 {
77  struct GNUNET_MESSENGER_SrvTunnel *tunnel = value;
78  destroy_tunnel (tunnel);
79  return GNUNET_YES;
80 }
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
static char * value
Value of the record to add/remove.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_clear_members()

static int iterate_clear_members ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 83 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_Service::contacts, decrease_contact_rc(), destroy_contact(), get_contact_id_from_key(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, GNUNET_MESSENGER_SrvRoom::service, and value.

Referenced by destroy_room().

84 {
85  struct GNUNET_MESSENGER_SrvContact *contact = value;
86 
87  if (GNUNET_YES == decrease_contact_rc (contact))
88  {
89  struct GNUNET_MESSENGER_SrvRoom *room = cls;
90 
91  const struct GNUNET_HashCode *id = get_contact_id_from_key (contact);
92 
94  destroy_contact (contact);
95  }
96 
97  return GNUNET_YES;
98 }
void destroy_contact(struct GNUNET_MESSENGER_SrvContact *contact)
Destroys a contact and frees its memory fully.
int decrease_contact_rc(struct GNUNET_MESSENGER_SrvContact *contact)
Decreases the reference counter if possible (can not underflow!) of a given contact and returns GNUNE...
struct GNUNET_MESSENGER_Service * service
static char * value
Value of the record to add/remove.
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
A 512-bit hashcode.
const struct GNUNET_HashCode * get_contact_id_from_key(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the resulting hashcode of the public key from a given contact.
struct GNUNET_CONTAINER_MultiHashMap * contacts
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_destroy_member_infos()

static int iterate_destroy_member_infos ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 101 of file gnunet-service-messenger_room.c.

References clear_list_messages(), GNUNET_free, GNUNET_YES, GNUNET_MESSENGER_MemberInfo::session_messages, and value.

Referenced by destroy_room().

102 {
103  struct GNUNET_MESSENGER_MemberInfo *info = value;
104 
106 
107  GNUNET_free(info);
108  return GNUNET_YES;
109 }
static char * value
Value of the record to add/remove.
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
struct GNUNET_MESSENGER_ListMessages session_messages
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_room()

void destroy_room ( struct GNUNET_MESSENGER_SrvRoom room)

Destroys a room and frees its memory fully.

Parameters
roomRoom

Definition at line 112 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_SrvRoom::basement, clear_list_messages(), clear_list_tunnels(), clear_message_store(), GNUNET_MESSENGER_Service::dir, GNUNET_assert, GNUNET_CADET_close_port(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_free, GNUNET_SCHEDULER_cancel(), handle_room_messages(), GNUNET_MESSENGER_SrvRoom::host, GNUNET_MESSENGER_SrvRoom::idle, iterate_clear_members(), iterate_destroy_member_infos(), iterate_destroy_tunnels(), GNUNET_MESSENGER_SrvRoom::last_messages, GNUNET_MESSENGER_SrvRoom::member_infos, GNUNET_MESSENGER_SrvRoom::members, merge_room_last_messages(), GNUNET_MESSENGER_SrvRoom::peer_message, GNUNET_MESSENGER_SrvRoom::port, GNUNET_MESSENGER_SrvRoom::requested, save_service_room_and_messages(), GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_SrvRoom::store, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by close_handle_room(), close_service_room(), entry_service_room(), GNUNET_MESSENGER_entry_room(), GNUNET_MESSENGER_open_room(), iterate_destroy_room(), iterate_destroy_rooms(), and open_service_room().

113 {
114  GNUNET_assert(room);
115 
116  if (room->idle)
117  {
119 
120  room->idle = NULL;
121  }
122 
123  if (room->port)
125 
126  merge_room_last_messages (room, room->host);
127 
129  NULL);
130 
131  handle_room_messages (room);
132 
133  if (room->service->dir)
135 
138 
139  clear_message_store (&(room->store));
140 
142 
146 
147  clear_list_tunnels (&(room->basement));
149 
150  if (room->peer_message)
151  GNUNET_free(room->peer_message);
152 
153  GNUNET_free(room);
154 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int iterate_clear_members(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
void handle_room_messages(struct GNUNET_MESSENGER_SrvRoom *room)
Handles all queued up messages of a room to handle in correct order.
struct GNUNET_CADET_Port * port
struct GNUNET_CONTAINER_MultiShortmap * member_infos
static int iterate_destroy_tunnels(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
void save_service_room_and_messages(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room)
Saves the configuration for a given room of a service which contains the last messages hash and the r...
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
struct GNUNET_SCHEDULER_Task * idle
struct GNUNET_MESSENGER_ListMessages last_messages
struct GNUNET_MESSENGER_Service * service
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_HashCode * peer_message
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void merge_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 clear_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Clears the list of tunnels peer identities.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_MESSENGER_SrvHandle * host
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *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.
struct GNUNET_MESSENGER_ListTunnels basement
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port().
Definition: cadet_api.c:808
struct GNUNET_CONTAINER_MultiHashMap * requested
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
static int iterate_destroy_member_infos(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
struct GNUNET_MESSENGER_MessageStore store
#define GNUNET_free(ptr)
Wrapper around free.
void clear_message_store(struct GNUNET_MESSENGER_MessageStore *store)
Clears a message store, wipes its content and deallocates its memory.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_room_contact()

struct GNUNET_MESSENGER_SrvContact* get_room_contact ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_ShortHashCode id 
)

Returns the contact of a member in a room identified by a given id.

If the room does not contain a member with the given id, NULL gets returned.

Parameters
roomRoom
idMember id
Returns
Contact or NULL

Definition at line 157 of file gnunet-service-messenger_room.c.

References GNUNET_assert, GNUNET_CONTAINER_multishortmap_get(), and GNUNET_MESSENGER_SrvRoom::members.

Referenced by handle_message_join(), handle_message_key(), and handle_message_name().

158 {
159  GNUNET_assert((room) && (room->members));
160 
161  return GNUNET_CONTAINER_multishortmap_get (room->members, id);
162 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiShortmap * members
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_room_contact()

void add_room_contact ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_ShortHashCode id,
const struct GNUNET_IDENTITY_PublicKey pubkey 
)

Adds a contact from the service to a room under a specific id with a given public key.

Parameters
roomRoom
idMember id
pubkeyPublic key of EGO

Definition at line 165 of file gnunet-service-messenger_room.c.

References get_service_contact_by_pubkey(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multishortmap_put(), GNUNET_OK, increase_contact_rc(), GNUNET_MESSENGER_SrvRoom::members, and GNUNET_MESSENGER_SrvRoom::service.

Referenced by handle_message_join().

167 {
168  struct GNUNET_MESSENGER_SrvContact *contact = get_service_contact_by_pubkey (room->service, pubkey);
169 
170  if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put (room->members, id, contact,
172  increase_contact_rc (contact);
173 }
void increase_contact_rc(struct GNUNET_MESSENGER_SrvContact *contact)
Increases the reference counter of a given contact which is zero as default.
struct GNUNET_MESSENGER_Service * service
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_MESSENGER_SrvContact * get_service_contact_by_pubkey(struct GNUNET_MESSENGER_Service *service, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Returns a contact of a service identified by a given public key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_room_member_info()

struct GNUNET_MESSENGER_MemberInfo* get_room_member_info ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_ShortHashCode id 
)

Returns the member information of a member in a room identified by a given id.

If the room does not contain a member with the given id, NULL gets returned.

Parameters
roomRoom
idMember id
Returns
Member information or NULL

Definition at line 176 of file gnunet-service-messenger_room.c.

References GNUNET_assert, GNUNET_CONTAINER_multishortmap_get(), and GNUNET_MESSENGER_SrvRoom::member_infos.

Referenced by handle_message_id(), handle_message_join(), handle_message_key(), handle_message_leave(), and handle_message_name().

177 {
178  GNUNET_assert((room) && (room->member_infos));
179 
181 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiShortmap * member_infos
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_room_member_id()

struct GNUNET_ShortHashCode* generate_room_member_id ( const struct GNUNET_MESSENGER_SrvRoom room)

Tries to generate and allocate a new unique member id checking all current members for possible duplicates.

If the function fails, NULL gets returned.

Parameters
roomRoom
Returns
New member id or NULL

Definition at line 184 of file gnunet-service-messenger_room.c.

References generate_free_member_id(), GNUNET_assert, GNUNET_free, GNUNET_new, GNUNET_YES, and GNUNET_MESSENGER_SrvRoom::members.

Referenced by generate_service_new_member_id().

185 {
186  struct GNUNET_ShortHashCode *unique_id = GNUNET_new(struct GNUNET_ShortHashCode);
187 
188  GNUNET_assert(room);
189 
190  if (GNUNET_YES == generate_free_member_id (unique_id, room->members))
191  return unique_id;
192  else
193  {
194  GNUNET_free(unique_id);
195  return NULL;
196  }
197 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A 256-bit hashcode.
struct GNUNET_CONTAINER_MultiShortmap * members
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.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_room_host_id()

const struct GNUNET_ShortHashCode* get_room_host_id ( const struct GNUNET_MESSENGER_SrvRoom room)

Returns the member id of the member representing the handle currently hosting this room.

Parameters
roomRoom
Returns
Host member id or NULL

Definition at line 200 of file gnunet-service-messenger_room.c.

References get_handle_member_id(), GNUNET_assert, GNUNET_MESSENGER_SrvRoom::host, and GNUNET_MESSENGER_SrvRoom::key.

Referenced by recv_message_info(), and recv_message_join().

201 {
202  GNUNET_assert(room);
203 
204  return get_handle_member_id (room->host, &(room->key));
205 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_SrvHandle * host
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ change_room_host_id()

void change_room_host_id ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_ShortHashCode unique_id 
)

Changes the member id of the member representing the handle currently hosting this room.

Parameters
roomRoom
unique_idUnique member id

Definition at line 208 of file gnunet-service-messenger_room.c.

References change_handle_member_id(), GNUNET_assert, GNUNET_MESSENGER_SrvRoom::host, and GNUNET_MESSENGER_SrvRoom::key.

Referenced by recv_message_info().

209 {
210  GNUNET_assert(room);
211 
212  change_handle_member_id (room->host, &(room->key), unique_id);
213 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void change_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.
struct GNUNET_MESSENGER_SrvHandle * host
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_room_info()

static int send_room_info ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
struct GNUNET_MESSENGER_SrvTunnel tunnel 
)
static

Definition at line 216 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_SrvTunnel::contact_id, create_message_info(), destroy_message(), get_handle_ego(), GNUNET_free, GNUNET_memcpy, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_MessageBody::info, is_tunnel_connected(), GNUNET_MESSENGER_SrvRoom::members, merge_room_last_messages(), GNUNET_MESSENGER_SrvTunnel::peer_message, send_tunnel_message(), and GNUNET_MESSENGER_MessageInfo::unique_id.

Referenced by callback_room_connect().

218 {
219  if (!handle)
220  return GNUNET_NO;
221 
222  merge_room_last_messages (room, handle);
223 
224  if (!is_tunnel_connected (tunnel))
225  return GNUNET_NO;
226 
227  struct GNUNET_MESSENGER_Message *message = create_message_info (get_handle_ego(handle), room->members);
228 
229  if (!message)
230  return GNUNET_NO;
231 
232  if ((tunnel->peer_message) && (tunnel->contact_id))
233  {
234  GNUNET_memcpy(&(message->body.info.unique_id), &(tunnel->contact_id), sizeof(struct GNUNET_ShortHashCode));
235  GNUNET_free(tunnel->contact_id);
236 
237  tunnel->contact_id = NULL;
238  }
239 
240  struct GNUNET_HashCode hash;
241 
242  send_tunnel_message (tunnel, handle, message, &hash);
243  destroy_message (message);
244 
245  if (tunnel->contact_id)
246  {
247  GNUNET_free(tunnel->contact_id);
248 
249  tunnel->contact_id = NULL;
250  }
251 
252  return GNUNET_YES;
253 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_Ego * get_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.
struct GNUNET_ShortHashCode unique_id
The new unique id for the receiver in a room.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MESSENGER_Message * create_message_info(struct GNUNET_MESSENGER_Ego *ego, struct GNUNET_CONTAINER_MultiShortmap *members)
Creates and allocates a new info message containing the hosts public key and a newly generated unique...
A 256-bit hashcode.
int is_tunnel_connected(const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Returns the status of a currently bound channel of a tunnel.
void merge_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...
struct GNUNET_MESSENGER_MessageBody body
Body.
void send_tunnel_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
Sends a message by packing it automatically into an envelope and passing it through the tunnel...
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_MESSENGER_MessageInfo info
struct GNUNET_ShortHashCode * contact_id
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_room_connect()

static void* callback_room_connect ( void *  cls,
struct GNUNET_CADET_Channel channel,
const struct GNUNET_PeerIdentity source 
)
static

Definition at line 256 of file gnunet-service-messenger_room.c.

References bind_tunnel(), GNUNET_MESSENGER_SrvTunnel::channel, create_tunnel(), delayed_disconnect_channel(), destroy_tunnel(), disconnect_tunnel(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_SrvRoom::host, send_room_info(), and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by open_room().

257 {
258  struct GNUNET_MESSENGER_SrvRoom *room = cls;
259 
261 
262  if (tunnel)
263  {
264  if (GNUNET_YES == bind_tunnel (tunnel, channel))
265  {
266  if (GNUNET_YES == send_room_info (room, room->host, tunnel))
267  return tunnel;
268  else
269  {
270  disconnect_tunnel (tunnel);
271  return NULL;
272  }
273  }
274  else
275  {
276  delayed_disconnect_channel (channel);
277  return NULL;
278  }
279  }
280  else
281  {
282  tunnel = create_tunnel (room, source);
283 
284  if ((GNUNET_YES == bind_tunnel (tunnel, channel)) && (GNUNET_OK
285  == GNUNET_CONTAINER_multipeermap_put (room->tunnels, source, tunnel,
287  {
288  if (GNUNET_YES == send_room_info (room, room->host, tunnel))
289  return tunnel;
290  else
291  {
292  GNUNET_CONTAINER_multipeermap_remove (room->tunnels, source, tunnel);
293 
294  disconnect_tunnel (tunnel);
295  destroy_tunnel (tunnel);
296  return NULL;
297  }
298  }
299  else
300  {
301  tunnel->channel = NULL;
302  destroy_tunnel (tunnel);
303 
304  delayed_disconnect_channel (channel);
305  return NULL;
306  }
307  }
308 }
void delayed_disconnect_channel(struct GNUNET_CADET_Channel *channel)
Starts an urgent task to close a CADET channel asynchronously.
int 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.
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
static int send_room_info(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
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.
struct GNUNET_MESSENGER_SrvHandle * host
struct GNUNET_CADET_Channel * channel
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.
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 bind_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel)
Binds a CADET channel to a tunnel on returns GNUNET_YES only if the bounds channel was replaced succe...
void disconnect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Disconnects and unbinds a channel from a tunnel.
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
Here is the call graph for this function:
Here is the caller graph for this function:

◆ join_room()

static int join_room ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_ShortHashCode member_id 
)
static

Definition at line 311 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_MemberInfo::access, add_to_list_messages(), change_handle_member_id(), create_message_join(), destroy_message(), get_handle_ego(), get_room_key(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multishortmap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_MEMBER_ALLOWED, GNUNET_new, GNUNET_NO, GNUNET_sh2s(), GNUNET_YES, init_list_messages(), GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_SrvRoom::member_infos, send_room_message(), and GNUNET_MESSENGER_MemberInfo::session_messages.

Referenced by join_room_locally(), and open_room().

313 {
314  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Joining room: %s (%s)\n", GNUNET_h2s(get_room_key(room)), GNUNET_sh2s(member_id));
315 
316  struct GNUNET_MESSENGER_Message *message = create_message_join (get_handle_ego(handle));
317 
318  if (!message)
319  {
320  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Your join message could not be created!\n");
321 
322  return GNUNET_NO;
323  }
324 
325  struct GNUNET_HashCode hash;
326 
327  send_room_message (room, handle, message, &hash);
328  destroy_message (message);
329 
331 
334 
335  if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_put (room->member_infos, member_id, info,
337  {
338  change_handle_member_id (handle, &(room->key), member_id);
339 
340  add_to_list_messages (&(info->session_messages), &hash);
341  return GNUNET_YES;
342  }
343  else
344  {
345  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Your member information could not be registered!\n");
346 
347  GNUNET_free(info);
348  return GNUNET_NO;
349  }
350 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_Ego * get_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.
struct GNUNET_HashCode * get_room_key(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void change_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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONTAINER_MultiShortmap * member_infos
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
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.
struct GNUNET_MESSENGER_Message * create_message_join(struct GNUNET_MESSENGER_Ego *ego)
Creates and allocates a new join message containing the clients public key.
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
A 512-bit hashcode.
void send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
Sends a message from a given handle into a room.
#define GNUNET_log(kind,...)
struct GNUNET_MESSENGER_ListMessages session_messages
enum GNUNET_MESSENGER_MemberAccess access
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ join_room_locally()

static int join_room_locally ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle 
)
static

Definition at line 353 of file gnunet-service-messenger_room.c.

References callback_tunnel_disconnect(), check_tunnel_message(), get_handle_member_id(), GNUNET_CONTAINER_multishortmap_get(), GNUNET_NO, GNUNET_YES, handle_tunnel_message(), join_room(), GNUNET_MESSENGER_SrvRoom::key, and GNUNET_MESSENGER_SrvRoom::member_infos.

Referenced by entry_room_at(), and open_room().

354 {
355  const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (handle, &(room->key));
356 
358 
359  if ((!info) && (GNUNET_NO == join_room (room, handle, member_id)))
360  return GNUNET_NO;
361 
362  return GNUNET_YES;
363 }
static int join_room(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_ShortHashCode *member_id)
struct GNUNET_CONTAINER_MultiShortmap * member_infos
A 256-bit hashcode.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_tunnel_message()

int check_tunnel_message ( void *  cls,
const struct GNUNET_MessageHeader header 
)

Definition at line 111 of file gnunet-service-messenger_tunnel.c.

References GNUNET_MESSENGER_Message::body, callback_room_recv(), callback_verify_room_message(), GNUNET_MESSENGER_SrvTunnel::contact_id, decode_message(), GNUNET_memcmp, GNUNET_memcpy, GNUNET_MESSENGER_KIND_PEER, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_PEER_resolve(), GNUNET_SYSERR, GNUNET_YES, hash_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_SrvTunnel::peer, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageBody::peer, result, GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MessageHeader::size.

Referenced by join_room_locally().

112 {
113  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
114 
115  if (!tunnel)
116  return GNUNET_NO;
117 
118  const uint16_t length = ntohs (header->size) - sizeof(*header);
119  const char *buffer = (const char*) &header[1];
120 
121  struct GNUNET_MESSENGER_Message message;
122 
123  if (length < sizeof(message.header))
124  return GNUNET_NO;
125 
126  if (GNUNET_YES != decode_message (&message, length, buffer))
127  return GNUNET_NO;
128 
129  struct GNUNET_HashCode hash;
130  hash_message (length, buffer, &hash);
131 
132  int result = callback_verify_room_message (tunnel->room, cls, &message, &hash);
133 
134  if (GNUNET_MESSENGER_KIND_PEER == message.header.kind)
135  {
137 
138  GNUNET_PEER_resolve (tunnel->peer, &identity);
139 
140  if (0 == GNUNET_memcmp(&(message.body.peer.peer), &(identity)))
141  {
142  if (tunnel->contact_id)
143  {
144  if (0 != GNUNET_memcmp(tunnel->contact_id, &(message.header.sender_id)))
145  result = GNUNET_SYSERR;
146  }
147  else
148  {
149  tunnel->contact_id = GNUNET_new(struct GNUNET_ShortHashCode);
150 
151  GNUNET_memcpy(tunnel->contact_id, &(message.header.sender_id), sizeof(struct GNUNET_ShortHashCode));
152  }
153  }
154  }
155 
156  return (result == GNUNET_YES ? GNUNET_OK : GNUNET_NO);
157 }
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer)
Decodes a message from a given buffer of a maximal length in bytes.
void hash_message(uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer of a length in bytes.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:225
A 256-bit hashcode.
int callback_verify_room_message(struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
struct GNUNET_MESSENGER_SrvRoom * room
static int result
Global testing status.
A 512-bit hashcode.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_ShortHashCode * contact_id
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_tunnel_message()

void handle_tunnel_message ( void *  cls,
const struct GNUNET_MessageHeader header 
)

Definition at line 164 of file gnunet-service-messenger_tunnel.c.

References callback_room_recv(), GNUNET_MESSENGER_SrvTunnel::channel, copy_message(), decode_message(), GNUNET_CADET_receive_done(), GNUNET_memcpy, GNUNET_new, hash_message(), GNUNET_MESSENGER_SrvTunnel::last_message, GNUNET_MESSENGER_SrvTunnel::room, and GNUNET_MessageHeader::size.

Referenced by join_room_locally().

165 {
166  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
167 
168  const uint16_t length = ntohs (header->size) - sizeof(*header);
169  const char *buffer = (const char*) &header[1];
170 
171  struct GNUNET_MESSENGER_Message message;
172  struct GNUNET_HashCode hash;
173 
174  decode_message (&message, length, buffer);
175  hash_message (length, buffer, &hash);
176 
177  if (tunnel)
178  {
179  if (!tunnel->last_message)
180  tunnel->last_message = GNUNET_new(struct GNUNET_HashCode);
181 
182  GNUNET_memcpy(tunnel->last_message, &hash, sizeof(struct GNUNET_HashCode));
183 
184  callback_room_recv (tunnel->room, cls, copy_message (&message), &hash);
185  }
186 
188 }
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer)
Decodes a message from a given buffer of a maximal length in bytes.
void hash_message(uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer of a length in bytes.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_MESSENGER_SrvRoom * room
void callback_room_recv(struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
A 512-bit hashcode.
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
struct GNUNET_CADET_Channel * channel
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:888
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_tunnel_disconnect()

void callback_tunnel_disconnect ( void *  cls,
const struct GNUNET_CADET_Channel channel 
)

Definition at line 94 of file gnunet-service-messenger_tunnel.c.

References callback_room_disconnect(), callback_verify_room_message(), GNUNET_MESSENGER_SrvTunnel::channel, and GNUNET_MESSENGER_SrvTunnel::room.

Referenced by connect_tunnel(), join_room_locally(), and open_room().

95 {
96  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
97 
98  if (tunnel)
99  {
100  tunnel->channel = NULL;
101 
102  callback_room_disconnect (tunnel->room, cls);
103  }
104 }
struct GNUNET_MESSENGER_SrvRoom * room
void callback_room_disconnect(struct GNUNET_MESSENGER_SrvRoom *room, void *cls)
struct GNUNET_CADET_Channel * channel
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_room()

int open_room ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle 
)

Tries to open a room for a given handle.

If the room has already been opened, the handle will locally join the room.

Calling this method should result in joining a room and sending a peer message as well for this peer.

If the function returns GNUNET_YES the port for this room is guranteed to be open for incoming connections.

Parameters
roomRoom
handleHandle
Returns
GNUNET_YES on success, GNUNET_NO on failure.

Definition at line 374 of file gnunet-service-messenger_room.c.

References cadet, callback_room_connect(), callback_tunnel_disconnect(), create_message_peer(), destroy_message(), get_handle_member_id(), get_room_cadet(), get_room_key(), GNUNET_CADET_close_port(), GNUNET_CADET_open_port(), GNUNET_CONTAINER_multishortmap_get(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_YES, join_room(), join_room_locally(), key, GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_SrvRoom::member_infos, GNUNET_MESSENGER_SrvRoom::port, send_room_message(), and GNUNET_MESSENGER_SrvRoom::service.

Referenced by open_service_room().

375 {
376  if (room->port)
377  return join_room_locally (room, handle);
378 
379  struct GNUNET_CADET_Handle *cadet = get_room_cadet (room);
380  struct GNUNET_HashCode *key = get_room_key (room);
381 
383  struct GNUNET_MessageHeader, NULL),
385 
386  room->port = GNUNET_CADET_open_port (cadet, key, callback_room_connect, room, NULL,
387  callback_tunnel_disconnect, handlers);
388 
389  const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (handle, &(room->key));
390 
392 
393  if ((!info) && (GNUNET_NO == join_room (room, handle, member_id)) && (room->port))
394  {
395  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not join the room, therefore it keeps closed!\n");
396 
398  room->port = NULL;
399 
400  return GNUNET_NO;
401  }
402 
403  struct GNUNET_MESSENGER_Message *message = create_message_peer (room->service);
404 
405  if (message)
406  {
407  struct GNUNET_HashCode hash;
408 
409  send_room_message (room, handle, message, &hash);
410  destroy_message (message);
411  }
412 
413  return (room->port ? GNUNET_YES : GNUNET_NO);
414 }
static struct GNUNET_CADET_Handle * cadet
Handle for cadet.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_HashCode * get_room_key(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
Opaque handle to the service.
Definition: cadet_api.c:38
static void * callback_room_connect(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source)
static int join_room(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_ShortHashCode *member_id)
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
struct GNUNET_CADET_Port * port
struct GNUNET_CONTAINER_MultiShortmap * member_infos
struct GNUNET_CADET_Handle * get_room_cadet(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the CADET handle from a rooms service.
A 256-bit hashcode.
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 incomming MQ-based channels.
Definition: cadet_api.c:970
struct GNUNET_MESSENGER_Service * service
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
A 512-bit hashcode.
Message handler for a specific message type.
struct GNUNET_HashCode key
The key used in the DHT.
void callback_tunnel_disconnect(void *cls, const struct GNUNET_CADET_Channel *channel)
void send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
Sends a message from a given handle into a room.
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.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_log(kind,...)
Header for all communications.
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port().
Definition: cadet_api.c:808
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
static int join_room_locally(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ entry_room_at()

int entry_room_at ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_PeerIdentity door 
)

Connects a tunnel to a hosting peer of a room through a so called door which is represented by a peer identity of a hosting peer.

During the connection the handle will join the room as a member, waiting for an info message from the selected host.

Parameters
roomRoom
handleHandle
doorPeer identity
Returns
GNUNET_YES on success, GNUNET_NO on failure.

Definition at line 417 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_Message::body, connect_tunnel(), create_tunnel(), destroy_tunnel(), get_room_message(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcmp, GNUNET_NO, GNUNET_OK, GNUNET_YES, join_room_locally(), msg, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_SrvRoom::peer_message, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by entry_service_room().

419 {
420  if (room->peer_message)
421  {
422  const struct GNUNET_MESSENGER_Message *msg = get_room_message (room, handle, room->peer_message, GNUNET_NO);
423 
424  if (0 == GNUNET_memcmp(&(msg->body.peer.peer), door))
425  return join_room_locally (room, handle);
426  }
427 
429 
430  if (tunnel)
431  {
432  switch (connect_tunnel (tunnel))
433  {
434  case GNUNET_YES:
435  return GNUNET_YES;
436  case GNUNET_NO:
437  return join_room_locally (room, handle);
438  default:
439  return GNUNET_NO;
440  }
441  }
442 
443  tunnel = create_tunnel (room, door);
444 
445  if ((GNUNET_YES == connect_tunnel (tunnel)) &&
446  (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (room->tunnels, door, tunnel,
448  return GNUNET_YES;
449  else
450  {
451  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not connect to that door!\n");
452 
453  destroy_tunnel (tunnel);
454  return GNUNET_NO;
455  }
456 }
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
int connect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Tries to connect a tunnel by creating a new CADET channel and binding it.
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_HashCode * peer_message
struct GNUNET_MESSENGER_MessageBody body
Body.
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.
struct GNUNET_MESSENGER_MessagePeer peer
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
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.
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.
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
static int join_room_locally(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_find_tunnel()

static int iterate_find_tunnel ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Definition at line 465 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_SrvTunnel::contact_id, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_SrvTunnelFinder::needle, GNUNET_MESSENGER_SrvTunnelFinder::tunnel, and value.

Referenced by find_room_tunnel_to().

466 {
467  struct GNUNET_MESSENGER_SrvTunnel *tunnel = value;
468  struct GNUNET_MESSENGER_SrvTunnelFinder *finder = cls;
469 
470  if ((tunnel->contact_id) && (0 == GNUNET_memcmp(tunnel->contact_id, finder->needle)))
471  {
472  finder->tunnel = tunnel;
473  return GNUNET_NO;
474  }
475 
476  return GNUNET_YES;
477 }
const struct GNUNET_ShortHashCode * needle
static char * value
Value of the record to add/remove.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_ShortHashCode * contact_id
struct GNUNET_MESSENGER_SrvTunnel * tunnel
Here is the caller graph for this function:

◆ find_room_tunnel_to()

struct GNUNET_MESSENGER_SrvTunnel* find_room_tunnel_to ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_ShortHashCode contact_id 
)

Returns a tunnel granting a direct connection to a specific member in a room.

The member gets identified by an id. If no tunnel has been linked to the selected id, NULL gets returned.

Parameters
roomRoom
contact_idMember id
Returns
Tunnel to the member or NULL

Definition at line 480 of file gnunet-service-messenger_room.c.

References GNUNET_CONTAINER_multipeermap_iterate(), iterate_find_tunnel(), GNUNET_MESSENGER_SrvTunnelFinder::needle, GNUNET_MESSENGER_SrvTunnelFinder::tunnel, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by recv_message_join().

481 {
482  struct GNUNET_MESSENGER_SrvTunnelFinder finder;
483 
484  finder.needle = contact_id;
485  finder.tunnel = NULL;
486 
488 
489  return finder.tunnel;
490 }
const struct GNUNET_ShortHashCode * needle
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int iterate_find_tunnel(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pack_room_message()

struct GNUNET_MQ_Envelope* pack_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
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.

It will set the timestamp of the message, the sender id and the previous messages hash automatically before packing. The message will be signed by the handles EGO.

If the optional hash parameter is a valid pointer, its value will be overriden by the signed messages hash.

If mode is set to GNUNET_MESSENGER_PACK_MODE_ENVELOPE, the function returns a valid envelope to send through a message queue, otherwise NULL.

Parameters
roomRoom
handleHandle
messageMessage
[out]hashHash of message
modePacking mode
Returns
New envelope or NULL

Definition at line 493 of file gnunet-service-messenger_room.c.

References get_handle_ego(), get_handle_member_id(), GNUNET_assert, GNUNET_memcpy, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_SrvRoom::last_messages, pack_message(), GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by iterate_send_room_message(), send_room_message(), send_room_message_ext(), and send_tunnel_message().

495 {
497 
498  const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, &(room->key));
499 
500  GNUNET_assert(id);
501 
502  GNUNET_memcpy(&(message->header.sender_id), id, sizeof(struct GNUNET_ShortHashCode));
503 
504  if (room->last_messages.head)
505  GNUNET_memcpy(&(message->header.previous), &(room->last_messages.head->hash), sizeof(struct GNUNET_HashCode));
506  else
507  memset (&(message->header.previous), 0, sizeof(struct GNUNET_HashCode));
508 
509  return pack_message (message, hash, get_handle_ego (handle), mode);
510 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_MESSENGER_Ego * get_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.
struct GNUNET_MESSENGER_ListMessage * head
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
A 256-bit hashcode.
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...
struct GNUNET_MESSENGER_ListMessages last_messages
A 512-bit hashcode.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_send_room_message()

static int iterate_send_room_message ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Definition at line 523 of file gnunet-service-messenger_room.c.

References callback_room_sent(), GNUNET_MESSENGER_SrvTunnel::contact_id, copy_message(), env, GNUNET_MESSENGER_ClosureSendRoom::exclude, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_NO, GNUNET_YES, handle, GNUNET_MESSENGER_ClosureSendRoom::handle, GNUNET_MESSENGER_ClosureSendRoom::hash, is_tunnel_connected(), GNUNET_MESSENGER_ClosureSendRoom::message, pack_message(), pack_room_message(), GNUNET_MESSENGER_ClosureSendRoom::packed, GNUNET_MESSENGER_ClosureSendRoom::room, send_tunnel_envelope(), GNUNET_MESSENGER_SrvTunnelFinder::tunnel, and value.

Referenced by forward_room_message(), send_room_message(), and send_room_message_ext().

524 {
525  struct GNUNET_MESSENGER_SrvTunnel *tunnel = value;
526 
527  if ((!is_tunnel_connected (tunnel)) || (!tunnel->contact_id))
528  return GNUNET_YES;
529 
530  struct GNUNET_MESSENGER_ClosureSendRoom *closure = cls;
531 
532  if (tunnel == closure->exclude)
533  return GNUNET_YES;
534 
535  struct GNUNET_MQ_Envelope *env = NULL;
536 
537  if (closure->packed == GNUNET_NO)
538  {
539  env = pack_room_message (closure->room, closure->handle, closure->message, closure->hash,
541 
542  if (env)
543  {
544  closure->message = copy_message (closure->message);
545  closure->packed = GNUNET_YES;
546  }
547  }
548  else
549  {
550  env = pack_message (closure->message, NULL, NULL,
552  }
553 
554  if (env)
555  send_tunnel_envelope (tunnel, closure->handle, env, closure->message, closure->hash);
556 
557  return GNUNET_YES;
558 }
struct GNUNET_MESSENGER_SrvHandle * handle
int is_tunnel_connected(const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Returns the status of a currently bound channel of a tunnel.
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...
static char * value
Value of the record to add/remove.
struct GNUNET_MESSENGER_SrvRoom * room
void send_tunnel_envelope(struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MQ_Envelope *env, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Sends an envelope containing a message with a given hash through a tunnel by a given handle...
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_MQ_Envelope * pack_room_message(struct GNUNET_MESSENGER_SrvRoom *room, 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.
struct GNUNET_MESSENGER_SrvTunnel * exclude
struct GNUNET_ShortHashCode * contact_id
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_room_sent()

void callback_room_sent ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
void *  cls,
struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Definition at line 998 of file gnunet-service-messenger_room.c.

References add_to_list_messages(), get_room_message(), GNUNET_free, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_NO, GNUNET_OK, GNUNET_YES, handle_room_messages(), GNUNET_MESSENGER_SrvRoom::handling, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, put_store_message(), send_message_id(), send_message_info(), send_message_join(), send_message_key(), send_message_leave(), send_message_miss(), send_message_name(), send_message_peer(), GNUNET_MESSENGER_SrvRoom::store, GNUNET_MESSENGER_SrvTunnelFinder::tunnel, and update_room_last_messages().

Referenced by iterate_send_room_message(), send_room_message(), send_room_message_ext(), and send_tunnel_envelope().

1000 {
1001  const struct GNUNET_MESSENGER_Message *old_message = get_room_message (room, handle, hash, GNUNET_NO);
1002 
1003  if ((old_message) || (GNUNET_OK != put_store_message (&(room->store), hash, message)))
1004  {
1005  if (old_message != message)
1006  GNUNET_free(message);
1007  }
1008  else
1009  {
1010  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; // may be NULL
1011 
1012  update_room_last_messages (room, message, hash);
1013 
1014  const int start_handle = room->handling.head ? GNUNET_NO : GNUNET_YES;
1015 
1016  add_to_list_messages (&(room->handling), hash);
1017 
1018  switch (message->header.kind)
1019  {
1021  send_message_info (room, handle, tunnel, message, hash);
1022  break;
1024  send_message_join (room, handle, tunnel, message, hash);
1025  break;
1027  send_message_leave (room, handle, tunnel, message, hash);
1028  break;
1030  send_message_name (room, handle, tunnel, message, hash);
1031  break;
1033  send_message_key (room, handle, tunnel, message, hash);
1034  break;
1036  send_message_peer (room, handle, tunnel, message, hash);
1037  break;
1039  send_message_id (room, handle, tunnel, message, hash);
1040  break;
1042  send_message_miss (room, handle, tunnel, message, hash);
1043  break;
1044  default:
1045  break;
1046  }
1047 
1048  if (GNUNET_YES == start_handle)
1049  handle_room_messages (room);
1050  }
1051 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_ListMessage * head
void send_message_leave(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent leave message.
void send_message_join(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent join message to ensure growth of the decentralized room structure. ...
void update_room_last_messages(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Updates the last messages of a room by replacing them if the previous hash of a given message matches...
void handle_room_messages(struct GNUNET_MESSENGER_SrvRoom *room)
Handles all queued up messages of a room to handle in correct order.
void send_message_miss(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent miss message.
void send_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent id message.
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 send_message_info(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent info message to setup a tunnels linked member id.
struct GNUNET_MESSENGER_ListMessages handling
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
void send_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent peer message to update the rooms peer message of this service.
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.
void send_message_name(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent name message.
void send_message_key(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent key message.
struct GNUNET_MESSENGER_MessageStore store
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_room_message()

void send_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash 
)

Sends a message from a given handle into a room.

The hash parameter will be updated with the hash-value resulting from the sent message.

The function handles packing the message automatically and will call linked message-events locally even if the message won't be sent to another peer.

Parameters
roomRoom
handleHandle
messageMessage
[out]hashHash of message

Definition at line 565 of file gnunet-service-messenger_room.c.

References callback_room_sent(), copy_message(), GNUNET_MESSENGER_ClosureSendRoom::exclude, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MESSENGER_PACK_MODE_UNKNOWN, GNUNET_NO, handle, GNUNET_MESSENGER_ClosureSendRoom::handle, GNUNET_MESSENGER_ClosureSendRoom::hash, iterate_send_room_message(), GNUNET_MESSENGER_ClosureSendRoom::message, pack_room_message(), GNUNET_MESSENGER_ClosureSendRoom::packed, GNUNET_MESSENGER_ClosureSendRoom::room, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by callback_room_disconnect(), close_service_room(), get_room_message(), join_room(), merge_room_last_messages(), open_room(), and send_handle_message().

567 {
568  struct GNUNET_MESSENGER_ClosureSendRoom closure;
569 
570  closure.room = room;
571  closure.handle = handle;
572  closure.exclude = NULL;
573  closure.message = message;
574  closure.hash = hash;
575  closure.packed = GNUNET_NO;
576 
578 
579  if ((GNUNET_NO == closure.packed) && (closure.message == message))
580  {
581  pack_room_message (room, handle, message, hash,
583 
584  callback_room_sent (room, handle, NULL, copy_message (message), hash);
585  }
586 }
static int iterate_send_room_message(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
void callback_room_sent(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, void *cls, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
#define GNUNET_MESSENGER_PACK_MODE_UNKNOWN
struct GNUNET_MESSENGER_SrvRoom * room
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_MQ_Envelope * pack_room_message(struct GNUNET_MESSENGER_SrvRoom *room, 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.
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_room_message_ext()

void send_room_message_ext ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash,
struct GNUNET_MESSENGER_SrvTunnel tunnel 
)

Sends a message from a given handle into a room excluding one specific tunnel.

The hash parameter will be updated with the hash-value resulting from the sent message.

The function handles packing the message automatically and will call linked message-events locally even if the message won't be sent to another peer.

Parameters
roomRoom
handleHandle
messageMessage
[out]hashHash of message
tunnelTunnel

Definition at line 589 of file gnunet-service-messenger_room.c.

References callback_room_sent(), copy_message(), GNUNET_MESSENGER_ClosureSendRoom::exclude, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MESSENGER_PACK_MODE_UNKNOWN, GNUNET_NO, handle, GNUNET_MESSENGER_ClosureSendRoom::handle, GNUNET_MESSENGER_ClosureSendRoom::hash, iterate_send_room_message(), GNUNET_MESSENGER_ClosureSendRoom::message, pack_room_message(), GNUNET_MESSENGER_ClosureSendRoom::packed, GNUNET_MESSENGER_ClosureSendRoom::room, GNUNET_MESSENGER_SrvTunnelFinder::tunnel, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by recv_message_info().

592 {
593  struct GNUNET_MESSENGER_ClosureSendRoom closure;
594 
595  closure.room = room;
596  closure.handle = handle;
597  closure.exclude = tunnel;
598  closure.message = message;
599  closure.hash = hash;
600  closure.packed = GNUNET_NO;
601 
603 
604  if ((GNUNET_NO == closure.packed) && (closure.message == message))
605  {
606  pack_room_message (room, handle, message, hash,
608 
609  callback_room_sent (room, handle, NULL, copy_message (message), hash);
610  }
611 }
static int iterate_send_room_message(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
void callback_room_sent(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, void *cls, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
#define GNUNET_MESSENGER_PACK_MODE_UNKNOWN
struct GNUNET_MESSENGER_SrvRoom * room
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_MQ_Envelope * pack_room_message(struct GNUNET_MESSENGER_SrvRoom *room, 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.
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
Here is the call graph for this function:
Here is the caller graph for this function:

◆ forward_room_message()

void forward_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvTunnel tunnel,
const 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.

Parameters
roomRoom
tunnelTunnel
messageMessage
hashHash of message

Definition at line 614 of file gnunet-service-messenger_room.c.

References copy_message(), GNUNET_MESSENGER_ClosureSendRoom::exclude, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_memcpy, GNUNET_YES, GNUNET_MESSENGER_ClosureSendRoom::handle, GNUNET_MESSENGER_ClosureSendRoom::hash, iterate_send_room_message(), GNUNET_MESSENGER_ClosureSendRoom::message, GNUNET_MESSENGER_ClosureSendRoom::packed, GNUNET_MESSENGER_ClosureSendRoom::room, GNUNET_MESSENGER_SrvTunnelFinder::tunnel, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by callback_room_recv().

616 {
617  struct GNUNET_MESSENGER_ClosureSendRoom closure;
618  struct GNUNET_HashCode message_hash;
619 
620  GNUNET_memcpy(&message_hash, hash, sizeof(struct GNUNET_HashCode));
621 
622  closure.room = room;
623  closure.handle = NULL;
624  closure.exclude = tunnel;
625  closure.message = copy_message (message);
626  closure.hash = &message_hash;
627  closure.packed = GNUNET_YES;
628 
630 }
static int iterate_send_room_message(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
A 512-bit hashcode.
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
Here is the call graph for this function:
Here is the caller graph for this function:

◆ merge_room_last_messages()

void merge_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 merging them down.

All merge messages will be sent from a given handle.

Parameters
roomRoom
handleHandle

Definition at line 633 of file gnunet-service-messenger_room.c.

References create_message_merge(), destroy_message(), GNUNET_CONTAINER_DLL_remove, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_SrvRoom::last_messages, GNUNET_MESSENGER_ListMessage::prev, send_room_message(), and GNUNET_MESSENGER_ListMessages::tail.

Referenced by destroy_room(), idle_request_room_messages(), and send_room_info().

634 {
635  if (!handle)
636  return;
637 
638  if (!room->last_messages.head)
639  return;
640 
641  while (room->last_messages.head != room->last_messages.tail)
642  {
643  struct GNUNET_MESSENGER_ListMessage *element = room->last_messages.tail;
644 
645  struct GNUNET_MESSENGER_Message *message = create_message_merge (&(element->hash));
646 
647  if (message)
648  {
649  struct GNUNET_HashCode hash;
650 
651  send_room_message (room, handle, message, &hash);
652  destroy_message (message);
653  }
654 
655  if (element->prev)
657  }
658 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_ListMessage * head
struct GNUNET_MESSENGER_ListMessage * prev
struct GNUNET_MESSENGER_ListMessages last_messages
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...
A 512-bit hashcode.
struct GNUNET_MESSENGER_ListMessage * tail
void send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
Sends a message from a given handle into a room.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_room_cadet()

struct GNUNET_CADET_Handle* get_room_cadet ( struct GNUNET_MESSENGER_SrvRoom room)

Returns the CADET handle from a rooms service.

Parameters
roomRoom
Returns
CADET handle

Definition at line 661 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_Service::cadet, and GNUNET_MESSENGER_SrvRoom::service.

Referenced by connect_tunnel(), and open_room().

662 {
663  return room->service->cadet;
664 }
struct GNUNET_CADET_Handle * cadet
struct GNUNET_MESSENGER_Service * service
Here is the caller graph for this function:

◆ get_room_key()

struct GNUNET_HashCode* get_room_key ( struct GNUNET_MESSENGER_SrvRoom room)

Returns the shared secret you need to access a room.

Parameters
roomRoom
Returns
Shared secret

Definition at line 667 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_SrvRoom::key.

Referenced by connect_tunnel(), join_room(), and open_room().

668 {
669  return &(room->key);
670 }
Here is the caller graph for this function:

◆ get_room_tunnel()

const struct GNUNET_MESSENGER_SrvTunnel* get_room_tunnel ( 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, otherwise NULL.

Parameters
roomRoom
peerPeer identity
Returns
Tunnel or NULL

Definition at line 673 of file gnunet-service-messenger_room.c.

References GNUNET_CONTAINER_multipeermap_get(), and GNUNET_MESSENGER_SrvRoom::tunnels.

674 {
675  return GNUNET_CONTAINER_multipeermap_get (room->tunnels, peer);
676 }
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.
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
Here is the call graph for this function:

◆ get_room_message()

const struct GNUNET_MESSENGER_Message* get_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_HashCode hash,
int  request 
)

Returns a message from a room identified by a given hash.

If no matching message is found and request is set to GNUNET_YES, the handle will request the missing message automatically.

The function uses the optimized check for a message via its hash from the message store.

See also
contains_store_message()

If a message is missing independent of the following request, NULL gets returned instead of the matching message.

Parameters
roomRoom
handleHandle
hashHash of message
requestFlag to request a message
Returns
Message or NULL

Definition at line 679 of file gnunet-service-messenger_room.c.

References create_message_request(), destroy_message(), get_store_message(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_SrvRoom::requested, send_room_message(), and GNUNET_MESSENGER_SrvRoom::store.

Referenced by callback_room_sent(), entry_room_at(), GNUNET_MESSENGER_get_message(), handle_get_message(), handle_room_messages(), iterate_send_member_infos(), load_service_room_and_messages(), recv_message_join(), recv_message_request(), search_room_for_message(), and send_message_join().

681 {
682  const struct GNUNET_MESSENGER_Message *message = get_store_message (&(room->store), hash);
683 
684  if ((message) || (!handle) || (GNUNET_YES != request)
686  return message;
687 
688  struct GNUNET_MESSENGER_Message *request_msg = create_message_request (hash);
689 
690  if (request_msg)
691  {
693  {
694  struct GNUNET_HashCode request_hash;
695 
696  send_room_message (room, handle, request_msg, &request_hash);
697  }
698 
699  destroy_message (request_msg);
700  }
701 
702  return message;
703 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_MESSENGER_Message * create_message_request(const struct GNUNET_HashCode *hash)
Creates and allocates a new request message containing the hash of a missing message.
A 512-bit hashcode.
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 send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
Sends a message from a given handle into a room.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_MultiHashMap * requested
struct GNUNET_MESSENGER_MessageStore store
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_room_disconnect()

void callback_room_disconnect ( struct GNUNET_MESSENGER_SrvRoom room,
void *  cls 
)

Definition at line 706 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_SrvRoom::basement, contains_list_tunnels(), create_message_miss(), destroy_message(), GNUNET_PEER_resolve(), GNUNET_YES, GNUNET_MESSENGER_SrvRoom::host, GNUNET_MESSENGER_SrvTunnel::peer, send_room_message(), and GNUNET_MESSENGER_SrvTunnelFinder::tunnel.

Referenced by bind_tunnel(), and callback_tunnel_disconnect().

707 {
708  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
709 
710  if (!room->host)
711  return;
712 
714 
715  GNUNET_PEER_resolve (tunnel->peer, &identity);
716 
718  {
720 
721  if (message)
722  {
723  struct GNUNET_HashCode hash;
724 
725  send_room_message (room, room->host, message, &hash);
726  destroy_message (message);
727  }
728  }
729 }
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...
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:225
A 512-bit hashcode.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
struct GNUNET_MESSENGER_SrvHandle * host
struct GNUNET_MESSENGER_Message * create_message_miss(const struct GNUNET_PeerIdentity *peer)
Creates and allocates a new miss message containing the missing peer identity.
void send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
Sends a message from a given handle into a room.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_MESSENGER_ListTunnels basement
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_verify_room_message()

int callback_verify_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
void *  cls,
struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash 
)

Definition at line 732 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_MemberInfo::access, GNUNET_MESSENGER_Message::body, contains_store_message(), get_contact_key(), get_service_contact_by_pubkey(), GNUNET_CONTAINER_multishortmap_get(), GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_MEMBER_BLOCKED, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageInfo::host_key, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_SrvRoom::member_infos, GNUNET_MESSENGER_SrvRoom::members, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_SrvRoom::store, GNUNET_MESSENGER_SrvRoom::strict_access, and verify_message().

Referenced by callback_tunnel_disconnect(), and check_tunnel_message().

734 {
735  if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind)
736  return GNUNET_SYSERR;
737 
739  &(message->header.sender_id));
740 
741  if (!contact)
742  {
743  if (GNUNET_MESSENGER_KIND_INFO == message->header.kind)
744  contact = get_service_contact_by_pubkey (room->service, &(message->body.info.host_key));
745  else if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind)
746  contact = get_service_contact_by_pubkey (room->service, &(message->body.join.key));
747  }
748 
749  if ((!contact) || (GNUNET_SYSERR == verify_message (message, hash, get_contact_key (contact))))
750  return GNUNET_SYSERR;
751 
752  if (GNUNET_YES == room->strict_access)
753  {
755  &(message->header.sender_id));
756 
757  if ((info) && (GNUNET_MESSENGER_MEMBER_BLOCKED == info->access))
758  return GNUNET_SYSERR;
759  }
760 
761  if (GNUNET_YES == contains_store_message (&(room->store), hash))
762  return GNUNET_NO;
763 
764  return GNUNET_YES;
765 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_IDENTITY_PublicKey host_key
The senders key to verify its signatures.
struct GNUNET_CONTAINER_MultiShortmap * member_infos
struct GNUNET_MESSENGER_Service * service
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_MESSENGER_MessageBody body
Body.
int contains_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Checks if a message matching a given hash is stored in a message store.
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the public key of a given contact.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_MESSENGER_MessageInfo info
struct GNUNET_MESSENGER_SrvContact * get_service_contact_by_pubkey(struct GNUNET_MESSENGER_Service *service, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Returns a contact of a service identified by a given public key.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
enum GNUNET_MESSENGER_MemberAccess access
struct GNUNET_MESSENGER_MessageJoin join
int verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_IDENTITY_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
struct GNUNET_MESSENGER_MessageStore store
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_room_for_message()

static void search_room_for_message ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_HashCode hash 
)
static

Definition at line 768 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_Message::body, get_room_message(), GNUNET_MESSENGER_KIND_MERGE, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_SrvRoom::host, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageMerge::previous, and GNUNET_MESSENGER_MessageHeader::previous.

Referenced by idle_request_room_messages().

769 {
770  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, room->host, hash, GNUNET_YES);
771 
772  if (!message)
773  return;
774 
775  if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind)
776  search_room_for_message (room, &(message->body.merge.previous));
777 
778  search_room_for_message (room, &(message->header.previous));
779 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
static void search_room_for_message(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash)
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
struct GNUNET_MESSENGER_SrvHandle * host
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_room_last_messages()

void update_room_last_messages ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Updates the last messages of a room by replacing them if the previous hash of a given message matches with one of the latest messages.

Parameters
roomRoom
messageMessage
hashHash of message

Definition at line 805 of file gnunet-service-messenger_room.c.

References add_to_list_messages(), GNUNET_MESSENGER_Message::body, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_remove_all(), GNUNET_CRYPTO_hash_cmp(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_MERGE, GNUNET_YES, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_SrvRoom::last_messages, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_ListMessage::next, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_SrvRoom::requested, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by callback_room_recv(), callback_room_sent(), and load_service_room_and_messages().

807 {
808  struct GNUNET_MESSENGER_ListMessage *element = room->last_messages.head;
809  struct GNUNET_MESSENGER_ListMessage *merging = NULL;
810 
811  if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind)
812  {
813  merging = room->last_messages.head;
814 
815  while (merging)
816  {
817  if (0 == GNUNET_CRYPTO_hash_cmp (&(merging->hash), &(message->body.merge.previous)))
818  break;
819 
820  merging = merging->next;
821  }
822 
823  if (merging)
824  element = merging->next;
825  }
826 
827  while (element)
828  {
829  if (0 == GNUNET_CRYPTO_hash_cmp (&(element->hash), &(message->header.previous)))
830  break;
831 
832  element = element->next;
833  }
834 
835  if ((merging) && (!element))
836  {
837  element = merging;
838  merging = NULL;
839  }
840 
841  if (element)
842  {
843  GNUNET_memcpy(&(element->hash), hash, sizeof(struct GNUNET_HashCode));
844 
845  if (merging)
847  }
848  else
849  add_to_list_messages (&(room->last_messages), hash);
850 
853 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_ListMessage * head
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
int GNUNET_CONTAINER_multihashmap_remove_all(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Remove all entries for the given key from the map.
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
struct GNUNET_MESSENGER_ListMessages last_messages
struct GNUNET_HashCode previous
The hash of a second previous message.
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.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageMerge merge
A 512-bit hashcode.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
struct GNUNET_MESSENGER_ListMessage * tail
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:311
struct GNUNET_CONTAINER_MultiHashMap * requested
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ switch_room_member_id()

void switch_room_member_id ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_ShortHashCode old_id,
const struct GNUNET_ShortHashCode new_id,
const struct GNUNET_HashCode hash 
)

Changes an id of a current member from an old id to a new one and adds optionally the hash of an id message to the members information.

Parameters
roomRoom
old_idOld member id
new_idNew member id
hashHash of id message

Definition at line 856 of file gnunet-service-messenger_room.c.

References add_to_list_messages(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CONTAINER_multishortmap_remove(), GNUNET_YES, GNUNET_MESSENGER_SrvRoom::member_infos, GNUNET_MESSENGER_SrvRoom::members, and GNUNET_MESSENGER_MemberInfo::session_messages.

Referenced by handle_message_id(), and recv_message_info().

858 {
860 
861  if ((contact) && (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (room->members, old_id, contact)))
862  GNUNET_CONTAINER_multishortmap_put (room->members, new_id, contact,
864 
866 
867  if ((!info) || (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove (room->member_infos, old_id, contact))
868  || (GNUNET_YES != GNUNET_CONTAINER_multishortmap_put (room->member_infos, new_id, contact,
870  return;
871 
872  if (hash)
873  add_to_list_messages (&(info->session_messages), hash);
874 }
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
struct GNUNET_CONTAINER_MultiShortmap * member_infos
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
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.
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_MultiShortmap * members
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
struct GNUNET_MESSENGER_ListMessages session_messages
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rebuild_room_basement_structure()

void rebuild_room_basement_structure ( struct GNUNET_MESSENGER_SrvRoom room)

Rebuilds the decentralized structure for a room by ensuring all required connections are made depending on the amount of peers and this peers index in the list of them.

Parameters
roomRoom

Definition at line 877 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_SrvRoom::basement, connect_tunnel(), count_of_tunnels(), disconnect_tunnel(), find_list_tunnels(), get_service_peer_identity(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_OK, GNUNET_PEER_resolve(), GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::next, GNUNET_MESSENGER_ListTunnel::peer, remove_from_list_tunnels(), required_connection_between(), GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_SrvTunnelFinder::tunnel, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by handle_message_miss(), and handle_message_peer().

878 {
879  struct GNUNET_PeerIdentity peer;
880  size_t src;
881 
882  if ((GNUNET_OK != get_service_peer_identity (room->service, &peer)) || (!find_list_tunnels (&(room->basement), &peer,
883  &src)))
884  return;
885 
886  size_t count = count_of_tunnels (&(room->basement));
887 
888  struct GNUNET_MESSENGER_ListTunnel *element = room->basement.head;
889  struct GNUNET_MESSENGER_SrvTunnel *tunnel;
890 
891  size_t dst = 0;
892 
893  while (element)
894  {
895  GNUNET_PEER_resolve (element->peer, &peer);
896 
898 
899  if (!tunnel)
900  {
901  element = remove_from_list_tunnels (&(room->basement), element);
902  continue;
903  }
904 
905  if (GNUNET_YES == required_connection_between (count, src, dst))
906  {
907  if (GNUNET_SYSERR == connect_tunnel (tunnel))
908  {
909  element = remove_from_list_tunnels (&(room->basement), element);
910  continue;
911  }
912  }
913  else
914  disconnect_tunnel (tunnel);
915 
916  element = element->next;
917  dst++;
918  }
919 }
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.
struct GNUNET_MESSENGER_ListTunnel * head
int connect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Tries to connect a tunnel by creating a new CADET channel and binding it.
struct GNUNET_MESSENGER_ListTunnel * next
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:225
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...
struct GNUNET_MESSENGER_Service * service
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).
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_MESSENGER_ListTunnels basement
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.
void disconnect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Disconnects and unbinds a channel from a tunnel.
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...
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
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...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_room_messages()

void handle_room_messages ( struct GNUNET_MESSENGER_SrvRoom room)

Handles all queued up messages of a room to handle in correct order.

Parameters
roomRoom

Definition at line 922 of file gnunet-service-messenger_room.c.

References get_room_message(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NO, handle_service_message(), GNUNET_MESSENGER_SrvRoom::handling, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_SrvRoom::host, msg, GNUNET_MESSENGER_SrvRoom::service, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by callback_room_recv(), callback_room_sent(), and destroy_room().

923 {
924  while (room->handling.head)
925  {
926  struct GNUNET_MESSENGER_ListMessage *element = room->handling.head;
927 
928  const struct GNUNET_MESSENGER_Message *msg = get_room_message (room, room->host, &(element->hash), GNUNET_NO);
929 
930  if (msg)
931  handle_service_message (room->service, room, msg, &(element->hash));
932 
933  GNUNET_CONTAINER_DLL_remove(room->handling.head, room->handling.tail, element);
934  GNUNET_free(element);
935  }
936 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MESSENGER_ListMessage * head
struct GNUNET_MESSENGER_Service * service
struct GNUNET_MESSENGER_ListMessages handling
struct GNUNET_MESSENGER_SrvHandle * host
struct GNUNET_MESSENGER_ListMessage * tail
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
#define GNUNET_free(ptr)
Wrapper around free.
void handle_service_message(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Sends a received or sent message with a given hash to each handle of a service which is currently mem...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_room_recv()

void callback_room_recv ( struct GNUNET_MESSENGER_SrvRoom room,
void *  cls,
struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Definition at line 941 of file gnunet-service-messenger_room.c.

References add_to_list_messages(), forward_room_message(), GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_NO, GNUNET_OK, GNUNET_YES, handle_room_messages(), GNUNET_MESSENGER_SrvRoom::handling, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, put_store_message(), recv_message_id(), recv_message_info(), recv_message_join(), recv_message_key(), recv_message_leave(), recv_message_miss(), recv_message_name(), recv_message_peer(), recv_message_request(), GNUNET_MESSENGER_SrvRoom::store, GNUNET_MESSENGER_SrvTunnelFinder::tunnel, and update_room_last_messages().

Referenced by check_tunnel_message(), and handle_tunnel_message().

943 {
944  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
945 
946  if (GNUNET_OK != put_store_message (&(room->store), hash, message))
947  return;
948 
949  update_room_last_messages (room, message, hash);
950 
951  if (GNUNET_MESSENGER_KIND_INFO != message->header.kind)
952  forward_room_message (room, tunnel, message, hash);
953 
954  const int start_handle = room->handling.head ? GNUNET_NO : GNUNET_YES;
955 
956  add_to_list_messages (&(room->handling), hash);
957 
958  switch (message->header.kind)
959  {
961  recv_message_info (room, tunnel, message, hash);
962  break;
964  recv_message_join (room, tunnel, message, hash);
965  break;
967  recv_message_leave (room, tunnel, message, hash);
968  break;
970  recv_message_name (room, tunnel, message, hash);
971  break;
973  recv_message_key (room, tunnel, message, hash);
974  break;
976  recv_message_peer (room, tunnel, message, hash);
977  break;
979  recv_message_id (room, tunnel, message, hash);
980  break;
982  recv_message_miss (room, tunnel, message, hash);
983  break;
985  recv_message_request (room, tunnel, message, hash);
986  break;
987  default:
988  break;
989  }
990 
991  if (GNUNET_YES == start_handle)
992  handle_room_messages (room);
993 }
void recv_message_miss(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received miss message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
void recv_message_key(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received key message.
void recv_message_info(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received info message to change the current member id to the one generated by the host conn...
struct GNUNET_MESSENGER_ListMessage * head
void forward_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, const 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.
void recv_message_name(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received name message.
void recv_message_request(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received request message by checking for the requested message and forwarding it back if th...
void update_room_last_messages(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Updates the last messages of a room by replacing them if the previous hash of a given message matches...
void handle_room_messages(struct GNUNET_MESSENGER_SrvRoom *room)
Handles all queued up messages of a room to handle in correct order.
void recv_message_join(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received join message to forward all member information to the new member if the message wa...
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.
struct GNUNET_MESSENGER_ListMessages handling
void recv_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received id message to change the tunnels linked member id if necessary.
void recv_message_leave(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received leave message.
void recv_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received peer message to link it to its origin tunnel if the peer identity matches...
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.
struct GNUNET_MESSENGER_MessageStore store
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function: