From 76aaa2908b6b2ef1aac1510d0724630ba76cd388 Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Wed, 23 Mar 2016 03:17:41 +0100 Subject: social -> gnunet/social --- secushare.pro | 32 ++-- src/app.cpp | 8 +- src/app.h | 2 +- src/gnunet/social/ego.cpp | 10 ++ src/gnunet/social/ego.h | 40 +++++ src/gnunet/social/guest.cpp | 141 ++++++++++++++++++ src/gnunet/social/guest.h | 67 +++++++++ src/gnunet/social/host.cpp | 162 ++++++++++++++++++++ src/gnunet/social/host.h | 82 +++++++++++ src/gnunet/social/message.cpp | 246 +++++++++++++++++++++++++++++++ src/gnunet/social/message.h | 215 +++++++++++++++++++++++++++ src/gnunet/social/modifier.cpp | 21 +++ src/gnunet/social/modifier.h | 121 +++++++++++++++ src/gnunet/social/nym.cpp | 12 ++ src/gnunet/social/nym.h | 113 ++++++++++++++ src/gnunet/social/place.cpp | 319 ++++++++++++++++++++++++++++++++++++++++ src/gnunet/social/place.h | 251 +++++++++++++++++++++++++++++++ src/gnunet/social/socialapp.cpp | 151 +++++++++++++++++++ src/gnunet/social/socialapp.h | 95 ++++++++++++ src/model/EgoListModel.h | 2 +- src/model/NymListModel.h | 4 +- src/model/PlaceListModel.h | 2 +- src/model/ThreadListModel.h | 2 +- src/model/ThreadModel.h | 2 +- src/social/ego.cpp | 10 -- src/social/ego.h | 40 ----- src/social/guest.cpp | 141 ------------------ src/social/guest.h | 67 --------- src/social/host.cpp | 162 -------------------- src/social/host.h | 82 ----------- src/social/message.cpp | 246 ------------------------------- src/social/message.h | 215 --------------------------- src/social/modifier.cpp | 21 --- src/social/modifier.h | 121 --------------- src/social/nym.cpp | 12 -- src/social/nym.h | 113 -------------- src/social/place.cpp | 319 ---------------------------------------- src/social/place.h | 251 ------------------------------- src/social/socialapp.cpp | 151 ------------------- src/social/socialapp.h | 95 ------------ src/util/qrimageprovider.h | 2 +- 41 files changed, 2074 insertions(+), 2074 deletions(-) create mode 100644 src/gnunet/social/ego.cpp create mode 100644 src/gnunet/social/ego.h create mode 100644 src/gnunet/social/guest.cpp create mode 100644 src/gnunet/social/guest.h create mode 100644 src/gnunet/social/host.cpp create mode 100644 src/gnunet/social/host.h create mode 100644 src/gnunet/social/message.cpp create mode 100644 src/gnunet/social/message.h create mode 100644 src/gnunet/social/modifier.cpp create mode 100644 src/gnunet/social/modifier.h create mode 100644 src/gnunet/social/nym.cpp create mode 100644 src/gnunet/social/nym.h create mode 100644 src/gnunet/social/place.cpp create mode 100644 src/gnunet/social/place.h create mode 100644 src/gnunet/social/socialapp.cpp create mode 100644 src/gnunet/social/socialapp.h delete mode 100644 src/social/ego.cpp delete mode 100644 src/social/ego.h delete mode 100644 src/social/guest.cpp delete mode 100644 src/social/guest.h delete mode 100644 src/social/host.cpp delete mode 100644 src/social/host.h delete mode 100644 src/social/message.cpp delete mode 100644 src/social/message.h delete mode 100644 src/social/modifier.cpp delete mode 100644 src/social/modifier.h delete mode 100644 src/social/nym.cpp delete mode 100644 src/social/nym.h delete mode 100644 src/social/place.cpp delete mode 100644 src/social/place.h delete mode 100644 src/social/socialapp.cpp delete mode 100644 src/social/socialapp.h diff --git a/secushare.pro b/secushare.pro index 05da98d..32d28d0 100644 --- a/secushare.pro +++ b/secushare.pro @@ -28,14 +28,14 @@ SOURCES += src/main.cpp \ src/model/ThreadListModel.cpp \ src/model/ThreadModel.cpp \ src/gnunet/gnunet.cpp \ - src/social/socialapp.cpp \ - src/social/nym.cpp \ - src/social/ego.cpp \ - src/social/modifier.cpp \ - src/social/message.cpp \ - src/social/place.cpp \ - src/social/host.cpp \ - src/social/guest.cpp \ + src/gnunet/social/socialapp.cpp \ + src/gnunet/social/nym.cpp \ + src/gnunet/social/ego.cpp \ + src/gnunet/social/modifier.cpp \ + src/gnunet/social/message.cpp \ + src/gnunet/social/place.cpp \ + src/gnunet/social/host.cpp \ + src/gnunet/social/guest.cpp \ src/settings/settings.cpp \ src/util/helpers.cpp \ src/util/qrimageprovider.cpp @@ -58,14 +58,14 @@ HEADERS += \ src/model/PlaceListModel.h \ src/model/ThreadListModel.h \ src/model/ThreadModel.h \ - src/social/socialapp.h \ - src/social/nym.h \ - src/social/ego.h \ - src/social/modifier.h \ - src/social/message.h \ - src/social/place.h \ - src/social/host.h \ - src/social/guest.h \ + src/gnunet/social/socialapp.h \ + src/gnunet/social/nym.h \ + src/gnunet/social/ego.h \ + src/gnunet/social/modifier.h \ + src/gnunet/social/message.h \ + src/gnunet/social/place.h \ + src/gnunet/social/host.h \ + src/gnunet/social/guest.h \ src/settings/settings.h \ src/util/helpers.h \ src/util/qrimageprovider.h diff --git a/src/app.cpp b/src/app.cpp index c59856b..c249ab5 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1,9 +1,9 @@ #include "app.h" -#include "social/socialapp.h" -#include "social/place.h" -#include "social/host.h" -#include "social/guest.h" +#include "gnunet/social/socialapp.h" +#include "gnunet/social/place.h" +#include "gnunet/social/host.h" +#include "gnunet/social/guest.h" #include #include diff --git a/src/app.h b/src/app.h index eca9460..6b95df3 100644 --- a/src/app.h +++ b/src/app.h @@ -8,8 +8,8 @@ #include #include "gnunet/gnunet.h" +#include "gnunet/social/socialapp.h" #include "model/models.h" -#include "social/socialapp.h" #include "settings/settings.h" #include "util/helpers.h" #include "util/qrimageprovider.h" diff --git a/src/gnunet/social/ego.cpp b/src/gnunet/social/ego.cpp new file mode 100644 index 0000000..410bab8 --- /dev/null +++ b/src/gnunet/social/ego.cpp @@ -0,0 +1,10 @@ +#include "ego.h" + +Ego::Ego (GNUNET_CRYPTO_EcdsaPublicKey pubKey, + QString name, + GNUNET_SOCIAL_Ego *ego, + QObject *parent) + : Nym (pubKey, name, 0, parent) +{ + setEgo (ego); +} diff --git a/src/gnunet/social/ego.h b/src/gnunet/social/ego.h new file mode 100644 index 0000000..fbf6370 --- /dev/null +++ b/src/gnunet/social/ego.h @@ -0,0 +1,40 @@ +#ifndef EGO_H +#define EGO_H + +#include + +#include "nym.h" +#include "gnunet.h" + +class Ego : public Nym +{ + Q_OBJECT; + + public: + + explicit + Ego (GNUNET_CRYPTO_EcdsaPublicKey pubKey, + QString name = "", + GNUNET_SOCIAL_Ego *ego = 0, + QObject *parent = 0); + + + GNUNET_SOCIAL_Ego * + ego () + { + return m_ego; + } + + void + setEgo (GNUNET_SOCIAL_Ego *ego) + { + m_ego = ego; + } + + protected: + + GNUNET_SOCIAL_Ego *m_ego; + +}; + +#endif diff --git a/src/gnunet/social/guest.cpp b/src/gnunet/social/guest.cpp new file mode 100644 index 0000000..0108598 --- /dev/null +++ b/src/gnunet/social/guest.cpp @@ -0,0 +1,141 @@ +#include "guest.h" +#include + +Guest::Guest (GNUNET_SOCIAL_App *app, + GNUNET_SOCIAL_Ego *ego, + const GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + const GNUNET_PeerIdentity *origin, + uint32_t relayCount, + const GNUNET_PeerIdentity *relays, + const GNUNET_PSYC_Message *entryMsg, + QObject *parent) : Place (parent) +{ + m_app = app; + m_ego = ego; + if (NULL == entryMsg) + { + GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create (); + GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_ASSIGN, "_test_abc", "abc def", 7); + GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_ASSIGN, "_test_abc_def", "abc def ghi", 11); + entryMsg = GNUNET_PSYC_message_create ("_request_enter", env, NULL, 0); + } + + m_guest = + GNUNET_SOCIAL_guest_enter (m_app, ego, placePubKey, + GNUNET_PSYC_SLAVE_JOIN_NONE, + origin, 0, NULL, + entryMsg, createSlicer (), + recvLocalEnterCallback, + recvEntryDecisionCallback, + this); + m_plc = GNUNET_SOCIAL_guest_get_place (m_guest); + connectSignals (); +} + + +Guest::Guest (GNUNET_SOCIAL_App *app, + GNUNET_SOCIAL_Ego *ego, + GNUNET_SOCIAL_GuestConnection *gconn, + QObject *parent) : Place (parent) +{ + m_app = app; + m_ego = ego; + m_guest = + GNUNET_SOCIAL_guest_enter_reconnect (gconn, + GNUNET_PSYC_SLAVE_JOIN_NONE, + createSlicer (), + recvLocalEnterCallback, + this); + m_plc = GNUNET_SOCIAL_guest_get_place (m_guest); + connectSignals (); +} + + +Guest::~Guest () +{ + GNUNET_SOCIAL_guest_disconnect (m_guest, NULL, NULL); +} + + +void +Guest::connectSignals () +{ + connect (this, SIGNAL (talkRequestSignal ()), + this, SLOT (talkRequest (QString)), + Qt::QueuedConnection); +} + +void +Guest::recvLocalEnterCallback (void *cls, int result, + const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + uint64_t max_message_id) +{ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Guest entered to local place, result : %i.\n", result); + + Guest *guest = (Guest *) cls; + guest->init (*placePubKey); +} + + +void +Guest::recvEntryDecisionCallback (void *cls, int is_admitted, + const struct GNUNET_PSYC_Message *entry_msg) +{ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Guest received entry decision: %d.\n", is_admitted); + + if (NULL != entry_msg) + { + struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create (); + const char *method_name = NULL; + const void *data = NULL; + uint16_t data_size = 0; + + struct GNUNET_PSYC_MessageHeader *pmsg = + GNUNET_PSYC_message_header_create_from_psyc (entry_msg); + GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n%.*s\n", method_name, data_size, + data); + GNUNET_free (pmsg); + } +} + + +void +Guest::talkRequest (Message *msg) +{ + if (m_inTransmit) + { + // FIXME: queue message + qDebug () << "Host.announce: already in transmit"; + return; + } + + m_inTransmit = true; + m_tmitData = msg->data ().toStdString (); + m_tmitSent = 0; + + GNUNET_PSYC_Environment *env = msg->getPsycEnv (); + m_talk = + GNUNET_SOCIAL_guest_talk (m_guest, msg->method ().toStdString ().c_str (), + env, notifyDataCallback, this, + GNUNET_SOCIAL_TALK_NONE); + GNUNET_PSYC_env_destroy (env); +} + + +void +Guest::talkRequest (QString text) +{ + Message msg ("_converse", QList(), text, 0); + talkRequest (&msg); +} + + +void +Guest::talk (QString text) +{ + emit talkRequestSignal (text); +} diff --git a/src/gnunet/social/guest.h b/src/gnunet/social/guest.h new file mode 100644 index 0000000..6d26864 --- /dev/null +++ b/src/gnunet/social/guest.h @@ -0,0 +1,67 @@ +#ifndef GUEST_H +#define GUEST_H + +#include +#include "place.h" + +class Guest : public Place +{ + + Q_OBJECT; + + public: + + explicit + Guest (GNUNET_SOCIAL_App *app, + GNUNET_SOCIAL_Ego *ego, + const GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + const GNUNET_PeerIdentity *origin, + uint32_t relayCount = 0, + const GNUNET_PeerIdentity *relays = NULL, + const GNUNET_PSYC_Message *entryMsg = NULL, + QObject *parent = NULL); + + explicit + Guest (GNUNET_SOCIAL_App *app, + GNUNET_SOCIAL_Ego *ego, + GNUNET_SOCIAL_GuestConnection *gconn, + QObject *parent = NULL); + + ~Guest (); + + Q_INVOKABLE void + talk (QString text); + + void + talkRequest (Message *msg); + + void + talkRequest (QString text); + + signals: + + void + talkRequestSignal (QString text); + + + private: + + GNUNET_SOCIAL_Guest *m_guest; + + GNUNET_SOCIAL_TalkRequest *m_talk; + + void + connectSignals (); + + static void + recvEntryDecisionCallback (void *cls, int is_admitted, + const struct GNUNET_PSYC_Message + *entry_resp); + + static void + recvLocalEnterCallback (void *cls, int result, + const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + uint64_t max_message_id); +}; + +#endif diff --git a/src/gnunet/social/host.cpp b/src/gnunet/social/host.cpp new file mode 100644 index 0000000..94a8dee --- /dev/null +++ b/src/gnunet/social/host.cpp @@ -0,0 +1,162 @@ +#include "host.h" +#include + +Host::Host (GNUNET_SOCIAL_App *app, + GNUNET_SOCIAL_Ego *ego, + enum GNUNET_PSYC_Policy policy, + QObject *parent) + : Place (parent) +{ + m_app = app; + m_ego = ego; + m_isHost = true; + m_host = + GNUNET_SOCIAL_host_enter (m_app, ego, policy, createSlicer (), + enterCallback, + answerDoorCallback, + farewellCallback, + this); + m_plc = GNUNET_SOCIAL_host_get_place (m_host); + connectSignals (); +} + + +Host::Host (GNUNET_SOCIAL_App *app, + GNUNET_SOCIAL_Ego *ego, + GNUNET_SOCIAL_HostConnection *hconn, + QObject *parent) + : Place (parent) +{ + m_app = app; + m_ego = ego; + m_isHost = true; + m_host = + GNUNET_SOCIAL_host_enter_reconnect (hconn, createSlicer (), + enterCallback, + answerDoorCallback, + farewellCallback, + this); + m_plc = GNUNET_SOCIAL_host_get_place (m_host); + connectSignals (); +} + + +Host::~Host () +{ + GNUNET_SOCIAL_host_disconnect (m_host, NULL, NULL); +} + + +void +Host::connectSignals () +{ + connect (this, SIGNAL (announceSignal (QString)), + this, SLOT (announce (QString)), + Qt::QueuedConnection); +} + + +void +Host::answerDoorCallback (void *cls, struct GNUNET_SOCIAL_Nym *nym, + const char *method_name, + struct GNUNET_PSYC_Environment *env, + const void *data, size_t data_size) +{ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Host received entry request from guest .\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "%s\n%.*s\n", method_name, data_size, data); + + Host *host = (Host *) cls; + emit host->answerDoorSignal (new Message (method_name, env, data, data_size, + 0, nym)); +} + + +void +Host::entryDecision (GNUNET_SOCIAL_Nym *nym, + bool isAdmitted, + Message *response) +{ + GNUNET_PSYC_Message *msg = NULL; + if (NULL != response) + msg = response->toPsyc (); + + GNUNET_SOCIAL_host_entry_decision (m_host, nym, + isAdmitted ? GNUNET_YES : GNUNET_NO, + msg); + if (NULL != msg) + GNUNET_free (msg); +} + + +void +Host::enterCallback (void *cls, int result, + const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + uint64_t max_message_id) +{ + Host *host = (Host *) cls; + host->init (*placePubKey); +} + +void +Host::farewellCallback (void *cls, + const struct GNUNET_SOCIAL_Nym *nym, + struct GNUNET_PSYC_Environment *env) +{ + const struct GNUNET_CRYPTO_EcdsaPublicKey * + nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Nym %s has left the place.\n", + GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key)); +} + + +void +Host::announce (Message *msg) +{ + if (m_inTransmit) + { + // FIXME: queue message + qDebug () << "Host.announce: already in transmit"; + return; + } + + m_inTransmit = true; + m_tmitData = msg->data ().toStdString (); + m_tmitSent = 0; + + GNUNET_PSYC_Environment *env = msg->getPsycEnv (); + m_announce = + GNUNET_SOCIAL_host_announce (m_host, msg->method ().toStdString ().c_str (), + env, notifyDataCallback, this, + GNUNET_SOCIAL_ANNOUNCE_NONE); + GNUNET_PSYC_env_destroy (env); +} + + +void +Host::announce (QString text) +{ + qDebug () << "Host.announce: " << text; + Message msg ("_converse", QList(), text); + announce (&msg); +} + + +void +Host::talk (QString text) +{ + qDebug () << "Host.talk: " << text; + emit announceSignal (text); +} + + +int +Host::zoneAddPlace (QString name) +{ + return + GNUNET_SOCIAL_zone_add_place (m_app, m_ego, name.toStdString().c_str(), NULL, + &m_pubKey, NULL, 0, NULL, + GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MONTHS), + NULL, NULL); +} diff --git a/src/gnunet/social/host.h b/src/gnunet/social/host.h new file mode 100644 index 0000000..ced0000 --- /dev/null +++ b/src/gnunet/social/host.h @@ -0,0 +1,82 @@ +#ifndef HOST_H +#define HOST_H + +#include +#include "place.h" +#include "message.h" + + +class Host : public Place +{ + + Q_OBJECT; + + public: + + explicit + Host (GNUNET_SOCIAL_App *app, + GNUNET_SOCIAL_Ego *ego, + enum GNUNET_PSYC_Policy policy, + QObject *parent = NULL); + + explicit + Host (GNUNET_SOCIAL_App *app, + GNUNET_SOCIAL_Ego *ego, + GNUNET_SOCIAL_HostConnection *hconn, + QObject *parent = NULL); + + ~Host (); + + Q_INVOKABLE void + talk (QString text); + + int + zoneAddPlace (QString name); + + public slots: + + void + announce (Message *msg); + + void + announce (QString text); + + signals: + + void + announceSignal (QString text); + + void + answerDoorSignal (Message *msg); + + private: + + GNUNET_SOCIAL_Host *m_host; + GNUNET_SOCIAL_Announcement *m_announce; + + void + connectSignals (); + + void + entryDecision (GNUNET_SOCIAL_Nym *nym, + bool isAdmitted, + Message *response); + + static void + answerDoorCallback (void *cls, struct GNUNET_SOCIAL_Nym *nym, + const char *method_name, + struct GNUNET_PSYC_Environment *env, + const void *data, size_t data_size); + + static void + enterCallback (void *cls, int result, + const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + uint64_t max_message_id); + + static void + farewellCallback (void *cls, + const struct GNUNET_SOCIAL_Nym *nym, + struct GNUNET_PSYC_Environment *env); +}; + +#endif diff --git a/src/gnunet/social/message.cpp b/src/gnunet/social/message.cpp new file mode 100644 index 0000000..abc3f9c --- /dev/null +++ b/src/gnunet/social/message.cpp @@ -0,0 +1,246 @@ +#include "message.h" +#include "modifier.h" + + +Message::Message (QString method, + QList env, + QByteArray data, + uint64_t id, + GNUNET_SOCIAL_Nym *nym, + Message *parent) + : QObject (parent) +{ + m_id = id; + m_nym = nym; + m_method = method; + m_env = env; + m_data = data; + m_parent = parent; +} + + +Message::Message (QString method, + QList env, + QString text, + uint64_t id, + GNUNET_SOCIAL_Nym *nym, + Message *parent) + : QObject (parent) +{ + m_id = id; + m_nym = nym; + m_method = method; + m_env = env; + m_data = text.toUtf8 (); + m_parent = parent; +} + + +Message::Message (const char *method, + GNUNET_PSYC_Environment *env, + const void *data, + size_t data_size, + uint64_t id, + GNUNET_SOCIAL_Nym *nym, + Message *parent) + : QObject (parent) +{ + m_id = id; + m_nym = nym; + m_method = QString::fromLatin1 (method); + m_data = QByteArray ((const char *) data, data_size); + m_parent = parent; + + GNUNET_PSYC_env_iterate (env, iterateEnv, this); +} + + +Message::~Message () +{ + // FIXME: delete children? + emit deleted (this); +} + + +/*** PSYC ***/ + + +void +Message::appendModifier (Modifier *mod) +{ + m_env.append (mod); +} + + +QByteArray & +Message::appendData (QByteArray data) +{ + return m_data.append (data); +} + + +QByteArray & +Message::appendData (char *data, size_t data_size) +{ + return m_data.append (data, data_size); +} + + +Modifier * +Message::findModifier (const QString name) +{ + QListIterator it (m_env); + while (it.hasNext ()) + { + Modifier *mod = it.next (); + if (mod->name () == name) + return mod; + } + return 0; +} + + +int +Message::iterateEnv (void *cls, GNUNET_PSYC_Operator oper, + const char *name, const char *value, + uint32_t value_size) +{ + Message *m = (Message *) cls; + m->m_env += new Modifier (oper, + QString (name), + QByteArray (value, value_size)); + return GNUNET_YES; +} + + +GNUNET_PSYC_Message * +Message::toPsyc () +{ + GNUNET_PSYC_Environment *env = getPsycEnv (); + GNUNET_PSYC_Message * + msg = GNUNET_PSYC_message_create (m_method.toLatin1 (), env, + m_data.constData (), m_data.size ()); + GNUNET_PSYC_env_destroy (env); + return msg; +} + + +GNUNET_PSYC_Environment * +Message::getPsycEnv () +{ + GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create (); + QListIterator it (m_env); + while (it.hasNext ()) + { + Modifier *mod = it.next (); + GNUNET_PSYC_env_add (env, mod->oper (), mod->name ().toLatin1 (), + mod->value (), mod->value ().size ()); + } + return env; +} + + +/*** Threads ***/ + + +/** + * Set parent message. + */ +void +Message::setParent (Message *msg) +{ + m_parent = msg; + QObject::setParent (msg); +} + + +/** + * Append @a msg at the end of children list. + */ +void +Message::appendChild (Message *msg) +{ + m_children.append (msg); + msg->setParent (this); + emit childAdded (msg); +} + + +/** + * Get nth child message. + */ +Message * +Message::child (int n) +{ + return m_children.value (n); +} + + +/** + * Get number of children. + */ +int +Message::childrenCount () const +{ + return m_children.count (); +} + + +/** + * Get parent message. + */ +Message * +Message::parent () +{ + return m_parent; +} + + +/** + * Get index of a given child message. + * + * @return Index or -1 if not found. + */ +int +Message::childIndex (Message *msg) const +{ + return m_children.indexOf (msg); +} + + +/** + * Get index of this message in its parent's children list. + * + * @return Position index or -1 if not found. + */ +int +Message::index () const +{ + return (m_parent) + ? m_parent->childIndex (const_cast (this)) + : -1; +} + + +/*** Operators ***/ + + +bool +Message::lessThan (Message &a, Message &b) +{ + return a.id () < b.id (); +} + + +bool +Message::operator< (Message &b) +{ + return id () < b.id (); +} + + +bool +Message::operator== (Message &b) +{ + return id () == b.id (); +} diff --git a/src/gnunet/social/message.h b/src/gnunet/social/message.h new file mode 100644 index 0000000..b3735ef --- /dev/null +++ b/src/gnunet/social/message.h @@ -0,0 +1,215 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include +#include +#include "modifier.h" +#include "gnunet.h" + +class Message : public QObject +{ + + Q_OBJECT; + + Q_PROPERTY (uint64_t id + READ id); + + Q_PROPERTY (QString method + READ method + WRITE setMethod); + + Q_PROPERTY (QString text + READ text + WRITE setText); + + public: + + explicit + Message (QString method, + QList env = QList(), + QByteArray data = "", + uint64_t id = 0, + GNUNET_SOCIAL_Nym *nym = 0, + Message *parent = 0); + + explicit + Message (QString method, + QList env, + QString text, + uint64_t id = 0, + GNUNET_SOCIAL_Nym *nym = 0, + Message *parent = 0); + + explicit + Message (const char *method, + GNUNET_PSYC_Environment *env, + const void *data = 0, + size_t data_size = 0, + uint64_t id = 0, + GNUNET_SOCIAL_Nym *nym = 0, + Message *parent = 0); + + ~Message (); + + /*** PSYC ***/ + + void + appendModifier (Modifier *mod); + + QByteArray & + appendData (QByteArray data); + + QByteArray & + appendData (char *data, size_t data_size); + + Modifier * + findModifier (const QString name); + + GNUNET_PSYC_Message * + toPsyc (); + + GNUNET_PSYC_Environment * + getPsycEnv (); + + + /*** Threads ***/ + + void + setParent (Message *msg); + + void + appendChild (Message *msg); + + Message * + child (int n); + + int + childrenCount () const; + + int + childIndex (Message *msg) const; + + int + index () const; + + Message * + parent (); + + + /*** Operators ***/ + + static bool + lessThan (Message &a, Message &b); + + bool + operator< (Message &b); + + bool + operator== (Message &b); + + + /*** Properties ***/ + + uint64_t + id () const + { + return m_id; + } + + GNUNET_SOCIAL_Nym * + nym () const + { + return m_nym; + } + + void + setNym (GNUNET_SOCIAL_Nym *nym) + { + m_nym = nym; + } + + + QString + method () const + { + return m_method; + } + + void + setMethod (QString method) + { + m_method = method; + } + + + QList + env () const + { + return m_env; + } + + void + setEnv (QList env) + { + m_env = env; + } + + + QByteArray + data () const + { + return m_data; + } + + void + setData (QByteArray data) + { + m_data = data; + } + + + QString + text () const + { + return m_data; + } + + void + setText (QString text) + { + m_data = text.toUtf8 (); + } + + + signals: + + void + modified (Message *msg); + + void + childAdded (Message *msg); + + void + deleted (Message *msg); + + private: + + uint64_t m_id; + GNUNET_SOCIAL_Nym *m_nym; + QString m_method; + QList m_env; + QByteArray m_data; + + QList m_children; + Message *m_parent; + + void *m_ptr; + + static int + iterateEnv (void *cls, GNUNET_PSYC_Operator oper, + const char *name, const char *value, + uint32_t value_size); + +}; + +#endif diff --git a/src/gnunet/social/modifier.cpp b/src/gnunet/social/modifier.cpp new file mode 100644 index 0000000..a784db2 --- /dev/null +++ b/src/gnunet/social/modifier.cpp @@ -0,0 +1,21 @@ +#include "modifier.h" + + +Modifier::Modifier (GNUNET_PSYC_Operator oper, QString name, QByteArray value, + QObject *parent) + : QObject (parent) +{ + m_oper = oper; + m_name = name; + m_value = value; +} + + +Modifier::Modifier (GNUNET_PSYC_Operator oper, QString name, QString text, + QObject *parent) + : QObject (parent) +{ + m_oper = oper; + m_name = name; + m_value = text.toUtf8 (); +} diff --git a/src/gnunet/social/modifier.h b/src/gnunet/social/modifier.h new file mode 100644 index 0000000..bfcb51c --- /dev/null +++ b/src/gnunet/social/modifier.h @@ -0,0 +1,121 @@ +#ifndef MODIFIER_H +#define MODIFIER_H + +#include +#include "gnunet.h" + +class Modifier : public QObject +{ + Q_OBJECT; + + Q_PROPERTY (GNUNET_PSYC_Operator oper + READ oper + WRITE setOper); + + Q_PROPERTY (QString name + READ name + WRITE setName); + + Q_PROPERTY (QByteArray value + READ value + WRITE setValue); + + Q_PROPERTY (QString text + READ text + WRITE setText); + + public: + + explicit + Modifier (GNUNET_PSYC_Operator oper, QString name, QByteArray value, QObject *parent = 0); + + explicit + Modifier (GNUNET_PSYC_Operator oper, QString name, QString text, QObject *parent = 0); + + + GNUNET_PSYC_Operator + oper () const + { + return m_oper; + } + + void + setOper (GNUNET_PSYC_Operator oper) + { + m_oper = oper; + } + + + QString + name () const + { + return m_name; + } + + void + setName (QString name) + { + m_name = name; + } + + + QByteArray + value () const + { + return m_value; + } + + void + setValue (QByteArray value) + { + m_value = value; + } + + + QString + text () const + { + return m_value; + } + + void + setText (QString text) + { + m_value = text.toUtf8 (); + } + + + uint64_t + amount () const + { + return m_value.toULongLong (); + } + + void + setAmount (quint64 num) + { + m_value = QByteArray::number (num); + } + + + int64_t + number () const + { + return m_value.toLongLong (); + } + + void + setNumber (qint64 num) + { + m_value = QByteArray::number (num); + } + + + private: + + GNUNET_PSYC_Operator m_oper; + QString m_name; + QByteArray m_value; +}; + +#endif diff --git a/src/gnunet/social/nym.cpp b/src/gnunet/social/nym.cpp new file mode 100644 index 0000000..007b26c --- /dev/null +++ b/src/gnunet/social/nym.cpp @@ -0,0 +1,12 @@ +#include "ego.h" + +Nym::Nym (GNUNET_CRYPTO_EcdsaPublicKey pubKey, + QString name, + GNUNET_SOCIAL_Nym *nym, + QObject *parent) + : QObject (parent) +{ + setPubKey (pubKey); + setName (name); + setNym (nym); +} diff --git a/src/gnunet/social/nym.h b/src/gnunet/social/nym.h new file mode 100644 index 0000000..9c7b88b --- /dev/null +++ b/src/gnunet/social/nym.h @@ -0,0 +1,113 @@ +#ifndef NYM_H +#define NYM_H + +#include + +#include "gnunet.h" + +class Nym : public QObject +{ + Q_OBJECT; + Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged); + Q_PROPERTY (QString pubKeyString READ pubKeyString); + Q_PROPERTY (QString gnsUrl READ gnsUrl CONSTANT); + + public: + + explicit + Nym (GNUNET_CRYPTO_EcdsaPublicKey pubKey, + QString name = "", + GNUNET_SOCIAL_Nym *nym = 0, + QObject *parent = 0); + + int + index () const + { + return m_index; + } + + void + setIndex (int index) + { + m_index = index; + } + + + QString + name () + { + return m_name; + } + + void + setName (QString name) + { + m_name = name; + emit nameChanged (name); + emit modified (m_index); + } + + + GNUNET_CRYPTO_EcdsaPublicKey + pubKey () const + { + return m_pubKey; + } + + QString + pubKeyString () + { + return m_pubKeyStr; + } + + void + setPubKey (GNUNET_CRYPTO_EcdsaPublicKey pubKey) + { + m_pubKey = pubKey; + char *pubKeyChr = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pubKey); + m_pubKeyStr = QString::fromLatin1 (pubKeyChr); + GNUNET_free (pubKeyChr); + + if (m_name.isEmpty ()) + { + m_name = m_pubKeyStr.left (8); + } + emit modified (m_index); + } + + QString + gnsUrl () + { + // should GNS appear explicitly in a client app? shouldn't it be + // used transparently behind the gnunet social API instead? + return QString ("gnunet://gns/%1").arg (m_pubKeyStr); + } + + GNUNET_SOCIAL_Nym * + nym () + { + return m_nym; + } + void + setNym (GNUNET_SOCIAL_Nym *nym) + { + m_nym = nym; + } + + protected: + + int m_index; + + QString m_name; + QString m_pubKeyStr; + GNUNET_CRYPTO_EcdsaPublicKey m_pubKey; + GNUNET_SOCIAL_Nym *m_nym; + + signals: + + void modified (int index); + void nameChanged (QString name); + +}; + +#endif diff --git a/src/gnunet/social/place.cpp b/src/gnunet/social/place.cpp new file mode 100644 index 0000000..8b1f4f3 --- /dev/null +++ b/src/gnunet/social/place.cpp @@ -0,0 +1,319 @@ +#include "place.h" +#include "model/models.h" +#include "model/PlaceListModel.h" +#include "app.h" + +#include +#include +#include + +/** + * @brief Place::Place, constructor should receive the public key as title + * @param key + * @param parent + */ +Place::Place (QObject *parent) : QObject (parent) +{ + m_type = "group"; //thread;group;contact + m_isHost = false; + m_inTransmit = false; + m_msg = 0; + m_mod = 0; + + #if FIXME + connect (this, &Place::setTrayMessage, + theApp, &App::setTrayMessage, Qt::QueuedConnection); + #endif +} + +void +Place::init (const GNUNET_CRYPTO_EddsaPublicKey pubKey) +{ + char *pubKeyChars = GNUNET_CRYPTO_eddsa_public_key_to_string (&pubKey); + QString pubKeyStr = QString::fromLatin1 (pubKeyChars); + + setPubKey (pubKey); + setName (pubKeyStr); +} + +/** + * Copy public key of place to clipboard. + */ +void +Place::copyToClipboard () +{ + QClipboard *clipboard = QApplication::clipboard (); + + clipboard->setText (m_pubKeyStr); +} + +/** + * Send a message to the place. + * + * @param text + * The message. + */ +void +Place::talk (QString text) +{ +#if FIXME + if (m_isHost) + { + emit hostTalkSignal (this, text); + } + else + { + emit guestTalkSignal (this, text); + } +#endif +} + + +GNUNET_PSYC_Slicer * +Place::createSlicer () +{ + m_slicer = GNUNET_PSYC_slicer_create (); + GNUNET_PSYC_slicer_method_add (m_slicer, "", NULL, + recvMethodCallback, + recvModifierCallback, + recvDataCallback, + recvEomCallback, + this); + return m_slicer; +} + + +void // static +Place::recvMethodCallback (void *cls, + const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_PSYC_MessageMethod *meth, + uint64_t message_id, + const char *method_name) +{ + Place *p = (Place *) cls; + p->recvMethod (msg, meth, message_id, method_name); +} + + +void +Place::recvMethod (const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_PSYC_MessageMethod *meth, + uint64_t message_id, + const char *method_name) +{ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Test #: Host received method for message ID %i:\n" "%s\n", + message_id, method_name); + if (m_msg) + delete m_msg; + m_msg = new Message (method_name); + m_mod = 0; +} + + +void // static +Place::recvModifierCallback (void *cls, + const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + enum GNUNET_PSYC_Operator oper, + const char *name, + const void *value, + uint16_t value_size, + uint16_t full_value_size) +{ + Place *p = (Place *) cls; + p->recvModifier (msg, pmsg, message_id, oper, name, + value, value_size, full_value_size); +} + + +void +Place::recvModifier (const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + enum GNUNET_PSYC_Operator oper, + const char *name, + const void *value, + uint16_t value_size, + uint16_t full_value_size) +{ + QString str = QString::fromLatin1 ((char *) value); + + qWarning () << "Host received modifier for message ID" + << message_id << oper << name << value_size << str; + Q_ASSERT (m_msg); + + if (!m_mod) + { + m_mod = new Modifier (oper, + QString (name), + QByteArray ((const char *) value, value_size)); + } + else + { + m_mod->value ().append ((const char *) value, value_size); + } + + if (m_mod->value ().size () == full_value_size) + { + m_msg->appendModifier (m_mod); + m_mod = 0; + } +} + + +void // static +Place::recvDataCallback (void *cls, + const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + const void *data, + uint16_t data_size) +{ + Place *p = (Place *) cls; + p->recvData (msg, pmsg, message_id, data, data_size); +} + + +void +Place::recvData (const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + const void *data, + uint16_t data_size) +{ + QString str = QString::fromLatin1 ((char *) data); + qWarning () << "Host received data for message ID " + << message_id << data_size << str; + + Q_ASSERT (m_msg); + m_msg->appendData ((char *) data, data_size); +} + + +void // static +Place::recvEomCallback (void *cls, + const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + uint8_t is_cancelled) +{ + Place *p = (Place *) cls; + p->recvEom (msg, pmsg, message_id, is_cancelled); +} + + +void +Place::recvEom (const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + uint8_t is_cancelled) +{ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Test #: Host received end of message ID %i, cancelled: %u\n", + message_id, is_cancelled); + Q_ASSERT (m_msg); + + if (GNUNET_NO == is_cancelled) + insertMessage (m_msg); + m_msg = 0; +} + + +/** + * Insert message to its place in the thread. + */ +void +Place::insertMessage (Message *msg) +{ + m_msgHash.insert (msg->id (), msg); + + // Find thread + + bool newThread = false; + uint64_t threadId = 0; + Modifier *mod = msg->findModifier ("_id_thread"); + if (mod) + threadId = mod->amount (); + + Message *thread = m_threadHash.value (threadId); + if (!thread) + { + if (msg->id () == threadId) + { + thread = msg; + } + else // missing thread starter message, or message not in thread + { + // Create a placeholder message that will be replaced + // when the missing message arrives (or not if it's not in a thread). + thread = new Message ("_INTERNAL_missing"); + // methods or variables of the _INTERNAL family must never be sent + // over the wire! history replay must ensure that. -lynX + + if (0 < threadId) + { + /// @todo request missing message(s) in thread from history + //FIXME: GNUNET_SOCIAL_history_replay_thread (m_plc, threadId, ...); + } + } + + m_threads += thread; + m_threadHash.insert (threadId, thread); + newThread = true; + } + + // Find parent message + + Message *parent = 0; + uint64_t parentId = 0; + mod = msg->findModifier ("_id_reply"); + if (mod) + parentId = mod->amount (); + + if (0 < parentId) + parent = m_msgHash.value (parentId); + + if (!parent && thread != msg) + parent = thread; + + if (parent) + parent->appendChild (msg); + + emit messageReceived (msg, parent, thread); + + if (newThread) + { + emit threadAdded (msg); + } +} + + +int +Place::notifyDataCallback (void *cls, uint16_t *data_size, void *data) +{ + Place *p = (Place *) cls; + return p->notifyData (data_size, data); +} + + +int +Place::notifyData (uint16_t *data_size, void *data) +{ + qDebug () << "Place: data_sent=" << m_tmitSent << ", " + << "data_size=" << *data_size; + + std::string sub = m_tmitData.substr (m_tmitSent, *data_size); + *data_size = sub.size (); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data_size: %u\n", *data_size); + memcpy (data, sub.c_str (), *data_size); + m_tmitSent += *data_size; + + if (m_tmitSent < m_tmitData.size ()) + return GNUNET_NO; + + m_inTransmit = false; + emit dataSent (); + return GNUNET_YES; +} diff --git a/src/gnunet/social/place.h b/src/gnunet/social/place.h new file mode 100644 index 0000000..c5445be --- /dev/null +++ b/src/gnunet/social/place.h @@ -0,0 +1,251 @@ +#ifndef PLACE_H +#define PLACE_H + +#include +#include "message.h" +#include "gnunet.h" + + +class Place : public QObject +{ + + Q_OBJECT; + Q_PROPERTY (QString pubkey READ pubKeyString NOTIFY pubKeyStringChanged); + Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged); + Q_PROPERTY (QString desc READ desc WRITE setDesc NOTIFY descChanged); + + public: + + explicit Place (QObject *parent = 0); + + //Index + int index () const + { + return m_index; + } + void setIndex (int index) + { + m_index = index; + } + + //Name + QString name () const + { + return m_name; + } + void setName (QString name) + { + m_name = name; + emit nameChanged (name); + emit modified (this); + } + + // Desc + QString desc () const + { + return m_desc; + } + void setDesc (QString desc) + { + m_desc = desc; + emit descChanged (desc); + emit modified (this); + } + + //Type + QString type () const + { + return m_type; + } + void setType (QString type) + { + m_type = type; + emit typeChanged (type); + emit modified (this); + } + + //Is Host ? + bool isHost () const + { + return m_isHost; + } + + //Public Key + GNUNET_CRYPTO_EddsaPublicKey pubKey () const + { + return m_pubKey; + } + + QString pubKeyString () const + { + return m_pubKeyStr; + } + + void setPubKey (GNUNET_CRYPTO_EddsaPublicKey pubKey) + { + m_pubKey = pubKey; + char *pubKeyChr = GNUNET_CRYPTO_eddsa_public_key_to_string (&pubKey); + m_pubKeyStr = QString::fromLatin1 (pubKeyChr); + GNUNET_free (pubKeyChr); + emit pubKeyStringChanged (m_pubKeyStr); + emit modified (this); + } + + const QList & + threads () + { + return m_threads; + } + + Q_INVOKABLE void + copyToClipboard (); + + Q_INVOKABLE void + talk (QString text); + + protected: + + int m_index; + + QString m_name; + + QString m_desc; + + QString m_type; // FIXME + + /// Message currently being received. + Message *m_msg; + + /// Modifier currently being received. + Modifier *m_mod; + + /// List of top-level, thread-starting messages. + QList m_threads; + + /// _thread_id -> thread starter Message + QHash m_threadHash; + + /// _message_id -> Message + QHash m_msgHash; + + QString m_pubKeyStr; + + GNUNET_CRYPTO_EddsaPublicKey m_pubKey; + + bool m_isHost; + + GNUNET_SOCIAL_App *m_app; + GNUNET_SOCIAL_Ego *m_ego; + GNUNET_SOCIAL_Place *m_plc; + GNUNET_PSYC_Slicer *m_slicer; + + bool m_inTransmit; + std::string m_tmitData; + size_t m_tmitSent; + + void + init (GNUNET_CRYPTO_EddsaPublicKey pubKey); + + GNUNET_PSYC_Slicer * + createSlicer (); + + static int + notifyDataCallback (void *cls, uint16_t *data_size, void *data); + + int + notifyData (uint16_t *data_size, void *data); + + void + insertMessage (Message *msg); + + static void + recvMethodCallback (void *cls, + const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_PSYC_MessageMethod *meth, + uint64_t message_id, + const char *method_name); + + void + recvMethod (const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_PSYC_MessageMethod *meth, + uint64_t message_id, + const char *method_name); + + static void + recvModifierCallback (void *cls, + const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + enum GNUNET_PSYC_Operator oper, + const char *name, const void *value, + uint16_t value_size, + uint16_t full_value_size); + + void + recvModifier (const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + enum GNUNET_PSYC_Operator oper, + const char *name, + const void *value, + uint16_t value_size, + uint16_t full_value_size); + + + static void + recvDataCallback (void *cls, + const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + const void *data, + uint16_t data_size); + + void + recvData (const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + const void *data, + uint16_t data_size); + + static void + recvEomCallback (void *cls, + const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + uint8_t is_cancelled); + + void + recvEom (const struct GNUNET_PSYC_MessageHeader *msg, + const struct GNUNET_MessageHeader *pmsg, + uint64_t message_id, + uint8_t is_cancelled); + + signals: + + void modified (Place *place); + + void pubKeyStringChanged (QString pubKeyString); + + void nameChanged (QString name); + + void descChanged (QString desc); + + void typeChanged (QString type); + + void dataSent (); + + void messageReceived (Message *msg, Message *parent, Message *thread); + + void threadAdded (Message *msg); + +#if FIXME + void talkSignal (QString text); + + void setTrayMessage (QString place, QString text); +#endif + +public slots: + +}; + +#endif diff --git a/src/gnunet/social/socialapp.cpp b/src/gnunet/social/socialapp.cpp new file mode 100644 index 0000000..e739574 --- /dev/null +++ b/src/gnunet/social/socialapp.cpp @@ -0,0 +1,151 @@ +#include "socialapp.h" +#include "app.h" + +#include "host.h" +#include "guest.h" + + +SocialApp::SocialApp (struct GNUNET_CONFIGURATION_Handle *config, + QObject *parent) + : QObject (parent) +{ + m_config = config; + m_app = + GNUNET_SOCIAL_app_connect (m_config, APP_NAME, + egoCallback, + hostPlaceCallback, + guestPlaceCallback, + this); +} + + +SocialApp::~SocialApp () +{ + GNUNET_SOCIAL_app_disconnect (m_app); +} + + +void +SocialApp::egoCallback (void *cls, + struct GNUNET_SOCIAL_Ego *ego, + const struct GNUNET_CRYPTO_EcdsaPublicKey *egoPubKey, + const char *name) +{ + SocialApp *s = (SocialApp *) cls; + s->addEgo (new Ego (*egoPubKey, QString::fromLatin1 (name), ego)); +} + + +void +SocialApp::addEgo (Ego *ego) +{ + m_egos += ego; + emit egoAdded (ego); +} + +void +SocialApp::addPlace (Place *place) +{ + m_places += place; + place->setIndex (m_places.count () - 1); + emit placeAdded (place); +} + +void +SocialApp::hostPlaceCallback (void *cls, + struct GNUNET_SOCIAL_HostConnection *hconn, + struct GNUNET_SOCIAL_Ego *ego, + const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + enum GNUNET_SOCIAL_AppPlaceState placeState) +{ + SocialApp *s = (SocialApp *) cls; + s->addPlace (new Host (s->m_app, ego, hconn, s)); +} + + +void +SocialApp::guestPlaceCallback (void *cls, + struct GNUNET_SOCIAL_GuestConnection *gconn, + struct GNUNET_SOCIAL_Ego *ego, + const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + enum GNUNET_SOCIAL_AppPlaceState placeState) +{ + SocialApp *s = (SocialApp *) cls; + s->addPlace (new Guest (s->m_app, ego, gconn, s)); +} + + +Ego * +SocialApp::findEgo (const QString pubKeyStr) +{ + QListIterator it (m_egos); + while (it.hasNext ()) + { + Ego *ego = it.next (); + if (ego->pubKeyString () == pubKeyStr) + return ego; + } + return 0; +} + + +void +SocialApp::createPlace (GNUNET_SOCIAL_Ego *ego) +{ + addPlace (new Host (m_app, ego, GNUNET_PSYC_CHANNEL_PRIVATE, this)); +} + + +void +SocialApp::createPlaceSlot (QString egoPubKeyStr) +{ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n"); + + Ego *ego = findEgo (egoPubKeyStr); + if (!ego) // FIXME: fall back to last added ego for now + { + Q_ASSERT (!m_egos.isEmpty ()); + ego = m_egos.last (); + } + + createPlace (ego->ego ()); +} + + +void +SocialApp::enterPlace (GNUNET_SOCIAL_Ego *ego, + GNUNET_CRYPTO_EddsaPublicKey *pubKey, + GNUNET_PeerIdentity *peerId) +{ + addPlace (new Guest (m_app, ego, pubKey, peerId, 0, NULL, NULL, this)); +} + + +void +SocialApp::enterPlaceSlot (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr) +{ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering place %s as guest.\n", + pubKeyStr.toStdString ().c_str ()); + + GNUNET_CRYPTO_EddsaPublicKey pubKey; + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_public_key_from_string (pubKeyStr.toStdString ().c_str (), + pubKeyStr.length (), + &pubKey)) + return; // Failed conversion + + GNUNET_PeerIdentity peerId; + if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peerIdStr.toStdString ().c_str (), + peerIdStr.length (), + &peerId.public_key)) + return; // Failed conversion + + Ego *ego = findEgo (egoPubKeyStr); + if (!ego) // FIXME: fall back to last added ego for now + { + Q_ASSERT (!m_egos.isEmpty ()); + ego = m_egos.last (); + } + + enterPlace (ego->ego (), &pubKey, &peerId); +} diff --git a/src/gnunet/social/socialapp.h b/src/gnunet/social/socialapp.h new file mode 100644 index 0000000..36b4ee4 --- /dev/null +++ b/src/gnunet/social/socialapp.h @@ -0,0 +1,95 @@ +#ifndef SOCIAL_APP_H +#define SOCIAL_APP_H + +#include +#include + +#include "ego.h" +#include "place.h" +#include "gnunet.h" + +class SocialApp : public QObject +{ + Q_OBJECT; + + public: + + explicit SocialApp (GNUNET_CONFIGURATION_Handle * config, + QObject *parent = 0); + ~SocialApp (); + + Ego * + findEgo (const QString pubKeyStr); + + void + createPlace (GNUNET_SOCIAL_Ego *ego); + + void + enterPlace (GNUNET_SOCIAL_Ego *ego, + GNUNET_CRYPTO_EddsaPublicKey *pubKey, + GNUNET_PeerIdentity *peerId); + + const QList & + egos () + { + return m_egos; + } + + const QList & + places () + { + return m_places; + } + + signals: + + void + egoAdded (Ego *ego); + + void + placeAdded (Place *place); + + public slots: + + void + createPlaceSlot (QString egoPubKeyStr); + + void + enterPlaceSlot (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr); + + private: + + GNUNET_SOCIAL_App *m_app; + QList m_egos; + QList m_places; + GNUNET_CONFIGURATION_Handle *m_config; + + static void + egoCallback (void *cls, + struct GNUNET_SOCIAL_Ego *ego, + const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key, + const char *name); + + void + addEgo (Ego *ego); + + void + addPlace (Place *place); + + static void + hostPlaceCallback (void *cls, + struct GNUNET_SOCIAL_HostConnection *hconn, + struct GNUNET_SOCIAL_Ego *ego, + const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + enum GNUNET_SOCIAL_AppPlaceState placeState); + + static void + guestPlaceCallback (void *cls, + struct GNUNET_SOCIAL_GuestConnection *gconn, + struct GNUNET_SOCIAL_Ego *ego, + const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, + enum GNUNET_SOCIAL_AppPlaceState placeState); + +}; + +#endif diff --git a/src/model/EgoListModel.h b/src/model/EgoListModel.h index 3347ab7..48b1e6a 100644 --- a/src/model/EgoListModel.h +++ b/src/model/EgoListModel.h @@ -24,7 +24,7 @@ #include #include -#include "social/ego.h" +#include "gnunet/social/ego.h" #include "gnunet.h" diff --git a/src/model/NymListModel.h b/src/model/NymListModel.h index 1546c26..db95b39 100644 --- a/src/model/NymListModel.h +++ b/src/model/NymListModel.h @@ -24,7 +24,7 @@ #include #include -#include "social/ego.h" +#include "gnunet/social/nym.h" #include "gnunet.h" @@ -64,7 +64,7 @@ public: public slots: void - rowAdded (Nym *ego); + rowAdded (Nym *nym); void rowModified (int index); diff --git a/src/model/PlaceListModel.h b/src/model/PlaceListModel.h index 452162a..ac755e0 100644 --- a/src/model/PlaceListModel.h +++ b/src/model/PlaceListModel.h @@ -24,7 +24,7 @@ #include #include "ThreadListModel.h" -#include "social/place.h" +#include "gnunet/social/place.h" class PlaceListModel : public QAbstractListModel diff --git a/src/model/ThreadListModel.h b/src/model/ThreadListModel.h index 0d67b88..5c6d94c 100644 --- a/src/model/ThreadListModel.h +++ b/src/model/ThreadListModel.h @@ -4,7 +4,7 @@ #include #include "ThreadModel.h" -#include "social/place.h" +#include "gnunet/social/place.h" class ThreadListModel : public QAbstractListModel diff --git a/src/model/ThreadModel.h b/src/model/ThreadModel.h index ff1111f..f28eab7 100644 --- a/src/model/ThreadModel.h +++ b/src/model/ThreadModel.h @@ -1,7 +1,7 @@ #ifndef THREADMODEL_H #define THREADMODEL_H -#include "social/message.h" +#include "gnunet/social/message.h" #include class ThreadModel : public QAbstractItemModel diff --git a/src/social/ego.cpp b/src/social/ego.cpp deleted file mode 100644 index 410bab8..0000000 --- a/src/social/ego.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "ego.h" - -Ego::Ego (GNUNET_CRYPTO_EcdsaPublicKey pubKey, - QString name, - GNUNET_SOCIAL_Ego *ego, - QObject *parent) - : Nym (pubKey, name, 0, parent) -{ - setEgo (ego); -} diff --git a/src/social/ego.h b/src/social/ego.h deleted file mode 100644 index fbf6370..0000000 --- a/src/social/ego.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef EGO_H -#define EGO_H - -#include - -#include "nym.h" -#include "gnunet.h" - -class Ego : public Nym -{ - Q_OBJECT; - - public: - - explicit - Ego (GNUNET_CRYPTO_EcdsaPublicKey pubKey, - QString name = "", - GNUNET_SOCIAL_Ego *ego = 0, - QObject *parent = 0); - - - GNUNET_SOCIAL_Ego * - ego () - { - return m_ego; - } - - void - setEgo (GNUNET_SOCIAL_Ego *ego) - { - m_ego = ego; - } - - protected: - - GNUNET_SOCIAL_Ego *m_ego; - -}; - -#endif diff --git a/src/social/guest.cpp b/src/social/guest.cpp deleted file mode 100644 index 0108598..0000000 --- a/src/social/guest.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include "guest.h" -#include - -Guest::Guest (GNUNET_SOCIAL_App *app, - GNUNET_SOCIAL_Ego *ego, - const GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - const GNUNET_PeerIdentity *origin, - uint32_t relayCount, - const GNUNET_PeerIdentity *relays, - const GNUNET_PSYC_Message *entryMsg, - QObject *parent) : Place (parent) -{ - m_app = app; - m_ego = ego; - if (NULL == entryMsg) - { - GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create (); - GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_ASSIGN, "_test_abc", "abc def", 7); - GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_ASSIGN, "_test_abc_def", "abc def ghi", 11); - entryMsg = GNUNET_PSYC_message_create ("_request_enter", env, NULL, 0); - } - - m_guest = - GNUNET_SOCIAL_guest_enter (m_app, ego, placePubKey, - GNUNET_PSYC_SLAVE_JOIN_NONE, - origin, 0, NULL, - entryMsg, createSlicer (), - recvLocalEnterCallback, - recvEntryDecisionCallback, - this); - m_plc = GNUNET_SOCIAL_guest_get_place (m_guest); - connectSignals (); -} - - -Guest::Guest (GNUNET_SOCIAL_App *app, - GNUNET_SOCIAL_Ego *ego, - GNUNET_SOCIAL_GuestConnection *gconn, - QObject *parent) : Place (parent) -{ - m_app = app; - m_ego = ego; - m_guest = - GNUNET_SOCIAL_guest_enter_reconnect (gconn, - GNUNET_PSYC_SLAVE_JOIN_NONE, - createSlicer (), - recvLocalEnterCallback, - this); - m_plc = GNUNET_SOCIAL_guest_get_place (m_guest); - connectSignals (); -} - - -Guest::~Guest () -{ - GNUNET_SOCIAL_guest_disconnect (m_guest, NULL, NULL); -} - - -void -Guest::connectSignals () -{ - connect (this, SIGNAL (talkRequestSignal ()), - this, SLOT (talkRequest (QString)), - Qt::QueuedConnection); -} - -void -Guest::recvLocalEnterCallback (void *cls, int result, - const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - uint64_t max_message_id) -{ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Guest entered to local place, result : %i.\n", result); - - Guest *guest = (Guest *) cls; - guest->init (*placePubKey); -} - - -void -Guest::recvEntryDecisionCallback (void *cls, int is_admitted, - const struct GNUNET_PSYC_Message *entry_msg) -{ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Guest received entry decision: %d.\n", is_admitted); - - if (NULL != entry_msg) - { - struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create (); - const char *method_name = NULL; - const void *data = NULL; - uint16_t data_size = 0; - - struct GNUNET_PSYC_MessageHeader *pmsg = - GNUNET_PSYC_message_header_create_from_psyc (entry_msg); - GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n%.*s\n", method_name, data_size, - data); - GNUNET_free (pmsg); - } -} - - -void -Guest::talkRequest (Message *msg) -{ - if (m_inTransmit) - { - // FIXME: queue message - qDebug () << "Host.announce: already in transmit"; - return; - } - - m_inTransmit = true; - m_tmitData = msg->data ().toStdString (); - m_tmitSent = 0; - - GNUNET_PSYC_Environment *env = msg->getPsycEnv (); - m_talk = - GNUNET_SOCIAL_guest_talk (m_guest, msg->method ().toStdString ().c_str (), - env, notifyDataCallback, this, - GNUNET_SOCIAL_TALK_NONE); - GNUNET_PSYC_env_destroy (env); -} - - -void -Guest::talkRequest (QString text) -{ - Message msg ("_converse", QList(), text, 0); - talkRequest (&msg); -} - - -void -Guest::talk (QString text) -{ - emit talkRequestSignal (text); -} diff --git a/src/social/guest.h b/src/social/guest.h deleted file mode 100644 index 6d26864..0000000 --- a/src/social/guest.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef GUEST_H -#define GUEST_H - -#include -#include "place.h" - -class Guest : public Place -{ - - Q_OBJECT; - - public: - - explicit - Guest (GNUNET_SOCIAL_App *app, - GNUNET_SOCIAL_Ego *ego, - const GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - const GNUNET_PeerIdentity *origin, - uint32_t relayCount = 0, - const GNUNET_PeerIdentity *relays = NULL, - const GNUNET_PSYC_Message *entryMsg = NULL, - QObject *parent = NULL); - - explicit - Guest (GNUNET_SOCIAL_App *app, - GNUNET_SOCIAL_Ego *ego, - GNUNET_SOCIAL_GuestConnection *gconn, - QObject *parent = NULL); - - ~Guest (); - - Q_INVOKABLE void - talk (QString text); - - void - talkRequest (Message *msg); - - void - talkRequest (QString text); - - signals: - - void - talkRequestSignal (QString text); - - - private: - - GNUNET_SOCIAL_Guest *m_guest; - - GNUNET_SOCIAL_TalkRequest *m_talk; - - void - connectSignals (); - - static void - recvEntryDecisionCallback (void *cls, int is_admitted, - const struct GNUNET_PSYC_Message - *entry_resp); - - static void - recvLocalEnterCallback (void *cls, int result, - const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - uint64_t max_message_id); -}; - -#endif diff --git a/src/social/host.cpp b/src/social/host.cpp deleted file mode 100644 index 94a8dee..0000000 --- a/src/social/host.cpp +++ /dev/null @@ -1,162 +0,0 @@ -#include "host.h" -#include - -Host::Host (GNUNET_SOCIAL_App *app, - GNUNET_SOCIAL_Ego *ego, - enum GNUNET_PSYC_Policy policy, - QObject *parent) - : Place (parent) -{ - m_app = app; - m_ego = ego; - m_isHost = true; - m_host = - GNUNET_SOCIAL_host_enter (m_app, ego, policy, createSlicer (), - enterCallback, - answerDoorCallback, - farewellCallback, - this); - m_plc = GNUNET_SOCIAL_host_get_place (m_host); - connectSignals (); -} - - -Host::Host (GNUNET_SOCIAL_App *app, - GNUNET_SOCIAL_Ego *ego, - GNUNET_SOCIAL_HostConnection *hconn, - QObject *parent) - : Place (parent) -{ - m_app = app; - m_ego = ego; - m_isHost = true; - m_host = - GNUNET_SOCIAL_host_enter_reconnect (hconn, createSlicer (), - enterCallback, - answerDoorCallback, - farewellCallback, - this); - m_plc = GNUNET_SOCIAL_host_get_place (m_host); - connectSignals (); -} - - -Host::~Host () -{ - GNUNET_SOCIAL_host_disconnect (m_host, NULL, NULL); -} - - -void -Host::connectSignals () -{ - connect (this, SIGNAL (announceSignal (QString)), - this, SLOT (announce (QString)), - Qt::QueuedConnection); -} - - -void -Host::answerDoorCallback (void *cls, struct GNUNET_SOCIAL_Nym *nym, - const char *method_name, - struct GNUNET_PSYC_Environment *env, - const void *data, size_t data_size) -{ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Host received entry request from guest .\n"); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "%s\n%.*s\n", method_name, data_size, data); - - Host *host = (Host *) cls; - emit host->answerDoorSignal (new Message (method_name, env, data, data_size, - 0, nym)); -} - - -void -Host::entryDecision (GNUNET_SOCIAL_Nym *nym, - bool isAdmitted, - Message *response) -{ - GNUNET_PSYC_Message *msg = NULL; - if (NULL != response) - msg = response->toPsyc (); - - GNUNET_SOCIAL_host_entry_decision (m_host, nym, - isAdmitted ? GNUNET_YES : GNUNET_NO, - msg); - if (NULL != msg) - GNUNET_free (msg); -} - - -void -Host::enterCallback (void *cls, int result, - const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - uint64_t max_message_id) -{ - Host *host = (Host *) cls; - host->init (*placePubKey); -} - -void -Host::farewellCallback (void *cls, - const struct GNUNET_SOCIAL_Nym *nym, - struct GNUNET_PSYC_Environment *env) -{ - const struct GNUNET_CRYPTO_EcdsaPublicKey * - nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Nym %s has left the place.\n", - GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key)); -} - - -void -Host::announce (Message *msg) -{ - if (m_inTransmit) - { - // FIXME: queue message - qDebug () << "Host.announce: already in transmit"; - return; - } - - m_inTransmit = true; - m_tmitData = msg->data ().toStdString (); - m_tmitSent = 0; - - GNUNET_PSYC_Environment *env = msg->getPsycEnv (); - m_announce = - GNUNET_SOCIAL_host_announce (m_host, msg->method ().toStdString ().c_str (), - env, notifyDataCallback, this, - GNUNET_SOCIAL_ANNOUNCE_NONE); - GNUNET_PSYC_env_destroy (env); -} - - -void -Host::announce (QString text) -{ - qDebug () << "Host.announce: " << text; - Message msg ("_converse", QList(), text); - announce (&msg); -} - - -void -Host::talk (QString text) -{ - qDebug () << "Host.talk: " << text; - emit announceSignal (text); -} - - -int -Host::zoneAddPlace (QString name) -{ - return - GNUNET_SOCIAL_zone_add_place (m_app, m_ego, name.toStdString().c_str(), NULL, - &m_pubKey, NULL, 0, NULL, - GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MONTHS), - NULL, NULL); -} diff --git a/src/social/host.h b/src/social/host.h deleted file mode 100644 index ced0000..0000000 --- a/src/social/host.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef HOST_H -#define HOST_H - -#include -#include "place.h" -#include "message.h" - - -class Host : public Place -{ - - Q_OBJECT; - - public: - - explicit - Host (GNUNET_SOCIAL_App *app, - GNUNET_SOCIAL_Ego *ego, - enum GNUNET_PSYC_Policy policy, - QObject *parent = NULL); - - explicit - Host (GNUNET_SOCIAL_App *app, - GNUNET_SOCIAL_Ego *ego, - GNUNET_SOCIAL_HostConnection *hconn, - QObject *parent = NULL); - - ~Host (); - - Q_INVOKABLE void - talk (QString text); - - int - zoneAddPlace (QString name); - - public slots: - - void - announce (Message *msg); - - void - announce (QString text); - - signals: - - void - announceSignal (QString text); - - void - answerDoorSignal (Message *msg); - - private: - - GNUNET_SOCIAL_Host *m_host; - GNUNET_SOCIAL_Announcement *m_announce; - - void - connectSignals (); - - void - entryDecision (GNUNET_SOCIAL_Nym *nym, - bool isAdmitted, - Message *response); - - static void - answerDoorCallback (void *cls, struct GNUNET_SOCIAL_Nym *nym, - const char *method_name, - struct GNUNET_PSYC_Environment *env, - const void *data, size_t data_size); - - static void - enterCallback (void *cls, int result, - const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - uint64_t max_message_id); - - static void - farewellCallback (void *cls, - const struct GNUNET_SOCIAL_Nym *nym, - struct GNUNET_PSYC_Environment *env); -}; - -#endif diff --git a/src/social/message.cpp b/src/social/message.cpp deleted file mode 100644 index abc3f9c..0000000 --- a/src/social/message.cpp +++ /dev/null @@ -1,246 +0,0 @@ -#include "message.h" -#include "modifier.h" - - -Message::Message (QString method, - QList env, - QByteArray data, - uint64_t id, - GNUNET_SOCIAL_Nym *nym, - Message *parent) - : QObject (parent) -{ - m_id = id; - m_nym = nym; - m_method = method; - m_env = env; - m_data = data; - m_parent = parent; -} - - -Message::Message (QString method, - QList env, - QString text, - uint64_t id, - GNUNET_SOCIAL_Nym *nym, - Message *parent) - : QObject (parent) -{ - m_id = id; - m_nym = nym; - m_method = method; - m_env = env; - m_data = text.toUtf8 (); - m_parent = parent; -} - - -Message::Message (const char *method, - GNUNET_PSYC_Environment *env, - const void *data, - size_t data_size, - uint64_t id, - GNUNET_SOCIAL_Nym *nym, - Message *parent) - : QObject (parent) -{ - m_id = id; - m_nym = nym; - m_method = QString::fromLatin1 (method); - m_data = QByteArray ((const char *) data, data_size); - m_parent = parent; - - GNUNET_PSYC_env_iterate (env, iterateEnv, this); -} - - -Message::~Message () -{ - // FIXME: delete children? - emit deleted (this); -} - - -/*** PSYC ***/ - - -void -Message::appendModifier (Modifier *mod) -{ - m_env.append (mod); -} - - -QByteArray & -Message::appendData (QByteArray data) -{ - return m_data.append (data); -} - - -QByteArray & -Message::appendData (char *data, size_t data_size) -{ - return m_data.append (data, data_size); -} - - -Modifier * -Message::findModifier (const QString name) -{ - QListIterator it (m_env); - while (it.hasNext ()) - { - Modifier *mod = it.next (); - if (mod->name () == name) - return mod; - } - return 0; -} - - -int -Message::iterateEnv (void *cls, GNUNET_PSYC_Operator oper, - const char *name, const char *value, - uint32_t value_size) -{ - Message *m = (Message *) cls; - m->m_env += new Modifier (oper, - QString (name), - QByteArray (value, value_size)); - return GNUNET_YES; -} - - -GNUNET_PSYC_Message * -Message::toPsyc () -{ - GNUNET_PSYC_Environment *env = getPsycEnv (); - GNUNET_PSYC_Message * - msg = GNUNET_PSYC_message_create (m_method.toLatin1 (), env, - m_data.constData (), m_data.size ()); - GNUNET_PSYC_env_destroy (env); - return msg; -} - - -GNUNET_PSYC_Environment * -Message::getPsycEnv () -{ - GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create (); - QListIterator it (m_env); - while (it.hasNext ()) - { - Modifier *mod = it.next (); - GNUNET_PSYC_env_add (env, mod->oper (), mod->name ().toLatin1 (), - mod->value (), mod->value ().size ()); - } - return env; -} - - -/*** Threads ***/ - - -/** - * Set parent message. - */ -void -Message::setParent (Message *msg) -{ - m_parent = msg; - QObject::setParent (msg); -} - - -/** - * Append @a msg at the end of children list. - */ -void -Message::appendChild (Message *msg) -{ - m_children.append (msg); - msg->setParent (this); - emit childAdded (msg); -} - - -/** - * Get nth child message. - */ -Message * -Message::child (int n) -{ - return m_children.value (n); -} - - -/** - * Get number of children. - */ -int -Message::childrenCount () const -{ - return m_children.count (); -} - - -/** - * Get parent message. - */ -Message * -Message::parent () -{ - return m_parent; -} - - -/** - * Get index of a given child message. - * - * @return Index or -1 if not found. - */ -int -Message::childIndex (Message *msg) const -{ - return m_children.indexOf (msg); -} - - -/** - * Get index of this message in its parent's children list. - * - * @return Position index or -1 if not found. - */ -int -Message::index () const -{ - return (m_parent) - ? m_parent->childIndex (const_cast (this)) - : -1; -} - - -/*** Operators ***/ - - -bool -Message::lessThan (Message &a, Message &b) -{ - return a.id () < b.id (); -} - - -bool -Message::operator< (Message &b) -{ - return id () < b.id (); -} - - -bool -Message::operator== (Message &b) -{ - return id () == b.id (); -} diff --git a/src/social/message.h b/src/social/message.h deleted file mode 100644 index b3735ef..0000000 --- a/src/social/message.h +++ /dev/null @@ -1,215 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include -#include -#include "modifier.h" -#include "gnunet.h" - -class Message : public QObject -{ - - Q_OBJECT; - - Q_PROPERTY (uint64_t id - READ id); - - Q_PROPERTY (QString method - READ method - WRITE setMethod); - - Q_PROPERTY (QString text - READ text - WRITE setText); - - public: - - explicit - Message (QString method, - QList env = QList(), - QByteArray data = "", - uint64_t id = 0, - GNUNET_SOCIAL_Nym *nym = 0, - Message *parent = 0); - - explicit - Message (QString method, - QList env, - QString text, - uint64_t id = 0, - GNUNET_SOCIAL_Nym *nym = 0, - Message *parent = 0); - - explicit - Message (const char *method, - GNUNET_PSYC_Environment *env, - const void *data = 0, - size_t data_size = 0, - uint64_t id = 0, - GNUNET_SOCIAL_Nym *nym = 0, - Message *parent = 0); - - ~Message (); - - /*** PSYC ***/ - - void - appendModifier (Modifier *mod); - - QByteArray & - appendData (QByteArray data); - - QByteArray & - appendData (char *data, size_t data_size); - - Modifier * - findModifier (const QString name); - - GNUNET_PSYC_Message * - toPsyc (); - - GNUNET_PSYC_Environment * - getPsycEnv (); - - - /*** Threads ***/ - - void - setParent (Message *msg); - - void - appendChild (Message *msg); - - Message * - child (int n); - - int - childrenCount () const; - - int - childIndex (Message *msg) const; - - int - index () const; - - Message * - parent (); - - - /*** Operators ***/ - - static bool - lessThan (Message &a, Message &b); - - bool - operator< (Message &b); - - bool - operator== (Message &b); - - - /*** Properties ***/ - - uint64_t - id () const - { - return m_id; - } - - GNUNET_SOCIAL_Nym * - nym () const - { - return m_nym; - } - - void - setNym (GNUNET_SOCIAL_Nym *nym) - { - m_nym = nym; - } - - - QString - method () const - { - return m_method; - } - - void - setMethod (QString method) - { - m_method = method; - } - - - QList - env () const - { - return m_env; - } - - void - setEnv (QList env) - { - m_env = env; - } - - - QByteArray - data () const - { - return m_data; - } - - void - setData (QByteArray data) - { - m_data = data; - } - - - QString - text () const - { - return m_data; - } - - void - setText (QString text) - { - m_data = text.toUtf8 (); - } - - - signals: - - void - modified (Message *msg); - - void - childAdded (Message *msg); - - void - deleted (Message *msg); - - private: - - uint64_t m_id; - GNUNET_SOCIAL_Nym *m_nym; - QString m_method; - QList m_env; - QByteArray m_data; - - QList m_children; - Message *m_parent; - - void *m_ptr; - - static int - iterateEnv (void *cls, GNUNET_PSYC_Operator oper, - const char *name, const char *value, - uint32_t value_size); - -}; - -#endif diff --git a/src/social/modifier.cpp b/src/social/modifier.cpp deleted file mode 100644 index a784db2..0000000 --- a/src/social/modifier.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "modifier.h" - - -Modifier::Modifier (GNUNET_PSYC_Operator oper, QString name, QByteArray value, - QObject *parent) - : QObject (parent) -{ - m_oper = oper; - m_name = name; - m_value = value; -} - - -Modifier::Modifier (GNUNET_PSYC_Operator oper, QString name, QString text, - QObject *parent) - : QObject (parent) -{ - m_oper = oper; - m_name = name; - m_value = text.toUtf8 (); -} diff --git a/src/social/modifier.h b/src/social/modifier.h deleted file mode 100644 index bfcb51c..0000000 --- a/src/social/modifier.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef MODIFIER_H -#define MODIFIER_H - -#include -#include "gnunet.h" - -class Modifier : public QObject -{ - Q_OBJECT; - - Q_PROPERTY (GNUNET_PSYC_Operator oper - READ oper - WRITE setOper); - - Q_PROPERTY (QString name - READ name - WRITE setName); - - Q_PROPERTY (QByteArray value - READ value - WRITE setValue); - - Q_PROPERTY (QString text - READ text - WRITE setText); - - public: - - explicit - Modifier (GNUNET_PSYC_Operator oper, QString name, QByteArray value, QObject *parent = 0); - - explicit - Modifier (GNUNET_PSYC_Operator oper, QString name, QString text, QObject *parent = 0); - - - GNUNET_PSYC_Operator - oper () const - { - return m_oper; - } - - void - setOper (GNUNET_PSYC_Operator oper) - { - m_oper = oper; - } - - - QString - name () const - { - return m_name; - } - - void - setName (QString name) - { - m_name = name; - } - - - QByteArray - value () const - { - return m_value; - } - - void - setValue (QByteArray value) - { - m_value = value; - } - - - QString - text () const - { - return m_value; - } - - void - setText (QString text) - { - m_value = text.toUtf8 (); - } - - - uint64_t - amount () const - { - return m_value.toULongLong (); - } - - void - setAmount (quint64 num) - { - m_value = QByteArray::number (num); - } - - - int64_t - number () const - { - return m_value.toLongLong (); - } - - void - setNumber (qint64 num) - { - m_value = QByteArray::number (num); - } - - - private: - - GNUNET_PSYC_Operator m_oper; - QString m_name; - QByteArray m_value; -}; - -#endif diff --git a/src/social/nym.cpp b/src/social/nym.cpp deleted file mode 100644 index 007b26c..0000000 --- a/src/social/nym.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "ego.h" - -Nym::Nym (GNUNET_CRYPTO_EcdsaPublicKey pubKey, - QString name, - GNUNET_SOCIAL_Nym *nym, - QObject *parent) - : QObject (parent) -{ - setPubKey (pubKey); - setName (name); - setNym (nym); -} diff --git a/src/social/nym.h b/src/social/nym.h deleted file mode 100644 index 9c7b88b..0000000 --- a/src/social/nym.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef NYM_H -#define NYM_H - -#include - -#include "gnunet.h" - -class Nym : public QObject -{ - Q_OBJECT; - Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged); - Q_PROPERTY (QString pubKeyString READ pubKeyString); - Q_PROPERTY (QString gnsUrl READ gnsUrl CONSTANT); - - public: - - explicit - Nym (GNUNET_CRYPTO_EcdsaPublicKey pubKey, - QString name = "", - GNUNET_SOCIAL_Nym *nym = 0, - QObject *parent = 0); - - int - index () const - { - return m_index; - } - - void - setIndex (int index) - { - m_index = index; - } - - - QString - name () - { - return m_name; - } - - void - setName (QString name) - { - m_name = name; - emit nameChanged (name); - emit modified (m_index); - } - - - GNUNET_CRYPTO_EcdsaPublicKey - pubKey () const - { - return m_pubKey; - } - - QString - pubKeyString () - { - return m_pubKeyStr; - } - - void - setPubKey (GNUNET_CRYPTO_EcdsaPublicKey pubKey) - { - m_pubKey = pubKey; - char *pubKeyChr = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pubKey); - m_pubKeyStr = QString::fromLatin1 (pubKeyChr); - GNUNET_free (pubKeyChr); - - if (m_name.isEmpty ()) - { - m_name = m_pubKeyStr.left (8); - } - emit modified (m_index); - } - - QString - gnsUrl () - { - // should GNS appear explicitly in a client app? shouldn't it be - // used transparently behind the gnunet social API instead? - return QString ("gnunet://gns/%1").arg (m_pubKeyStr); - } - - GNUNET_SOCIAL_Nym * - nym () - { - return m_nym; - } - void - setNym (GNUNET_SOCIAL_Nym *nym) - { - m_nym = nym; - } - - protected: - - int m_index; - - QString m_name; - QString m_pubKeyStr; - GNUNET_CRYPTO_EcdsaPublicKey m_pubKey; - GNUNET_SOCIAL_Nym *m_nym; - - signals: - - void modified (int index); - void nameChanged (QString name); - -}; - -#endif diff --git a/src/social/place.cpp b/src/social/place.cpp deleted file mode 100644 index 8b1f4f3..0000000 --- a/src/social/place.cpp +++ /dev/null @@ -1,319 +0,0 @@ -#include "place.h" -#include "model/models.h" -#include "model/PlaceListModel.h" -#include "app.h" - -#include -#include -#include - -/** - * @brief Place::Place, constructor should receive the public key as title - * @param key - * @param parent - */ -Place::Place (QObject *parent) : QObject (parent) -{ - m_type = "group"; //thread;group;contact - m_isHost = false; - m_inTransmit = false; - m_msg = 0; - m_mod = 0; - - #if FIXME - connect (this, &Place::setTrayMessage, - theApp, &App::setTrayMessage, Qt::QueuedConnection); - #endif -} - -void -Place::init (const GNUNET_CRYPTO_EddsaPublicKey pubKey) -{ - char *pubKeyChars = GNUNET_CRYPTO_eddsa_public_key_to_string (&pubKey); - QString pubKeyStr = QString::fromLatin1 (pubKeyChars); - - setPubKey (pubKey); - setName (pubKeyStr); -} - -/** - * Copy public key of place to clipboard. - */ -void -Place::copyToClipboard () -{ - QClipboard *clipboard = QApplication::clipboard (); - - clipboard->setText (m_pubKeyStr); -} - -/** - * Send a message to the place. - * - * @param text - * The message. - */ -void -Place::talk (QString text) -{ -#if FIXME - if (m_isHost) - { - emit hostTalkSignal (this, text); - } - else - { - emit guestTalkSignal (this, text); - } -#endif -} - - -GNUNET_PSYC_Slicer * -Place::createSlicer () -{ - m_slicer = GNUNET_PSYC_slicer_create (); - GNUNET_PSYC_slicer_method_add (m_slicer, "", NULL, - recvMethodCallback, - recvModifierCallback, - recvDataCallback, - recvEomCallback, - this); - return m_slicer; -} - - -void // static -Place::recvMethodCallback (void *cls, - const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_PSYC_MessageMethod *meth, - uint64_t message_id, - const char *method_name) -{ - Place *p = (Place *) cls; - p->recvMethod (msg, meth, message_id, method_name); -} - - -void -Place::recvMethod (const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_PSYC_MessageMethod *meth, - uint64_t message_id, - const char *method_name) -{ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Test #: Host received method for message ID %i:\n" "%s\n", - message_id, method_name); - if (m_msg) - delete m_msg; - m_msg = new Message (method_name); - m_mod = 0; -} - - -void // static -Place::recvModifierCallback (void *cls, - const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - enum GNUNET_PSYC_Operator oper, - const char *name, - const void *value, - uint16_t value_size, - uint16_t full_value_size) -{ - Place *p = (Place *) cls; - p->recvModifier (msg, pmsg, message_id, oper, name, - value, value_size, full_value_size); -} - - -void -Place::recvModifier (const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - enum GNUNET_PSYC_Operator oper, - const char *name, - const void *value, - uint16_t value_size, - uint16_t full_value_size) -{ - QString str = QString::fromLatin1 ((char *) value); - - qWarning () << "Host received modifier for message ID" - << message_id << oper << name << value_size << str; - Q_ASSERT (m_msg); - - if (!m_mod) - { - m_mod = new Modifier (oper, - QString (name), - QByteArray ((const char *) value, value_size)); - } - else - { - m_mod->value ().append ((const char *) value, value_size); - } - - if (m_mod->value ().size () == full_value_size) - { - m_msg->appendModifier (m_mod); - m_mod = 0; - } -} - - -void // static -Place::recvDataCallback (void *cls, - const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - const void *data, - uint16_t data_size) -{ - Place *p = (Place *) cls; - p->recvData (msg, pmsg, message_id, data, data_size); -} - - -void -Place::recvData (const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - const void *data, - uint16_t data_size) -{ - QString str = QString::fromLatin1 ((char *) data); - qWarning () << "Host received data for message ID " - << message_id << data_size << str; - - Q_ASSERT (m_msg); - m_msg->appendData ((char *) data, data_size); -} - - -void // static -Place::recvEomCallback (void *cls, - const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - uint8_t is_cancelled) -{ - Place *p = (Place *) cls; - p->recvEom (msg, pmsg, message_id, is_cancelled); -} - - -void -Place::recvEom (const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - uint8_t is_cancelled) -{ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Test #: Host received end of message ID %i, cancelled: %u\n", - message_id, is_cancelled); - Q_ASSERT (m_msg); - - if (GNUNET_NO == is_cancelled) - insertMessage (m_msg); - m_msg = 0; -} - - -/** - * Insert message to its place in the thread. - */ -void -Place::insertMessage (Message *msg) -{ - m_msgHash.insert (msg->id (), msg); - - // Find thread - - bool newThread = false; - uint64_t threadId = 0; - Modifier *mod = msg->findModifier ("_id_thread"); - if (mod) - threadId = mod->amount (); - - Message *thread = m_threadHash.value (threadId); - if (!thread) - { - if (msg->id () == threadId) - { - thread = msg; - } - else // missing thread starter message, or message not in thread - { - // Create a placeholder message that will be replaced - // when the missing message arrives (or not if it's not in a thread). - thread = new Message ("_INTERNAL_missing"); - // methods or variables of the _INTERNAL family must never be sent - // over the wire! history replay must ensure that. -lynX - - if (0 < threadId) - { - /// @todo request missing message(s) in thread from history - //FIXME: GNUNET_SOCIAL_history_replay_thread (m_plc, threadId, ...); - } - } - - m_threads += thread; - m_threadHash.insert (threadId, thread); - newThread = true; - } - - // Find parent message - - Message *parent = 0; - uint64_t parentId = 0; - mod = msg->findModifier ("_id_reply"); - if (mod) - parentId = mod->amount (); - - if (0 < parentId) - parent = m_msgHash.value (parentId); - - if (!parent && thread != msg) - parent = thread; - - if (parent) - parent->appendChild (msg); - - emit messageReceived (msg, parent, thread); - - if (newThread) - { - emit threadAdded (msg); - } -} - - -int -Place::notifyDataCallback (void *cls, uint16_t *data_size, void *data) -{ - Place *p = (Place *) cls; - return p->notifyData (data_size, data); -} - - -int -Place::notifyData (uint16_t *data_size, void *data) -{ - qDebug () << "Place: data_sent=" << m_tmitSent << ", " - << "data_size=" << *data_size; - - std::string sub = m_tmitData.substr (m_tmitSent, *data_size); - *data_size = sub.size (); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data_size: %u\n", *data_size); - memcpy (data, sub.c_str (), *data_size); - m_tmitSent += *data_size; - - if (m_tmitSent < m_tmitData.size ()) - return GNUNET_NO; - - m_inTransmit = false; - emit dataSent (); - return GNUNET_YES; -} diff --git a/src/social/place.h b/src/social/place.h deleted file mode 100644 index c5445be..0000000 --- a/src/social/place.h +++ /dev/null @@ -1,251 +0,0 @@ -#ifndef PLACE_H -#define PLACE_H - -#include -#include "message.h" -#include "gnunet.h" - - -class Place : public QObject -{ - - Q_OBJECT; - Q_PROPERTY (QString pubkey READ pubKeyString NOTIFY pubKeyStringChanged); - Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged); - Q_PROPERTY (QString desc READ desc WRITE setDesc NOTIFY descChanged); - - public: - - explicit Place (QObject *parent = 0); - - //Index - int index () const - { - return m_index; - } - void setIndex (int index) - { - m_index = index; - } - - //Name - QString name () const - { - return m_name; - } - void setName (QString name) - { - m_name = name; - emit nameChanged (name); - emit modified (this); - } - - // Desc - QString desc () const - { - return m_desc; - } - void setDesc (QString desc) - { - m_desc = desc; - emit descChanged (desc); - emit modified (this); - } - - //Type - QString type () const - { - return m_type; - } - void setType (QString type) - { - m_type = type; - emit typeChanged (type); - emit modified (this); - } - - //Is Host ? - bool isHost () const - { - return m_isHost; - } - - //Public Key - GNUNET_CRYPTO_EddsaPublicKey pubKey () const - { - return m_pubKey; - } - - QString pubKeyString () const - { - return m_pubKeyStr; - } - - void setPubKey (GNUNET_CRYPTO_EddsaPublicKey pubKey) - { - m_pubKey = pubKey; - char *pubKeyChr = GNUNET_CRYPTO_eddsa_public_key_to_string (&pubKey); - m_pubKeyStr = QString::fromLatin1 (pubKeyChr); - GNUNET_free (pubKeyChr); - emit pubKeyStringChanged (m_pubKeyStr); - emit modified (this); - } - - const QList & - threads () - { - return m_threads; - } - - Q_INVOKABLE void - copyToClipboard (); - - Q_INVOKABLE void - talk (QString text); - - protected: - - int m_index; - - QString m_name; - - QString m_desc; - - QString m_type; // FIXME - - /// Message currently being received. - Message *m_msg; - - /// Modifier currently being received. - Modifier *m_mod; - - /// List of top-level, thread-starting messages. - QList m_threads; - - /// _thread_id -> thread starter Message - QHash m_threadHash; - - /// _message_id -> Message - QHash m_msgHash; - - QString m_pubKeyStr; - - GNUNET_CRYPTO_EddsaPublicKey m_pubKey; - - bool m_isHost; - - GNUNET_SOCIAL_App *m_app; - GNUNET_SOCIAL_Ego *m_ego; - GNUNET_SOCIAL_Place *m_plc; - GNUNET_PSYC_Slicer *m_slicer; - - bool m_inTransmit; - std::string m_tmitData; - size_t m_tmitSent; - - void - init (GNUNET_CRYPTO_EddsaPublicKey pubKey); - - GNUNET_PSYC_Slicer * - createSlicer (); - - static int - notifyDataCallback (void *cls, uint16_t *data_size, void *data); - - int - notifyData (uint16_t *data_size, void *data); - - void - insertMessage (Message *msg); - - static void - recvMethodCallback (void *cls, - const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_PSYC_MessageMethod *meth, - uint64_t message_id, - const char *method_name); - - void - recvMethod (const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_PSYC_MessageMethod *meth, - uint64_t message_id, - const char *method_name); - - static void - recvModifierCallback (void *cls, - const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - enum GNUNET_PSYC_Operator oper, - const char *name, const void *value, - uint16_t value_size, - uint16_t full_value_size); - - void - recvModifier (const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - enum GNUNET_PSYC_Operator oper, - const char *name, - const void *value, - uint16_t value_size, - uint16_t full_value_size); - - - static void - recvDataCallback (void *cls, - const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - const void *data, - uint16_t data_size); - - void - recvData (const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - const void *data, - uint16_t data_size); - - static void - recvEomCallback (void *cls, - const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - uint8_t is_cancelled); - - void - recvEom (const struct GNUNET_PSYC_MessageHeader *msg, - const struct GNUNET_MessageHeader *pmsg, - uint64_t message_id, - uint8_t is_cancelled); - - signals: - - void modified (Place *place); - - void pubKeyStringChanged (QString pubKeyString); - - void nameChanged (QString name); - - void descChanged (QString desc); - - void typeChanged (QString type); - - void dataSent (); - - void messageReceived (Message *msg, Message *parent, Message *thread); - - void threadAdded (Message *msg); - -#if FIXME - void talkSignal (QString text); - - void setTrayMessage (QString place, QString text); -#endif - -public slots: - -}; - -#endif diff --git a/src/social/socialapp.cpp b/src/social/socialapp.cpp deleted file mode 100644 index e739574..0000000 --- a/src/social/socialapp.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "socialapp.h" -#include "app.h" - -#include "host.h" -#include "guest.h" - - -SocialApp::SocialApp (struct GNUNET_CONFIGURATION_Handle *config, - QObject *parent) - : QObject (parent) -{ - m_config = config; - m_app = - GNUNET_SOCIAL_app_connect (m_config, APP_NAME, - egoCallback, - hostPlaceCallback, - guestPlaceCallback, - this); -} - - -SocialApp::~SocialApp () -{ - GNUNET_SOCIAL_app_disconnect (m_app); -} - - -void -SocialApp::egoCallback (void *cls, - struct GNUNET_SOCIAL_Ego *ego, - const struct GNUNET_CRYPTO_EcdsaPublicKey *egoPubKey, - const char *name) -{ - SocialApp *s = (SocialApp *) cls; - s->addEgo (new Ego (*egoPubKey, QString::fromLatin1 (name), ego)); -} - - -void -SocialApp::addEgo (Ego *ego) -{ - m_egos += ego; - emit egoAdded (ego); -} - -void -SocialApp::addPlace (Place *place) -{ - m_places += place; - place->setIndex (m_places.count () - 1); - emit placeAdded (place); -} - -void -SocialApp::hostPlaceCallback (void *cls, - struct GNUNET_SOCIAL_HostConnection *hconn, - struct GNUNET_SOCIAL_Ego *ego, - const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - enum GNUNET_SOCIAL_AppPlaceState placeState) -{ - SocialApp *s = (SocialApp *) cls; - s->addPlace (new Host (s->m_app, ego, hconn, s)); -} - - -void -SocialApp::guestPlaceCallback (void *cls, - struct GNUNET_SOCIAL_GuestConnection *gconn, - struct GNUNET_SOCIAL_Ego *ego, - const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - enum GNUNET_SOCIAL_AppPlaceState placeState) -{ - SocialApp *s = (SocialApp *) cls; - s->addPlace (new Guest (s->m_app, ego, gconn, s)); -} - - -Ego * -SocialApp::findEgo (const QString pubKeyStr) -{ - QListIterator it (m_egos); - while (it.hasNext ()) - { - Ego *ego = it.next (); - if (ego->pubKeyString () == pubKeyStr) - return ego; - } - return 0; -} - - -void -SocialApp::createPlace (GNUNET_SOCIAL_Ego *ego) -{ - addPlace (new Host (m_app, ego, GNUNET_PSYC_CHANNEL_PRIVATE, this)); -} - - -void -SocialApp::createPlaceSlot (QString egoPubKeyStr) -{ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n"); - - Ego *ego = findEgo (egoPubKeyStr); - if (!ego) // FIXME: fall back to last added ego for now - { - Q_ASSERT (!m_egos.isEmpty ()); - ego = m_egos.last (); - } - - createPlace (ego->ego ()); -} - - -void -SocialApp::enterPlace (GNUNET_SOCIAL_Ego *ego, - GNUNET_CRYPTO_EddsaPublicKey *pubKey, - GNUNET_PeerIdentity *peerId) -{ - addPlace (new Guest (m_app, ego, pubKey, peerId, 0, NULL, NULL, this)); -} - - -void -SocialApp::enterPlaceSlot (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr) -{ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering place %s as guest.\n", - pubKeyStr.toStdString ().c_str ()); - - GNUNET_CRYPTO_EddsaPublicKey pubKey; - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_public_key_from_string (pubKeyStr.toStdString ().c_str (), - pubKeyStr.length (), - &pubKey)) - return; // Failed conversion - - GNUNET_PeerIdentity peerId; - if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peerIdStr.toStdString ().c_str (), - peerIdStr.length (), - &peerId.public_key)) - return; // Failed conversion - - Ego *ego = findEgo (egoPubKeyStr); - if (!ego) // FIXME: fall back to last added ego for now - { - Q_ASSERT (!m_egos.isEmpty ()); - ego = m_egos.last (); - } - - enterPlace (ego->ego (), &pubKey, &peerId); -} diff --git a/src/social/socialapp.h b/src/social/socialapp.h deleted file mode 100644 index 36b4ee4..0000000 --- a/src/social/socialapp.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef SOCIAL_APP_H -#define SOCIAL_APP_H - -#include -#include - -#include "ego.h" -#include "place.h" -#include "gnunet.h" - -class SocialApp : public QObject -{ - Q_OBJECT; - - public: - - explicit SocialApp (GNUNET_CONFIGURATION_Handle * config, - QObject *parent = 0); - ~SocialApp (); - - Ego * - findEgo (const QString pubKeyStr); - - void - createPlace (GNUNET_SOCIAL_Ego *ego); - - void - enterPlace (GNUNET_SOCIAL_Ego *ego, - GNUNET_CRYPTO_EddsaPublicKey *pubKey, - GNUNET_PeerIdentity *peerId); - - const QList & - egos () - { - return m_egos; - } - - const QList & - places () - { - return m_places; - } - - signals: - - void - egoAdded (Ego *ego); - - void - placeAdded (Place *place); - - public slots: - - void - createPlaceSlot (QString egoPubKeyStr); - - void - enterPlaceSlot (QString egoPubKeyStr, QString pubKeyStr, QString peerIdStr); - - private: - - GNUNET_SOCIAL_App *m_app; - QList m_egos; - QList m_places; - GNUNET_CONFIGURATION_Handle *m_config; - - static void - egoCallback (void *cls, - struct GNUNET_SOCIAL_Ego *ego, - const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key, - const char *name); - - void - addEgo (Ego *ego); - - void - addPlace (Place *place); - - static void - hostPlaceCallback (void *cls, - struct GNUNET_SOCIAL_HostConnection *hconn, - struct GNUNET_SOCIAL_Ego *ego, - const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - enum GNUNET_SOCIAL_AppPlaceState placeState); - - static void - guestPlaceCallback (void *cls, - struct GNUNET_SOCIAL_GuestConnection *gconn, - struct GNUNET_SOCIAL_Ego *ego, - const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey, - enum GNUNET_SOCIAL_AppPlaceState placeState); - -}; - -#endif diff --git a/src/util/qrimageprovider.h b/src/util/qrimageprovider.h index 10ffdc4..531a465 100644 --- a/src/util/qrimageprovider.h +++ b/src/util/qrimageprovider.h @@ -2,7 +2,7 @@ #define QRIMAGEPROVIDER_H #include -#include "social/nym.h" +#include "gnunet/social/nym.h" class QrImageProvider : public QQuickImageProvider -- cgit v1.2.3