summaryrefslogtreecommitdiff
path: root/src/social/socialapp.cpp
blob: f72360c8f34db9295078887977038c0f9710dc34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "social/socialapp.h"
#include "app.h"

#include "nym/ego.h"
#include "model/models.h"

#include "social/host.h"
#include "social/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);

  connect (this, &SocialApp::createPlaceSignal,
           this, &SocialApp::createPlaceSlot, Qt::QueuedConnection);

  connect (this, &SocialApp::enterPlaceSignal,
           this, &SocialApp::enterPlaceSlot, Qt::QueuedConnection);
}


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->m_curEgo = ego;
  Ego *e = new Ego (*egoPubKey);
  e->setEgo (ego);
  e->setName (QString::fromLatin1 (name));
  theApp->models ()->egos ()->add (e);
}

void
SocialApp::hostPlaceCallback (void *cls,
                              struct GNUNET_SOCIAL_HostConnection *hconn,
                              struct GNUNET_SOCIAL_Ego *ego,
                              const struct GNUNET_CRYPTO_EddsaPublicKey *placePubKey,
                              enum GNUNET_SOCIAL_PlaceState placeState)
{
  SocialApp *s = (SocialApp *) cls;
  s->m_places += 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_PlaceState placeState)
{
  SocialApp *s = (SocialApp *) cls;
  s->m_places += new Guest (s->m_app, ego, gconn, s);
}


void
SocialApp::placeCreate ()
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n");

  Host *host = new Host (m_app, m_curEgo, GNUNET_PSYC_CHANNEL_PRIVATE, this); // FIXME: ego
  m_places += host;
}


void
SocialApp::createPlaceSlot ()
{
  placeCreate ();
}


void
SocialApp::createPlace ()
{
  emit createPlaceSignal ();
}


void
SocialApp::placeEnter (QString pubKeyStr, QString peerIdStr)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering place %s as guest.\n",
              pubKeyStr.toStdString ().c_str ());

  GNUNET_CRYPTO_EddsaPublicKey *pubKey = new GNUNET_CRYPTO_EddsaPublicKey;
  if (GNUNET_OK !=
      GNUNET_CRYPTO_eddsa_public_key_from_string (pubKeyStr.toStdString ().c_str (),
                                                  pubKeyStr.length (),
                                                  pubKey))
    return; // Failed conversion

  GNUNET_PeerIdentity peerId;
  GNUNET_CRYPTO_eddsa_public_key_from_string (peerIdStr.toStdString ().c_str (),
                                              peerIdStr.length (),
                                              &peerId.public_key);
  m_places += new Guest (m_app, m_curEgo, pubKey, &peerId, 0, NULL, NULL, this);
}


void
SocialApp::enterPlaceSlot (QString pubKeyStr, QString peerIdStr)
{
  placeEnter (pubKeyStr, peerIdStr);
}


void
SocialApp::enterPlace (QString pubKeyStr, QString peerIdStr)
{
  emit enterPlaceSignal (pubKeyStr, peerIdStr);
}