Skip to content
Snippets Groups Projects
Commit 9cbe9c81 authored by inso's avatar inso
Browse files

Fix identity lookup going in infinite loop

parent 42acb595
No related branches found
No related tags found
No related merge requests found
...@@ -45,11 +45,10 @@ class IdentitiesRegistry: ...@@ -45,11 +45,10 @@ class IdentitiesRegistry:
return {'registry': identities_json} return {'registry': identities_json}
@asyncio.coroutine @asyncio.coroutine
def future_find(self, pubkey, community): def _find_by_lookup(self, pubkey, community):
def lookup(): identity = self._instances[pubkey]
nonlocal identity
lookup_tries = 0 lookup_tries = 0
while lookup_tries < 3 and identity.local_state == LocalState.NOT_FOUND: while lookup_tries < 3:
try: try:
data = yield from community.bma_access.simple_request(bma.wot.Lookup, data = yield from community.bma_access.simple_request(bma.wot.Lookup,
req_args={'search': pubkey}) req_args={'search': pubkey})
...@@ -65,6 +64,7 @@ class IdentitiesRegistry: ...@@ -65,6 +64,7 @@ class IdentitiesRegistry:
identity.uid = identity_uid identity.uid = identity_uid
identity.blockchain_state = BlockchainState.BUFFERED identity.blockchain_state = BlockchainState.BUFFERED
identity.local_state = LocalState.PARTIAL identity.local_state = LocalState.PARTIAL
return identity
logging.debug("Lookup : found {0}".format(identity)) logging.debug("Lookup : found {0}".format(identity))
except ValueError as e: except ValueError as e:
lookup_tries += 1 lookup_tries += 1
...@@ -74,7 +74,10 @@ class IdentitiesRegistry: ...@@ -74,7 +74,10 @@ class IdentitiesRegistry:
lookup_tries += 1 lookup_tries += 1
except NoPeerAvailable: except NoPeerAvailable:
return identity return identity
return identity
@asyncio.coroutine
def future_find(self, pubkey, community):
if pubkey in self._instances: if pubkey in self._instances:
identity = self._instances[pubkey] identity = self._instances[pubkey]
else: else:
...@@ -89,7 +92,7 @@ class IdentitiesRegistry: ...@@ -89,7 +92,7 @@ class IdentitiesRegistry:
identity.blockchain_state = BlockchainState.VALIDATED identity.blockchain_state = BlockchainState.VALIDATED
except ValueError as e: except ValueError as e:
if '404' in str(e) or '400' in str(e): if '404' in str(e) or '400' in str(e):
yield from lookup() identity = yield from self._find_by_lookup(pubkey, community)
return identity return identity
else: else:
tries += 1 tries += 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment