Treat receiving chain length None as 0
It appears a receiving chain length set to None just means we haven't received any message for this session yet. It doesn't make sense to spam heartbeats at this stage Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
baf29cb05f
commit
91a04000d7
1 changed files with 3 additions and 4 deletions
|
@ -536,8 +536,8 @@ class XEP_0384(BasePlugin):
|
||||||
if session is None:
|
if session is None:
|
||||||
continue
|
continue
|
||||||
skr = session._DoubleRatchet__skr
|
skr = session._DoubleRatchet__skr
|
||||||
sending = skr.sending_chain_length or -1
|
sending = skr.sending_chain_length or 0
|
||||||
receiving = skr.receiving_chain_length or -1
|
receiving = skr.receiving_chain_length or 0
|
||||||
lengths['sending'].append((did, sending))
|
lengths['sending'].append((did, sending))
|
||||||
lengths['receiving'].append((did, receiving))
|
lengths['receiving'].append((did, receiving))
|
||||||
|
|
||||||
|
@ -556,8 +556,7 @@ class XEP_0384(BasePlugin):
|
||||||
|
|
||||||
receiving_chain_lengths = self._chain_lengths(jid).get('receiving', [])
|
receiving_chain_lengths = self._chain_lengths(jid).get('receiving', [])
|
||||||
lengths = map(lambda d_l: d_l[1], receiving_chain_lengths)
|
lengths = map(lambda d_l: d_l[1], receiving_chain_lengths)
|
||||||
min_length = reduce(lambda x, d_l: min(x, d_l[1]), receiving_chain_lengths, 0) == -1
|
return max(lengths, default=0) > self.heartbeat_after
|
||||||
return min_length == -1 or max(lengths, default=0) > self.heartbeat_after
|
|
||||||
|
|
||||||
async def make_heartbeat(self, jid: JID) -> Message:
|
async def make_heartbeat(self, jid: JID) -> Message:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue