Skip to content

Commit 1a66716

Browse files
committed
selectively set network interface based on platform
1 parent faf0a99 commit 1a66716

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/software/thunderscope/binary_context_managers/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ py_library(
2323
"//proto:import_all_protos",
2424
"//software/networking:ssl_proto_communication",
2525
"//software/thunderscope/common:thread_safe_circular_buffer",
26+
"//software/thunderscope:util",
2627
],
2728
)
2829

src/software/thunderscope/binary_context_managers/game_controller.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import random
55
import logging
66
import os
7-
import socket
87
import time
98
from subprocess import Popen
109
from typing import Any
@@ -21,6 +20,7 @@
2120
from software.thunderscope.common.thread_safe_circular_buffer import (
2221
ThreadSafeCircularBuffer,
2322
)
23+
from software.thunderscope.util import is_current_platform_macos
2424

2525
logger = logging.getLogger(__name__)
2626
import itertools
@@ -288,10 +288,16 @@ def __send_referee_command(data: Referee) -> None:
288288
if autoref_proto_unix_io is not None:
289289
autoref_proto_unix_io.send_proto(Referee, data)
290290

291+
292+
if is_current_platform_macos():
293+
loopback_iface = "en0"
294+
else:
295+
loopback_iface = "lo"
296+
291297
self.receive_referee_command = tbots_cpp.SSLRefereeProtoListener(
292298
Gamecontroller.REFEREE_IP,
293299
self.referee_port,
294-
"lo",
300+
loopback_iface,
295301
__send_referee_command,
296302
True,
297303
)

src/software/thunderscope/util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import platform
12
from typing import Callable, NoReturn, TYPE_CHECKING
23

34
if TYPE_CHECKING:
@@ -195,3 +196,10 @@ def color_from_gradient(
195196
int(b_range[i] + (b_range[i + 1] - b_range[i]) * sig_val),
196197
int(a_range[i] + (a_range[i + 1] - a_range[i]) * sig_val),
197198
)
199+
200+
def is_current_platform_macos() -> bool:
201+
"""
202+
Return True if the current process is running on macOS.
203+
Uses platform.system(), which should reliably return 'Darwin' on macOS.
204+
"""
205+
return platform.system().lower() == "darwin"

0 commit comments

Comments
 (0)