This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Piotr Krysik gerrit-no-reply at lists.osmocom.orgPiotr Krysik has submitted this change and it was merged. ( https://gerrit.osmocom.org/10423 )
Change subject: trx/ctrl_if.py: send control responses to where commands are from
......................................................................
trx/ctrl_if.py: send control responses to where commands are from
When we receive a control command, we should not simply send the
response to the default destination, but send it back to the exact
IP/prt from which the command originated.
This ensures correct routing of responses even in case multiple
programs are interfacing concurrently with a control socket.
Cherry-picked from: I24a0bba6eed059b101af95dac7d059f34dd715fc
Change-Id: I1f304ea887dc957d3ad53adb1e3c56ab27d8f196
---
M python/trx/ctrl_if.py
M python/trx/udp_link.py
2 files changed, 12 insertions(+), 9 deletions(-)
Approvals:
Piotr Krysik: Looks good to me, approved; Verified
diff --git a/python/trx/ctrl_if.py b/python/trx/ctrl_if.py
index 7dee0f8..ae5cf05 100644
--- a/python/trx/ctrl_if.py
+++ b/python/trx/ctrl_if.py
@@ -25,15 +25,15 @@
from grgsm.trx import udp_link
class ctrl_if(udp_link):
- def handle_rx(self, data):
+ def handle_rx(self, data, remote):
if self.verify_req(data):
request = self.prepare_req(data)
rc = self.parse_cmd(request)
if type(rc) is tuple:
- self.send_response(request, rc[0], rc[1])
+ self.send_response(request, remote, rc[0], rc[1])
else:
- self.send_response(request, rc)
+ self.send_response(request, remote, rc)
else:
print("[!] Wrong data on CTRL interface")
@@ -65,7 +65,7 @@
return True
- def send_response(self, request, response_code, params = None):
+ def send_response(self, request, remote, response_code, params = None):
# Include status code, for example ["TXTUNE", "0", "941600"]
request.insert(1, str(response_code))
@@ -76,7 +76,7 @@
# Add the response signature, and join back to string
response = "RSP " + " ".join(request) + "\0"
# Now we have something like "RSP TXTUNE 0 941600"
- self.send(response)
+ self.send(response, remote)
def parse_cmd(self, request):
raise NotImplementedError
diff --git a/python/trx/udp_link.py b/python/trx/udp_link.py
index 1fae8b4..d96a6aa 100644
--- a/python/trx/udp_link.py
+++ b/python/trx/udp_link.py
@@ -45,13 +45,16 @@
# Check for incoming data
if self.sock in r_event:
data, addr = self.sock.recvfrom(128)
- self.handle_rx(data.decode())
+ self.handle_rx(data.decode(), addr)
- def send(self, data):
+ def send(self, data, remote = None):
if type(data) not in [bytearray, bytes]:
data = data.encode()
- self.sock.sendto(data, (self.remote_addr, self.remote_port))
+ if remote is None:
+ remote = (self.remote_addr, self.remote_port)
- def handle_rx(self, data):
+ self.sock.sendto(data, remote)
+
+ def handle_rx(self, data, remote):
raise NotImplementedError
--
To view, visit https://gerrit.osmocom.org/10423
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1f304ea887dc957d3ad53adb1e3c56ab27d8f196
Gerrit-Change-Number: 10423
Gerrit-PatchSet: 2
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Piotr Krysik <ptrkrysik at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180810/9c4dddd2/attachment.htm>