/*
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,
*/
#include "platform.h"
#include "gnunet_conversation_service.h"
+#include "gnunet_gnsrecord_lib.h"
#include "gnunet_gns_service.h"
#include "conversation.h"
* 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.
*/
- struct GNUNET_CRYPTO_EccPrivateKey my_zone;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey my_zone;
/**
* Identity of the person calling us (valid while in state #PS_RINGING).
*/
- struct GNUNET_CRYPTO_EccPublicSignKey caller_id;
+ struct GNUNET_CRYPTO_EcdsaPublicKey caller_id;
/**
* State machine for the phone.
*/
static void
handle_caller_name (void *cls,
- const struct GNUNET_CRYPTO_EccPrivateKey *zone,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
const char *label,
unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd)
+ const struct GNUNET_GNSRECORD_Data *rd)
{
struct GNUNET_CONVERSATION_Phone *phone = cls;
char *name;
phone->qe = NULL;
if (NULL == label)
- name = GNUNET_strdup (GNUNET_NAMESTORE_pkey_to_zkey (&phone->caller_id));
+ name = GNUNET_strdup (GNUNET_GNSRECORD_pkey_to_zkey (&phone->caller_id));
else
GNUNET_asprintf (&name, "%.gnu", label);
phone->event_handler (phone->event_handler_cls,
/**
- * 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);
*/
void
GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone,
- struct GNUNET_NAMESTORE_RecordData *rd)
+ struct GNUNET_GNSRECORD_Data *rd)
{
rd->data = &phone->my_record;
rd->expiration_time = 0;
rd->data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord);
- rd->record_type = GNUNET_NAMESTORE_TYPE_PHONE;
- rd->flags = GNUNET_NAMESTORE_RF_NONE;
+ rd->record_type = GNUNET_GNSRECORD_TYPE_PHONE;
+ rd->flags = GNUNET_GNSRECORD_RF_NONE;
}
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)
+ const struct GNUNET_GNSRECORD_Data *rd)
{
struct GNUNET_CONVERSATION_Call *call = cls;
uint32_t i;
call->gns_lookup = NULL;
for (i=0;i<rd_count;i++)
{
- if (GNUNET_NAMESTORE_TYPE_PHONE == rd[i].record_type)
+ if (GNUNET_GNSRECORD_TYPE_PHONE == rd[i].record_type)
{
if (rd[i].data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord))
{
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 }
};
- if (NULL != call->mq)
+ struct GNUNET_CRYPTO_EcdsaPublicKey my_zone;
+
+ if (CS_ACTIVE == call->state)
+ {
+ call->speaker->disable_speaker (call->speaker->cls);
+ call->mic->disable_microphone (call->mic->cls);
+ }
+ if (NULL != call->mq)
{
GNUNET_MQ_destroy (call->mq);
call->mq = NULL;
GNUNET_CLIENT_disconnect (call->client);
call->client = NULL;
}
+ call->state = CS_SHUTDOWN;
call->client = GNUNET_CLIENT_connect ("conversation", call->cfg);
if (NULL == call->client)
return;
handlers,
&call_error_handler,
call);
+ call->state = CS_LOOKUP;
+ GNUNET_IDENTITY_ego_get_public_key (call->caller_id,
+ &my_zone);
+ call->gns_lookup = GNUNET_GNS_lookup (call->gns,
+ call->callee,
+ &my_zone,
+ GNUNET_GNSRECORD_TYPE_PHONE,
+ GNUNET_NO,
+ NULL /* FIXME: add shortening support */,
+ &handle_gns_response, call);
+ GNUNET_assert (NULL != call->gns_lookup);
}
void *event_handler_cls)
{
struct GNUNET_CONVERSATION_Call *call;
- struct GNUNET_CRYPTO_EccPublicSignKey my_zone;
- GNUNET_IDENTITY_ego_get_public_key (caller_id,
- &my_zone);
call = GNUNET_new (struct GNUNET_CONVERSATION_Call);
call->cfg = cfg;
call->caller_id = caller_id;
GNUNET_CONVERSATION_call_stop (call, NULL);
return NULL;
}
- call->gns_lookup = GNUNET_GNS_lookup (call->gns, callee,
- &my_zone,
- GNUNET_NAMESTORE_TYPE_PHONE,
- GNUNET_NO,
- NULL /* FIXME: add shortening support */,
- &handle_gns_response, call);
- GNUNET_assert (NULL != call->gns_lookup);
return call;
}
+/**
+ * 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)
{
GNUNET_GNS_disconnect (call->gns);
call->gns = NULL;
}
-
+ GNUNET_free (call->callee);
GNUNET_free (call);
}