[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r36673 - in gnunet-qt/secushare: core/identity core/social
From: |
gnunet |
Subject: |
[GNUnet-SVN] r36673 - in gnunet-qt/secushare: core/identity core/social models |
Date: |
Wed, 18 Nov 2015 23:15:54 +0100 |
Author: tg
Date: 2015-11-18 23:15:53 +0100 (Wed, 18 Nov 2015)
New Revision: 36673
Modified:
gnunet-qt/secushare/core/identity/identity.h
gnunet-qt/secushare/core/social/place.h
gnunet-qt/secushare/core/social/socialservice.cpp
gnunet-qt/secushare/core/social/socialservice.h
gnunet-qt/secushare/models/PlacesModel.cpp
Log:
use place listener API to enter places after startup
Modified: gnunet-qt/secushare/core/identity/identity.h
===================================================================
--- gnunet-qt/secushare/core/identity/identity.h 2015-11-18 22:13:27 UTC
(rev 36672)
+++ gnunet-qt/secushare/core/identity/identity.h 2015-11-18 22:15:53 UTC
(rev 36673)
@@ -44,7 +44,7 @@
QString url ()
{
- return QString ("GNUNET://GNS/%1/").arg (m_key);
+ return QString ("gnunet://gns/%1/").arg (m_key);
}
GNUNET_IDENTITY_Ego *ego ()
Modified: gnunet-qt/secushare/core/social/place.h
===================================================================
--- gnunet-qt/secushare/core/social/place.h 2015-11-18 22:13:27 UTC (rev
36672)
+++ gnunet-qt/secushare/core/social/place.h 2015-11-18 22:15:53 UTC (rev
36673)
@@ -108,22 +108,22 @@
}
//Private Key
- struct GNUNET_CRYPTO_EddsaPrivateKey *privateKey () const
+ const struct GNUNET_CRYPTO_EddsaPrivateKey *privateKey () const
{
return m_placeKey;
}
- void setPrivateKey (struct GNUNET_CRYPTO_EddsaPrivateKey *key)
+ void setPrivateKey (const struct GNUNET_CRYPTO_EddsaPrivateKey *key)
{
m_placeKey = key;
}
//Public Key
- struct GNUNET_CRYPTO_EddsaPublicKey *publicKey () const
+ const struct GNUNET_CRYPTO_EddsaPublicKey *publicKey () const
{
return m_placePubKey;
}
- void setPublicKey (struct GNUNET_CRYPTO_EddsaPublicKey *key)
+ void setPublicKey (const struct GNUNET_CRYPTO_EddsaPublicKey *key)
{
m_placePubKey = key;
}
@@ -146,7 +146,7 @@
QString m_content;
- struct GNUNET_CRYPTO_EddsaPrivateKey *m_placeKey;
+ const struct GNUNET_CRYPTO_EddsaPrivateKey *m_placeKey;
QString m_key;
@@ -161,7 +161,7 @@
struct GNUNET_SOCIAL_Host *m_hst;
- struct GNUNET_CRYPTO_EddsaPublicKey *m_placePubKey;
+ const struct GNUNET_CRYPTO_EddsaPublicKey *m_placePubKey;
//The peer got his inscrition approved ?
bool m_approved;
Modified: gnunet-qt/secushare/core/social/socialservice.cpp
===================================================================
--- gnunet-qt/secushare/core/social/socialservice.cpp 2015-11-18 22:13:27 UTC
(rev 36672)
+++ gnunet-qt/secushare/core/social/socialservice.cpp 2015-11-18 22:15:53 UTC
(rev 36673)
@@ -41,71 +41,108 @@
m_hostEgo = id->ego ();
- //Load rooms
- theApp->models ()->placesModel ()->load ();
+ GNUNET_SOCIAL_place_listen_start (config, m_hostEgo,
+ placeNotifyHostCallback,
+ placeNotifyGuestCallback,
+ this);
}
void
-SocialService::createPlace (QString name)
+SocialService::placeNotifyHostCallback (void *cls,
+ const struct
GNUNET_CRYPTO_EddsaPrivateKey *placeKey,
+ enum GNUNET_PSYC_Policy policy)
{
- emit createPlaceSignal (name);
+ SocialService *s = (SocialService *) cls;
+ s->hostEnterPlace (placeKey, policy);
}
+
void
-SocialService::createPlaceSlot (QString name)
+SocialService::placeNotifyGuestCallback (void *cls,
+ const struct
GNUNET_CRYPTO_EddsaPublicKey *placePubKey,
+ const struct GNUNET_PeerIdentity
*origin,
+ uint32_t relayCount,
+ const struct GNUNET_PeerIdentity
*relays,
+ const struct GNUNET_PSYC_Message
*entryMsg)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n");
+ SocialService *s = (SocialService *) cls;
+ s->guestEnterPlace (placePubKey, origin, relayCount, relays, entryMsg);
+}
- QString filename = thePrefs->getFolder () + "/places/" + name + ".private";
- GNUNET_CRYPTO_EddsaPrivateKey *placeKey =
- GNUNET_CRYPTO_eddsa_key_create_from_file (filename.toStdString ().
- c_str ());
+GNUNET_SOCIAL_Host *
+SocialService::hostEnterPlace (const GNUNET_CRYPTO_EddsaPrivateKey *placeKey,
+ enum GNUNET_PSYC_Policy policy)
+{
GNUNET_CRYPTO_EddsaPublicKey *placePubKey = new GNUNET_CRYPTO_EddsaPublicKey;
-
GNUNET_CRYPTO_eddsa_key_get_public (placeKey, placePubKey);
- char *id = GNUNET_CRYPTO_eddsa_public_key_to_string (placePubKey);
- QString strId = QString::fromLatin1 (id);
- Place *newPlace = theApp->models ()->placesModel ()->add (strId);
+ char *placePubKeyChars = GNUNET_CRYPTO_eddsa_public_key_to_string
(placePubKey);
+ QString placePubKeyStr = QString::fromLatin1 (placePubKeyChars);
- newPlace->setName (name);
+ Place *newPlace = theApp->models ()->placesModel ()->add (placePubKeyStr);
+
+ newPlace->setName (placePubKeyStr);
newPlace->setPrivateKey (placeKey);
newPlace->setPublicKey (placePubKey);
GNUNET_SOCIAL_Slicer *slicer = GNUNET_SOCIAL_slicer_create ();
-
- GNUNET_SOCIAL_slicer_method_add (slicer, "", &hostRecvMethodCallback,
- &hostRecvModifierCallback,
- &hostRecvDataCallback, &hostRecvEomCallback,
+ GNUNET_SOCIAL_slicer_method_add (slicer, "",
+ hostRecvMethodCallback,
+ hostRecvModifierCallback,
+ hostRecvDataCallback,
+ hostRecvEomCallback,
newPlace);
newPlace->setSlicer (slicer);
GNUNET_SOCIAL_Host *host =
GNUNET_SOCIAL_host_enter (m_config, m_hostEgo, placeKey,
- GNUNET_PSYC_CHANNEL_PRIVATE,
- slicer,
- &hostEnteredCallback,
- &hostAnswerDoorCallback,
- &hostFarewellCallback,
+ policy, slicer,
+ hostEnteredCallback,
+ hostAnswerDoorCallback,
+ hostFarewellCallback,
newPlace);
newPlace->setHost (host);
-
connect (newPlace, &Place::hostTalkSignal, this, &SocialService::hostTalk,
Qt::QueuedConnection);
+}
- //Save hosts
- theApp->models ()->placesModel ()->save ();
+void
+SocialService::createPlaceSlot (QString name)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n");
+
+ GNUNET_CRYPTO_EddsaPrivateKey *placeKey = GNUNET_CRYPTO_eddsa_key_create ();
+ GNUNET_SOCIAL_Host *
+ host = hostEnterPlace (placeKey, GNUNET_PSYC_CHANNEL_PRIVATE);
+
+ if (0 < name.length ())
+ {
+ GNUNET_CRYPTO_EddsaPublicKey *placePubKey = new
GNUNET_CRYPTO_EddsaPublicKey;
+ GNUNET_CRYPTO_eddsa_key_get_public (placeKey, placePubKey);
+
+ GNUNET_SOCIAL_host_advertise (host, name.toStdString ().c_str (),
+ 0, NULL,
+ GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_MONTHS),
+ NULL, NULL, NULL);
+ }
}
void
+SocialService::createPlace (QString name)
+{
+ emit createPlaceSignal (name);
+}
+
+
+void
SocialService::hostRecvMethodCallback (void *cls,
- const struct GNUNET_PSYC_MessageMethod
- *meth, uint64_t message_id,
+ const struct GNUNET_PSYC_MessageMethod
*meth,
+ uint64_t message_id,
uint32_t flags,
const struct GNUNET_SOCIAL_Nym *nym,
const char *method_name)
@@ -113,7 +150,6 @@
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Test #: Host received method for message ID %i:\n" "%s\n",
message_id, method_name);
- /* FIXME: check message */
}
@@ -126,17 +162,10 @@
uint16_t value_size,
uint16_t full_value_size)
{
- /* GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- * "Test #: Host received modifier for message ID %i:\n"
- * "%i %s: %i %s\n",
- * message_id, oper, name, value_size, value);
- */
-
-
QString str = QString::fromLatin1 ((char *) value);
- qWarning () << "Host received modifier for message ID" << message_id << oper
- << name << value_size << str;
+ qWarning () << "Host received modifier for message ID"
+ << message_id << oper << name << value_size << str;
}
@@ -146,11 +175,6 @@
uint64_t message_id, uint64_t data_offset,
const void *data, uint16_t data_size)
{
- /*GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- * "Test #: Host received data for message ID %i:\n"
- * "%.*s\n",
- * message_id, data_size, data); */
-
QString str = QString::fromLatin1 ((char *) data);
Place *place = (Place *) cls;
@@ -170,25 +194,6 @@
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Test #: Host received end of message ID %i, cancelled: %u\n",
message_id, cancelled);
- /*
- * switch (test)
- * {
- * case TEST_HOST_ANNOUNCE:
- * test = TEST_HOST_ANNOUNCE_END;
- * //host_announce2 ();
- * break;
- *
- * case TEST_HOST_ANNOUNCE_END:
- * guest_talk ();
- * break;
- *
- * case TEST_GUEST_TALK:
- * guest_leave ();
- * break;
- *
- * default:
- * GNUNET_assert (0);
- * } */
}
@@ -230,27 +235,6 @@
GNUNET_SOCIAL_host_entry_decision (place->host (), nym, GNUNET_YES,
join_resp);
-
- /*
- * switch (test)
- * {
- * case TEST_HOST_ANSWER_DOOR_REFUSE:
- * test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
- * join_resp = GNUNET_PSYC_message_create ("_refuse_nym", env,
- * DATA2ARG ("Go away!"));
- * GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
- * break;
- *
- * case TEST_HOST_ANSWER_DOOR_ADMIT:
- * test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
- * join_resp = GNUNET_PSYC_message_create ("_admit_nym", env,
- * DATA2ARG ("Welcome, nym!"));
- * GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
- * break;
- *
- * default:
- * GNUNET_assert (0);
- * } */
}
@@ -274,11 +258,6 @@
GNUNET_SOCIAL_nym_get_key (nym);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Nym %s has left the place.\n",
GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key));
-
- /*
- * GNUNET_assert (0 == memcmp (&guest_pub_key, nym_key, sizeof (*nym_key)));
- *
- * GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL); */
}
@@ -298,11 +277,9 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Guest entered to local place, result : %i.\n", result);
+}
-
-}
-
void
SocialService::guestRecvEntryDecisionCallback (void *cls, int is_admitted,
const struct GNUNET_PSYC_Message
@@ -328,43 +305,52 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n%.*s\n", method_name, data_size,
data);
GNUNET_free (pmsg);
- /* FIXME: check response message */
}
-
- /*
- * switch (test)
- * {
- * case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
- * GNUNET_assert (GNUNET_NO == is_admitted);
- * guest_enter ();
- * break;
- *
- * case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
- * GNUNET_assert (GNUNET_YES == is_admitted);
- * host_announce ();
- * break;
- *
- * default:
- * GNUNET_assert (0);
- * } */
}
+GNUNET_SOCIAL_Guest *
+SocialService::guestEnterPlace (const GNUNET_CRYPTO_EddsaPublicKey
*placePubKey,
+ const GNUNET_PeerIdentity *origin,
+ uint32_t relayCount,
+ const GNUNET_PeerIdentity *relays,
+ const GNUNET_PSYC_Message *entryMsg)
+{
+ char *placePubKeyChars = GNUNET_CRYPTO_eddsa_public_key_to_string
(placePubKey);
+ QString placePubKeyStr = QString::fromLatin1 (placePubKeyChars);
-void
-SocialService::enterRoom (QString pubKey, QString peerIdentity)
-{
- emit enterRoomSignal (pubKey, peerIdentity);
+ Place *newPlace = theApp->models ()->placesModel ()->add (placePubKeyStr);
+ newPlace->setName (placePubKeyStr);
+ newPlace->setPublicKey (placePubKey);
+
+ GNUNET_SOCIAL_Slicer *slicer = GNUNET_SOCIAL_slicer_create ();
+
+ GNUNET_SOCIAL_slicer_method_add (slicer, "", &hostRecvMethodCallback,
+ &hostRecvModifierCallback,
+ &hostRecvDataCallback, &hostRecvEomCallback,
+ newPlace);
+ newPlace->setSlicer (slicer);
+
+ //TODO change place pub key to arbitrary value
+ GNUNET_SOCIAL_Guest *gst =
+ GNUNET_SOCIAL_guest_enter (m_config, m_hostEgo, placePubKey,
+ origin, 0, NULL, entryMsg,
+ slicer, &guestRecvLocalEnterCallback,
+ &guestRecvEntryDecisionCallback, newPlace);
+ newPlace->setSocialGuest (gst);
+
+ connect (newPlace, &Place::guestTalkSignal, this, &SocialService::guestTalk,
+ Qt::QueuedConnection);
}
+
void
-SocialService::enterRoomSlot (QString pubKey, QString peerIdentity)
+SocialService::enterRoomSlot (QString pubKeyStr, QString peerIdentity)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place %s as guest.\n",
- pubKey.toStdString ().c_str ());
+ pubKeyStr.toStdString ().c_str ());
GuestEnterMessage emsg;
-
emsg.method_name = "_request_enter";
emsg.env = GNUNET_ENV_environment_create ();
GNUNET_ENV_environment_add (emsg.env, GNUNET_ENV_OP_ASSIGN, "_abc", "abc
def",
@@ -373,56 +359,28 @@
"abc def ghi", 11);
emsg.data = "let me in";
emsg.data_size = strlen (emsg.data) + 1;
- emsg.msg =
- GNUNET_PSYC_message_create (emsg.method_name, emsg.env, emsg.data,
- emsg.data_size);
+ emsg.msg = GNUNET_PSYC_message_create (emsg.method_name, emsg.env,
+ emsg.data, emsg.data_size);
- GNUNET_CRYPTO_EddsaPublicKey *convertedRoomKey =
- new GNUNET_CRYPTO_EddsaPublicKey;
+ GNUNET_CRYPTO_EddsaPublicKey *pubKey = new GNUNET_CRYPTO_EddsaPublicKey;
- int result =
- GNUNET_CRYPTO_eddsa_public_key_from_string (pubKey.toStdString ().
- c_str (),
- pubKey.length (),
- convertedRoomKey);
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (pubKeyStr.toStdString
().c_str (),
+ pubKeyStr.length (),
+ pubKey))
+ return; // Failed conversion
+ guestEnterPlace (pubKey, theApp->gnunet ()->myPeer (), 0, NULL, emsg.msg);
+}
- if (result != GNUNET_OK) // Failed conversion
- return;
+void
+SocialService::enterRoom (QString pubKey, QString peerIdentity)
+{
+ emit enterRoomSignal (pubKey, peerIdentity);
+}
- Place *newPlace = theApp->models ()->placesModel ()->add (pubKey);
- newPlace->setName (pubKey);
- newPlace->setPublicKey (convertedRoomKey);
- GNUNET_SOCIAL_Slicer *slicer = GNUNET_SOCIAL_slicer_create ();
-
- GNUNET_SOCIAL_slicer_method_add (slicer, "", &hostRecvMethodCallback,
- &hostRecvModifierCallback,
- &hostRecvDataCallback, &hostRecvEomCallback,
- newPlace);
-
- newPlace->setSlicer (slicer);
-
-
- //TODO change place pub key to arbitrary value
- GNUNET_SOCIAL_Guest *gst =
- GNUNET_SOCIAL_guest_enter (m_config, m_hostEgo, convertedRoomKey,
- theApp->gnunet ()->myPeer (), 0, NULL,
- emsg.msg,
- slicer, &guestRecvLocalEnterCallback,
- &guestRecvEntryDecisionCallback, newPlace);
-
- newPlace->setSocialGuest (gst);
-
- connect (newPlace, &Place::guestTalkSignal, this, &SocialService::guestTalk,
- Qt::QueuedConnection);
-
-
-
-
-}
-
static void
transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
Modified: gnunet-qt/secushare/core/social/socialservice.h
===================================================================
--- gnunet-qt/secushare/core/social/socialservice.h 2015-11-18 22:13:27 UTC
(rev 36672)
+++ gnunet-qt/secushare/core/social/socialservice.h 2015-11-18 22:15:53 UTC
(rev 36673)
@@ -25,6 +25,7 @@
} TransmitClosure;
class Place;
+class PlaceListener;
class SocialService:public QObject
{
@@ -31,6 +32,24 @@
Q_OBJECT public:
explicit SocialService (QObject * parent = 0);
+ static void
+ placeNotifyHostCallback (void *cls,
+ const struct GNUNET_CRYPTO_EddsaPrivateKey
*place_key,
+ enum GNUNET_PSYC_Policy policy);
+
+ static void
+ placeNotifyGuestCallback (void *cls,
+ const struct GNUNET_CRYPTO_EddsaPublicKey
*place_key,
+ const struct GNUNET_PeerIdentity *origin,
+ uint32_t relay_count,
+ const struct GNUNET_PeerIdentity *relays,
+ const struct GNUNET_PSYC_Message *entry_msg);
+
+
+ GNUNET_SOCIAL_Host *
+ hostEnterPlace (const GNUNET_CRYPTO_EddsaPrivateKey *placeKey,
+ enum GNUNET_PSYC_Policy policy);
+
static void hostRecvMethodCallback (void *cls,
const struct GNUNET_PSYC_MessageMethod
*meth, uint64_t message_id,
@@ -68,6 +87,14 @@
struct GNUNET_ENV_Environment *env);
+ GNUNET_SOCIAL_Guest *
+ guestEnterPlace (const GNUNET_CRYPTO_EddsaPublicKey *placePubKey,
+ const GNUNET_PeerIdentity *origin,
+ uint32_t relay_count,
+ const GNUNET_PeerIdentity *relays,
+ const GNUNET_PSYC_Message *entry_msg);
+
+
static void guestRecvEntryDecisionCallback (void *cls, int is_admitted,
const struct GNUNET_PSYC_Message
*entry_resp);
Modified: gnunet-qt/secushare/models/PlacesModel.cpp
===================================================================
--- gnunet-qt/secushare/models/PlacesModel.cpp 2015-11-18 22:13:27 UTC (rev
36672)
+++ gnunet-qt/secushare/models/PlacesModel.cpp 2015-11-18 22:15:53 UTC (rev
36673)
@@ -49,70 +49,6 @@
}
-/**
- * @brief PlacesModel::save, will save the list of places
- */
-void
-PlacesModel::save ()
-{
- QString filename = thePrefs->getFolder () + "/rooms.keys";
-
- QFile file (filename);
-
- if (!file.open (QIODevice::WriteOnly))
- {
- qDebug () << "Could not open " << filename;
- return;
- }
-
- QDataStream out (&file);
-
- //out.setVersion(QDataStream::Qt_5_1);
-
-
- foreach (Place * place, m_data)
- {
- out << place->name ();
- out << place->isHost ();
- }
-}
-
-
-void
-PlacesModel::load ()
-{
- QString filename = thePrefs->getFolder () + "/rooms.keys";
-
- QFile file (filename);
-
- if (!file.open (QIODevice::ReadOnly))
- {
- qDebug () << "Could not open " << filename;
- return;
- }
-
- QDataStream in (&file);
-
- //out.setVersion(QDataStream::Qt_5_1);
-
-
- while (!in.atEnd ())
- {
- QString publicKey;
-
- bool isHost;
-
- in >> publicKey >> isHost;
-
-
- qWarning () << publicKey << " Is host:" << isHost;
-
- theApp->gnunet ()->social ()->enterRoom (publicKey, "");
- }
-
-}
-
-
int
PlacesModel::rowCount (const QModelIndex & parent) const
{
@@ -225,7 +161,6 @@
m_lookupIndex[key] = index;
endInsertRows ();
- save ();
return item;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r36673 - in gnunet-qt/secushare: core/identity core/social models,
gnunet <=