Commit e89f7766 authored by Ondřej Kuzník's avatar Ondřej Kuzník

Fixes to cookie tracking

parent 349af5d0
Pipeline #1048 passed with stage
in 49 seconds
......@@ -48,7 +48,7 @@ def connect_and_setup(uri, config):
conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
if uri.urlscheme == 'ldap':
starttls = config.get('starttls', 'yes')
starttls = config.get('starttls', 'no')
if starttls:
try:
conn.start_tls_s()
......
......@@ -42,11 +42,6 @@ class SyncreplCookie:
if cookie:
self.update(cookie)
if self.rid is None:
self.rid = 0
if self.sid is None:
self.sid = 0
def _parse_csn(self, csn):
return csn.split('#', 3) # time, order, sid, other
......@@ -101,7 +96,7 @@ class SyncreplCookie:
def unparse(self):
"Return the cookie as a string"
cookie = 'rid={:03},sid={:03x}'.format(self.rid, self.sid)
cookie = 'rid={:03},sid={:03x}'.format(self.rid or 0, self.sid or 0)
if self._csnset:
cookie += ',csn='
cookie += ';'.join(sorted(self._csnset.values()))
......@@ -120,7 +115,11 @@ class SyncreplCookie:
return self._csnset[key]
def __sub__(self, cookie):
if cookie is None:
return self.copy()
if not isinstance(cookie, __class__):
logger.error("Got a %r instead of %r", type(cookie), __class__)
raise NotImplementedError
result = self.copy()
......@@ -134,6 +133,9 @@ class SyncreplCookie:
def __and__(self, cookie):
"""The highest cookie contained in both"""
if not cookie:
return cookie
if not isinstance(item, __class__):
raise NotImplementedError
......@@ -153,6 +155,10 @@ class SyncreplCookie:
return self._csnset.keys()
def __contains__(self, item):
"""Is the state described in item contained in this cookie?"""
if item is None:
return True
if not isinstance(item, __class__):
raise NotImplementedError
......
......@@ -80,6 +80,7 @@ class Provider:
cookie_updated = Signal()
state_changed = Signal()
sid_discovered = Signal()
def __init__(self, uri, config, searchbase, scope=ldap0.SCOPE_BASE, cookie=None, mode='refreshAndPersist'):
self.uri = uri
......@@ -127,6 +128,7 @@ class Provider:
logger.debug("Update from ourselves, cookie %s", new_cookie)
if self.sid is None:
self.sid = new_cookie.sid
self.sid_discovered(self.sid)
self.cookie.update(new_cookie)
self.cookie_updated(new_cookie)
......@@ -135,6 +137,7 @@ class Provider:
self.state_changed(self.state)
def _catch_up_event(self, caught_up):
assert self.catching_up_set
diff = self.cookie - self.catching_up_from
if self.catching_up_set & diff == diff:
# we have seen progress on all relevant sids
......
......@@ -58,6 +58,7 @@ class ProviderEntry(urwid.LineBox):
self.provider.cookie_updated.connect(self.cookie_updated)
self.provider.state_changed.connect(self.state_changed)
self.provider.sid_discovered.connect(self.new_sid)
def cookie_updated(self, cookie):
self.body.contents[1:] = [(urwid.Text(csn), self.body.options()) for csn in cookie]
......@@ -65,6 +66,9 @@ class ProviderEntry(urwid.LineBox):
def state_changed(self, new_state):
self.state.set_text(new_state.value)
def new_sid(self, sid):
self.set_title(self.provider.uri + " sid=%03x" % self.provider.sid)
def stop(self):
self.provider.stop()
......
......@@ -55,7 +55,11 @@ class Watchdog:
def clear(self, rearm=False):
if self.set:
self.cleared.emit(self.set)
self.set = False
if self.timer:
self.timer.cancel()
self.timer = None
if rearm:
self.rearm(True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment