summaryrefslogtreecommitdiff
path: root/src/social/socialapp.cpp
blob: 10b6be26f8e8822a2a56c8953c713f71a5435263 (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
#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 (QObject *parent) : QObject (parent)
{
}


/**
 * @brief Should be called when the GNUnet service is connected to start everything
 * @param config
 */
void
SocialApp::start (struct GNUNET_CONFIGURATION_Handle *config)
{
  this->m_config = config;
  this->m_app =
    GNUNET_SOCIAL_app_connect (config, APP_NAME,
                               egoCallback,
                               hostPlaceCallback,
                               guestPlaceCallback,
                               this);
}


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);
}


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);
}


void
SocialApp::createPlaceSlot ()
{

}


bool
SocialApp::createPlace ()
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n");
  if (NULL == m_app || NULL == )

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


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


void
SocialApp::enterPlace (QString pubKeyStr, QString peerIdStr)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to 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);
//  emit enterPlaceSignal (pubKey, peerId);
}