fix sync logic bug about seqno
demo works with small flaws
diff --git a/chatdialog.cpp b/chatdialog.cpp
index e325d6b..4d7c358 100644
--- a/chatdialog.cpp
+++ b/chatdialog.cpp
@@ -92,7 +92,6 @@
return;
}
- std::cout << "<<<< Received Message: " << msg.data() << std::endl;
QTextCursor cursor(textEdit->textCursor());
cursor.movePosition(QTextCursor::End);
QTextTableFormat tableFormat;
@@ -103,18 +102,23 @@
table->cellAt(0, 1).firstCursorPosition().insertText(msg.data().c_str());
QScrollBar *bar = textEdit->verticalScrollBar();
bar->setValue(bar->maximum());
- std::cout << "<<<<, Message appended " << std::endl;
}
void
ChatDialog::processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo> v, Sync::SyncAppSocket *sock)
{
emit treeUpdated(v);
+#ifdef __DEBUG
+ std::cout << "<<< Tree update signal emitted" << std::endl;
+#endif
}
void
ChatDialog::processTreeUpdate(const std::vector<Sync::MissingDataInfo> v)
{
+#ifdef __DEBUG
+ std::cout << "<<< processing Tree Update" << std::endl;
+#endif
if (v.empty())
{
return;
@@ -136,6 +140,9 @@
for (Sync::SeqNo seq = v[i].low; seq <= v[i].high; ++seq)
{
m_sock->fetchRaw(v[i].prefix, seq, bind(&ChatDialog::processDataWrapper, this, _1, _2, _3), 2);
+#ifdef __DEBUG
+ std::cout << "<<< Fetching " << v[i].prefix << "/" <<seq.getSession() <<"/" << seq.getSeq() << std::endl;
+#endif
}
}
}
@@ -156,6 +163,9 @@
ChatDialog::processDataWrapper(std::string name, const char *buf, size_t len)
{
emit dataReceived(name.c_str(), buf, len);
+#ifdef __DEBUG
+ std::cout <<"<<< " << name << " fetched" << std::endl;
+#endif
}
void
@@ -266,7 +276,7 @@
m_sock->publishRaw(m_user.getPrefix().toStdString(), m_session, buf, size, 60);
int nextSequence = m_sock->getNextSeq(m_user.getPrefix().toStdString(), m_session);
- Sync::MissingDataInfo mdi = {m_user.getPrefix().toStdString(), Sync::SeqNo(0), Sync::SeqNo(nextSequence)};
+ Sync::MissingDataInfo mdi = {m_user.getPrefix().toStdString(), Sync::SeqNo(0), Sync::SeqNo(nextSequence - 1)};
std::vector<Sync::MissingDataInfo> v;
v.push_back(mdi);
m_scene->processUpdate(v, m_sock->getRootDigest().c_str());
diff --git a/digesttreescene.cpp b/digesttreescene.cpp
index 35df071..4bf699e 100644
--- a/digesttreescene.cpp
+++ b/digesttreescene.cpp
@@ -25,13 +25,18 @@
for (int i = 0; i < n; i++)
{
Roster_iterator it = m_roster.find(v[i].prefix.c_str());
- if (it == m_roster.end()) {
+ if (it == m_roster.end())
+ {
rePlot = true;
DisplayUserPtr p(new DisplayUser());
p->setPrefix(v[i].prefix.c_str());
p->setSeq(v[i].high);
m_roster.insert(p->getPrefix(), p);
}
+ else
+ {
+ it.value()->setSeq(v[i].high);
+ }
}
if (rePlot)
@@ -77,7 +82,7 @@
reDrawNode(p, Qt::red);
- if (previouslyUpdatedUser != DisplayUserNullPtr)
+ if (previouslyUpdatedUser != DisplayUserNullPtr && previouslyUpdatedUser != p)
{
reDrawNode(previouslyUpdatedUser, Qt::darkBlue);
}