make one's prefix unique
diff --git a/chatdialog.cpp b/chatdialog.cpp
index 58bdd90..57de04e 100644
--- a/chatdialog.cpp
+++ b/chatdialog.cpp
@@ -6,6 +6,8 @@
#include <QTimer>
#include <QMetaType>
#include <QMessageBox>
+#include <boost/random/random_device.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
#define BROADCAST_PREFIX_FOR_SYNC_DEMO "/ndn/broadcast/sync-demo"
@@ -282,6 +284,21 @@
msg.set_type(SyncDemo::ChatMessage::CHAT);
}
+static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
+
+QString
+ChatDialog::getRandomString()
+{
+ std::string randStr;
+ boost::random::random_device rng;
+ boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
+ for (int i = 0; i < 10; i ++)
+ {
+ randStr += chars[index_dist(rng)];
+ }
+ return randStr.c_str();
+}
+
bool
ChatDialog::readSettings()
{
@@ -390,7 +407,7 @@
needWrite = true;
}
if (!prefix.isEmpty() && prefix != m_user.getPrefix()) {
- m_user.setPrefix(prefix);
+ m_user.setPrefix(prefix + "/" + getRandomString());
needWrite = true;
// TODO: set the previous prefix as left?
}
diff --git a/chatdialog.h b/chatdialog.h
index 116e20e..0d4984a 100644
--- a/chatdialog.h
+++ b/chatdialog.h
@@ -39,6 +39,7 @@
void processData(QString name, const char *buf, size_t len);
private:
+ QString getRandomString();
void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
bool readSettings();
void writeSettings();
diff --git a/digesttreescene.cpp b/digesttreescene.cpp
index 50d170b..b0b3d7c 100644
--- a/digesttreescene.cpp
+++ b/digesttreescene.cpp
@@ -95,7 +95,7 @@
#ifdef __DEBUG
else
{
- std::cout << "Couldn't find prefix, let's check"<< std::endl;
+ std::cout << "Couldn't find prefix, " << prefix.toStdString() << ": let's check"<< std::endl;
Roster_iterator ii = m_roster.begin();
while (ii != m_roster.end())
{
diff --git a/sync-demo.pro b/sync-demo.pro
index f65fbdd..c82c20b 100644
--- a/sync-demo.pro
+++ b/sync-demo.pro
@@ -20,7 +20,7 @@
QMAKE_CXXFLAGS *= -g
QMAKE_CFLAGS *= -g
-LIBS += -lboost_system-mt
+LIBS += -lboost_system-mt -lboost_random
CONFIG += console