Started adding conditionals to validate messages
for example: if we haven't yet received a peer list from the master, we should not be processing keep-alives from peers.
This commit is contained in:
parent
2e0f29fc97
commit
8f8608cbfc
17
ipsc.py
17
ipsc.py
@ -59,9 +59,7 @@ def strip_hash(_data):
|
|||||||
# Determine if the provided peer ID is valid for the provided network
|
# Determine if the provided peer ID is valid for the provided network
|
||||||
#
|
#
|
||||||
def valid_peer(_network, _peerid):
|
def valid_peer(_network, _peerid):
|
||||||
print(' %s' % binascii.b2a_hex(_peerid))
|
|
||||||
for peer in NETWORK[_network]['PEERS']:
|
for peer in NETWORK[_network]['PEERS']:
|
||||||
print(binascii.b2a_hex(peer['RADIO_ID']))
|
|
||||||
if peer['RADIO_ID'] == _peerid:
|
if peer['RADIO_ID'] == _peerid:
|
||||||
return True
|
return True
|
||||||
return True #MUST BE FIXED!!!!!! should return false, but there are other issues right now...
|
return True #MUST BE FIXED!!!!!! should return false, but there are other issues right now...
|
||||||
@ -137,7 +135,6 @@ def mode_decode(_mode):
|
|||||||
link_mode = _mode & PEER_MODE_MSK
|
link_mode = _mode & PEER_MODE_MSK
|
||||||
ts1 = _mode & IPSC_TS1_MSK
|
ts1 = _mode & IPSC_TS1_MSK
|
||||||
ts2 = _mode & IPSC_TS2_MSK
|
ts2 = _mode & IPSC_TS2_MSK
|
||||||
|
|
||||||
# Determine whether or not the peer is operational
|
# Determine whether or not the peer is operational
|
||||||
if link_op == 0b01000000:
|
if link_op == 0b01000000:
|
||||||
_peer_op = True
|
_peer_op = True
|
||||||
@ -145,8 +142,6 @@ def mode_decode(_mode):
|
|||||||
_peer_op = False
|
_peer_op = False
|
||||||
else:
|
else:
|
||||||
_peer_op = False
|
_peer_op = False
|
||||||
|
|
||||||
|
|
||||||
# Determine the operational mode of the peer
|
# Determine the operational mode of the peer
|
||||||
if link_mode == 0b00000000:
|
if link_mode == 0b00000000:
|
||||||
_peer_mode = 'NO_RADIO'
|
_peer_mode = 'NO_RADIO'
|
||||||
@ -156,19 +151,16 @@ def mode_decode(_mode):
|
|||||||
_peer_mode = 'DIGITAL'
|
_peer_mode = 'DIGITAL'
|
||||||
else:
|
else:
|
||||||
_peer_node = 'NO_RADIO'
|
_peer_node = 'NO_RADIO'
|
||||||
|
|
||||||
# Determine whether or not timeslot 1 is linked
|
# Determine whether or not timeslot 1 is linked
|
||||||
if ts1 == 0b00001000:
|
if ts1 == 0b00001000:
|
||||||
_ts1 = True
|
_ts1 = True
|
||||||
else:
|
else:
|
||||||
_ts1 = False
|
_ts1 = False
|
||||||
|
|
||||||
# Determine whether or not timeslot 2 is linked
|
# Determine whether or not timeslot 2 is linked
|
||||||
if ts2 == 0b00000010:
|
if ts2 == 0b00000010:
|
||||||
_ts2 = True
|
_ts2 = True
|
||||||
else:
|
else:
|
||||||
_ts2 = False
|
_ts2 = False
|
||||||
|
|
||||||
# Return a tuple with the decoded values
|
# Return a tuple with the decoded values
|
||||||
return _peer_op, _peer_mode, _ts1, _ts2
|
return _peer_op, _peer_mode, _ts1, _ts2
|
||||||
|
|
||||||
@ -349,18 +341,21 @@ class IPSC(DatagramProtocol):
|
|||||||
logger.warning('(%s) AuthError: IPSC packet failed authentication. Type %s: Peer ID: %s', self._network, binascii.b2a_hex(_packettype), _dec_peerid)
|
logger.warning('(%s) AuthError: IPSC packet failed authentication. Type %s: Peer ID: %s', self._network, binascii.b2a_hex(_packettype), _dec_peerid)
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._master_stat['CONNECTED'] == True:
|
if (_packettype == PEER_ALIVE_REQ):
|
||||||
if valid_peer(self._network, _peerid) == False or valid_master(self._network, _peerid) == False:
|
if valid_peer(self._network, _peerid) == False:
|
||||||
logger.warning('(%s) PeerError: Peer not in peer-list: %s', self._network, _dec_peerid)
|
logger.warning('(%s) PeerError: Peer not in peer-list: %s', self._network, _dec_peerid)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (_packettype == PEER_ALIVE_REQ):
|
|
||||||
logger.debug('<<- (%s) Peer Keep-alive Request From Peer ID %s at:%s:%s', self._network, _dec_peerid, host, port)
|
logger.debug('<<- (%s) Peer Keep-alive Request From Peer ID %s at:%s:%s', self._network, _dec_peerid, host, port)
|
||||||
peer_alive_reply_packet = hashed_packet(self._local['AUTH_KEY'], self.PEER_ALIVE_REPLY_PKT)
|
peer_alive_reply_packet = hashed_packet(self._local['AUTH_KEY'], self.PEER_ALIVE_REPLY_PKT)
|
||||||
self.transport.write(peer_alive_reply_packet, (host, port))
|
self.transport.write(peer_alive_reply_packet, (host, port))
|
||||||
logger.debug('->> (%s) Peer Keep-alive Reply sent To:%s:%s', self._network, host, port)
|
logger.debug('->> (%s) Peer Keep-alive Reply sent To:%s:%s', self._network, host, port)
|
||||||
|
|
||||||
elif (_packettype == MASTER_ALIVE_REPLY):
|
elif (_packettype == MASTER_ALIVE_REPLY):
|
||||||
|
if valid_master(self._network, _peerid) == False:
|
||||||
|
logger.warning('(%s) PeerError: Peer not in peer-list: %s', self._network, _dec_peerid)
|
||||||
|
return
|
||||||
|
|
||||||
logger.debug('<<- (%s) Master Keep-alive Reply From: %s \t@ IP: %s:%s', self._network, _dec_peerid, host, port)
|
logger.debug('<<- (%s) Master Keep-alive Reply From: %s \t@ IP: %s:%s', self._network, _dec_peerid, host, port)
|
||||||
#### increment keep-alive outstanding here
|
#### increment keep-alive outstanding here
|
||||||
|
|
||||||
|
@ -36,3 +36,40 @@ LINK_TYPE_IPSC = b'\x04'
|
|||||||
|
|
||||||
# IPSC Version and Link Type are Used for a 4-byte version field in registration packets
|
# IPSC Version and Link Type are Used for a 4-byte version field in registration packets
|
||||||
IPSC_VER = LINK_TYPE_IPSC + IPSC_VER_19 + LINK_TYPE_IPSC + IPSC_VER_17
|
IPSC_VER = LINK_TYPE_IPSC + IPSC_VER_19 + LINK_TYPE_IPSC + IPSC_VER_17
|
||||||
|
|
||||||
|
# Conditions for accepting certain types of messages... the cornerstone of a secure IPSC system :)
|
||||||
|
REQ_VALID_PEER = [
|
||||||
|
PEER_REG_REQ,
|
||||||
|
PEER_REG_REPLY
|
||||||
|
]
|
||||||
|
|
||||||
|
REQ_VALID_MASTER = [
|
||||||
|
MASTER_REG_REQ,
|
||||||
|
MASTER_REG_REPLY
|
||||||
|
]
|
||||||
|
|
||||||
|
REQ_MASTER_CONNECTED = [
|
||||||
|
CALL_CTL_1,
|
||||||
|
CALL_CTL_2,
|
||||||
|
CALL_CTL_3,
|
||||||
|
XCMP_XNL,
|
||||||
|
GROUP_VOICE,
|
||||||
|
PVT_VOICE,
|
||||||
|
GROUP_DATA,
|
||||||
|
GROUP_VOICE,
|
||||||
|
PVT_DATA,
|
||||||
|
RPT_WAKE_UP,
|
||||||
|
MASTER_ALIVE_REQ,
|
||||||
|
MASTER_ALIVE_REPLY,
|
||||||
|
DE_REG_REQ,
|
||||||
|
DE_REG_REPLY
|
||||||
|
]
|
||||||
|
|
||||||
|
REQ_PEER_CONNECTED = [
|
||||||
|
PEER_ALIVE_REQ,
|
||||||
|
PEER_ALIVE_REPLY
|
||||||
|
]
|
||||||
|
|
||||||
|
REQ_VALID_MASTER_OR_PEER = [
|
||||||
|
REQ_VALID_PEER, REQ_VALID_MASTER
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user