diff --git a/bridge_master.py b/bridge_master.py index b5e710f..b80f4bb 100755 --- a/bridge_master.py +++ b/bridge_master.py @@ -315,6 +315,8 @@ def rule_timer_loop(): else: if _system['SYSTEM'][0:3] != 'OBP': _bridge_used = True + else if _system['SYSTEM'][0:3] == 'OBP' and _system['TO_TYPE'] == 'STAT': + _bridge_used = True logger.debug('(ROUTER) Conference Bridge NO ACTION: System: %s, Bridge: %s, TS: %s, TGID: %s', _system['SYSTEM'], _bridge, _system['TS'], int_id(_system['TGID'])) if _bridge_used == False: diff --git a/hotspot_proxy.py b/hotspot_proxy.py index 446327c..a7625c9 100644 --- a/hotspot_proxy.py +++ b/hotspot_proxy.py @@ -5,33 +5,54 @@ from time import time class Proxy(DatagramProtocol): - def __init__(self,ListenPort,connTrack,Timeout): + def __init__(self,ListenPort,connTrack,Timeout,Debug): self.connTrack = connTrack self.timeout = Timeout + self.debug = Debug def datagramReceived(self, data, addr): host,port = addr + Debug = self.debug + + #If the packet comes from the master if host == '127.0.0.1' and port in self.connTrack: if int(self.connTrack[port]['time'])+self.timeout > time(): self.transport.write(data,(self.connTrack[port]['host'],self.connTrack[port]['sport'])) + #if master refuses login, remove tracking and block for timeout seconds + if data == b'MSTNAK\x00#\xbf"': + self.connTrack[port]['time'] = False + self.connTrack[port]['nacktime'] = time()+self.timeout + if Debug: + print(data) return for dport in self.connTrack: + #If blocked from refused login, ignore the packet if its been less than nacktime + if int(self.connTrack[dport]['nacktime']) + self.timeout > time(): + if Debug: + print("NACK\n") + return + #If we have a conntrack for this connect and the timeout has not expired, forward to tracked port if self.connTrack[dport]['host'] == host and self.connTrack[dport]['sport'] == port and (int(self.connTrack[dport]['time'])+self.timeout > time()): self.connTrack[dport]['time'] = time() self.connTrack[dport]['host'] = host self.connTrack[dport]['sport'] = port self.transport.write(data, ('127.0.0.1',dport)) self.connTrack[dport]['time'] = time() + if Debug: + print(data) return - + + #Find free port to map for new connection for dport in self.connTrack: if (self.connTrack[dport]['time'] == False or (int(self.connTrack[dport]['time'])+self.timeout < time())): self.connTrack[dport]['sport'] = port self.connTrack[dport]['host'] = host self.connTrack[dport]['time'] = time() self.transport.write(data, ('127.0.0.1',dport)) + if Debug: + print(data) return @@ -41,10 +62,11 @@ if __name__ == '__main__': #*** CONFIG HERE *** ListenPort = 62031 - DestportStart = 50000 - DestPortEnd = 50500 + DestportStart = 54001 + DestPortEnd = 54002 Timeout = 35 Stats = True + Debug = False #******************* @@ -52,9 +74,9 @@ if __name__ == '__main__': CONNTRACK = {} for port in range(DestportStart,DestPortEnd,1): - CONNTRACK[port] = {'host': False,'time': False,'sport':False} + CONNTRACK[port] = {'host': False,'time': False,'sport':False, 'nacktime': False} - reactor.listenUDP(ListenPort,Proxy(ListenPort,CONNTRACK,Timeout)) + reactor.listenUDP(ListenPort,Proxy(ListenPort,CONNTRACK,Timeout,Debug)) def loopingErrHandle(failure): print('(GLOBAL) STOPPING REACTOR TO AVOID MEMORY LEAK: Unhandled error in timed loop.\n {}'.format(failure))