Merge pull request #10 from yuvelq/patch-1

Update hotspot_proxy_v2.py
This commit is contained in:
hacknix 2021-09-08 20:24:49 +01:00 committed by GitHub
commit 96e3739590
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
from twisted.internet.protocol import DatagramProtocol from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor, task from twisted.internet import reactor, task
from time import time from time import time
from resettabletimer import ResettableTimer
from dmr_utils3.utils import int_id from dmr_utils3.utils import int_id
import random import random
import ipaddress import ipaddress
@ -95,23 +94,21 @@ class Proxy(DatagramProtocol):
_peer_id = self.connTrack[port] _peer_id = self.connTrack[port]
elif _command == MSTN: elif _command == MSTN:
_peer_id = data[6:10] _peer_id = data[6:10]
self.peerTrack[_peer_id]['timer'].cancel()
self.reaper(_peer_id)
return
elif _command == MSTP: elif _command == MSTP:
_peer_id = data[7:11] _peer_id = data[7:11]
elif _command == MSTC: elif _command == MSTC:
_peer_id = data[5:9] _peer_id = data[5:9]
self.peerTrack[_peer_id]['timer'].cancel()
self.reaper(_peer_id)
return
# _peer_id = self.connTrack[port] # _peer_id = self.connTrack[port]
if self.debug: if self.debug:
print(data) print(data)
if _peer_id and _peer_id in self.peerTrack: if _peer_id in self.peerTrack:
self.transport.write(data,(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport'])) self.transport.write(data,(self.peerTrack[_peer_id]['shost'],self.peerTrack[_peer_id]['sport']))
#self.peerTrack[_peer_id]['timer'].reset() #self.peerTrack[_peer_id]['timer'].reset()
# Remove the client after send a MSTN or MSTC packet
if _command in (MSTN,MSTC):
self.peerTrack[_peer_id]['timer'].cancel()
self.reaper(_peer_id)
return return
@ -122,7 +119,7 @@ class Proxy(DatagramProtocol):
if _command == DMRD: # DMRData -- encapsulated DMR data frame if _command == DMRD: # DMRData -- encapsulated DMR data frame
_peer_id = data[11:15] _peer_id = data[11:15]
elif _command == DMRA: # DMRAlias -- Talker Alias information elif _command == DMRA: # DMRAlias -- Talker Alias information
_peer_id = _data[4:8] _peer_id = data[4:8]
elif _command == RPTL: # RPTLogin -- a repeater wants to login elif _command == RPTL: # RPTLogin -- a repeater wants to login
_peer_id = data[4:8] _peer_id = data[4:8]
elif _command == RPTK: # Repeater has answered our login challenge elif _command == RPTK: # Repeater has answered our login challenge
@ -144,7 +141,7 @@ class Proxy(DatagramProtocol):
self.peerTrack[_peer_id]['sport'] = port self.peerTrack[_peer_id]['sport'] = port
self.peerTrack[_peer_id]['shost'] = host self.peerTrack[_peer_id]['shost'] = host
self.transport.write(data, (Master,_dport)) self.transport.write(data, (Master,_dport))
self.peerTrack[_peer_id]['timer'].reset() self.peerTrack[_peer_id]['timer'].reset(self.timeout)
if self.debug: if self.debug:
print(data) print(data)
return return
@ -163,8 +160,7 @@ class Proxy(DatagramProtocol):
self.peerTrack[_peer_id]['dport'] = _dport self.peerTrack[_peer_id]['dport'] = _dport
self.peerTrack[_peer_id]['sport'] = port self.peerTrack[_peer_id]['sport'] = port
self.peerTrack[_peer_id]['shost'] = host self.peerTrack[_peer_id]['shost'] = host
self.peerTrack[_peer_id]['timer'] = ResettableTimer(self.timeout,self.reaper,[_peer_id]) self.peerTrack[_peer_id]['timer'] = reactor.callLater(self.timeout,self.reaper,_peer_id)
self.peerTrack[_peer_id]['timer'].start()
self.transport.write(data, (self.master,_dport)) self.transport.write(data, (self.master,_dport))
if self.debug: if self.debug:
print(data) print(data)