Skip to content

Commit

Permalink
Merge pull request #378 from farmio/tunneling-ia
Browse files Browse the repository at this point in the history
use the IA provided by a tunnelling server only for the current connection
  • Loading branch information
farmio committed Sep 6, 2020
2 parents 6167ba1 + 64edbb6 commit b3415e0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples/example_tunnel.py
Expand Up @@ -18,7 +18,8 @@ async def main():
return

gateway = gateways[0]
src_address = PhysicalAddress("15.15.249")
# an individual address will most likely be assigned by the tunnelling server
xknx.own_address = PhysicalAddress("15.15.249")

print(
"Connecting to {}:{} from {}".format(
Expand All @@ -28,7 +29,6 @@ async def main():

tunnel = Tunnel(
xknx,
src_address,
local_ip=gateway.local_ip,
gateway_ip=gateway.ip_addr,
gateway_port=gateway.port,
Expand Down
2 changes: 0 additions & 2 deletions xknx/io/connect.py
Expand Up @@ -37,5 +37,3 @@ def on_success_hook(self, knxipframe):
"""Set communication channel and identifier after having received a valid answer."""
self.communication_channel = knxipframe.body.communication_channel
self.identifier = knxipframe.body.identifier
# Use the address they gave us
self.xknx.own_address.raw = self.identifier
1 change: 0 additions & 1 deletion xknx/io/knxip_interface.py
Expand Up @@ -140,7 +140,6 @@ async def start_tunnelling(
)
self.interface = Tunnel(
self.xknx,
self.xknx.own_address,
local_ip=local_ip,
gateway_ip=gateway_ip,
gateway_port=gateway_port,
Expand Down
9 changes: 5 additions & 4 deletions xknx/io/tunnel.py
Expand Up @@ -7,7 +7,7 @@

from xknx.exceptions import XKNXException
from xknx.knxip import CEMIMessageCode, KNXIPFrame, KNXIPServiceType, TunnellingRequest
from xknx.telegram import TelegramDirection
from xknx.telegram import PhysicalAddress, TelegramDirection

from .connect import Connect
from .connectionstate import ConnectionState
Expand All @@ -24,7 +24,6 @@ class Tunnel:
def __init__(
self,
xknx,
src_address,
local_ip,
gateway_ip,
gateway_port,
Expand All @@ -35,7 +34,6 @@ def __init__(
"""Initialize Tunnel class."""
# pylint: disable=too-many-arguments
self.xknx = xknx
self.src_address = src_address
self.local_ip = local_ip
self.gateway_ip = gateway_ip
self.gateway_port = gateway_port
Expand All @@ -44,6 +42,7 @@ def __init__(
self.udp_client = None
self.init_udp_client()

self._src_address = xknx.own_address
self.sequence_number = 0
self.communication_channel = None
self.number_heartbeat_failed = 0
Expand Down Expand Up @@ -124,6 +123,8 @@ async def connect(self):
)
self._reconnect_task = None
self.communication_channel = connect.communication_channel
# Use the individual address provided by the tunnelling server
self._src_address = PhysicalAddress(connect.identifier)
self.sequence_number = 0
await self.start_heartbeat()

Expand Down Expand Up @@ -164,7 +165,7 @@ async def _send_telegram_impl(self, telegram):
self.xknx,
self.udp_client,
telegram,
self.src_address,
self._src_address,
self.sequence_number,
self.communication_channel,
)
Expand Down

0 comments on commit b3415e0

Please sign in to comment.