From 2e0f29fc97253355da8fbd344c2c5ccffb30af1c Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Tue, 30 Jul 2013 10:52:10 -0500 Subject: [PATCH] Peer Validation - In Progress Mostly done.. must find a way to allow master registration and reception of peer list BEFORE validating incoming messages to the peer list -- chicken and egg problem. Easily solved, but needs an EFFICIENT solution since EVERY PACKET will be passed through this test. --- ipsc.py | 20 +++++++++++++++----- ipsc_logger.py | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ipsc.py b/ipsc.py index 9e3dbe9..21016e0 100644 --- a/ipsc.py +++ b/ipsc.py @@ -59,12 +59,20 @@ def strip_hash(_data): # Determine if the provided peer ID is valid for the provided network # def valid_peer(_network, _peerid): - return True + print(' %s' % binascii.b2a_hex(_peerid)) + for peer in NETWORK[_network]['PEERS']: + print(binascii.b2a_hex(peer['RADIO_ID'])) + if peer['RADIO_ID'] == _peerid: + return True + return True #MUST BE FIXED!!!!!! should return false, but there are other issues right now... # Determine if the provided master ID is valid for the provided network # def valid_master(_network, _peerid): - return True + if NETWORK[_network]['MASTER']['RADIO_ID'] == _peerid: + return True + else: + return False # Take a packet to be SENT, calcualte auth hash and return the whole thing # @@ -341,9 +349,10 @@ class IPSC(DatagramProtocol): logger.warning('(%s) AuthError: IPSC packet failed authentication. Type %s: Peer ID: %s', self._network, binascii.b2a_hex(_packettype), _dec_peerid) return - if valid_peer(self._network, _peerid) == False or valid_master(self._network, _dec_peerid) == True: - logger.warning('(%s) PeerError: Peer not in peer-list: %s', self._network, _dec_peerid) - return + if self._master_stat['CONNECTED'] == True: + if valid_peer(self._network, _peerid) == False or valid_master(self._network, _peerid) == False: + logger.warning('(%s) PeerError: Peer not in peer-list: %s', self._network, _dec_peerid) + 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) @@ -363,6 +372,7 @@ class IPSC(DatagramProtocol): logger.debug('<<- (%s) Master Registration Packet Recieved', self._network) elif (_packettype == MASTER_REG_REPLY): + self._master['RADIO_ID'] = _peerid self._master_stat['CONNECTED'] = True self._master_stat['KEEP_ALIVES_OUTSTANDING'] = 0 logger.debug('<<- (%s) Master Registration Reply From:%s:%s ', self._network, host, port) diff --git a/ipsc_logger.py b/ipsc_logger.py index ec2908e..1fa664c 100644 --- a/ipsc_logger.py +++ b/ipsc_logger.py @@ -47,7 +47,7 @@ dictConfig({ 'ipsc': { # 'handlers': ['file-timed', 'console-timed'], 'handlers': ['file', 'console'], - 'level': 'DEBUG', + 'level': 'INFO', 'propagate': True, } }