diff options
author | George Hazan <ghazan@miranda.im> | 2022-09-12 12:12:47 -0700 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-09-12 12:12:47 -0700 |
commit | df5f0921ccc21b76e17b70e5e55b92ae96a4ab31 (patch) | |
tree | e96871cff9bd78cfb64a4d754f8ea672fd1daddf /protocols/JabberG/src | |
parent | c37dd53c975775172b6e225dca188bcb1102b5a8 (diff) |
Jabber: fix for stream management
Diffstat (limited to 'protocols/JabberG/src')
-rw-r--r-- | protocols/JabberG/src/jabber_iqid.cpp | 6 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_strm_mgmt.cpp | 32 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_strm_mgmt.h | 3 |
3 files changed, 25 insertions, 16 deletions
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 6d9e915567..9ec0dfee1e 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -260,8 +260,8 @@ void CJabberProto::OnLoggedIn() m_ThreadInfo->dwLoginRqs = 0;
// XEP-0083 support
- if (!(m_StrmMgmt.IsSessionResumed()))
- {
+// if (!(m_StrmMgmt.IsSessionResumed()))
+// {
// ugly hack to prevent hangup during login process
CJabberIqInfo *pIqInfo = AddIQ(&CJabberProto::OnIqResultNestedRosterGroups, JABBER_IQ_TYPE_GET);
pIqInfo->SetTimeout(30000);
@@ -276,7 +276,7 @@ void CJabberProto::OnLoggedIn() m_ThreadInfo->send(
XmlNodeIq(AddIQ(&CJabberProto::OnIqResultDiscoBookmarks, JABBER_IQ_TYPE_GET))
<< XQUERY(JABBER_FEAT_PRIVATE_STORAGE) << XCHILDNS("storage", "storage:bookmarks"));
- }
+// }
m_bPepSupported = false;
diff --git a/protocols/JabberG/src/jabber_strm_mgmt.cpp b/protocols/JabberG/src/jabber_strm_mgmt.cpp index 8305822c8e..bc39f3c0bd 100644 --- a/protocols/JabberG/src/jabber_strm_mgmt.cpp +++ b/protocols/JabberG/src/jabber_strm_mgmt.cpp @@ -31,14 +31,14 @@ strm_mgmt::strm_mgmt(CJabberProto *_proto) : void strm_mgmt::OnProcessEnabled(const TiXmlElement *node, ThreadData * /*info*/)
{
m_bEnabled = true;
- auto *val = XmlGetAttr(node, "max");
- if (val)
- m_nResumeMaxSeconds = atoi(val);
- val = XmlGetAttr(node, "resume");
+ auto *val = XmlGetAttr(node, "resume");
if (val) {
if (mir_strcmp(val, "true") || mir_strcmp(val, "1")) {
m_bResumeSupported = true;
m_sResumeId = XmlGetAttr(node, "id");
+
+ val = XmlGetAttr(node, "max");
+ m_nResumeMaxSeconds = val ? atoi(val) : 86400;
}
}
//TODO: handle 'location'
@@ -50,14 +50,14 @@ void strm_mgmt::OnProcessResumed(const TiXmlElement *node, ThreadData * /*info*/ {
if (mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:xmpp:sm:3"))
return;
-
+
auto *var = XmlGetAttr(node, "previd");
if (!var)
return;
-
+
if (m_sResumeId != var)
return; //TODO: unknown session, what we should do ?
-
+
var = XmlGetAttr(node, "h");
if (!var)
return;
@@ -130,7 +130,7 @@ void strm_mgmt::ResendNodes(uint32_t size) }
}
}
- std::list<TiXmlElement*> tmp_list = NodeCache;
+ std::list<TiXmlElement *> tmp_list = NodeCache;
NodeCache.clear();
m_nLocalSCount = m_nSrvHCount; //we have handled missed nodes, set our counter to match server side value
for (auto i : tmp_list)
@@ -143,11 +143,11 @@ void strm_mgmt::OnProcessSMr(const TiXmlElement *node) SendAck();
}
-void strm_mgmt::OnProcessFailed(const TiXmlElement *node, ThreadData * info) //used failed instead of failure, notes: https://xmpp.org/extensions/xep-0198.html#errors
+void strm_mgmt::OnProcessFailed(const TiXmlElement *node, ThreadData *info) //used failed instead of failure, notes: https://xmpp.org/extensions/xep-0198.html#errors
{
if (mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:xmpp:sm:3"))
return;
-
+
proto->debugLogA("strm_mgmt: error: Failed to resume session %s", m_sResumeId.c_str());
m_bEnabled = false;
@@ -191,7 +191,7 @@ void strm_mgmt::HandleOutgoingNode(TiXmlElement *node) {
if (!m_bEnabled)
return;
-
+
auto *pNodeCopy = node->DeepClone(&xmlStorage)->ToElement();
if (pNodeCopy == nullptr)
return;
@@ -208,6 +208,8 @@ void strm_mgmt::ResetState() //reset state of stream management
m_bEnabled = false;
m_bPendingEnable = false;
+ m_nResumeMaxSeconds = 0;
+ m_tConnLostTime = 0;
//reset stream management h counters
m_nLocalHCount = m_nLocalSCount = m_nSrvHCount = 0;
//clear resume id
@@ -217,6 +219,7 @@ void strm_mgmt::ResetState() void strm_mgmt::HandleConnectionLost()
{
m_bEnabled = false;
+ m_tConnLostTime = time(0);
}
bool strm_mgmt::HandleIncommingNode(const TiXmlElement *node)
@@ -249,7 +252,7 @@ void strm_mgmt::EnableStrmMgmt() else //resume session
{
XmlNode enable_sm("resume");
- enable_sm << XATTR("xmlns", "urn:xmpp:sm:3") << XATTRI("h", m_nLocalHCount) << XATTR("previd", m_sResumeId.c_str());
+ enable_sm << XATTR("xmlns", "urn:xmpp:sm:3") << XATTRI("h", m_nLocalHCount) << XATTR("previd", m_sResumeId.c_str());
proto->m_ThreadInfo->send(enable_sm);
}
}
@@ -258,6 +261,7 @@ void strm_mgmt::SendAck() {
if (!m_bEnabled)
return;
+
proto->debugLogA("strm_mgmt: info: sending ack: locally received node count %d", m_nLocalHCount);
XmlNode enable_sm("a");
enable_sm << XATTR("xmlns", "urn:xmpp:sm:3") << XATTRI("h", m_nLocalHCount);
@@ -280,6 +284,10 @@ bool strm_mgmt::IsSessionResumed() bool strm_mgmt::IsResumeIdPresent()
{
+ if (m_tConnLostTime && m_nResumeMaxSeconds && time(0) - m_tConnLostTime > m_nResumeMaxSeconds) {
+ ResetState();
+ return false;
+ }
return !m_sResumeId.empty();
}
diff --git a/protocols/JabberG/src/jabber_strm_mgmt.h b/protocols/JabberG/src/jabber_strm_mgmt.h index b50e7e7dd7..fae80df6ba 100644 --- a/protocols/JabberG/src/jabber_strm_mgmt.h +++ b/protocols/JabberG/src/jabber_strm_mgmt.h @@ -38,12 +38,13 @@ class strm_mgmt CJabberProto *proto;
TiXmlDocument xmlStorage;
- uint32_t m_nSrvHCount, m_nLocalHCount, m_nLocalSCount, m_nResumeMaxSeconds;
+ uint32_t m_nSrvHCount, m_nLocalHCount, m_nLocalSCount, m_nResumeMaxSeconds = 0;
const uint32_t m_nCacheSize = 10;
bool m_bEnabled = false;
bool m_bPendingEnable = false;
bool m_bResumeSupported = false;
bool m_bSessionResumed = false;
+ time_t m_tConnLostTime = 0;
std::string m_sResumeId;
std::list<TiXmlElement*> NodeCache;
|