From 80832e8abc78615680d2fa8d4d3cd2adaa09fd66 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 21 May 2022 17:56:08 +0100 Subject: [PATCH 001/128] add build for extrastats --- .gitlab-ci.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b9c1a77..d730c82 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,6 +31,21 @@ build-dev: # This job runs in the build stage, which runs first. only: - master +build-extrastats: # This job runs in the build stage, which runs first. + stage: build + tags: + - buildx + script: + - echo "Compiling the code..." + - cd docker-configs + - docker buildx build --no-cache -f Dockerfile-proxy -t hacknix/freedmr:development-latest -t gitlab.hacknix.net:5050/hacknix/freedmr-extrastats:development-latest --platform linux/arm/v7,linux/amd64,linux/i386,linux/arm64 --push . + + + + - echo "Compile complete." + only: + - extrastats + build-release: # This job runs in the build stage, which runs first. stage: build tags: From 09955eb8ac283b047efab7935ca236ef15dca7ff Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 21 May 2022 17:59:16 +0100 Subject: [PATCH 002/128] Revert "add build for extrastats" This reverts commit b33d4d07f403fff14ffc7de3d03efdccd040a04e. --- .gitlab-ci.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d730c82..b9c1a77 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,21 +31,6 @@ build-dev: # This job runs in the build stage, which runs first. only: - master -build-extrastats: # This job runs in the build stage, which runs first. - stage: build - tags: - - buildx - script: - - echo "Compiling the code..." - - cd docker-configs - - docker buildx build --no-cache -f Dockerfile-proxy -t hacknix/freedmr:development-latest -t gitlab.hacknix.net:5050/hacknix/freedmr-extrastats:development-latest --platform linux/arm/v7,linux/amd64,linux/i386,linux/arm64 --push . - - - - - echo "Compile complete." - only: - - extrastats - build-release: # This job runs in the build stage, which runs first. stage: build tags: From fe29bf4bdf4d858e6424a5bd4043031816da289d Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 21 May 2022 18:09:58 +0100 Subject: [PATCH 003/128] Revert "Revert "add build for extrastats"" This reverts commit b5cbf164e9198c3a9ef3235f0e1f06aa263733dc. --- .gitlab-ci.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b9c1a77..d730c82 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,6 +31,21 @@ build-dev: # This job runs in the build stage, which runs first. only: - master +build-extrastats: # This job runs in the build stage, which runs first. + stage: build + tags: + - buildx + script: + - echo "Compiling the code..." + - cd docker-configs + - docker buildx build --no-cache -f Dockerfile-proxy -t hacknix/freedmr:development-latest -t gitlab.hacknix.net:5050/hacknix/freedmr-extrastats:development-latest --platform linux/arm/v7,linux/amd64,linux/i386,linux/arm64 --push . + + + + - echo "Compile complete." + only: + - extrastats + build-release: # This job runs in the build stage, which runs first. stage: build tags: From 9b8f66eaced89a0a72fdb34c0e7287b8e2c93858 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 21 May 2022 22:24:00 +0100 Subject: [PATCH 004/128] s --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d730c82..20ef2be 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,7 +38,7 @@ build-extrastats: # This job runs in the build stage, which runs first. script: - echo "Compiling the code..." - cd docker-configs - - docker buildx build --no-cache -f Dockerfile-proxy -t hacknix/freedmr:development-latest -t gitlab.hacknix.net:5050/hacknix/freedmr-extrastats:development-latest --platform linux/arm/v7,linux/amd64,linux/i386,linux/arm64 --push . + - docker buildx build --no-cache -f Dockerfile-proxy -t hacknix/freedmr:extrastats-development-latest -t gitlab.hacknix.net:5050/hacknix/freedmr:extrastats-development-latest --platform linux/arm64 --push . From 3410438a89e2883f4d6afcd06732655a06ed6f53 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 23 May 2022 22:14:20 +0100 Subject: [PATCH 005/128] Don't allow traffic from servers with SERVER_ID: 0 --- hblink.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hblink.py b/hblink.py index 2c8ba22..cf50b65 100755 --- a/hblink.py +++ b/hblink.py @@ -449,8 +449,7 @@ class OPENBRIDGE(DatagramProtocol): return #Discard bad source server - if ((len(str(int.from_bytes(_source_server,'big'))) < 4) or (len(str(int.from_bytes(_source_server,'big'))) > 7)) and int.from_bytes(_source_server,'big') > 0: - if _stream_id not in self._laststrid: + if ((len(str(int.from_bytes(_source_server,'big'))) < 4) or (len(str(int.from_bytes(_source_server,'big'))) > 7)): logger.warning('(%s) Source Server should be between 4 and 7 digits, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) self.send_bcsq(_dst_id,_stream_id) self._laststrid.append(_stream_id) From 4fb62cf9b16a70c3c104a1e549c960209761ed7e Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 23 May 2022 22:16:27 +0100 Subject: [PATCH 006/128] fix --- hblink.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hblink.py b/hblink.py index cf50b65..d27f736 100755 --- a/hblink.py +++ b/hblink.py @@ -450,6 +450,7 @@ class OPENBRIDGE(DatagramProtocol): #Discard bad source server if ((len(str(int.from_bytes(_source_server,'big'))) < 4) or (len(str(int.from_bytes(_source_server,'big'))) > 7)): + if _stream_id not in self._laststrid: logger.warning('(%s) Source Server should be between 4 and 7 digits, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) self.send_bcsq(_dst_id,_stream_id) self._laststrid.append(_stream_id) From 3129660f34cc4a243c5e18f61ba1b82580d99ebd Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 24 May 2022 12:10:46 +0100 Subject: [PATCH 007/128] Check top-level server IDs for validity: Add this to freedmr.cfg [ALIASES] SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv SERVER_ID_FILE: freedmr_hosts.tsv Also, if you run docker, you may need to map the file outside: touch /etc/freedmr/json/freedmr_hosts.tsv chown 54000:54000 /etc/freedmr/json/freedmr_hosts.tsv then in docker-compose.yml: - '/etc/freedmr/json/server_ids.tsv:/opt/freedmr/server_ids.tsv' --- bridge_master.py | 11 ++++++----- config.py | 5 ++++- hblink.py | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 1f6a876..2d15fc9 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -654,12 +654,12 @@ def threadAlias(): logger.debug('(ALIAS) starting alias thread') reactor.callInThread(aliasb) -def setAlias(_peer_ids,_subscriber_ids, _talkgroup_ids, _local_subscriber_ids): - peer_ids, subscriber_ids, talkgroup_ids,local_subscriber_ids = _peer_ids, _subscriber_ids, _talkgroup_ids, _local_subscriber_ids +def setAlias(_peer_ids,_subscriber_ids, _talkgroup_ids, _local_subscriber_ids, _server_ids): + peer_ids, subscriber_ids, talkgroup_ids,local_subscriber_ids,server_ids = _peer_ids, _subscriber_ids, _talkgroup_ids, _local_subscriber_ids,_server_ids def aliasb(): - _peer_ids, _subscriber_ids, _talkgroup_ids, _local_subscriber_ids = mk_aliases(CONFIG) - reactor.callFromThread(setAlias,_peer_ids, _subscriber_ids, _talkgroup_ids, _local_subscriber_ids) + _peer_ids, _subscriber_ids, _talkgroup_ids, _local_subscriber_ids, _server_ids = mk_aliases(CONFIG) + reactor.callFromThread(setAlias,_peer_ids, _subscriber_ids, _talkgroup_ids, _local_subscriber_ids, _server_ids) def ident(): for system in systems: @@ -2863,7 +2863,7 @@ if __name__ == '__main__': signal.signal(sig, sig_handler) # Create the name-number mapping dictionaries - peer_ids, subscriber_ids, talkgroup_ids, local_subscriber_ids = mk_aliases(CONFIG) + peer_ids, subscriber_ids, talkgroup_ids, local_subscriber_ids, server_ids = mk_aliases(CONFIG) #Add special IDs to DB subscriber_ids[900999] = 'D-APRS' @@ -2872,6 +2872,7 @@ if __name__ == '__main__': CONFIG['_SUB_IDS'] = subscriber_ids CONFIG['_PEER_IDS'] = peer_ids CONFIG['_LOCAL_SUBSCRIBER_IDS'] = local_subscriber_ids + CONFIG['_SERVER_IDS'] = server_ids diff --git a/config.py b/config.py index 260e1a4..9076b8e 100755 --- a/config.py +++ b/config.py @@ -183,7 +183,10 @@ def build_config(_config_file): 'TGID_URL': config.get(section, 'TGID_URL'), 'STALE_TIME': config.getint(section, 'STALE_DAYS') * 86400, 'SUB_MAP_FILE': config.get(section, 'SUB_MAP_FILE'), - 'LOCAL_SUBSCRIBER_FILE': config.get(section, 'LOCAL_SUBSCRIBER_FILE') + 'LOCAL_SUBSCRIBER_FILE': config.get(section, 'LOCAL_SUBSCRIBER_FILE'), + 'SERVER_ID_URL': config.get(section, 'SERVER_ID_URL'), + 'SERVER_ID_FILE': config.get(section, 'SERVER_ID_FILE') + }) elif section == 'MYSQL': diff --git a/hblink.py b/hblink.py index d27f736..0e1bffc 100755 --- a/hblink.py +++ b/hblink.py @@ -62,6 +62,8 @@ import ssl from os.path import isfile, getmtime from urllib.request import urlopen +import csv + logging.TRACE = 5 logging.addLevelName(logging.TRACE, 'TRACE') @@ -455,6 +457,12 @@ class OPENBRIDGE(DatagramProtocol): self.send_bcsq(_dst_id,_stream_id) self._laststrid.append(_stream_id) return + elif (len(str(int.from_bytes(_source_server,'big'))) == 4 or (len(str(int.from_bytes(_source_server,'big'))) == 5)) and ((str(int.from_bytes(_source_server,'big'))[:4]) not in self._CONFIG['_SERVER_IDS'] ): + if _stream_id not in self._laststrid: + logger.warning('(%s) Source Server ID is 4 or 5 digits but not in list: %s', self._system, int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return elif len(str(int.from_bytes(_source_server,'big'))) > 5 and not self.validate_id(_source_server): if _stream_id not in self._laststrid: logger.warning('(%s) Source Server 6 or 7 digits but not a valid DMR ID, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) @@ -1384,6 +1392,19 @@ def try_download(_path, _file, _url, _stale,): return result +#Read list of listed servers from CSV (actually TSV) file +def mk_server_dict(path,filename): + server_ids = {} + try: + with open(path+filename,newline='') as csvfile: + reader = csv.DictReader(csvfile,dialect='excel-tab') + for _row in reader: + server_ids[_row['OPB Net ID']] = _row['Country'] + return(server_ids) + except IOError as err: + logger.warning('ID ALIAS MAPPER: %s could not be read due to IOError: %s',file,err) + return(False) + # ID ALIAS CREATION # Download @@ -1398,6 +1419,10 @@ def mk_aliases(_config): #Try updating tgid aliases file result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['TGID_FILE'], _config['ALIASES']['TGID_URL'], _config['ALIASES']['STALE_TIME']) logger.info('(ALIAS) %s', result) + #Try updating server ids file + result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE'], _config['ALIASES']['SERVER_ID_URL'], _config['ALIASES']['STALE_TIME']) + logger.info('(ALIAS) %s', result) + # Make Dictionaries @@ -1420,10 +1445,13 @@ def mk_aliases(_config): local_subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['LOCAL_SUBSCRIBER_FILE']) if subscriber_ids: logger.info('(ALIAS) ID ALIAS MAPPER: local_subscriber_ids dictionary is available') - + + server_ids = mk_server_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE']) + if server_ids: + logger.info('(ALIAS) ID ALIAS MAPPER: server_ids dictionary is available') - return peer_ids, subscriber_ids, talkgroup_ids, local_subscriber_ids + return peer_ids, subscriber_ids, talkgroup_ids, local_subscriber_ids, server_ids #************************************************ From c629ee8bd3a3b0be6e22e11f7628f6326ab2881c Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 24 May 2022 12:16:46 +0100 Subject: [PATCH 008/128] bug --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 0e1bffc..8d333ed 100755 --- a/hblink.py +++ b/hblink.py @@ -1402,7 +1402,7 @@ def mk_server_dict(path,filename): server_ids[_row['OPB Net ID']] = _row['Country'] return(server_ids) except IOError as err: - logger.warning('ID ALIAS MAPPER: %s could not be read due to IOError: %s',file,err) + logger.warning('ID ALIAS MAPPER: %s could not be read due to IOError: %s',filename,err) return(False) From d391eebbf571cf5f054ac17149f1209eff902ccb Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 24 May 2022 15:05:50 +0100 Subject: [PATCH 009/128] Tidy up --- FreeDMR-SAMPLE-commented.cfg | 5 ++++- FreeDMR-SAMPLE.cfg | 5 ++++- docker-configs/docker_install.sh | 8 ++++++-- loro.cfg | 3 +++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/FreeDMR-SAMPLE-commented.cfg b/FreeDMR-SAMPLE-commented.cfg index 35259e4..7863033 100755 --- a/FreeDMR-SAMPLE-commented.cfg +++ b/FreeDMR-SAMPLE-commented.cfg @@ -112,7 +112,10 @@ PEER_URL: https://www.radioid.net/static/rptrs.json SUBSCRIBER_URL: https://www.radioid.net/static/users.json TGID_URL: http://downloads.freedmr.uk/downloads/talkgroup_ids.json LOCAL_SUBSCRIBER_FILE: local_subcriber_ids.json -STALE_DAYS: 7 +STALE_DAYS: 1 +SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv +SERVER_ID_FILE: server_ids.tsv + #Control server shared allstar instance via dial / AMI [ALLSTAR] diff --git a/FreeDMR-SAMPLE.cfg b/FreeDMR-SAMPLE.cfg index 2a0d88e..c82238d 100755 --- a/FreeDMR-SAMPLE.cfg +++ b/FreeDMR-SAMPLE.cfg @@ -36,8 +36,11 @@ PEER_URL: https://www.radioid.net/static/rptrs.json SUBSCRIBER_URL: https://www.radioid.net/static/users.json TGID_URL: http://downloads.freedmr.uk/downloads/talkgroup_ids.json LOCAL_SUBSCRIBER_FILE: local_subcriber_ids.json -STALE_DAYS: 7 +STALE_DAYS: 1 SUB_MAP_FILE: +SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv +SERVER_ID_FILE: server_ids.tsv + #Control server shared allstar instance via dial / AMI [ALLSTAR] diff --git a/docker-configs/docker_install.sh b/docker-configs/docker_install.sh index 428bc15..99c245c 100755 --- a/docker-configs/docker_install.sh +++ b/docker-configs/docker_install.sh @@ -33,8 +33,9 @@ TGID_TS1_ACL: PERMIT:ALL TGID_TS2_ACL: PERMIT:ALL GEN_STAT_BRIDGES: True ALLOW_NULL_PASSPHRASE: True -ANNOUNCEMENT_LANGUAGES: en_GB,en_GB_2,en_US,es_ES,es_ES_2,fr_FR,de_DE,dk_DK,it_IT,no_NO,pl_PL,se_SE +ANNOUNCEMENT_LANGUAGES: SERVER_ID: 0 +DATA_GATEWAY: False [REPORTS] REPORT: True @@ -57,7 +58,10 @@ TGID_FILE: talkgroup_ids.json PEER_URL: https://www.radioid.net/static/rptrs.json SUBSCRIBER_URL: https://www.radioid.net/static/users.json TGID_URL: TGID_URL: http://downloads.freedmr.uk/downloads/talkgroup_ids.json -STALE_DAYS: 7 +STALE_DAYS: 1 +SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv +SERVER_ID_FILE: server_ids.tsv + #Control server shared allstar instance via dial / AMI [ALLSTAR] diff --git a/loro.cfg b/loro.cfg index 1cd27bc..e9d5b89 100644 --- a/loro.cfg +++ b/loro.cfg @@ -113,6 +113,9 @@ TGID_URL: http://downloads.freedmr.uk/downloads/talkgroup_ids.json LOCAL_SUBSCRIBER_FILE: local_subscriber_ids.json STALE_DAYS: 7 SUB_MAP_FILE: +SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv +SERVER_ID_FILE: server_ids.tsv + #Read further repeater configs from MySQL [MYSQL] From 8aa900feba02718031d8d14db3e771717d18ec81 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 24 May 2022 18:20:03 +0100 Subject: [PATCH 010/128] Add switch for server ID validation: You should add this to [GLOBAL]: VALIDATE_SERVER_IDS: True Please set to True if you are part of FreeDMR network. If you are standalone or private network, You can set it to False if you want. --- config.py | 3 ++- hblink.py | 39 ++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/config.py b/config.py index 9076b8e..e6cf1f8 100755 --- a/config.py +++ b/config.py @@ -147,7 +147,8 @@ def build_config(_config_file): 'ALLOW_NULL_PASSPHRASE': config.getboolean(section, 'ALLOW_NULL_PASSPHRASE'), 'ANNOUNCEMENT_LANGUAGES': config.get(section, 'ANNOUNCEMENT_LANGUAGES'), 'SERVER_ID': config.getint(section, 'SERVER_ID').to_bytes(4, 'big'), - 'DATA_GATEWAY': config.getboolean(section, 'DATA_GATEWAY') + 'DATA_GATEWAY': config.getboolean(section, 'DATA_GATEWAY'), + 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS') }) if not CONFIG['GLOBAL']['ANNOUNCEMENT_LANGUAGES']: diff --git a/hblink.py b/hblink.py index 8d333ed..3a3bf70 100755 --- a/hblink.py +++ b/hblink.py @@ -450,25 +450,26 @@ class OPENBRIDGE(DatagramProtocol): logger.warning('(%s) Packet more than 5s old!, discarding', self._system) return - #Discard bad source server - if ((len(str(int.from_bytes(_source_server,'big'))) < 4) or (len(str(int.from_bytes(_source_server,'big'))) > 7)): - if _stream_id not in self._laststrid: - logger.warning('(%s) Source Server should be between 4 and 7 digits, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - elif (len(str(int.from_bytes(_source_server,'big'))) == 4 or (len(str(int.from_bytes(_source_server,'big'))) == 5)) and ((str(int.from_bytes(_source_server,'big'))[:4]) not in self._CONFIG['_SERVER_IDS'] ): - if _stream_id not in self._laststrid: - logger.warning('(%s) Source Server ID is 4 or 5 digits but not in list: %s', self._system, int.from_bytes(_source_server,'big')) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - elif len(str(int.from_bytes(_source_server,'big'))) > 5 and not self.validate_id(_source_server): - if _stream_id not in self._laststrid: - logger.warning('(%s) Source Server 6 or 7 digits but not a valid DMR ID, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return + if self._CONFIG['GLOBAL']['VALIDATE_SERVER_IDS']: + #Discard bad source server + if ((len(str(int.from_bytes(_source_server,'big'))) < 4) or (len(str(int.from_bytes(_source_server,'big'))) > 7)): + if _stream_id not in self._laststrid: + logger.warning('(%s) Source Server should be between 4 and 7 digits, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + elif (len(str(int.from_bytes(_source_server,'big'))) == 4 or (len(str(int.from_bytes(_source_server,'big'))) == 5)) and ((str(int.from_bytes(_source_server,'big'))[:4]) not in self._CONFIG['_SERVER_IDS'] ): + if _stream_id not in self._laststrid: + logger.warning('(%s) Source Server ID is 4 or 5 digits but not in list: %s', self._system, int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + elif len(str(int.from_bytes(_source_server,'big'))) > 5 and not self.validate_id(_source_server): + if _stream_id not in self._laststrid: + logger.warning('(%s) Source Server 6 or 7 digits but not a valid DMR ID, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return #Increment max hops _inthops = _hops +1 From 5f5c01de27d69433879dd8c45fac150e83de3864 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 01:43:58 +0100 Subject: [PATCH 011/128] end-of-life protocols 2 and 3 --- hblink.py | 111 +++--------------------------------------------------- 1 file changed, 5 insertions(+), 106 deletions(-) diff --git a/hblink.py b/hblink.py index 3a3bf70..626bde5 100755 --- a/hblink.py +++ b/hblink.py @@ -532,112 +532,11 @@ class OPENBRIDGE(DatagramProtocol): elif _packet[:4] == DMRF: - _data = _packet[:53] - _timestamp = _packet[53:60] - _hops = _packet[61] - _hash = _packet[62:] - #_ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest() - _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) - if 'VER' in self._config and self._config['VER'] > 2: - _h.update(_packet[:53]) - elif 'VER' in self._config and self._config['VER'] == 2: - _h.update(_packet[:61]) - - _ckhs = _h.digest() - - if compare_digest(_hash, _ckhs) and (_sockaddr == self._config['TARGET_SOCK'] or self._config['RELAX_CHECKS']): - _peer_id = _data[11:15] - if self._config['NETWORK_ID'] != _peer_id: - logger.error('(%s) OpenBridge packet discarded because NETWORK_ID: %s Does not match sent Peer ID: %s', self._system, int_id(self._config['NETWORK_ID']), int_id(_peer_id)) - return - _seq = _data[4] - _rf_src = _data[5:8] - _dst_id = _data[8:11] - _int_dst_id = int_id(_dst_id) - _bits = _data[15] - _slot = 2 if (_bits & 0x80) else 1 - #_call_type = 'unit' if (_bits & 0x40) else 'group' - if _bits & 0x40: - _call_type = 'unit' - elif (_bits & 0x23) == 0x23: - _call_type = 'vcsbk' - else: - _call_type = 'group' - _frame_type = (_bits & 0x30) >> 4 - _dtype_vseq = (_bits & 0xF) # data, 1=voice header, 2=voice terminator; voice, 0=burst A ... 5=burst F - _stream_id = _data[16:20] - #logger.debug('(%s) DMRD - Seqence: %s, RF Source: %s, Destination ID: %s', self._system, int_id(_seq), int_id(_rf_src), int_id(_dst_id)) - - #Don't do anything if we are STUNned - if 'STUN' in self._CONFIG: - if _stream_id not in self._laststrid: - logger.warning('(%s) Bridge STUNned, discarding', self._system) - self._laststrid.append(_stream_id) - return - - #Increment max hops - _inthops = _hops +1 - - if _inthops > 10: - logger.warning('(%s) MAX HOPS exceed, dropping. Hops: %s, DST: %s', self._system, _inthops, _int_dst_id) - self.send_bcsq(_dst_id,_stream_id) - return - - - #Low-level TG filtering - if _call_type != 'unit': - _int_dst_id = int_id(_dst_id) - if _int_dst_id <= 79 or (_int_dst_id >= 9990 and _int_dst_id <= 9999) or _int_dst_id == 900999: - if _stream_id not in self._laststrid: - logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY GLOBAL TG FILTER', self._system, int_id(_stream_id), _int_dst_id) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - - # ACL Processing - if self._CONFIG['GLOBAL']['USE_ACL']: - if not acl_check(_rf_src, self._CONFIG['GLOBAL']['SUB_ACL']): - if _stream_id not in self._laststrid: - logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS1 ACL', self._system, int_id(_stream_id), int_id(_rf_src)) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - if _slot == 1 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG1_ACL']): - if _stream_id not in self._laststrid: - logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS1 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - if self._config['USE_ACL']: - if not acl_check(_rf_src, self._config['SUB_ACL']): - if _stream_id not in self._laststrid: - logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY SYSTEM ACL', self._system, int_id(_stream_id), int_id(_rf_src)) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - if not acl_check(_dst_id, self._config['TG1_ACL']): - if _stream_id not in self._laststrid: - logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY SYSTEM ACL', self._system, int_id(_stream_id), int_id(_dst_id)) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - - - - #Remove timestamp from data. For now dmrd_received does not expect it - #Leaving it in screws up the AMBE data - #_data = b''.join([_data[:5],_data[12:]]) - _data = b''.join([DMRD,_data[4:]]) - - _hops = _inthops.to_bytes(1,'big') - # Userland actions -- typically this is the function you subclass for an application - self.dmrd_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data,_hash,_hops) - #Silently treat a DMRD packet like a keepalive - this is because it's traffic and the - #Other end may not have enabled ENAHNCED_OBP - self._config['_bcka'] = time() - else: - h,p = _sockaddr - logger.warning('(%s) FreeBridge HMAC failed, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:61]), len(_packet[61:]), repr(_packet[61:]),h,p) + logger.warning('(%s) *ProtoControl* Protocols 2 and 3 are no longer supported',self._system) + if _stream_id not in self._laststrid: + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return if self._config['ENHANCED_OBP']: if _packet[:2] == BC: # Bridge Control packet (Extended OBP) From 6b0c430662cbe213a56cef687c87bc2f669c61e9 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 01:46:52 +0100 Subject: [PATCH 012/128] fix log spamming --- hblink.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hblink.py b/hblink.py index 626bde5..9a933e8 100755 --- a/hblink.py +++ b/hblink.py @@ -532,6 +532,7 @@ class OPENBRIDGE(DatagramProtocol): elif _packet[:4] == DMRF: + _stream_id = _data[16:20] logger.warning('(%s) *ProtoControl* Protocols 2 and 3 are no longer supported',self._system) if _stream_id not in self._laststrid: self.send_bcsq(_dst_id,_stream_id) From 32dc7782e1ce7dbc50530f17038a3935b385b61f Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 01:51:53 +0100 Subject: [PATCH 013/128] fix log spamming more --- hblink.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hblink.py b/hblink.py index 9a933e8..8254191 100755 --- a/hblink.py +++ b/hblink.py @@ -532,9 +532,9 @@ class OPENBRIDGE(DatagramProtocol): elif _packet[:4] == DMRF: - _stream_id = _data[16:20] - logger.warning('(%s) *ProtoControl* Protocols 2 and 3 are no longer supported',self._system) + _stream_id = _packet[16:20] if _stream_id not in self._laststrid: + logger.warning('(%s) *ProtoControl* Protocols 2 and 3 are no longer supported',self._system) self.send_bcsq(_dst_id,_stream_id) self._laststrid.append(_stream_id) return From bb2569a89220f33d0aa0c976a3a44fb8e3f0f598 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 02:05:47 +0100 Subject: [PATCH 014/128] Revert "fix log spamming" This reverts commit c9ce8a93c4d2a6c64dcff8bca9f43b3c1b967856. --- hblink.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hblink.py b/hblink.py index 8254191..a55eb43 100755 --- a/hblink.py +++ b/hblink.py @@ -533,6 +533,7 @@ class OPENBRIDGE(DatagramProtocol): elif _packet[:4] == DMRF: _stream_id = _packet[16:20] + if _stream_id not in self._laststrid: logger.warning('(%s) *ProtoControl* Protocols 2 and 3 are no longer supported',self._system) self.send_bcsq(_dst_id,_stream_id) From 2c2a84891f7e187d83f78e3ea97cf94c2a146196 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 02:06:05 +0100 Subject: [PATCH 015/128] Revert "fix log spamming more" This reverts commit 27886112379cc2a0929f8b4c6a6a4fc46bff87a0. --- hblink.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index a55eb43..bf8edb6 100755 --- a/hblink.py +++ b/hblink.py @@ -532,10 +532,11 @@ class OPENBRIDGE(DatagramProtocol): elif _packet[:4] == DMRF: +<<<<<<< HEAD _stream_id = _packet[16:20] + if _stream_id not in self._laststrid: - logger.warning('(%s) *ProtoControl* Protocols 2 and 3 are no longer supported',self._system) self.send_bcsq(_dst_id,_stream_id) self._laststrid.append(_stream_id) return From 3c182213897ae66e38b2ae9a1d64214ecd1e4bfb Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 02:06:28 +0100 Subject: [PATCH 016/128] Revert "end-of-life protocols 2 and 3" This reverts commit fd8bcf6e8155c5c41efbef348130abed27b9690a. --- hblink.py | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 105 insertions(+), 6 deletions(-) diff --git a/hblink.py b/hblink.py index bf8edb6..3f7a64c 100755 --- a/hblink.py +++ b/hblink.py @@ -532,14 +532,113 @@ class OPENBRIDGE(DatagramProtocol): elif _packet[:4] == DMRF: -<<<<<<< HEAD - _stream_id = _packet[16:20] + _data = _packet[:53] + _timestamp = _packet[53:60] + _hops = _packet[61] + _hash = _packet[62:] + #_ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest() + _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) + if 'VER' in self._config and self._config['VER'] > 2: + _h.update(_packet[:53]) + elif 'VER' in self._config and self._config['VER'] == 2: + _h.update(_packet[:61]) + + _ckhs = _h.digest() + if compare_digest(_hash, _ckhs) and (_sockaddr == self._config['TARGET_SOCK'] or self._config['RELAX_CHECKS']): + _peer_id = _data[11:15] + if self._config['NETWORK_ID'] != _peer_id: + logger.error('(%s) OpenBridge packet discarded because NETWORK_ID: %s Does not match sent Peer ID: %s', self._system, int_id(self._config['NETWORK_ID']), int_id(_peer_id)) + return + _seq = _data[4] + _rf_src = _data[5:8] + _dst_id = _data[8:11] + _int_dst_id = int_id(_dst_id) + _bits = _data[15] + _slot = 2 if (_bits & 0x80) else 1 + #_call_type = 'unit' if (_bits & 0x40) else 'group' + if _bits & 0x40: + _call_type = 'unit' + elif (_bits & 0x23) == 0x23: + _call_type = 'vcsbk' + else: + _call_type = 'group' + _frame_type = (_bits & 0x30) >> 4 + _dtype_vseq = (_bits & 0xF) # data, 1=voice header, 2=voice terminator; voice, 0=burst A ... 5=burst F + _stream_id = _data[16:20] + #logger.debug('(%s) DMRD - Seqence: %s, RF Source: %s, Destination ID: %s', self._system, int_id(_seq), int_id(_rf_src), int_id(_dst_id)) + + #Don't do anything if we are STUNned + if 'STUN' in self._CONFIG: + if _stream_id not in self._laststrid: + logger.warning('(%s) Bridge STUNned, discarding', self._system) + self._laststrid.append(_stream_id) + return + + #Increment max hops + _inthops = _hops +1 + + if _inthops > 10: + logger.warning('(%s) MAX HOPS exceed, dropping. Hops: %s, DST: %s', self._system, _inthops, _int_dst_id) + self.send_bcsq(_dst_id,_stream_id) + return + + + #Low-level TG filtering + if _call_type != 'unit': + _int_dst_id = int_id(_dst_id) + if _int_dst_id <= 79 or (_int_dst_id >= 9990 and _int_dst_id <= 9999) or _int_dst_id == 900999: + if _stream_id not in self._laststrid: + logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY GLOBAL TG FILTER', self._system, int_id(_stream_id), _int_dst_id) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + + # ACL Processing + if self._CONFIG['GLOBAL']['USE_ACL']: + if not acl_check(_rf_src, self._CONFIG['GLOBAL']['SUB_ACL']): + if _stream_id not in self._laststrid: + logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS1 ACL', self._system, int_id(_stream_id), int_id(_rf_src)) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + if _slot == 1 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG1_ACL']): + if _stream_id not in self._laststrid: + logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS1 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + if self._config['USE_ACL']: + if not acl_check(_rf_src, self._config['SUB_ACL']): + if _stream_id not in self._laststrid: + logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY SYSTEM ACL', self._system, int_id(_stream_id), int_id(_rf_src)) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + if not acl_check(_dst_id, self._config['TG1_ACL']): + if _stream_id not in self._laststrid: + logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY SYSTEM ACL', self._system, int_id(_stream_id), int_id(_dst_id)) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + - if _stream_id not in self._laststrid: - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return + + #Remove timestamp from data. For now dmrd_received does not expect it + #Leaving it in screws up the AMBE data + #_data = b''.join([_data[:5],_data[12:]]) + _data = b''.join([DMRD,_data[4:]]) + + _hops = _inthops.to_bytes(1,'big') + # Userland actions -- typically this is the function you subclass for an application + self.dmrd_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data,_hash,_hops) + #Silently treat a DMRD packet like a keepalive - this is because it's traffic and the + #Other end may not have enabled ENAHNCED_OBP + self._config['_bcka'] = time() + else: + h,p = _sockaddr + logger.warning('(%s) FreeBridge HMAC failed, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:61]), len(_packet[61:]), repr(_packet[61:]),h,p) +>>>>>>> parent of fd8bcf6 (end-of-life protocols 2 and 3) if self._config['ENHANCED_OBP']: if _packet[:2] == BC: # Bridge Control packet (Extended OBP) From 8e223af2f716bd8da8bcbfc6407177552a3eb03e Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 02:08:53 +0100 Subject: [PATCH 017/128] dd --- hblink.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hblink.py b/hblink.py index 3f7a64c..3a3bf70 100755 --- a/hblink.py +++ b/hblink.py @@ -638,7 +638,6 @@ class OPENBRIDGE(DatagramProtocol): else: h,p = _sockaddr logger.warning('(%s) FreeBridge HMAC failed, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:61]), len(_packet[61:]), repr(_packet[61:]),h,p) ->>>>>>> parent of fd8bcf6 (end-of-life protocols 2 and 3) if self._config['ENHANCED_OBP']: if _packet[:2] == BC: # Bridge Control packet (Extended OBP) From c2fd4cf23c6785df9943fec9ed575f38688ee534 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 18:41:29 +0100 Subject: [PATCH 018/128] tweak validate ID --- hblink.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/hblink.py b/hblink.py index 3a3bf70..ce58794 100755 --- a/hblink.py +++ b/hblink.py @@ -450,26 +450,25 @@ class OPENBRIDGE(DatagramProtocol): logger.warning('(%s) Packet more than 5s old!, discarding', self._system) return - if self._CONFIG['GLOBAL']['VALIDATE_SERVER_IDS']: - #Discard bad source server - if ((len(str(int.from_bytes(_source_server,'big'))) < 4) or (len(str(int.from_bytes(_source_server,'big'))) > 7)): - if _stream_id not in self._laststrid: - logger.warning('(%s) Source Server should be between 4 and 7 digits, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - elif (len(str(int.from_bytes(_source_server,'big'))) == 4 or (len(str(int.from_bytes(_source_server,'big'))) == 5)) and ((str(int.from_bytes(_source_server,'big'))[:4]) not in self._CONFIG['_SERVER_IDS'] ): - if _stream_id not in self._laststrid: - logger.warning('(%s) Source Server ID is 4 or 5 digits but not in list: %s', self._system, int.from_bytes(_source_server,'big')) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return - elif len(str(int.from_bytes(_source_server,'big'))) > 5 and not self.validate_id(_source_server): - if _stream_id not in self._laststrid: - logger.warning('(%s) Source Server 6 or 7 digits but not a valid DMR ID, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) - return + #Discard bad source server + if ((len(str(int.from_bytes(_source_server,'big'))) < 4) or (len(str(int.from_bytes(_source_server,'big'))) > 7)): + if _stream_id not in self._laststrid: + logger.warning('(%s) Source Server should be between 4 and 7 digits, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + elif self._CONFIG['GLOBAL']['VALIDATE_SERVER_IDS'] and (len(str(int.from_bytes(_source_server,'big'))) == 4 or (len(str(int.from_bytes(_source_server,'big'))) == 5)) and ((str(int.from_bytes(_source_server,'big'))[:4]) not in self._CONFIG['_SERVER_IDS'] ): + if _stream_id not in self._laststrid: + logger.warning('(%s) Source Server ID is 4 or 5 digits but not in list: %s', self._system, int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return + elif len(str(int.from_bytes(_source_server,'big'))) > 5 and not self.validate_id(_source_server): + if _stream_id not in self._laststrid: + logger.warning('(%s) Source Server 6 or 7 digits but not a valid DMR ID, discarding Src: %s', self._system, int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) + return #Increment max hops _inthops = _hops +1 From 6535c22f21df7a7716e042d92dcf0f5ab9786a4a Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 23:25:36 +0100 Subject: [PATCH 019/128] fix bridge --- bridge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge.py b/bridge.py index 1fddf49..9535bdc 100755 --- a/bridge.py +++ b/bridge.py @@ -941,7 +941,7 @@ if __name__ == '__main__': signal.signal(sig, sig_handler) # Create the name-number mapping dictionaries - peer_ids, subscriber_ids, talkgroup_ids, local_subscriber_ids = mk_aliases(CONFIG) + peer_ids, subscriber_ids, talkgroup_ids, local_subscriber_ids,server_ids = mk_aliases(CONFIG) # Import the ruiles file as a module, and create BRIDGES from it spec = importlib.util.spec_from_file_location("module.name", cli_args.RULES_FILE) From 31545ad10a498fce0b30cb5ff456379d5a0dd1b2 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 23:30:11 +0100 Subject: [PATCH 020/128] fix parrot --- loro.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loro.cfg b/loro.cfg index e9d5b89..47ba000 100644 --- a/loro.cfg +++ b/loro.cfg @@ -115,7 +115,7 @@ STALE_DAYS: 7 SUB_MAP_FILE: SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv SERVER_ID_FILE: server_ids.tsv - +VALIDATE_SERVER_IDS: True #Read further repeater configs from MySQL [MYSQL] From 12a2124fe4330da5864016ae6002ac63dde8fe5b Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 May 2022 23:30:43 +0100 Subject: [PATCH 021/128] ff --- loro.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loro.cfg b/loro.cfg index 47ba000..1603072 100644 --- a/loro.cfg +++ b/loro.cfg @@ -50,6 +50,7 @@ ALLOW_NULL_PASSPHRASE: False ANNOUNCEMENT_LANGUAGES: es_ES SERVER_ID: 9990 DATA_GATEWAY: False +VALIDATE_SERVER_IDS: True @@ -115,7 +116,6 @@ STALE_DAYS: 7 SUB_MAP_FILE: SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv SERVER_ID_FILE: server_ids.tsv -VALIDATE_SERVER_IDS: True #Read further repeater configs from MySQL [MYSQL] From f9736ab6830dd2a16895adfc68e55db3ba65d1c1 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 26 May 2022 00:38:29 +0100 Subject: [PATCH 022/128] false --- loro.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loro.cfg b/loro.cfg index 1603072..89fca9a 100644 --- a/loro.cfg +++ b/loro.cfg @@ -50,7 +50,7 @@ ALLOW_NULL_PASSPHRASE: False ANNOUNCEMENT_LANGUAGES: es_ES SERVER_ID: 9990 DATA_GATEWAY: False -VALIDATE_SERVER_IDS: True +VALIDATE_SERVER_IDS: False From 7c268806519129313a7f9f98e69947c28eca0fd0 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 27 May 2022 23:53:05 +0100 Subject: [PATCH 023/128] fix bridge mode --- bridge.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bridge.py b/bridge.py index 9535bdc..735445d 100755 --- a/bridge.py +++ b/bridge.py @@ -943,6 +943,15 @@ if __name__ == '__main__': # Create the name-number mapping dictionaries peer_ids, subscriber_ids, talkgroup_ids, local_subscriber_ids,server_ids = mk_aliases(CONFIG) + #Add special IDs to DB + subscriber_ids[900999] = 'D-APRS' + subscriber_ids[4294967295] = 'SC' + + CONFIG['_SUB_IDS'] = subscriber_ids + CONFIG['_PEER_IDS'] = peer_ids + CONFIG['_LOCAL_SUBSCRIBER_IDS'] = local_subscriber_ids + CONFIG['_SERVER_IDS'] = server_ids + # Import the ruiles file as a module, and create BRIDGES from it spec = importlib.util.spec_from_file_location("module.name", cli_args.RULES_FILE) rules_module = importlib.util.module_from_spec(spec) From 1a8100714808a21bc4096d6b3e77a2839eaaaac6 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 15 Jun 2022 00:58:18 +0100 Subject: [PATCH 024/128] Only send ident if the slot has been idle for at least 30 seconds for RX and TX. --- bridge_master.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 2d15fc9..28f87bb 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -680,7 +680,7 @@ def ident(): _slot = systems[system].STATUS[2] #If slot is idle for RX and TX #print("RX:"+str(_slot['RX_TYPE'])+" TX:"+str(_slot['TX_TYPE'])+" TIME:"+str(time() - _slot['TX_TIME'])) - if (_slot['RX_TYPE'] == HBPF_SLT_VTERM) and (_slot['TX_TYPE'] == HBPF_SLT_VTERM) and (time() - _slot['TX_TIME'] > CONFIG['SYSTEMS'][system]['GROUP_HANGTIME']): + if (_slot['RX_TYPE'] == HBPF_SLT_VTERM) and (_slot['TX_TYPE'] == HBPF_SLT_VTERM) and (time() - _slot['TX_TIME'] > 30 and time() - _slot['RX_TIME'] > 30): #_stream_id = hex_str_4(1234567) logger.info('(%s) System idle. Sending voice ident',system) _say = [words[_lang]['silence']] @@ -713,7 +713,8 @@ def ident(): #_say.append(AMBEobj.readSingleFile('alpha.ambe')) _all_call = bytes_3(16777215) _source_id= bytes_3(5000) - speech = pkt_gen(_source_id, _all_call, bytes_4(16777215), 1, _say) + _peer_id = bytes_4(self._CONFIG['GLOBAL']['SERVER_ID']) + speech = pkt_gen(_source_id, _all_call, _peer_id, 1, _say) sleep(1) _slot = systems[system].STATUS[2] From 348d08efb88a8cce286643bcc0f1468e08506878 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 15 Jun 2022 01:20:42 +0100 Subject: [PATCH 025/128] Fix bug --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 28f87bb..65c6816 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -713,7 +713,7 @@ def ident(): #_say.append(AMBEobj.readSingleFile('alpha.ambe')) _all_call = bytes_3(16777215) _source_id= bytes_3(5000) - _peer_id = bytes_4(self._CONFIG['GLOBAL']['SERVER_ID']) + _peer_id = bytes_4(CONFIG['GLOBAL']['SERVER_ID']) speech = pkt_gen(_source_id, _all_call, _peer_id, 1, _say) sleep(1) From 6ee6678c93c532c8f7934483d6cda1f2ab5da993 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 14:33:33 +0100 Subject: [PATCH 026/128] First pass - override ident TG --- bridge_master.py | 2 +- report_receiver.py | 33 +++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 65c6816..06c55a5 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2814,7 +2814,7 @@ if __name__ == '__main__': if cli_args.LOG_LEVEL: CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL logger = log.config_logging(CONFIG['LOGGER']) - logger.info('\n\nCopyright (c) 2020, 2021 Simon G7RZU simon@gb7fr.org.uk') + logger.info('\n\nCopyright (c) 2020, 2021, 2022 Simon G7RZU simon@gb7fr.org.uk') logger.info('Copyright (c) 2013, 2014, 2015, 2016, 2018, 2019\n\tThe Regents of the K0USY Group. All rights reserved.\n') logger.debug('(GLOBAL) Logging system started, anything from here on gets logged') diff --git a/report_receiver.py b/report_receiver.py index 5f16c6c..37b8b07 100644 --- a/report_receiver.py +++ b/report_receiver.py @@ -27,6 +27,8 @@ from twisted.protocols.basic import NetstringReceiver from reporting_const import * +from pprint import pprint + class reportClient(NetstringReceiver): def stringReceived(self, data): @@ -34,9 +36,11 @@ class reportClient(NetstringReceiver): if data[:1] == REPORT_OPCODES['BRDG_EVENT']: self.bridgeEvent(data[1:].decode('UTF-8')) elif data[:1] == REPORT_OPCODES['CONFIG_SND']: - self.configSend(data[1:]) + if cli_args.CONFIG: + self.configSend(data[1:]) elif data[:1] == REPORT_OPCODES['BRIDGE_SND']: - self.bridgeSend(data[1:]) + if cli_args.BRIDGES: + self.bridgeSend(data[1:]) elif data == b'bridge updated': pass else: @@ -60,15 +64,19 @@ class reportClient(NetstringReceiver): if len(datalist) > 9: event['duration'] = datalist[9] - print(event) + if cli_args.EVENTS: + pprint(event, compact=True) def bridgeSend(self,data): self.BRIDGES = pickle.loads(data) - print(self.BRIDGES) + if cli_args.WATCH and cli_args.WATCH in self.BRIDGES: + pprint(self.BRIDGES[cli_args.WATCH], compact=True) + else: + pprint(self.BRIDGES, compact=True, indent=4) def configSend(self,data): self.CONFIG = pickle.loads(data) - print(self.CONFIG) + pprint(self.CONFIG, compact=True) @@ -100,6 +108,7 @@ if __name__ == '__main__': import signal import sys import os + import argparse #Set process title early setproctitle(__file__) @@ -110,10 +119,22 @@ if __name__ == '__main__': def sig_handler(_signal, _frame): print('SHUTDOWN: TERMINATING WITH SIGNAL {}'.format(str(_signal))) reactor.stop() + + # CLI argument parser - handles picking up the config file from the command line, and sending a "help" message + parser = argparse.ArgumentParser() + parser.add_argument('-e', '--events', action='store', dest='EVENTS', help='print events [0|1]') + parser.add_argument('-c', '--config', action='store', dest='CONFIG', help='print config [0|1]') + parser.add_argument('-b', '--bridges', action='store', dest='BRIDGES', help='print bridges [0|1]') + parser.add_argument('-w', '--watch', action='store', dest='WATCH', help='watch bridge ') + parser.add_argument('-o', '--host', action='store', dest='HOST', help='host to connect to ') + parser.add_argument('-p', '--port', action='store', dest='PORT', help='port to connect to ') + + + cli_args = parser.parse_args() # Set signal handers so that we can gracefully exit if need be for sig in [signal.SIGINT, signal.SIGTERM]: signal.signal(sig, sig_handler) - reactor.connectTCP(sys.argv[1],int(sys.argv[2]), reportClientFactory(reportClient)) + reactor.connectTCP(cli_args.HOST,int(cli_args.PORT), reportClientFactory(reportClient)) reactor.run() From a4028a8b68619d4a77158463405566eabea9ee6e Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 14:36:05 +0100 Subject: [PATCH 027/128] Server ID was already bytes_4 --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 65c6816..de84fc2 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -713,7 +713,7 @@ def ident(): #_say.append(AMBEobj.readSingleFile('alpha.ambe')) _all_call = bytes_3(16777215) _source_id= bytes_3(5000) - _peer_id = bytes_4(CONFIG['GLOBAL']['SERVER_ID']) + _peer_id = CONFIG['GLOBAL']['SERVER_ID'] speech = pkt_gen(_source_id, _all_call, _peer_id, 1, _say) sleep(1) From c9864cd87447713eecf12b8e40a8afa163487595 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 14:53:37 +0100 Subject: [PATCH 028/128] fix conflict with stash --- bridge_master.py | 10 ++++++++++ config.py | 3 ++- playback_file.cfg | 3 +++ playback_file.py | 4 ++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 06c55a5..09396a3 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -713,6 +713,14 @@ def ident(): #_say.append(AMBEobj.readSingleFile('alpha.ambe')) _all_call = bytes_3(16777215) _source_id= bytes_3(5000) + + _dst_id = b'' + + if CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']: + _dst_id = bytes_3(OVERRIDE_IDENT_TG) + else: + _dst_id = _all_call + _peer_id = bytes_4(CONFIG['GLOBAL']['SERVER_ID']) speech = pkt_gen(_source_id, _all_call, _peer_id, 1, _say) @@ -760,6 +768,8 @@ def options_config(): _options['TS1_STATIC'] = _options.pop('TS1') if 'TS2' in _options: _options['TS2_STATIC'] = _options.pop('TS2') + if 'VOICETG' in _options: + _options['OVERRIDE_IDENT_TG'] = _options.pop('VOICETG') #DMR+ style options if 'StartRef' in _options: diff --git a/config.py b/config.py index e6cf1f8..15caf6d 100755 --- a/config.py +++ b/config.py @@ -336,7 +336,8 @@ def build_config(_config_file): 'GENERATOR': config.getint(section, 'GENERATOR'), 'ANNOUNCEMENT_LANGUAGE': config.get(section, 'ANNOUNCEMENT_LANGUAGE'), 'ALLOW_UNREG_ID': config.getboolean(section,'ALLOW_UNREG_ID'), - 'PROXY_CONTROL' : config.getboolean(section,'PROXY_CONTROL') + 'PROXY_CONTROL' : config.getboolean(section,'PROXY_CONTROL'), + 'OVERRIDE_IDENT_TG': config.get(section, 'OVERRIDE_IDENT_TG') }}) CONFIG['SYSTEMS'][section].update({'PEERS': {}}) diff --git a/playback_file.cfg b/playback_file.cfg index 47e72d2..89f269d 100644 --- a/playback_file.cfg +++ b/playback_file.cfg @@ -50,6 +50,7 @@ ALLOW_NULL_PASSPHRASE: False ANNOUNCEMENT_LANGUAGES: es_ES SERVER_ID: 9990 DATA_GATEWAY: False +VALIDATE_SERVER_IDS: False @@ -113,6 +114,8 @@ TGID_URL: http://downloads.freedmr.uk/downloads/talkgroup_ids.json LOCAL_SUBSCRIBER_FILE: local_subscriber_ids.json STALE_DAYS: 7 SUB_MAP_FILE: +SERVER_ID_FILE: +SERVER_ID_URL: #Read further repeater configs from MySQL [MYSQL] diff --git a/playback_file.py b/playback_file.py index ffe1bd4..2d13158 100644 --- a/playback_file.py +++ b/playback_file.py @@ -76,8 +76,8 @@ def playFileOnRequest(system,fileName,dstTG,subid): _say.append(AMBEobj.readSingleFile(fileName)) _say.append(SILENCE) _say.append(SILENCE) - except IOError: - logger.warning('(%s) cannot read file %s',system,fileName) + except IOError as err: + logger.warning('(%s) cannot read file %s: %s',system,fileName,err) return speech = pkt_gen(_source_id, _dst_id, bytes_4(5000), 0, _say) sleep(1) From 98e6285926f33d00c97b599ecbb7e2b6cb3c750a Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 14:57:53 +0100 Subject: [PATCH 029/128] Pass of identtg --- bridge_master.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 09396a3..4defac1 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -721,7 +721,7 @@ def ident(): else: _dst_id = _all_call - _peer_id = bytes_4(CONFIG['GLOBAL']['SERVER_ID']) + _peer_id = CONFIG['GLOBAL']['SERVER_ID'] speech = pkt_gen(_source_id, _all_call, _peer_id, 1, _say) sleep(1) @@ -769,7 +769,7 @@ def options_config(): if 'TS2' in _options: _options['TS2_STATIC'] = _options.pop('TS2') if 'VOICETG' in _options: - _options['OVERRIDE_IDENT_TG'] = _options.pop('VOICETG') + _options['OVERRIDE_IDENT_TG'] = _options.pop('IDENTTG') #DMR+ style options if 'StartRef' in _options: @@ -862,9 +862,14 @@ def options_config(): continue if isinstance(_options['DEFAULT_REFLECTOR'], str) and not _options['DEFAULT_REFLECTOR'].isdigit(): - logger.debug('(OPTIONS) %s - DEFAULT_UA_TIMER is not an integer, ignoring',_system) + logger.debug('(OPTIONS) %s - DEFAULT_REFLECTOR is not an integer, ignoring',_system) + continue + + if isinstance(_options['OVERRIDE_IDENT_TG'], str) and not _options['OVERRIDE_IDENT_TG'].isdigit(): + logger.debug('(OPTIONS) %s - OVERRIDE_IDENT_TG is not an integer, ignoring',_system) continue + if isinstance(_options['DEFAULT_UA_TIMER'], str) and not _options['DEFAULT_UA_TIMER'].isdigit(): logger.debug('(OPTIONS) %s - DEFAULT_REFLECTOR is not an integer, ignoring',_system) continue From 909668b49854b79bb37ca6c36871d1306556ce82 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 15:02:38 +0100 Subject: [PATCH 030/128] identtg --- bridge_master.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 4defac1..5bbcd39 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -682,7 +682,16 @@ def ident(): #print("RX:"+str(_slot['RX_TYPE'])+" TX:"+str(_slot['TX_TYPE'])+" TIME:"+str(time() - _slot['TX_TIME'])) if (_slot['RX_TYPE'] == HBPF_SLT_VTERM) and (_slot['TX_TYPE'] == HBPF_SLT_VTERM) and (time() - _slot['TX_TIME'] > 30 and time() - _slot['RX_TIME'] > 30): #_stream_id = hex_str_4(1234567) - logger.info('(%s) System idle. Sending voice ident',system) + _all_call = bytes_3(16777215) + _source_id= bytes_3(5000) + + _dst_id = b'' + + if CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']: + _dst_id = bytes_3(OVERRIDE_IDENT_TG) + else: + _dst_id = _all_call + logger.info('(%s) System idle. Sending voice ident to TG',system,int_id(_dst_id)) _say = [words[_lang]['silence']] _say.append(words[_lang]['silence']) _say.append(words[_lang]['silence']) @@ -711,15 +720,7 @@ def ident(): #test #_say.append(AMBEobj.readSingleFile('alpha.ambe')) - _all_call = bytes_3(16777215) - _source_id= bytes_3(5000) - _dst_id = b'' - - if CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']: - _dst_id = bytes_3(OVERRIDE_IDENT_TG) - else: - _dst_id = _all_call _peer_id = CONFIG['GLOBAL']['SERVER_ID'] speech = pkt_gen(_source_id, _all_call, _peer_id, 1, _say) From a4360b04b65317140cef9ef769ab873c9c9d6d0b Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 15:09:36 +0100 Subject: [PATCH 031/128] falsy --- bridge_master.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 5bbcd39..a5541cd 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -769,7 +769,7 @@ def options_config(): _options['TS1_STATIC'] = _options.pop('TS1') if 'TS2' in _options: _options['TS2_STATIC'] = _options.pop('TS2') - if 'VOICETG' in _options: + if 'IDENTTG' in _options: _options['OVERRIDE_IDENT_TG'] = _options.pop('IDENTTG') #DMR+ style options @@ -825,6 +825,9 @@ def options_config(): if 'DEFAULT_REFLECTOR' not in _options: _options['DEFAULT_REFLECTOR'] = 0 + + if 'OVERRIDE_IDENT_TG' not in _options: + _options['OVERRIDE_IDENT_TG'] = False if 'DEFAULT_UA_TIMER' not in _options: _options['DEFAULT_UA_TIMER'] = CONFIG['SYSTEMS'][_system]['DEFAULT_UA_TIMER'] From 88309b8294f4abea0f75cb868ee37f349d43c2b9 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 15:38:24 +0100 Subject: [PATCH 032/128] If in --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index a5541cd..267d1da 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -687,7 +687,7 @@ def ident(): _dst_id = b'' - if CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']: + if 'OVERRIDE_IDENT_TG' in CONFIG['SYSTEMS'][system] and CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']: _dst_id = bytes_3(OVERRIDE_IDENT_TG) else: _dst_id = _all_call From 0bfea842e17062235dbf428068e1ce33f55d4f39 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 15:44:54 +0100 Subject: [PATCH 033/128] ds --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 267d1da..63297a9 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -688,7 +688,7 @@ def ident(): _dst_id = b'' if 'OVERRIDE_IDENT_TG' in CONFIG['SYSTEMS'][system] and CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']: - _dst_id = bytes_3(OVERRIDE_IDENT_TG) + _dst_id = bytes_3(CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']) else: _dst_id = _all_call logger.info('(%s) System idle. Sending voice ident to TG',system,int_id(_dst_id)) From 28f2f9601704fba5497e3ef0055fc34e2c9a867c Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 16:21:31 +0100 Subject: [PATCH 034/128] convert tg --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 63297a9..da0b8e1 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -691,7 +691,7 @@ def ident(): _dst_id = bytes_3(CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']) else: _dst_id = _all_call - logger.info('(%s) System idle. Sending voice ident to TG',system,int_id(_dst_id)) + logger.info('(%s) System idle. Sending voice ident to TG %s',system,int_id(_dst_id)) _say = [words[_lang]['silence']] _say.append(words[_lang]['silence']) _say.append(words[_lang]['silence']) From bba42852c737d45efa86385ef9b704ab5c473b09 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 18:14:25 +0100 Subject: [PATCH 035/128] Alias ident --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index da0b8e1..088a836 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -691,7 +691,7 @@ def ident(): _dst_id = bytes_3(CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']) else: _dst_id = _all_call - logger.info('(%s) System idle. Sending voice ident to TG %s',system,int_id(_dst_id)) + logger.info('(%s) %s System idle. Sending voice ident to TG %s',_callsign,get_alias(_dst_id,talkgroup_ids)) _say = [words[_lang]['silence']] _say.append(words[_lang]['silence']) _say.append(words[_lang]['silence']) From 3603b3989aa0239ca5712e0b5bc66ada2dc1eed6 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 18:54:36 +0100 Subject: [PATCH 036/128] flarp --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 088a836..4159935 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -691,7 +691,7 @@ def ident(): _dst_id = bytes_3(CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']) else: _dst_id = _all_call - logger.info('(%s) %s System idle. Sending voice ident to TG %s',_callsign,get_alias(_dst_id,talkgroup_ids)) + logger.info('(%s) %s System idle. Sending voice ident to TG %s',_callsign,get_alias(system,_dst_id,talkgroup_ids)) _say = [words[_lang]['silence']] _say.append(words[_lang]['silence']) _say.append(words[_lang]['silence']) From 6b35f923fc92e12dc1f60004ef232bf14ca2c6e4 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 19:13:47 +0100 Subject: [PATCH 037/128] Tidyup in Options --- bridge_master.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 4159935..d5c7dee 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -771,7 +771,11 @@ def options_config(): _options['TS2_STATIC'] = _options.pop('TS2') if 'IDENTTG' in _options: _options['OVERRIDE_IDENT_TG'] = _options.pop('IDENTTG') - + elif 'VOICETG' in _options: + _options['OVERRIDE_IDENT_TG'] = _options.pop('VOICETG') + if 'IDENT' in _options: + _options['VOICE'] = _options.pop('IDENT') + #DMR+ style options if 'StartRef' in _options: _options['DEFAULT_REFLECTOR'] = _options.pop('StartRef') @@ -936,7 +940,7 @@ def options_config(): if CONFIG['SYSTEMS'][_system]['TS2_STATIC']: ts2 = CONFIG['SYSTEMS'][_system]['TS2_STATIC'].split(',') for tg in ts2: - if not tg: + if not tg or int(tg) == 0 or int(tg) >= 16777215: continue tg = int(tg) reset_static_tg(tg,2,_tmout,_system) @@ -944,7 +948,7 @@ def options_config(): if _options['TS2_STATIC']: ts2 = _options['TS2_STATIC'].split(',') for tg in ts2: - if not tg: + if not tg or int(tg) == 0 or int(tg) >= 16777215: continue tg = int(tg) make_static_tg(tg,2,_tmout,_system) @@ -953,8 +957,8 @@ def options_config(): CONFIG['SYSTEMS'][_system]['TS2_STATIC'] = _options['TS2_STATIC'] CONFIG['SYSTEMS'][_system]['DEFAULT_REFLECTOR'] = int(_options['DEFAULT_REFLECTOR']) CONFIG['SYSTEMS'][_system]['DEFAULT_UA_TIMER'] = int(_options['DEFAULT_UA_TIMER']) - except Exception: - logger.exception('(OPTIONS) caught exception:') + except Exception as e: + logger.exception('(OPTIONS) caught exception: %s',e) continue def mysqlGetConfig(): From 333dbbf5aadd33f31afe9aa838dd0e9e0e49ddb0 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 19:32:58 +0100 Subject: [PATCH 038/128] f --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 9cdbb6c..40c924f 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -691,7 +691,7 @@ def ident(): _dst_id = bytes_3(CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']) else: _dst_id = _all_call - logger.info('(%s) %s System idle. Sending voice ident to TG %s',_callsign,get_alias(system,_dst_id,talkgroup_ids)) + logger.info('(%s) %s System idle. Sending voice ident to TG %s',system,_callsign,get_alias(_dst_id,talkgroup_ids)) _say = [words[_lang]['silence']] _say.append(words[_lang]['silence']) _say.append(words[_lang]['silence']) From 9a604464d38ff0273b7399b7c355e5c7a5bb29fd Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 21:43:43 +0100 Subject: [PATCH 039/128] fix parrot config --- loro.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/loro.cfg b/loro.cfg index 89fca9a..2c392ef 100644 --- a/loro.cfg +++ b/loro.cfg @@ -196,4 +196,5 @@ GENERATOR: 1 ANNOUNCEMENT_LANGUAGE:es_ES ALLOW_UNREG_ID: True PROXY_CONTROL: False +OVERRIDE_IDENT_TG: From a0c39e813b388d2aae866b7f8d48f75ca6d849e8 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 22:33:20 +0100 Subject: [PATCH 040/128] fix options parsing for IDENTTG --- bridge_master.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 40c924f..8edd508 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -687,7 +687,7 @@ def ident(): _dst_id = b'' - if 'OVERRIDE_IDENT_TG' in CONFIG['SYSTEMS'][system] and CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']: + if 'OVERRIDE_IDENT_TG' in CONFIG['SYSTEMS'][system] and CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG'] and int(CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']) > 0 and int(CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG'] < 16777215): _dst_id = bytes_3(CONFIG['SYSTEMS'][system]['OVERRIDE_IDENT_TG']) else: _dst_id = _all_call @@ -839,10 +839,15 @@ def options_config(): CONFIG['SYSTEMS'][_system]['VOICE_IDENT'] = bool(int(_options['VOICE'])) logger.debug("(OPTIONS) %s - Setting voice ident to %s",_system,CONFIG['SYSTEMS'][_system]['VOICE_IDENT']) + if 'IDENTTG' in _options and _options['IDENTTG'] and (CONFIG['SYSTEMS'][_system]['OVERRIDE_IDENT_TG'] != int(_options['IDENTTG'])): + CONFIG['SYSTEMS'][_system]['OVERRIDE_IDENT_TG'] = int(_options['IDENTTG']) + logger.debug("(OPTIONS) %s - Setting OVERRIDE_IDENT_TG to %s",_system,CONFIG['SYSTEMS'][_system]['OVERRIDE_IDENT_TG']) + if 'LANG' in _options and _options['LANG'] in words and _options['LANG'] != CONFIG['SYSTEMS'][_system]['ANNOUNCEMENT_LANGUAGE'] : CONFIG['SYSTEMS'][_system]['ANNOUNCEMENT_LANGUAGE'] = _options['LANG'] logger.debug("(OPTIONS) %s - Setting voice language to %s",_system,CONFIG['SYSTEMS'][_system]['ANNOUNCEMENT_LANGUAGE']) + if 'SINGLE' in _options and (CONFIG['SYSTEMS'][_system]['SINGLE_MODE'] != bool(int(_options['SINGLE']))): CONFIG['SYSTEMS'][_system]['SINGLE_MODE'] = bool(int(_options['SINGLE'])) logger.debug("(OPTIONS) %s - Setting SINGLE_MODE to %s",_system,CONFIG['SYSTEMS'][_system]['SINGLE_MODE']) From 9e2682d7644749e53034bd3f31bf1a41a549b16a Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 19 Jun 2022 22:37:09 +0100 Subject: [PATCH 041/128] fix options parsing for IDENTTG again --- bridge_master.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 8edd508..46dc3c5 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -839,8 +839,8 @@ def options_config(): CONFIG['SYSTEMS'][_system]['VOICE_IDENT'] = bool(int(_options['VOICE'])) logger.debug("(OPTIONS) %s - Setting voice ident to %s",_system,CONFIG['SYSTEMS'][_system]['VOICE_IDENT']) - if 'IDENTTG' in _options and _options['IDENTTG'] and (CONFIG['SYSTEMS'][_system]['OVERRIDE_IDENT_TG'] != int(_options['IDENTTG'])): - CONFIG['SYSTEMS'][_system]['OVERRIDE_IDENT_TG'] = int(_options['IDENTTG']) + if 'OVERRIDE_IDENT_TG' in _options and _options['OVERRIDE_IDENT_TG'] and (CONFIG['SYSTEMS'][_system]['OVERRIDE_IDENT_TG'] != int(_options['OVERRIDE_IDENT_TG'])): + CONFIG['SYSTEMS'][_system]['OVERRIDE_IDENT_TG'] = int(_options['OVERRIDE_IDENT_TG']) logger.debug("(OPTIONS) %s - Setting OVERRIDE_IDENT_TG to %s",_system,CONFIG['SYSTEMS'][_system]['OVERRIDE_IDENT_TG']) if 'LANG' in _options and _options['LANG'] in words and _options['LANG'] != CONFIG['SYSTEMS'][_system]['ANNOUNCEMENT_LANGUAGE'] : From de148c7ad34273483d9fb9db28e33c755eb48279 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 20 Jun 2022 11:46:37 +0100 Subject: [PATCH 042/128] Fix ident to 9 --- bridge_master.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 46dc3c5..f9e1806 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -678,10 +678,8 @@ def ident(): logger.debug("(IDENT) %s System has no peers or no recorded callsign (%s), skipping",system,_callsign) continue _slot = systems[system].STATUS[2] - #If slot is idle for RX and TX - #print("RX:"+str(_slot['RX_TYPE'])+" TX:"+str(_slot['TX_TYPE'])+" TIME:"+str(time() - _slot['TX_TIME'])) + #If slot is idle for RX and TX for over 30 seconds if (_slot['RX_TYPE'] == HBPF_SLT_VTERM) and (_slot['TX_TYPE'] == HBPF_SLT_VTERM) and (time() - _slot['TX_TIME'] > 30 and time() - _slot['RX_TIME'] > 30): - #_stream_id = hex_str_4(1234567) _all_call = bytes_3(16777215) _source_id= bytes_3(5000) @@ -722,7 +720,7 @@ def ident(): #_say.append(AMBEobj.readSingleFile('alpha.ambe')) _peer_id = CONFIG['GLOBAL']['SERVER_ID'] - speech = pkt_gen(_source_id, _all_call, _peer_id, 1, _say) + speech = pkt_gen(_source_id, _dst_id, _peer_id, 1, _say) sleep(1) _slot = systems[system].STATUS[2] From 1964f1ca21ead3fe8a6d9202e26a856109c46dd8 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 20 Jun 2022 12:18:24 +0100 Subject: [PATCH 043/128] One more fix --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index f9e1806..96eca58 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -734,7 +734,7 @@ def ident(): _stream_id = pkt[16:20] _pkt_time = time() - reactor.callFromThread(sendVoicePacket,systems[system],pkt,_source_id,_all_call,_slot) + reactor.callFromThread(sendVoicePacket,systems[system],pkt,_source_id,_dst_id,_slot) def options_config(): logger.debug('(OPTIONS) Running options parser') From ec1a54a8eff6c25df003e9e0775c3314b2d1a674 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 21 Jun 2022 01:53:07 +0100 Subject: [PATCH 044/128] If bridge_master.py is killed with HUP: write config and bridge state to disk. If, when started again, state files are less that 25 seconds old load these instead of parsing freedmr.cfg and rules.py This means, it's possible to effect a seamless restart, without causing systems to have to re-login. --- FreeDMR-SAMPLE-commented.cfg | 8 ++++- bridge_master.py | 58 ++++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/FreeDMR-SAMPLE-commented.cfg b/FreeDMR-SAMPLE-commented.cfg index 7863033..ed9f224 100755 --- a/FreeDMR-SAMPLE-commented.cfg +++ b/FreeDMR-SAMPLE-commented.cfg @@ -4,7 +4,13 @@ # - how often the Master maintenance loop runs # MAX_MISSED - how many pings are missed before we give up and re-register # - number of times the master maintenance loop runs before de-registering a peer +# You should not need to change this from the default. # +# GEN_STAT_BRIDGES - Generate static bridges to forward traffic to other connected servers. +# Generally this should be left True, unless you are building a hidden server +# Which does not participate in the mesh network +# +# ALLOW_NULL_PASSPHRASE # ACLs: # # Access Control Lists are a very powerful tool for administering your system. @@ -45,7 +51,7 @@ REG_ACL: PERMIT:ALL SUB_ACL: DENY:1 TGID_TS1_ACL: PERMIT:ALL TGID_TS2_ACL: PERMIT:ALL -GEN_STAT_BRIDGES: False +GEN_STAT_BRIDGES: True ALLOW_NULL_PASSPHRASE: True ANNOUNCEMENT_LANGUAGES: SERVER_ID: 0000 diff --git a/bridge_master.py b/bridge_master.py index 96eca58..20beb0e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -409,6 +409,24 @@ def subMapWrite(): except: logger.warning('(SUBSCRIBER) Cannot write SUB_MAP to file') +def configPickle(): + try: + _fh = open('config.pkl','wb') + pickle.dump(CONFIG,_fh) + _fh.close() + logger.info('(GLOBAL) Writing CONFIG to disk') + except: + logger.warning('(GLOBAL) Cannot write config.pkl') + +def bridgePickle(): + try: + _fh = open('bridge.pkl','wb') + pickle.dump(BRIDGES,_fh) + _fh.close() + logger.info('(GLOBAL) Writing BRIDGES to disk') + except: + logger.warning('(GLOBAL) Cannot write bridge.pkl') + #Subscriber Map trimmer loop def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') @@ -2828,8 +2846,20 @@ if __name__ == '__main__': if not cli_args.CONFIG_FILE: cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' - # Call the external routine to build the configuration dictionary - CONFIG = config.build_config(cli_args.CONFIG_FILE) + file_exists = os.path.isfile('config.pkl') == True + if file_exists: + if os.path.getmtime('config.pkl') > (time() - 25): + try: + with open('config.pkl','rb') as _fh: + CONFIG = pickle.load(_fh) + print('(CONFIG) loaded config .pkl from previous shutdown') + except: + print('(CONFIG) Cannot load config.pkl file') + CONFIG = config.build_config(cli_args.CONFIG_FILE) + else: + os.unlink("config.pkl") + else: + CONFIG = config.build_config(cli_args.CONFIG_FILE) # Ensure we have a path for the rules file, if one wasn't specified, then use the default (top of file) if not cli_args.RULES_FILE: @@ -2883,9 +2913,13 @@ if __name__ == '__main__': reactor.stop() if CONFIG['ALIASES']['SUB_MAP_FILE']: subMapWrite() + if _signal == signal.SIGHUP: + configPickle() + bridgePickle() + # Set signal handers so that we can gracefully exit if need be - for sig in [signal.SIGINT, signal.SIGTERM]: + for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGHUP]: signal.signal(sig, sig_handler) # Create the name-number mapping dictionaries @@ -2911,8 +2945,22 @@ if __name__ == '__main__': except (ImportError, FileNotFoundError): sys.exit('(ROUTER) TERMINATING: Routing bridges file not found or invalid: {}'.format(cli_args.RULES_FILE)) - # Build the routing rules file - BRIDGES = make_bridges(rules_module.BRIDGES) + #Load pickle of bridges if it's less than 25 seconds old + if os.path.isfile('bridge.pkl'): + if os.path.getmtime('config.pkl') > (time() - 25): + try: + with open('bridge.pkl','rb') as _fh: + BRIDGES = pickle.load(_fh) + logger.info('(BRIDGE) loaded bridge.pkl from previous shutdown') + except: + logger.warning('(BRIDGE) Cannot load bridge.pkl file') + BRIDGES = make_bridges(rules_module.BRIDGES) + else: + BRIDGES = make_bridges(rules_module.BRIDGES) + os.unlink("bridge.pkl") + else: + BRIDGES = make_bridges(rules_module.BRIDGES) + #Subscriber map for unit calls - complete with test entry #SUB_MAP = {bytes_3(73578):('REP-1',1,time())} From d0c718ff3dd8fc394d57c257e2267e65dc2fd611 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 21 Jun 2022 02:01:33 +0100 Subject: [PATCH 045/128] exclude mysql config initially if we load from pickle --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 20beb0e..4e67969 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2880,7 +2880,7 @@ if __name__ == '__main__': SQLCONFIG = {} sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],CONFIG['MYSQL']['TABLE'],logger) #Run it once immediately - if sql.con(): + if sql.con() and os.path.getmtime('config.pkl') < (time() - 25): logger.info('(MYSQL) reading config from database') try: SQLCONFIG = sql.getConfig() From d8d261cd178530afd7e08347e3893cafd7149a03 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 21 Jun 2022 02:03:59 +0100 Subject: [PATCH 046/128] configP --- bridge_master.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 4e67969..fee93d1 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2846,6 +2846,7 @@ if __name__ == '__main__': if not cli_args.CONFIG_FILE: cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' + configP = False file_exists = os.path.isfile('config.pkl') == True if file_exists: if os.path.getmtime('config.pkl') > (time() - 25): @@ -2853,6 +2854,7 @@ if __name__ == '__main__': with open('config.pkl','rb') as _fh: CONFIG = pickle.load(_fh) print('(CONFIG) loaded config .pkl from previous shutdown') + configP = True except: print('(CONFIG) Cannot load config.pkl file') CONFIG = config.build_config(cli_args.CONFIG_FILE) @@ -2880,7 +2882,7 @@ if __name__ == '__main__': SQLCONFIG = {} sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],CONFIG['MYSQL']['TABLE'],logger) #Run it once immediately - if sql.con() and os.path.getmtime('config.pkl') < (time() - 25): + if sql.con() and not configP: logger.info('(MYSQL) reading config from database') try: SQLCONFIG = sql.getConfig() From 38a10f79cfaa6eb94a21a4de5861e7b14e964827 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 21 Jun 2022 02:07:07 +0100 Subject: [PATCH 047/128] Revert "configP" This reverts commit c2b5375729152df3895c1abb9f66f390d2322304. --- bridge_master.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index fee93d1..4e67969 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2846,7 +2846,6 @@ if __name__ == '__main__': if not cli_args.CONFIG_FILE: cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' - configP = False file_exists = os.path.isfile('config.pkl') == True if file_exists: if os.path.getmtime('config.pkl') > (time() - 25): @@ -2854,7 +2853,6 @@ if __name__ == '__main__': with open('config.pkl','rb') as _fh: CONFIG = pickle.load(_fh) print('(CONFIG) loaded config .pkl from previous shutdown') - configP = True except: print('(CONFIG) Cannot load config.pkl file') CONFIG = config.build_config(cli_args.CONFIG_FILE) @@ -2882,7 +2880,7 @@ if __name__ == '__main__': SQLCONFIG = {} sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],CONFIG['MYSQL']['TABLE'],logger) #Run it once immediately - if sql.con() and not configP: + if sql.con() and os.path.getmtime('config.pkl') < (time() - 25): logger.info('(MYSQL) reading config from database') try: SQLCONFIG = sql.getConfig() From 1d144bb42c8b1c06da280a90cd38cfe21278019b Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 21 Jun 2022 02:07:09 +0100 Subject: [PATCH 048/128] Revert "exclude mysql config initially if we load from pickle" This reverts commit 63817c2db83e64e5c6c362b2e0297be0168d1f37. --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 4e67969..20beb0e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2880,7 +2880,7 @@ if __name__ == '__main__': SQLCONFIG = {} sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],CONFIG['MYSQL']['TABLE'],logger) #Run it once immediately - if sql.con() and os.path.getmtime('config.pkl') < (time() - 25): + if sql.con(): logger.info('(MYSQL) reading config from database') try: SQLCONFIG = sql.getConfig() From 46da9bc20a028d2ac73aedc94e18c42e75135b3e Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 21 Jun 2022 02:07:10 +0100 Subject: [PATCH 049/128] Revert "If bridge_master.py is killed with HUP:" This reverts commit 19a656c88bd2708a7fc3e94031570d3444c82ad8. --- FreeDMR-SAMPLE-commented.cfg | 8 +---- bridge_master.py | 58 ++++-------------------------------- 2 files changed, 6 insertions(+), 60 deletions(-) diff --git a/FreeDMR-SAMPLE-commented.cfg b/FreeDMR-SAMPLE-commented.cfg index ed9f224..7863033 100755 --- a/FreeDMR-SAMPLE-commented.cfg +++ b/FreeDMR-SAMPLE-commented.cfg @@ -4,13 +4,7 @@ # - how often the Master maintenance loop runs # MAX_MISSED - how many pings are missed before we give up and re-register # - number of times the master maintenance loop runs before de-registering a peer -# You should not need to change this from the default. # -# GEN_STAT_BRIDGES - Generate static bridges to forward traffic to other connected servers. -# Generally this should be left True, unless you are building a hidden server -# Which does not participate in the mesh network -# -# ALLOW_NULL_PASSPHRASE # ACLs: # # Access Control Lists are a very powerful tool for administering your system. @@ -51,7 +45,7 @@ REG_ACL: PERMIT:ALL SUB_ACL: DENY:1 TGID_TS1_ACL: PERMIT:ALL TGID_TS2_ACL: PERMIT:ALL -GEN_STAT_BRIDGES: True +GEN_STAT_BRIDGES: False ALLOW_NULL_PASSPHRASE: True ANNOUNCEMENT_LANGUAGES: SERVER_ID: 0000 diff --git a/bridge_master.py b/bridge_master.py index 20beb0e..96eca58 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -409,24 +409,6 @@ def subMapWrite(): except: logger.warning('(SUBSCRIBER) Cannot write SUB_MAP to file') -def configPickle(): - try: - _fh = open('config.pkl','wb') - pickle.dump(CONFIG,_fh) - _fh.close() - logger.info('(GLOBAL) Writing CONFIG to disk') - except: - logger.warning('(GLOBAL) Cannot write config.pkl') - -def bridgePickle(): - try: - _fh = open('bridge.pkl','wb') - pickle.dump(BRIDGES,_fh) - _fh.close() - logger.info('(GLOBAL) Writing BRIDGES to disk') - except: - logger.warning('(GLOBAL) Cannot write bridge.pkl') - #Subscriber Map trimmer loop def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') @@ -2846,20 +2828,8 @@ if __name__ == '__main__': if not cli_args.CONFIG_FILE: cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' - file_exists = os.path.isfile('config.pkl') == True - if file_exists: - if os.path.getmtime('config.pkl') > (time() - 25): - try: - with open('config.pkl','rb') as _fh: - CONFIG = pickle.load(_fh) - print('(CONFIG) loaded config .pkl from previous shutdown') - except: - print('(CONFIG) Cannot load config.pkl file') - CONFIG = config.build_config(cli_args.CONFIG_FILE) - else: - os.unlink("config.pkl") - else: - CONFIG = config.build_config(cli_args.CONFIG_FILE) + # Call the external routine to build the configuration dictionary + CONFIG = config.build_config(cli_args.CONFIG_FILE) # Ensure we have a path for the rules file, if one wasn't specified, then use the default (top of file) if not cli_args.RULES_FILE: @@ -2913,13 +2883,9 @@ if __name__ == '__main__': reactor.stop() if CONFIG['ALIASES']['SUB_MAP_FILE']: subMapWrite() - if _signal == signal.SIGHUP: - configPickle() - bridgePickle() - # Set signal handers so that we can gracefully exit if need be - for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGHUP]: + for sig in [signal.SIGINT, signal.SIGTERM]: signal.signal(sig, sig_handler) # Create the name-number mapping dictionaries @@ -2945,22 +2911,8 @@ if __name__ == '__main__': except (ImportError, FileNotFoundError): sys.exit('(ROUTER) TERMINATING: Routing bridges file not found or invalid: {}'.format(cli_args.RULES_FILE)) - #Load pickle of bridges if it's less than 25 seconds old - if os.path.isfile('bridge.pkl'): - if os.path.getmtime('config.pkl') > (time() - 25): - try: - with open('bridge.pkl','rb') as _fh: - BRIDGES = pickle.load(_fh) - logger.info('(BRIDGE) loaded bridge.pkl from previous shutdown') - except: - logger.warning('(BRIDGE) Cannot load bridge.pkl file') - BRIDGES = make_bridges(rules_module.BRIDGES) - else: - BRIDGES = make_bridges(rules_module.BRIDGES) - os.unlink("bridge.pkl") - else: - BRIDGES = make_bridges(rules_module.BRIDGES) - + # Build the routing rules file + BRIDGES = make_bridges(rules_module.BRIDGES) #Subscriber map for unit calls - complete with test entry #SUB_MAP = {bytes_3(73578):('REP-1',1,time())} From 900f88e5d69aaae6d67759e511a4cc11e2f50580 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 24 Jun 2022 01:09:30 +0100 Subject: [PATCH 050/128] Comment out bridge and config pickle Reset bridges on logout. --- bridge_master.py | 65 ++++++++++++++++++++++++++---------------------- hblink.py | 2 ++ 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index fee93d1..630ca17 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -757,6 +757,10 @@ def ident(): def options_config(): logger.debug('(OPTIONS) Running options parser') for _system in CONFIG['SYSTEMS']: + if '_reset' in CONFIG['SYSTEMS'][_system] and CONFIG['SYSTEMS'][_system]['_reset']: + logger.debug('(OPTIONS) Bridge reset for %s - no peers'._system) + remove_bridge_system(_system) + CONFIG['SYSTEMS'][_system]['_reset'] = False try: if CONFIG['SYSTEMS'][_system]['MODE'] != 'MASTER': continue @@ -2846,22 +2850,22 @@ if __name__ == '__main__': if not cli_args.CONFIG_FILE: cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' - configP = False - file_exists = os.path.isfile('config.pkl') == True - if file_exists: - if os.path.getmtime('config.pkl') > (time() - 25): - try: - with open('config.pkl','rb') as _fh: - CONFIG = pickle.load(_fh) - print('(CONFIG) loaded config .pkl from previous shutdown') - configP = True - except: - print('(CONFIG) Cannot load config.pkl file') - CONFIG = config.build_config(cli_args.CONFIG_FILE) - else: - os.unlink("config.pkl") - else: - CONFIG = config.build_config(cli_args.CONFIG_FILE) + #configP = False + #if os.path.isfile('config.pkl'): + #if os.path.getmtime('config.pkl') > (time() - 25): + #try: + #with open('config.pkl','rb') as _fh: + #CONFIG = pickle.load(_fh) + #print('(CONFIG) loaded config .pkl from previous shutdown') + #configP = True + #except: + #print('(CONFIG) Cannot load config.pkl file') + #CONFIG = config.build_config(cli_args.CONFIG_FILE) + #else: + #os.unlink("config.pkl") + #else: + + CONFIG = config.build_config(cli_args.CONFIG_FILE) # Ensure we have a path for the rules file, if one wasn't specified, then use the default (top of file) if not cli_args.RULES_FILE: @@ -2948,20 +2952,21 @@ if __name__ == '__main__': sys.exit('(ROUTER) TERMINATING: Routing bridges file not found or invalid: {}'.format(cli_args.RULES_FILE)) #Load pickle of bridges if it's less than 25 seconds old - if os.path.isfile('bridge.pkl'): - if os.path.getmtime('config.pkl') > (time() - 25): - try: - with open('bridge.pkl','rb') as _fh: - BRIDGES = pickle.load(_fh) - logger.info('(BRIDGE) loaded bridge.pkl from previous shutdown') - except: - logger.warning('(BRIDGE) Cannot load bridge.pkl file') - BRIDGES = make_bridges(rules_module.BRIDGES) - else: - BRIDGES = make_bridges(rules_module.BRIDGES) - os.unlink("bridge.pkl") - else: - BRIDGES = make_bridges(rules_module.BRIDGES) + #if os.path.isfile('bridge.pkl'): + #if os.path.getmtime('config.pkl') > (time() - 25): + #try: + #with open('bridge.pkl','rb') as _fh: + #BRIDGES = pickle.load(_fh) + #logger.info('(BRIDGE) loaded bridge.pkl from previous shutdown') + #except: + #logger.warning('(BRIDGE) Cannot load bridge.pkl file') + #BRIDGES = make_bridges(rules_module.BRIDGES) + #else: + #BRIDGES = make_bridges(rules_module.BRIDGES) + #os.unlink("bridge.pkl") + #else: + + BRIDGES = make_bridges(rules_module.BRIDGES) #Subscriber map for unit calls - complete with test entry diff --git a/hblink.py b/hblink.py index ce58794..c4b27b7 100755 --- a/hblink.py +++ b/hblink.py @@ -776,8 +776,10 @@ class HBSYSTEM(DatagramProtocol): if '_default_options' in self._CONFIG['SYSTEMS'][self._system]: logger.info('(%s) Setting default Options: %s',self._system, self._CONFIG['SYSTEMS'][self._system]['_default_options']) self._CONFIG['SYSTEMS'][self._system]['OPTIONS'] = self._CONFIG['SYSTEMS'][self._system]['_default_options'] + self._CONFIG['SYSTEMS'][self._system]['_reset'] = True else: del self._CONFIG['SYSTEMS'][self._system]['OPTIONS'] + self._CONFIG['SYSTEMS'][self._system]['_reset'] = True logger.info('(%s) Deleting HBP Options',self._system) # Aliased in __init__ to maintenance_loop if system is a peer From 85d41558ba2ae94b38be51a9ef9fd530ebb97f8b Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 24 Jun 2022 01:12:11 +0100 Subject: [PATCH 051/128] on logout as well as timeout --- hblink.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index c4b27b7..2fed0cc 100755 --- a/hblink.py +++ b/hblink.py @@ -779,7 +779,7 @@ class HBSYSTEM(DatagramProtocol): self._CONFIG['SYSTEMS'][self._system]['_reset'] = True else: del self._CONFIG['SYSTEMS'][self._system]['OPTIONS'] - self._CONFIG['SYSTEMS'][self._system]['_reset'] = True + w logger.info('(%s) Deleting HBP Options',self._system) # Aliased in __init__ to maintenance_loop if system is a peer @@ -1076,9 +1076,11 @@ class HBSYSTEM(DatagramProtocol): if '_default_options' in self._CONFIG['SYSTEMS'][self._system]: self._CONFIG['SYSTEMS'][self._system]['OPTIONS'] = self._CONFIG['SYSTEMS'][self._system]['_default_options'] logger.info('(%s) Setting default Options: %s',self._system, self._CONFIG['SYSTEMS'][self._system]['_default_options']) + self._CONFIG['SYSTEMS'][self._system]['_reset'] = True else: logger.info('(%s) Deleting HBP Options',self._system) del self._CONFIG['SYSTEMS'][self._system]['OPTIONS'] + self._CONFIG['SYSTEMS'][self._system]['_reset'] = True else: _peer_id = _data[4:8] # Configure Command From 8663ee8519a71d49579da0d9f09e4046c04b543b Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 24 Jun 2022 01:42:04 +0100 Subject: [PATCH 052/128] typo --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 3d2b318..4018a84 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -740,7 +740,7 @@ def options_config(): logger.debug('(OPTIONS) Running options parser') for _system in CONFIG['SYSTEMS']: if '_reset' in CONFIG['SYSTEMS'][_system] and CONFIG['SYSTEMS'][_system]['_reset']: - logger.debug('(OPTIONS) Bridge reset for %s - no peers'._system) + logger.debug('(OPTIONS) Bridge reset for %s - no peers',_system) remove_bridge_system(_system) CONFIG['SYSTEMS'][_system]['_reset'] = False try: From 0408e8876e3a8e8f862869d63dc347ca0803f760 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 1 Jul 2022 02:15:52 +0100 Subject: [PATCH 053/128] use path for SUB_MAP_FILE --- bridge_master.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 4018a84..bd5a130 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -402,7 +402,7 @@ def kaReporting(): #Write SUB_MAP to disk def subMapWrite(): try: - _fh = open(CONFIG['ALIASES']['SUB_MAP_FILE'],'wb') + _fh = open(CONFIG['ALIASES']['PATH'] + CONFIG['ALIASES']['SUB_MAP_FILE'],'wb') pickle.dump(SUB_MAP,_fh) _fh.close() logger.info('(SUBSCRIBER) Writing SUB_MAP to disk') @@ -2954,7 +2954,7 @@ if __name__ == '__main__': if CONFIG['ALIASES']['SUB_MAP_FILE']: try: - with open(CONFIG['ALIASES']['SUB_MAP_FILE'],'rb') as _fh: + with open(CONFIG['ALIASES']['PATH'] + CONFIG['ALIASES']['SUB_MAP_FILE'],'rb') as _fh: SUB_MAP = pickle.load(_fh) except: logger.warning('(SUBSCRIBER) Cannot load SUB_MAP file') From b4801b455e748079c5fddf75e24d75ca9366be84 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 1 Jul 2022 02:34:23 +0100 Subject: [PATCH 054/128] Tidy up docker install - use directories for JSON and logs. --- docker-configs/docker-compose.yml | 15 +++++---------- docker-configs/docker-compose_install.sh | 19 ++++++------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/docker-configs/docker-compose.yml b/docker-configs/docker-compose.yml index 528d3b6..c4c3738 100644 --- a/docker-configs/docker-compose.yml +++ b/docker-configs/docker-compose.yml @@ -24,13 +24,11 @@ services: mem_reservation: 600m volumes: - '/etc/freedmr/freedmr.cfg:/opt/freedmr/freedmr.cfg' - - '/var/log/freedmr/freedmr.log:/opt/freedmr/freedmr.log' + - '/var/log/freedmr/:/opt/freedmr/log/' - '/etc/freedmr/rules.py:/opt/freedmr/rules.py' #Write JSON files outside of container - - '/etc/freedmr/json/talkgroup_ids.json:/opt/freedmr/talkgroup_ids.json' - - '/etc/freedmr/json/subscriber_ids.json:/opt/freedmr/subscriber_ids.json' - - '/etc/freedmr/json/peer_ids.json:/opt/freedmr/peer_ids.json' - - '/etc/freedmr/json/sub_map.pkl:/opt/freedmr/sub_map.pkl' + - '/etc/freedmr/json/:/opt/freedmr/json/' + ports: - '62031:62031/udp' #Change the below to inlude ports used for your OBP(s) @@ -62,12 +60,9 @@ services: volumes: #This should be kept to a manageable size from #cron or logrotate outisde of the container. - - '/var/log/FreeDMRmonitor/lastheard.log:/opt/FreeDMRmonitor/log/lastheard.log' - - '/var/log/FreeDMRmonitor/hbmon.log:/opt/FreeDMRmonitor/log/hbmon.log' + - '/var/log/FreeDMRmonitor/:/opt/FreeDMRmonitor/log/' #Write JSON files outside of container - - '/etc/freedmr/json/talkgroup_ids.json:/opt/FreeDMRmonitor/talkgroup_ids.json' - - '/etc/freedmr/json/subscriber_ids.json:/opt/FreeDMRmonitor/subscriber_ids.json' - - '/etc/freedmr/json/peer_ids.json:/opt/FreeDMRmonitor/peer_ids.json' + - '/etc/freedmr/json/:/opt/FreeDMRmonitor/json/' #Override config file # - '/etc/freedmr/config.py:/opt/FreeDMRmonitor/config.py' diff --git a/docker-configs/docker-compose_install.sh b/docker-configs/docker-compose_install.sh index 6613396..f1a2bc1 100644 --- a/docker-configs/docker-compose_install.sh +++ b/docker-configs/docker-compose_install.sh @@ -37,14 +37,7 @@ chmod 755 /etc/freedmr && echo make json directory... mkdir -p /etc/freedmr/json && - -echo get json files... -cd /etc/freedmr/json && -curl http://downloads.freedmr.uk/downloads/local_subscriber_ids.json -o subscriber_ids.json && -curl http://downloads.freedmr.uk/downloads/talkgroup_ids.json -o talkgroup_ids.json && -curl https://www.radioid.net/static/rptrs.json -o peer_ids.json && -touch /etc/freedmr/json/sub_map.pkl && -chmod -R 777 /etc/freedmr/json && +chown 54000:54000 /etc/freedmr/json && echo Install /etc/freedmr/freedmr.cfg ... cat << EOF > /etc/freedmr/freedmr.cfg @@ -70,21 +63,21 @@ REPORT_PORT: 4321 REPORT_CLIENTS: * [LOGGER] -LOG_FILE: freedmr.log +LOG_FILE: log/freedmr.log LOG_HANDLERS: file-timed LOG_LEVEL: INFO LOG_NAME: FreeDMR [ALIASES] -TRY_DOWNLOAD: False -PATH: ./ +TRY_DOWNLOAD: True +PATH: ./json/ PEER_FILE: peer_ids.json SUBSCRIBER_FILE: subscriber_ids.json TGID_FILE: talkgroup_ids.json PEER_URL: https://www.radioid.net/static/rptrs.json SUBSCRIBER_URL: http://downloads.freedmr.uk/downloads/local_subscriber_ids.json -TGID_URL: TGID_URL: http://downloads.freedmr.uk/downloads/talkgroup_ids.json -STALE_DAYS: 7 +TGID_URL: TGID_URL: https://freedmr.cymru/talkgroups/talkgroup_ids_json.php +STALE_DAYS: 1 LOCAL_SUBSCRIBER_FILE: local_subcriber_ids.json SUB_MAP_FILE: sub_map.pkl From 30696dabcfdd2485052b1bff7aa339b67c291d54 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 17 Jul 2022 01:15:52 +0100 Subject: [PATCH 055/128] Explicitly send NAK when we timeout a peer --- hblink.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hblink.py b/hblink.py index 2fed0cc..7e15032 100755 --- a/hblink.py +++ b/hblink.py @@ -769,6 +769,8 @@ class HBSYSTEM(DatagramProtocol): remove_list.append(peer) for peer in remove_list: logger.info('(%s) Peer %s (%s) has timed out and is being removed', self._system, self._peers[peer]['CALLSIGN'], self._peers[peer]['RADIO_ID']) + #First, NAK the peer + self.transport.write(b''.join([MSTNAK, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) # Remove any timed out peers from the configuration del self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer] if 'PEERS' not in self._CONFIG['SYSTEMS'][self._system] and 'OPTIONS' in self._CONFIG['SYSTEMS'][self._system]: From bc73e3c8bf9d94e2e876260b60a0b27c6a14618e Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 17 Jul 2022 10:34:02 +0100 Subject: [PATCH 056/128] Send 3 x MSTCL from proxy --- hblink.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hblink.py b/hblink.py index 7e15032..c1770b4 100755 --- a/hblink.py +++ b/hblink.py @@ -769,8 +769,10 @@ class HBSYSTEM(DatagramProtocol): remove_list.append(peer) for peer in remove_list: logger.info('(%s) Peer %s (%s) has timed out and is being removed', self._system, self._peers[peer]['CALLSIGN'], self._peers[peer]['RADIO_ID']) - #First, NAK the peer - self.transport.write(b''.join([MSTNAK, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) + #First, MSTCL the peer - three times + self.transport.write(b''.join([MSTCL, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) + self.transport.write(b''.join([MSTCL, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) + self.transport.write(b''.join([MSTCL, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) # Remove any timed out peers from the configuration del self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer] if 'PEERS' not in self._CONFIG['SYSTEMS'][self._system] and 'OPTIONS' in self._CONFIG['SYSTEMS'][self._system]: From 56e29d96a8726a82b65cb2428872330bb30fdba1 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 17 Jul 2022 11:13:47 +0100 Subject: [PATCH 057/128] fixup --- hotspot_proxy_v2.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hotspot_proxy_v2.py b/hotspot_proxy_v2.py index 6a8aa4e..84d5bb9 100644 --- a/hotspot_proxy_v2.py +++ b/hotspot_proxy_v2.py @@ -71,6 +71,10 @@ class Proxy(DatagramProtocol): if self.clientinfo and _peer_id != b'\xff\xff\xff\xff': print(f"{datetime.now().replace(microsecond=0)} Client: ID:{str(int_id(_peer_id)).rjust(9)} IP:{self.peerTrack[_peer_id]['shost'].rjust(15)} Port:{self.peerTrack[_peer_id]['sport']} Removed.") self.transport.write(b'RPTCL'+_peer_id, (self.master,self.peerTrack[_peer_id]['dport'])) + #Tell client we have closed do the session - 3 times, in case they are on a lossy network + self.transport.write(b'MSTCL',(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport'])) + self.transport.write(b'MSTCL',(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport'])) + self.transport.write(b'MSTCL',(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport'])) self.connTrack[self.peerTrack[_peer_id]['dport']] = False del self.peerTrack[_peer_id] From 6e50c8a45ed85f66774e841ea1267815f81e0337 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 17 Jul 2022 11:30:26 +0100 Subject: [PATCH 058/128] Fix stack trace - key not found --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index bd5a130..6c9e703 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2621,7 +2621,7 @@ class routerHBP(HBSYSTEM): self.STATUS[_slot]['LOOPLOG'] = True self.STATUS[_slot]['LAST'] = pkt_time - if CONFIG['SYSTEMS'][self._system]['ENHANCED_OBP'] and '_bcsq' not in self.STATUS[_slot]: + if 'ENHANCED_OBP' in CONFIG['SYSTEMS'][self._system] and CONFIG['SYSTEMS'][self._system]['ENHANCED_OBP'] and '_bcsq' not in self.STATUS[_slot]: systems[self._system].send_bcsq(_dst_id,_stream_id) self.STATUS[_slot]['_bcsq'] = True return From 4084b12739cf8bcee82bf99724ef9f15d834d9d5 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 17 Jul 2022 21:31:12 +0100 Subject: [PATCH 059/128] 5s is plenty to wait for other side to respond to closedown - 15 sec was too much --- hotspot_proxy_v2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hotspot_proxy_v2.py b/hotspot_proxy_v2.py index 84d5bb9..deb59a5 100644 --- a/hotspot_proxy_v2.py +++ b/hotspot_proxy_v2.py @@ -71,7 +71,7 @@ class Proxy(DatagramProtocol): if self.clientinfo and _peer_id != b'\xff\xff\xff\xff': print(f"{datetime.now().replace(microsecond=0)} Client: ID:{str(int_id(_peer_id)).rjust(9)} IP:{self.peerTrack[_peer_id]['shost'].rjust(15)} Port:{self.peerTrack[_peer_id]['sport']} Removed.") self.transport.write(b'RPTCL'+_peer_id, (self.master,self.peerTrack[_peer_id]['dport'])) - #Tell client we have closed do the session - 3 times, in case they are on a lossy network + #Tell client we have closed the session - 3 times, in case they are on a lossy network self.transport.write(b'MSTCL',(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport'])) self.transport.write(b'MSTCL',(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport'])) self.transport.write(b'MSTCL',(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport'])) @@ -154,7 +154,7 @@ class Proxy(DatagramProtocol): # Remove the client after send a MSTN or MSTC packet if _command in (MSTN,MSTC): # Give time to the client for a reply to prevent port reassignment - self.peerTrack[_peer_id]['timer'].reset(15) + self.peerTrack[_peer_id]['timer'].reset(5) return From 062def921b5cf93aec3943a1ef4e4825036fa410 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 17 Jul 2022 22:49:14 +0100 Subject: [PATCH 060/128] Maybe 15 was ok --- hotspot_proxy_v2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot_proxy_v2.py b/hotspot_proxy_v2.py index deb59a5..d1e1efb 100644 --- a/hotspot_proxy_v2.py +++ b/hotspot_proxy_v2.py @@ -154,7 +154,7 @@ class Proxy(DatagramProtocol): # Remove the client after send a MSTN or MSTC packet if _command in (MSTN,MSTC): # Give time to the client for a reply to prevent port reassignment - self.peerTrack[_peer_id]['timer'].reset(5) + self.peerTrack[_peer_id]['timer'].reset(15) return From 569c636f61a6eb64ccee007f27c501f5ba961e4c Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 18 Jul 2022 02:18:44 +0100 Subject: [PATCH 061/128] Don't clobber files if they can't be downloaded --- hblink.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/hblink.py b/hblink.py index c1770b4..053eea5 100755 --- a/hblink.py +++ b/hblink.py @@ -769,9 +769,7 @@ class HBSYSTEM(DatagramProtocol): remove_list.append(peer) for peer in remove_list: logger.info('(%s) Peer %s (%s) has timed out and is being removed', self._system, self._peers[peer]['CALLSIGN'], self._peers[peer]['RADIO_ID']) - #First, MSTCL the peer - three times - self.transport.write(b''.join([MSTCL, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) - self.transport.write(b''.join([MSTCL, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) + #First, MSTCL the peer self.transport.write(b''.join([MSTCL, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) # Remove any timed out peers from the configuration del self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer] @@ -1389,12 +1387,13 @@ def try_download(_path, _file, _url, _stale,): result = 'ID ALIAS MAPPER: \'{}\' successfully downloaded'.format(_file) except IOError: result = 'ID ALIAS MAPPER: \'{}\' could not be downloaded due to an IOError'.format(_file) - try: - with open(_path+_file, 'wb') as outfile: - outfile.write(data) - outfile.close() - except IOError: - result = 'ID ALIAS mapper \'{}\' file could not be written due to an IOError'.format(_file) + else: + try: + with open(_path+_file, 'wb') as outfile: + outfile.write(data) + outfile.close() + except IOError: + result = 'ID ALIAS mapper \'{}\' file could not be written due to an IOError'.format(_file) else: result = 'ID ALIAS MAPPER: \'{}\' is current, not downloaded'.format(_file) From 5551f63e1ed2a406dd6542d56c444f34dbeee7a5 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 18 Jul 2022 22:00:46 +0100 Subject: [PATCH 062/128] Fix bug in master maintenence stopping peers from being removed on timeout --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 053eea5..d2a4a52 100755 --- a/hblink.py +++ b/hblink.py @@ -770,7 +770,7 @@ class HBSYSTEM(DatagramProtocol): for peer in remove_list: logger.info('(%s) Peer %s (%s) has timed out and is being removed', self._system, self._peers[peer]['CALLSIGN'], self._peers[peer]['RADIO_ID']) #First, MSTCL the peer - self.transport.write(b''.join([MSTCL, _peer_id]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) + self.transport.write(b''.join([MSTCL, peer]),self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer]['SOCKADDR']) # Remove any timed out peers from the configuration del self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer] if 'PEERS' not in self._CONFIG['SYSTEMS'][self._system] and 'OPTIONS' in self._CONFIG['SYSTEMS'][self._system]: From 6127f9dfa09413c4f0c938ea93788a252adcb335 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 25 Jul 2022 23:59:03 +0100 Subject: [PATCH 063/128] Fix global SMS sending --- bridge_master.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 6c9e703..8fdcc1e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1642,7 +1642,7 @@ class routerOBP(OPENBRIDGE): #Send all data to DATA-GATEWAY if enabled and valid if CONFIG['GLOBAL']['DATA_GATEWAY'] and 'DATA-GATEWAY' in CONFIG['SYSTEMS'] and CONFIG['SYSTEMS']['DATA-GATEWAY']['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS']['DATA-GATEWAY']['ENABLED']: logger.debug('(%s) DATA packet sent to DATA-GATEWAY',self._system) - self.sendDataToOBP('DATA-GATEWAY',_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_source_rptr,_ber,_rssi) + self.sendDataToOBP('DATA-GATEWAY',_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_source_server,_ber,_rssi,_source_rptr) #Send other openbridges @@ -1654,7 +1654,7 @@ class routerOBP(OPENBRIDGE): #We only want to send data calls to individual IDs via OpenBridge #Only send if proto ver for bridge is > 1 if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS'][system]['VER'] > 1 and (_int_dst_id >= 1000000): - self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops,_source_server,_ber,_rssi) + self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops,_source_server,_ber,_rssi,_source_server) #If destination ID is in the Subscriber Map if _dst_id in SUB_MAP: @@ -2256,7 +2256,7 @@ class routerHBP(HBSYSTEM): #Send all data to DATA-GATEWAY if enabled and valid if CONFIG['GLOBAL']['DATA_GATEWAY'] and 'DATA-GATEWAY' in CONFIG['SYSTEMS'] and CONFIG['SYSTEMS']['DATA-GATEWAY']['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS']['DATA-GATEWAY']['ENABLED']: logger.debug('(%s) DATA packet sent to DATA-GATEWAY',self._system) - self.sendDataToOBP('DATA-GATEWAY',_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_source_rptr) + self.sendDataToOBP('DATA-GATEWAY',_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_ber,_rssi,_source_server,_source_rptr) #Send to all openbridges # sysIgnore = [] @@ -2267,7 +2267,7 @@ class routerHBP(HBSYSTEM): continue #We only want to send data calls to individual IDs via FreeBridge (not OpenBridge) if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS'][system]['VER'] > 1 and (_int_dst_id >= 1000000): - self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_source_rptr) + self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_ber,_rssi,_source_server,_source_rptr) #If destination ID is in the Subscriber Map if _dst_id in SUB_MAP: From bdf9234fbb69224011fa092c3b36f57d1284ca12 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 26 Jul 2022 00:20:35 +0100 Subject: [PATCH 064/128] Revert "Fix global SMS sending" This reverts commit fa76ba714358771a67b1873cb182c932cae98c77. --- bridge_master.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 8fdcc1e..6c9e703 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1642,7 +1642,7 @@ class routerOBP(OPENBRIDGE): #Send all data to DATA-GATEWAY if enabled and valid if CONFIG['GLOBAL']['DATA_GATEWAY'] and 'DATA-GATEWAY' in CONFIG['SYSTEMS'] and CONFIG['SYSTEMS']['DATA-GATEWAY']['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS']['DATA-GATEWAY']['ENABLED']: logger.debug('(%s) DATA packet sent to DATA-GATEWAY',self._system) - self.sendDataToOBP('DATA-GATEWAY',_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_source_server,_ber,_rssi,_source_rptr) + self.sendDataToOBP('DATA-GATEWAY',_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_source_rptr,_ber,_rssi) #Send other openbridges @@ -1654,7 +1654,7 @@ class routerOBP(OPENBRIDGE): #We only want to send data calls to individual IDs via OpenBridge #Only send if proto ver for bridge is > 1 if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS'][system]['VER'] > 1 and (_int_dst_id >= 1000000): - self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops,_source_server,_ber,_rssi,_source_server) + self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops,_source_server,_ber,_rssi) #If destination ID is in the Subscriber Map if _dst_id in SUB_MAP: @@ -2256,7 +2256,7 @@ class routerHBP(HBSYSTEM): #Send all data to DATA-GATEWAY if enabled and valid if CONFIG['GLOBAL']['DATA_GATEWAY'] and 'DATA-GATEWAY' in CONFIG['SYSTEMS'] and CONFIG['SYSTEMS']['DATA-GATEWAY']['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS']['DATA-GATEWAY']['ENABLED']: logger.debug('(%s) DATA packet sent to DATA-GATEWAY',self._system) - self.sendDataToOBP('DATA-GATEWAY',_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_ber,_rssi,_source_server,_source_rptr) + self.sendDataToOBP('DATA-GATEWAY',_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_source_rptr) #Send to all openbridges # sysIgnore = [] @@ -2267,7 +2267,7 @@ class routerHBP(HBSYSTEM): continue #We only want to send data calls to individual IDs via FreeBridge (not OpenBridge) if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS'][system]['VER'] > 1 and (_int_dst_id >= 1000000): - self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_ber,_rssi,_source_server,_source_rptr) + self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_source_rptr) #If destination ID is in the Subscriber Map if _dst_id in SUB_MAP: From 1140a83001c923fff24b4477b19aab70850cf3a5 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 26 Jul 2022 00:21:42 +0100 Subject: [PATCH 065/128] Fix SMS global sending - again! --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 6c9e703..a2c6345 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2130,7 +2130,7 @@ class routerHBP(HBSYSTEM): if CONFIG['REPORTS']['REPORT']: systems[_d_system]._report.send_bridgeEvent('UNIT DATA,DATA,TX,{},{},{},{},{},{}'.format(_d_system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), 1, _int_dst_id).encode(encoding='utf-8', errors='ignore')) - def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops = b'',_ber = b'\x00', _rssi = b'\x00',_source_server = b'\x00\x00\x00\x00', _source_rptr = b'\x00\x00\x00\x00'): + def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops = b'',_ber = b'\x00', _rssi = b'\x00',_source_server = self._CONFIG['GLOBAL']['SERVER_ID'] , _source_rptr = b'\x00\x00\x00\x00'): # _sysIgnore = sysIgnore _int_dst_id = int_id(_dst_id) _target_status = systems[_target].STATUS From 2b3bb4fb8fc441b9964574bf0e8c6b0d580b57d7 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 26 Jul 2022 00:23:24 +0100 Subject: [PATCH 066/128] Fix aqgain1 --- bridge_master.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index a2c6345..017e418 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2130,8 +2130,9 @@ class routerHBP(HBSYSTEM): if CONFIG['REPORTS']['REPORT']: systems[_d_system]._report.send_bridgeEvent('UNIT DATA,DATA,TX,{},{},{},{},{},{}'.format(_d_system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), 1, _int_dst_id).encode(encoding='utf-8', errors='ignore')) - def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops = b'',_ber = b'\x00', _rssi = b'\x00',_source_server = self._CONFIG['GLOBAL']['SERVER_ID'] , _source_rptr = b'\x00\x00\x00\x00'): + def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops = b'',_ber = b'\x00', _rssi = b'\x00',_source_server = b'\x00\x00\x00\x00', _source_rptr = b'\x00\x00\x00\x00'): # _sysIgnore = sysIgnore + _source_server = self._CONFIG['GLOBAL']['SERVER_ID'] _int_dst_id = int_id(_dst_id) _target_status = systems[_target].STATUS _target_system = self._CONFIG['SYSTEMS'][_target] From 677a7a7f708d6d46acbb2651318cd6cbf05a14dc Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 26 Jul 2022 00:36:29 +0100 Subject: [PATCH 067/128] Also send peer properly in data packets --- bridge_master.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 017e418..8a77e1e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2132,7 +2132,8 @@ class routerHBP(HBSYSTEM): def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops = b'',_ber = b'\x00', _rssi = b'\x00',_source_server = b'\x00\x00\x00\x00', _source_rptr = b'\x00\x00\x00\x00'): # _sysIgnore = sysIgnore - _source_server = self._CONFIG['GLOBAL']['SERVER_ID'] + _source_server = self._CONFIG['GLOBAL']['SERVER_ID'] + _source_rptr = _peer_id _int_dst_id = int_id(_dst_id) _target_status = systems[_target].STATUS _target_system = self._CONFIG['SYSTEMS'][_target] From e6295639f522c7b132a89d46ec8dc64a4de798a7 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 26 Jul 2022 00:52:32 +0100 Subject: [PATCH 068/128] Also properly log source repeater for data packets coming over OBP --- bridge_master.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 8a77e1e..bc4ad41 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1616,28 +1616,28 @@ class routerOBP(OPENBRIDGE): if _dtype_vseq == 3: - logger.info('(%s) *UNIT CSBK* STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) DST_ID %s (%s), TS %s, SRC: %s', \ - self._system, int_id(_stream_id), self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot, int_id(_source_server)) + logger.info('(%s) *UNIT CSBK* STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) DST_ID %s (%s), TS %s, SRC: %s, RPTR: %s', \ + self._system, int_id(_stream_id), self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot, int_id(_source_server),int_id(_source_rptr)) if CONFIG['REPORTS']['REPORT']: self._report.send_bridgeEvent('UNIT CSBK,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 6: - logger.info('(%s) *UNIT DATA HEADER* STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) DST_ID %s (%s), TS %s, SRC: %s', \ - self._system, int_id(_stream_id),self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server)) + logger.info('(%s) *UNIT DATA HEADER* STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) DST_ID %s (%s), TS %s, SRC: %s, RPTR: %s', \ + self._system, int_id(_stream_id),self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server,int_id(_source_rptr))) if CONFIG['REPORTS']['REPORT']: self._report.send_bridgeEvent('UNIT DATA HEADER,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 7: - logger.info('(%s) *UNIT VCSBK 1/2 DATA BLOCK * STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s, SRC: %s', \ - self._system, int_id(_stream_id), self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot, int_id(_source_server)) + logger.info('(%s) *UNIT VCSBK 1/2 DATA BLOCK * STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s, SRC: %s, RPTR: %s', \ + self._system, int_id(_stream_id), self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot, int_id(_source_server),int_id(_source_rptr)) if CONFIG['REPORTS']['REPORT']: self._report.send_bridgeEvent('UNIT VCSBK 1/2 DATA BLOCK,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 8: - logger.info('(%s) *UNIT VCSBK 3/4 DATA BLOCK * STREAM ID: %s, RPTR: %s, SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s, SRC: %s', \ - self._system, int_id(_stream_id), self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server)) + logger.info('(%s) *UNIT VCSBK 3/4 DATA BLOCK * STREAM ID: %s, RPTR: %s, SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s, SRC: %s, RPTR: %s', \ + self._system, int_id(_stream_id), self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server),int_id(_source_rptr)) if CONFIG['REPORTS']['REPORT']: self._report.send_bridgeEvent('UNIT VCSBK 3/4 DATA BLOCK,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) else: - logger.info('(%s) *UNKNOWN DATA TYPE* STREAM ID: %s, RPTR: %s, SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s, SRC: %s', \ - self._system, int_id(_stream_id), self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server)) + logger.info('(%s) *UNKNOWN DATA TYPE* STREAM ID: %s, RPTR: %s, SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s, SRC: %s, RPTR: %s', \ + self._system, int_id(_stream_id), self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server),int_id(_source_rptr)) #Send all data to DATA-GATEWAY if enabled and valid if CONFIG['GLOBAL']['DATA_GATEWAY'] and 'DATA-GATEWAY' in CONFIG['SYSTEMS'] and CONFIG['SYSTEMS']['DATA-GATEWAY']['MODE'] == 'OPENBRIDGE' and CONFIG['SYSTEMS']['DATA-GATEWAY']['ENABLED']: From e089bc0c2c4199680ecaed1b9520aae261848eb1 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 9 Aug 2022 13:17:13 +0100 Subject: [PATCH 069/128] Auto topography discovery system: new config directive: under [ALIAS] TOPO_FILE: topography.json A JSON file is output showing all of the SERVER_IDs seen, at the top level, and where they are bridged to. Example: { "2341" : { #Top-level server ID seen "7301" : { #Is bridged with server 7301 "hops" : 2, #Hops it took for the topography packet to reach us "time" : 1660047369.11104, #Timestamp on which the packet was received "ver" : 5, #Version of FBP this bridge speaks "uid" : 1820181884 #Unique ID to identify the topography packet. Mostly so we don't duplicate. } } Squashed commit of the following: commit 950f3e1c3e5157023707ab90df8d51dac2fd1489 Author: Simon Date: Tue Aug 9 13:16:40 2022 +0100 Topo ready for merge commit 4dc9f817a7b4060b9fdb3278c1e99287f9113f6d Author: Simon Date: Tue Aug 9 02:01:08 2022 +0100 Fix trimmer commit 48c520c86377f1f56e9ad841db14596a5f5eaf9c Author: Simon Date: Mon Aug 8 01:35:43 2022 +0100 Think this may be ready :) commit 8a860bb382b1a86aeff1ae47044ef41aa8b91df9 Author: Simon Date: Mon Aug 8 00:29:14 2022 +0100 Fix back to operational params commit 3657760112f39baa5d88aa21a3e7a4b45cf33d12 Author: Simon Date: Mon Aug 8 00:18:18 2022 +0100 UID typo commit 047b1df5a43bb41fc34e5270ef33a300121bd783 Author: Simon Date: Mon Aug 8 00:17:12 2022 +0100 Fix BCTO commit dfe21bfaa3fffe16d52cf8d92640416fb5732eea Author: Simon Date: Mon Aug 8 00:12:48 2022 +0100 Testing with 10 sec commit 8431b4dcf63f571020a96ade1362b05f6e9c7599 Author: Simon Date: Fri Aug 5 00:10:28 2022 +0100 Use UID in BCTO commit 620a9818bfa9966e96522d385869712a229d00f3 Author: Simon Date: Thu Aug 4 02:38:59 2022 +0100 dfkldlk commit 1f92e1b78439a86d9bb6d60f36e473556ae689d7 Author: Simon Date: Thu Aug 4 02:16:48 2022 +0100 retrans with correct passphrase commit 445ae4474c921a94b9dce4abfb62ffe7c9cb16c2 Author: Simon Date: Thu Aug 4 01:47:01 2022 +0100 Retransmit to right systems! commit ba0da271a2837096854ea35912a400618b556367 Author: Simon Date: Thu Aug 4 01:08:56 2022 +0100 my hops commit 80e42f7837c5c0937469848a266e75be44a40090 Author: Simon Date: Thu Aug 4 00:51:47 2022 +0100 dfdf commit 0991670323fdd6f9a2401ba85656ec8786a6831d Author: Simon Date: Thu Aug 4 00:49:10 2022 +0100 fkjkj commit 275306af50a2b384d2f3ba758fca31e2e3fc205c Author: Simon Date: Thu Aug 4 00:48:12 2022 +0100 f commit c9cb71accd851882e53bcef9e66f09c86d304b8a Author: Simon Date: Thu Aug 4 00:47:10 2022 +0100 hoppy commit d01019fa6138163f94e861ac0a6a62a217bdaf59 Author: Simon Date: Thu Aug 4 00:23:39 2022 +0100 bctony commit f3de53d47bb045e39dca31d862389c46ea41c463 Author: Simon Date: Thu Aug 4 00:04:50 2022 +0100 fklflk commit 752b8407a812f37cbfa23dde066e062401895b7a Author: Simon Date: Wed Aug 3 23:59:17 2022 +0100 lkflkk commit dd92b059eef3af67e47332639314ebdee7bf7ef6 Author: Simon Date: Wed Aug 3 23:58:14 2022 +0100 dlfklk commit 220d5bc6bbb5e36a92c0f2e3bcc437bafe371c37 Author: Simon Date: Wed Aug 3 23:57:25 2022 +0100 dlkfdlkf commit d9e46764c1a988415e2ad953ede24baeefa91c39 Author: Simon Date: Wed Aug 3 23:49:52 2022 +0100 dflklxk commit 9aba9d2fdc4ae8f03361bfb8aab35d73f91c2a8e Author: Simon Date: Wed Aug 3 23:48:06 2022 +0100 ;fl;sl commit 0d2d6fc5ea61de554d827f35e4ca71b5a56b0c99 Author: Simon Date: Wed Aug 3 23:46:20 2022 +0100 lskdlk commit aad811c080d15d912fc21dd6b4c7fa96c82ab65e Author: Simon Date: Wed Aug 3 23:39:59 2022 +0100 flklk commit a531b5f2b814c3aba20ae42fd054000a02946d1f Author: Simon Date: Wed Aug 3 23:39:00 2022 +0100 hoppy commit 648bd3d77ccad944763b6dfb0d19ad916bd3cb1c Author: Simon Date: Wed Aug 3 23:37:27 2022 +0100 slfkdlsk commit 32f70379732e4dd82eaa6b3603778582de8181b2 Author: Simon Date: Wed Aug 3 23:35:55 2022 +0100 dflkldk commit e1e58321c198e062d593eef390f7c3545b9b76f7 Author: Simon Date: Wed Aug 3 23:33:49 2022 +0100 djklk commit f7985a6119d3f080a48d7a3556bd47441f15349c Author: Simon Date: Wed Aug 3 23:32:59 2022 +0100 f f commit dfcf4184f438fde07ba9943a3b80873c705534d0 Author: Simon Date: Wed Aug 3 23:31:58 2022 +0100 fix fix commit dd76e6ce4e47f7e24d24e1ba773719ab8a7494a9 Author: Simon Date: Wed Aug 3 23:30:35 2022 +0100 fix hmac commit 5306f366752b0bc416ab81dfd0a485f4b6b93d11 Author: Simon Date: Wed Aug 3 23:28:40 2022 +0100 10 sec test commit 549f8245e68bff09c183ce17c59e169798f52430 Author: Simon Date: Wed Aug 3 23:23:54 2022 +0100 packet commit 011db46f479cad700dc34d56b7805f09ce443974 Author: Simon Date: Wed Aug 3 23:10:44 2022 +0100 Lets test the TOPO! commit d1cee872e564d2f25bda2589ee73db081bda181e Author: Simon Date: Tue Aug 2 00:47:15 2022 +0100 Topo first pass --- bridge_master.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++- config.py | 7 +++-- const.py | 3 +- hblink.py | 71 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 153 insertions(+), 5 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index bc4ad41..5049f25 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -38,6 +38,7 @@ from time import time,sleep,perf_counter import importlib.util import re import copy +import json from setproctitle import setproctitle #from crccheck.crc import Crc32 @@ -126,6 +127,7 @@ def config_reports(_config, _factory): i = i +1 logger.info('(REPORT) %s systems have at least one peer',i) logger.info('(REPORT) Subscriber Map has %s entries',len(SUB_MAP)) + logger.info('(REPORT) %s SERVER_ID\'s seen by topography system', len(TOPO)) logger.info('(REPORT) HBlink TCP reporting server configured') @@ -409,6 +411,27 @@ def subMapWrite(): except: logger.warning('(SUBSCRIBER) Cannot write SUB_MAP to file') +def topoWrite(): + try: + _fh = open(CONFIG['ALIASES']['PATH'] + CONFIG['ALIASES']['TOPO_FILE'],'w') + json.dump(TOPO,_fh) + _fh.close() + logger.info('(TOPO) Writing topography file to disk') + except: + logger.warning('(TOPO) Cannot write topography file to disk') + +def topoRead(): + try: + _fh = open(CONFIG['ALIASES']['PATH'] + CONFIG['ALIASES']['TOPO_FILE'],'r') + _topo = {} + _topo = json.load(_fh) + _fh.close() + logger.info('(TOPO) Reading topography file from disk') + except: + logger.warning('(TOPO) Cannot read topography file from disk') + finally: + return(_topo) + #Subscriber Map trimmer loop def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') @@ -538,6 +561,25 @@ def stream_trimmer_loop(): else: logger.debug('(%s) Attemped to remove OpenBridge Stream ID %s not in the Stream ID list: %s', system, int_id(stream_id), [id for id in systems[system].STATUS]) +def topoTrimmer(): + logger.debug('(TOPO) Trimming stale entries') + _now = time() + _toprem = [] + for _src in TOPO: + _dstrem = [] + for _dst in TOPO[_src]: + if _now - TOPO[_src][_dst]['time'] > 1800: + _dstrem.append(_dst) + for _remove in _dstrem: + TOPO[_src].pop(_remove) + if len(TOPO[_src]) == 0: + _toprem.append(_src) + for _remove in _toprem: + TOPO.pop(_remove) + topoWrite() + + + def sendVoicePacket(self,pkt,_source_id,_dest_id,_slot): _stream_id = pkt[16:20] _pkt_time = time() @@ -1876,6 +1918,30 @@ class routerOBP(OPENBRIDGE): self.STATUS[_stream_id]['_fin'] = True self.STATUS[_stream_id]['lastSeq'] = False + + def process_bcto(self,_uid,_src,_dst,_ver,_hops): + _uid = int_id(_uid) + _src = int_id(_src) + _dst = int_id(_dst) + _ver = int.from_bytes(_ver,'big') + _hops = int.from_bytes(_hops,'big') + if _src not in TOPO: + TOPO[_src] = {} + TOPO[_src][_dst] = { + 'ver' : _ver, + 'time' : time(), + 'uid' : _uid, + 'hops' : _hops, + } + + def check_bcto_uid(self,_uid): + _uid = int_id(_uid) + for src in TOPO: + for dst in TOPO[src]: + if TOPO[src][dst]['uid'] == _uid: + return(True) + return(False) + class routerHBP(HBSYSTEM): @@ -2904,6 +2970,9 @@ if __name__ == '__main__': reactor.stop() if CONFIG['ALIASES']['SUB_MAP_FILE']: subMapWrite() + if CONFIG['ALIASES']['TOPO_FILE']: + topoWrite() + # Set signal handers so that we can gracefully exit if need be for sig in [signal.SIGINT, signal.SIGTERM]: @@ -2921,7 +2990,7 @@ if __name__ == '__main__': CONFIG['_LOCAL_SUBSCRIBER_IDS'] = local_subscriber_ids CONFIG['_SERVER_IDS'] = server_ids - + TOPO = topoRead() # Import the ruiles file as a module, and create BRIDGES from it spec = importlib.util.spec_from_file_location("module.name", cli_args.RULES_FILE) @@ -3118,6 +3187,12 @@ if __name__ == '__main__': sub_trimmer = sub_trimmer_task.start(3600)#3600 sub_trimmer.addErrback(loopingErrHandle) + #topography trimmer + topo_trimmer_task = task.LoopingCall(topoTrimmer) + topo_trimmer = topo_trimmer_task.start(610)#610 + topo_trimmer.addErrback(loopingErrHandle) + + #more threads reactor.suggestThreadPoolSize(100) diff --git a/config.py b/config.py index 15caf6d..504b9c9 100755 --- a/config.py +++ b/config.py @@ -148,7 +148,8 @@ def build_config(_config_file): 'ANNOUNCEMENT_LANGUAGES': config.get(section, 'ANNOUNCEMENT_LANGUAGES'), 'SERVER_ID': config.getint(section, 'SERVER_ID').to_bytes(4, 'big'), 'DATA_GATEWAY': config.getboolean(section, 'DATA_GATEWAY'), - 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS') + 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS'), + 'ISO_COUNTRY_CODE' : config.get(section, 'ISO_COUNTRY_CODE'), }) if not CONFIG['GLOBAL']['ANNOUNCEMENT_LANGUAGES']: @@ -186,7 +187,9 @@ def build_config(_config_file): 'SUB_MAP_FILE': config.get(section, 'SUB_MAP_FILE'), 'LOCAL_SUBSCRIBER_FILE': config.get(section, 'LOCAL_SUBSCRIBER_FILE'), 'SERVER_ID_URL': config.get(section, 'SERVER_ID_URL'), - 'SERVER_ID_FILE': config.get(section, 'SERVER_ID_FILE') + 'SERVER_ID_FILE': config.get(section, 'SERVER_ID_FILE'), + 'TOPO_FILE': config.get(section, 'TOPO_FILE'), + }) diff --git a/const.py b/const.py index 630b76f..862555a 100755 --- a/const.py +++ b/const.py @@ -83,9 +83,10 @@ BCKA = b'BCKA' BCSQ = b'BCSQ' BCST = b'BCST' BCVE = b'BCVE' +BCTO = b'BCTO' #Protocol version -VER = 5 +VER = 6 # Higheset peer ID permitted by HBP PEER_MAX = 4294967295 diff --git a/hblink.py b/hblink.py index d2a4a52..a17f3ae 100755 --- a/hblink.py +++ b/hblink.py @@ -163,6 +163,11 @@ class OPENBRIDGE(DatagramProtocol): self._bcve = self._bcve_task.start(60) self._bcve.addErrback(self.loopingErrHandle) + logger.debug('(%s) *BridgeControl* starting topography timer',self._system) + self._bcto_task = task.LoopingCall(self.send_my_bcto) + self._bcto = self._bcto_task.start(604)#600 + self._bcto.addErrback(self.loopingErrHandle) + def dereg(self): logger.info('(%s) is mode OPENBRIDGE. No De-Registration required, continuing shutdown', self._system) @@ -262,12 +267,52 @@ class OPENBRIDGE(DatagramProtocol): logger.trace('(%s) *BridgeControl* sent BCVE. Ver: %s',self._system,VER) else: logger.trace('(%s) *BridgeControl* not sending BCVE, TARGET_IP currently not known',self._system) + + def send_my_bcto(self): + if self._config['VER'] > 5: + _hops = 1 + _hops = _hops.to_bytes(1,'big') + for system in self._CONFIG['SYSTEMS']: + if self._CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and self._CONFIG['SYSTEMS'][system]['ENABLED']: + if self._config['ENHANCED_OBP'] and self._config['TARGET_IP']: + if '_bcka' in self._CONFIG['SYSTEMS'][system] and self._CONFIG['SYSTEMS'][system]['_bcka'] < time() - 60: + continue + _uid = bytes_4(randint(0x00, 0xFFFFFFFF)) + _packet = b''.join([BCTO,_uid,self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops]) + _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) + _h.update(_packet) + _hash = _h.digest() + _packet = b''.join([_packet,_hash]) + self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) + logger.trace('(%s) *BridgeControl* sent BCTO. DST: %s, VER: %s ',self._system,int_id(self._CONFIG['SYSTEMS'][system]['NETWORK_ID']),self._CONFIG['SYSTEMS'][system]['VER']) + else: + logger.trace('(%s) *BridgeControl* not sending BCTO, TARGET_IP currently not known. DST: %s, VER: %s ',self._system,int_id(self._CONFIG['SYSTEMS'][system]['NETWORK_ID']),self._CONFIG['SYSTEMS'][system]['VER']) + + + def retransmit_bcto(self,_string,_hops): + _hops += 1 + _hops = _hops.to_bytes(1,'big') + for system in self._CONFIG['SYSTEMS']: + if self._CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and self._CONFIG['SYSTEMS'][system]['VER'] > 5: + if self._config['ENHANCED_OBP'] and self._config['TARGET_IP']: + _packet = b''.join([BCTO,_string,_hops]) + _h = blake2b(key=self._CONFIG['SYSTEMS'][system]['PASSPHRASE'], digest_size=16) + _h.update(_packet) + _hash = _h.digest() + _packet = b''.join([_packet,_hash]) + self.transport.write(_packet, (self._CONFIG['SYSTEMS'][system]['TARGET_IP'], self._CONFIG['SYSTEMS'][system]['TARGET_PORT'])) + logger.trace('(%s) *BridgeControl* retransmitted BCTO.',self._system) + else: + logger.trace('(%s) *BridgeControl* not retransmitting BCTO, TARGET_IP currently not known.',self._system) def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data,_hash,_hops = b'', _source_server = b'\x00\x00\x00\x00', _ber = b'\x00', _rssi = b'\x00', _source_rptr = b'\x00\x00\x00\x00'): pass #print(int_id(_peer_id), int_id(_rf_src), int_id(_dst_id), int_id(_seq), _slot, _call_type, _frame_type, repr(_dtype_vseq), int_id(_stream_id)) + + def process_bcto(self,src,dst,ver): + pass def datagramReceived(self, _packet, _sockaddr): # Keep This Line Commented Unless HEAVILY Debugging! @@ -289,7 +334,7 @@ class OPENBRIDGE(DatagramProtocol): if compare_digest(_hash, _ckhs) and (_sockaddr == self._config['TARGET_SOCK'] or self._config['RELAX_CHECKS']): _peer_id = _data[11:15] if self._config['NETWORK_ID'] != _peer_id: - logger.error('(%s) OpenBridge packet discarded because NETWORK_ID: %s Does not match sent Peer ID: %s', self._system, int_id(self._config['NETWORK_ID']), int_id(_peer_id)) + logger.error('(%s) OpenBridge packet discarded because NETWORK_ID: %s Does not match sent Server ID: %s', self._system, int_id(self._config['NETWORK_ID']), int_id(_peer_id)) return #This is a v1 packet, so all the extended stuff we can set to default @@ -704,6 +749,30 @@ class OPENBRIDGE(DatagramProtocol): else: h,p = _sockaddr logger.warning('(%s) *ProtoControl* BCVE invalid, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:53]), len(_packet[53:]), repr(_packet[53:]),h,p) + + if _packet[:4] == BCTO: + if self._config['VER'] > 5: + _hash = _packet[18:] + _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) + _h.update(_packet[:18]) + _hash2 = _h.digest() + _uid = _packet[4:8] + _src = _packet[8:12] + _dst = _packet[12:16] + _ver = _packet[16:17] + _hops = _packet[17:18] + if _hash == _hash2: + logger.trace('(%s) *ProtoControl* BCTO received: %s connected to %s with proto ver. %s. HOPS: %s ',self._system, int_id(_src), int_id(_dst), int.from_bytes(_ver,'big'), int.from_bytes(_hops,'big')) + if int.from_bytes(_hops,'big') < 10 and _src != self._CONFIG['GLOBAL']['SERVER_ID'] and not self.check_bcto_uid(_uid): + self.retransmit_bcto(_packet[4:17],int.from_bytes(_hops,'big')) + else: + logger.trace('(%s) *BridgeControl* not retransmitting BCTO - hop count exceeded, already seen or my packet',self._system) + if not self.check_bcto_uid(_uid): + self.process_bcto(_uid,_src,_dst,_ver,_hops) + else: + h,p = _sockaddr + logger.warning('(%s) *ProtoControl* BCTO invalid, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:18]), len(_packet[18:]),repr(_packet[18:]),h,p) + From e6d5029e8a7c9d58a74cf59a6eee2551dbdf8a80 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 9 Aug 2022 14:10:32 +0100 Subject: [PATCH 070/128] no need for country code --- config.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config.py b/config.py index 504b9c9..256bb0a 100755 --- a/config.py +++ b/config.py @@ -29,7 +29,6 @@ change. import configparser import sys import const - import socket import ipaddress from socket import gethostbyname @@ -148,9 +147,7 @@ def build_config(_config_file): 'ANNOUNCEMENT_LANGUAGES': config.get(section, 'ANNOUNCEMENT_LANGUAGES'), 'SERVER_ID': config.getint(section, 'SERVER_ID').to_bytes(4, 'big'), 'DATA_GATEWAY': config.getboolean(section, 'DATA_GATEWAY'), - 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS'), - 'ISO_COUNTRY_CODE' : config.get(section, 'ISO_COUNTRY_CODE'), - + 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS') }) if not CONFIG['GLOBAL']['ANNOUNCEMENT_LANGUAGES']: CONFIG['GLOBAL']['ANNOUNCEMENT_LANGUAGES'] = languages From 938f45f1c54a30351ab55da242609c5ef514fe02 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 9 Aug 2022 14:14:40 +0100 Subject: [PATCH 071/128] Top --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 5049f25..64dec94 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -421,9 +421,9 @@ def topoWrite(): logger.warning('(TOPO) Cannot write topography file to disk') def topoRead(): + _topo = {} try: _fh = open(CONFIG['ALIASES']['PATH'] + CONFIG['ALIASES']['TOPO_FILE'],'r') - _topo = {} _topo = json.load(_fh) _fh.close() logger.info('(TOPO) Reading topography file from disk') From 7d54e520ee8054e2840fd95efdafa4f500b7de03 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 9 Aug 2022 14:29:43 +0100 Subject: [PATCH 072/128] loro fix --- loro.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/loro.cfg b/loro.cfg index 2c392ef..b0a01ec 100644 --- a/loro.cfg +++ b/loro.cfg @@ -116,6 +116,7 @@ STALE_DAYS: 7 SUB_MAP_FILE: SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv SERVER_ID_FILE: server_ids.tsv +TOPO_FILE: topography.json #Read further repeater configs from MySQL [MYSQL] From 3348e0a212fe9a64e25f234a3a2034bf167b27b5 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 9 Aug 2022 18:38:17 +0100 Subject: [PATCH 073/128] Fix IPV6 send problems --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index a17f3ae..5f9062f 100755 --- a/hblink.py +++ b/hblink.py @@ -300,7 +300,7 @@ class OPENBRIDGE(DatagramProtocol): _h.update(_packet) _hash = _h.digest() _packet = b''.join([_packet,_hash]) - self.transport.write(_packet, (self._CONFIG['SYSTEMS'][system]['TARGET_IP'], self._CONFIG['SYSTEMS'][system]['TARGET_PORT'])) + systems[system].transport.write(_packet, (self._CONFIG['SYSTEMS'][system]['TARGET_IP'], self._CONFIG['SYSTEMS'][system]['TARGET_PORT'])) logger.trace('(%s) *BridgeControl* retransmitted BCTO.',self._system) else: logger.trace('(%s) *BridgeControl* not retransmitting BCTO, TARGET_IP currently not known.',self._system) From e400191dc370470020bb7c6676ada69019b5fe76 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 9 Aug 2022 23:01:40 +0100 Subject: [PATCH 074/128] dkjdjk --- hblink.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hblink.py b/hblink.py index 5f9062f..4e3844e 100755 --- a/hblink.py +++ b/hblink.py @@ -278,6 +278,8 @@ class OPENBRIDGE(DatagramProtocol): if '_bcka' in self._CONFIG['SYSTEMS'][system] and self._CONFIG['SYSTEMS'][system]['_bcka'] < time() - 60: continue _uid = bytes_4(randint(0x00, 0xFFFFFFFF)) + #add data from this packet to our local TOPO view + self.process_bcto(self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops) _packet = b''.join([BCTO,_uid,self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops]) _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) _h.update(_packet) From 494c9fd4526baf22f9ef3c8e98d508c82b2d4649 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 9 Aug 2022 23:20:03 +0100 Subject: [PATCH 075/128] Further refine self processing of BCTO --- hblink.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hblink.py b/hblink.py index 4e3844e..f51f4dc 100755 --- a/hblink.py +++ b/hblink.py @@ -766,11 +766,11 @@ class OPENBRIDGE(DatagramProtocol): if _hash == _hash2: logger.trace('(%s) *ProtoControl* BCTO received: %s connected to %s with proto ver. %s. HOPS: %s ',self._system, int_id(_src), int_id(_dst), int.from_bytes(_ver,'big'), int.from_bytes(_hops,'big')) if int.from_bytes(_hops,'big') < 10 and _src != self._CONFIG['GLOBAL']['SERVER_ID'] and not self.check_bcto_uid(_uid): + self.process_bcto(_uid,_src,_dst,_ver,_hops) self.retransmit_bcto(_packet[4:17],int.from_bytes(_hops,'big')) else: logger.trace('(%s) *BridgeControl* not retransmitting BCTO - hop count exceeded, already seen or my packet',self._system) - if not self.check_bcto_uid(_uid): - self.process_bcto(_uid,_src,_dst,_ver,_hops) + else: h,p = _sockaddr logger.warning('(%s) *ProtoControl* BCTO invalid, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:18]), len(_packet[18:]),repr(_packet[18:]),h,p) From 59841eadac1f3bc9b3c1628549d9e6a492eca238 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 10 Aug 2022 00:24:32 +0100 Subject: [PATCH 076/128] Revert "Further refine self processing of BCTO" This reverts commit 321360cce9f35d4de956d814b4377cf6f1c353c8. --- hblink.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hblink.py b/hblink.py index f51f4dc..4e3844e 100755 --- a/hblink.py +++ b/hblink.py @@ -766,11 +766,11 @@ class OPENBRIDGE(DatagramProtocol): if _hash == _hash2: logger.trace('(%s) *ProtoControl* BCTO received: %s connected to %s with proto ver. %s. HOPS: %s ',self._system, int_id(_src), int_id(_dst), int.from_bytes(_ver,'big'), int.from_bytes(_hops,'big')) if int.from_bytes(_hops,'big') < 10 and _src != self._CONFIG['GLOBAL']['SERVER_ID'] and not self.check_bcto_uid(_uid): - self.process_bcto(_uid,_src,_dst,_ver,_hops) self.retransmit_bcto(_packet[4:17],int.from_bytes(_hops,'big')) else: logger.trace('(%s) *BridgeControl* not retransmitting BCTO - hop count exceeded, already seen or my packet',self._system) - + if not self.check_bcto_uid(_uid): + self.process_bcto(_uid,_src,_dst,_ver,_hops) else: h,p = _sockaddr logger.warning('(%s) *ProtoControl* BCTO invalid, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:18]), len(_packet[18:]),repr(_packet[18:]),h,p) From abb6163bb9cf9b151de1706368483fa3fa04ef80 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 10 Aug 2022 00:46:28 +0100 Subject: [PATCH 077/128] flo --- hblink.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hblink.py b/hblink.py index 5f9062f..4e3844e 100755 --- a/hblink.py +++ b/hblink.py @@ -278,6 +278,8 @@ class OPENBRIDGE(DatagramProtocol): if '_bcka' in self._CONFIG['SYSTEMS'][system] and self._CONFIG['SYSTEMS'][system]['_bcka'] < time() - 60: continue _uid = bytes_4(randint(0x00, 0xFFFFFFFF)) + #add data from this packet to our local TOPO view + self.process_bcto(self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops) _packet = b''.join([BCTO,_uid,self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops]) _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) _h.update(_packet) From 211e06bb63c9a9a831a04a970e76673ca9077232 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 10 Aug 2022 00:47:23 +0100 Subject: [PATCH 078/128] Revert "dkjdjk" This reverts commit 0fdfec8fc9b59c974ebd68cd50a6dd532e2f3cdb. --- hblink.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/hblink.py b/hblink.py index 4e3844e..5f9062f 100755 --- a/hblink.py +++ b/hblink.py @@ -278,8 +278,6 @@ class OPENBRIDGE(DatagramProtocol): if '_bcka' in self._CONFIG['SYSTEMS'][system] and self._CONFIG['SYSTEMS'][system]['_bcka'] < time() - 60: continue _uid = bytes_4(randint(0x00, 0xFFFFFFFF)) - #add data from this packet to our local TOPO view - self.process_bcto(self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops) _packet = b''.join([BCTO,_uid,self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops]) _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) _h.update(_packet) From 700c7c38741c047f96d87a258448b33f0a1293ac Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 10 Aug 2022 22:23:05 +0100 Subject: [PATCH 079/128] fix network SMS issue --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 64dec94..9a24957 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1664,7 +1664,7 @@ class routerOBP(OPENBRIDGE): self._report.send_bridgeEvent('UNIT CSBK,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 6: logger.info('(%s) *UNIT DATA HEADER* STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) DST_ID %s (%s), TS %s, SRC: %s, RPTR: %s', \ - self._system, int_id(_stream_id),self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server,int_id(_source_rptr))) + self._system, int_id(_stream_id),self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server),int_id(_source_rptr)) if CONFIG['REPORTS']['REPORT']: self._report.send_bridgeEvent('UNIT DATA HEADER,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 7: From 35a9f3305d6b0d957eae553743dacfcf31f68722 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 00:53:26 +0100 Subject: [PATCH 080/128] Better handling of packets older than 5s --- hblink.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 5f9062f..f805208 100755 --- a/hblink.py +++ b/hblink.py @@ -492,7 +492,10 @@ class OPENBRIDGE(DatagramProtocol): #Discard old packets if (int.from_bytes(_timestamp,'big')/1000000000) < (time() - 5): - logger.warning('(%s) Packet more than 5s old!, discarding', self._system) + if _stream_id not in self._laststrid: + logger.warning('(%s) Packet from server % more than 5s old!, discarding', self._system,int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) return #Discard bad source server From b6ba7dca7e39807e9a47c817185823e4d1964672 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 00:56:38 +0100 Subject: [PATCH 081/128] Fix typo --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index f805208..be30130 100755 --- a/hblink.py +++ b/hblink.py @@ -493,7 +493,7 @@ class OPENBRIDGE(DatagramProtocol): #Discard old packets if (int.from_bytes(_timestamp,'big')/1000000000) < (time() - 5): if _stream_id not in self._laststrid: - logger.warning('(%s) Packet from server % more than 5s old!, discarding', self._system,int.from_bytes(_source_server,'big')) + logger.warning('(%s) Packet from server %s more than 5s old!, discarding', self._system,int.from_bytes(_source_server,'big')) self.send_bcsq(_dst_id,_stream_id) self._laststrid.append(_stream_id) return From ba4359adb7cac3d9cd31098696e6934736bf9ac5 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:36:26 +0100 Subject: [PATCH 082/128] Revert "Fix typo" This reverts commit 05b84ba24060e58883755bbd9302b8cae33769ab. --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index be30130..f805208 100755 --- a/hblink.py +++ b/hblink.py @@ -493,7 +493,7 @@ class OPENBRIDGE(DatagramProtocol): #Discard old packets if (int.from_bytes(_timestamp,'big')/1000000000) < (time() - 5): if _stream_id not in self._laststrid: - logger.warning('(%s) Packet from server %s more than 5s old!, discarding', self._system,int.from_bytes(_source_server,'big')) + logger.warning('(%s) Packet from server % more than 5s old!, discarding', self._system,int.from_bytes(_source_server,'big')) self.send_bcsq(_dst_id,_stream_id) self._laststrid.append(_stream_id) return From 66108521195c55f5157ba09409e9b3e398dd9c52 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:36:28 +0100 Subject: [PATCH 083/128] Revert "Better handling of packets older than 5s" This reverts commit 694d5331b26eb1214d08cef07f9329c2a2387639. --- hblink.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hblink.py b/hblink.py index f805208..5f9062f 100755 --- a/hblink.py +++ b/hblink.py @@ -492,10 +492,7 @@ class OPENBRIDGE(DatagramProtocol): #Discard old packets if (int.from_bytes(_timestamp,'big')/1000000000) < (time() - 5): - if _stream_id not in self._laststrid: - logger.warning('(%s) Packet from server % more than 5s old!, discarding', self._system,int.from_bytes(_source_server,'big')) - self.send_bcsq(_dst_id,_stream_id) - self._laststrid.append(_stream_id) + logger.warning('(%s) Packet more than 5s old!, discarding', self._system) return #Discard bad source server From 658de3c1fa764f5604ba8f0ebaf441648a2baa99 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:36:29 +0100 Subject: [PATCH 084/128] Revert "fix network SMS issue" This reverts commit 19cbb5378b04de2e204f5e89df3323697c966dd9. --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 9a24957..64dec94 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1664,7 +1664,7 @@ class routerOBP(OPENBRIDGE): self._report.send_bridgeEvent('UNIT CSBK,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 6: logger.info('(%s) *UNIT DATA HEADER* STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) DST_ID %s (%s), TS %s, SRC: %s, RPTR: %s', \ - self._system, int_id(_stream_id),self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server),int_id(_source_rptr)) + self._system, int_id(_stream_id),self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server,int_id(_source_rptr))) if CONFIG['REPORTS']['REPORT']: self._report.send_bridgeEvent('UNIT DATA HEADER,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 7: From 381f94aaa228b50db05e66d2c2c3a561ff0ce1e6 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:36:29 +0100 Subject: [PATCH 085/128] Revert "Revert "dkjdjk"" This reverts commit 3538196ee0060ee0838ef2d52fe83ac455cd3c2f. --- hblink.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hblink.py b/hblink.py index 5f9062f..4e3844e 100755 --- a/hblink.py +++ b/hblink.py @@ -278,6 +278,8 @@ class OPENBRIDGE(DatagramProtocol): if '_bcka' in self._CONFIG['SYSTEMS'][system] and self._CONFIG['SYSTEMS'][system]['_bcka'] < time() - 60: continue _uid = bytes_4(randint(0x00, 0xFFFFFFFF)) + #add data from this packet to our local TOPO view + self.process_bcto(self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops) _packet = b''.join([BCTO,_uid,self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops]) _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) _h.update(_packet) From 005ef538459716fd6152bef0ef6c694466d7517c Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:38:40 +0100 Subject: [PATCH 086/128] Revert "Fix IPV6 send problems" This reverts commit 3c7f54d7d57a336260f07b4357613ce13f4f42b6. --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 4e3844e..f146c3f 100755 --- a/hblink.py +++ b/hblink.py @@ -302,7 +302,7 @@ class OPENBRIDGE(DatagramProtocol): _h.update(_packet) _hash = _h.digest() _packet = b''.join([_packet,_hash]) - systems[system].transport.write(_packet, (self._CONFIG['SYSTEMS'][system]['TARGET_IP'], self._CONFIG['SYSTEMS'][system]['TARGET_PORT'])) + self.transport.write(_packet, (self._CONFIG['SYSTEMS'][system]['TARGET_IP'], self._CONFIG['SYSTEMS'][system]['TARGET_PORT'])) logger.trace('(%s) *BridgeControl* retransmitted BCTO.',self._system) else: logger.trace('(%s) *BridgeControl* not retransmitting BCTO, TARGET_IP currently not known.',self._system) From fd687d9ed9debc3d798dad989e3b35cc69b729f8 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:38:41 +0100 Subject: [PATCH 087/128] Revert "loro fix" This reverts commit 2e9647a9e19887b1e2ed1921230a28b77d85cb9d. --- loro.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/loro.cfg b/loro.cfg index b0a01ec..2c392ef 100644 --- a/loro.cfg +++ b/loro.cfg @@ -116,7 +116,6 @@ STALE_DAYS: 7 SUB_MAP_FILE: SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv SERVER_ID_FILE: server_ids.tsv -TOPO_FILE: topography.json #Read further repeater configs from MySQL [MYSQL] From cb49d5c069cb1bd7101c501ba60f2b181749a257 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:38:42 +0100 Subject: [PATCH 088/128] Revert "no need for country code" This reverts commit d02e9cec594c250c91f6e9615e3a7aca2bc4ba9f. --- config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 256bb0a..504b9c9 100755 --- a/config.py +++ b/config.py @@ -29,6 +29,7 @@ change. import configparser import sys import const + import socket import ipaddress from socket import gethostbyname @@ -147,7 +148,9 @@ def build_config(_config_file): 'ANNOUNCEMENT_LANGUAGES': config.get(section, 'ANNOUNCEMENT_LANGUAGES'), 'SERVER_ID': config.getint(section, 'SERVER_ID').to_bytes(4, 'big'), 'DATA_GATEWAY': config.getboolean(section, 'DATA_GATEWAY'), - 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS') + 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS'), + 'ISO_COUNTRY_CODE' : config.get(section, 'ISO_COUNTRY_CODE'), + }) if not CONFIG['GLOBAL']['ANNOUNCEMENT_LANGUAGES']: CONFIG['GLOBAL']['ANNOUNCEMENT_LANGUAGES'] = languages From 4750089ada8e0207d001485ed3939985f35fdb81 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:41:28 +0100 Subject: [PATCH 089/128] Revert "Auto topography discovery system:" This reverts commit 7eccd3e307f64d50afef5f70a46139cecfd6a225. --- bridge_master.py | 80 ++---------------------------------------------- config.py | 7 ++--- const.py | 3 +- hblink.py | 37 +++------------------- 4 files changed, 9 insertions(+), 118 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 64dec94..a129beb 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -38,7 +38,6 @@ from time import time,sleep,perf_counter import importlib.util import re import copy -import json from setproctitle import setproctitle #from crccheck.crc import Crc32 @@ -127,7 +126,6 @@ def config_reports(_config, _factory): i = i +1 logger.info('(REPORT) %s systems have at least one peer',i) logger.info('(REPORT) Subscriber Map has %s entries',len(SUB_MAP)) - logger.info('(REPORT) %s SERVER_ID\'s seen by topography system', len(TOPO)) logger.info('(REPORT) HBlink TCP reporting server configured') @@ -411,27 +409,7 @@ def subMapWrite(): except: logger.warning('(SUBSCRIBER) Cannot write SUB_MAP to file') -def topoWrite(): - try: - _fh = open(CONFIG['ALIASES']['PATH'] + CONFIG['ALIASES']['TOPO_FILE'],'w') - json.dump(TOPO,_fh) - _fh.close() - logger.info('(TOPO) Writing topography file to disk') - except: - logger.warning('(TOPO) Cannot write topography file to disk') - -def topoRead(): - _topo = {} - try: - _fh = open(CONFIG['ALIASES']['PATH'] + CONFIG['ALIASES']['TOPO_FILE'],'r') - _topo = json.load(_fh) - _fh.close() - logger.info('(TOPO) Reading topography file from disk') - except: - logger.warning('(TOPO) Cannot read topography file from disk') - finally: - return(_topo) - + #Subscriber Map trimmer loop def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') @@ -446,8 +424,6 @@ def SubMapTrimmer(): if CONFIG['ALIASES']['SUB_MAP_FILE']: subMapWrite() - - # run this every 10 seconds to trim stream ids def stream_trimmer_loop(): @@ -561,25 +537,6 @@ def stream_trimmer_loop(): else: logger.debug('(%s) Attemped to remove OpenBridge Stream ID %s not in the Stream ID list: %s', system, int_id(stream_id), [id for id in systems[system].STATUS]) -def topoTrimmer(): - logger.debug('(TOPO) Trimming stale entries') - _now = time() - _toprem = [] - for _src in TOPO: - _dstrem = [] - for _dst in TOPO[_src]: - if _now - TOPO[_src][_dst]['time'] > 1800: - _dstrem.append(_dst) - for _remove in _dstrem: - TOPO[_src].pop(_remove) - if len(TOPO[_src]) == 0: - _toprem.append(_src) - for _remove in _toprem: - TOPO.pop(_remove) - topoWrite() - - - def sendVoicePacket(self,pkt,_source_id,_dest_id,_slot): _stream_id = pkt[16:20] _pkt_time = time() @@ -1918,30 +1875,6 @@ class routerOBP(OPENBRIDGE): self.STATUS[_stream_id]['_fin'] = True self.STATUS[_stream_id]['lastSeq'] = False - - def process_bcto(self,_uid,_src,_dst,_ver,_hops): - _uid = int_id(_uid) - _src = int_id(_src) - _dst = int_id(_dst) - _ver = int.from_bytes(_ver,'big') - _hops = int.from_bytes(_hops,'big') - if _src not in TOPO: - TOPO[_src] = {} - TOPO[_src][_dst] = { - 'ver' : _ver, - 'time' : time(), - 'uid' : _uid, - 'hops' : _hops, - } - - def check_bcto_uid(self,_uid): - _uid = int_id(_uid) - for src in TOPO: - for dst in TOPO[src]: - if TOPO[src][dst]['uid'] == _uid: - return(True) - return(False) - class routerHBP(HBSYSTEM): @@ -2970,9 +2903,6 @@ if __name__ == '__main__': reactor.stop() if CONFIG['ALIASES']['SUB_MAP_FILE']: subMapWrite() - if CONFIG['ALIASES']['TOPO_FILE']: - topoWrite() - # Set signal handers so that we can gracefully exit if need be for sig in [signal.SIGINT, signal.SIGTERM]: @@ -2990,7 +2920,7 @@ if __name__ == '__main__': CONFIG['_LOCAL_SUBSCRIBER_IDS'] = local_subscriber_ids CONFIG['_SERVER_IDS'] = server_ids - TOPO = topoRead() + # Import the ruiles file as a module, and create BRIDGES from it spec = importlib.util.spec_from_file_location("module.name", cli_args.RULES_FILE) @@ -3187,12 +3117,6 @@ if __name__ == '__main__': sub_trimmer = sub_trimmer_task.start(3600)#3600 sub_trimmer.addErrback(loopingErrHandle) - #topography trimmer - topo_trimmer_task = task.LoopingCall(topoTrimmer) - topo_trimmer = topo_trimmer_task.start(610)#610 - topo_trimmer.addErrback(loopingErrHandle) - - #more threads reactor.suggestThreadPoolSize(100) diff --git a/config.py b/config.py index 504b9c9..15caf6d 100755 --- a/config.py +++ b/config.py @@ -148,8 +148,7 @@ def build_config(_config_file): 'ANNOUNCEMENT_LANGUAGES': config.get(section, 'ANNOUNCEMENT_LANGUAGES'), 'SERVER_ID': config.getint(section, 'SERVER_ID').to_bytes(4, 'big'), 'DATA_GATEWAY': config.getboolean(section, 'DATA_GATEWAY'), - 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS'), - 'ISO_COUNTRY_CODE' : config.get(section, 'ISO_COUNTRY_CODE'), + 'VALIDATE_SERVER_IDS': config.getboolean(section, 'VALIDATE_SERVER_IDS') }) if not CONFIG['GLOBAL']['ANNOUNCEMENT_LANGUAGES']: @@ -187,9 +186,7 @@ def build_config(_config_file): 'SUB_MAP_FILE': config.get(section, 'SUB_MAP_FILE'), 'LOCAL_SUBSCRIBER_FILE': config.get(section, 'LOCAL_SUBSCRIBER_FILE'), 'SERVER_ID_URL': config.get(section, 'SERVER_ID_URL'), - 'SERVER_ID_FILE': config.get(section, 'SERVER_ID_FILE'), - 'TOPO_FILE': config.get(section, 'TOPO_FILE'), - + 'SERVER_ID_FILE': config.get(section, 'SERVER_ID_FILE') }) diff --git a/const.py b/const.py index 862555a..630b76f 100755 --- a/const.py +++ b/const.py @@ -83,10 +83,9 @@ BCKA = b'BCKA' BCSQ = b'BCSQ' BCST = b'BCST' BCVE = b'BCVE' -BCTO = b'BCTO' #Protocol version -VER = 6 +VER = 5 # Higheset peer ID permitted by HBP PEER_MAX = 4294967295 diff --git a/hblink.py b/hblink.py index f146c3f..8ba156d 100755 --- a/hblink.py +++ b/hblink.py @@ -163,11 +163,6 @@ class OPENBRIDGE(DatagramProtocol): self._bcve = self._bcve_task.start(60) self._bcve.addErrback(self.loopingErrHandle) - logger.debug('(%s) *BridgeControl* starting topography timer',self._system) - self._bcto_task = task.LoopingCall(self.send_my_bcto) - self._bcto = self._bcto_task.start(604)#600 - self._bcto.addErrback(self.loopingErrHandle) - def dereg(self): logger.info('(%s) is mode OPENBRIDGE. No De-Registration required, continuing shutdown', self._system) @@ -267,6 +262,7 @@ class OPENBRIDGE(DatagramProtocol): logger.trace('(%s) *BridgeControl* sent BCVE. Ver: %s',self._system,VER) else: logger.trace('(%s) *BridgeControl* not sending BCVE, TARGET_IP currently not known',self._system) +<<<<<<< HEAD def send_my_bcto(self): if self._config['VER'] > 5: @@ -306,15 +302,14 @@ class OPENBRIDGE(DatagramProtocol): logger.trace('(%s) *BridgeControl* retransmitted BCTO.',self._system) else: logger.trace('(%s) *BridgeControl* not retransmitting BCTO, TARGET_IP currently not known.',self._system) +======= +>>>>>>> parent of 7eccd3e (Auto topography discovery system:) def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data,_hash,_hops = b'', _source_server = b'\x00\x00\x00\x00', _ber = b'\x00', _rssi = b'\x00', _source_rptr = b'\x00\x00\x00\x00'): pass #print(int_id(_peer_id), int_id(_rf_src), int_id(_dst_id), int_id(_seq), _slot, _call_type, _frame_type, repr(_dtype_vseq), int_id(_stream_id)) - - def process_bcto(self,src,dst,ver): - pass def datagramReceived(self, _packet, _sockaddr): # Keep This Line Commented Unless HEAVILY Debugging! @@ -336,7 +331,7 @@ class OPENBRIDGE(DatagramProtocol): if compare_digest(_hash, _ckhs) and (_sockaddr == self._config['TARGET_SOCK'] or self._config['RELAX_CHECKS']): _peer_id = _data[11:15] if self._config['NETWORK_ID'] != _peer_id: - logger.error('(%s) OpenBridge packet discarded because NETWORK_ID: %s Does not match sent Server ID: %s', self._system, int_id(self._config['NETWORK_ID']), int_id(_peer_id)) + logger.error('(%s) OpenBridge packet discarded because NETWORK_ID: %s Does not match sent Peer ID: %s', self._system, int_id(self._config['NETWORK_ID']), int_id(_peer_id)) return #This is a v1 packet, so all the extended stuff we can set to default @@ -751,30 +746,6 @@ class OPENBRIDGE(DatagramProtocol): else: h,p = _sockaddr logger.warning('(%s) *ProtoControl* BCVE invalid, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:53]), len(_packet[53:]), repr(_packet[53:]),h,p) - - if _packet[:4] == BCTO: - if self._config['VER'] > 5: - _hash = _packet[18:] - _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) - _h.update(_packet[:18]) - _hash2 = _h.digest() - _uid = _packet[4:8] - _src = _packet[8:12] - _dst = _packet[12:16] - _ver = _packet[16:17] - _hops = _packet[17:18] - if _hash == _hash2: - logger.trace('(%s) *ProtoControl* BCTO received: %s connected to %s with proto ver. %s. HOPS: %s ',self._system, int_id(_src), int_id(_dst), int.from_bytes(_ver,'big'), int.from_bytes(_hops,'big')) - if int.from_bytes(_hops,'big') < 10 and _src != self._CONFIG['GLOBAL']['SERVER_ID'] and not self.check_bcto_uid(_uid): - self.retransmit_bcto(_packet[4:17],int.from_bytes(_hops,'big')) - else: - logger.trace('(%s) *BridgeControl* not retransmitting BCTO - hop count exceeded, already seen or my packet',self._system) - if not self.check_bcto_uid(_uid): - self.process_bcto(_uid,_src,_dst,_ver,_hops) - else: - h,p = _sockaddr - logger.warning('(%s) *ProtoControl* BCTO invalid, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:18]), len(_packet[18:]),repr(_packet[18:]),h,p) - From 4e6e11ce7c6f40d7beb09e870875938f5b3a598b Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 12:42:53 +0100 Subject: [PATCH 090/128] fix --- hblink.py | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/hblink.py b/hblink.py index 8ba156d..fdd4911 100755 --- a/hblink.py +++ b/hblink.py @@ -262,50 +262,6 @@ class OPENBRIDGE(DatagramProtocol): logger.trace('(%s) *BridgeControl* sent BCVE. Ver: %s',self._system,VER) else: logger.trace('(%s) *BridgeControl* not sending BCVE, TARGET_IP currently not known',self._system) -<<<<<<< HEAD - - def send_my_bcto(self): - if self._config['VER'] > 5: - _hops = 1 - _hops = _hops.to_bytes(1,'big') - for system in self._CONFIG['SYSTEMS']: - if self._CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and self._CONFIG['SYSTEMS'][system]['ENABLED']: - if self._config['ENHANCED_OBP'] and self._config['TARGET_IP']: - if '_bcka' in self._CONFIG['SYSTEMS'][system] and self._CONFIG['SYSTEMS'][system]['_bcka'] < time() - 60: - continue - _uid = bytes_4(randint(0x00, 0xFFFFFFFF)) - #add data from this packet to our local TOPO view - self.process_bcto(self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops) - _packet = b''.join([BCTO,_uid,self._CONFIG['GLOBAL']['SERVER_ID'],self._CONFIG['SYSTEMS'][system]['NETWORK_ID'],self._CONFIG['SYSTEMS'][system]['VER'].to_bytes(1,"big"),_hops]) - _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) - _h.update(_packet) - _hash = _h.digest() - _packet = b''.join([_packet,_hash]) - self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) - logger.trace('(%s) *BridgeControl* sent BCTO. DST: %s, VER: %s ',self._system,int_id(self._CONFIG['SYSTEMS'][system]['NETWORK_ID']),self._CONFIG['SYSTEMS'][system]['VER']) - else: - logger.trace('(%s) *BridgeControl* not sending BCTO, TARGET_IP currently not known. DST: %s, VER: %s ',self._system,int_id(self._CONFIG['SYSTEMS'][system]['NETWORK_ID']),self._CONFIG['SYSTEMS'][system]['VER']) - - - def retransmit_bcto(self,_string,_hops): - _hops += 1 - _hops = _hops.to_bytes(1,'big') - for system in self._CONFIG['SYSTEMS']: - if self._CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and self._CONFIG['SYSTEMS'][system]['VER'] > 5: - if self._config['ENHANCED_OBP'] and self._config['TARGET_IP']: - _packet = b''.join([BCTO,_string,_hops]) - _h = blake2b(key=self._CONFIG['SYSTEMS'][system]['PASSPHRASE'], digest_size=16) - _h.update(_packet) - _hash = _h.digest() - _packet = b''.join([_packet,_hash]) - self.transport.write(_packet, (self._CONFIG['SYSTEMS'][system]['TARGET_IP'], self._CONFIG['SYSTEMS'][system]['TARGET_PORT'])) - logger.trace('(%s) *BridgeControl* retransmitted BCTO.',self._system) - else: - logger.trace('(%s) *BridgeControl* not retransmitting BCTO, TARGET_IP currently not known.',self._system) -======= ->>>>>>> parent of 7eccd3e (Auto topography discovery system:) - - def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data,_hash,_hops = b'', _source_server = b'\x00\x00\x00\x00', _ber = b'\x00', _rssi = b'\x00', _source_rptr = b'\x00\x00\x00\x00'): pass From 6e1289a955181f9c78081d724ca4e1853b4782cb Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 13:47:39 +0100 Subject: [PATCH 091/128] Fix typo preventing network SMS sending --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index a129beb..c3e9104 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1621,7 +1621,7 @@ class routerOBP(OPENBRIDGE): self._report.send_bridgeEvent('UNIT CSBK,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 6: logger.info('(%s) *UNIT DATA HEADER* STREAM ID: %s, RPTR: %s SUB: %s (%s) PEER: %s (%s) DST_ID %s (%s), TS %s, SRC: %s, RPTR: %s', \ - self._system, int_id(_stream_id),self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server,int_id(_source_rptr))) + self._system, int_id(_stream_id),self.get_rptr(_source_rptr), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot,int_id(_source_server),int_id(_source_rptr)) if CONFIG['REPORTS']['REPORT']: self._report.send_bridgeEvent('UNIT DATA HEADER,DATA,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) elif _dtype_vseq == 7: From 133c90b92a0a81ef279598ec19d9f735730ba82f Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 11 Aug 2022 13:51:22 +0100 Subject: [PATCH 092/128] better logging of packets older than 5s --- hblink.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index fdd4911..4dd90f9 100755 --- a/hblink.py +++ b/hblink.py @@ -445,7 +445,10 @@ class OPENBRIDGE(DatagramProtocol): #Discard old packets if (int.from_bytes(_timestamp,'big')/1000000000) < (time() - 5): - logger.warning('(%s) Packet more than 5s old!, discarding', self._system) + if _stream_id not in self._laststrid: + logger.warning('(%s) Packet from server %s more than 5s old!, discarding', self._system,int.from_bytes(_source_server,'big')) + self.send_bcsq(_dst_id,_stream_id) + self._laststrid.append(_stream_id) return #Discard bad source server From 8f78236442555d930ca3c98ca590ac69115f8b8c Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 14 Aug 2022 12:53:51 +0100 Subject: [PATCH 093/128] More refinement of logging info --- bridge_master.py | 2 +- hblink.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index c3e9104..bf8ce10 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -88,7 +88,7 @@ from AMI import AMI # Does anybody read this stuff? There's a PEP somewhere that says I should do this. __author__ = 'Cortney T. Buffington, N0MJS, Forked by Simon Adlem - G7RZU' -__copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group, Simon Adlem, G7RZU 2020,2021' +__copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group, Simon Adlem, G7RZU 2020,2021, 2022' __credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT; Jon Lee, G4TSN; Norman Williams, M6NBP, Eric Craw KF7EEL' __license__ = 'GNU GPLv3' __maintainer__ = 'Simon Adlem G7RZU' diff --git a/hblink.py b/hblink.py index 4dd90f9..a846bd4 100755 --- a/hblink.py +++ b/hblink.py @@ -72,7 +72,7 @@ logging.trace = partial(logging.log, logging.TRACE) # Does anybody read this stuff? There's a PEP somewhere that says I should do this. __author__ = 'Cortney T. Buffington, N0MJS, Forked by Simon Adlem - G7RZU' -__copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group, Simon Adlem, G7RZU 2020,2021' +__copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group, Simon Adlem, G7RZU 2020,2021,2022' __credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT; Jon Lee, G4TSN; Norman Williams, M6NBP' __license__ = 'GNU GPLv3' __maintainer__ = 'Simon Adlem G7RZU' @@ -475,7 +475,7 @@ class OPENBRIDGE(DatagramProtocol): _inthops = _hops +1 if _inthops > 10: - logger.warning('(%s) MAX HOPS exceed, dropping. Hops: %s, DST: %s', self._system, _inthops, _int_dst_id) + logger.warning('(%s) MAX HOPS exceed, dropping. Hops: %s, DST: %s, SRC: %s', self._system, _inthops, _int_dst_id, int.from_bytes(_source_server,'big')) self.send_bcsq(_dst_id,_stream_id) return From 4398a86f145acd47878d889333324f14c0d1eb9a Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 15 Aug 2022 23:44:33 +0100 Subject: [PATCH 094/128] Fix error in fi error reporting --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index bf8ce10..ff41df7 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1783,7 +1783,7 @@ class routerOBP(OPENBRIDGE): hr_times = None if not fi: - logger.warning("(%s) OBP *LoopControl* fi is empty for some reason : %s, STREAM ID: %s, TG: %s, TS: %s",self._system, int_id(_stream_id), int_id(_dst_id),_sysslot) + logger.warning("(%s) OBP *LoopControl* fi is empty for some reason : STREAM ID: %s, TG: %s, TS: %s",self._system, int_id(_stream_id), int_id(_dst_id),_sysslot) return if self._system != fi: From d369093b92edb136a53799150a6c9ebdf6b6c2f0 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 21 Aug 2022 01:51:12 +0100 Subject: [PATCH 095/128] Extra checks on JSON files downloaded --- hblink.py | 83 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/hblink.py b/hblink.py index a846bd4..0b1a66c 100755 --- a/hblink.py +++ b/hblink.py @@ -1389,12 +1389,16 @@ def try_download(_path, _file, _url, _stale,): except IOError: result = 'ID ALIAS MAPPER: \'{}\' could not be downloaded due to an IOError'.format(_file) else: - try: - with open(_path+_file, 'wb') as outfile: - outfile.write(data) - outfile.close() - except IOError: - result = 'ID ALIAS mapper \'{}\' file could not be written due to an IOError'.format(_file) + if data and (data != b'{}'): + try: + with open(_path+_file, 'wb') as outfile: + outfile.write(data) + outfile.close() + except IOError: + result = 'ID ALIAS mapper \'{}\' file could not be written due to an IOError'.format(_file) + else: + result = 'ID ALIAS mapper \'{}\' file not written because downloaded data is empty for some reason'.format(_file) + else: result = 'ID ALIAS MAPPER: \'{}\' is current, not downloaded'.format(_file) @@ -1417,6 +1421,11 @@ def mk_server_dict(path,filename): # ID ALIAS CREATION # Download def mk_aliases(_config): + peer_ids = {} + subscriber_ids = {} + local_subscriber_ids = {} + talkgroup_ids = {} + server_ids = {} if _config['ALIASES']['TRY_DOWNLOAD'] == True: # Try updating peer aliases file result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE'], _config['ALIASES']['PEER_URL'], _config['ALIASES']['STALE_TIME']) @@ -1431,30 +1440,50 @@ def mk_aliases(_config): result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE'], _config['ALIASES']['SERVER_ID_URL'], _config['ALIASES']['STALE_TIME']) logger.info('(ALIAS) %s', result) - - # Make Dictionaries - peer_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE']) - if peer_ids: - logger.info('(ALIAS) ID ALIAS MAPPER: peer_ids dictionary is available') - - subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SUBSCRIBER_FILE']) - #Add special IDs to DB - subscriber_ids[900999] = 'D-APRS' - subscriber_ids[4294967295] = 'SC' + try: + _peer_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE']) + except Exception as e: + logger.error('(ALIAS) ID ALIAS MAPPER: problem with data in peer_ids dictionary, not updating: %s',e) + else: + peer_ids = _peer_ids + if peer_ids: + logger.info('(ALIAS) ID ALIAS MAPPER: peer_ids dictionary is available') - if subscriber_ids: - logger.info('(ALIAS) ID ALIAS MAPPER: subscriber_ids dictionary is available') + try: + _subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SUBSCRIBER_FILE']) + except Exception as e: + logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in subscriber_ids dictionary, not updating: %s',e) + else: + subscriber_ids = _subscriber_ids + #Add special IDs to DB + subscriber_ids[900999] = 'D-APRS' + subscriber_ids[4294967295] = 'SC' - talkgroup_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['TGID_FILE']) - if talkgroup_ids: - logger.info('(ALIAS) ID ALIAS MAPPER: talkgroup_ids dictionary is available') - - local_subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['LOCAL_SUBSCRIBER_FILE']) - if subscriber_ids: - logger.info('(ALIAS) ID ALIAS MAPPER: local_subscriber_ids dictionary is available') - - server_ids = mk_server_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE']) + if subscriber_ids: + logger.info('(ALIAS) ID ALIAS MAPPER: subscriber_ids dictionary is available') + try: + _talkgroup_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['TGID_FILE']) + except Exception as e: + logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in talkgroup_ids dictionary, not updating: %s',e) + else: + talkgroup_ids = _talkgroup_ids + if talkgroup_ids: + logger.info('(ALIAS) ID ALIAS MAPPER: talkgroup_ids dictionary is available') + try: + _local_subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['LOCAL_SUBSCRIBER_FILE']) + except Exception as e: + logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in local_subscriber_ids dictionary, not updating: %s',e) + else: + local_subscriber_ids = _local_subscriber_ids + if subscriber_ids: + logger.info('(ALIAS) ID ALIAS MAPPER: local_subscriber_ids dictionary is available') + try: + _server_ids = mk_server_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE']) + except Exception as e: + logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in server_ids dictionary, not updating: %s',e) + else: + server_ids = _server_ids if server_ids: logger.info('(ALIAS) ID ALIAS MAPPER: server_ids dictionary is available') From fb7a2db9f874db1e01073433729aaa1cb46d848d Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 00:10:30 +0100 Subject: [PATCH 096/128] GC stats and leak detection --- bridge_master.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bridge_master.py b/bridge_master.py index ff41df7..4fb3f6b 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -82,6 +82,11 @@ from binascii import b2a_hex as ahex from AMI import AMI +#debugging and profiling +import gc + +gc.set_debug(gc.DEBUG_STATS) +gc.set_debug(gc.DEBUG_LEAK) ##from hmac import new as hmac_new, compare_digest ##from hashlib import sha256, hash From 7cfa70dbd44b6a5857a3bd698a25f2cddccb96b8 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 00:13:51 +0100 Subject: [PATCH 097/128] d --- bridge_master.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 4fb3f6b..d2b9400 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -85,8 +85,7 @@ from AMI import AMI #debugging and profiling import gc -gc.set_debug(gc.DEBUG_STATS) -gc.set_debug(gc.DEBUG_LEAK) +gc.set_debug(gc.DEBUG_LEAK, gc.DEBUG_STATS) ##from hmac import new as hmac_new, compare_digest ##from hashlib import sha256, hash From 2c1c023e0842372aa3309b48184c3800ff35dc73 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 00:15:42 +0100 Subject: [PATCH 098/128] dkl --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index d2b9400..e583fc9 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -85,7 +85,7 @@ from AMI import AMI #debugging and profiling import gc -gc.set_debug(gc.DEBUG_LEAK, gc.DEBUG_STATS) +gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) ##from hmac import new as hmac_new, compare_digest ##from hashlib import sha256, hash From d38c095ab9880acd1df13a4241f9360dbc9f269d Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 00:32:59 +0100 Subject: [PATCH 099/128] garbae! --- bridge_master.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bridge_master.py b/bridge_master.py index e583fc9..3c52735 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2907,6 +2907,8 @@ if __name__ == '__main__': reactor.stop() if CONFIG['ALIASES']['SUB_MAP_FILE']: subMapWrite() + + print(gc.garbage) # Set signal handers so that we can gracefully exit if need be for sig in [signal.SIGINT, signal.SIGTERM]: From 85047a7c106c8ff592e1615f3a3124f9769597e5 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 00:33:47 +0100 Subject: [PATCH 100/128] fd --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 3c52735..5b65a36 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2908,7 +2908,7 @@ if __name__ == '__main__': if CONFIG['ALIASES']['SUB_MAP_FILE']: subMapWrite() - print(gc.garbage) + print("<<<<<<<<< Date: Tue, 23 Aug 2022 00:37:27 +0100 Subject: [PATCH 101/128] Dkjskj --- bridge_master.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 5b65a36..4be635e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2901,14 +2901,13 @@ if __name__ == '__main__': # Set up the signal handler def sig_handler(_signal, _frame): + print("<<<<<<<<< Date: Tue, 23 Aug 2022 00:38:50 +0100 Subject: [PATCH 102/128] flkjdkj --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 4be635e..f7c36c5 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2901,7 +2901,7 @@ if __name__ == '__main__': # Set up the signal handler def sig_handler(_signal, _frame): - print("<<<<<<<<< Date: Tue, 23 Aug 2022 00:39:38 +0100 Subject: [PATCH 103/128] djkjk --- bridge_master.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index f7c36c5..e583fc9 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -2901,7 +2901,6 @@ if __name__ == '__main__': # Set up the signal handler def sig_handler(_signal, _frame): - print(gc.garbage) logger.info('(GLOBAL) SHUTDOWN: CONFBRIDGE IS TERMINATING WITH SIGNAL %s', str(_signal)) hblink_handler(_signal, _frame) logger.info('(GLOBAL) SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR') From 5abbf2e712a9d4573476da15bd13d7e9f70e404c Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 02:36:47 +0100 Subject: [PATCH 104/128] Force garbage collector every hour. --- bridge_master.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bridge_master.py b/bridge_master.py index e583fc9..e17c2e3 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -392,6 +392,9 @@ def statTrimmer(): logger.debug('(ROUTER) STAT bridge %s removed',_bridgerem) if CONFIG['REPORTS']['REPORT']: report_server.send_clients(b'bridge updated') + + #Run garbage collector manually + gc.collect() def kaReporting(): logger.debug('(ROUTER) KeepAlive reporting loop started') From cf7685cec62f7d123cc344c5a5f34d5f3a18367b Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 13:58:57 +0100 Subject: [PATCH 105/128] Don't add an options static if it's default for DIAL --- bridge_master.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index ff41df7..a353b42 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -933,7 +933,8 @@ def options_config(): if _options['TS1_STATIC']: ts1 = _options['TS1_STATIC'].split(',') for tg in ts1: - if not tg: + if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['_DEFAULT_REFLECTOR']: + logger.debug('(OPTIONS) %s not setting TS1 Static %s. Bad TG or conflict with DIAL',_system,tg) continue tg = int(tg) make_static_tg(tg,1,_tmout,_system) @@ -945,7 +946,8 @@ def options_config(): if CONFIG['SYSTEMS'][_system]['TS2_STATIC']: ts2 = CONFIG['SYSTEMS'][_system]['TS2_STATIC'].split(',') for tg in ts2: - if not tg or int(tg) == 0 or int(tg) >= 16777215: + if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['_DEFAULT_REFLECTOR']: + logger.debug('(OPTIONS) %s not setting TS2 Static %s. Bad TG or conflict DIAL',_system,tg) continue tg = int(tg) reset_static_tg(tg,2,_tmout,_system) From c9fb86d1c29a198973287398bfcb0ad6df5a85d4 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 14:00:37 +0100 Subject: [PATCH 106/128] _ --- bridge_master.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index a353b42..7051ed8 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -933,7 +933,7 @@ def options_config(): if _options['TS1_STATIC']: ts1 = _options['TS1_STATIC'].split(',') for tg in ts1: - if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['_DEFAULT_REFLECTOR']: + if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['DEFAULT_REFLECTOR']: logger.debug('(OPTIONS) %s not setting TS1 Static %s. Bad TG or conflict with DIAL',_system,tg) continue tg = int(tg) @@ -946,7 +946,7 @@ def options_config(): if CONFIG['SYSTEMS'][_system]['TS2_STATIC']: ts2 = CONFIG['SYSTEMS'][_system]['TS2_STATIC'].split(',') for tg in ts2: - if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['_DEFAULT_REFLECTOR']: + if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['DEFAULT_REFLECTOR']: logger.debug('(OPTIONS) %s not setting TS2 Static %s. Bad TG or conflict DIAL',_system,tg) continue tg = int(tg) From cde287fbaa2e9cb544ef557c644ccaeaa6415c43 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 14:36:48 +0100 Subject: [PATCH 107/128] don't allow setting a static on TS2 if it's already set on TS1 --- bridge_master.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 7051ed8..d6ac15f 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -946,8 +946,8 @@ def options_config(): if CONFIG['SYSTEMS'][_system]['TS2_STATIC']: ts2 = CONFIG['SYSTEMS'][_system]['TS2_STATIC'].split(',') for tg in ts2: - if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['DEFAULT_REFLECTOR']: - logger.debug('(OPTIONS) %s not setting TS2 Static %s. Bad TG or conflict DIAL',_system,tg) + if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['DEFAULT_REFLECTOR'] or tg in ts1: + logger.debug('(OPTIONS) %s not setting TS2 Static %s. Bad TG or conflict with DIAL or TS1',_system,tg) continue tg = int(tg) reset_static_tg(tg,2,_tmout,_system) From 058415a0e19fc16eced074d533165263d38794d2 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 20:37:01 +0100 Subject: [PATCH 108/128] Fix bug --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index d6ac15f..eaecc45 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -946,7 +946,7 @@ def options_config(): if CONFIG['SYSTEMS'][_system]['TS2_STATIC']: ts2 = CONFIG['SYSTEMS'][_system]['TS2_STATIC'].split(',') for tg in ts2: - if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['DEFAULT_REFLECTOR'] or tg in ts1: + if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['DEFAULT_REFLECTOR'] or (tg and tg in ts1): logger.debug('(OPTIONS) %s not setting TS2 Static %s. Bad TG or conflict with DIAL or TS1',_system,tg) continue tg = int(tg) From cbfe818e006c378d88e6d56f5a79ff22f6a5bbf6 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 23 Aug 2022 22:30:35 +0100 Subject: [PATCH 109/128] Still trying to fix trace ! --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index eaecc45..a580e39 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -946,7 +946,7 @@ def options_config(): if CONFIG['SYSTEMS'][_system]['TS2_STATIC']: ts2 = CONFIG['SYSTEMS'][_system]['TS2_STATIC'].split(',') for tg in ts2: - if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['DEFAULT_REFLECTOR'] or (tg and tg in ts1): + if not tg or int(tg) == 0 or int(tg) >= 16777215 or tg == _options['DEFAULT_REFLECTOR'] or (tg and ts1 and tg in ts1): logger.debug('(OPTIONS) %s not setting TS2 Static %s. Bad TG or conflict with DIAL or TS1',_system,tg) continue tg = int(tg) From f95b53f8e3787c9ee26314990229789de6dae803 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 01:17:17 +0100 Subject: [PATCH 110/128] Convert string concat to join - more efficient in time and meory --- bridge_master.py | 56 ++++++++++++++++++++++++------------------------ hblink.py | 14 ++++++------ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index a580e39..0b9bf59 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -230,7 +230,7 @@ def make_stat_bridge(_tgid): def make_default_reflector(reflector,_tmout,system): - bridge = '#'+str(reflector) + bridge = ''.join(['#',str(reflector)]) #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] if bridge not in BRIDGES: BRIDGES[bridge] = [] @@ -273,7 +273,7 @@ def reset_static_tg(tg,ts,_tmout,system): return def reset_default_reflector(reflector,_tmout,system): - bridge = '#'+str(reflector) + bridge = ''.join(['#',str(reflector)]) #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] if bridge not in BRIDGES: BRIDGES[bridge] = [] @@ -288,7 +288,7 @@ def reset_default_reflector(reflector,_tmout,system): def make_single_reflector(_tgid,_tmout,_sourcesystem): _tgid_s = str(int_id(_tgid)) - _bridge = '#' + _tgid_s + _bridge = ''.join(['#',_tgid_s]) #1 min timeout for echo if _tgid_s == '9990': _tmout = 1 @@ -620,7 +620,7 @@ def playFileOnRequest(self,fileNumber): sleep(1) _say = [] try: - _say.append(AMBEobj.readSingleFile('/'+_lang+'/ondemand/'+str(fileNumber)+'.ambe')) + _say.append(AMBEobj.readSingleFile(''.join(['/',_lang,'/ondemand/',str(fileNumber),'.ambe']))) except IOError: logger.warning('(%s) cannot read file for number %s',system,fileNumber) return @@ -784,39 +784,39 @@ def options_config(): if 'TS1_1' in _options: _options['TS1_STATIC'] = _options.pop('TS1_1') if 'TS1_2' in _options: - _options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_2') + _options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_2')]) if 'TS1_3' in _options: - _options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_3') + _options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_3')]) if 'TS1_4' in _options: - _options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_4') + _options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_4')]) if 'TS1_5' in _options: - _options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_5') + _options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_5')]) if 'TS1_6' in _options: - _options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_6') + _options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_6')]) if 'TS1_7' in _options: - _options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_7') + _options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_7')]) if 'TS1_8' in _options: - _options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_8') + _options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_8')]) if 'TS1_9' in _options: - _options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_9') + _options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_9')]) if 'TS2_1' in _options: _options['TS2_STATIC'] = _options.pop('TS2_1') if 'TS2_2' in _options: - _options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_2') + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],','. _options.pop('TS2_2')]) if 'TS2_3' in _options: - _options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_3') + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_3')]) if 'TS2_4' in _options: - _options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_4') + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_4')]) if 'TS2_5' in _options: - _options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_5') + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_5')]) if 'TS2_6' in _options: - _options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_6') + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_6')]) if 'TS2_7' in _options: - _options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_7') + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_7')]) if 'TS2_8' in _options: - _options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_8') + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_8')]) if 'TS2_9' in _options: - _options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_9') + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_9')]) if 'UserLink' in _options: _options.pop('UserLink') @@ -1730,7 +1730,7 @@ class routerOBP(OPENBRIDGE): # If we don't have a voice header then don't wait to decode the Embedded LC # just make a new one from the HBP header. This is good enough, and it saves lots of time else: - self.STATUS[_stream_id]['LC'] = LC_OPT + _dst_id + _rf_src + self.STATUS[_stream_id]['LC'] = b''.join([LC_OPT,_dst_id,_rf_src]) _inthops = 0 if _hops: @@ -2070,7 +2070,7 @@ class routerHBP(HBSYSTEM): _target_status[_target['TS']]['TX_RFS'] = _rf_src _target_status[_target['TS']]['TX_PEER'] = _peer_id # Generate LCs (full and EMB) for the TX stream - dst_lc = self.STATUS[_slot]['RX_LC'][0:3] + _target['TGID'] + _rf_src + dst_lc = b''.join([self.STATUS[_slot]['RX_LC'][0:3],_target['TGID'],_rf_src]) _target_status[_target['TS']]['TX_H_LC'] = bptc.encode_header_lc(dst_lc) _target_status[_target['TS']]['TX_T_LC'] = bptc.encode_terminator_lc(dst_lc) _target_status[_target['TS']]['TX_EMB_LC'] = bptc.encode_emblc(dst_lc) @@ -2373,7 +2373,7 @@ class routerHBP(HBSYSTEM): logger.info('(%s) Reflector: Private call from %s to %s',self._system, int_id(_rf_src), _int_dst_id) if _int_dst_id >= 5 and _int_dst_id != 8 and _int_dst_id != 9 and _int_dst_id <= 999999: - _bridgename = '#'+ str(_int_dst_id) + _bridgename = ''.join(['#',str(_int_dst_id)]) if _bridgename not in BRIDGES and not (_int_dst_id >= 4000 and _int_dst_id <= 5000) and not (_int_dst_id >=9991 and _int_dst_id <= 9999): logger.info('(%s) [A] Reflector for TG %s does not exist. Creating as User Activated. Timeout: %s',self._system, _int_dst_id,CONFIG['SYSTEMS'][self._system]['DEFAULT_UA_TIMER']) make_single_reflector(_dst_id,CONFIG['SYSTEMS'][self._system]['DEFAULT_UA_TIMER'],self._system) @@ -2569,7 +2569,7 @@ class routerHBP(HBSYSTEM): # If we don't have a voice header then don't wait to decode it from the Embedded LC # just make a new one from the HBP header. This is good enough, and it saves lots of time else: - self.STATUS[_slot]['RX_LC'] = LC_OPT + _dst_id + _rf_src + self.STATUS[_slot]['RX_LC'] = b''.join([LC_OPT,_dst_id,_rf_src]) #Create default bridge for unknown TG if int_id(_dst_id) >= 5 and int_id(_dst_id) != 9 and int_id(_dst_id) != 4000 and int_id(_dst_id) != 5000 and (str(int_id(_dst_id)) not in BRIDGES): @@ -2672,7 +2672,7 @@ class routerHBP(HBSYSTEM): if _bridge[0:1] == '#': _bridge = _bridge[1:] else: - _bridge = '#'+_bridge + _bridge = ''.join(['#',_bridge]) if _bridge in BRIDGES: _sysIgnore = self.to_target(_peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data, pkt_time, dmrpkt, _bits,_bridge,_system,False,_sysIgnore,_source_server,_ber,_rssi,_source_rptr) @@ -2794,12 +2794,12 @@ class bridgeReportFactory(reportFactory): def send_bridge(self): serialized = pickle.dumps(BRIDGES, protocol=2) #.decode("utf-8", errors='ignore') - self.send_clients(REPORT_OPCODES['BRIDGE_SND']+serialized) + self.send_clients(b''.join([REPORT_OPCODES['BRIDGE_SND'],serialized])) def send_bridgeEvent(self, _data): if isinstance(_data, str): _data = _data.decode('utf-8', error='ignore') - self.send_clients(REPORT_OPCODES['BRDG_EVENT']+_data) + self.send_clients(b''.join([REPORT_OPCODES['BRDG_EVENT'],_data])) #************************************************ @@ -2974,7 +2974,7 @@ if __name__ == '__main__': if CONFIG['SYSTEMS'][system]['ENABLED']: if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER' and (CONFIG['SYSTEMS'][system]['GENERATOR'] > 1): for count in range(CONFIG['SYSTEMS'][system]['GENERATOR']): - _systemname = system+'-'+str(count) + _systemname = ''.join([system,'-',str(count)]) generator[_systemname] = copy.deepcopy(CONFIG['SYSTEMS'][system]) generator[_systemname]['PORT'] = generator[_systemname]['PORT'] + count generator[_systemname]['_default_options'] = "TS1_STATIC={};TS2_STATIC={};SINGLE={};DEFAULT_UA_TIMER={};DEFAULT_REFLECTOR={};VOICE={};LANG={}".format(generator[_systemname]['TS1_STATIC'],generator[_systemname]['TS2_STATIC'],int(generator[_systemname]['SINGLE_MODE']),generator[_systemname]['DEFAULT_UA_TIMER'],generator[_systemname]['DEFAULT_REFLECTOR'],int(generator[_systemname]['VOICE_IDENT']), generator[_systemname]['ANNOUNCEMENT_LANGUAGE']) diff --git a/hblink.py b/hblink.py index 0b1a66c..28fe40f 100755 --- a/hblink.py +++ b/hblink.py @@ -256,7 +256,7 @@ class OPENBRIDGE(DatagramProtocol): def send_bcve(self): if self._config['ENHANCED_OBP'] and self._config['TARGET_IP']: - _packet = BCVE + VER.to_bytes(1,'big') + _packet = b''.join([BCVE,VER.to_bytes(1,'big')]) _packet = b''.join([_packet, (hmac_new(self._config['PASSPHRASE'],_packet[4:5],sha1).digest())]) self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) logger.trace('(%s) *BridgeControl* sent BCVE. Ver: %s',self._system,VER) @@ -872,11 +872,11 @@ class HBSYSTEM(DatagramProtocol): def master_dereg(self): for _peer in self._peers: - self.send_peer(_peer, MSTCL + _peer) + self.send_peer(_peer, b''.join([MSTCL,_peer])) logger.info('(%s) De-Registration sent to Peer: %s (%s)', self._system, self._peers[_peer]['CALLSIGN'], self._peers[_peer]['RADIO_ID']) def peer_dereg(self): - self.send_master(RPTCL + self._config['RADIO_ID']) + self.send_master(b''.join([RPTCL,self._config['RADIO_ID']])) logger.info('(%s) De-Registration sent to Master: %s:%s', self._system, self._config['MASTER_SOCKADDR'][0], self._config['MASTER_SOCKADDR'][1]) def proxy_IPBlackList(self,peer_id,sockaddr): @@ -1376,9 +1376,9 @@ class reportFactory(Factory): def try_download(_path, _file, _url, _stale,): no_verify = ssl._create_unverified_context() now = time() - file_exists = isfile(_path+_file) == True + file_exists = isfile(''.join([_path,_file])) == True if file_exists: - file_old = (getmtime(_path+_file) + _stale) < now + file_old = (getmtime(''.join([_path,_file])) + _stale) < now if not file_exists or (file_exists and file_old): try: with urlopen(_url, context=no_verify) as response: @@ -1391,7 +1391,7 @@ def try_download(_path, _file, _url, _stale,): else: if data and (data != b'{}'): try: - with open(_path+_file, 'wb') as outfile: + with open(''.join([_path,_file]), 'wb') as outfile: outfile.write(data) outfile.close() except IOError: @@ -1408,7 +1408,7 @@ def try_download(_path, _file, _url, _stale,): def mk_server_dict(path,filename): server_ids = {} try: - with open(path+filename,newline='') as csvfile: + with open(''.join([path,filename]),newline='') as csvfile: reader = csv.DictReader(csvfile,dialect='excel-tab') for _row in reader: server_ids[_row['OPB Net ID']] = _row['Country'] From 4e428565a90890d1e44728a3a13db14929e90c87 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 02:44:59 +0100 Subject: [PATCH 111/128] Convert lists to deque() --- bridge_master.py | 33 +++++++++++++++++---------------- hblink.py | 4 ++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 7049b08..19c618e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -39,6 +39,7 @@ import importlib.util import re import copy from setproctitle import setproctitle +from collections import deque #from crccheck.crc import Crc32 from hashlib import blake2b @@ -83,9 +84,9 @@ from binascii import b2a_hex as ahex from AMI import AMI #debugging and profiling -import gc +#import gc -gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) +#gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) ##from hmac import new as hmac_new, compare_digest ##from hashlib import sha256, hash @@ -239,7 +240,7 @@ def make_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = [] + bridgetemp = deque() for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -252,7 +253,7 @@ def make_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] if str(tg) not in BRIDGES: make_single_bridge(bytes_3(tg),system,ts,_tmout) - bridgetemp = [] + bridgetemp = deque() for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: bridgetemp.append({'SYSTEM': system, 'TS': ts, 'TGID': bytes_3(tg),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(tg),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -263,7 +264,7 @@ def make_static_tg(tg,ts,_tmout,system): def reset_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] - bridgetemp = [] + bridgetemp = deque() try: for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: @@ -282,7 +283,7 @@ def reset_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = [] + bridgetemp = deque() for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -324,7 +325,7 @@ def remove_bridge_system(system): def rule_timer_loop(): logger.debug('(ROUTER) routerHBP Rule timer loop started') _now = time() - _remove_bridges = [] + _remove_bridges = deque() for _bridge in BRIDGES: _bridge_used = False for _system in BRIDGES[_bridge]: @@ -374,7 +375,7 @@ def rule_timer_loop(): def statTrimmer(): logger.debug('(ROUTER) STAT trimmer loop started') - _remove_bridges = [] + _remove_bridges = deque() for _bridge in BRIDGES: _bridge_stat = False _in_use = False @@ -394,7 +395,7 @@ def statTrimmer(): report_server.send_clients(b'bridge updated') #Run garbage collector manually - gc.collect() + #gc.collect() def kaReporting(): logger.debug('(ROUTER) KeepAlive reporting loop started') @@ -421,7 +422,7 @@ def subMapWrite(): def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') _sub_time = time() - _remove_list = [] + _remove_list = deque() for _subscriber in SUB_MAP: if SUB_MAP[_subscriber][2] < (_sub_time - 86400): _remove_list.append(_subscriber) @@ -470,8 +471,8 @@ def stream_trimmer_loop(): # OBP systems # We can't delete items from a dicationry that's being iterated, so we have to make a temporarly list of entrys to remove later if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': - remove_list = [] - fin_list = [] + remove_list = deque() + fin_list = deque() for stream_id in systems[system].STATUS: #if stream already marked as finished, just remove it @@ -533,7 +534,7 @@ def stream_trimmer_loop(): removed = systems[system].STATUS.pop(stream_id) try: - _bcsq_remove = [] + _bcsq_remove = deque() for tgid in _sysconfig['_bcsq']: if _sysconfig['_bcsq'][tgid] == stream_id: _bcsq_remove.append(tgid) @@ -1861,7 +1862,7 @@ class routerOBP(OPENBRIDGE): logger.debug('(%s) Bridge for STAT TG %s does not exist. Creating',self._system, int_id(_dst_id)) make_stat_bridge(_dst_id) - _sysIgnore = [] + _sysIgnore = deque() for _bridge in BRIDGES: for _system in BRIDGES[_bridge]: @@ -2667,7 +2668,7 @@ class routerHBP(HBSYSTEM): #Save this packet self.STATUS[_slot]['lastData'] = _data - _sysIgnore = [] + _sysIgnore = deque() for _bridge in BRIDGES: #if _bridge[0:1] != '#': if True: @@ -2976,7 +2977,7 @@ if __name__ == '__main__': #Generator generator = {} - systemdelete = [] + systemdelete = deque() for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER' and (CONFIG['SYSTEMS'][system]['GENERATOR'] > 1): diff --git a/hblink.py b/hblink.py index 28fe40f..edad688 100755 --- a/hblink.py +++ b/hblink.py @@ -91,7 +91,7 @@ def config_reports(_config, _factory): logger.info('(GLOBAL) HBlink TCP reporting server configured') report_server = _factory(_config) - report_server.clients = [] + report_server.clients = deque() reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server) reporting = task.LoopingCall(reporting_loop, logger, report_server) @@ -762,7 +762,7 @@ class HBSYSTEM(DatagramProtocol): # Aliased in __init__ to maintenance_loop if system is a master def master_maintenance_loop(self): logger.debug('(%s) Master maintenance loop started', self._system) - remove_list = [] + remove_list = deque() for peer in self._peers: _this_peer = self._peers[peer] # Check to see if any of the peers have been quiet (no ping) longer than allowed From e06b8cec9f6ab0ebb64d2c063afd6c5219eb4056 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 02:47:04 +0100 Subject: [PATCH 112/128] c --- bridge_master.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 19c618e..fe86c7b 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -83,13 +83,6 @@ from binascii import b2a_hex as ahex from AMI import AMI -#debugging and profiling -#import gc - -#gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) - -##from hmac import new as hmac_new, compare_digest -##from hashlib import sha256, hash # Does anybody read this stuff? There's a PEP somewhere that says I should do this. __author__ = 'Cortney T. Buffington, N0MJS, Forked by Simon Adlem - G7RZU' @@ -393,9 +386,6 @@ def statTrimmer(): logger.debug('(ROUTER) STAT bridge %s removed',_bridgerem) if CONFIG['REPORTS']['REPORT']: report_server.send_clients(b'bridge updated') - - #Run garbage collector manually - #gc.collect() def kaReporting(): logger.debug('(ROUTER) KeepAlive reporting loop started') From 69692e408424b94f05b1bd2d25c75be08f827376 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 03:05:57 +0100 Subject: [PATCH 113/128] set not deque --- bridge_master.py | 27 +++++++++++++-------------- hblink.py | 4 ++-- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index fe86c7b..5c15fd4 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -39,7 +39,6 @@ import importlib.util import re import copy from setproctitle import setproctitle -from collections import deque #from crccheck.crc import Crc32 from hashlib import blake2b @@ -233,7 +232,7 @@ def make_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = deque() + bridgetemp = set() for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -246,7 +245,7 @@ def make_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] if str(tg) not in BRIDGES: make_single_bridge(bytes_3(tg),system,ts,_tmout) - bridgetemp = deque() + bridgetemp = set() for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: bridgetemp.append({'SYSTEM': system, 'TS': ts, 'TGID': bytes_3(tg),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(tg),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -257,7 +256,7 @@ def make_static_tg(tg,ts,_tmout,system): def reset_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] - bridgetemp = deque() + bridgetemp = set() try: for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: @@ -276,7 +275,7 @@ def reset_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = deque() + bridgetemp = set() for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -318,7 +317,7 @@ def remove_bridge_system(system): def rule_timer_loop(): logger.debug('(ROUTER) routerHBP Rule timer loop started') _now = time() - _remove_bridges = deque() + _remove_bridges = set() for _bridge in BRIDGES: _bridge_used = False for _system in BRIDGES[_bridge]: @@ -368,7 +367,7 @@ def rule_timer_loop(): def statTrimmer(): logger.debug('(ROUTER) STAT trimmer loop started') - _remove_bridges = deque() + _remove_bridges = set() for _bridge in BRIDGES: _bridge_stat = False _in_use = False @@ -412,7 +411,7 @@ def subMapWrite(): def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') _sub_time = time() - _remove_list = deque() + _remove_list = set() for _subscriber in SUB_MAP: if SUB_MAP[_subscriber][2] < (_sub_time - 86400): _remove_list.append(_subscriber) @@ -461,8 +460,8 @@ def stream_trimmer_loop(): # OBP systems # We can't delete items from a dicationry that's being iterated, so we have to make a temporarly list of entrys to remove later if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': - remove_list = deque() - fin_list = deque() + remove_list = set() + fin_list = set() for stream_id in systems[system].STATUS: #if stream already marked as finished, just remove it @@ -524,7 +523,7 @@ def stream_trimmer_loop(): removed = systems[system].STATUS.pop(stream_id) try: - _bcsq_remove = deque() + _bcsq_remove = set() for tgid in _sysconfig['_bcsq']: if _sysconfig['_bcsq'][tgid] == stream_id: _bcsq_remove.append(tgid) @@ -1852,7 +1851,7 @@ class routerOBP(OPENBRIDGE): logger.debug('(%s) Bridge for STAT TG %s does not exist. Creating',self._system, int_id(_dst_id)) make_stat_bridge(_dst_id) - _sysIgnore = deque() + _sysIgnore = set() for _bridge in BRIDGES: for _system in BRIDGES[_bridge]: @@ -2658,7 +2657,7 @@ class routerHBP(HBSYSTEM): #Save this packet self.STATUS[_slot]['lastData'] = _data - _sysIgnore = deque() + _sysIgnore = set() for _bridge in BRIDGES: #if _bridge[0:1] != '#': if True: @@ -2967,7 +2966,7 @@ if __name__ == '__main__': #Generator generator = {} - systemdelete = deque() + systemdelete = set() for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER' and (CONFIG['SYSTEMS'][system]['GENERATOR'] > 1): diff --git a/hblink.py b/hblink.py index edad688..d67a1f0 100755 --- a/hblink.py +++ b/hblink.py @@ -91,7 +91,7 @@ def config_reports(_config, _factory): logger.info('(GLOBAL) HBlink TCP reporting server configured') report_server = _factory(_config) - report_server.clients = deque() + report_server.clients = set() reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server) reporting = task.LoopingCall(reporting_loop, logger, report_server) @@ -762,7 +762,7 @@ class HBSYSTEM(DatagramProtocol): # Aliased in __init__ to maintenance_loop if system is a master def master_maintenance_loop(self): logger.debug('(%s) Master maintenance loop started', self._system) - remove_list = deque() + remove_list = set() for peer in self._peers: _this_peer = self._peers[peer] # Check to see if any of the peers have been quiet (no ping) longer than allowed From 9dcf8bb7af0bfc3f1295c109e1ff60448efbb1b3 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 03:09:32 +0100 Subject: [PATCH 114/128] Revert "set not deque" This reverts commit c57659146e83fec16f9938144b4953768a6a9207. --- bridge_master.py | 27 ++++++++++++++------------- hblink.py | 4 ++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 5c15fd4..fe86c7b 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -39,6 +39,7 @@ import importlib.util import re import copy from setproctitle import setproctitle +from collections import deque #from crccheck.crc import Crc32 from hashlib import blake2b @@ -232,7 +233,7 @@ def make_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = set() + bridgetemp = deque() for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -245,7 +246,7 @@ def make_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] if str(tg) not in BRIDGES: make_single_bridge(bytes_3(tg),system,ts,_tmout) - bridgetemp = set() + bridgetemp = deque() for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: bridgetemp.append({'SYSTEM': system, 'TS': ts, 'TGID': bytes_3(tg),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(tg),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -256,7 +257,7 @@ def make_static_tg(tg,ts,_tmout,system): def reset_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] - bridgetemp = set() + bridgetemp = deque() try: for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: @@ -275,7 +276,7 @@ def reset_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = set() + bridgetemp = deque() for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -317,7 +318,7 @@ def remove_bridge_system(system): def rule_timer_loop(): logger.debug('(ROUTER) routerHBP Rule timer loop started') _now = time() - _remove_bridges = set() + _remove_bridges = deque() for _bridge in BRIDGES: _bridge_used = False for _system in BRIDGES[_bridge]: @@ -367,7 +368,7 @@ def rule_timer_loop(): def statTrimmer(): logger.debug('(ROUTER) STAT trimmer loop started') - _remove_bridges = set() + _remove_bridges = deque() for _bridge in BRIDGES: _bridge_stat = False _in_use = False @@ -411,7 +412,7 @@ def subMapWrite(): def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') _sub_time = time() - _remove_list = set() + _remove_list = deque() for _subscriber in SUB_MAP: if SUB_MAP[_subscriber][2] < (_sub_time - 86400): _remove_list.append(_subscriber) @@ -460,8 +461,8 @@ def stream_trimmer_loop(): # OBP systems # We can't delete items from a dicationry that's being iterated, so we have to make a temporarly list of entrys to remove later if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': - remove_list = set() - fin_list = set() + remove_list = deque() + fin_list = deque() for stream_id in systems[system].STATUS: #if stream already marked as finished, just remove it @@ -523,7 +524,7 @@ def stream_trimmer_loop(): removed = systems[system].STATUS.pop(stream_id) try: - _bcsq_remove = set() + _bcsq_remove = deque() for tgid in _sysconfig['_bcsq']: if _sysconfig['_bcsq'][tgid] == stream_id: _bcsq_remove.append(tgid) @@ -1851,7 +1852,7 @@ class routerOBP(OPENBRIDGE): logger.debug('(%s) Bridge for STAT TG %s does not exist. Creating',self._system, int_id(_dst_id)) make_stat_bridge(_dst_id) - _sysIgnore = set() + _sysIgnore = deque() for _bridge in BRIDGES: for _system in BRIDGES[_bridge]: @@ -2657,7 +2658,7 @@ class routerHBP(HBSYSTEM): #Save this packet self.STATUS[_slot]['lastData'] = _data - _sysIgnore = set() + _sysIgnore = deque() for _bridge in BRIDGES: #if _bridge[0:1] != '#': if True: @@ -2966,7 +2967,7 @@ if __name__ == '__main__': #Generator generator = {} - systemdelete = set() + systemdelete = deque() for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER' and (CONFIG['SYSTEMS'][system]['GENERATOR'] > 1): diff --git a/hblink.py b/hblink.py index d67a1f0..edad688 100755 --- a/hblink.py +++ b/hblink.py @@ -91,7 +91,7 @@ def config_reports(_config, _factory): logger.info('(GLOBAL) HBlink TCP reporting server configured') report_server = _factory(_config) - report_server.clients = set() + report_server.clients = deque() reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server) reporting = task.LoopingCall(reporting_loop, logger, report_server) @@ -762,7 +762,7 @@ class HBSYSTEM(DatagramProtocol): # Aliased in __init__ to maintenance_loop if system is a master def master_maintenance_loop(self): logger.debug('(%s) Master maintenance loop started', self._system) - remove_list = set() + remove_list = deque() for peer in self._peers: _this_peer = self._peers[peer] # Check to see if any of the peers have been quiet (no ping) longer than allowed From bdfe7a68a997757137043e27375cf6e54c812611 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 03:09:33 +0100 Subject: [PATCH 115/128] Revert "c" This reverts commit 11ee6fc19cef463d042d119fb9f81b6ca9320b35. --- bridge_master.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bridge_master.py b/bridge_master.py index fe86c7b..19c618e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -83,6 +83,13 @@ from binascii import b2a_hex as ahex from AMI import AMI +#debugging and profiling +#import gc + +#gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) + +##from hmac import new as hmac_new, compare_digest +##from hashlib import sha256, hash # Does anybody read this stuff? There's a PEP somewhere that says I should do this. __author__ = 'Cortney T. Buffington, N0MJS, Forked by Simon Adlem - G7RZU' @@ -386,6 +393,9 @@ def statTrimmer(): logger.debug('(ROUTER) STAT bridge %s removed',_bridgerem) if CONFIG['REPORTS']['REPORT']: report_server.send_clients(b'bridge updated') + + #Run garbage collector manually + #gc.collect() def kaReporting(): logger.debug('(ROUTER) KeepAlive reporting loop started') From 1fbc3bdfc2dbe03bd6a900846d90200af95cec8b Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 03:09:34 +0100 Subject: [PATCH 116/128] Revert "Convert lists to deque()" This reverts commit 60383ee4824224c3815823579153908340e37c9a. --- bridge_master.py | 33 ++++++++++++++++----------------- hblink.py | 4 ++-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 19c618e..7049b08 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -39,7 +39,6 @@ import importlib.util import re import copy from setproctitle import setproctitle -from collections import deque #from crccheck.crc import Crc32 from hashlib import blake2b @@ -84,9 +83,9 @@ from binascii import b2a_hex as ahex from AMI import AMI #debugging and profiling -#import gc +import gc -#gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) +gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) ##from hmac import new as hmac_new, compare_digest ##from hashlib import sha256, hash @@ -240,7 +239,7 @@ def make_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = deque() + bridgetemp = [] for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -253,7 +252,7 @@ def make_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] if str(tg) not in BRIDGES: make_single_bridge(bytes_3(tg),system,ts,_tmout) - bridgetemp = deque() + bridgetemp = [] for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: bridgetemp.append({'SYSTEM': system, 'TS': ts, 'TGID': bytes_3(tg),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(tg),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -264,7 +263,7 @@ def make_static_tg(tg,ts,_tmout,system): def reset_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] - bridgetemp = deque() + bridgetemp = [] try: for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: @@ -283,7 +282,7 @@ def reset_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = deque() + bridgetemp = [] for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -325,7 +324,7 @@ def remove_bridge_system(system): def rule_timer_loop(): logger.debug('(ROUTER) routerHBP Rule timer loop started') _now = time() - _remove_bridges = deque() + _remove_bridges = [] for _bridge in BRIDGES: _bridge_used = False for _system in BRIDGES[_bridge]: @@ -375,7 +374,7 @@ def rule_timer_loop(): def statTrimmer(): logger.debug('(ROUTER) STAT trimmer loop started') - _remove_bridges = deque() + _remove_bridges = [] for _bridge in BRIDGES: _bridge_stat = False _in_use = False @@ -395,7 +394,7 @@ def statTrimmer(): report_server.send_clients(b'bridge updated') #Run garbage collector manually - #gc.collect() + gc.collect() def kaReporting(): logger.debug('(ROUTER) KeepAlive reporting loop started') @@ -422,7 +421,7 @@ def subMapWrite(): def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') _sub_time = time() - _remove_list = deque() + _remove_list = [] for _subscriber in SUB_MAP: if SUB_MAP[_subscriber][2] < (_sub_time - 86400): _remove_list.append(_subscriber) @@ -471,8 +470,8 @@ def stream_trimmer_loop(): # OBP systems # We can't delete items from a dicationry that's being iterated, so we have to make a temporarly list of entrys to remove later if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': - remove_list = deque() - fin_list = deque() + remove_list = [] + fin_list = [] for stream_id in systems[system].STATUS: #if stream already marked as finished, just remove it @@ -534,7 +533,7 @@ def stream_trimmer_loop(): removed = systems[system].STATUS.pop(stream_id) try: - _bcsq_remove = deque() + _bcsq_remove = [] for tgid in _sysconfig['_bcsq']: if _sysconfig['_bcsq'][tgid] == stream_id: _bcsq_remove.append(tgid) @@ -1862,7 +1861,7 @@ class routerOBP(OPENBRIDGE): logger.debug('(%s) Bridge for STAT TG %s does not exist. Creating',self._system, int_id(_dst_id)) make_stat_bridge(_dst_id) - _sysIgnore = deque() + _sysIgnore = [] for _bridge in BRIDGES: for _system in BRIDGES[_bridge]: @@ -2668,7 +2667,7 @@ class routerHBP(HBSYSTEM): #Save this packet self.STATUS[_slot]['lastData'] = _data - _sysIgnore = deque() + _sysIgnore = [] for _bridge in BRIDGES: #if _bridge[0:1] != '#': if True: @@ -2977,7 +2976,7 @@ if __name__ == '__main__': #Generator generator = {} - systemdelete = deque() + systemdelete = [] for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER' and (CONFIG['SYSTEMS'][system]['GENERATOR'] > 1): diff --git a/hblink.py b/hblink.py index edad688..28fe40f 100755 --- a/hblink.py +++ b/hblink.py @@ -91,7 +91,7 @@ def config_reports(_config, _factory): logger.info('(GLOBAL) HBlink TCP reporting server configured') report_server = _factory(_config) - report_server.clients = deque() + report_server.clients = [] reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server) reporting = task.LoopingCall(reporting_loop, logger, report_server) @@ -762,7 +762,7 @@ class HBSYSTEM(DatagramProtocol): # Aliased in __init__ to maintenance_loop if system is a master def master_maintenance_loop(self): logger.debug('(%s) Master maintenance loop started', self._system) - remove_list = deque() + remove_list = [] for peer in self._peers: _this_peer = self._peers[peer] # Check to see if any of the peers have been quiet (no ping) longer than allowed From 0086464f2bbf9c2611bab53cec3d231bddab4d2e Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 03:12:18 +0100 Subject: [PATCH 117/128] Revert "Revert "Convert lists to deque()"" This reverts commit 78fbe0fc7bcc092f687ea5427a1f49fc484c6b32. --- bridge_master.py | 33 +++++++++++++++++---------------- hblink.py | 4 ++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 7049b08..19c618e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -39,6 +39,7 @@ import importlib.util import re import copy from setproctitle import setproctitle +from collections import deque #from crccheck.crc import Crc32 from hashlib import blake2b @@ -83,9 +84,9 @@ from binascii import b2a_hex as ahex from AMI import AMI #debugging and profiling -import gc +#import gc -gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) +#gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) ##from hmac import new as hmac_new, compare_digest ##from hashlib import sha256, hash @@ -239,7 +240,7 @@ def make_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = [] + bridgetemp = deque() for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -252,7 +253,7 @@ def make_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] if str(tg) not in BRIDGES: make_single_bridge(bytes_3(tg),system,ts,_tmout) - bridgetemp = [] + bridgetemp = deque() for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: bridgetemp.append({'SYSTEM': system, 'TS': ts, 'TGID': bytes_3(tg),'ACTIVE': True,'TIMEOUT': _tmout * 60,'TO_TYPE': 'OFF','OFF': [],'ON': [bytes_3(tg),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -263,7 +264,7 @@ def make_static_tg(tg,ts,_tmout,system): def reset_static_tg(tg,ts,_tmout,system): #_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] - bridgetemp = [] + bridgetemp = deque() try: for bridgesystem in BRIDGES[str(tg)]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == ts: @@ -282,7 +283,7 @@ def reset_default_reflector(reflector,_tmout,system): if bridge not in BRIDGES: BRIDGES[bridge] = [] make_single_reflector(bytes_3(reflector),_tmout, system) - bridgetemp = [] + bridgetemp = deque() for bridgesystem in BRIDGES[bridge]: if bridgesystem['SYSTEM'] == system and bridgesystem['TS'] == 2: bridgetemp.append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(reflector),],'RESET': [], 'TIMER': time() + (_tmout * 60)}) @@ -324,7 +325,7 @@ def remove_bridge_system(system): def rule_timer_loop(): logger.debug('(ROUTER) routerHBP Rule timer loop started') _now = time() - _remove_bridges = [] + _remove_bridges = deque() for _bridge in BRIDGES: _bridge_used = False for _system in BRIDGES[_bridge]: @@ -374,7 +375,7 @@ def rule_timer_loop(): def statTrimmer(): logger.debug('(ROUTER) STAT trimmer loop started') - _remove_bridges = [] + _remove_bridges = deque() for _bridge in BRIDGES: _bridge_stat = False _in_use = False @@ -394,7 +395,7 @@ def statTrimmer(): report_server.send_clients(b'bridge updated') #Run garbage collector manually - gc.collect() + #gc.collect() def kaReporting(): logger.debug('(ROUTER) KeepAlive reporting loop started') @@ -421,7 +422,7 @@ def subMapWrite(): def SubMapTrimmer(): logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') _sub_time = time() - _remove_list = [] + _remove_list = deque() for _subscriber in SUB_MAP: if SUB_MAP[_subscriber][2] < (_sub_time - 86400): _remove_list.append(_subscriber) @@ -470,8 +471,8 @@ def stream_trimmer_loop(): # OBP systems # We can't delete items from a dicationry that's being iterated, so we have to make a temporarly list of entrys to remove later if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': - remove_list = [] - fin_list = [] + remove_list = deque() + fin_list = deque() for stream_id in systems[system].STATUS: #if stream already marked as finished, just remove it @@ -533,7 +534,7 @@ def stream_trimmer_loop(): removed = systems[system].STATUS.pop(stream_id) try: - _bcsq_remove = [] + _bcsq_remove = deque() for tgid in _sysconfig['_bcsq']: if _sysconfig['_bcsq'][tgid] == stream_id: _bcsq_remove.append(tgid) @@ -1861,7 +1862,7 @@ class routerOBP(OPENBRIDGE): logger.debug('(%s) Bridge for STAT TG %s does not exist. Creating',self._system, int_id(_dst_id)) make_stat_bridge(_dst_id) - _sysIgnore = [] + _sysIgnore = deque() for _bridge in BRIDGES: for _system in BRIDGES[_bridge]: @@ -2667,7 +2668,7 @@ class routerHBP(HBSYSTEM): #Save this packet self.STATUS[_slot]['lastData'] = _data - _sysIgnore = [] + _sysIgnore = deque() for _bridge in BRIDGES: #if _bridge[0:1] != '#': if True: @@ -2976,7 +2977,7 @@ if __name__ == '__main__': #Generator generator = {} - systemdelete = [] + systemdelete = deque() for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER' and (CONFIG['SYSTEMS'][system]['GENERATOR'] > 1): diff --git a/hblink.py b/hblink.py index 28fe40f..edad688 100755 --- a/hblink.py +++ b/hblink.py @@ -91,7 +91,7 @@ def config_reports(_config, _factory): logger.info('(GLOBAL) HBlink TCP reporting server configured') report_server = _factory(_config) - report_server.clients = [] + report_server.clients = deque() reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server) reporting = task.LoopingCall(reporting_loop, logger, report_server) @@ -762,7 +762,7 @@ class HBSYSTEM(DatagramProtocol): # Aliased in __init__ to maintenance_loop if system is a master def master_maintenance_loop(self): logger.debug('(%s) Master maintenance loop started', self._system) - remove_list = [] + remove_list = deque() for peer in self._peers: _this_peer = self._peers[peer] # Check to see if any of the peers have been quiet (no ping) longer than allowed From e12ff92ec12b5669a3a5716564e4b10f79dfa64b Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 03:12:20 +0100 Subject: [PATCH 118/128] Revert "Revert "c"" This reverts commit 48c1ccc7bb9d930ecc0bca2579c76237fd6b52fe. --- bridge_master.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 19c618e..fe86c7b 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -83,13 +83,6 @@ from binascii import b2a_hex as ahex from AMI import AMI -#debugging and profiling -#import gc - -#gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_STATS) - -##from hmac import new as hmac_new, compare_digest -##from hashlib import sha256, hash # Does anybody read this stuff? There's a PEP somewhere that says I should do this. __author__ = 'Cortney T. Buffington, N0MJS, Forked by Simon Adlem - G7RZU' @@ -393,9 +386,6 @@ def statTrimmer(): logger.debug('(ROUTER) STAT bridge %s removed',_bridgerem) if CONFIG['REPORTS']['REPORT']: report_server.send_clients(b'bridge updated') - - #Run garbage collector manually - #gc.collect() def kaReporting(): logger.debug('(ROUTER) KeepAlive reporting loop started') From 0ab5c478e7db23cdb345a65266ae0a7b64385cb0 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Aug 2022 10:44:40 +0100 Subject: [PATCH 119/128] Explicitly close sql cursor after query --- mysql_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql_config.py b/mysql_config.py index fe8553b..9acf6e6 100644 --- a/mysql_config.py +++ b/mysql_config.py @@ -93,7 +93,7 @@ class useMYSQL: CONFIG['SYSTEMS'][callsign].update({'PEERS': {}}) except TypeError: logger.info('(MYSQL) Problem with data from MySQL - TypeError, carrying on to next row') - + _cursor.close() return(CONFIG['SYSTEMS']) From 045d2f2f4a15a0300e0c07c49191a64eca6ac36a Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 25 Aug 2022 12:53:03 +0100 Subject: [PATCH 120/128] Fix trace in options TS2 parsing --- bridge_master.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index fe86c7b..4f9750b 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -915,11 +915,11 @@ def options_config(): else: logger.debug('(OPTIONS) %s default reflector disabled, updating',_system) reset_default_reflector(int(_options['DEFAULT_REFLECTOR']),_tmout,_system) - + + ts1 = [] if _options['TS1_STATIC'] != CONFIG['SYSTEMS'][_system]['TS1_STATIC']: _tmout = int(_options['DEFAULT_UA_TIMER']) logger.debug('(OPTIONS) %s TS1 static TGs changed, updating',_system) - ts1 = [] if CONFIG['SYSTEMS'][_system]['TS1_STATIC']: ts1 = CONFIG['SYSTEMS'][_system]['TS1_STATIC'].split(',') for tg in ts1: @@ -927,7 +927,6 @@ def options_config(): continue tg = int(tg) reset_static_tg(tg,1,_tmout,_system) - ts1 = [] if _options['TS1_STATIC']: ts1 = _options['TS1_STATIC'].split(',') for tg in ts1: @@ -936,11 +935,10 @@ def options_config(): continue tg = int(tg) make_static_tg(tg,1,_tmout,_system) - + ts2 = [] if _options['TS2_STATIC'] != CONFIG['SYSTEMS'][_system]['TS2_STATIC']: _tmout = int(_options['DEFAULT_UA_TIMER']) logger.debug('(OPTIONS) %s TS2 static TGs changed, updating',_system) - ts2 = [] if CONFIG['SYSTEMS'][_system]['TS2_STATIC']: ts2 = CONFIG['SYSTEMS'][_system]['TS2_STATIC'].split(',') for tg in ts2: From a2f7b3a74fac0df16726ba2dabb08e1380d48b41 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 25 Aug 2022 13:32:09 +0100 Subject: [PATCH 121/128] remove uneccasary variables --- hblink.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/hblink.py b/hblink.py index edad688..2c0dd21 100755 --- a/hblink.py +++ b/hblink.py @@ -1442,20 +1442,18 @@ def mk_aliases(_config): # Make Dictionaries try: - _peer_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE']) + peer_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE']) except Exception as e: logger.error('(ALIAS) ID ALIAS MAPPER: problem with data in peer_ids dictionary, not updating: %s',e) else: - peer_ids = _peer_ids if peer_ids: logger.info('(ALIAS) ID ALIAS MAPPER: peer_ids dictionary is available') try: - _subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SUBSCRIBER_FILE']) + subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SUBSCRIBER_FILE']) except Exception as e: logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in subscriber_ids dictionary, not updating: %s',e) else: - subscriber_ids = _subscriber_ids #Add special IDs to DB subscriber_ids[900999] = 'D-APRS' subscriber_ids[4294967295] = 'SC' @@ -1463,27 +1461,23 @@ def mk_aliases(_config): if subscriber_ids: logger.info('(ALIAS) ID ALIAS MAPPER: subscriber_ids dictionary is available') try: - _talkgroup_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['TGID_FILE']) + talkgroup_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['TGID_FILE']) except Exception as e: logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in talkgroup_ids dictionary, not updating: %s',e) else: - talkgroup_ids = _talkgroup_ids if talkgroup_ids: logger.info('(ALIAS) ID ALIAS MAPPER: talkgroup_ids dictionary is available') try: - _local_subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['LOCAL_SUBSCRIBER_FILE']) + local_subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['LOCAL_SUBSCRIBER_FILE']) except Exception as e: logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in local_subscriber_ids dictionary, not updating: %s',e) else: - local_subscriber_ids = _local_subscriber_ids if subscriber_ids: logger.info('(ALIAS) ID ALIAS MAPPER: local_subscriber_ids dictionary is available') try: - _server_ids = mk_server_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE']) + server_ids = mk_server_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE']) except Exception as e: logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in server_ids dictionary, not updating: %s',e) - else: - server_ids = _server_ids if server_ids: logger.info('(ALIAS) ID ALIAS MAPPER: server_ids dictionary is available') From d26ef3eae06566f03324f96cb5eae40a969e60c1 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 25 Aug 2022 13:40:27 +0100 Subject: [PATCH 122/128] Remove legacy MySQL support completely. --- bridge_master.py | 367 +---------------------------------------------- config.py | 11 -- mysql_config.py | 107 -------------- requirements.txt | 1 - 4 files changed, 5 insertions(+), 481 deletions(-) delete mode 100644 mysql_config.py diff --git a/bridge_master.py b/bridge_master.py index 4f9750b..7b4570f 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -65,10 +65,6 @@ from read_ambe import readAMBE #Remap some words for certain languages from i8n_voice_map import voiceMap - -#MySQL -from mysql_config import useMYSQL - # Stuff for socket reporting import pickle # REMOVE LATER from datetime import datetime @@ -643,10 +639,6 @@ def threadIdent(): logger.debug('(IDENT) starting ident thread') reactor.callInThread(ident) -def threadedMysql(): - logger.debug('(MYSQL) Starting MySQL thread') - reactor.callInThread(mysqlGetConfig) - def threadAlias(): logger.debug('(ALIAS) starting alias thread') reactor.callInThread(aliasb) @@ -920,6 +912,7 @@ def options_config(): if _options['TS1_STATIC'] != CONFIG['SYSTEMS'][_system]['TS1_STATIC']: _tmout = int(_options['DEFAULT_UA_TIMER']) logger.debug('(OPTIONS) %s TS1 static TGs changed, updating',_system) + ts1 = [] if CONFIG['SYSTEMS'][_system]['TS1_STATIC']: ts1 = CONFIG['SYSTEMS'][_system]['TS1_STATIC'].split(',') for tg in ts1: @@ -964,324 +957,6 @@ def options_config(): logger.exception('(OPTIONS) caught exception: %s',e) continue -def mysqlGetConfig(): - logger.debug('(MYSQL) Periodic config check') - SQLGETCONFIG = {} - if sql.con(): - logger.debug('(MYSQL) reading config from database') - try: - SQLGETCONFIG = sql.getConfig() - except: - logger.debug('(MYSQL) problem with SQL query, aborting') - sql.close() - return - else: - logger.debug('(MYSQL) problem connecting to SQL server, aborting') - sql.close() - return - - sql.close() - reactor.callFromThread(mysql_config_check,SQLGETCONFIG) - - -def mysql_config_check(SQLGETCONFIG): - - SQLCONFIG = SQLGETCONFIG - for system in SQLGETCONFIG: - if system not in CONFIG['SYSTEMS']: - if SQLCONFIG[system]['ENABLED']: - logger.debug('(MYSQL) new enabled system %s, starting HBP listener',system) - CONFIG['SYSTEMS'][system] = SQLCONFIG[system] - systems[system] = routerHBP(system, CONFIG, report_server) - listeningPorts[system] = reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) - else: - logger.debug('(MYSQL) new disabled system %s',system) - _tmout = SQLCONFIG[system]['DEFAULT_UA_TIMER'] - #Do ACL processing - # Subscriber and TGID ACLs - logger.debug('(MYSQL) building ACLs') - # Registration ACLs - SQLCONFIG[system]['REG_ACL'] = acl_build(SQLCONFIG[system]['REG_ACL'], PEER_MAX) - for acl in ['SUB_ACL', 'TG1_ACL', 'TG2_ACL']: - SQLCONFIG[system][acl] = acl_build(SQLCONFIG[system][acl], ID_MAX) - - #Add system to bridges - if SQLCONFIG[system]['ENABLED']: - logger.debug('(MYSQL) adding new system to static bridges') - for _bridge in BRIDGES: - ts1 = False - ts2 = False - for i,e in enumerate(BRIDGES[_bridge]): - if e['SYSTEM'] == system and e['TS'] == 1: - ts1 = True - if e['SYSTEM'] == system and e['TS'] == 2: - ts2 = True - if _bridge[0:1] != '#': - if ts1 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 1, 'TGID': bytes_3(int(_bridge)),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(int(_bridge)),],'RESET': [], 'TIMER': time()}) - if ts2 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(int(_bridge)),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(int(_bridge)),],'RESET': [], 'TIMER': time()}) - else: - if ts2 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [bytes_3(4000)],'ON': [],'RESET': [], 'TIMER': time()}) - - if SQLCONFIG[system]['DEFAULT_REFLECTOR'] > 0: - logger.debug('(MYSQL) %s setting default reflector',system) - make_default_reflector(SQLCONFIG[system]['DEFAULT_REFLECTOR'],_tmout,system) - - if SQLCONFIG[system]['TS1_STATIC']: - logger.debug('(MYSQL) %s setting static TGs on TS1',system) - ts1 = SQLCONFIG[system]['TS1_STATIC'].split(',') - for tg in ts1: - if not tg: - continue - tg = int(tg) - make_static_tg(tg,1,_tmout,system) - - if SQLCONFIG[system]['TS2_STATIC']: - logger.debug('(MYSQL) %s setting static TGs on TS2',system) - ts2 = SQLCONFIG[system]['TS2_STATIC'].split(',') - for tg in ts2: - if not tg: - continue - tg = int(tg) - make_static_tg(tg,2,_tmout,system) - - continue - - #Preserve options line - if 'OPTIONS' in CONFIG['SYSTEMS'][system]: - SQLCONFIG[system]['OPTIONS'] = CONFIG['SYSTEMS'][system]['OPTIONS'] - SQLCONFIG[system]['TS1_STATIC'] = CONFIG['SYSTEMS'][system]['TS1_STATIC'] - SQLCONFIG[system]['TS2_STATIC'] = CONFIG['SYSTEMS'][system]['TS2_STATIC'] - SQLCONFIG[system]['DEFAULT_UA_TIMER'] = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER'] - SQLCONFIG[system]['DEFAULT_REFLECTOR'] = CONFIG['SYSTEMS'][system]['DEFAULT_REFLECTOR'] - - #logger.debug('(MYSQL) %s has HBP Options line - skipping',system) - #continue - - - if SQLCONFIG[system]['ENABLED'] == False and CONFIG['SYSTEMS'][system]['ENABLED'] == True: - logger.debug('(MYSQL) %s changed from enabled to disabled, killing HBP listener and removing from bridges',system) - systems[system].master_dereg() - if systems[system]._system_maintenance is not None and systems[system]._system_maintenance.running == True: - systems[system]._system_maintenance.stop() - systems[system]._system_maintenance = None - remove_bridge_system(system) - listeningPorts[system].stopListening() - - if CONFIG['SYSTEMS'][system]['ENABLED'] == False and SQLCONFIG[system]['ENABLED'] == True: - logger.debug('(MYSQL) %s changed from disabled to enabled, starting HBP listener',system) - systems[system] = routerHBP(system, CONFIG, report_server) - listeningPorts[system] = reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) - logger.debug('(GLOBAL) %s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system]) - logger.debug('(MYSQL) adding new system to static bridges') - _tmout = SQLCONFIG[system]['DEFAULT_UA_TIMER'] - for _bridge in BRIDGES: - ts1 = False - ts2 = False - for i,e in enumerate(BRIDGES[_bridge]): - if e['SYSTEM'] == system and e['TS'] == 1: - ts1 = True - if e['SYSTEM'] == system and e['TS'] == 2: - ts2 = True - if _bridge[0:1] != '#': - if ts1 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 1, 'TGID': bytes_3(int(_bridge)),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(int(_bridge)),],'RESET': [], 'TIMER': time()}) - if ts2 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(int(_bridge)),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(int(_bridge)),],'RESET': [], 'TIMER': time()}) - else: - if ts2 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [bytes_3(4000)],'ON': [],'RESET': [], 'TIMER': time()}) - - - if SQLCONFIG[system]['DEFAULT_REFLECTOR'] > 0: - if 'OPTIONS' not in SQLCONFIG[system]: - logger.debug('(MYSQL) %s setting default reflector',system) - make_default_reflector(SQLCONFIG[system]['DEFAULT_REFLECTOR'],_tmout,system) - - if SQLCONFIG[system]['TS1_STATIC']: - if 'OPTIONS' not in SQLCONFIG[system]: - logger.debug('(MYSQL) %s setting static TGs on TS1',system) - ts1 = SQLCONFIG[system]['TS1_STATIC'].split(',') - for tg in ts1: - if not tg: - continue - tg = int(tg) - make_static_tg(tg,1,_tmout,system) - - if SQLCONFIG[system]['TS2_STATIC']: - logger.debug('(MYSQL) %s setting static TGs on TS2',system) - ts2 = SQLCONFIG[system]['TS2_STATIC'].split(',') - for tg in ts2: - if not tg: - continue - tg = int(tg) - make_static_tg(tg,2,_tmout,system) - - if SQLCONFIG[system]['DEFAULT_UA_TIMER'] != CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER']: - if 'OPTIONS' not in CONFIG['SYSTEMS'][system]: - logger.debug('(MYSQL) %s DEFAULT_UA_TIMER changed. Updating bridges.',system) - remove_bridge_system(system) - for _bridge in BRIDGES: - ts1 = False - ts2 = False - _tmout = CONFIG['SYSTEMS'][system][DEFAULT_UA_TIMER] - for i,e in enumerate(BRIDGES[_bridge]): - if e['SYSTEM'] == system and e['TS'] == 1: - ts1 = True - if e['SYSTEM'] == system and e['TS'] == 2: - ts2 = True - if _bridge[0:1] != '#': - if ts1 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 1, 'TGID': bytes_3(int(_bridge)),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(int(_bridge)),],'RESET': [], 'TIMER': time()}) - if ts2 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(int(_bridge)),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [],'ON': [bytes_3(int(_bridge)),],'RESET': [], 'TIMER': time()}) - else: - if ts2 == False: - BRIDGES[_bridge].append({'SYSTEM': system, 'TS': 2, 'TGID': bytes_3(9),'ACTIVE': False,'TIMEOUT': _tmout * 60,'TO_TYPE': 'ON','OFF': [bytes_3(4000)],'ON': [],'RESET': [], 'TIMER': time()}) - - - if SQLCONFIG[system]['DEFAULT_REFLECTOR'] > 0: - # if 'OPTIONS' not in SQLCONFIG[system]: - logger.debug('(MYSQL) %s setting default reflector',system) - make_default_reflector(SQLCONFIG[system]['DEFAULT_REFLECTOR'],_tmout,system) - - if SQLCONFIG[system]['TS1_STATIC']: - # if 'OPTIONS' not in SQLCONFIG[system]: - logger.debug('(MYSQL) %s setting static TGs on TS1',system) - ts1 = SQLCONFIG[system]['TS1_STATIC'].split(',') - for tg in ts1: - if not tg: - continue - tg = int(tg) - make_static_tg(tg,1,_tmout,system) - - if SQLCONFIG[system]['TS2_STATIC']: - logger.debug('(MYSQL) %s setting static TGs on TS2',system) - ts2 = SQLCONFIG[system]['TS2_STATIC'].split(',') - for tg in ts2: - if not tg: - continue - tg = int(tg) - make_static_tg(tg,2,_tmout,system) - - - - if SQLCONFIG[system]['IP'] != CONFIG['SYSTEMS'][system]['IP'] and CONFIG['SYSTEMS'][system]['ENABLED'] == True: - logger.debug('(MYSQL) %s IP binding changed on enabled system, killing HBP listener. Will restart in 1 minute',system) - systems[system].master_dereg() - if systems[system]._system_maintenance is not None and systems[system]._system_maintenance.running == True: - systems[system]._system_maintenance.stop() - systems[system]._system_maintenance = None - listeningPorts[system].stopListening() - SQLCONFIG[system]['ENABLED'] = False - - if SQLCONFIG[system]['PORT'] != CONFIG['SYSTEMS'][system]['PORT'] and CONFIG['SYSTEMS'][system]['ENABLED'] == True: - logger.debug('(MYSQL) %s Port binding changed on enabled system, killing HBP listener. Will restart in 1 minute',system) - systems[system].master_dereg() - if systems[system]._system_maintenance is not None and systems[system]._system_maintenance.running == True: - systems[system]._system_maintenance.stop() - systems[system]._system_maintenance = None - listeningPorts[system].stopListening() - SQLCONFIG[system]['ENABLED'] = False - - if SQLCONFIG[system]['MAX_PEERS'] != CONFIG['SYSTEMS'][system]['MAX_PEERS'] and CONFIG['SYSTEMS'][system]['ENABLED'] == True: - logger.debug('(MYSQL) %s MAX_PEERS changed on enabled system, killing HBP listener. Will restart in 1 minute',system) - systems[system].master_dereg() - if systems[system]._system_maintenance is not None and systems[system]._system_maintenance.running == True: - systems[system]._system_maintenance.stop() - systems[system]._system_maintenance = None - listeningPorts[system].stopListening() - SQLCONFIG[system]['ENABLED'] = False - - if SQLCONFIG[system]['PASSPHRASE'] != CONFIG['SYSTEMS'][system]['PASSPHRASE'] and CONFIG['SYSTEMS'][system]['ENABLED'] == True: - logger.debug('(MYSQL) %s Passphrase changed on enabled system. Kicking peers',system) - systems[system].master_dereg() - - if SQLCONFIG[system]['DEFAULT_REFLECTOR'] != CONFIG['SYSTEMS'][system]['DEFAULT_REFLECTOR']: - if 'OPTIONS' not in SQLCONFIG[system]: - _tmout = SQLCONFIG[system]['DEFAULT_UA_TIMER'] - if SQLCONFIG[system]['DEFAULT_REFLECTOR'] > 0: - logger.debug('(MYSQL) %s default reflector changed, updating',system) - reset_default_reflector(CONFIG['SYSTEMS'][system]['DEFAULT_REFLECTOR'],_tmout,system) - make_default_reflector(SQLCONFIG[system]['DEFAULT_REFLECTOR'],_tmout,system) - else: - logger.debug('(MYSQL) %s default reflector disabled, updating',system) - reset_default_reflector(CONFIG['SYSTEMS'][system]['DEFAULT_REFLECTOR'],_tmout,system) - - if SQLCONFIG[system]['TS1_STATIC'] != CONFIG['SYSTEMS'][system]['TS1_STATIC']: - if 'OPTIONS' not in CONFIG['SYSTEMS'][system]: - _tmout = SQLCONFIG[system]['DEFAULT_UA_TIMER'] - logger.debug('(MYSQL) %s TS1 static TGs changed, updating',system) - ts1 = [] - if CONFIG['SYSTEMS'][system]['TS1_STATIC']: - ts1 = CONFIG['SYSTEMS'][system]['TS1_STATIC'].split(',') - for tg in ts1: - if not tg: - continue - tg = int(tg) - reset_static_tg(tg,1,_tmout,system) - ts1 = [] - if SQLCONFIG[system]['TS1_STATIC']: - ts1 = SQLCONFIG[system]['TS1_STATIC'].split(',') - for tg in ts1: - if not tg: - continue - tg = int(tg) - make_static_tg(tg,1,_tmout,system) - - if SQLCONFIG[system]['TS2_STATIC'] != CONFIG['SYSTEMS'][system]['TS2_STATIC']: - if 'OPTIONS' not in CONFIG['SYSTEMS'][system]: - _tmout = SQLCONFIG[system]['DEFAULT_UA_TIMER'] - logger.debug('(MYSQL) %s TS2 static TGs changed, updating',system) - ts2 = [] - if CONFIG['SYSTEMS'][system]['TS2_STATIC']: - ts2 = CONFIG['SYSTEMS'][system]['TS2_STATIC'].split(',') - for tg in ts2: - if not tg: - continue - tg = int(tg) - reset_static_tg(tg,2,_tmout,system) - ts2 = [] - if SQLCONFIG[system]['TS2_STATIC']: - ts2 = SQLCONFIG[system]['TS2_STATIC'].split(',') - for tg in ts2: - if not tg: - continue - tg = int(tg) - make_static_tg(tg,2,_tmout,system) - - if SQLCONFIG[system]['ANNOUNCEMENT_LANGUAGE'] != CONFIG['SYSTEMS'][system]['ANNOUNCEMENT_LANGUAGE']: - logger.debug('(MYSQL) %s announcement language changed to %s',system, SQLCONFIG[system]['ANNOUNCEMENT_LANGUAGE']) - - #Rebuild ACLs - SQLCONFIG[system]['REG_ACL'] = acl_build(SQLCONFIG[system]['REG_ACL'], PEER_MAX) - SQLCONFIG[system]['SUB_ACL'] = acl_build(SQLCONFIG[system]['SUB_ACL'], ID_MAX) - SQLCONFIG[system]['TG1_ACL'] = acl_build(SQLCONFIG[system]['TG1_ACL'], ID_MAX) - SQLCONFIG[system]['TG2_ACL'] = acl_build(SQLCONFIG[system]['TG2_ACL'], ID_MAX) - - if SQLCONFIG[system]['REG_ACL'] != CONFIG['SYSTEMS'][system]['REG_ACL']: - logger.debug('(MYSQL) registration ACL changed') - if SQLCONFIG[system]['SUB_ACL'] != CONFIG['SYSTEMS'][system]['SUB_ACL']: - logger.debug('(MYSQL) subscriber ACL changed') - if SQLCONFIG[system]['TG1_ACL'] != CONFIG['SYSTEMS'][system]['TG1_ACL']: - logger.debug('(MYSQL) TG1 ACL changed') - if SQLCONFIG[system]['TG2_ACL'] != CONFIG['SYSTEMS'][system]['TG2_ACL']: - logger.debug('(MYSQL) TG2 ACL changed') - - #Preserve peers list - if system in CONFIG['SYSTEMS'] and CONFIG['SYSTEMS'][system]['ENABLED'] and 'PEERS' in CONFIG['SYSTEMS'][system] : - SQLCONFIG[system]['PEERS'] = CONFIG['SYSTEMS'][system]['PEERS'] - CONFIG['SYSTEMS'][system].update(SQLCONFIG[system]) - else: - CONFIG['SYSTEMS'][system].update(SQLCONFIG[system]) - - - #Add MySQL config data to config dict - #CONFIG['SYSTEMS'].update(SQLCONFIG) - - SQLCONFIG = {} class routerOBP(OPENBRIDGE): @@ -2861,36 +2536,11 @@ if __name__ == '__main__': logger.info('Copyright (c) 2013, 2014, 2015, 2016, 2018, 2019\n\tThe Regents of the K0USY Group. All rights reserved.\n') logger.debug('(GLOBAL) Logging system started, anything from here on gets logged') - - #If MySQL is enabled, read master config from MySQL too - if CONFIG['MYSQL']['USE_MYSQL'] == True: - logger.info('(MYSQL) MySQL config enabled') - SQLCONFIG = {} - sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],CONFIG['MYSQL']['TABLE'],logger) - #Run it once immediately - if sql.con(): - logger.info('(MYSQL) reading config from database') - try: - SQLCONFIG = sql.getConfig() - #Add MySQL config data to config dict - except: - logger.warning('(MYSQL) problem with SQL query, aborting') - sql.close() - logger.debug('(MYSQL) building ACLs') - # Build ACLs - for system in SQLCONFIG: - SQLCONFIG[system]['REG_ACL'] = acl_build(SQLCONFIG[system]['REG_ACL'], PEER_MAX) - for acl in ['SUB_ACL', 'TG1_ACL', 'TG2_ACL']: - SQLCONFIG[system][acl] = acl_build(SQLCONFIG[system][acl], ID_MAX) - - CONFIG['SYSTEMS'].update(SQLCONFIG) - else: - logger.warning('(MYSQL) problem connecting to SQL server, aborting') - if CONFIG['ALLSTAR']['ENABLED']: - logger.info('(AMI) Setting up AMI: Server: %s, Port: %s, User: %s, Pass: %s, Node: %s',CONFIG['ALLSTAR']['SERVER'],CONFIG['ALLSTAR']['PORT'],CONFIG['ALLSTAR']['USER'],CONFIG['ALLSTAR']['PASS'],CONFIG['ALLSTAR']['NODE']) - - AMIOBJ = AMI(CONFIG['ALLSTAR']['SERVER'],CONFIG['ALLSTAR']['PORT'],CONFIG['ALLSTAR']['USER'],CONFIG['ALLSTAR']['PASS'],CONFIG['ALLSTAR']['NODE']) + if CONFIG['ALLSTAR']['ENABLED']: + logger.info('(AMI) Setting up AMI: Server: %s, Port: %s, User: %s, Pass: %s, Node: %s',CONFIG['ALLSTAR']['SERVER'],CONFIG['ALLSTAR']['PORT'],CONFIG['ALLSTAR']['USER'],CONFIG['ALLSTAR']['PASS'],CONFIG['ALLSTAR']['NODE']) + + AMIOBJ = AMI(CONFIG['ALLSTAR']['SERVER'],CONFIG['ALLSTAR']['PORT'],CONFIG['ALLSTAR']['USER'],CONFIG['ALLSTAR']['PASS'],CONFIG['ALLSTAR']['NODE']) # Set up the signal handler @@ -3091,13 +2741,6 @@ if __name__ == '__main__': options_task = task.LoopingCall(options_config) options = options_task.start(26) options.addErrback(loopingErrHandle) - - #Mysql config checker - #This runs in a thread so as not to block the reactor - if CONFIG['MYSQL']['USE_MYSQL'] == True: - mysql_task = task.LoopingCall(threadedMysql) - mysql = mysql_task.start(33) - mysql.addErrback(loopingErrHandle) #STAT trimmer - once every hour (roughly - shifted so all timed tasks don't run at once if CONFIG['GLOBAL']['GEN_STAT_BRIDGES']: diff --git a/config.py b/config.py index 15caf6d..cec13ea 100755 --- a/config.py +++ b/config.py @@ -128,7 +128,6 @@ def build_config(_config_file): CONFIG['LOGGER'] = {} CONFIG['ALIASES'] = {} CONFIG['SYSTEMS'] = {} - CONFIG['MYSQL'] = {} CONFIG['ALLSTAR'] = {} try: @@ -190,16 +189,6 @@ def build_config(_config_file): }) - elif section == 'MYSQL': - CONFIG['MYSQL'].update({ - 'USE_MYSQL': config.getboolean(section, 'USE_MYSQL'), - 'USER': config.get(section, 'USER'), - 'PASS': config.get(section, 'PASS'), - 'DB': config.get(section, 'DB'), - 'SERVER': config.get(section, 'SERVER'), - 'PORT': config.getint(section,'PORT'), - 'TABLE': config.get(section, 'TABLE') - }) elif section == 'ALLSTAR': CONFIG['ALLSTAR'].update({ diff --git a/mysql_config.py b/mysql_config.py deleted file mode 100644 index 9acf6e6..0000000 --- a/mysql_config.py +++ /dev/null @@ -1,107 +0,0 @@ -import mysql.connector -from mysql.connector import errorcode -#import mysql.connector.pooling - -# Does anybody read this stuff? There's a PEP somewhere that says I should do this. -__author__ = 'Simon Adlem - G7RZU' -__copyright__ = 'Copyright (c) Simon Adlem, G7RZU 2020,2021' -__credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT; Jon Lee, G4TSN; Norman Williams, M6NBP' -__license__ = 'GNU GPLv3' -__maintainer__ = 'Simon Adlem G7RZU' -__email__ = 'simon@gb7fr.org.uk' - - -class useMYSQL: - #Init new object - def __init__(self, server,user,password,database,table,logger): - self.server = server - self.user = user - self.password = password - self.database = database - self.table = table - self.logger = logger - - #Connect - def con(self): - logger = self.logger - try: - self.db = mysql.connector.connect( - host=self.server, - user=self.user, - password=self.password, - database=self.database, - # pool_name = "hblink_master", - # pool_size = 2 - ) - except mysql.connector.Error as err: - if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: - logger.info('(MYSQL) username or password error') - return (False) - elif err.errno == errorcode.ER_BAD_DB_ERROR: - logger.info('(MYSQL) DB Error') - return (False) - else: - logger.info('(MYSQL) error: %s',err) - return(False) - - return(True) - - #Close DB connection - def close(self): - self.db.close() - - #Get config from DB - def getConfig(self): - - CONFIG = {} - CONFIG['SYSTEMS'] = {} - - _cursor = self.db.cursor() - - try: - _cursor.execute("select * from {} where MODE='MASTER'".format(self.table)) - except mysql.connector.Error as err: - _cursor.close() - logger.info('(MYSQL) error, problem with cursor execute') - raise Exception('Problem with cursor execute') - - for (callsign, mode, enabled, _repeat, max_peers, export_ambe, ip, port, passphrase, group_hangtime, use_acl, reg_acl, sub_acl, tgid_ts1_acl, tgid_ts2_acl, default_ua_timer, single_mode, voice_ident,ts1_static,ts2_static,default_reflector, announce_lang) in _cursor: - try: - CONFIG['SYSTEMS'].update({callsign: { - 'MODE': mode, - 'ENABLED': bool(enabled), - 'REPEAT': bool(_repeat), - 'MAX_PEERS': int(max_peers), - 'IP': ip, - 'PORT': int(port), - 'PASSPHRASE': bytes(passphrase, 'utf-8'), - 'GROUP_HANGTIME': int(group_hangtime), - 'USE_ACL': bool(use_acl), - 'REG_ACL': reg_acl, - 'SUB_ACL': sub_acl, - 'TG1_ACL': tgid_ts1_acl, - 'TG2_ACL': tgid_ts2_acl, - 'DEFAULT_UA_TIMER': int(default_ua_timer), - 'SINGLE_MODE': bool(single_mode), - 'VOICE_IDENT': bool(voice_ident), - 'TS1_STATIC': ts1_static, - 'TS2_STATIC': ts2_static, - 'DEFAULT_REFLECTOR': int(default_reflector), - 'GENERATOR': int(1), - 'ANNOUNCEMENT_LANGUAGE': announce_lang - }}) - CONFIG['SYSTEMS'][callsign].update({'PEERS': {}}) - except TypeError: - logger.info('(MYSQL) Problem with data from MySQL - TypeError, carrying on to next row') - _cursor.close() - return(CONFIG['SYSTEMS']) - - -#For testing -if __name__ == '__main__': - - sql = useMYSQL("ip","user","pass","db") - - sql.con() - - print( sql.getConfig()) diff --git a/requirements.txt b/requirements.txt index 6fd9564..98a1d9e 100755 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,5 @@ bitarray>=0.8.1 Twisted>=16.3.0 dmr_utils3>=0.1.19 configparser>=3.0.0 -mysql-connector resettabletimer>=0.7.0 setproctitle From 5428a3e0d5e04d8f597845e9b52d75210ab6bca9 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 25 Aug 2022 16:10:24 +0100 Subject: [PATCH 123/128] Add stats option --- config.py | 2 -- report_receiver.py | 14 ++++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index cec13ea..5a9f5c0 100755 --- a/config.py +++ b/config.py @@ -202,8 +202,6 @@ def build_config(_config_file): elif section == 'PROXY': pass - - elif config.getboolean(section, 'ENABLED'): if config.get(section, 'MODE') == 'PEER': diff --git a/report_receiver.py b/report_receiver.py index 37b8b07..971bc1f 100644 --- a/report_receiver.py +++ b/report_receiver.py @@ -69,10 +69,16 @@ class reportClient(NetstringReceiver): def bridgeSend(self,data): self.BRIDGES = pickle.loads(data) - if cli_args.WATCH and cli_args.WATCH in self.BRIDGES: - pprint(self.BRIDGES[cli_args.WATCH], compact=True) + if cli_args.STATS: + print('There are currently {} active bridges in the bridge table:\n\n'.format(len(self.BRIDGES))) + for _bridge in self.BRIDGES: + print('{},'.format({_bridge})) + else: - pprint(self.BRIDGES, compact=True, indent=4) + if cli_args.WATCH and cli_args.WATCH in self.BRIDGES: + pprint(self.BRIDGES[cli_args.WATCH], compact=True) + else: + pprint(self.BRIDGES, compact=True, indent=4) def configSend(self,data): self.CONFIG = pickle.loads(data) @@ -128,7 +134,7 @@ if __name__ == '__main__': parser.add_argument('-w', '--watch', action='store', dest='WATCH', help='watch bridge ') parser.add_argument('-o', '--host', action='store', dest='HOST', help='host to connect to ') parser.add_argument('-p', '--port', action='store', dest='PORT', help='port to connect to ') - + parser.add_argument('-s', '--stats', action='store', dest='STATS', help='print stats only') cli_args = parser.parse_args() From 64248b3b6947bb7773521349a69d6c78f8adb35f Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 25 Aug 2022 16:12:45 +0100 Subject: [PATCH 124/128] keys --- report_receiver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report_receiver.py b/report_receiver.py index 971bc1f..486c60b 100644 --- a/report_receiver.py +++ b/report_receiver.py @@ -70,8 +70,8 @@ class reportClient(NetstringReceiver): def bridgeSend(self,data): self.BRIDGES = pickle.loads(data) if cli_args.STATS: - print('There are currently {} active bridges in the bridge table:\n\n'.format(len(self.BRIDGES))) - for _bridge in self.BRIDGES: + print('There are currently {} active bridges in the bridge table:\n'.format(len(self.BRIDGES))) + for _bridge in keys(self.BRIDGES): print('{},'.format({_bridge})) else: From 4590bdd710c0148596f57fa791736dc9b68d5e5e Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 25 Aug 2022 16:14:20 +0100 Subject: [PATCH 125/128] kflk --- report_receiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/report_receiver.py b/report_receiver.py index 486c60b..c07474b 100644 --- a/report_receiver.py +++ b/report_receiver.py @@ -71,7 +71,7 @@ class reportClient(NetstringReceiver): self.BRIDGES = pickle.loads(data) if cli_args.STATS: print('There are currently {} active bridges in the bridge table:\n'.format(len(self.BRIDGES))) - for _bridge in keys(self.BRIDGES): + for _bridge in self.BRIDGES.keys(): print('{},'.format({_bridge})) else: From bccd0ff6dfc95605acab94508885c630a5f9ac93 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 25 Aug 2022 16:16:55 +0100 Subject: [PATCH 126/128] ldkfl --- report_receiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/report_receiver.py b/report_receiver.py index c07474b..97893fd 100644 --- a/report_receiver.py +++ b/report_receiver.py @@ -72,7 +72,7 @@ class reportClient(NetstringReceiver): if cli_args.STATS: print('There are currently {} active bridges in the bridge table:\n'.format(len(self.BRIDGES))) for _bridge in self.BRIDGES.keys(): - print('{},'.format({_bridge})) + print('{},'.format({str(_bridge)})) else: if cli_args.WATCH and cli_args.WATCH in self.BRIDGES: From 8ccf08958e855aadcd23f7cc4f8d402b064ef523 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 27 Aug 2022 00:13:52 +0000 Subject: [PATCH 127/128] Update loro.cfg --- loro.cfg | 9 --------- 1 file changed, 9 deletions(-) diff --git a/loro.cfg b/loro.cfg index 2c392ef..63eed1f 100644 --- a/loro.cfg +++ b/loro.cfg @@ -117,15 +117,6 @@ SUB_MAP_FILE: SERVER_ID_URL: http://downloads.freedmr.uk/downloads/FreeDMR_Hosts.csv SERVER_ID_FILE: server_ids.tsv -#Read further repeater configs from MySQL -[MYSQL] -USE_MYSQL: False -USER: hblink -PASS: mypassword -DB: hblink -SERVER: 127.0.0.1 -PORT: 3306 -TABLE: repeaters # OPENBRIDGE INSTANCES - DUPLICATE SECTION FOR MULTIPLE CONNECTIONS # OpenBridge is a protocol originall created by DMR+ for connection between an From 0eb9f3be22c7befae29f32b50012f19b28f7fca8 Mon Sep 17 00:00:00 2001 From: rune Date: Sat, 27 Aug 2022 00:23:41 +0000 Subject: [PATCH 128/128] Typo in options handling --- bridge_master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge_master.py b/bridge_master.py index 7b4570f..976a293 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -792,7 +792,7 @@ def options_config(): if 'TS2_1' in _options: _options['TS2_STATIC'] = _options.pop('TS2_1') if 'TS2_2' in _options: - _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],','. _options.pop('TS2_2')]) + _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',', _options.pop('TS2_2')]) if 'TS2_3' in _options: _options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_3')]) if 'TS2_4' in _options: