GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
gnunet-service-messenger_room.h File Reference

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_cadet_service.h"
#include "gnunet_container_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_identity_service.h"
#include "gnunet_mq_lib.h"
#include "gnunet_messenger_service.h"
#include "gnunet-service-messenger_basement.h"
#include "gnunet-service-messenger_handle.h"
#include "gnunet-service-messenger_message_state.h"
#include "gnunet-service-messenger_list_messages.h"
#include "messenger_api_list_tunnels.h"
#include "gnunet-service-messenger_member_store.h"
#include "gnunet-service-messenger_message_store.h"
#include "gnunet-service-messenger_operation_store.h"
#include "messenger_api_ego.h"
Include dependency graph for gnunet-service-messenger_room.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_SrvRoom
 

Macros

#define GNUNET_MESSENGER_IDLE_DELAY
 
#define GNUNET_MESSENGER_REQUEST_DELAY
 
#define GNUNET_MESSENGER_MERGE_DELAY
 

Typedefs

typedef void() GNUNET_MESSENGER_MessageRequestCallback(void *cls, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Method called whenever a message is found during a request in a room. More...
 

Functions

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...
 
void destroy_room (struct GNUNET_MESSENGER_SrvRoom *room)
 Destroys a room and frees its memory fully. More...
 
struct GNUNET_MESSENGER_MemberStoreget_room_member_store (struct GNUNET_MESSENGER_SrvRoom *room)
 Returns the used member store of a given room. More...
 
struct GNUNET_MESSENGER_MessageStoreget_room_message_store (struct GNUNET_MESSENGER_SrvRoom *room)
 Returns the used message store of a given room. More...
 
struct GNUNET_MESSENGER_OperationStoreget_room_operation_store (struct GNUNET_MESSENGER_SrvRoom *room)
 Returns the used operation store of a given room. More...
 
int open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
 Tries to open a room for a given handle. More...
 
int enter_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...
 
struct GNUNET_MQ_Envelopepack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode)
 Packs a message depending on the selected mode into a newly allocated envelope. More...
 
int send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message)
 Sends a message from a given handle into a room. More...
 
void forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Forwards a message with a given hash to a specific tunnel inside of a room. More...
 
void check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Checks the current state of opening a given room from this peer and re-publishes it if necessary to a selected tunnel or to all connected tunnels if necessary or if the selected tunnel is NULL. 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...
 
int delete_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
 Deletes a message from the room with a given hash in a specific delay if the provided member by its session is permitted to do so. More...
 
struct GNUNET_CADET_Handleget_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room)
 Returns the CADET handle from a rooms service. More...
 
const struct GNUNET_HashCodeget_room_key (const struct GNUNET_MESSENGER_SrvRoom *room)
 Returns the shared secret you need to access a room. More...
 
const struct GNUNET_MESSENGER_SrvTunnelget_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *peer)
 Returns a tunnel inside of a room leading towards a given peer if such a tunnel exists, otherwise NULL. More...
 
int request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, GNUNET_MESSENGER_MessageRequestCallback callback, void *cls)
 Requests a message from a room identified by a given hash. More...
 
void solve_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_IDENTITY_PublicKey *public_key, const struct GNUNET_ShortHashCode *member_id, struct GNUNET_TIME_Absolute timestamp)
 Checks for potential collisions with member ids and solves them changing active handles ids if they use an already used member id (comparing public key and timestamp). 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 load_room (struct GNUNET_MESSENGER_SrvRoom *room)
 Loads the local configuration for a given room of a service which contains the last messages hash and the ruleset for general access of new members. More...
 
void save_room (struct GNUNET_MESSENGER_SrvRoom *room)
 Saves the configuration for a given room of a service which contains the last messages hash and the ruleset for general access of new members locally. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_room.h.

Macro Definition Documentation

◆ GNUNET_MESSENGER_IDLE_DELAY

#define GNUNET_MESSENGER_IDLE_DELAY
Value:
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_(void)
Return relative time of 1s.
Definition: time.c:136
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:311

Definition at line 49 of file gnunet-service-messenger_room.h.

◆ GNUNET_MESSENGER_REQUEST_DELAY

#define GNUNET_MESSENGER_REQUEST_DELAY
Value:
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
Return relative time of 1 minute.
Definition: time.c:145

Definition at line 52 of file gnunet-service-messenger_room.h.

◆ GNUNET_MESSENGER_MERGE_DELAY

#define GNUNET_MESSENGER_MERGE_DELAY

Typedef Documentation

◆ GNUNET_MESSENGER_MessageRequestCallback

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

Method called whenever a message is found during a request in a room.

Parameters
[in/out]cls Closure from request_room_message
[in/out]room Room
[in]messageMessage or NULL
[in]hashHash of message

Definition at line 296 of file gnunet-service-messenger_room.h.

Function Documentation

◆ 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
[in/out]handle Handle
[in]keyKey of room
Returns
New room

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

48 {
49  GNUNET_assert((handle) && (key));
50 
52 
53  room->service = handle->service;
54  room->host = handle;
55  room->port = NULL;
56 
57  GNUNET_memcpy(&(room->key), key, sizeof(struct GNUNET_HashCode));
58 
60 
64 
65  init_list_tunnels (&(room->basement));
66  init_message_state(&(room->state));
67 
68  room->peer_message = NULL;
69 
70  init_list_messages (&(room->handling));
71  room->idle = NULL;
72 
73  if (room->service->dir)
74  load_room (room);
75 
77 
78  return room;
79 }
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
void init_member_store(struct GNUNET_MESSENGER_MemberStore *store, struct GNUNET_MESSENGER_SrvRoom *room)
Initializes a member store as fully empty connected to a room.
void init_message_state(struct GNUNET_MESSENGER_MessageState *state)
void init_message_store(struct GNUNET_MESSENGER_MessageStore *store)
Initializes a message store as fully empty.
void init_operation_store(struct GNUNET_MESSENGER_OperationStore *store, struct GNUNET_MESSENGER_SrvRoom *room)
Initializes an operation store as fully empty with a given room.
struct GNUNET_MESSENGER_OperationStore * get_room_operation_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used operation store of a given room.
static void idle_request_room_messages(void *cls)
struct GNUNET_MESSENGER_MessageStore * get_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.
struct GNUNET_MESSENGER_MemberStore * get_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
void load_room(struct GNUNET_MESSENGER_SrvRoom *room)
Loads the local configuration for a given room of a service which contains the last messages hash and...
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_NO
Definition: gnunet_common.h:94
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).
#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.
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_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Initializes list of tunnels peer identities as empty list.
A 512-bit hashcode.
struct GNUNET_HashCode * peer_message
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
struct GNUNET_MESSENGER_Service * service
struct GNUNET_CADET_Port * port
struct GNUNET_MESSENGER_ListTunnels basement
struct GNUNET_SCHEDULER_Task * idle
struct GNUNET_MESSENGER_MessageState state
struct GNUNET_MESSENGER_ListMessages handling
struct GNUNET_MESSENGER_SrvHandle * host

References GNUNET_MESSENGER_SrvRoom::basement, GNUNET_MESSENGER_Service::dir, get_room_member_store(), get_room_message_store(), get_room_operation_store(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_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_member_store(), init_message_state(), init_message_store(), init_operation_store(), key, GNUNET_MESSENGER_SrvRoom::key, load_room(), GNUNET_MESSENGER_SrvRoom::peer_message, GNUNET_MESSENGER_SrvRoom::port, GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_SrvRoom::state, and GNUNET_MESSENGER_SrvRoom::tunnels.

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

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
[in/out]room Room

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

96 {
97  GNUNET_assert(room);
98 
99  if (room->idle)
100  {
102 
103  room->idle = NULL;
104  }
105 
106  if (room->port)
108 
110 
111  handle_room_messages (room);
112 
113  if (room->service->dir)
114  save_room (room);
115 
119 
121 
122  clear_list_tunnels (&(room->basement));
123  clear_message_state(&(room->state));
124 
125  if (room->peer_message)
126  GNUNET_free(room->peer_message);
127 
128  GNUNET_free(room);
129 }
void clear_member_store(struct GNUNET_MESSENGER_MemberStore *store)
Clears a member store, wipes its content and deallocates its memory.
void clear_message_state(struct GNUNET_MESSENGER_MessageState *state)
void clear_message_store(struct GNUNET_MESSENGER_MessageStore *store)
Clears a message store, wipes its content and deallocates its memory.
void clear_operation_store(struct GNUNET_MESSENGER_OperationStore *store)
Clears an operation store, stops all operations and deallocates its memory.
void save_room(struct GNUNET_MESSENGER_SrvRoom *room)
Saves the configuration for a given room of a service which contains the last messages hash and the r...
static int iterate_destroy_tunnels(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
static void handle_room_messages(struct GNUNET_MESSENGER_SrvRoom *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
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
void clear_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Clears the list of tunnels peer identities.

References GNUNET_MESSENGER_SrvRoom::basement, clear_list_tunnels(), clear_member_store(), clear_message_state(), clear_message_store(), clear_operation_store(), GNUNET_MESSENGER_Service::dir, get_room_member_store(), get_room_message_store(), get_room_operation_store(), GNUNET_assert, GNUNET_CADET_close_port(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_free, GNUNET_SCHEDULER_cancel(), handle_room_messages(), GNUNET_MESSENGER_SrvRoom::idle, iterate_destroy_tunnels(), GNUNET_MESSENGER_SrvRoom::peer_message, GNUNET_MESSENGER_SrvRoom::port, GNUNET_MESSENGER_SrvTunnel::room, save_room(), GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_SrvRoom::state, and GNUNET_MESSENGER_SrvRoom::tunnels.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_room_member_store()

struct GNUNET_MESSENGER_MemberStore* get_room_member_store ( struct GNUNET_MESSENGER_SrvRoom room)

Returns the used member store of a given room.

Parameters
[in/out]room Room
Returns
Member store

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

133 {
134  GNUNET_assert(room);
135 
136  return &(room->member_store);
137 }
struct GNUNET_MESSENGER_MemberStore member_store

References GNUNET_assert, GNUNET_MESSENGER_SrvRoom::member_store, and GNUNET_MESSENGER_MemberStore::room.

Referenced by callback_found_message(), callback_room_handle_message(), check_room_peer_status(), create_room(), destroy_room(), get_handle_member_session(), handle_get_message(), handle_room_messages(), join_room_locally(), load_room(), open_room(), recv_message_info(), recv_message_request(), save_room(), and solve_room_member_collisions().

Here is the caller graph for this function:

◆ get_room_message_store()

struct GNUNET_MESSENGER_MessageStore* get_room_message_store ( struct GNUNET_MESSENGER_SrvRoom room)

Returns the used message store of a given room.

Parameters
[in/out]room Room
Returns
Message store

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

141 {
142  GNUNET_assert(room);
143 
144  return &(room->message_store);
145 }
struct GNUNET_MESSENGER_MessageStore message_store

References GNUNET_assert, and GNUNET_MESSENGER_SrvRoom::message_store.

Referenced by callback_room_deletion(), callback_verify_room_message(), check_member_session_completion(), check_room_peer_status(), create_room(), delete_room_message(), destroy_room(), forward_about_members(), handle_room_messages(), load_room(), notify_about_members(), request_room_message_step(), save_room(), update_room_message(), and update_tunnel_last_message().

Here is the caller graph for this function:

◆ get_room_operation_store()

struct GNUNET_MESSENGER_OperationStore* get_room_operation_store ( struct GNUNET_MESSENGER_SrvRoom room)

Returns the used operation store of a given room.

Parameters
[in/out]room Room
Returns
Operation store

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

149 {
150  GNUNET_assert(room);
151 
152  return &(room->operation_store);
153 }
struct GNUNET_MESSENGER_OperationStore operation_store

References GNUNET_assert, GNUNET_MESSENGER_SrvRoom::operation_store, and GNUNET_MESSENGER_OperationStore::room.

Referenced by callback_found_message(), create_room(), delete_room_message(), destroy_room(), idle_request_room_messages(), load_room(), save_room(), send_message_request(), update_room_message(), and update_tunnel_last_message().

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 guaranteed to be open for incoming connections.

Parameters
[in/out]room Room
[in/out]handle Handle
Returns
GNUNET_YES on success, GNUNET_NO on failure.

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

334 {
335  GNUNET_assert((room) && (handle));
336 
337  if (room->port)
338  return join_room_locally (room, handle);
339 
340  struct GNUNET_CADET_Handle *cadet = get_room_cadet (room);
341  const struct GNUNET_HashCode *key = get_room_key (room);
342 
344  struct GNUNET_MessageHeader, NULL),
346 
347  struct GNUNET_HashCode port;
350  handlers);
351 
352  if (room->port)
353  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Port of room (%s) was opened!\n",
354  GNUNET_h2s(get_room_key(room)));
355  else
356  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Port of room (%s) could not be opened!\n",
357  GNUNET_h2s(get_room_key(room)));
358 
359  const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (handle, get_room_key(room));
360 
362  struct GNUNET_MESSENGER_Member *member = get_store_member(member_store, member_id);
363 
364  if (member)
365  goto exit_open_room;
366 
367  member = add_store_member(member_store, member_id);
368 
369  if ((GNUNET_NO == join_room (room, handle, member)) && (room->port))
370  {
371  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not join the room, therefore it keeps closed!\n");
372 
374  room->port = NULL;
375 
376  return GNUNET_NO;
377  }
378 
379 exit_open_room:
380  return (room->port ? send_room_message (room, handle, create_message_peer (room->service)) : GNUNET_NO);
381 }
static uint16_t port
Port number.
Definition: gnunet-bcd.c:83
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_CADET_Handle * cadet
Handle for cadet.
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
struct GNUNET_MESSENGER_Member * get_store_member(const struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Returns the member in a store identified by a given id.
struct GNUNET_MESSENGER_Member * add_store_member(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Adds a member to a store under a specific id and returns it on success.
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.
static int join_room(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Member *member)
int send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle into a room.
const struct GNUNET_HashCode * get_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
static int join_room_locally(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
static void * callback_room_connect(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source)
void callback_tunnel_disconnect(void *cls, const struct GNUNET_CADET_Channel *channel)
struct GNUNET_CADET_Handle * get_room_cadet(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the CADET handle from a rooms service.
#define GNUNET_log(kind,...)
struct GNUNET_CADET_Port * GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Open a port to receive incoming MQ-based channels.
Definition: cadet_api.c:970
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
void convert_messenger_key_to_port(const struct GNUNET_HashCode *key, struct GNUNET_HashCode *port)
Converts a Messenger service key of a room to the specific port which gets used for the CADET channel...
Opaque handle to the service.
Definition: cadet_api.c:39
Message handler for a specific message type.
Header for all communications.
A 256-bit hashcode.

References add_store_member(), cadet, callback_room_connect(), callback_tunnel_disconnect(), convert_messenger_key_to_port(), create_message_peer(), get_handle_member_id(), get_room_cadet(), get_room_key(), get_room_member_store(), get_store_member(), GNUNET_assert, GNUNET_CADET_close_port(), GNUNET_CADET_open_port(), GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, handle, handlers, join_room(), join_room_locally(), key, port, GNUNET_MESSENGER_SrvRoom::port, GNUNET_MESSENGER_MemberStore::room, GNUNET_MESSENGER_MemberNotify::room, send_room_message(), and GNUNET_MESSENGER_SrvRoom::service.

Referenced by open_service_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter_room_at()

int enter_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
[in/out]room Room
[in/out]handle Handle
[in]doorPeer identity
Returns
GNUNET_YES on success, GNUNET_NO on failure.

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

387 {
388  GNUNET_assert((room) && (handle) && (door));
389 
390  struct GNUNET_PeerIdentity peer;
391 
392  if ((GNUNET_OK == get_service_peer_identity (room->service, &peer)) &&
393  (0 == GNUNET_memcmp(&peer, door)))
394  return join_room_locally (room, handle);
395 
397 
398  if (!tunnel)
399  {
400  tunnel = create_tunnel (room, door);
401 
404  {
405  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not connect to that door!\n");
406  destroy_tunnel (tunnel);
407  return GNUNET_NO;
408  }
409  }
410 
411  if (GNUNET_SYSERR == connect_tunnel (tunnel))
412  {
413  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Connection failure during entrance!\n");
415  destroy_tunnel (tunnel);
416  return GNUNET_NO;
417  }
418 
419  return join_room_locally (room, handle);
420 }
static void destroy_tunnel(void *cls)
This tunnel is no longer used, destroy it.
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.
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_SrvTunnel * create_tunnel(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *door)
Creates and allocates a tunnel of a room to a specific peer identity (called door).
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_ERROR_TYPE_ERROR
struct GNUNET_MESSENGER_SrvRoom * room
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References connect_tunnel(), create_tunnel(), destroy_tunnel(), get_service_peer_identity(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcmp, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, handle, join_room_locally(), peer, GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvRoom::service, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by entry_service_room().

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 ( const struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_MESSENGER_SrvHandle handle,
struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash,
int  mode 
)

Packs a message depending on the selected mode into a newly allocated envelope.

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 overridden 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
[in]roomRoom
[in]handleHandle
[in/out]message Message
[out]hashHash of message
[in]modePacking mode
Returns
New envelope or NULL

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

428 {
429  GNUNET_assert((room) && (handle) && (message) && (hash));
430 
432 
433  const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, get_room_key(room));
434 
435  GNUNET_assert(id);
436 
437  GNUNET_memcpy(&(message->header.sender_id), id, sizeof(struct GNUNET_ShortHashCode));
438  get_message_state_chain_hash (&(room->state), &(message->header.previous));
439 
440  return pack_message (message, hash, get_handle_ego (handle), mode);
441 }
const struct GNUNET_MESSENGER_Ego * get_handle_ego(const struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.
void get_message_state_chain_hash(const struct GNUNET_MESSENGER_MessageState *state, struct GNUNET_HashCode *hash)
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
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_HashCode previous
The hash of the previous message from the senders perspective.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_MESSENGER_MessageHeader header
Header.

References get_handle_ego(), get_handle_member_id(), get_message_state_chain_hash(), get_room_key(), GNUNET_assert, GNUNET_memcpy, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), handle, GNUNET_MESSENGER_Message::header, mode, pack_message(), GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_SrvRoom::state, and GNUNET_MESSENGER_MessageHeader::timestamp.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_room_message()

int send_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
struct GNUNET_MESSENGER_Message message 
)

Sends a message from a given handle into a room.

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.

The function returns GNUNET_YES on success, GNUNET_NO if message is null and GNUNET_SYSERR if the message was known already.

Parameters
[in/out]room Room
[in/out]handle Handle
[in/out]message Message
Returns
GNUNET_YES on success, GNUNET_NO or GNUNET_SYSERR otherwise.

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

503 {
504  GNUNET_assert((room) && (handle));
505 
506  if (!message)
507  return GNUNET_NO;
508 
509  if (GNUNET_YES == is_message_session_bound(message))
511 
512  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sending message from handle with member id: %s\n",
514 
515  struct GNUNET_HashCode hash;
516  struct GNUNET_MESSENGER_ClosureSendRoom closure;
517 
518  closure.room = room;
519  closure.handle = handle;
520  closure.exclude = NULL;
521  closure.message = message;
522  closure.hash = &hash;
523  closure.packed = GNUNET_NO;
524 
526 
527  if (GNUNET_NO == closure.packed)
529 
530  const int new_message = update_room_message (room, message, &hash);
531 
532  if (GNUNET_YES != new_message)
533  return GNUNET_SYSERR;
534 
535  switch (message->header.kind)
536  {
539  break;
542  break;
545  break;
548  break;
549  default:
550  break;
551  }
552 
554  return GNUNET_YES;
555 }
void send_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent id message to update the handles member id in the room.
void send_message_request(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent request message to trigger the request operation for this service.
void send_message_join(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent join message to ensure growth of the decentralized room structure.
void send_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a sent peer message to update the rooms peer message of this service.
struct GNUNET_MQ_Envelope * pack_room_message(const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode)
Packs a message depending on the selected mode into a newly allocated envelope.
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 callback_room_handle_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
int update_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
static int iterate_send_room_message(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
@ GNUNET_YES
Definition: gnunet_common.h:97
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
int is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
#define GNUNET_MESSENGER_PACK_MODE_UNKNOWN
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_SrvRoom * room
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.

References callback_room_handle_message(), GNUNET_MESSENGER_ClosureSendRoom::exclude, get_handle_member_id(), get_room_key(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_PACK_MODE_UNKNOWN, GNUNET_NO, GNUNET_sh2s(), GNUNET_SYSERR, GNUNET_YES, handle, GNUNET_MESSENGER_ClosureSendRoom::handle, GNUNET_MESSENGER_ClosureSendRoom::hash, GNUNET_MESSENGER_Message::header, is_message_session_bound(), iterate_send_room_message(), GNUNET_MESSENGER_MessageHeader::kind, merge_room_last_messages(), GNUNET_MESSENGER_ClosureSendRoom::message, pack_room_message(), GNUNET_MESSENGER_ClosureSendRoom::packed, GNUNET_MESSENGER_ClosureSendRoom::room, send_message_id(), send_message_join(), send_message_peer(), send_message_request(), GNUNET_MESSENGER_SrvRoom::tunnels, and update_room_message().

Referenced by callback_found_message(), callback_room_disconnect(), callback_room_merge(), check_room_peer_status(), close_service_room(), join_room(), merge_room_last_messages(), open_room(), send_handle_message(), and solve_room_member_collisions().

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,
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
[in/out]room Room
[in/out]tunnel Tunnel
[in/out]message Message
[in]hashHash of message

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

562 {
563  GNUNET_assert((room) && (tunnel));
564 
565  if (!message)
566  return;
567 
568  struct GNUNET_MESSENGER_ClosureSendRoom closure;
569  struct GNUNET_HashCode message_hash;
570 
571  GNUNET_memcpy(&message_hash, hash, sizeof(struct GNUNET_HashCode));
572 
573  closure.room = room;
574  closure.handle = NULL;
575  closure.exclude = tunnel;
576  closure.message = message;
577  closure.hash = &message_hash;
578  closure.packed = GNUNET_YES;
579 
581 }

References GNUNET_MESSENGER_ClosureSendRoom::exclude, GNUNET_assert, 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, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_room_peer_status()

void check_room_peer_status ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvTunnel tunnel 
)

Checks the current state of opening a given room from this peer and re-publishes it if necessary to a selected tunnel or to all connected tunnels if necessary or if the selected tunnel is NULL.

Parameters
[in/out]room Room
[in/out]tunnel Tunnel

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

586 {
587  if (!room->peer_message)
588  return;
589 
590  struct GNUNET_MESSENGER_MessageStore *message_store = get_room_message_store(room);
591 
592  const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, room->peer_message);
593 
594  if (!message)
595  {
596  GNUNET_free(room->peer_message);
597  room->peer_message = NULL;
598  return;
599  }
600 
602  struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
603 
604  if (!member)
605  goto resend_peer_message;
606 
607  struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, room->peer_message);
608 
609  if (GNUNET_YES == is_member_session_closed(session))
610  goto resend_peer_message;
611 
612  if (tunnel)
613  forward_tunnel_message(tunnel, message, room->peer_message);
614 
615  return;
616 
617 resend_peer_message:
618  if (room->host)
619  send_room_message (room, room->host, create_message_peer (room->service));
620 }
struct GNUNET_MESSENGER_MemberSession * get_member_session_of(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Returns the member session of a member using a public key which can verify the signature of a given m...
int is_member_session_closed(const struct GNUNET_MESSENGER_MemberSession *session)
Returns if the given member session has been closed.
struct GNUNET_MESSENGER_Member * get_store_member_of(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_MESSENGER_Message *message)
Returns the member of a store using a sender id of a given message.
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 forward_tunnel_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Forwards a given message with a known hash through a tunnel.

References create_message_peer(), forward_tunnel_message(), get_member_session_of(), get_room_member_store(), get_room_message_store(), get_store_member_of(), get_store_message(), GNUNET_free, GNUNET_YES, GNUNET_MESSENGER_SrvRoom::host, is_member_session_closed(), GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_SrvRoom::peer_message, GNUNET_MESSENGER_MemberStore::room, send_room_message(), and GNUNET_MESSENGER_SrvRoom::service.

Referenced by recv_message_info(), and send_message_join().

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
[in/out]room Room
[in/out]handle Handle

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

625 {
626  GNUNET_assert(room);
627 
628  if (!handle)
629  return;
630 
631  const struct GNUNET_HashCode *hash;
632 
633 merge_next:
634  hash = get_message_state_merge_hash (&(room->state));
635 
636  if (!hash)
637  return;
638 
640  goto merge_next;
641 }
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...
const struct GNUNET_HashCode * get_message_state_merge_hash(const struct GNUNET_MESSENGER_MessageState *state)

References create_message_merge(), get_message_state_merge_hash(), GNUNET_assert, handle, send_room_message(), and GNUNET_MESSENGER_SrvRoom::state.

Referenced by send_room_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_room_message()

int delete_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_HashCode hash,
const struct GNUNET_TIME_Relative  delay 
)

Deletes a message from the room with a given hash in a specific delay if the provided member by its session is permitted to do so.

Parameters
[in/out]room Room
[in/out]session Member session
[in]hashHash of message
[in]delayDelay of deletion
Returns
GNUNET_YES on success, GNUNET_NO if permission gets denied, GNUNET_SYSERR on operation failure

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

669 {
670  GNUNET_assert((room) && (session) && (hash));
671 
673 
674  if (0 == GNUNET_memcmp(&forever, &delay))
675  {
676  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Deletion is delayed forever: operation is impossible!\n");
677  return GNUNET_SYSERR;
678  }
679 
680  struct GNUNET_MESSENGER_MessageStore *message_store = get_room_message_store(room);
681 
682  const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, hash);
683 
684  if (!message)
685  return GNUNET_YES;
686 
687  if (GNUNET_YES != check_member_session_history(session, hash, GNUNET_YES))
688  {
689  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unpermitted request for deletion by member (%s) of message (%s)!\n",
690  GNUNET_sh2s(get_member_session_id(session)), GNUNET_h2s(hash));
691 
692  return GNUNET_NO;
693  }
694 
696 
697  if (GNUNET_OK != use_store_operation(operation_store, hash, GNUNET_MESSENGER_OP_DELETE, delay))
698  {
699  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Deletion has failed: operation denied!\n");
700  return GNUNET_SYSERR;
701  }
702 
703  return GNUNET_YES;
704 }
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
const struct GNUNET_ShortHashCode * get_member_session_id(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the member id of a given member session.
int check_member_session_history(const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, int ownership)
Checks the history of a session for a specific message which is identified by its hash and if the own...
int use_store_operation(struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_OperationType type, struct GNUNET_TIME_Relative delay)
Tries to use an operation under a given hash in a specific operation store.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_(void)
Return "forever".
Definition: time.c:163
Time for relative time used by GNUnet, in microseconds.

References check_member_session_history(), delay, get_member_session_id(), get_room_message_store(), get_room_operation_store(), get_store_message(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_memcmp, GNUNET_MESSENGER_OP_DELETE, GNUNET_NO, GNUNET_OK, GNUNET_sh2s(), GNUNET_SYSERR, GNUNET_TIME_relative_get_forever_(), GNUNET_YES, GNUNET_MESSENGER_OperationStore::room, and use_store_operation().

Referenced by handle_message_delete().

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
[in/out]room Room
Returns
CADET handle

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

708 {
709  GNUNET_assert(room);
710 
711  return room->service->cadet;
712 }
struct GNUNET_CADET_Handle * cadet

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

Referenced by connect_tunnel(), and open_room().

Here is the caller graph for this function:

◆ get_room_key()

const struct GNUNET_HashCode* get_room_key ( const struct GNUNET_MESSENGER_SrvRoom room)

Returns the shared secret you need to access a room.

Parameters
[in]roomRoom
Returns
Shared secret

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

716 {
717  GNUNET_assert(room);
718 
719  return &(room->key);
720 }

References GNUNET_assert, and GNUNET_MESSENGER_SrvRoom::key.

Referenced by callback_found_message(), callback_room_connect(), connect_tunnel(), get_member_store_key(), get_room_data_subdir(), handle_message_join(), handle_message_leave(), handle_service_message(), join_room(), join_room_locally(), notify_about_members(), open_room(), pack_room_message(), send_message_id(), send_room_message(), solve_room_member_collisions(), and update_room_message().

Here is the caller graph for this function:

◆ get_room_tunnel()

const struct GNUNET_MESSENGER_SrvTunnel* get_room_tunnel ( const struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_PeerIdentity peer 
)

Returns a tunnel inside of a room leading towards a given peer if such a tunnel exists, otherwise NULL.

Parameters
[in]roomRoom
[in]peerPeer identity
Returns
Tunnel or NULL

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

725 {
726  GNUNET_assert((room) && (peer));
727 
729 }

References GNUNET_assert, GNUNET_CONTAINER_multipeermap_get(), peer, GNUNET_MESSENGER_SrvTunnel::room, and GNUNET_MESSENGER_SrvRoom::tunnels.

Here is the call graph for this function:

◆ request_room_message()

int request_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_HashCode hash,
const struct GNUNET_MESSENGER_MemberSession session,
GNUNET_MESSENGER_MessageRequestCallback  callback,
void *  cls 
)

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

If the message is found, the selected callback will be called with it and the provided closure. If no matching message is found but it wasn't deleted the selected callback will be called with #NULL as message instead. In case of deletion the next available previous message will be used to call the callback.

It is also possible that the given callback will not be called if the requesting session is not permitted!

Parameters
[in/out]room Room
[in]hashHash of message
[in]callbackCallback to process result
[in]clsClosure for the callback
Returns
GNUNET_YES if the request could be processed, otherwise GNUNET_NO

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

776 {
777  GNUNET_assert((room) && (hash));
778 
779  int result = request_room_message_step (room, hash, session, callback, cls);
780 
781  if ((GNUNET_NO == result) && (callback))
782  callback (cls, room, NULL, hash);
783 
784  return result;
785 }
static int result
Global testing status.
static int request_room_message_step(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, GNUNET_MESSENGER_MessageRequestCallback callback, void *cls)

References GNUNET_assert, GNUNET_NO, request_room_message_step(), and result.

Referenced by handle_get_message(), and recv_message_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solve_room_member_collisions()

void solve_room_member_collisions ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_IDENTITY_PublicKey public_key,
const struct GNUNET_ShortHashCode member_id,
struct GNUNET_TIME_Absolute  timestamp 
)

Checks for potential collisions with member ids and solves them changing active handles ids if they use an already used member id (comparing public key and timestamp).

Parameters
[in/out]room Room
[in]public_keyPublic key of EGO
[in]member_idMember ID
[in]timestampTimestamp

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

874 {
875  GNUNET_assert ((room) && (public_key) && (member_id));
876 
878  struct GNUNET_MESSENGER_Member *member = get_store_member(member_store, member_id);
879 
880  if ((!member) || (1 >= GNUNET_CONTAINER_multihashmap_size(member->sessions)))
881  return;
882 
883  struct GNUNET_MESSENGER_ListHandles *handles = &(room->service->handles);
884  struct GNUNET_MESSENGER_ListHandle* element;
885 
886  for (element = handles->head; element; element = element->next)
887  {
888  if (0 != GNUNET_memcmp(member_id, get_handle_member_id(element->handle, get_room_key(room))))
889  continue;
890 
891  if (0 == GNUNET_memcmp(public_key, &(get_handle_ego(element->handle)->pub)))
892  continue;
893 
895 
896  if (!session)
897  continue;
898 
900 
901  if (GNUNET_TIME_relative_get_zero_().rel_value_us != GNUNET_TIME_absolute_get_difference(start, timestamp).rel_value_us)
902  continue;
903 
904  struct GNUNET_ShortHashCode random_id;
905  generate_free_member_id (&random_id, member_store->members);
906 
907  send_room_message(room, element->handle, create_message_id(&random_id));
908  }
909 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
struct GNUNET_MESSENGER_MemberSession * get_member_session(const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key)
Returns the member session of a member identified by a given public key.
struct GNUNET_TIME_Absolute get_member_session_start(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the timestamp of the member session's start.
struct GNUNET_MESSENGER_Message * create_message_id(const struct GNUNET_ShortHashCode *unique_id)
Creates and allocates a new id message containing the unique member id to change to.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition: time.c:100
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:248
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.
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_MESSENGER_ListHandle * next
struct GNUNET_MESSENGER_SrvHandle * handle
struct GNUNET_MESSENGER_ListHandle * head
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_CONTAINER_MultiHashMap * sessions
struct GNUNET_MESSENGER_ListHandles handles
Time for absolute times used by GNUnet, in microseconds.

References create_message_id(), generate_free_member_id(), get_handle_ego(), get_handle_member_id(), get_member_session(), get_member_session_start(), get_room_key(), get_room_member_store(), get_store_member(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_size(), GNUNET_memcmp, GNUNET_TIME_absolute_get_difference(), GNUNET_TIME_relative_get_zero_(), GNUNET_MESSENGER_ListHandle::handle, GNUNET_MESSENGER_Service::handles, GNUNET_MESSENGER_ListHandles::head, GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberStore::members, GNUNET_MESSENGER_ListHandle::next, GNUNET_MESSENGER_Ego::pub, GNUNET_MESSENGER_MemberStore::room, send_room_message(), GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_Member::sessions, and start.

Referenced by handle_message_id(), and handle_message_join().

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
[in/out]room Room

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

913 {
914  GNUNET_assert(room);
915 
916  struct GNUNET_PeerIdentity peer;
917  size_t src;
918 
919  if ((GNUNET_OK != get_service_peer_identity (room->service, &peer)) ||
920  (!find_list_tunnels (&(room->basement), &peer, &src)))
921  return;
922 
923  size_t count = count_of_tunnels (&(room->basement));
924 
925  struct GNUNET_MESSENGER_ListTunnel *element = room->basement.head;
926  struct GNUNET_MESSENGER_SrvTunnel *tunnel;
927 
928  size_t dst = 0;
929 
930  while (element)
931  {
932  GNUNET_PEER_resolve (element->peer, &peer);
933 
935 
936  if (!tunnel)
937  {
938  element = remove_from_list_tunnels (&(room->basement), element);
939  continue;
940  }
941 
942  if (GNUNET_YES == required_connection_between (count, src, dst))
943  {
944  if (GNUNET_SYSERR == connect_tunnel (tunnel))
945  {
946  element = remove_from_list_tunnels (&(room->basement), element);
947  continue;
948  }
949  }
950  else
951  disconnect_tunnel (tunnel);
952 
953  element = element->next;
954  dst++;
955  }
956 }
int required_connection_between(size_t count, size_t src, size_t dst)
Returns GNUNET_YES or GNUNET_NO to determine if the peers of index src and index dst should be connec...
size_t count_of_tunnels(const struct GNUNET_MESSENGER_ListTunnels *tunnels)
Returns the count of peers in a list (typically from the basement of a room).
void disconnect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Disconnects and unbinds a channel from a tunnel.
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
struct GNUNET_MESSENGER_ListTunnel * remove_from_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element)
Removes a specific element from the list of tunnels peer identities and returns the next element in t...
struct GNUNET_MESSENGER_ListTunnel * find_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index)
Searches linearly through the list of tunnels peer identities for matching a specific peer identity a...
struct GNUNET_MESSENGER_ListTunnel * next
struct GNUNET_MESSENGER_ListTunnel * head

References GNUNET_MESSENGER_SrvRoom::basement, connect_tunnel(), count_of_tunnels(), disconnect_tunnel(), find_list_tunnels(), get_service_peer_identity(), GNUNET_assert, 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, peer, remove_from_list_tunnels(), required_connection_between(), GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvRoom::service, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by handle_message_miss(), and handle_message_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_room()

void load_room ( struct GNUNET_MESSENGER_SrvRoom room)

Loads the local configuration for a given room of a service which contains the last messages hash and the ruleset for general access of new members.

Parameters
[out]roomRoom

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

1174 {
1175  GNUNET_assert(room);
1176 
1177  char *room_dir;
1178  get_room_data_subdir (room, &room_dir);
1179 
1181  {
1182  load_member_store (get_room_member_store(room), room_dir);
1183  load_message_store (get_room_message_store(room), room_dir);
1185 
1186  char *basement_file;
1187  GNUNET_asprintf (&basement_file, "%s%s", room_dir, "basement.list");
1188 
1189  load_list_tunnels(&(room->basement), basement_file);
1190  GNUNET_free(basement_file);
1191 
1192  char *last_messages_file;
1193  GNUNET_asprintf (&last_messages_file, "%s%s", room_dir, "last_messages.list");
1194 
1195  load_message_state(&(room->state), room_dir);
1196  GNUNET_free (last_messages_file);
1197  }
1198 
1199  GNUNET_free(room_dir);
1200 }
void load_member_store(struct GNUNET_MESSENGER_MemberStore *store, const char *directory)
Loads members from a directory into a member store.
void load_message_state(struct GNUNET_MESSENGER_MessageState *state, const char *path)
void load_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Loads messages from a directory into a message store.
void load_operation_store(struct GNUNET_MESSENGER_OperationStore *store, const char *directory)
Loads operations from a directory into an operation store.
static void get_room_data_subdir(struct GNUNET_MESSENGER_SrvRoom *room, char **dir)
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
void load_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path)
Loads the list of tunnels peer identities from a file under a given path.

References GNUNET_MESSENGER_SrvRoom::basement, get_room_data_subdir(), get_room_member_store(), get_room_message_store(), get_room_operation_store(), GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_YES, load_list_tunnels(), load_member_store(), load_message_state(), load_message_store(), load_operation_store(), and GNUNET_MESSENGER_SrvRoom::state.

Referenced by create_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_room()

void save_room ( struct GNUNET_MESSENGER_SrvRoom room)

Saves the configuration for a given room of a service which contains the last messages hash and the ruleset for general access of new members locally.

Parameters
[in]roomRoom

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

1204 {
1205  GNUNET_assert(room);
1206 
1207  char *room_dir;
1208  get_room_data_subdir (room, &room_dir);
1209 
1210  if ((GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_NO)) ||
1211  (GNUNET_OK == GNUNET_DISK_directory_create (room_dir)))
1212  {
1213  save_member_store(get_room_member_store(room), room_dir);
1214  save_message_store (get_room_message_store(room), room_dir);
1216 
1217  char *basement_file;
1218  GNUNET_asprintf (&basement_file, "%s%s", room_dir, "basement.list");
1219 
1220  save_list_tunnels(&(room->basement), basement_file);
1221  GNUNET_free(basement_file);
1222 
1223  save_message_state(&(room->state), room_dir);
1224  }
1225 
1226  GNUNET_free(room_dir);
1227 }
void save_member_store(struct GNUNET_MESSENGER_MemberStore *store, const char *directory)
Saves members from a member store into a directory.
void save_message_state(const struct GNUNET_MESSENGER_MessageState *state, const char *path)
void save_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Saves messages from a message store into a directory.
void save_operation_store(const struct GNUNET_MESSENGER_OperationStore *store, const char *directory)
Saves operations from an operation store into a directory.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496
void save_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path)
Saves the list of tunnels peer identities to a file under a given path.

References GNUNET_MESSENGER_SrvRoom::basement, get_room_data_subdir(), get_room_member_store(), get_room_message_store(), get_room_operation_store(), GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_YES, save_list_tunnels(), save_member_store(), save_message_state(), save_message_store(), save_operation_store(), and GNUNET_MESSENGER_SrvRoom::state.

Referenced by destroy_room().

Here is the call graph for this function:
Here is the caller graph for this function: