/*
This file is part of GNUnet
(C) 2013 Christian Grothoff (and other contributing authors)
-
+
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
-
+
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Our configuration.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
-
+
/**
* Handle to talk with CONVERSATION service.
*/
/**
* Connection to NAMESTORE (for reverse lookup).
- */
+ */
struct GNUNET_NAMESTORE_Handle *ns;
/**
/**
* This phone's record.
*/
- struct GNUNET_CONVERSATION_PhoneRecord my_record;
+ struct GNUNET_CONVERSATION_PhoneRecord my_record;
/**
* My GNS zone.
/**
- * We encountered an error talking with the conversation service.
+ * We encountered an error talking with the conversation service.
*
* @param cls the `struct GNUNET_CONVERSATION_Phone`
* @param error details about the error
enum GNUNET_MQ_Error error)
{
struct GNUNET_CONVERSATION_Phone *phone = cls;
-
+
GNUNET_break (0);
FPRINTF (stderr,
_("Internal error %d\n"),
static struct GNUNET_MQ_MessageHandler handlers[] =
{
{ &handle_phone_ring,
- GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING,
+ GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING,
sizeof (struct ClientPhoneRingMessage) },
{ &handle_phone_hangup,
GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
0 },
{ &handle_phone_audio_message,
GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
- 0 },
- { NULL, 0, 0 }
+ 0 },
+ { NULL, 0, 0 }
};
struct GNUNET_MQ_Envelope *e;
struct ClientPhoneRegisterMessage *reg;
+ if (PS_ACTIVE == phone->state)
+ {
+ phone->speaker->disable_speaker (phone->speaker->cls);
+ phone->mic->disable_microphone (phone->mic->cls);
+ }
if (NULL != phone->mq)
{
GNUNET_MQ_destroy (phone->mq);
unsigned long long line;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
+ GNUNET_CONFIGURATION_get_value_number (cfg,
"CONVERSATION",
"LINE",
&line))
return NULL;
phone = GNUNET_new (struct GNUNET_CONVERSATION_Phone);
if (GNUNET_OK !=
- GNUNET_CRYPTO_get_host_identity (cfg,
+ GNUNET_CRYPTO_get_peer_identity (cfg,
&phone->my_record.peer))
{
GNUNET_break (0);
struct ClientAudioMessage *am;
GNUNET_assert (PS_ACTIVE == phone->state);
- e = GNUNET_MQ_msg_extra (am,
+ e = GNUNET_MQ_msg_extra (am,
data_size,
GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
memcpy (&am[1], data, data_size);
/**
- * Picks up a (ringing) phone. This will connect the speaker
+ * Picks up a (ringing) phone. This will connect the speaker
* to the microphone of the other party, and vice versa.
*
* @param phone phone to pick up
* Our configuration.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
-
+
/**
* Handle to talk with CONVERSATION service.
*/
* Our microphone.
*/
struct GNUNET_MICROPHONE_Handle *mic;
-
+
/**
* Function to call with events.
*/
/**
* Connection to GNS (can be NULL).
- */
+ */
struct GNUNET_GNS_Handle *gns;
/**
struct ClientAudioMessage *am;
GNUNET_assert (CS_ACTIVE == call->state);
- e = GNUNET_MQ_msg_extra (am,
+ e = GNUNET_MQ_msg_extra (am,
data_size,
GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
memcpy (&am[1], data, data_size);
metadata = (const char *) &am[1];
if ( (0 == size) ||
('\0' != metadata[size - 1]) )
- metadata = NULL;
+ metadata = NULL;
switch (call->state)
{
case CS_LOOKUP:
reason = (const char *) &am[1];
if ( (0 == size) ||
('\0' != reason[size - 1]) )
- reason = NULL;
+ reason = NULL;
switch (call->state)
{
case CS_LOOKUP:
* @param rd_count number of records in @a rd
* @param rd the records in reply
*/
-static void
+static void
handle_gns_response (void *cls,
uint32_t rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
GNUNET_break_op (0);
continue;
- }
+ }
memcpy (&call->phone_record,
rd[i].data,
rd[i].data_size);
/**
- * We encountered an error talking with the conversation service.
+ * We encountered an error talking with the conversation service.
*
* @param cls the `struct GNUNET_CONVERSATION_Call`
* @param error details about the error
static struct GNUNET_MQ_MessageHandler handlers[] =
{
{ &handle_call_busy,
- GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_BUSY,
+ GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_BUSY,
sizeof (struct ClientPhoneBusyMessage) },
{ &handle_call_picked_up,
- GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP,
+ GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP,
0 },
{ &handle_call_hangup,
GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
0 },
{ &handle_call_audio_message,
GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
- 0 },
- { NULL, 0, 0 }
+ 0 },
+ { NULL, 0, 0 }
};
struct GNUNET_CRYPTO_EccPublicSignKey my_zone;
call->state = CS_LOOKUP;
GNUNET_IDENTITY_ego_get_public_key (call->caller_id,
&my_zone);
- call->gns_lookup = GNUNET_GNS_lookup (call->gns,
+ call->gns_lookup = GNUNET_GNS_lookup (call->gns,
call->callee,
&my_zone,
GNUNET_NAMESTORE_TYPE_PHONE,
}
+/**
+ * We've sent the hang up message, now finish terminating the call.
+ *
+ * @param cls the `struct GNUNET_CONVERSATION_Call` to terminate
+ */
+static void
+finish_stop (void *cls)
+{
+ struct GNUNET_CONVERSATION_Call *call = cls;
+
+ GNUNET_assert (CS_SHUTDOWN == call->state);
+ GNUNET_CONVERSATION_call_stop (call, NULL);
+}
+
+
/**
* Terminate a call. The call may be ringing or ready at this time.
*
GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call,
const char *reason)
{
+ struct GNUNET_MQ_Envelope *e;
+ struct ClientPhoneHangupMessage *hang;
+ size_t slen;
+
+ if ( (NULL != call->speaker) &&
+ (CS_ACTIVE == call->state) )
+ call->speaker->disable_speaker (call->speaker->cls);
+ if ( (NULL != call->mic) &&
+ (CS_ACTIVE == call->state) )
+ call->mic->disable_microphone (call->mic->cls);
if (NULL != reason)
{
- // FIXME: transmit reason to service... (not implemented!)
- GNUNET_break (0);
- // return;
- }
- if (NULL != call->speaker)
- {
- if (CS_ACTIVE == call->state)
- call->speaker->disable_speaker (call->speaker->cls);
- call->speaker = NULL;
- }
- if (NULL != call->mic)
- {
- if (CS_ACTIVE == call->state)
- call->mic->disable_microphone (call->mic->cls);
- call->mic =NULL;
+ slen = strlen (reason) + 1;
+ e = GNUNET_MQ_msg_extra (hang, slen, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
+ memcpy (&hang[1], reason, slen);
+ GNUNET_MQ_notify_sent (e, &finish_stop, call);
+ GNUNET_MQ_send (call->mq, e);
+ call->state = CS_SHUTDOWN;
+ return;
}
if (NULL != call->mq)
{