Skip to content

Commit

Permalink
Retry identity REST ports on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink committed Jun 14, 2024
1 parent fb1fd7e commit 5801e90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion doc/basics/identity_tutorial_integration/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from asyncio import run
from base64 import b64encode
from time import sleep

from ipv8.configuration import get_default_configuration
from ipv8.REST.rest_manager import RESTManager
Expand All @@ -21,7 +22,15 @@ async def start_community() -> None:
ipv8 = IPv8(configuration)
await ipv8.start()
rest_manager = RESTManager(ipv8)
await rest_manager.start(14410 + peer_id)

# We REALLY want this particular port, keep trying
keep_trying = True
while keep_trying:
try:
await rest_manager.start(14410 + peer_id)
keep_trying = False
except OSError:
sleep(1.0)

# Print the peer for reference
print("Starting peer", b64encode(ipv8.keys["anonymous id"].mid))
Expand Down
11 changes: 10 additions & 1 deletion doc/deprecated/attestation_tutorial_integration/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from base64 import b64encode
from binascii import unhexlify
from sys import argv
from time import sleep

from ipv8.attestation.identity.community import IdentityCommunity
from ipv8.attestation.wallet.community import AttestationCommunity
Expand Down Expand Up @@ -109,7 +110,15 @@ async def start_communities() -> None:
})
await ipv8.start()
rest_manager = RESTManager(ipv8)
await rest_manager.start(14410 + i)

# We REALLY want this particular port, keep trying
keep_trying = True
while keep_trying:
try:
await rest_manager.start(14410 + i)
keep_trying = False
except OSError:
sleep(1.0)

# Print the peer for reference
print("Starting peer", b64encode(ipv8.keys["anonymous id"].mid))
Expand Down

0 comments on commit 5801e90

Please sign in to comment.