Exemplo n.º 1
0
def build_peer_list(_peers):
    concatenated_peers = ''
    for peer in _peers:
        hex_ip = IPHexStr(_peers[peer]['IP'])
        hex_port = hex_str_2(_peers[peer]['PORT'])
        mode = _peers[peer]['MODE']        
        concatenated_peers += peer + hex_ip + hex_port + mode
    
    peer_list = hex_str_2(len(concatenated_peers)) + concatenated_peers
    return peer_list
Exemplo n.º 2
0
def build_peer_list(_peers):
    concatenated_peers = ''
    for peer in _peers:
        hex_ip = IPHexStr(_peers[peer]['IP'])
        hex_port = hex_str_2(_peers[peer]['PORT'])
        mode = _peers[peer]['MODE']
        concatenated_peers += peer + hex_ip + hex_port + mode

    peer_list = hex_str_2(len(concatenated_peers)) + concatenated_peers
    return peer_list
Exemplo n.º 3
0
    def master_reg_req(self, _data, _peerid, _host, _port):
        _ip_address = _host
        _port = _port
        _hex_mode = _data[5]
        _hex_flags = _data[6:10]
        _decoded_mode = process_mode_byte(_hex_mode)
        _decoded_flags = process_flags_bytes(_hex_flags)

        self.MASTER_REG_REPLY_PKT = (MASTER_REG_REPLY + self._local_id +
                                     self.TS_FLAGS +
                                     hex_str_2(self._local['NUM_PEERS']) +
                                     IPSC_VER)
        self.send_packet(self.MASTER_REG_REPLY_PKT, (_host, _port))
        self._logger.info(
            '(%s) Master Registration Packet Received from peer %s, %s:%s',
            self._system, int_id(_peerid), _host, _port)

        # If this entry was NOT already in our list, add it.
        if _peerid not in self._peers.keys():
            self._peers[_peerid] = {
                'IP': _ip_address,
                'PORT': _port,
                'MODE': _hex_mode,
                'MODE_DECODE': _decoded_mode,
                'FLAGS': _hex_flags,
                'FLAGS_DECODE': _decoded_flags,
                'STATUS': {
                    'CONNECTED': True,
                    'KEEP_ALIVES_SENT': 0,
                    'KEEP_ALIVES_MISSED': 0,
                    'KEEP_ALIVES_OUTSTANDING': 0,
                    'KEEP_ALIVES_RECEIVED': 0,
                    'KEEP_ALIVE_RX_TIME': int(time())
                }
            }
        self._local['NUM_PEERS'] = len(self._peers)
        self._logger.debug(
            '(%s) Peer Added To Peer List: %s, %s:%s (IPSC now has %s Peers)',
            self._system, self._peers[_peerid], _host, _port,
            self._local['NUM_PEERS'])
Exemplo n.º 4
0
    def master_reg_req(self, _data, _peerid, _host, _port):
        _ip_address    = _host
        _port          = _port
        _hex_mode      = _data[5]
        _hex_flags     = _data[6:10]
        _decoded_mode  = process_mode_byte(_hex_mode)
        _decoded_flags = process_flags_bytes(_hex_flags)
        
        self.MASTER_REG_REPLY_PKT = (MASTER_REG_REPLY + self._local_id + self.TS_FLAGS + hex_str_2(self._local['NUM_PEERS']) + IPSC_VER)
        self.send_packet(self.MASTER_REG_REPLY_PKT, (_host, _port))
        self._logger.info('(%s) Master Registration Packet Received from peer %s, %s:%s', self._system, int_id(_peerid), _host, _port)

        # If this entry was NOT already in our list, add it.
        if _peerid not in self._peers.keys():
            self._peers[_peerid] = {
                'IP':          _ip_address, 
                'PORT':        _port, 
                'MODE':        _hex_mode,            
                'MODE_DECODE': _decoded_mode,
                'FLAGS':       _hex_flags,
                'FLAGS_DECODE': _decoded_flags,
                'STATUS': {
                    'CONNECTED':               True,
                    'KEEP_ALIVES_SENT':        0,
                    'KEEP_ALIVES_MISSED':      0,
                    'KEEP_ALIVES_OUTSTANDING': 0,
                    'KEEP_ALIVES_RECEIVED':    0,
                    'KEEP_ALIVE_RX_TIME':      int(time())
                    }
                }
        self._local['NUM_PEERS'] = len(self._peers)       
        self._logger.debug('(%s) Peer Added To Peer List: %s, %s:%s (IPSC now has %s Peers)', self._system, self._peers[_peerid], _host, _port, self._local['NUM_PEERS'])