Skip to content

Commit 9daf20d

Browse files
committed
Merge branch 'sei-jmattson-multicast-ttl'
2 parents 81833f1 + c371dcc commit 9daf20d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

docs/configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ PyTAK has the following built-in configuration parameters:
6969

7070
For systems with multiple IP network interfaces, specifies which IP interface to use for the multicast group.
7171

72+
* **`PYTAK_MULTICAST_TTL`**
73+
* Default: `1`
74+
75+
For clients that are more than one hop away from the TAK broadcast network, specifies the time-to-live (TTL) of multicast packets. This is helpful when the client is hosted in a virtual machine or container with an overlay network.
76+
7277
* **`PYTAK_NO_HELLO`**
7378
* Default: `False`
7479

src/pytak/client_functions.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ async def protocol_factory( # NOQA pylint: disable=too-many-locals,too-many-bra
102102
),
103103
0,
104104
)
105-
reader, writer = await pytak.create_udp_client(cot_url, local_addr)
105+
multicast_ttl = config.get("PYTAK_MULTICAST_TTL", 1)
106+
reader, writer = await pytak.create_udp_client(cot_url, local_addr, multicast_ttl)
106107

107108
# LOG
108109
elif "log" in scheme:
@@ -124,7 +125,7 @@ async def protocol_factory( # NOQA pylint: disable=too-many-locals,too-many-bra
124125

125126

126127
async def create_udp_client(
127-
url: ParseResult, local_addr=None
128+
url: ParseResult, local_addr=None, multicast_ttl=1
128129
) -> Tuple[Union[DatagramClient, None], DatagramClient]:
129130
"""Create an AsyncIO UDP network client for Unicast, Broadcast & Multicast.
130131
@@ -164,6 +165,11 @@ async def create_udp_client(
164165
if is_broadcast:
165166
writer.socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
166167

168+
if is_multicast:
169+
writer.socket.setsockopt(
170+
socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack("b", multicast_ttl)
171+
)
172+
167173
if is_write_only:
168174
return reader, writer
169175

@@ -201,11 +207,7 @@ async def create_udp_client(
201207
)
202208
group = int(ipaddress.IPv4Address(host))
203209
mreq = struct.pack("!LL", group, ip)
204-
205210
reader.socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
206-
reader.socket.setsockopt(
207-
socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack("b", 1)
208-
)
209211

210212
return reader, writer
211213

0 commit comments

Comments
 (0)