Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix community bootstrap #1319

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions ipv8/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,19 @@ def add_message_handler(self, msg_num: int | type[Payload], callback: MessageHan
actual_msg_num: int = 256
if not isinstance(msg_num, int):
if not hasattr(msg_num, "msg_id"):
raise RuntimeError("Attempted to add a handler for Payload %s, which does not specify a msg_id!"
% msg_num)
msg = f"Attempted to add a handler for Payload {msg_num}, which does not specify a msg_id!"
raise RuntimeError(msg)
actual_msg_num = cast(int, msg_num.msg_id) # type: ignore[attr-defined]
else:
if msg_num < 0 or msg_num > 255:
raise RuntimeError("Attempted to add a handler for message number %d, which is not a byte!" % msg_num)
msg = f"Attempted to add a handler for message number {msg_num}, which is not a byte!"
raise RuntimeError(msg)
actual_msg_num = msg_num

if self.decode_map[actual_msg_num]:
raise RuntimeError("Attempted to add a handler for message number %d, already mapped to %s!" %
(actual_msg_num, self.decode_map[actual_msg_num]))
msg = (f"Attempted to add a handler for message number {actual_msg_num}, "
f"already mapped to {self.decode_map[actual_msg_num]}!")
raise RuntimeError(msg)
self.decode_map[actual_msg_num] = callback

def on_deprecated_message(self, source_address: Address, data: bytes) -> None:
Expand All @@ -221,7 +223,7 @@ async def _bootstrap(self, bootstrapper: Bootstrapper) -> None:
task = ensure_future(bootstrapper.initialize(self))

addresses = await bootstrapper.get_addresses(self, 60.0)
for address in (addresses if self.max_peers > 0 else islice(addresses, self.max_peers)):
for address in (islice(addresses, self.max_peers) if self.max_peers > 0 else addresses):
self.walk_to(address)

await task
Expand Down