GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
gnunet-messenger.c File Reference
#include <stdio.h>
#include <unistd.h>
#include "gnunet_identity_service.h"
#include "gnunet_messenger_service.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-messenger.c:

Go to the source code of this file.

Macros

#define MAX_BUFFER_SIZE   57345
 

Functions

static void delay_shutdown (void *cls)
 Delay forced shutdown by input to wait for data processing.
 
static void idle (void *cls)
 Initial task to startup application.
 
static void on_message (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Contact *recipient, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)
 Function called whenever a message is received or sent.
 
static void shutdown_hook (void *cls)
 Task to shut down this application.
 
static void listen_stdio (void *cls)
 Wait for input on STDIO and send it out over the ch.
 
static int iterate_send_private_message (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
 
static void read_stdio (void *cls)
 Task run in stdio mode, after some data is available at stdin.
 
static void on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle)
 Function called when an identity is retrieved.
 
static void on_ego_lookup (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run by the scheduler.
 
int main (int argc, char **argv)
 The main function to obtain messenger information.
 

Variables

const struct GNUNET_CONFIGURATION_Handleconfig
 
struct GNUNET_MESSENGER_Handlemessenger
 
uint64_t waiting
 
struct GNUNET_SCHEDULER_Taskread_task
 
int silence_flag
 
int request_flag
 
int talk_mode
 
struct GNUNET_IDENTITY_EgoLookupego_lookup
 
int private_mode
 
char * door_id
 
char * ego_name
 
char * room_key
 
int public_mode
 
struct GNUNET_SCHEDULER_Taskshutdown_task
 

Macro Definition Documentation

◆ MAX_BUFFER_SIZE

#define MAX_BUFFER_SIZE   57345

Definition at line 437 of file gnunet-messenger.c.

Function Documentation

◆ delay_shutdown()

static void delay_shutdown ( void *  cls)
static

Delay forced shutdown by input to wait for data processing.

Parameters
[in,out]clsClosure

Definition at line 49 of file gnunet-messenger.c.

50{
51 read_task = NULL;
52
53 if (waiting)
54 return;
55
57}
uint64_t waiting
struct GNUNET_SCHEDULER_Task * read_task
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:567

References GNUNET_SCHEDULER_shutdown(), read_task, and waiting.

Referenced by on_message(), and read_stdio().

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

◆ idle()

static void idle ( void *  cls)
static

Initial task to startup application.

Parameters
[in,out]clsClosure

Definition at line 546 of file gnunet-messenger.c.

547{
548 struct GNUNET_MESSENGER_Room *room;
549
550 GNUNET_assert (cls);
551
552 room = cls;
553
554 if ((GNUNET_YES != talk_mode) ||
556 printf ("* You joined the room.\n");
557
559}
static void listen_stdio(void)
Wait for input on STDIO and send it out over the ch.
int talk_mode
int silence_flag
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1304

References GNUNET_assert, GNUNET_SCHEDULER_add_now(), GNUNET_YES, listen_stdio(), read_task, silence_flag, and talk_mode.

Referenced by on_message().

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

◆ on_message()

static void on_message ( void *  cls,
struct GNUNET_MESSENGER_Room room,
const struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Contact recipient,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
enum GNUNET_MESSENGER_MessageFlags  flags 
)
static

Function called whenever a message is received or sent.

Parameters
[in,out]clsClosure
[in]roomRoom
[in]senderSender of message
[in]messageMessage
[in]hashHash of message
[in]flagsFlags of message

Definition at line 74 of file gnunet-messenger.c.

81{
82 uint64_t waited;
83 const char *sender_name;
84 const char *recipient_name;
85
86 waited = waiting;
87
88 if (GNUNET_YES == talk_mode)
89 {
91 {
93 {
94 waiting = waiting > message->body.talk.length?
95 waiting - message->body.talk.length : 0;
96 }
97 else if ((GNUNET_YES != silence_flag) &&
98 (0 < write (1, message->body.talk.data,
99 message->body.talk.length)))
100 {
101 fflush (stdout);
102 }
103 }
104
105 goto skip_printing;
106 }
107 else
108 {
110 {
113
114 GNUNET_MESSENGER_get_message (room, &(message->header.previous));
115 }
116
118 goto skip_printing;
119 }
120
121 sender_name = GNUNET_MESSENGER_contact_get_name (sender);
122 recipient_name = GNUNET_MESSENGER_contact_get_name (recipient);
123
124 if (! sender_name)
125 sender_name = "anonymous";
126
127 if (! recipient_name)
128 recipient_name = "anonymous";
129
130 printf ("[%s ->", GNUNET_h2s (&(message->header.previous)));
131 printf (" %s]", GNUNET_h2s (hash));
132 printf ("[%s] ", GNUNET_sh2s (&(message->header.sender_id)));
133
135 printf ("*( '%s' ) ", recipient_name);
137 printf ("*(~) ");
138
139 switch (message->header.kind)
140 {
142 {
143 printf ("* '%s' joins the room!\n", sender_name);
144 break;
145 }
147 {
148 printf ("* '%s' leaves the room!\n", sender_name);
149 break;
150 }
152 {
153 printf ("* '%s' gets renamed to '%s'\n", sender_name,
154 message->body.name.name);
155 break;
156 }
158 {
159 printf ("* '%s' updates key!\n", sender_name);
160 break;
161 }
163 {
164 printf ("* '%s' opens the room on: %s\n", sender_name,
165 GNUNET_i2s_full (&(message->body.peer.peer)));
166 break;
167 }
169 {
170 printf ("* '%s' changes id to: %s\n", sender_name,
171 GNUNET_sh2s (&(message->body.id.id)));
172 break;
173 }
175 {
176 printf ("* '%s' misses peer: %s\n", sender_name,
177 GNUNET_i2s_full (&(message->body.miss.peer)));
178 break;
179 }
181 {
182 printf ("* '%s' merges: ", sender_name);
183 printf ("[%s ->", GNUNET_h2s (&(message->body.merge.previous)));
184 printf (" %s]\n", GNUNET_h2s (hash));
185 break;
186 }
188 {
189 printf ("* '%s' requests: [%s]\n", sender_name,
190 GNUNET_h2s (&(message->body.request.hash)));
191 break;
192 }
194 {
195 printf ("* '%s' invites to chat on: %s %s\n", sender_name,
196 GNUNET_i2s_full (&(message->body.invite.door)),
197 GNUNET_h2s_full (&(message->body.invite.key.hash)));
198 break;
199 }
201 {
202 uint16_t len;
203
204 if (message->body.text.text)
205 len = strlen (message->body.text.text) + 1;
206 else
207 len = 0;
208
209 if (flags & GNUNET_MESSENGER_FLAG_SENT)
210 {
211 waiting = waiting > len? waiting - len : 0;
212
213 printf (">");
214 }
215 else
216 printf ("<");
217
218 if (message->body.text.text)
219 printf (" '%s' says: \"%s\"\n", sender_name,
220 message->body.text.text);
221 else
222 printf (" '%s' mumbles\n", sender_name);
223 break;
224 }
226 {
227 if (flags & GNUNET_MESSENGER_FLAG_SENT)
228 printf (">");
229 else
230 printf ("<");
231
232 printf (" '%s' shares: \"%s\"\n%s\n", sender_name,
233 message->body.file.name, message->body.file.uri);
234 break;
235 }
237 {
238 if (flags & GNUNET_MESSENGER_FLAG_SENT)
239 printf (">");
240 else
241 printf ("<");
242
243 printf (" '%s' whispers\n", sender_name);
244 break;
245 }
247 {
248 printf ("* '%s' deletes: [%s]\n", sender_name,
249 GNUNET_h2s (&(message->body.deletion.hash)));
250 break;
251 }
253 {
254 printf ("* '%s' updates connection details: %u, %x\n",
255 sender_name,
256 message->body.connection.amount,
257 message->body.connection.flags);
258 break;
259 }
261 {
262 printf ("* '%s' provides ticket: %s\n", sender_name,
263 message->body.ticket.identifier);
264 break;
265 }
267 {
268 if (flags & GNUNET_MESSENGER_FLAG_SENT)
269 printf (">");
270 else
271 printf ("<");
272
273 if (message->body.tag.tag)
274 printf (" '%s' tags [%s] with: \"%s\"\n", sender_name,
275 GNUNET_h2s (&(message->body.tag.hash)),
276 message->body.tag.tag);
277 else
278 printf (" '%s' blocks [%s]\n", sender_name,
279 GNUNET_h2s (&(message->body.tag.hash)));
280 break;
281 }
283 {
284 printf ("* '%s' subscribes: %s\n", sender_name,
285 GNUNET_sh2s (&(message->body.subscribtion.discourse)));
286 break;
287 }
289 {
290 printf ("* '%s' talks %u bytes in: %s\n", sender_name,
291 message->body.talk.length,
292 GNUNET_sh2s (&(message->body.talk.discourse)));
293 break;
294 }
296 {
297 printf ("* '%s' announces epoch key [%s]%s\n", sender_name,
300 " of group" : "");
301 break;
302 }
304 {
305 if (flags & GNUNET_MESSENGER_FLAG_SENT)
306 printf (">");
307 else
308 printf ("<");
309
310 printf (" '%s' whispers towards: %s\n", sender_name,
311 GNUNET_sh2s (&(message->body.secret.identifier.hash)));
312 break;
313 }
315 {
316 printf ("* '%s' appeals the epoch key from: %s\n", sender_name,
317 GNUNET_h2s (&(message->body.appeal.event)));
318 break;
319 }
321 {
322 printf ("* '%s' grants access to: %s\n", sender_name,
323 GNUNET_h2s (&(message->body.access.event)));
324 break;
325 }
327 {
328 printf ("* '%s' revolutionizes the epoch key [%s]%s\n", sender_name,
331 " of group" : "");
332 break;
333 }
335 {
336 printf ("* '%s' proposes group [%s] of { %s", sender_name,
337 GNUNET_sh2s (&(message->body.group.identifier.hash)),
338 GNUNET_h2s (&(message->body.group.initiator)));
339 printf (", %s }\n",
340 GNUNET_h2s (&(message->body.group.partner)));
341 break;
342 }
344 {
345 printf ("* '%s' authorizes group [%s] to: %s\n", sender_name,
347 GNUNET_h2s (&(message->body.authorization.event)));
348 break;
349 }
350 default:
351 {
352 printf ("~ message: %s\n",
354 break;
355 }
356 }
357
358skip_printing:
359 if ((! read_task) && (! waiting) && (waited))
362 delay_shutdown, NULL);
363
364 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) &&
366 {
368 const char *name;
369
370 if (! read_task)
373 idle, room);
374
376
377 if (! name)
378 return;
379
381 response.body.name.name = GNUNET_strdup (name);
382
384
385 GNUNET_free (response.body.name.name);
386
387 if (GNUNET_YES != talk_mode)
388 return;
389
391 response.body.subscribtion.flags =
393 response.body.subscribtion.time =
395
396 memset (&(response.body.subscribtion.discourse), 0,
397 sizeof(response.body.subscribtion.discourse));
398
400 }
401}
static struct MHD_Response * response
Our canonical response.
static void delay_shutdown(void *cls)
Delay forced shutdown by input to wait for data processing.
static void idle(void *cls)
Initial task to startup application.
struct GNUNET_MESSENGER_Handle * messenger
int request_flag
static char * name
Name (label) of the records to list.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_free(ptr)
Wrapper around free.
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
const char * GNUNET_MESSENGER_contact_get_name(const struct GNUNET_MESSENGER_Contact *contact)
Get the name used by the contact.
const struct GNUNET_MESSENGER_Message * GNUNET_MESSENGER_get_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
Get the message in a room identified by its hash and requests it if necessary.
const char * GNUNET_MESSENGER_get_name(const struct GNUNET_MESSENGER_Handle *handle)
Get the name (if specified, otherwise NULL) used by the messenger.
void GNUNET_MESSENGER_send_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_Contact *contact)
Send a message into a room.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_AUTHORIZATION
The authorization kind.
@ GNUNET_MESSENGER_KIND_ANNOUNCEMENT
The announcement kind.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_TAG
The tag kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_APPEAL
The appeal kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_ACCESS
The access kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_REVOLUTION
The revolution kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_SECRET
The secret kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscribtion kind.
@ GNUNET_MESSENGER_KIND_DELETION
The deletion kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_GROUP
The group kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
@ GNUNET_MESSENGER_FLAG_SECRET
The secret flag.
@ GNUNET_MESSENGER_FLAG_PRIVATE
The private flag.
@ GNUNET_MESSENGER_FLAG_SENT
The sent flag.
@ GNUNET_MESSENGER_FLAG_SUBSCRIPTION_KEEP_ALIVE
The keep alive flag.
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:1231
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_(void)
Return relative time of 1s.
Definition time.c:169
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition time.c:620
struct GNUNET_HashCode event
The hash of the linked announcement or group message event.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_HashCode event
The hash of the linked announcement message event.
struct GNUNET_HashCode event
The hash of the linked group message event.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_MESSENGER_MessageAnnouncement announcement
struct GNUNET_MESSENGER_MessageSubscribtion subscribtion
struct GNUNET_MESSENGER_MessageGroup group
struct GNUNET_MESSENGER_MessageSecret secret
struct GNUNET_MESSENGER_MessageDeletion deletion
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageRevolution revolution
struct GNUNET_MESSENGER_MessageTalk talk
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageTag tag
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageAccess access
struct GNUNET_MESSENGER_MessageAuthorization authorization
struct GNUNET_MESSENGER_MessageAppeal appeal
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageTicket ticket
uint32_t amount
The amount of connections of a peer.
uint32_t flags
The flags about the connections of a peer.
struct GNUNET_HashCode hash
The hash of the message to delete.
char * uri
The uri of the encrypted file.
char name[NAME_MAX]
The name of the original file.
struct GNUNET_HashCode initiator
The hash of the initiator group announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode partner
The hash of the partner group announcement.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
union GNUNET_MESSENGER_RoomKey key
The hash identifying the port of the room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
char * name
The new name which replaces the current senders name.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_HashCode hash
The hash of the requested message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscribtion.
struct GNUNET_HashCode hash
The hash of the message to tag.
uint16_t length
The length of the talk message data.
char * data
The data of the talk message.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.
char * identifier
The identifier of a ticket.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_EpochIdentifierCode code

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::appeal, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_EpochIdentifier::code, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessageTalk::data, delay_shutdown(), GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageAppeal::event, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_free, GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_i2s_full(), GNUNET_MESSENGER_contact_get_name(), GNUNET_MESSENGER_FLAG_PRIVATE, GNUNET_MESSENGER_FLAG_SECRET, GNUNET_MESSENGER_FLAG_SENT, GNUNET_MESSENGER_FLAG_SUBSCRIPTION_KEEP_ALIVE, GNUNET_MESSENGER_get_message(), GNUNET_MESSENGER_get_name(), GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_name_of_kind(), GNUNET_MESSENGER_send_message(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_sh2s(), GNUNET_strdup, GNUNET_TIME_relative_get_second_(), GNUNET_TIME_relative_hton(), GNUNET_YES, GNUNET_MESSENGER_MessageBody::group, GNUNET_MESSENGER_EpochIdentifierCode::group_bit, GNUNET_MESSENGER_RoomKey::hash, GNUNET_MESSENGER_EpochIdentifier::hash, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageDeletion::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageGroup::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, idle(), GNUNET_MESSENGER_MessageGroup::initiator, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageBody::merge, messenger, GNUNET_MESSENGER_MessageBody::miss, name, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageGroup::partner, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageMerge::previous, read_task, GNUNET_MESSENGER_MessageBody::request, request_flag, response, GNUNET_MESSENGER_MessageBody::revolution, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageHeader::sender_id, silence_flag, GNUNET_MESSENGER_MessageBody::subscribtion, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, talk_mode, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageFile::uri, and waiting.

Referenced by on_ego_lookup(), and run().

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

◆ shutdown_hook()

static void shutdown_hook ( void *  cls)
static

Task to shut down this application.

Parameters
[in,out]clsClosure

Definition at line 412 of file gnunet-messenger.c.

413{
414 struct GNUNET_MESSENGER_Room *room;
415
416 GNUNET_assert (cls);
417
418 room = cls;
419
420 if (read_task)
422
423 if (room)
425
426 if (messenger)
428
429 if (ego_lookup)
431}
struct GNUNET_IDENTITY_EgoLookup * ego_lookup
void GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el)
Abort ego lookup attempt.
void GNUNET_MESSENGER_disconnect(struct GNUNET_MESSENGER_Handle *handle)
Disconnect all of the messengers used services and clears up its used memory.
void GNUNET_MESSENGER_close_room(struct GNUNET_MESSENGER_Room *room)
Close a room which was entered, opened or both in various order and variety.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980

References ego_lookup, GNUNET_assert, GNUNET_IDENTITY_ego_lookup_cancel(), GNUNET_MESSENGER_close_room(), GNUNET_MESSENGER_disconnect(), GNUNET_SCHEDULER_cancel(), messenger, and read_task.

Referenced by on_identity(), and run().

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

◆ listen_stdio()

static void listen_stdio ( void *  cls)
static

Wait for input on STDIO and send it out over the ch.

Parameters
[in,out]clsClosure

Definition at line 523 of file gnunet-messenger.c.

524{
525 struct GNUNET_NETWORK_FDSet *rs;
526
527 read_task = NULL;
528
531
534 NULL, &read_stdio, cls);
535
537}
static void read_stdio(void *cls)
Task run in stdio mode, after some data is available at stdin.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition network.c:1185
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition network.c:1169
void GNUNET_NETWORK_fdset_set_native(struct GNUNET_NETWORK_FDSet *to, int nfd)
Set a native fd in a set.
Definition network.c:1058
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition scheduler.c:1835
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
collection of IO descriptors

References GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_NETWORK_fdset_set_native(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_TIME_UNIT_FOREVER_REL, read_stdio(), and read_task.

Here is the call graph for this function:

◆ iterate_send_private_message()

static int iterate_send_private_message ( void *  cls,
struct GNUNET_MESSENGER_Room room,
const struct GNUNET_MESSENGER_Contact contact 
)
static

Definition at line 440 of file gnunet-messenger.c.

443{
444 struct GNUNET_MESSENGER_Message *message;
445
446 GNUNET_assert ((cls) && (room) && (contact));
447
448 message = cls;
449
451 GNUNET_MESSENGER_send_message (room, message, contact);
452
453 return GNUNET_YES;
454}
const struct GNUNET_CRYPTO_PublicKey * GNUNET_MESSENGER_contact_get_key(const struct GNUNET_MESSENGER_Contact *contact)
Get the public key used by the contact or NULL if the anonymous key was used.

References GNUNET_assert, GNUNET_MESSENGER_contact_get_key(), GNUNET_MESSENGER_send_message(), and GNUNET_YES.

Referenced by read_stdio().

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

◆ read_stdio()

static void read_stdio ( void *  cls)
static

Task run in stdio mode, after some data is available at stdin.

Parameters
[in,out]clsClosure

Definition at line 465 of file gnunet-messenger.c.

466{
467 struct GNUNET_MESSENGER_Room *room;
468 struct GNUNET_MESSENGER_Message message;
469 char buffer[MAX_BUFFER_SIZE];
470 ssize_t length;
471
472 GNUNET_assert (cls);
473
474 room = cls;
475 read_task = NULL;
476
477 length = read (0, buffer, MAX_BUFFER_SIZE - 1);
478
479 if ((length <= 0) || (length >= MAX_BUFFER_SIZE))
480 {
481 delay_shutdown (NULL);
482 return;
483 }
484
485 waiting += length;
486
487 if (GNUNET_YES == talk_mode)
488 {
489 message.header.kind = GNUNET_MESSENGER_KIND_TALK;
490 message.body.talk.length = length;
491 message.body.talk.data = buffer;
492
493 memset (&(message.body.talk.discourse), 0,
494 sizeof(message.body.talk.discourse));
495 }
496 else
497 {
498 if (buffer[length - 1] == '\n')
499 buffer[length - 1] = '\0';
500 else
501 buffer[length] = '\0';
502
503 message.header.kind = GNUNET_MESSENGER_KIND_TEXT;
504 message.body.text.text = buffer;
505 }
506
509 &message);
510 else
511 GNUNET_MESSENGER_send_message (room, &message, NULL);
512
514}
int private_mode
static int iterate_send_private_message(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
#define MAX_BUFFER_SIZE
int GNUNET_MESSENGER_iterate_members(struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, void *cls)
Iterates through all members of a given room and calls a selected callback for each of them with a pr...

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageTalk::data, delay_shutdown(), GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_assert, GNUNET_MESSENGER_iterate_members(), GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_send_message(), GNUNET_SCHEDULER_add_now(), GNUNET_YES, GNUNET_MESSENGER_Message::header, iterate_send_private_message(), GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageTalk::length, listen_stdio(), MAX_BUFFER_SIZE, private_mode, read_task, GNUNET_MESSENGER_MessageBody::talk, talk_mode, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, and waiting.

Referenced by listen_stdio().

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

◆ on_identity()

static void on_identity ( void *  cls,
struct GNUNET_MESSENGER_Handle handle 
)
static

Function called when an identity is retrieved.

Parameters
[in,out]clsClosure
[in,out]handleHandle of messenger service

Definition at line 577 of file gnunet-messenger.c.

579{
581 struct GNUNET_MESSENGER_Room *room;
582 struct GNUNET_PeerIdentity door_peer;
583 struct GNUNET_PeerIdentity *door;
584 const char *name;
585
587 &key,
588 room_key,
591 GNUNET_NO);
592
593 door = NULL;
594
595 if ((door_id) &&
597 strlen (
598 door_id),
599 &(door_peer.
600 public_key))))
601 door = &door_peer;
602
603 if ((GNUNET_YES == talk_mode) ||
605 goto skip_welcome;
606
608
609 if (! name)
610 name = "anonymous";
611
612 printf ("* Welcome to the messenger, '%s'!\n", name);
613
614skip_welcome:
615 if (door)
616 {
617 if ((GNUNET_YES != talk_mode) ||
619 printf ("* You try to entry a room...\n");
620
622 }
623 else
624 {
625 if ((GNUNET_YES != talk_mode) ||
627 printf ("* You try to open a room...\n");
628
630 }
631
633
635
636 waiting = 0;
637
638 if (! room)
640 else
641 read_task = NULL;
642}
struct GNUNET_HashCode key
The key used in the DHT.
int public_mode
char * door_id
struct GNUNET_SCHEDULER_Task * shutdown_task
char * room_key
static void shutdown_hook(void *cls)
Task to shut down this application.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition gnunet-vpn.c:35
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition crypto_ecc.c:361
@ GNUNET_OK
@ GNUNET_NO
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_enter_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const union GNUNET_MESSENGER_RoomKey *key)
Enter a room to send and receive messages through a door opened using GNUNET_MESSENGER_open_room.
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_open_room(struct GNUNET_MESSENGER_Handle *handle, const union GNUNET_MESSENGER_RoomKey *key)
Open a room to send and receive messages.
void GNUNET_MESSENGER_create_room_key(union GNUNET_MESSENGER_RoomKey *key, const char *input, enum GNUNET_GenericReturnValue is_public, enum GNUNET_GenericReturnValue is_group, enum GNUNET_GenericReturnValue is_feed)
Creates a room key from given optional input string using certain properties for this targeted room.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1339
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
A room key unifies a room key code and its 512bit hash representation.

References door_id, GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_MESSENGER_create_room_key(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_get_name(), GNUNET_MESSENGER_open_room(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), GNUNET_YES, handle, key, messenger, name, GNUNET_PeerIdentity::public_key, public_mode, read_task, room_key, shutdown_hook(), shutdown_task, silence_flag, talk_mode, and waiting.

Referenced by on_ego_lookup(), and run().

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

◆ on_ego_lookup()

static void on_ego_lookup ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

Definition at line 646 of file gnunet-messenger.c.

648{
649 const struct GNUNET_CRYPTO_PrivateKey *key;
650
651 ego_lookup = NULL;
652
653 key = ego ? GNUNET_IDENTITY_ego_get_private_key (ego) : NULL;
654
656 NULL);
657
658 on_identity (NULL, messenger);
659}
static void on_identity(void *cls, struct GNUNET_MESSENGER_Handle *handle)
Function called when an identity is retrieved.
char * ego_name
const struct GNUNET_CONFIGURATION_Handle * config
static void on_message(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Contact *recipient, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)
Function called whenever a message is received or sent.
const struct GNUNET_CRYPTO_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
struct GNUNET_MESSENGER_Handle * GNUNET_MESSENGER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, const struct GNUNET_CRYPTO_PrivateKey *key, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
Set up a handle for the messenger related functions and connects to all necessary services.
A private key for an identity as per LSD0001.

References config, ego_lookup, ego_name, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_MESSENGER_connect(), key, messenger, on_identity(), and on_message().

Referenced by run().

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

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run by the scheduler.

Parameters
[in/out]cls closure
[in]argsremaining command-line arguments
[in]cfgfilename of the configuration file used (for saving, can be NULL!)
[in]cfgconfiguration

Definition at line 671 of file gnunet-messenger.c.

675{
676 config = cfg;
677
678 if (ego_name)
679 {
681 NULL);
682 messenger = NULL;
683 }
684 else
685 {
686 ego_lookup = NULL;
687 messenger = GNUNET_MESSENGER_connect (cfg, NULL, NULL, &on_message, NULL);
688 }
689
691
692 if (messenger)
693 on_identity (NULL, messenger);
694}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static void on_ego_lookup(void *cls, struct GNUNET_IDENTITY_Ego *ego)
struct GNUNET_IDENTITY_EgoLookup * GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
Lookup an ego by name.

References cfg, config, ego_lookup, ego_name, GNUNET_IDENTITY_ego_lookup(), GNUNET_MESSENGER_connect(), GNUNET_SCHEDULER_add_shutdown(), messenger, on_ego_lookup(), on_identity(), on_message(), shutdown_hook(), and shutdown_task.

Referenced by main().

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

◆ main()

int main ( int  argc,
char **  argv 
)

The main function to obtain messenger information.

Parameters
[in]argcnumber of arguments from the command line
[in]argvcommand line arguments
Returns
#EXIT_SUCCESS ok, #EXIT_FAILURE on error

Definition at line 705 of file gnunet-messenger.c.

707{
708 const char *description =
709 "Open and connect to rooms using the MESSENGER to chat.";
710
712 GNUNET_GETOPT_option_string ('d', "door", "PEERIDENTITY",
713 "peer identity to entry into the room",
714 &door_id),
715 GNUNET_GETOPT_option_string ('e', "ego", "IDENTITY",
716 "identity to use for messaging",
717 &ego_name),
718 GNUNET_GETOPT_option_string ('r', "room", "ROOMKEY",
719 "key of the room to connect to",
720 &room_key),
721 GNUNET_GETOPT_option_flag ('p', "private", "flag to enable private mode",
722 &private_mode),
723 GNUNET_GETOPT_option_flag ('s', "silence",
724 "flag to silence all others to send only",
725 &silence_flag),
726 GNUNET_GETOPT_option_flag ('R', "request",
727 "flag to enable requesting older messages",
728 &request_flag),
729 GNUNET_GETOPT_option_flag ('t', "talk", "flag to enable talk mode",
730 &talk_mode),
731 GNUNET_GETOPT_option_flag ('P', "public", "flag to disable forward secrecy",
732 &public_mode),
734 };
735
736 return (GNUNET_OK ==
738 argc,
739 argv,
740 "gnunet-messenger\0",
742 &run,
743 NULL) ? EXIT_SUCCESS : EXIT_FAILURE);
744}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
#define gettext_noop(String)
Definition gettext.h:74
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
Definition of a command line option.
const char * description
Help text for the option (description)

References GNUNET_GETOPT_CommandLineOption::description, door_id, ego_name, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_string(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, private_mode, public_mode, request_flag, room_key, run(), silence_flag, and talk_mode.

Here is the call graph for this function:

Variable Documentation

◆ config

◆ messenger

struct GNUNET_MESSENGER_Handle* messenger

Definition at line 34 of file gnunet-messenger.c.

Referenced by on_ego_lookup(), on_identity(), on_message(), run(), and shutdown_hook().

◆ waiting

uint64_t waiting

Definition at line 36 of file gnunet-messenger.c.

Referenced by delay_shutdown(), on_identity(), on_message(), and read_stdio().

◆ read_task

◆ silence_flag

int silence_flag

Definition at line 39 of file gnunet-messenger.c.

Referenced by idle(), main(), on_identity(), and on_message().

◆ request_flag

int request_flag

Definition at line 40 of file gnunet-messenger.c.

Referenced by main(), and on_message().

◆ talk_mode

int talk_mode

Definition at line 41 of file gnunet-messenger.c.

Referenced by idle(), main(), on_identity(), on_message(), and read_stdio().

◆ ego_lookup

struct GNUNET_IDENTITY_EgoLookup* ego_lookup

Definition at line 404 of file gnunet-messenger.c.

Referenced by on_ego_lookup(), run(), and shutdown_hook().

◆ private_mode

int private_mode

Definition at line 457 of file gnunet-messenger.c.

Referenced by main(), and read_stdio().

◆ door_id

char* door_id

Definition at line 562 of file gnunet-messenger.c.

Referenced by main(), and on_identity().

◆ ego_name

char* ego_name

Definition at line 563 of file gnunet-messenger.c.

Referenced by identity_zone_cb(), main(), on_ego_lookup(), and run().

◆ room_key

char* room_key

Definition at line 564 of file gnunet-messenger.c.

Referenced by GNUNET_MESSENGER_cmd_join_room(), main(), and on_identity().

◆ public_mode

int public_mode

Definition at line 566 of file gnunet-messenger.c.

Referenced by main(), and on_identity().

◆ shutdown_task