GNUnet  0.10.x
Data Structures | Enumerations | Functions
conversation_api.c File Reference

phone and caller API to the conversation service More...

#include "platform.h"
#include "gnunet_conversation_service.h"
#include "conversation.h"
Include dependency graph for conversation_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CONVERSATION_Caller
 A caller is the handle we have for an incoming call. More...
 
struct  GNUNET_CONVERSATION_Phone
 A phone is a device that can ring to signal an incoming call and that you can pick up to answer the call and hang up to terminate the call. More...
 

Enumerations

enum  CallerState {
  CS_RINGING, CS_ACTIVE, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED,
  CS_BOTH_SUSPENDED
}
 Possible states of a caller. More...
 
enum  PhoneState {
  PS_REGISTER = 0, PS_READY, PS_LOOKUP_EGO, PS_LISTEN,
  PS_ACCEPTED, PS_ERROR
}
 Possible states of a phone. More...
 

Functions

static void reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
 The phone got disconnected, reconnect to the service. More...
 
static void transmit_phone_audio (void *cls, size_t data_size, const void *data)
 Process recorded audio data. More...
 
static void handle_phone_ring (void *cls, const struct ClientPhoneRingMessage *ring)
 We received a struct ClientPhoneRingMessage More...
 
static struct GNUNET_CONVERSATION_Callerfind_caller (struct GNUNET_CONVERSATION_Phone *phone, uint32_t cid)
 Find the record of the caller matching the cid. More...
 
static void handle_phone_hangup (void *cls, const struct ClientPhoneHangupMessage *hang)
 We received a struct ClientPhoneHangupMessage. More...
 
static void handle_phone_suspend (void *cls, const struct ClientPhoneSuspendMessage *suspend)
 We received a struct ClientPhoneSuspendMessage. More...
 
static void handle_phone_resume (void *cls, const struct ClientPhoneResumeMessage *resume)
 We received a struct ClientPhoneResumeMessage. More...
 
static int check_phone_audio (void *cls, const struct ClientAudioMessage *am)
 We received a struct ClientAudioMessage, check it is well-formed. More...
 
static void handle_phone_audio (void *cls, const struct ClientAudioMessage *am)
 We received a struct ClientAudioMessage More...
 
static void phone_error_handler (void *cls, enum GNUNET_MQ_Error error)
 We encountered an error talking with the conversation service. More...
 
static void clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone)
 Clean up all callers of the given phone. More...
 
struct GNUNET_CONVERSATION_PhoneGNUNET_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. More...
 
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. More...
 
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. More...
 
void GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller)
 Hang up up a (possibly ringing) phone. More...
 
void GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone)
 Destroys a phone. More...
 
void GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller)
 Pause conversation of an active call. More...
 
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. More...
 

Detailed Description

phone and caller API to the conversation service

Author
Simon Dieterle
Andreas Fuchs
Christian Grothoff

Definition in file conversation_api.c.

Enumeration Type Documentation

◆ CallerState

Possible states of a caller.

Enumerator
CS_RINGING 

The phone is ringing (user knows about incoming call).

CS_ACTIVE 

The phone is in an active conversation.

CS_CALLEE_SUSPENDED 

We suspended the conversation.

CS_CALLER_SUSPENDED 

Caller suspended the conversation.

CS_BOTH_SUSPENDED 

Both sides suspended the conversation.

Definition at line 36 of file conversation_api.c.

36  {
40  CS_RINGING,
41 
45  CS_ACTIVE,
46 
51 
56 
61 };
The phone is in an active conversation.
The phone is ringing (user knows about incoming call).
We suspended the conversation.
Caller suspended the conversation.
Both sides suspended the conversation.

◆ PhoneState

enum PhoneState

Possible states of a 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 124 of file conversation_api.c.

124  {
128  PS_REGISTER = 0,
129 
133  PS_READY
134 };
We still need to register the phone.
We are waiting for calls.

Function Documentation

◆ reconnect_phone()

static void reconnect_phone ( struct GNUNET_CONVERSATION_Phone phone)
static

The phone got disconnected, reconnect to the service.

Parameters
phonephone to reconnect

Definition at line 557 of file conversation_api.c.

References GNUNET_CONVERSATION_Phone::cfg, clean_up_callers(), e, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, GNUNET_MQ_destroy(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), ClientPhoneRegisterMessage::line_port, GNUNET_CONVERSATION_PhoneRecord::line_port, GNUNET_CONVERSATION_Phone::mq, GNUNET_CONVERSATION_Phone::my_record, phone_error_handler(), PS_READY, PS_REGISTER, and GNUNET_CONVERSATION_Phone::state.

Referenced by GNUNET_CONVERSATION_phone_create(), and phone_error_handler().

558 {
560  GNUNET_MQ_hd_fixed_size(phone_ring,
562  struct ClientPhoneRingMessage,
563  phone),
564  GNUNET_MQ_hd_fixed_size(phone_hangup,
567  phone),
568  GNUNET_MQ_hd_fixed_size(phone_suspend,
571  phone),
572  GNUNET_MQ_hd_fixed_size(phone_resume,
575  phone),
576  GNUNET_MQ_hd_var_size(phone_audio,
578  struct ClientAudioMessage,
579  phone),
581  };
582  struct GNUNET_MQ_Envelope *e;
583  struct ClientPhoneRegisterMessage *reg;
584 
585  clean_up_callers(phone);
586  if (NULL != phone->mq)
587  {
588  GNUNET_MQ_destroy(phone->mq);
589  phone->mq = NULL;
590  }
591  phone->state = PS_REGISTER;
592  phone->mq = GNUNET_CLIENT_connect(phone->cfg,
593  "conversation",
594  handlers,
596  phone);
597  if (NULL == phone->mq)
598  return;
599  e = GNUNET_MQ_msg(reg,
601  reg->line_port = phone->my_record.line_port;
602  GNUNET_MQ_send(phone->mq,
603  e);
604  phone->state = PS_READY;
605 }
We still need to register the phone.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
enum PhoneState state
State machine for the phone.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:900
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
static struct Experiment * e
Client -> Service message to register a phone.
Definition: conversation.h:68
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO
Client <-> Server message to send audio data.
static void clean_up_callers(struct GNUNET_CONVERSATION_Phone *phone)
Clean up all callers of the given phone.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING
Client <- Server message to indicate a ringing phone.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
Client <-> Service hang up phone that may or may not be ringing.
Definition: conversation.h:163
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_CONVERSATION_PhoneRecord my_record
This phone&#39;s record.
Message handler for a specific message type.
We are waiting for calls.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME
Client <-> Server message to resume connection.
struct GNUNET_HashCode line_port
Phone line / CADET port to register.
Definition: conversation.h:82
Service <-> Client message for phone was resumed.
Definition: conversation.h:128
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER
Client -> Server message to register a phone.
struct GNUNET_MQ_Handle * mq
Handle for transmitting to the CONVERSATION service.
Service -> Client message for phone is ringing.
Definition: conversation.h:89
Message Client <-> Service to transmit the audio.
Definition: conversation.h:180
struct GNUNET_HashCode line_port
Phone line (CADET port) to connect to.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:351
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND
Client <-> Server message to suspend connection.
Service <-> Client message for phone was suspended.
Definition: conversation.h:111
static void phone_error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error talking with the conversation service.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP
Client -> Server message to reject/hangup a call.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_phone_audio()

static void transmit_phone_audio ( void *  cls,
size_t  data_size,
const void *  data 
)
static

Process recorded audio data.

Parameters
clsclosure with the struct GNUNET_CONVERSATION_Caller
data_sizenumber of bytes in data
dataaudio data to play

Definition at line 218 of file conversation_api.c.

References GNUNET_CONVERSATION_Caller::cid, ClientAudioMessage::cid, e, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_CONVERSATION_Phone::mq, and GNUNET_CONVERSATION_Caller::phone.

Referenced by GNUNET_CONVERSATION_caller_pick_up(), GNUNET_CONVERSATION_caller_resume(), and handle_phone_resume().

221 {
222  struct GNUNET_CONVERSATION_Caller *caller = cls;
223  struct GNUNET_CONVERSATION_Phone *phone = caller->phone;
224  struct GNUNET_MQ_Envelope *e;
225  struct ClientAudioMessage *am;
226 
227  e = GNUNET_MQ_msg_extra(am,
228  data_size,
230  am->cid = caller->cid;
231  GNUNET_memcpy(&am[1],
232  data,
233  data_size);
234  GNUNET_MQ_send(phone->mq,
235  e);
236 }
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static struct Experiment * e
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO
Client <-> Server message to send audio data.
A phone is a device that can ring to signal an incoming call and that you can pick up to answer the c...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
uint32_t cid
Internal handle to identify the caller with the service.
A caller is the handle we have for an incoming call.
struct GNUNET_CONVERSATION_Phone * phone
Our phone.
struct GNUNET_MQ_Handle * mq
Handle for transmitting to the CONVERSATION service.
Message Client <-> Service to transmit the audio.
Definition: conversation.h:180
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:351
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
uint32_t cid
CID, internal caller ID to identify which active call we are sending data to.
Definition: conversation.h:190
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_phone_ring()

static void handle_phone_ring ( void *  cls,
const struct ClientPhoneRingMessage ring 
)
static

We received a struct ClientPhoneRingMessage

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
ringthe message

Definition at line 246 of file conversation_api.c.

References GNUNET_CONVERSATION_Phone::caller_head, ClientPhoneRingMessage::caller_id, GNUNET_CONVERSATION_Caller::caller_id, GNUNET_CONVERSATION_Phone::caller_tail, ClientPhoneRingMessage::cid, GNUNET_CONVERSATION_Caller::cid, CS_RINGING, GNUNET_CONVERSATION_Phone::event_handler, GNUNET_CONVERSATION_Phone::event_handler_cls, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONVERSATION_EC_PHONE_RING, GNUNET_new, GNUNET_CONVERSATION_Caller::phone, PS_READY, PS_REGISTER, GNUNET_CONVERSATION_Caller::state, and GNUNET_CONVERSATION_Phone::state.

248 {
249  struct GNUNET_CONVERSATION_Phone *phone = cls;
250  struct GNUNET_CONVERSATION_Caller *caller;
251 
252  switch (phone->state)
253  {
254  case PS_REGISTER:
255  GNUNET_assert(0);
256  break;
257 
258  case PS_READY:
259  caller = GNUNET_new(struct GNUNET_CONVERSATION_Caller);
260  caller->phone = phone;
262  phone->caller_tail,
263  caller);
264  caller->caller_id = ring->caller_id;
265  caller->cid = ring->cid;
266  caller->state = CS_RINGING;
267  phone->event_handler(phone->event_handler_cls,
269  caller,
270  &caller->caller_id);
271  break;
272  }
273 }
We still need to register the phone.
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
enum PhoneState state
State machine for the phone.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Who is calling us?
Definition: conversation.h:104
GNUNET_CONVERSATION_PhoneEventHandler event_handler
Function to call for phone events.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A phone is a device that can ring to signal an incoming call and that you can pick up to answer the c...
enum CallerState state
State machine for the phone.
void * event_handler_cls
Closure for event_handler.
struct GNUNET_CONVERSATION_Caller * caller_tail
We keep all callers in a DLL.
The phone is ringing (user knows about incoming call).
uint32_t cid
Internal handle to identify the caller with the service.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Identity of the person calling us.
A caller is the handle we have for an incoming call.
We are waiting for calls.
uint32_t cid
CID, internal caller ID number used in the future to identify which active call we are talking about...
Definition: conversation.h:99
struct GNUNET_CONVERSATION_Phone * phone
Our phone.
We are the callee and the phone is ringing.
struct GNUNET_CONVERSATION_Caller * caller_head
We keep all callers in a DLL.

◆ find_caller()

static struct GNUNET_CONVERSATION_Caller* find_caller ( struct GNUNET_CONVERSATION_Phone phone,
uint32_t  cid 
)
static

Find the record of the caller matching the cid.

Parameters
phonephone to search
cidcaller ID to search for (in NBO)
Returns
NULL if cid was not found

Definition at line 284 of file conversation_api.c.

References GNUNET_CONVERSATION_Phone::caller_head, GNUNET_CONVERSATION_Caller::cid, and GNUNET_CONVERSATION_Caller::next.

Referenced by handle_phone_audio(), handle_phone_hangup(), handle_phone_resume(), and handle_phone_suspend().

286 {
287  struct GNUNET_CONVERSATION_Caller *caller;
288 
289  for (caller = phone->caller_head; NULL != caller; caller = caller->next)
290  if (cid == caller->cid)
291  return caller;
292  return NULL;
293 }
struct GNUNET_CONVERSATION_Caller * next
We keep all callers in a DLL.
uint32_t cid
Internal handle to identify the caller with the service.
A caller is the handle we have for an incoming call.
struct GNUNET_CONVERSATION_Caller * caller_head
We keep all callers in a DLL.
Here is the caller graph for this function:

◆ handle_phone_hangup()

static void handle_phone_hangup ( void *  cls,
const struct ClientPhoneHangupMessage hang 
)
static

We received a struct ClientPhoneHangupMessage.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone *
msgthe message

Definition at line 303 of file conversation_api.c.

References GNUNET_CONVERSATION_Phone::caller_head, GNUNET_CONVERSATION_Caller::caller_id, GNUNET_CONVERSATION_Phone::caller_tail, ClientPhoneHangupMessage::cid, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_BOTH_SUSPENDED, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED, CS_RINGING, GNUNET_MICROPHONE_Handle::disable_microphone, GNUNET_SPEAKER_Handle::disable_speaker, GNUNET_CONVERSATION_Phone::event_handler, GNUNET_CONVERSATION_Phone::event_handler_cls, find_caller(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_log, GNUNET_CONVERSATION_Caller::mic, GNUNET_CONVERSATION_Caller::phone, GNUNET_CONVERSATION_Caller::speaker, and GNUNET_CONVERSATION_Caller::state.

305 {
306  struct GNUNET_CONVERSATION_Phone *phone = cls;
307  struct GNUNET_CONVERSATION_Caller *caller;
308 
309  caller = find_caller(phone,
310  hang->cid);
311  if (NULL == caller)
312  {
314  "Received HANG_UP message for unknown caller ID %u\n",
315  (unsigned int)hang->cid);
316  return;
317  }
318 
320  "Received HANG_UP message, terminating call with `%s'\n",
322  switch (caller->state)
323  {
324  case CS_RINGING:
325  phone->event_handler(phone->event_handler_cls,
327  caller,
328  &caller->caller_id);
329  break;
330 
331  case CS_ACTIVE:
332  caller->speaker->disable_speaker(caller->speaker->cls);
333  caller->mic->disable_microphone(caller->mic->cls);
334  phone->event_handler(phone->event_handler_cls,
336  caller,
337  &caller->caller_id);
338  break;
339 
340  case CS_CALLEE_SUSPENDED:
341  case CS_CALLER_SUSPENDED:
342  case CS_BOTH_SUSPENDED:
343  phone->event_handler(phone->event_handler_cls,
345  caller,
346  &caller->caller_id);
347  break;
348  }
350  phone->caller_tail,
351  caller);
352  GNUNET_free(caller);
353 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
The phone is in an active conversation.
GNUNET_MICROPHONE_DisableCallback disable_microphone
Turn the microphone off.
GNUNET_CONVERSATION_PhoneEventHandler event_handler
Function to call for phone events.
uint32_t cid
CID, internal caller ID to identify which active call we are talking about.
Definition: conversation.h:173
struct GNUNET_SPEAKER_Handle * speaker
Speaker, or NULL if none is attached.
GNUNET_SPEAKER_DisableCallback disable_speaker
Turn the speaker off.
A phone is a device that can ring to signal an incoming call and that you can pick up to answer the c...
enum CallerState state
State machine for the phone.
void * event_handler_cls
Closure for event_handler.
struct GNUNET_CONVERSATION_Caller * caller_tail
We keep all callers in a DLL.
The phone is ringing (user knows about incoming call).
struct GNUNET_MICROPHONE_Handle * mic
Microphone, or NULL if none is attached.
void * cls
Closure for the callbacks.
We suspended the conversation.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Identity of the person calling us.
Caller suspended the conversation.
A caller is the handle we have for an incoming call.
The conversation was terminated by the caller.
static struct GNUNET_CONVERSATION_Caller * find_caller(struct GNUNET_CONVERSATION_Phone *phone, uint32_t cid)
Find the record of the caller matching the cid.
void * cls
Closure for the callbacks.
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.
Both sides suspended the conversation.
#define GNUNET_log(kind,...)
struct GNUNET_CONVERSATION_Caller * caller_head
We keep all callers in a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ handle_phone_suspend()

static void handle_phone_suspend ( void *  cls,
const struct ClientPhoneSuspendMessage suspend 
)
static

We received a struct ClientPhoneSuspendMessage.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
suspendthe message

Definition at line 363 of file conversation_api.c.

References ClientPhoneSuspendMessage::cid, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_BOTH_SUSPENDED, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED, CS_RINGING, GNUNET_MICROPHONE_Handle::disable_microphone, GNUNET_SPEAKER_Handle::disable_speaker, GNUNET_CONVERSATION_Caller::event_handler, GNUNET_CONVERSATION_Caller::event_handler_cls, find_caller(), GNUNET_break_op, GNUNET_CONVERSATION_EC_CALLER_SUSPEND, GNUNET_CONVERSATION_Caller::mic, GNUNET_CONVERSATION_Caller::phone, GNUNET_CONVERSATION_Caller::speaker, and GNUNET_CONVERSATION_Caller::state.

365 {
366  struct GNUNET_CONVERSATION_Phone *phone = cls;
367  struct GNUNET_CONVERSATION_Caller *caller;
368 
369  caller = find_caller(phone,
370  suspend->cid);
371  if (NULL == caller)
372  return;
373  switch (caller->state)
374  {
375  case CS_RINGING:
376  GNUNET_break_op(0);
377  break;
378 
379  case CS_ACTIVE:
380  caller->state = CS_CALLER_SUSPENDED;
381  caller->speaker->disable_speaker(caller->speaker->cls);
382  caller->mic->disable_microphone(caller->mic->cls);
383  caller->event_handler(caller->event_handler_cls,
385  break;
386 
387  case CS_CALLEE_SUSPENDED:
388  caller->state = CS_BOTH_SUSPENDED;
389  caller->event_handler(caller->event_handler_cls,
391  break;
392 
393  case CS_CALLER_SUSPENDED:
394  case CS_BOTH_SUSPENDED:
395  GNUNET_break_op(0);
396  break;
397  }
398 }
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
The phone is in an active conversation.
GNUNET_MICROPHONE_DisableCallback disable_microphone
Turn the microphone off.
struct GNUNET_SPEAKER_Handle * speaker
Speaker, or NULL if none is attached.
GNUNET_SPEAKER_DisableCallback disable_speaker
Turn the speaker off.
A phone is a device that can ring to signal an incoming call and that you can pick up to answer the c...
enum CallerState state
State machine for the phone.
The phone is ringing (user knows about incoming call).
struct GNUNET_MICROPHONE_Handle * mic
Microphone, or NULL if none is attached.
GNUNET_CONVERSATION_CallerEventHandler event_handler
Function to call for phone events.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * cls
Closure for the callbacks.
We suspended the conversation.
Caller suspended the conversation.
A caller is the handle we have for an incoming call.
static struct GNUNET_CONVERSATION_Caller * find_caller(struct GNUNET_CONVERSATION_Phone *phone, uint32_t cid)
Find the record of the caller matching the cid.
void * cls
Closure for the callbacks.
Both sides suspended the conversation.
We are the callee and the caller suspended the call.
void * event_handler_cls
Closure for event_handler.
uint32_t cid
CID, internal caller ID to identify which active call we are talking about.
Definition: conversation.h:121
Here is the call graph for this function:

◆ handle_phone_resume()

static void handle_phone_resume ( void *  cls,
const struct ClientPhoneResumeMessage resume 
)
static

We received a struct ClientPhoneResumeMessage.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
resumethe message

Definition at line 408 of file conversation_api.c.

References ClientPhoneResumeMessage::cid, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_BOTH_SUSPENDED, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED, CS_RINGING, GNUNET_MICROPHONE_Handle::enable_microphone, GNUNET_SPEAKER_Handle::enable_speaker, GNUNET_CONVERSATION_Caller::event_handler, GNUNET_CONVERSATION_Caller::event_handler_cls, find_caller(), GNUNET_break_op, GNUNET_CONVERSATION_EC_CALLER_RESUME, GNUNET_CONVERSATION_Caller::mic, GNUNET_CONVERSATION_Caller::phone, GNUNET_CONVERSATION_Caller::speaker, GNUNET_CONVERSATION_Caller::state, and transmit_phone_audio().

410 {
411  struct GNUNET_CONVERSATION_Phone *phone = cls;
412  struct GNUNET_CONVERSATION_Caller *caller;
413 
414  caller = find_caller(phone,
415  resume->cid);
416  if (NULL == caller)
417  return;
418  switch (caller->state)
419  {
420  case CS_RINGING:
421  GNUNET_break_op(0);
422  break;
423 
424  case CS_ACTIVE:
425  case CS_CALLEE_SUSPENDED:
426  GNUNET_break_op(0);
427  break;
428 
429  case CS_CALLER_SUSPENDED:
430  caller->state = CS_ACTIVE;
431  caller->speaker->enable_speaker(caller->speaker->cls);
432  caller->mic->enable_microphone(caller->mic->cls,
434  caller);
435  caller->event_handler(caller->event_handler_cls,
437  break;
438 
439  case CS_BOTH_SUSPENDED:
440  caller->state = CS_CALLEE_SUSPENDED;
441  caller->event_handler(caller->event_handler_cls,
443  break;
444  }
445 }
uint32_t cid
CID, internal caller ID to identify which active call we are talking about.
Definition: conversation.h:138
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
The phone is in an active conversation.
struct GNUNET_SPEAKER_Handle * speaker
Speaker, or NULL if none is attached.
We are the callee and the caller resumed the call.
GNUNET_MICROPHONE_EnableCallback enable_microphone
Turn on the microphone.
A phone is a device that can ring to signal an incoming call and that you can pick up to answer the c...
enum CallerState state
State machine for the phone.
The phone is ringing (user knows about incoming call).
struct GNUNET_MICROPHONE_Handle * mic
Microphone, or NULL if none is attached.
GNUNET_CONVERSATION_CallerEventHandler event_handler
Function to call for phone events.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * cls
Closure for the callbacks.
We suspended the conversation.
Caller suspended the conversation.
A caller is the handle we have for an incoming call.
GNUNET_SPEAKER_EnableCallback enable_speaker
Turn on the speaker.
static void transmit_phone_audio(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static struct GNUNET_CONVERSATION_Caller * find_caller(struct GNUNET_CONVERSATION_Phone *phone, uint32_t cid)
Find the record of the caller matching the cid.
void * cls
Closure for the callbacks.
Both sides suspended the conversation.
void * event_handler_cls
Closure for event_handler.
Here is the call graph for this function:

◆ check_phone_audio()

static int check_phone_audio ( void *  cls,
const struct ClientAudioMessage am 
)
static

We received a struct ClientAudioMessage, check it is well-formed.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
amthe message
Returns
GNUNET_OK if am is well-formed

Definition at line 456 of file conversation_api.c.

References GNUNET_OK.

458 {
459  (void)cls;
460  (void)am;
461 
462  /* any variable-size payload is OK */
463  return GNUNET_OK;
464 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_phone_audio()

static void handle_phone_audio ( void *  cls,
const struct ClientAudioMessage am 
)
static

We received a struct ClientAudioMessage

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
amthe message

Definition at line 474 of file conversation_api.c.

References ClientAudioMessage::cid, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_BOTH_SUSPENDED, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED, CS_RINGING, find_caller(), GNUNET_break_op, ClientAudioMessage::header, GNUNET_CONVERSATION_Caller::phone, GNUNET_SPEAKER_Handle::play, GNUNET_MessageHeader::size, GNUNET_CONVERSATION_Caller::speaker, and GNUNET_CONVERSATION_Caller::state.

476 {
477  struct GNUNET_CONVERSATION_Phone *phone = cls;
478  struct GNUNET_CONVERSATION_Caller *caller;
479 
480  caller = find_caller(phone,
481  am->cid);
482  if (NULL == caller)
483  return;
484  switch (caller->state)
485  {
486  case CS_RINGING:
487  GNUNET_break_op(0);
488  break;
489 
490  case CS_ACTIVE:
491  caller->speaker->play(caller->speaker->cls,
492  ntohs(am->header.size) - sizeof(struct ClientAudioMessage),
493  &am[1]);
494  break;
495 
496  case CS_CALLEE_SUSPENDED:
497  case CS_CALLER_SUSPENDED:
498  case CS_BOTH_SUSPENDED:
499  break;
500  }
501 }
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
The phone is in an active conversation.
struct GNUNET_SPEAKER_Handle * speaker
Speaker, or NULL if none is attached.
GNUNET_SPEAKER_PlayCallback play
Play audio.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
A phone is a device that can ring to signal an incoming call and that you can pick up to answer the c...
enum CallerState state
State machine for the phone.
The phone is ringing (user knows about incoming call).
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
We suspended the conversation.
Caller suspended the conversation.
A caller is the handle we have for an incoming call.
static struct GNUNET_CONVERSATION_Caller * find_caller(struct GNUNET_CONVERSATION_Phone *phone, uint32_t cid)
Find the record of the caller matching the cid.
void * cls
Closure for the callbacks.
Both sides suspended the conversation.
Message Client <-> Service to transmit the audio.
Definition: conversation.h:180
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO.
Definition: conversation.h:184
uint32_t cid
CID, internal caller ID to identify which active call we are sending data to.
Definition: conversation.h:190
Here is the call graph for this function:

◆ phone_error_handler()

static void phone_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We encountered an error talking with the conversation service.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
errordetails about the error

Definition at line 511 of file conversation_api.c.

References _, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_CONVERSATION_Caller::phone, and reconnect_phone().

Referenced by reconnect_phone().

513 {
514  struct GNUNET_CONVERSATION_Phone *phone = cls;
515 
516  (void)error;
518  _("Connection to conversation service lost, trying to reconnect\n"));
519  reconnect_phone(phone);
520 }
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
A phone is a device that can ring to signal an incoming call and that you can pick up to answer the c...
static void reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone)
The phone got disconnected, reconnect to the service.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_up_callers()

static void clean_up_callers ( struct GNUNET_CONVERSATION_Phone phone)
static

Clean up all callers of the given phone.

Parameters
phonephone to clean up callers for

Definition at line 529 of file conversation_api.c.

References GNUNET_CONVERSATION_Phone::caller_head, GNUNET_CONVERSATION_Caller::caller_id, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_CALLER_SUSPENDED, GNUNET_MICROPHONE_Handle::disable_microphone, GNUNET_SPEAKER_Handle::disable_speaker, GNUNET_CONVERSATION_Phone::event_handler, GNUNET_CONVERSATION_Phone::event_handler_cls, GNUNET_CONVERSATION_caller_hang_up(), GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, GNUNET_CONVERSATION_Caller::mic, GNUNET_CONVERSATION_Caller::speaker, and GNUNET_CONVERSATION_Caller::state.

Referenced by GNUNET_CONVERSATION_phone_destroy(), and reconnect_phone().

530 {
531  struct GNUNET_CONVERSATION_Caller *caller;
532 
533  while (NULL != (caller = phone->caller_head))
534  {
535  /* make sure mic/speaker are disabled *before* callback */
536  if (CS_ACTIVE == caller->state)
537  {
538  caller->speaker->disable_speaker(caller->speaker->cls);
539  caller->mic->disable_microphone(caller->mic->cls);
540  caller->state = CS_CALLER_SUSPENDED;
541  }
542  phone->event_handler(phone->event_handler_cls,
544  caller,
545  &caller->caller_id);
547  }
548 }
The phone is in an active conversation.
GNUNET_MICROPHONE_DisableCallback disable_microphone
Turn the microphone off.
GNUNET_CONVERSATION_PhoneEventHandler event_handler
Function to call for phone events.
void GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller)
Hang up up a (possibly ringing) phone.
struct GNUNET_SPEAKER_Handle * speaker
Speaker, or NULL if none is attached.
GNUNET_SPEAKER_DisableCallback disable_speaker
Turn the speaker off.
enum CallerState state
State machine for the phone.
void * event_handler_cls
Closure for event_handler.
struct GNUNET_MICROPHONE_Handle * mic
Microphone, or NULL if none is attached.
void * cls
Closure for the callbacks.
struct GNUNET_CRYPTO_EcdsaPublicKey caller_id
Identity of the person calling us.
Caller suspended the conversation.
A caller is the handle we have for an incoming call.
The conversation was terminated by the caller.
void * cls
Closure for the callbacks.
struct GNUNET_CONVERSATION_Caller * caller_head
We keep all callers in a DLL.
Here is the call graph for this function:
Here is the caller graph for this function: