From 916ed46fef21018b627c856a709178386562ab12 Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Tue, 10 Sep 2013 09:43:45 -0500 Subject: [PATCH] FIxed calculation of number of peers in an IPSC Incorrect decodeing of determination of the peer-list. As it turns out, the packet indicates the length of the list, not the number of peers. So, take that value / 11 (length of a peer entry) for the number of peers. Thanks to Hans for pointing this out! --- README.md | 8 +++++--- ipsc.py | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e1cf194..b897b77 100644 --- a/README.md +++ b/README.md @@ -152,16 +152,18 @@ PEER LIST REQUEST: PEER LIST RESPONSE: - TYPE(1 Byte) + SRC_ID (4 Bytes) + NUM_PEERS * (2 Bytes) + {PEER_ID, PEER_IP, PEER_PORT, PEER_LINKING}... [+ AUTHENTICATION (10 Bytes)] - 93 0004c2c0 002c* + TYPE(1 Byte) + SRC_ID (4 Bytes) + PEER_LIST_LENGTH* (2 Bytes) + {PEER_ID, PEER_IP, PEER_PORT, PEER_LINKING}... [+ AUTHENTICATION (10 Bytes)] + 93 0004c2c0 002c 00000001 6ccf7505 c351 6a 0004c2c3 d17271e9 c35a 6a 0004c2c5 446716bb c35c 6a 00c83265 a471c50c c351 6a d66a94568d29357205c2 + + *Number of peers can be derived from PEER_LIST_LENGTH, as each peer entry is 11 bytes (Thanks Hans!) -*Number of Peers, oddly formatted, stripping most significant non-zero digit seems to produce the correct value, such as 0x2c = 44, or 4 peers; or 0x6e = 110, or 10 peers +Number of peers can be derived from PEER_LIST_LENGTH, as each peer entry is 11 bytes **CAPABILITIES: Bytes 6-14 (6-16 for master reg. reply):** (Displayed in most to least significant bytes) diff --git a/ipsc.py b/ipsc.py index 9f4e5a6..ba57a04 100644 --- a/ipsc.py +++ b/ipsc.py @@ -160,14 +160,14 @@ def process_peer_list(_data, _network, _peer_list): # _log = logger.debug # Set the status flag to indicate we have recieved a Peer List NETWORK[_network]['MASTER']['STATUS']['PEER-LIST'] = True - # Determine how many peers are in the list by parsing the packet - _num_peers = int(str(int(binascii.b2a_hex(_data[5:7]), 16))[1:]) - # Record the number of peers in the data structure... we'll use it later. - NETWORK[_network]['LOCAL']['NUM_PEERS'] = _num_peers + # Determine the length of the peer list for the parsing iterator + _peer_list_length = int(binascii.b2a_hex(_data[5:7]), 16) + # Record the number of peers in the data structure... we'll use it later (11 bytes per peer entry) + NETWORK[_network]['LOCAL']['NUM_PEERS'] = _peer_list_length/11 # _log('<<- (%s) The Peer List has been Received from Master\n%s There are %s peers in this IPSC Network', _network, (' '*(len(_network)+7)), _num_peers) # Iterate each peer entry in the peer list. Skip the header, then pull the next peer, the next, etc. - for i in range(7, (_num_peers*11)+7, 11): + for i in range(7, (_peer_list_length)+7, 11): # Extract various elements from each entry... _hex_radio_id = (_data[i:i+4]) _hex_address = (_data[i+4:i+8])