Permalink
Browse files

real uuid function

  • Loading branch information...
RJ committed Feb 5, 2010
1 parent 27abfb1 commit 57d0d90b06c7fdaf803b7df6a808230d1b069ffa
Showing with 36 additions and 28 deletions.
  1. +12 −0 src/cjuuid.h
  2. +4 −1 src/conjist.cpp
  3. +3 −0 src/conjist.h
  4. +8 −13 src/servent.cpp
  5. +5 −5 src/servent.h
  6. +4 −9 src/src.pro
View
@@ -0,0 +1,12 @@
+#ifndef CJUUID_H
+#define CJUUID_H
+#include <QUuid>
+inline static QString uuid()
+{
+ QString q = QUuid::createUuid();
+ q.remove(1);
+ q.chop(1);
+ return q;
+}
+
+#endif // CJUUID_H
View
@@ -1,14 +1,17 @@
+#include <QTime>
#include "conjist.h"
#include "portfwd.h"
#include "getopt_helper.h"
#include "QXmppLogger.h"
#include "QXmppConfiguration.h"
+// default port, can be set using --listenport on command line
#define CONJISTPORT 50210
conjist::conjist(int argc, char *argv[])
: QCoreApplication(argc, argv), m_go(argc,argv), m_servent(0), m_externalPort(0), m_port(CONJISTPORT)
{
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); // for uuid generator
// do the setup once event loop started, so we can call exit() correctly
QTimer::singleShot(0, this, SLOT(setup()));
}
@@ -123,7 +126,7 @@ void conjist::newJabberPeer(QString name)
QVariantMap m;
if(m_servent->visibleExternally())
{
- QString key = "blah-jabber-ofer-key";
+ QString key = uuid();
ControlConnection * cc = new ControlConnection(m_servent);
cc->setName(name);
m_servent->registerOffer(key, cc);
View
@@ -3,6 +3,7 @@
#include <QCoreApplication>
#include <QVariantMap>
#include <QHostAddress>
+#include <QUuid>
#include <qjson/parser.h>
#include <qjson/serializer.h>
@@ -13,6 +14,8 @@
#include "getopt_helper.h"
#include "controlconnection.h"
+#include "cjuuid.h"
+
class conjist : public QCoreApplication
{
Q_OBJECT
View
@@ -124,7 +124,7 @@ void Servent::readyRead()
// use a copy, leave original there - offer can be reused.
conn = conn->clone();
}
- conn->setName("Incoming-"+key);
+ //conn->setName("Incoming-"+key);
conn->setPeerPort(pport);
// hand over the socket
sock->_disowned = true;
@@ -157,15 +157,9 @@ void Servent::createParallelConnection(Connection * orig_conn, Connection * new_
}
else // ask them to connect to us:
{
- QString tmpkey = "key-xxx"; // random, temp
+ QString tmpkey = uuid(); // random, temp
m_offers[tmpkey] = new_conn;
- // we need to tell peer to connect to us using this offer-key
- //QVariantMap m;
- //m["conntype"] = "request-offer";
- //m["key"] = key;
- //m["port"] = publicPort();
-
orig_conn->sendMsg(QString("{ \"conntype\" : \"request-offer\", "
" \"key\" : \"%1\", "
" \"offer\" : \"%2\" , "
@@ -226,7 +220,8 @@ void Servent::reverseOfferRequest(Connection * orig_conn, QString key, QString t
return;
}
Connection * new_conn = m_offers[key];
- new_conn->setName(key);
+ new_conn->setName(orig_conn->name() + "::parallel");
+ //new_conn->setName(key);
// use a push-offer instead of default accept offer:
QVariantMap m;
m["conntype"] = "push-offer";
@@ -327,7 +322,7 @@ void Servent::unregisterProxyConnection()
// debug stuff:
-
+/*
void Servent::debug_handleLine(QString line)
@@ -393,14 +388,14 @@ void Servent::debug_connected()
qDebug() << "Connnnnnected " << conn->id();
conn->sendMsg(QByteArray("First post"));
- /*
+
qDebug() << "Trying to dupe this connection";
ControlConnection * cc = new ControlConnection(this);
cc->setName("dupeconn");
connect(cc, SIGNAL(ready()), this, SLOT(debug_connected_dupe()));
connect(cc, SIGNAL(failed()), this, SLOT(debug_failed()));
createParallelConnection(conn, cc, "key2");
- */
+
}
void Servent::debug_connected_dupe()
@@ -419,5 +414,5 @@ void Servent::debug_failed()
}
-
+*/
View
@@ -18,7 +18,7 @@
#include "zeroconf/bonjourserviceresolver.h"
#include "connection.h"
-
+#include "cjuuid.h"
@@ -65,10 +65,10 @@ public slots:
void socketError(QAbstractSocket::SocketError);
void socketConnected();
- void debug_handleLine(QString line);
- void debug_failed();
- void debug_connected();
- void debug_connected_dupe();
+ //void debug_handleLine(QString line);
+ //void debug_failed();
+ //void debug_connected();
+ //void debug_connected_dupe();
private slots:
void readyRead();
View
@@ -1,10 +1,9 @@
TEMPLATE = app
OBJECTS_DIR = ../build
MOC_DIR = ../build
-QT += network xml
-
+QT += network \
+ xml
TARGET = ../conjist
-
HEADERS += servent.h \
connection.h \
controlconnection.h \
@@ -19,8 +18,8 @@ HEADERS += servent.h \
conjist.h \
jabberclient.h \
portfwd.h \
- getopt_helper.h
-
+ getopt_helper.h \
+ cjuuid.h
SOURCES += servent.cpp \
connection.cpp \
main.cpp \
@@ -35,18 +34,14 @@ SOURCES += servent.cpp \
jabberclient.cpp \
portfwd.cpp \
getopt_helper.cpp
-
LIBPATH += ../qxmpp/
LIBPATH += ../miniupnp/
-
INCLUDEPATH += ../qxmpp/
INCLUDEPATH += ../miniupnp/
-
LIBS += -L/usr/local/lib \
-lqjson \
-lQXmppClient \
-lminiupnp
-
!mac:x11:LIBS += -ldns_sd
win32:LIBS += -ldnssd

0 comments on commit 57d0d90

Please sign in to comment.