GNUnet  0.10.x
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
gnunet-conversation.c File Reference

conversation implementation More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_conversation_service.h"
#include "gnunet_namestore_service.h"
Include dependency graph for gnunet-conversation.c:

Go to the source code of this file.

Data Structures

struct  CallList
 List of incoming calls. More...
 
struct  VoipCommand
 Structure which defines a command. More...
 

Macros

#define MAX_MESSAGE_LENGTH   1024
 Maximum length allowed for the command line input. More...
 
#define XSTRINGIFY(x)   STRINGIFY(x)
 
#define STRINGIFY(x)   (#x)
 

Typedefs

typedef void(* ActionFunction) (const char *arguments)
 Function declareation for executing a action. More...
 

Enumerations

enum  PhoneState {
  PS_REGISTER = 0, PS_READY, PS_LOOKUP_EGO, PS_LISTEN,
  PS_ACCEPTED, PS_ERROR
}
 Possible states of the phone. More...
 
enum  CallState {
  CS_LOOKUP = 0, CS_RINGING, CS_ACTIVE, CS_SHUTDOWN,
  CS_SUSPENDED_CALLER, CS_SUSPENDED_CALLEE, CS_SUSPENDED_BOTH, CS_RESOLVING,
  CS_RINGING, CS_CONNECTED, CS_SUSPENDED
}
 States for current outgoing call. More...
 

Functions

static void phone_event_handler (void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
 Function called with an event emitted by a phone. More...
 
static void caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
 Function called with an event emitted by a caller. More...
 
static void start_phone ()
 Start our phone. More...
 
static void call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
 Function called with an event emitted by a call. More...
 
static void do_help (const char *args)
 Action function to print help for the command shell. More...
 
static void do_quit (const char *args)
 Terminate the client. More...
 
static void do_unknown (const char *msg)
 Handler for unknown command. More...
 
static void do_call (const char *arg)
 Initiating a new call. More...
 
static void do_accept (const char *args)
 Accepting an incoming call. More...
 
static void do_address (const char *args)
 Print address information for this phone. More...
 
static void do_status (const char *args)
 Accepting an incoming call. More...
 
static void do_suspend (const char *args)
 Suspending a call. More...
 
static void do_resume (const char *args)
 Resuming a call. More...
 
static void do_reject (const char *args)
 Rejecting a call. More...
 
static void do_stop_task (void *cls)
 Task run during shutdown. More...
 
static void handle_command_string (char *message, size_t str_len)
 Handle user command. More...
 
static void handle_command (void *cls)
 Task to handle commands from the terminal. More...
 
static void identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
 Function called by identity service with information about egos. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 The main function to conversation. More...
 

Variables

static struct GNUNET_CONVERSATION_Phonephone
 Phone handle. More...
 
static struct GNUNET_CONVERSATION_Callcall
 Call handle (for active outgoing call). More...
 
static struct CallListcl_active
 Caller handle (for active incoming call). More...
 
static struct CallListcl_head
 Head of calls waiting to be accepted. More...
 
static struct CallListcl_tail
 Tail of calls waiting to be accepted. More...
 
static char * line
 Desired phone line (string to be converted to a hash). More...
 
static struct GNUNET_SCHEDULER_Taskhandle_cmd_task
 Task which handles the commands. More...
 
static struct GNUNET_SPEAKER_Handlespeaker
 Our speaker. More...
 
static struct GNUNET_MICROPHONE_Handlemic
 Our microphone. More...
 
static struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static struct GNUNET_IDENTITY_Egomy_caller_id
 Our ego. More...
 
static struct GNUNET_IDENTITY_Handleid
 Handle to identity service. More...
 
static char * ego_name
 Name of our ego. More...
 
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
 Public key of active conversation partner (if any). More...
 
static char * peer_name
 Name of active conversation partner (if any). More...
 
static struct GNUNET_DISK_FileHandlestdin_fh
 File handle for stdin. More...
 
static enum PhoneState phone_state
 Our phone's current state. More...
 
static enum CallState call_state
 Our call's current state. More...
 
static unsigned int caller_num_gen
 Counts the number of incoming calls we have had so far. More...
 
static char * address
 GNS address for this phone. More...
 
static int verbose
 Be verbose. More...
 
static struct VoipCommand commands []
 List of supported commands. More...
 

Detailed Description

conversation implementation

Author
Simon Dieterle
Andreas Fuchs

Definition in file gnunet-conversation.c.

Macro Definition Documentation

◆ MAX_MESSAGE_LENGTH

#define MAX_MESSAGE_LENGTH   1024

Maximum length allowed for the command line input.

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

Referenced by handle_command().

◆ XSTRINGIFY

#define XSTRINGIFY (   x)    STRINGIFY(x)

Definition at line 38 of file gnunet-conversation.c.

◆ STRINGIFY

#define STRINGIFY (   x)    (#x)

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

Typedef Documentation

◆ ActionFunction

typedef void(* ActionFunction) (const char *arguments)

Function declareation for executing a action.

Parameters
argumentsarguments given to the function

Definition at line 444 of file gnunet-conversation.c.

Enumeration Type Documentation

◆ PhoneState

enum PhoneState

Possible states of the phone.

Enumerator
PS_REGISTER 

We still need to register the phone.

PS_READY 

We are waiting for calls.

PS_LOOKUP_EGO 

We're waiting for our own idenitty.

PS_LISTEN 

We're listening for calls.

PS_ACCEPTED 

We accepted an incoming phone call.

PS_ERROR 

Internal error.

Definition at line 45 of file gnunet-conversation.c.

45  {
50 
54  PS_LISTEN,
55 
60 
64  PS_ERROR
65 };
Internal error.
We're waiting for our own idenitty.
We accepted an incoming phone call.
We're listening for calls.

◆ CallState

enum CallState

States for current outgoing call.

Enumerator
CS_LOOKUP 

We still need to lookup the callee.

CS_RINGING 

The call is ringing.

CS_ACTIVE 

The call is in an active conversation.

CS_SHUTDOWN 

The call is in termination.

CS_SUSPENDED_CALLER 

The call was suspended by the caller.

CS_SUSPENDED_CALLEE 

The call was suspended by the callee.

CS_SUSPENDED_BOTH 

The call was suspended by both caller and callee.

CS_RESOLVING 

We are looking up some other participant.

CS_RINGING 

We are now ringing the other participant.

CS_CONNECTED 

The other party accepted our call and we are now connected.

CS_SUSPENDED 

The call is currently suspended (by us).

Definition at line 71 of file gnunet-conversation.c.

71  {
76 
80  CS_RINGING,
81 
86 
91 };
The other party accepted our call and we are now connected.
We are now ringing the other participant.
The call is currently suspended (by us).
We are looking up some other participant.

Function Documentation

◆ phone_event_handler()

static void phone_event_handler ( void *  cls,
enum GNUNET_CONVERSATION_PhoneEventCode  code,
struct GNUNET_CONVERSATION_Caller caller,
const struct GNUNET_CRYPTO_EcdsaPublicKey caller_id 
)
static

Function called with an event emitted by a phone.

Parameters
clsclosure
codetype of the event
callerhandle for the caller
caller_idpublic key of the caller (in GNS)

Definition at line 241 of file gnunet-conversation.c.

References _, CallList::caller, CallList::caller_id, CallList::caller_num, caller_num_gen, cl_active, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, GNUNET_CONVERSATION_EC_PHONE_RING, GNUNET_free, GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_new, CallList::next, phone_state, and PS_LISTEN.

Referenced by start_phone().

245 {
246  struct CallList *cl;
247 
248  (void)cls;
249  switch (code)
250  {
252  /*
253  * FIXME: we should be playing our ringtones from contrib/sounds now!
254  *
255  ring_my_bell();
256  *
257  * see https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html on how to play a wav using the gst framework being used here
258  */
259  fprintf(
260  stdout,
261  _(
262  "Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"),
266  cl = GNUNET_new(struct CallList);
267  cl->caller = caller;
268  cl->caller_id = *caller_id;
269  cl->caller_num = caller_num_gen++;
271  break;
272 
274  for (cl = cl_head; NULL != cl; cl = cl->next)
275  if (caller == cl->caller)
276  break;
277  if ((NULL == cl) && (caller == cl_active->caller))
278  cl = cl_active;
279  if (NULL == cl)
280  {
281  GNUNET_break(0);
282  return;
283  }
284  fprintf(stdout,
285  _("Call from `%s' terminated\n"),
287  if (cl == cl_active)
288  {
289  cl_active = NULL;
291  }
292  else
293  {
295  }
296  GNUNET_free(cl);
297  break;
298  }
299 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct CallList * cl_tail
Tail of calls waiting to be accepted.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
List of incoming calls.
unsigned int caller_num
Unique number of the call.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct CallList * next
A DLL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
The conversation was terminated by the caller.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
We're listening for calls.
We are the callee and the phone is ringing.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
static unsigned int caller_num_gen
Counts the number of incoming calls we have had so far.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Public key identifying the caller.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ caller_event_handler()

static void caller_event_handler ( void *  cls,
enum GNUNET_CONVERSATION_CallerEventCode  code 
)
static

Function called with an event emitted by a caller.

Parameters
clsclosure with the struct CallList of the caller
codetype of the event issued by the caller

Definition at line 309 of file gnunet-conversation.c.

References _, CallList::caller_id, GNUNET_CONVERSATION_EC_CALLER_RESUME, GNUNET_CONVERSATION_EC_CALLER_SUSPEND, and GNUNET_GNSRECORD_pkey_to_zkey().

Referenced by do_accept().

310 {
311  struct CallList *cl = cls;
312 
313  switch (code)
314  {
316  fprintf(stdout,
317  _("Call from `%s' suspended by other user\n"),
319  break;
320 
322  fprintf(stdout,
323  _("Call from `%s' resumed by other user\n"),
325  break;
326  }
327 }
List of incoming calls.
We are the callee and the caller resumed the call.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
We are the callee and the caller suspended the call.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Public key identifying the caller.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_phone()

static void start_phone ( )
static

Start our phone.

Definition at line 334 of file gnunet-conversation.c.

References _, address, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, ego_name, GNUNET_assert, GNUNET_CONVERSATION_phone_create(), GNUNET_CONVERSATION_phone_get_record(), GNUNET_free_non_null, GNUNET_GNSRECORD_value_to_string(), phone_event_handler(), phone_state, PS_ERROR, PS_LISTEN, PS_LOOKUP_EGO, and GNUNET_GNSRECORD_Data::record_type.

Referenced by identity_cb().

335 {
336  struct GNUNET_GNSRECORD_Data rd;
337 
338  if (NULL == my_caller_id)
339  {
340  fprintf(stderr,
341  _("Ego `%s' no longer available, phone is now down.\n"),
342  ego_name);
344  return;
345  }
346  GNUNET_assert(NULL == phone);
348  my_caller_id,
350  NULL);
351  /* FIXME: get record and print full GNS record info later here... */
352  if (NULL == phone)
353  {
354  fprintf(stderr, "%s", _("Failed to setup phone (internal error)\n"));
356  }
357  else
358  {
361  address =
362  GNUNET_GNSRECORD_value_to_string(rd.record_type, rd.data, rd.data_size);
363  fprintf(
364  stdout,
365  _(
366  "Phone active at `%s'. Type `/help' for a list of available commands\n"),
367  address);
369  }
370 }
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
Internal error.
We're waiting for our own idenitty.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * ego_name
Name of our ego.
static enum PhoneState phone_state
Our phone's current state.
void GNUNET_CONVERSATION_phone_get_record(struct GNUNET_CONVERSATION_Phone *phone, struct GNUNET_GNSRECORD_Data *rd)
Fill in a namestore record with the contact information for this phone.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_IDENTITY_Ego * my_caller_id
Our ego.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void phone_event_handler(void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
Function called with an event emitted by a phone.
We're listening for calls.
struct GNUNET_CONVERSATION_Phone * GNUNET_CONVERSATION_phone_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_IDENTITY_Ego *ego, GNUNET_CONVERSATION_PhoneEventHandler event_handler, void *event_handler_cls)
Create a new phone.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
Definition: gnsrecord.c:142
static char * address
GNS address for this phone.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ call_event_handler()

static void call_event_handler ( void *  cls,
enum GNUNET_CONVERSATION_CallEventCode  code 
)
static

Function called with an event emitted by a call.

Parameters
clsclosure, NULL
codetype of the event on the call

Definition at line 380 of file gnunet-conversation.c.

References _, call_state, CS_CONNECTED, CS_RESOLVING, CS_RINGING, GNUNET_break, GNUNET_CONVERSATION_EC_CALL_ERROR, GNUNET_CONVERSATION_EC_CALL_GNS_FAIL, GNUNET_CONVERSATION_EC_CALL_HUNG_UP, GNUNET_CONVERSATION_EC_CALL_PICKED_UP, GNUNET_CONVERSATION_EC_CALL_RESUMED, GNUNET_CONVERSATION_EC_CALL_RINGING, GNUNET_CONVERSATION_EC_CALL_SUSPENDED, GNUNET_free, and peer_name.

Referenced by do_call().

381 {
382  (void)cls;
383 
384  switch (code)
385  {
388  fprintf(stdout,
389  _("Resolved address of `%s'. Now ringing other party.\n"),
390  peer_name);
392  break;
393 
396  fprintf(stdout, _("Connection established to `%s'\n"), peer_name);
398  break;
399 
402  fprintf(stdout, _("Failed to resolve `%s'\n"), peer_name);
404  peer_name = NULL;
405  call = NULL;
406  break;
407 
409  fprintf(stdout, _("Call to `%s' terminated\n"), peer_name);
411  peer_name = NULL;
412  call = NULL;
413  break;
414 
417  fprintf(stdout,
418  _("Connection to `%s' suspended (by other user)\n"),
419  peer_name);
420  break;
421 
424  fprintf(stdout,
425  _("Connection to `%s' resumed (by other user)\n"),
426  peer_name);
427  break;
428 
430  fprintf(stdout, _("Error with the call, restarting it\n"));
432  peer_name = NULL;
433  call = NULL;
434  break;
435  }
436 }
static enum CallState call_state
Our call's current state.
We are the caller and the callee suspended the call.
static char * peer_name
Name of active conversation partner (if any).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
We are the caller and are now ready to talk as the callee picked up.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
We are the caller and are now ringing the other party (GNS lookup succeeded).
We are the caller and the callee called GNUNET_CONVERSATION_caller_hang_up.
We are the caller and failed to locate a phone record in GNS.
The other party accepted our call and we are now connected.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We are now ringing the other participant.
We are the caller and the callee suspended the call.
We had an error handing the call, and are now restarting it (back to lookup).
We are looking up some other participant.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ do_help()

static void do_help ( const char *  args)
static

Action function to print help for the command shell.

Parameters
argsarguments given to the command

Definition at line 973 of file gnunet-conversation.c.

References VoipCommand::Action, VoipCommand::command, gettext, and VoipCommand::helptext.

Referenced by do_call().

974 {
975  unsigned int i;
976 
977  i = 0;
978  while ((NULL != args) && (0 != strlen(args)) &&
979  (commands[i].Action != &do_help))
980  {
981  if (0 == strncasecmp(&args[1], &commands[i].command[1], strlen(args) - 1))
982  {
983  fprintf(stdout, "%s\n", gettext(commands[i].helptext));
984  return;
985  }
986  i++;
987  }
988  i = 0;
989  fprintf(stdout, "%s", "Available commands:\n");
990  while (commands[i].Action != &do_help)
991  {
992  fprintf(stdout, "%s\n", gettext(commands[i].command));
993  i++;
994  }
995  fprintf(stdout, "%s", "\n");
996  fprintf(stdout, "%s\n", gettext(commands[i].helptext));
997 }
#define gettext(Msgid)
Definition: gettext.h:45
static struct VoipCommand commands[]
List of supported commands.
static void do_help(const char *args)
Action function to print help for the command shell.
Here is the caller graph for this function:

◆ do_quit()

static void do_quit ( const char *  args)
static

Terminate the client.

Parameters
argsarguments given to the command

Definition at line 483 of file gnunet-conversation.c.

References GNUNET_SCHEDULER_shutdown().

484 {
485  (void)args;
487 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
Here is the call graph for this function:

◆ do_unknown()

static void do_unknown ( const char *  msg)
static

Handler for unknown command.

Parameters
msgarguments given to the command

Definition at line 496 of file gnunet-conversation.c.

References _.

497 {
498  fprintf(stderr, _("Unknown command `%s'\n"), msg);
499 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define _(String)
GNU gettext support macro.
Definition: platform.h:181

◆ do_call()

static void do_call ( const char *  arg)
static

Initiating a new call.

Parameters
argarguments given to the command

Definition at line 508 of file gnunet-conversation.c.

References _, call_event_handler(), call_state, CS_RESOLVING, do_help(), ego_name, GNUNET_assert, GNUNET_CONVERSATION_call_start(), GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_strdup, peer_key, peer_name, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

509 {
510  if (NULL == my_caller_id)
511  {
512  fprintf(stderr, _("Ego `%s' not available\n"), ego_name);
513  return;
514  }
515  if (NULL != call)
516  {
517  fprintf(stderr,
518  _("You are calling someone else already, hang up first!\n"));
519  return;
520  }
521  switch (phone_state)
522  {
523  case PS_LOOKUP_EGO:
524  fprintf(stderr, _("Ego `%s' not available\n"), ego_name);
525  return;
526 
527  case PS_LISTEN:
528  /* ok to call! */
529  break;
530 
531  case PS_ACCEPTED:
532  fprintf(
533  stderr,
534  _(
535  "You are answering call from `%s', hang up or suspend that call first!\n"),
537  return;
538 
539  case PS_ERROR:
540  /* ok to call */
541  break;
542  }
543  if (NULL == arg)
544  {
545  fprintf(stderr, _("Call recipient missing.\n"));
546  do_help("/call");
547  return;
548  }
551  GNUNET_assert(NULL == call);
553  my_caller_id,
554  arg,
555  speaker,
556  mic,
558  NULL);
559 }
Internal error.
We're waiting for our own idenitty.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static enum CallState call_state
Our call's current state.
static char * ego_name
Name of our ego.
static enum PhoneState phone_state
Our phone's current state.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * peer_name
Name of active conversation partner (if any).
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
We accepted an incoming phone call.
static struct GNUNET_IDENTITY_Ego * my_caller_id
Our ego.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
struct GNUNET_CONVERSATION_Call * GNUNET_CONVERSATION_call_start(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_IDENTITY_Ego *caller_id, const char *callee, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic, GNUNET_CONVERSATION_CallEventHandler event_handler, void *event_handler_cls)
Call the phone of another user.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
Public key of active conversation partner (if any).
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
static void call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
Function called with an event emitted by a call.
We are looking up some other participant.
static void do_help(const char *args)
Action function to print help for the command shell.
Here is the call graph for this function:

◆ do_accept()

static void do_accept ( const char *  args)
static

Accepting an incoming call.

Parameters
argsarguments given to the command

Definition at line 568 of file gnunet-conversation.c.

References _, buf, call_state, CallList::caller, caller_event_handler(), CallList::caller_id, CallList::caller_num, cl_head, CS_SUSPENDED, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONVERSATION_caller_pick_up(), GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_snprintf(), CallList::next, peer_key, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

569 {
570  struct CallList *cl;
571  char buf[32];
572 
573  if ((NULL != call) && (CS_SUSPENDED != call_state))
574  {
575  fprintf(stderr,
576  _("You are calling someone else already, hang up first!\n"));
577  return;
578  }
579  switch (phone_state)
580  {
581  case PS_LOOKUP_EGO:
582  GNUNET_break(0);
583  break;
584 
585  case PS_LISTEN:
586  /* this is the expected state */
587  break;
588 
589  case PS_ACCEPTED:
590  fprintf(
591  stderr,
592  _(
593  "You are answering call from `%s', hang up or suspend that call first!\n"),
595  return;
596 
597  case PS_ERROR:
598  GNUNET_break(0);
599  break;
600  }
601  cl = cl_head;
602  if (NULL == cl)
603  {
604  fprintf(stderr, _("There is no incoming call to accept here!\n"));
605  return;
606  }
607  if ((NULL != cl->next) || (NULL != args))
608  {
609  for (cl = cl_head; NULL != cl; cl = cl->next)
610  {
611  GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num);
612  if (0 == strcmp(buf, args))
613  break;
614  }
615  }
616  if (NULL == cl)
617  {
618  fprintf(stderr,
619  _("There is no incoming call `%s' to accept right now!\n"),
620  args);
621  return;
622  }
624  cl_active = cl;
625  peer_key = cl->caller_id;
629  cl,
630  speaker,
631  mic);
632 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct CallList * cl_tail
Tail of calls waiting to be accepted.
Internal error.
We're waiting for our own idenitty.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
List of incoming calls.
unsigned int caller_num
Unique number of the call.
static enum CallState call_state
Our call's current state.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct CallList * next
A DLL.
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
We accepted an incoming phone call.
static void caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
Function called with an event emitted by a caller.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
static char buf[2048]
void GNUNET_CONVERSATION_caller_pick_up(struct GNUNET_CONVERSATION_Caller *caller, GNUNET_CONVERSATION_CallerEventHandler event_handler, void *event_handler_cls, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic)
Picks up a (ringing) phone.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
Public key of active conversation partner (if any).
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
The call is currently suspended (by us).
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Public key identifying the caller.
Here is the call graph for this function:

◆ do_address()

static void do_address ( const char *  args)
static

Print address information for this phone.

Parameters
argsarguments given to the command

Definition at line 641 of file gnunet-conversation.c.

References _, and address.

642 {
643  (void)args;
644  if (NULL == address)
645  {
646  fprintf(stdout, "%s", _("We currently do not have an address.\n"));
647  return;
648  }
649  fprintf(stdout, "%s\n", address);
650 }
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * address
GNS address for this phone.

◆ do_status()

static void do_status ( const char *  args)
static

Accepting an incoming call.

Parameters
argsarguments given to the command

Definition at line 659 of file gnunet-conversation.c.

References _, call_state, CallList::caller_id, CallList::caller_num, CS_CONNECTED, CS_RESOLVING, CS_RINGING, CS_SUSPENDED, ego_name, GNUNET_GNSRECORD_pkey_to_zkey(), line, CallList::next, peer_key, peer_name, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

660 {
661  struct CallList *cl;
662 
663  (void)args;
664  switch (phone_state)
665  {
666  case PS_LOOKUP_EGO:
667  fprintf(
668  stdout,
669  _(
670  "We are currently trying to locate the private key for the ego `%s'.\n"),
671  ego_name);
672  break;
673 
674  case PS_LISTEN:
675  fprintf(stdout,
676  _(
677  "We are listening for incoming calls for ego `%s' on line `%s'.\n"),
678  ego_name,
679  line);
680  break;
681 
682  case PS_ACCEPTED:
683  fprintf(stdout,
684  _("You are having a conversation with `%s'.\n"),
686  ;
687  break;
688 
689  case PS_ERROR:
690  fprintf(
691  stdout,
692  _(
693  "We had an internal error setting up our phone line. You can still make calls.\n"));
694  break;
695  }
696  if (NULL != call)
697  {
698  switch (call_state)
699  {
700  case CS_RESOLVING:
701  fprintf(stdout,
702  _("We are trying to find the network address to call `%s'.\n"),
703  peer_name);
704  break;
705 
706  case CS_RINGING:
707  fprintf(stdout,
708  _("We are calling `%s', their phone should be ringing.\n"),
709  peer_name);
710  break;
711 
712  case CS_CONNECTED:
713  fprintf(stdout,
714  _("You are having a conversation with `%s'.\n"),
715  peer_name);
716  break;
717 
718  case CS_SUSPENDED:
719  /* ok to accept incoming call right now */
720  break;
721  }
722  }
723  if ((NULL != cl_head) && ((cl_head != cl_active) || (cl_head != cl_tail)))
724  {
725  fprintf(stdout, "%s", _("Calls waiting:\n"));
726  for (cl = cl_head; NULL != cl; cl = cl->next)
727  {
728  if (cl == cl_active)
729  continue;
730  fprintf(stdout,
731  _("#%u: `%s'\n"),
732  cl->caller_num,
734  }
735  fprintf(stdout, "%s", "\n");
736  }
737 }
static struct CallList * cl_tail
Tail of calls waiting to be accepted.
Internal error.
We're waiting for our own idenitty.
List of incoming calls.
unsigned int caller_num
Unique number of the call.
static enum CallState call_state
Our call's current state.
static char * ego_name
Name of our ego.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
static char * peer_name
Name of active conversation partner (if any).
struct CallList * next
A DLL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * line
Desired phone line (string to be converted to a hash).
We accepted an incoming phone call.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
Public key of active conversation partner (if any).
The other party accepted our call and we are now connected.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
We are now ringing the other participant.
static struct CallList * cl_active
Caller handle (for active incoming call).
The call is currently suspended (by us).
We are looking up some other participant.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Public key identifying the caller.
Here is the call graph for this function:

◆ do_suspend()

static void do_suspend ( const char *  args)
static

Suspending a call.

Parameters
argsarguments given to the command

Definition at line 746 of file gnunet-conversation.c.

References _, call_state, CallList::caller, CS_CONNECTED, CS_RESOLVING, CS_RINGING, CS_SUSPENDED, GNUNET_assert, GNUNET_CONVERSATION_call_suspend(), GNUNET_CONVERSATION_caller_suspend(), phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

747 {
748  (void)args;
749  if (NULL != call)
750  {
751  switch (call_state)
752  {
753  case CS_RESOLVING:
754  case CS_RINGING:
755  case CS_SUSPENDED:
756  fprintf(stderr,
757  "%s",
758  _("There is no call that could be suspended right now.\n"));
759  return;
760 
761  case CS_CONNECTED:
764  return;
765  }
766  }
767  switch (phone_state)
768  {
769  case PS_LOOKUP_EGO:
770  case PS_LISTEN:
771  case PS_ERROR:
772  fprintf(stderr,
773  "%s",
774  _("There is no call that could be suspended right now.\n"));
775  return;
776 
777  case PS_ACCEPTED:
778  /* expected state, do rejection logic */
779  break;
780  }
781  GNUNET_assert(NULL != cl_active);
783  cl_active = NULL;
785 }
Internal error.
We're waiting for our own idenitty.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static enum CallState call_state
Our call's current state.
static enum PhoneState phone_state
Our phone's current state.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
We accepted an incoming phone call.
The other party accepted our call and we are now connected.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
void GNUNET_CONVERSATION_caller_suspend(struct GNUNET_CONVERSATION_Caller *caller)
Pause conversation of an active call.
We are now ringing the other participant.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
The call is currently suspended (by us).
We are looking up some other participant.
void GNUNET_CONVERSATION_call_suspend(struct GNUNET_CONVERSATION_Call *call)
Pause a call.
Here is the call graph for this function:

◆ do_resume()

static void do_resume ( const char *  args)
static

Resuming a call.

Parameters
argsarguments given to the command

Definition at line 794 of file gnunet-conversation.c.

References _, buf, call_state, CallList::caller, CallList::caller_num, cl_head, CS_CONNECTED, CS_RESOLVING, CS_RINGING, CS_SUSPENDED, GNUNET_assert, GNUNET_CONVERSATION_call_resume(), GNUNET_CONVERSATION_caller_resume(), GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_snprintf(), CallList::next, peer_key, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

795 {
796  struct CallList *cl;
797  char buf[32];
798 
799  if (NULL != call)
800  {
801  switch (call_state)
802  {
803  case CS_RESOLVING:
804  case CS_RINGING:
805  case CS_CONNECTED:
806  fprintf(stderr,
807  "%s",
808  _("There is no call that could be resumed right now.\n"));
809  return;
810 
811  case CS_SUSPENDED:
814  return;
815  }
816  }
817  switch (phone_state)
818  {
819  case PS_LOOKUP_EGO:
820  case PS_ERROR:
821  fprintf(stderr,
822  "%s",
823  _("There is no call that could be resumed right now.\n"));
824  return;
825 
826  case PS_LISTEN:
827  /* expected state, do resume logic */
828  break;
829 
830  case PS_ACCEPTED:
831  fprintf(stderr,
832  _("Already talking with `%s', cannot resume a call right now.\n"),
834  return;
835  }
836  GNUNET_assert(NULL == cl_active);
837  cl = cl_head;
838  if (NULL == cl)
839  {
840  fprintf(stderr, _("There is no incoming call to resume here!\n"));
841  return;
842  }
843  if ((NULL != cl->next) || (NULL != args))
844  {
845  for (cl = cl_head; NULL != cl; cl = cl->next)
846  {
847  GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num);
848  if (0 == strcmp(buf, args))
849  break;
850  }
851  }
852  if (NULL == cl)
853  {
854  fprintf(stderr,
855  _("There is no incoming call `%s' to resume right now!\n"),
856  args);
857  return;
858  }
859  cl_active = cl;
862 }
Internal error.
We're waiting for our own idenitty.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
List of incoming calls.
unsigned int caller_num
Unique number of the call.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static enum CallState call_state
Our call's current state.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
struct CallList * next
A DLL.
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
We accepted an incoming phone call.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
void GNUNET_CONVERSATION_call_resume(struct GNUNET_CONVERSATION_Call *call, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic)
Resumes a call after GNUNET_CONVERSATION_call_suspend.
static char buf[2048]
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
Public key of active conversation partner (if any).
The other party accepted our call and we are now connected.
void GNUNET_CONVERSATION_caller_resume(struct GNUNET_CONVERSATION_Caller *caller, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic)
Resume suspended conversation of a phone.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
We are now ringing the other participant.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
The call is currently suspended (by us).
We are looking up some other participant.
Here is the call graph for this function:

◆ do_reject()

static void do_reject ( const char *  args)
static

Rejecting a call.

Parameters
argsarguments given to the command

Definition at line 871 of file gnunet-conversation.c.

References _, buf, CallList::caller, CallList::caller_num, cl_head, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONVERSATION_call_stop(), GNUNET_CONVERSATION_caller_hang_up(), GNUNET_free, GNUNET_snprintf(), CallList::next, phone_state, PS_ACCEPTED, PS_ERROR, PS_LISTEN, and PS_LOOKUP_EGO.

872 {
873  struct CallList *cl;
874  char buf[32];
875 
876  if (NULL != call)
877  {
879  call = NULL;
880  return;
881  }
882  switch (phone_state)
883  {
884  case PS_LOOKUP_EGO:
885  case PS_ERROR:
886  fprintf(stderr,
887  "%s",
888  _("There is no call that could be cancelled right now.\n"));
889  return;
890 
891  case PS_LISTEN:
892  /* look for active incoming calls to refuse */
893  cl = cl_head;
894  if (NULL == cl)
895  {
896  fprintf(stderr, _("There is no incoming call to refuse here!\n"));
897  return;
898  }
899  if ((NULL != cl->next) || (NULL != args))
900  {
901  for (cl = cl_head; NULL != cl; cl = cl->next)
902  {
903  GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num);
904  if (0 == strcmp(buf, args))
905  break;
906  }
907  }
908  if (NULL == cl)
909  {
910  fprintf(stderr,
911  _("There is no incoming call `%s' to refuse right now!\n"),
912  args);
913  return;
914  }
917  GNUNET_free(cl);
918  break;
919 
920  case PS_ACCEPTED:
921  /* expected state, do rejection logic */
922  GNUNET_assert(NULL != cl_active);
924  cl_active = NULL;
926  break;
927  }
928 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct CallList * cl_tail
Tail of calls waiting to be accepted.
Internal error.
We're waiting for our own idenitty.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
List of incoming calls.
unsigned int caller_num
Unique number of the call.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller)
Hang up up a (possibly ringing) phone.
static enum PhoneState phone_state
Our phone's current state.
static struct CallList * cl_head
Head of calls waiting to be accepted.
struct CallList * next
A DLL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
We accepted an incoming phone call.
static char buf[2048]
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
We're listening for calls.
void GNUNET_CONVERSATION_call_stop(struct GNUNET_CONVERSATION_Call *call)
Terminate a call.
static struct CallList * cl_active
Caller handle (for active incoming call).
struct GNUNET_CONVERSATION_Caller * caller
Handle to hang up or activate.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ do_stop_task()

static void do_stop_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsNULL

Definition at line 1006 of file gnunet-conversation.c.

References ego_name, GNUNET_CONVERSATION_call_stop(), GNUNET_CONVERSATION_phone_destroy(), GNUNET_free, GNUNET_free_non_null, GNUNET_IDENTITY_disconnect(), GNUNET_MICROPHONE_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_SPEAKER_destroy(), peer_name, phone_state, and PS_ERROR.

Referenced by run().

1007 {
1008  (void)cls;
1009  if (NULL != call)
1010  {
1012  call = NULL;
1013  }
1014  if (NULL != phone)
1015  {
1017  phone = NULL;
1018  }
1019  if (NULL != handle_cmd_task)
1020  {
1022  handle_cmd_task = NULL;
1023  }
1024  if (NULL != id)
1025  {
1027  id = NULL;
1028  }
1030  speaker = NULL;
1032  mic = NULL;
1034  ego_name = NULL;
1036  peer_name = NULL;
1038 }
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
Internal error.
static struct GNUNET_SCHEDULER_Task * handle_cmd_task
Task which handles the commands.
static char * ego_name
Name of our ego.
static enum PhoneState phone_state
Our phone's current state.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static char * peer_name
Name of active conversation partner (if any).
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
void GNUNET_CONVERSATION_phone_destroy(struct GNUNET_CONVERSATION_Phone *phone)
Destroys a phone.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:835
void GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker)
Destroy a speaker.
Definition: speaker.c:181
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
void GNUNET_MICROPHONE_destroy(struct GNUNET_MICROPHONE_Handle *microphone)
Destroy a microphone.
Definition: microphone.c:192
void GNUNET_CONVERSATION_call_stop(struct GNUNET_CONVERSATION_Call *call)
Terminate a call.
#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:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_command_string()

static void handle_command_string ( char *  message,
size_t  str_len 
)
static

Handle user command.

Parameters
messagecommand the user typed in
str_lennumber of bytes to process in message

Definition at line 1048 of file gnunet-conversation.c.

References VoipCommand::Action, and VoipCommand::command.

Referenced by handle_command().

1049 {
1050  size_t i;
1051  const char *ptr;
1052 
1053  if (0 == str_len)
1054  return;
1055  if (message[str_len - 1] == '\n')
1056  message[str_len - 1] = '\0';
1057  if (message[str_len - 2] == '\r')
1058  message[str_len - 2] = '\0';
1059  if (0 == strlen(message))
1060  return;
1061  i = 0;
1062  while (
1063  (NULL != commands[i].command) &&
1064  (0 !=
1065  strncasecmp(commands[i].command, message, strlen(commands[i].command))))
1066  i++;
1067  ptr = &message[strlen(commands[i].command)];
1068  while (isspace((unsigned char)*ptr))
1069  ptr++;
1070  if ('\0' == *ptr)
1071  ptr = NULL;
1072  commands[i].Action(ptr);
1073 }
static struct VoipCommand commands[]
List of supported commands.
ActionFunction Action
Function to call on command.
Here is the caller graph for this function:

◆ handle_command()

static void handle_command ( void *  cls)
static

Task to handle commands from the terminal.

Parameters
clsNULL

Definition at line 1082 of file gnunet-conversation.c.

References GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_UNIT_FOREVER_REL, handle_command_string(), and MAX_MESSAGE_LENGTH.

Referenced by run().

1083 {
1084  char message[MAX_MESSAGE_LENGTH + 1];
1085 
1086  (void)cls;
1087  handle_cmd_task =
1089  stdin_fh,
1090  &handle_command,
1091  NULL);
1092  /* read message from command line and handle it */
1093  memset(message, 0, MAX_MESSAGE_LENGTH + 1);
1094  if (NULL == fgets(message, MAX_MESSAGE_LENGTH, stdin))
1095  return;
1096  handle_command_string(message, strlen(message));
1097 }
static void handle_command(void *cls)
Task to handle commands from the terminal.
static struct GNUNET_SCHEDULER_Task * handle_cmd_task
Task which handles the commands.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1615
static void handle_command_string(char *message, size_t str_len)
Handle user command.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static struct GNUNET_DISK_FileHandle * stdin_fh
File handle for stdin.
#define MAX_MESSAGE_LENGTH
Maximum length allowed for the command line input.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ identity_cb()

static void identity_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  name 
)
static

Function called by identity service with information about egos.

Parameters
clsNULL
egoego handle
ctxunused
namename of the ego

Definition at line 1109 of file gnunet-conversation.c.

References _, ego_name, GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_strdup, line, start_phone(), and verbose.

Referenced by run().

1113 {
1114  (void)cls;
1115  (void)ctx;
1116  if (NULL == name)
1117  return;
1118  if (ego == my_caller_id)
1119  {
1120  if (verbose)
1121  fprintf(stdout, _("Name of our ego changed to `%s'\n"), name);
1124  return;
1125  }
1126  if (0 != strcmp(name, ego_name))
1127  return;
1128  if (NULL == ego)
1129  {
1130  if (verbose)
1131  fprintf(stdout, _("Our ego `%s' was deleted!\n"), ego_name);
1132  my_caller_id = NULL;
1133  return;
1134  }
1135  my_caller_id = ego;
1136  GNUNET_CONFIGURATION_set_value_string(cfg, "CONVERSATION", "LINE", line);
1137  start_phone();
1138 }
static char * ego_name
Name of our ego.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_IDENTITY_Ego * my_caller_id
Our ego.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
static void start_phone()
Start our phone.
const char * name
static int verbose
Be verbose.
#define GNUNET_free(ptr)
Wrapper around free.
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 c 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 1150 of file gnunet-conversation.c.

References _, do_stop_task(), ego_name, GNUNET_CONFIGURATION_dup(), GNUNET_IDENTITY_connect(), GNUNET_MICROPHONE_create_from_hardware(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_UI, GNUNET_SPEAKER_create_from_hardware(), handle_command(), and identity_cb().

Referenced by main().

1154 {
1155  (void)cls;
1156  (void)args;
1157  (void)cfgfile;
1161  if (NULL == ego_name)
1162  {
1163  fprintf(stderr, "%s", _("You must specify the NAME of an ego to use\n"));
1164  return;
1165  }
1166  id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL);
1167  handle_cmd_task =
1169  &handle_command,
1170  NULL);
1172 }
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:525
static void handle_command(void *cls)
Task to handle commands from the terminal.
static struct GNUNET_SCHEDULER_Task * handle_cmd_task
Task which handles the commands.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
struct GNUNET_SPEAKER_Handle * GNUNET_SPEAKER_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a speaker that corresponds to the speaker hardware of our system.
Definition: speaker.c:158
static char * ego_name
Name of our ego.
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:1191
Run with priority for interactive tasks.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_SPEAKER_Handle * speaker
Our speaker.
static void identity_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Function called by identity service with information about egos.
static void do_stop_task(void *cls)
Task run during shutdown.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
struct GNUNET_MICROPHONE_Handle * GNUNET_MICROPHONE_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a microphone that corresponds to the microphone hardware of our system.
Definition: microphone.c:170
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function to conversation.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 1183 of file gnunet-conversation.c.

References ego_name, gettext_noop, GNUNET_CONFIGURATION_destroy(), GNUNET_DISK_get_handle_from_int_fd(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_log_strerror, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), line, ret, and run().

1184 {
1187  'e',
1188  "ego",
1189  "NAME",
1190  gettext_noop("sets the NAME of the ego to use for the caller ID"),
1191  &ego_name),
1193  "phone",
1194  "LINE",
1195  gettext_noop(
1196  "sets the LINE to use for the phone"),
1197  &line),
1199  int ret;
1200 
1201  int flags;
1202  flags = fcntl(0, F_GETFL, 0);
1203  flags |= O_NONBLOCK;
1204  if (0 != fcntl(0, F_SETFL, flags))
1207 
1208  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1209  return 2;
1210  ret =
1211  GNUNET_PROGRAM_run(argc,
1212  argv,
1213  "gnunet-conversation",
1214  gettext_noop(
1215  "Enables having a conversation with other GNUnet users."),
1216  options,
1217  &run,
1218  NULL);
1219  GNUNET_free((void *)argv);
1220  if (NULL != cfg)
1221  {
1223  cfg = NULL;
1224  }
1225  return (GNUNET_OK == ret) ? 0 : 1;
1226 }
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run by the scheduler.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
static char * ego_name
Name of our ego.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static struct GNUNET_DISK_FileHandle * stdin_fh
File handle for stdin.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
Definition: disk.c:1369
int GNUNET_PROGRAM_run(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, parse options).
Definition: program.c:367
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ phone

struct GNUNET_CONVERSATION_Phone* phone
static

Phone handle.

Definition at line 128 of file gnunet-conversation.c.

◆ call

struct GNUNET_CONVERSATION_Call* call
static

◆ cl_active

struct CallList* cl_active
static

Caller handle (for active incoming call).

This call handler is NOT in the cl_head / cl_tail list.

Definition at line 139 of file gnunet-conversation.c.

Referenced by phone_event_handler().

◆ cl_head

struct CallList* cl_head
static

Head of calls waiting to be accepted.

Definition at line 144 of file gnunet-conversation.c.

Referenced by do_accept(), do_reject(), and do_resume().

◆ cl_tail

struct CallList* cl_tail
static

Tail of calls waiting to be accepted.

Definition at line 149 of file gnunet-conversation.c.

◆ line

char* line
static

◆ handle_cmd_task

struct GNUNET_SCHEDULER_Task* handle_cmd_task
static

Task which handles the commands.

Definition at line 159 of file gnunet-conversation.c.

◆ speaker

struct GNUNET_SPEAKER_Handle* speaker
static

Our speaker.

Definition at line 164 of file gnunet-conversation.c.

◆ mic

struct GNUNET_MICROPHONE_Handle* mic
static

◆ cfg

struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 174 of file gnunet-conversation.c.

◆ my_caller_id

struct GNUNET_IDENTITY_Ego* my_caller_id
static

Our ego.

Definition at line 179 of file gnunet-conversation.c.

◆ id

struct GNUNET_IDENTITY_Handle* id
static

◆ ego_name

char* ego_name
static

Name of our ego.

Definition at line 189 of file gnunet-conversation.c.

Referenced by do_call(), do_status(), do_stop_task(), identity_cb(), main(), run(), and start_phone().

◆ peer_key

struct GNUNET_CRYPTO_EcdsaPublicKey peer_key
static

Public key of active conversation partner (if any).

Definition at line 194 of file gnunet-conversation.c.

Referenced by do_accept(), do_call(), do_resume(), and do_status().

◆ peer_name

char* peer_name
static

Name of active conversation partner (if any).

Definition at line 199 of file gnunet-conversation.c.

Referenced by call_event_handler(), do_call(), do_status(), and do_stop_task().

◆ stdin_fh

struct GNUNET_DISK_FileHandle* stdin_fh
static

File handle for stdin.

Definition at line 204 of file gnunet-conversation.c.

◆ phone_state

enum PhoneState phone_state
static

Our phone's current state.

Definition at line 209 of file gnunet-conversation.c.

Referenced by do_accept(), do_call(), do_reject(), do_resume(), do_status(), do_stop_task(), do_suspend(), phone_event_handler(), and start_phone().

◆ call_state

enum CallState call_state
static

Our call's current state.

Definition at line 214 of file gnunet-conversation.c.

Referenced by call_event_handler(), do_accept(), do_call(), do_resume(), do_status(), and do_suspend().

◆ caller_num_gen

unsigned int caller_num_gen
static

Counts the number of incoming calls we have had so far.

Definition at line 219 of file gnunet-conversation.c.

Referenced by phone_event_handler().

◆ address

char* address
static

GNS address for this phone.

Definition at line 224 of file gnunet-conversation.c.

Referenced by ack_proc(), add_address_to_hello(), address_notification(), broadcast_mst_cb(), check_address_add(), check_client_address_to_string(), check_reply(), client_lookup_session(), client_run(), copy_latest(), create_channel_to_destination(), delta_match(), do_address(), dump_pc(), find_matching(), find_validation_entry(), free_all_it(), GAS_handle_address_add(), GAS_proportional_address_add(), GAS_ril_address_add(), GST_receive_callback(), handle_client_address_to_string(), handle_dummy(), handle_reply(), handle_response(), handle_session_add(), handle_tcp_welcome(), http_common_address_from_socket(), http_common_plugin_address_pretty_printer(), http_common_plugin_address_to_string(), http_common_plugin_address_to_url(), http_common_plugin_string_to_address(), LIBGNUNET_PLUGIN_TRANSPORT_DONE(), libgnunet_plugin_transport_unix_done(), lookup_session(), main(), mlp_create_problem_add_address_information(), mlp_propagate_results(), normalize_address(), notify_change(), process_data(), process_udp_message(), read_process_ack(), send_syn_ack_message(), server_add_address(), server_remove_address(), setup_sender(), start_address_validation(), start_phone(), tcp_nat_port_map_callback(), tcp_plugin_get_session(), tcp_plugin_string_to_address(), udp_nat_port_map_callback(), udp_plugin_lookup_session(), udp_string_to_address(), unix_demultiplexer(), unix_plugin_string_to_address(), and vpn_allocation_cb().

◆ verbose

int verbose
static

Be verbose.

Definition at line 229 of file gnunet-conversation.c.

Referenced by identity_cb().

◆ commands

struct VoipCommand commands[]
static

List of supported commands.

Definition at line 934 of file gnunet-conversation.c.