summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortg(x) <*@tg-x.net>2016-02-05 23:40:52 +0100
committertg(x) <*@tg-x.net>2016-02-05 23:40:52 +0100
commit5b561f21f818205eb1569169c35439f23540b1cc (patch)
tree5a4fb699e4078b31a6bbbbf9c9f3171e7feef339
parent556d43ec105a2873e299ffbc5cad60727586b85c (diff)
downloadsecushare-5b561f21f818205eb1569169c35439f23540b1cc.tar.gz
secushare-5b561f21f818205eb1569169c35439f23540b1cc.zip
connecting to gnunet
-rw-r--r--secushare.pro2
-rw-r--r--src/app.cpp29
-rw-r--r--src/app.h16
-rw-r--r--src/gnunet/gnunet.cpp123
-rw-r--r--src/gnunet/gnunet.h131
-rw-r--r--src/social/socialapp.cpp28
-rw-r--r--src/social/socialapp.h5
7 files changed, 132 insertions, 202 deletions
diff --git a/secushare.pro b/secushare.pro
index 4bc4b1b..fb36ce8 100644
--- a/secushare.pro
+++ b/secushare.pro
@@ -15,6 +15,7 @@ SOURCES += src/main.cpp \
15 src/model/PlaceListModel.cpp \ 15 src/model/PlaceListModel.cpp \
16 src/nym/nym.cpp \ 16 src/nym/nym.cpp \
17 src/nym/ego.cpp \ 17 src/nym/ego.cpp \
18 src/gnunet/gnunet.cpp \
18 src/social/socialapp.cpp \ 19 src/social/socialapp.cpp \
19 src/social/modifier.cpp \ 20 src/social/modifier.cpp \
20 src/social/message.cpp \ 21 src/social/message.cpp \
@@ -36,6 +37,7 @@ include(deployment.pri)
36HEADERS += \ 37HEADERS += \
37 src/app.h \ 38 src/app.h \
38 src/gnunet.h \ 39 src/gnunet.h \
40 src/gnunet/gnunet.h \
39 src/model/models.h \ 41 src/model/models.h \
40 src/model/EgoListModel.h \ 42 src/model/EgoListModel.h \
41 src/model/PlaceListModel.h \ 43 src/model/PlaceListModel.h \
diff --git a/src/app.cpp b/src/app.cpp
index dc277cb..10669b2 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -24,11 +24,38 @@ App::App (QObject * parent)
24 m_models = new Models (this); 24 m_models = new Models (this);
25 m_helpers = new Helpers (this); 25 m_helpers = new Helpers (this);
26 m_qrProvider = new QrImageProvider (); 26 m_qrProvider = new QrImageProvider ();
27 m_social = new SocialApp (this);
28 registerQmlTypes (); 27 registerQmlTypes ();
29 setupTray (); 28 setupTray ();
29 startGnuNet ();
30} 30}
31 31
32/**
33 * Connect to GNUnet services.
34 * It needs to run in a separate thread.
35 */
36void
37App::startGnuNet ()
38{
39 //Create the GnuNet object
40 m_gnunet = new GnuNet ();
41
42 //New thread where the Gnunet will be run on.
43 m_gnunetThread = new QThread ();
44
45 m_gnunet->moveToThread (m_gnunetThread);
46
47 // Call the start function after our thread is ready to run
48 connect (m_gnunetThread, &QThread::started,
49 m_gnunet, &GnuNet::start);
50
51 m_gnunetThread->start ();
52
53 connect (m_gnunet, &GnuNet::connectedChanged,
54 this, &App::setConnected,
55 Qt::QueuedConnection);
56}
57
58
32// theApp singleton type provider 59// theApp singleton type provider
33static QObject * 60static QObject *
34theApp_provider (QQmlEngine * engine, QJSEngine * scriptEngine) 61theApp_provider (QQmlEngine * engine, QJSEngine * scriptEngine)
diff --git a/src/app.h b/src/app.h
index bd2dfc4..b0d17ca 100644
--- a/src/app.h
+++ b/src/app.h
@@ -7,6 +7,7 @@
7#include <QQmlEngine> 7#include <QQmlEngine>
8#include <QQuickWindow> 8#include <QQuickWindow>
9 9
10#include "gnunet/gnunet.h"
10#include "model/models.h" 11#include "model/models.h"
11#include "social/socialapp.h" 12#include "social/socialapp.h"
12#include "settings/settings.h" 13#include "settings/settings.h"
@@ -63,7 +64,7 @@ public:
63 64
64 SocialApp *social () const 65 SocialApp *social () const
65 { 66 {
66 return m_social; 67 return m_gnunet->social ();
67 } 68 }
68 69
69 void setupTray (); 70 void setupTray ();
@@ -79,12 +80,11 @@ public:
79private: 80private:
80 81
81 Models * m_models; 82 Models * m_models;
82
83 Helpers *m_helpers; 83 Helpers *m_helpers;
84 84 GnuNet *m_gnunet;
85 QrImageProvider *m_qrProvider; 85 QThread *m_gnunetThread;
86
87 SocialApp *m_social; 86 SocialApp *m_social;
87 QrImageProvider *m_qrProvider;
88 88
89 QMenu *m_trayMenu; 89 QMenu *m_trayMenu;
90 QSystemTrayIcon *m_tray; 90 QSystemTrayIcon *m_tray;
@@ -93,7 +93,11 @@ private:
93 // is the connection established to the GNUnet social service? 93 // is the connection established to the GNUnet social service?
94 bool m_connected; 94 bool m_connected;
95 95
96 void close (); 96 void
97 startGnuNet ();
98
99 void
100 close ();
97 101
98signals: 102signals:
99 void connectedChanged (bool connected); 103 void connectedChanged (bool connected);
diff --git a/src/gnunet/gnunet.cpp b/src/gnunet/gnunet.cpp
index cb18637..6ceeb6f 100644
--- a/src/gnunet/gnunet.cpp
+++ b/src/gnunet/gnunet.cpp
@@ -20,34 +20,40 @@
20 20
21#include "gnunet.h" 21#include "gnunet.h"
22 22
23#include "preferences/preferences.h" 23#include "social/socialapp.h"
24#include "identity/identityService.h"
25#include "social/socialservice.h"
26 24
27#include <math.h> 25#include <math.h>
28#include <QElapsedTimer> 26#include <QElapsedTimer>
29#include <QWaitCondition> 27#include <QWaitCondition>
30 28
31 29
30GnuNet::GnuNet (QObject * parent)
31 : QObject (parent)
32{
33 m_connected = false;
34}
35
36GnuNet::~GnuNet ()
37{
38
39}
40
41
32/*********************************** 42/***********************************
33 * START STATIC CALLBACKS 43 * START STATIC CALLBACKS
34 ***********************************/ 44 ***********************************/
35 45
36/** 46/**
37 * Static function. 47 * Static function.
38 * The first function executed when GNUNet is running. 48 * The first function executed when GnuNet is running.
39 */ 49 */
40void 50void
41GNUNet::mainLoopCallback (void *cls, char *const *args, const char *cfgfile, 51GnuNet::mainLoopCallback (void *cls, char *const *args, const char *cfgfile,
42 const struct GNUNET_CONFIGURATION_Handle *cfg) 52 const struct GNUNET_CONFIGURATION_Handle *cfg)
43{ 53{
44 //Retrive our main funtion 54 GnuNet *gnunet = (GnuNet *) cls;
45 GNUNet *gnunetInstance = (GNUNet *) cls; 55 Q_ASSERT (NULL != gnunet);
46 56 gnunet->mainLoop (args, cfgfile, cfg);
47 Q_ASSERT (gnunetInstance);
48
49 //Call our main loop
50 gnunetInstance->mainLoop (args, cfgfile, cfg);
51} 57}
52 58
53 59
@@ -56,22 +62,21 @@ GNUNet::mainLoopCallback (void *cls, char *const *args, const char *cfgfile,
56 * Called to process our internal messages 62 * Called to process our internal messages
57 */ 63 */
58void 64void
59GNUNet::keepaliveTaskCallback (void *cls, 65GnuNet::keepaliveTaskCallback (void *cls,
60 const struct GNUNET_SCHEDULER_TaskContext *tc) 66 const struct GNUNET_SCHEDULER_TaskContext *tc)
61{ 67{
62 Q_UNUSED (tc); 68 Q_UNUSED (tc);
63 69
64 //Retrive our main funtion 70 GnuNet *gnunet = (GnuNet *) cls;
65 Q_ASSERT (cls); 71 Q_ASSERT (NULL != gnunet);
66 GNUNet *gnunetInstance = (GNUNet *) cls;
67 72
68 //Process the events 73 //Process the events
69 gnunetInstance->processEvents (); 74 gnunet->processEvents ();
70 75
71 //Call again in 500 millisecond. 76 //Call again in 500 millisecond.
72 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 77 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
73 (GNUNET_TIME_UNIT_MILLISECONDS, 500), 78 (GNUNET_TIME_UNIT_MILLISECONDS, 500),
74 &keepaliveTaskCallback, gnunetInstance); 79 &keepaliveTaskCallback, gnunet);
75} 80}
76 81
77 82
@@ -80,32 +85,13 @@ GNUNet::keepaliveTaskCallback (void *cls,
80 ***********************************/ 85 ***********************************/
81 86
82 87
83GNUNet::GNUNet (QObject * parent):
84QObject (parent)
85{
86
87 m_connected = false;
88 m_myPeer = new GNUNET_PeerIdentity;
89
90
91}
92
93GNUNet::~GNUNet ()
94{
95 delete m_myPeer;
96}
97
98/** 88/**
99 * Start GNUnet 89 * Start GNUnet
100 */ 90 */
101 91
102void 92void
103GNUNet::start () 93GnuNet::start ()
104{ 94{
105 m_identity = new IdentityService (this);
106
107 m_social = new SocialService (this);
108
109 static struct GNUNET_GETOPT_CommandLineOption options[] = { 95 static struct GNUNET_GETOPT_CommandLineOption options[] = {
110 GNUNET_GETOPT_OPTION_END 96 GNUNET_GETOPT_OPTION_END
111 }; 97 };
@@ -121,85 +107,52 @@ GNUNet::start ()
121} 107}
122 108
123/** 109/**
124 * It's the first function executed when GNUNet is running. 110 * It's the first function executed when GnuNet is running.
125 */ 111 */
126void 112void
127GNUNet::mainLoop (char *const *args, const char *cfgfile, 113GnuNet::mainLoop (char *const *args, const char *cfgfile,
128 const struct GNUNET_CONFIGURATION_Handle *cfg) 114 const struct GNUNET_CONFIGURATION_Handle *cfg)
129{ 115{
130 Q_UNUSED (args); 116 Q_UNUSED (args);
131 Q_UNUSED (cfgfile); 117 Q_UNUSED (cfgfile);
132 Q_UNUSED (cfg); 118 Q_UNUSED (cfg);
133 119
134 char *privateKeyFileName; 120 // Create our configuration
135
136 //Create our configuration
137 m_config = GNUNET_CONFIGURATION_create (); 121 m_config = GNUNET_CONFIGURATION_create ();
138 GNUNET_CONFIGURATION_load (m_config, cfgfile); 122 GNUNET_CONFIGURATION_load (m_config, cfgfile);
139 123
140 //Get my information
141
142 //load private key
143 if (GNUNET_OK !=
144 GNUNET_CONFIGURATION_get_value_filename (m_config, "PEER", "PRIVATE_KEY",
145 &privateKeyFileName))
146 {
147 qWarning () <<
148 QString
149 ("Could not find option `GNUNETD:HOSTKEYFILE' in configuration.\n");
150 return;
151 }
152
153
154 //Get my own peer 124 //Get my own peer
155 GNUNET_CRYPTO_get_peer_identity (m_config, m_myPeer); 125 GNUNET_CRYPTO_get_peer_identity (m_config, &m_peerId);
156
157 char *str = GNUNET_CRYPTO_eddsa_public_key_to_string (&m_myPeer->public_key);
158 126
159 setMyPublicKeyStr (QString (str)); 127 char *str = GNUNET_CRYPTO_eddsa_public_key_to_string (&m_peerId.public_key);
128 m_peerIdStr = QString (str);
160 GNUNET_free (str); 129 GNUNET_free (str);
161 130
131 emit peerIdChanged (m_peerId);
132 emit peerIdStringChanged (m_peerIdStr);
162 133
163 //A update function to process our messages 134 // An update function to process our messages
164 GNUNET_SCHEDULER_add_now (keepaliveTaskCallback, this); 135 GNUNET_SCHEDULER_add_now (keepaliveTaskCallback, this);
165 136
166 137 connectServices ();
167 //Start arm
168 startServices ();
169} 138}
170 139
171 140
172/** 141/**
173 * Start the services such as filesharing 142 * Connect to the services
174 */ 143 */
175
176void 144void
177GNUNet::startServices () 145GnuNet::connectServices ()
178{ 146{
179 m_identity->start (m_config); 147 m_social = new SocialApp (m_config, this);
180
181 emit gnunetStarted (); 148 emit gnunetStarted ();
182} 149}
183 150
184
185void
186GNUNet::identitySetSlot ()
187{
188 m_social->start (m_config);
189}
190
191/** 151/**
192 * Process our internal pending messages. 152 * Process our internal pending messages.
193 */ 153 */
194void 154void
195GNUNet::processEvents () 155GnuNet::processEvents ()
196{ 156{
197 QCoreApplication::processEvents (); 157 QCoreApplication::processEvents ();
198} 158}
199
200
201GNUNET_PeerIdentity *
202GNUNet::myPeer () const
203{
204 return m_myPeer;
205}
diff --git a/src/gnunet/gnunet.h b/src/gnunet/gnunet.h
index 52546c7..07290f9 100644
--- a/src/gnunet/gnunet.h
+++ b/src/gnunet/gnunet.h
@@ -21,42 +21,49 @@
21 21
22#ifndef GNUNET_H 22#ifndef GNUNET_H
23#define GNUNET_H 23#define GNUNET_H
24
24#include <QtCore> 25#include <QtCore>
25#include <QString> 26#include <QString>
26 27
28#include "social/socialapp.h"
27 29
28#include "gnunet_includes.h" 30class GnuNet : public QObject
31{
32 Q_OBJECT;
29 33
34 Q_PROPERTY (SocialApp * social
35 READ social CONSTANT);
30 36
31class IdentityService; 37 Q_PROPERTY (GNUNET_CONFIGURATION_Handle * config
38 READ config);
32 39
33class SocialService; 40 Q_PROPERTY (bool connected
41 READ isConnected
42 NOTIFY connectedChanged);
34 43
35class GNUNet:public QObject 44 Q_PROPERTY (GNUNET_PeerIdentity peerId
36{ 45 READ peerId
37Q_OBJECT Q_PROPERTY (IdentityService * identity READ identity CONSTANT) Q_PROPERTY (SocialService * social READ social CONSTANT) Q_PROPERTY (GNUNET_CONFIGURATION_Handle * config READ config) Q_PROPERTY (bool connected READ isConnected WRITE setConnected NOTIFY connectedChanged) Q_PROPERTY (QString myPublicKeyStr READ myPublicKeyStr WRITE setMyPublicKeyStr NOTIFY myPublicKeyStrChanged) public: 46 NOTIFY peerIdChanged);
38 explicit GNUNet (QObject * parent =
39 0);
40 ~GNUNet ();
41 47
42 IdentityService *identity () const 48 Q_PROPERTY (QString peerIdString
43 { 49 READ peerIdString
44 return m_identity; 50 NOTIFY peerIdStringChanged);
45 }
46 51
47 SocialService *social () const 52 public:
53
54 explicit GnuNet (QObject *parent = 0);
55 ~GnuNet ();
56
57 SocialApp *social () const
48 { 58 {
49 return m_social; 59 return m_social;
50 } 60 }
51 61
52
53 GNUNET_CONFIGURATION_Handle *config () const 62 GNUNET_CONFIGURATION_Handle *config () const
54 { 63 {
55 return m_config; 64 return m_config;
56 } 65 }
57 66
58
59
60 bool isConnected () const 67 bool isConnected () const
61 { 68 {
62 return m_connected; 69 return m_connected;
@@ -68,30 +75,24 @@ Q_OBJECT Q_PROPERTY (IdentityService * identity READ identity CONSTANT) Q_PROPER
68 emit connectedChanged (m_connected); 75 emit connectedChanged (m_connected);
69 } 76 }
70 77
71 78 // Peer ID
72 79 GNUNET_PeerIdentity peerId () const
73 //Public Key Str
74 QString myPublicKeyStr () const
75 { 80 {
76 return m_myPublicKeyStr; 81 return m_peerId;
77 } 82 }
78 void setMyPublicKeyStr (QString key) 83 QString peerIdString () const
79 { 84 {
80 m_myPublicKeyStr = key; 85 return m_peerIdStr;
81 emit myPublicKeyStrChanged (key);
82 } 86 }
83 87
88 private:
84 89
85 90 GNUNET_PeerIdentity m_peerId;
86 GNUNET_PeerIdentity *myPeer () const; 91 QString m_peerIdStr;
87
88
89
90private:
91 92
92 /** 93 /**
93 Static Definitions 94 * Static Definitions
94 */ 95 */
95 static void mainLoopCallback (void *cls, char *const *args, 96 static void mainLoopCallback (void *cls, char *const *args,
96 const char *cfgfile, 97 const char *cfgfile,
97 const struct GNUNET_CONFIGURATION_Handle *cfg); 98 const struct GNUNET_CONFIGURATION_Handle *cfg);
@@ -100,73 +101,39 @@ private:
100 const struct GNUNET_SCHEDULER_TaskContext 101 const struct GNUNET_SCHEDULER_TaskContext
101 *tc); 102 *tc);
102 103
103public: 104 signals:
104 void armConnectionStateChange (int connected);
105 105
106
107signals:
108 void gnunetStarted (); 106 void gnunetStarted ();
109 107
110 void gnunetConnected (); 108 void gnunetConnected ();
111 109
112 void connectedChanged (bool connected); 110 void connectedChanged (bool connected);
113 111
114 void myPublicKeyStrChanged (QString key); 112 void peerIdChanged (GNUNET_PeerIdentity peerId);
115
116 113
117 public slots:void start (); 114 void peerIdStringChanged (QString peerIdStr);
118 115
119 void identitySetSlot (); 116 public slots:
120 117
121 private slots:void startServices (); 118 void start ();
122 119
123private: 120 private slots:
124 121
125 /** 122 void connectServices ();
126 * Pointer to GNUnet Identity Service.
127 */
128 IdentityService * m_identity;
129
130
131 /**
132 * Pointer to GNUnet Social Service.
133 */
134 SocialService *m_social;
135
136
137
138 /**
139 * @brief m_config
140 */
141 struct GNUNET_CONFIGURATION_Handle *m_config;
142
143 /**
144 * @brief m_connected
145 */
146 bool m_connected;
147
148
149
150 /**
151 * My peer.
152 */
153
154 struct GNUNET_PeerIdentity *m_myPeer;
155
156 /**
157 * My public key.
158 */
159 QString m_myPublicKeyStr;
160 123
124 private:
161 125
126 SocialApp *m_social;
162 127
128 struct GNUNET_CONFIGURATION_Handle *m_config;
163 129
130 bool m_connected;
164 131
165 void processEvents (); 132 void processEvents ();
166 133
167 void mainLoop (char *const *args, const char *cfgfile, 134 void mainLoop (char *const *args, const char *cfgfile,
168 const GNUNET_CONFIGURATION_Handle * cfg); 135 const GNUNET_CONFIGURATION_Handle * cfg);
169 136
170}; 137};
171 138
172#endif // GNUNET_H 139#endif
diff --git a/src/social/socialapp.cpp b/src/social/socialapp.cpp
index 10b6be2..4ad9970 100644
--- a/src/social/socialapp.cpp
+++ b/src/social/socialapp.cpp
@@ -8,17 +8,9 @@
8#include "social/guest.h" 8#include "social/guest.h"
9 9
10 10
11SocialApp::SocialApp (QObject *parent) : QObject (parent) 11SocialApp::SocialApp (struct GNUNET_CONFIGURATION_Handle *config,
12{ 12 QObject *parent)
13} 13 : QObject (parent)
14
15
16/**
17 * @brief Should be called when the GNUnet service is connected to start everything
18 * @param config
19 */
20void
21SocialApp::start (struct GNUNET_CONFIGURATION_Handle *config)
22{ 14{
23 this->m_config = config; 15 this->m_config = config;
24 this->m_app = 16 this->m_app =
@@ -70,17 +62,9 @@ SocialApp::guestPlaceCallback (void *cls,
70 62
71 63
72void 64void
73SocialApp::createPlaceSlot ()
74{
75
76}
77
78
79bool
80SocialApp::createPlace () 65SocialApp::createPlace ()
81{ 66{
82 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n"); 67 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n");
83 if (NULL == m_app || NULL == )
84 68
85 Host *host = new Host (m_app, m_curEgo); // FIXME: ego 69 Host *host = new Host (m_app, m_curEgo); // FIXME: ego
86 m_places += host; 70 m_places += host;
@@ -89,12 +73,6 @@ SocialApp::createPlace ()
89 73
90 74
91void 75void
92SocialApp::enterPlaceSlot (QString pubKeyStr, QString peerIdStr)
93{
94}
95
96
97void
98SocialApp::enterPlace (QString pubKeyStr, QString peerIdStr) 76SocialApp::enterPlace (QString pubKeyStr, QString peerIdStr)
99{ 77{
100 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place %s as guest.\n", 78 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place %s as guest.\n",
diff --git a/src/social/socialapp.h b/src/social/socialapp.h
index 1dc5776..519eef4 100644
--- a/src/social/socialapp.h
+++ b/src/social/socialapp.h
@@ -13,9 +13,8 @@ class SocialApp : public QObject
13 13
14 public: 14 public:
15 15
16 explicit SocialApp (QObject *parent = 0); 16 explicit SocialApp (GNUNET_CONFIGURATION_Handle * config,
17 17 QObject *parent = 0);
18 void start (GNUNET_CONFIGURATION_Handle * config);
19 18
20 Q_INVOKABLE void createPlace (); 19 Q_INVOKABLE void createPlace ();
21 Q_INVOKABLE void enterPlace (QString pubKeyStr, QString peerIdStr); 20 Q_INVOKABLE void enterPlace (QString pubKeyStr, QString peerIdStr);