Skip to content

Commit

Permalink
Restyled by yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed May 5, 2020
1 parent 1c1a667 commit 2548262
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions other/fun/bootstrap_node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def print_help() -> None:
# first byte is INFO_REQUEST_ID, other bytes don't matter as long as reqest's
# length matches INFO_REQUEST_LENGTH
INFO_REQUEST_PACKET = INFO_PACKET_ID + (
b"0" * (INFO_REQUEST_PACKET_LENGTH - len(INFO_PACKET_ID))
)
b"0" * (INFO_REQUEST_PACKET_LENGTH - len(INFO_PACKET_ID)))

PACKET_ID_LENGTH = len(INFO_PACKET_ID)
# https://github.com/irungentoo/toxcore/blob/881b2d900d1998981fb6b9938ec66012d049635f/other/bootstrap_node_packets.c#L44
Expand Down Expand Up @@ -83,15 +82,11 @@ def main(protocol: str, host: str, port: int) -> None:
try:
data, _ = sock.recvfrom(MAX_INFO_RESPONSE_PACKET_LENGTH)
except socket.timeout:
print(
"The DHT bootstrap node didn't reply in "
+ str(SOCK_TIMEOUT_SECONDS)
+ " sec."
)
print("The DHT bootstrap node didn't reply in " +
str(SOCK_TIMEOUT_SECONDS) + " sec.")
print(
"The likely reason for that is that the DHT bootstrap node is either "
"offline or has no info set."
)
"offline or has no info set.")
sys.exit(2)

packet_id = data[:PACKET_ID_LENGTH]
Expand All @@ -107,14 +102,13 @@ def main(protocol: str, host: str, port: int) -> None:
)
print(
"Are you sure that you are pointing the script at a Tox DHT bootstrap "
"node and that the script is up to date?"
)
"node and that the script is up to date?")
sys.exit(3)

version = int.from_bytes(
data[PACKET_ID_LENGTH : PACKET_ID_LENGTH + VERSION_LENGTH], byteorder="big"
)
motd = data[PACKET_ID_LENGTH + VERSION_LENGTH :].decode("utf-8")
version = int.from_bytes(data[PACKET_ID_LENGTH:PACKET_ID_LENGTH +
VERSION_LENGTH],
byteorder="big")
motd = data[PACKET_ID_LENGTH + VERSION_LENGTH:].decode("utf-8")
print("Version: " + str(version))
print("MOTD: " + motd)
sys.exit(0)
Expand All @@ -126,5 +120,7 @@ def main(protocol: str, host: str, port: int) -> None:
sys.exit(1)

main(
protocol=sys.argv[1], host=sys.argv[2], port=int(sys.argv[3]),
protocol=sys.argv[1],
host=sys.argv[2],
port=int(sys.argv[3]),
)

0 comments on commit 2548262

Please sign in to comment.