GNUnet 0.21.1
messenger_api_cmd_join_room.c File Reference

cmd to join a room in a messenger service. More...

Include dependency graph for messenger_api_cmd_join_room.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_JoinRoomState
 

Functions

static void join_room_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 
static void join_room_cleanup (void *cls)
 
struct GNUNET_TESTING_Command GNUNET_MESSENGER_cmd_join_room (const char *label, const char *service_label, const char *room_key)
 

Detailed Description

cmd to join a room in a messenger service.

Author
Tobias Frisch

Definition in file messenger_api_cmd_join_room.c.

Function Documentation

◆ join_room_run()

static void join_room_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

Definition at line 42 of file messenger_api_cmd_join_room.c.

44{
45 struct GNUNET_MESSENGER_JoinRoomState *jrs = cls;
46 struct GNUNET_HashCode key;
47
48 if (jrs->room_key)
49 GNUNET_CRYPTO_hash (jrs->room_key, strlen (jrs->room_key), &key);
50 else
51 memset (&key, 0, sizeof(key));
52
53 const struct GNUNET_TESTING_Command *service_cmd;
55 jrs->service_label);
56
58 GNUNET_MESSENGER_get_trait_state (service_cmd, &sss);
59
60 unsigned int peer_index;
61 unsigned int stage_index;
63
65 if (rs)
66 goto skip_room_state;
67
70 &key,
71 rs,
73 {
75 "Testing library failed to create a room state with key '%s'\n",
76 jrs->room_key);
78 return;
79 }
80
81skip_room_state:
82 peer_index = sss->peer_index;
83 stage_index = sss->stage_index;
84
85 const unsigned int index = stage_index * sss->topology->peer_amount
86 + peer_index;
87 const struct GNUNET_MESSENGER_TestStage *stage =
88 &(sss->topology->peer_stages[index]);
89
90 unsigned int door_index = stage->door_id;
91
92 if (door_index == 0)
93 door_index = (peer_index + GNUNET_CRYPTO_random_u32 (
95 sss->topology->peer_amount - 1
96 ) + 1) % sss->topology->peer_amount;
97 else
98 door_index = (door_index - 1) % sss->topology->peer_amount;
99
100 struct GNUNET_PeerIdentity *door;
101 door = GNUNET_TESTING_get_peer (door_index, sss->tl_system);
102 if (! door)
103 {
105 "Testing library failed to get peer identity of index '%u'\n",
106 door_index);
108 return;
109 }
110
111 struct GNUNET_MESSENGER_Room *room;
112 switch (stage->join)
113 {
115 room = GNUNET_MESSENGER_open_room (sss->msg, &key);
116
117 if (! room)
118 {
120 "Testing library failed to open room with key '%s'\n",
121 jrs->room_key);
122 GNUNET_free (door);
124 return;
125 }
126
127 break;
129 room = GNUNET_MESSENGER_enter_room (sss->msg, door, &key);
130
131 if (! room)
132 {
134 "Testing library failed to enter room with key '%s'\n",
135 jrs->room_key);
136 GNUNET_free (door);
138 return;
139 }
140
141 break;
142 default:
143 room = NULL;
144 break;
145 }
146
147 jrs->room = room;
148TODO: sss->stage_index++;
149
150 GNUNET_free (door);
151}
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_HashCode key
The key used in the DHT.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
struct GNUNET_PeerIdentity * GNUNET_TESTING_get_peer(unsigned int num, const struct GNUNET_TESTING_System *tl_system)
Retrieve peer identity from the test system with the unique node id.
Definition: testing.c:2276
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_open_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Open a room to send and receive messages.
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_enter_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Enter a room to send and receive messages through a door opened using GNUNET_MESSENGER_open_room.
enum GNUNET_GenericReturnValue GNUNET_MESSENGER_get_trait_state(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_MESSENGER_StartServiceState **ret)
struct GNUNET_MESSENGER_RoomState * GNUNET_MESSENGER_create_room_state(struct GNUNET_MESSENGER_TestStageTopology *topology)
@ GNUNET_MESSENGER_STAGE_JOIN_ENTER_ROOM
@ GNUNET_MESSENGER_STAGE_JOIN_OPEN_ROOM
A 512-bit hashcode.
struct GNUNET_MESSENGER_Room * room
struct GNUNET_MESSENGER_Handle * msg
struct GNUNET_MESSENGER_TestStageTopology * topology
struct GNUNET_CONTAINER_MultiHashMap * rooms
const struct GNUNET_TESTING_System * tl_system
struct GNUNET_MESSENGER_TestStage * peer_stages
enum GNUNET_MESSENGER_TestStageJoin join
The identity of the host (wraps the signing key of the peer).
A command to be run by the interpreter.

References GNUNET_MESSENGER_TestStage::door_id, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_MESSENGER_create_room_state(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_get_trait_state(), GNUNET_MESSENGER_open_room(), GNUNET_MESSENGER_STAGE_JOIN_ENTER_ROOM, GNUNET_MESSENGER_STAGE_JOIN_OPEN_ROOM, GNUNET_OK, GNUNET_TESTING_get_peer(), GNUNET_TESTING_interpreter_fail(), GNUNET_TESTING_interpreter_lookup_command(), is, GNUNET_MESSENGER_TestStage::join, key, GNUNET_MESSENGER_StartServiceState::msg, GNUNET_MESSENGER_TestStageTopology::peer_amount, GNUNET_MESSENGER_StartServiceState::peer_index, GNUNET_MESSENGER_TestStageTopology::peer_stages, GNUNET_MESSENGER_JoinRoomState::room, GNUNET_MESSENGER_JoinRoomState::room_key, GNUNET_MESSENGER_StartServiceState::rooms, GNUNET_MESSENGER_JoinRoomState::service_label, GNUNET_MESSENGER_StartServiceState::stage_index, GNUNET_MESSENGER_StartServiceState::tl_system, and GNUNET_MESSENGER_StartServiceState::topology.

Referenced by GNUNET_MESSENGER_cmd_join_room().

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

◆ join_room_cleanup()

static void join_room_cleanup ( void *  cls)
static

Definition at line 155 of file messenger_api_cmd_join_room.c.

156{
157 struct GNUNET_MESSENGER_JoinRoomState *jrs = cls;
158
159 GNUNET_free (jrs->room_key);
161 GNUNET_free (jrs);
162}

References GNUNET_free, GNUNET_MESSENGER_JoinRoomState::room_key, and GNUNET_MESSENGER_JoinRoomState::service_label.

Referenced by GNUNET_MESSENGER_cmd_join_room().

Here is the caller graph for this function:

◆ GNUNET_MESSENGER_cmd_join_room()

struct GNUNET_TESTING_Command GNUNET_MESSENGER_cmd_join_room ( const char *  label,
const char *  service_label,
const char *  room_key 
)

Definition at line 166 of file messenger_api_cmd_join_room.c.

169{
171
175
176 return GNUNET_TESTING_command_new (jrs,
177 label,
180 NULL,
181 NULL);
182}
char * room_key
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void join_room_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
static void join_room_cleanup(void *cls)

References GNUNET_new, GNUNET_strdup, GNUNET_TESTING_command_new(), join_room_cleanup(), join_room_run(), room_key, GNUNET_MESSENGER_JoinRoomState::room_key, and GNUNET_MESSENGER_JoinRoomState::service_label.

Here is the call graph for this function: