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!
This commit is contained in:
Cort Buffington 2013-09-10 09:43:45 -05:00
parent 3f9aee2c3c
commit 916ed46fef
2 changed files with 10 additions and 8 deletions

View File

@ -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)

10
ipsc.py
View File

@ -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])