Work on Master Support

This commit is contained in:
Cort Buffington 2014-05-14 20:58:58 -05:00
parent f915131a23
commit 8d451abebc
2 changed files with 34 additions and 9 deletions

View File

@ -26,6 +26,7 @@ from hmac import new as hmac_new
from binascii import b2a_hex as h from binascii import b2a_hex as h
from hashlib import sha1 from hashlib import sha1
from socket import inet_ntoa as IPAddr from socket import inet_ntoa as IPAddr
from socket import inet_aton as IPHexStr
from twisted.internet.protocol import DatagramProtocol from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor from twisted.internet import reactor
from twisted.internet import task from twisted.internet import task
@ -295,10 +296,29 @@ except ImportError:
# UTILITY FUNCTIONS FOR INTERNAL USE # UTILITY FUNCTIONS FOR INTERNAL USE
#************************************************ #************************************************
# Create a 3 byte TGID or UID from an integer # Create a 2 byte hex string from an integer
# #
def hex_id(_int_id): def hex_str_2(_int_id):
return hex(_int_id)[2:].rjust(6,'0').decode('hex') try:
return hex(_int_id)[2:].rjust(4,'0').decode('hex')
except TypeError:
logger.error('hex_str_2: invalid integer length')
# Create a 3 byte hex string from an integer
#
def hex_str_3(_int_id):
try:
return hex(_int_id)[2:].rjust(6,'0').decode('hex')
except TypeError:
logger.error('hex_str_3: invalid integer length')
# Create a 4 byte hex string from an integer
#
def hex_str_4(_int_id):
try:
return hex(_int_id)[2:].rjust(8,'0').decode('hex')
except TypeError:
logger.error('hex_str_4: invalid integer length')
# Convert a hex string to an int (radio ID, etc.) # Convert a hex string to an int (radio ID, etc.)
# #
@ -1082,15 +1102,20 @@ class IPSC(DatagramProtocol):
# REQUEST FOR A KEEP-ALIVE REPLY (WE KNOW THE PEER IS STILL ALIVE TOO) # REQUEST FOR A KEEP-ALIVE REPLY (WE KNOW THE PEER IS STILL ALIVE TOO)
elif _packettype == MASTER_ALIVE_REQ: elif _packettype == MASTER_ALIVE_REQ:
self._peers[_peerid]['STATUS']['KEEP_ALIVES_SENT'] += 1 if _peerid in self._peers.keys():
master_alive_reply_packet = self.hashed_packet(self._local['AUTH_KEY'], self.MASTER_ALIVE_REPLY_PKT) self._peers[_peerid]['STATUS']['KEEP_ALIVES_SENT'] += 1
self.transport.write(master_alive_reply_packet, (host, port)) master_alive_reply_packet = self.hashed_packet(self._local['AUTH_KEY'], self.MASTER_ALIVE_REPLY_PKT)
logger.debug('(%s) Master Keep-Alive Request Received from peer %s', self._network, int_id(_peerid)) self.transport.write(master_alive_reply_packet, (host, port))
logger.debug('(%s) Master Keep-Alive Request Received from peer %s', self._network, int_id(_peerid))
else:
logger.warning('(%s) Master Keep-Alive Request Received from *UNREGISTERED* peer %s', self._network, int_id(_peerid))
return return
# REQUEST FOR A PEER LIST # REQUEST FOR A PEER LIST
elif _packettype == PEER_LIST_REQ: elif _packettype == PEER_LIST_REQ:
logger.debug('(%s) Peer List Request from peer %s', self._network, int_id(_peerid)) logger.debug('(%s) Peer List Request from peer %s', self._network, int_id(_peerid))
for peer in self._peers:
print(self._peers[peer])
return return

View File

@ -13,7 +13,7 @@ from twisted.internet import reactor
from binascii import b2a_hex as h from binascii import b2a_hex as h
import sys, time import sys, time
from dmrlink import IPSC, NETWORK, networks, logger, dmr_nat, int_id, send_to_ipsc, hex_id from dmrlink import IPSC, NETWORK, networks, logger, dmr_nat, int_id, send_to_ipsc, hex_str_3
__author__ = 'Cortney T. Buffington, N0MJS' __author__ = 'Cortney T. Buffington, N0MJS'
__copyright__ = 'Copyright (c) 2014 Cortney T. Buffington, N0MJS and the K0USY Group' __copyright__ = 'Copyright (c) 2014 Cortney T. Buffington, N0MJS and the K0USY Group'
@ -30,7 +30,7 @@ try:
except ImportError: except ImportError:
sys.exit('Configuration file not found or invalid') sys.exit('Configuration file not found or invalid')
HEX_TGID = hex_id(TGID) HEX_TGID = hex_str_3(TGID)
class playbackIPSC(IPSC): class playbackIPSC(IPSC):