当前位置: 首页>>代码示例>>Python>>正文


Python utils.idec函数代码示例

本文整理汇总了Python中utils.idec函数的典型用法代码示例。如果您正苦于以下问题:Python idec函数的具体用法?Python idec怎么用?Python idec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了idec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_packet

    def load_packet(cls, packet):
        '''
        Though TCP provides a connection-oriented medium, Ethereum nodes
        communicate in terms of packets. These packets are formed as a 4-byte
        synchronisation token (0x22400891), a 4-byte "payload size", to be
        interpreted as a big-endian integer and finally an N-byte
        RLP-serialised data structure, where N is the aforementioned
        "payload size". To be clear, the payload size specifies the number of
        bytes in the packet ''following'' the first 8.

        :return: (success, result), where result should be None when fail,
        and (header, payload_len, cmd, data) when success
        '''
        header = idec(packet[:4])
        if header != cls.SYNCHRONIZATION_TOKEN:
            return False, 'check header failed, skipping message,'\
                'sync token was hex: {0:x}'.format(header)

        try:
            payload_len = idec(packet[4:8])
            payload = lrlp_decode(packet[8:8 + payload_len])
        except Exception as e:
            return False, str(e)

        if (not len(payload)) or (idec(payload[0]) not in cls.cmd_map):
            return False, 'check cmd failed'

        cmd = Packeter.cmd_map.get(idec(payload[0]))
        return True, (header, payload_len, cmd, payload[1:])
开发者ID:pdecker,项目名称:pyethereum,代码行数:29,代码来源:wireprotocol.py

示例2: _recv_Status

    def _recv_Status(self, data):
        # [0x10: P, protocolVersion: P, networkID: P, totalDifficulty: P, latestHash: B_32, genesisHash: B_32]
        # check compatibility
        try:
            ethereum_protocol_version, network_id = idec(data[0]), idec(data[1])
            total_difficulty, head_hash, genesis_hash = idec(data[2]), data[3], data[4]
        except IndexError:
            return self.send_Disconnect(reason='Incompatible network protocols')

        log_eth.debug('received Status',
                      remote_id=self,
                      ethereum_protocol_version=ethereum_protocol_version,
                      total_difficulty=total_difficulty,
                      head=head_hash.encode('hex'),
                      genesis=genesis_hash.encode('hex'))

        if ethereum_protocol_version != packeter.ETHEREUM_PROTOCOL_VERSION:
            return self.send_Disconnect(reason='Incompatible network protocols')

        if network_id != packeter.NETWORK_ID:
            return self.send_Disconnect(reason='Wrong genesis block')

        self.status_received = True
        self.status_head_hash = head_hash
        self.status_total_difficulty = total_difficulty
        signals.peer_status_received.send(sender=Peer, genesis_hash=genesis_hash, peer=self)
开发者ID:ckeenan,项目名称:pyethereum,代码行数:26,代码来源:peer.py

示例3: _recv_Hello

    def _recv_Hello(self, data):
        # check compatibility
        peer_protocol_version, network_id, client_id = idec(data[0]), idec(data[1]), data[2]
        capabilities, listen_port, node_id = idec(data[3]), idec(data[4]), data[5]

        logger.debug('received Hello %s V:%r N:%r C:%r P:%r I:%s', client_id,
                     peer_protocol_version, network_id, capabilities, listen_port,
                     node_id.encode('hex'))

        if peer_protocol_version != packeter.PROTOCOL_VERSION:
            return self.send_Disconnect(
                reason='Incompatible network protocols')

        if network_id != packeter.NETWORK_ID:
            return self.send_Disconnect(reason='Wrong genesis block')

        # add to known peers list in handshake signal
        self.hello_received = True
        self.client_id = client_id
        self.node_id = node_id
        self.port = listen_port  # replace connection port with listen port

        # reply with hello if not send
        if not self.hello_sent:
            self.send_Hello()

        signals.peer_handshake_success.send(sender=Peer, peer=self)
开发者ID:andregoiano,项目名称:pyethereum,代码行数:27,代码来源:peer.py

示例4: _recv_Status

    def _recv_Status(self, data):
        # [0x10: P, protocolVersion: P, networkID: P, totalDifficulty: P, latestHash: B_32, genesisHash: B_32]
        # check compatibility
        try:
            ethereum_protocol_version, network_id = idec(data[0]), idec(data[1])
            total_difficulty, head_hash, genesis_hash = idec(data[2]), data[3], data[4]
        except IndexError:
            return self.send_Disconnect(reason="Incompatible network protocols")

        logger.debug(
            "%r, received Status ETHPROTOCOL:%r TD:%d HEAD:%r GENESIS:%r",
            self,
            ethereum_protocol_version,
            total_difficulty,
            head_hash.encode("hex"),
            genesis_hash.encode("hex"),
        )

        if ethereum_protocol_version != packeter.ETHEREUM_PROTOCOL_VERSION:
            return self.send_Disconnect(reason="Incompatible network protocols")

        if network_id != packeter.NETWORK_ID:
            return self.send_Disconnect(reason="Wrong genesis block")

        if genesis_hash != blocks.genesis().hash:
            return self.send_Disconnect(reason="Wrong genesis block")

        self.status_received = True
        self.status_head_hash = head_hash
        self.status_total_difficulty = total_difficulty
        signals.peer_status_received.send(sender=Peer, peer=self)
开发者ID:miro-blakeley,项目名称:pyethereum,代码行数:31,代码来源:peer.py

示例5: _recv_Hello

    def _recv_Hello(self, data):
        # check compatibility
        peer_protocol_version = idec(data[0])

        logger.debug('received Hello protocol_version:{0:#04x}'.format(
                     peer_protocol_version))

        if peer_protocol_version != packeter.PROTOCOL_VERSION:
            return self.send_Disconnect(
                reason='Incompatible network protocols.'
                ' Expected:{0:#04x} received:{1:#04x}'.format(
                    packeter.PROTOCOL_VERSION, peer_protocol_version))

        if idec(data[1]) != packeter.NETWORK_ID:
            return self.send_Disconnect(reason='Wrong genesis block')

        # add to known peers list in handshake signal
        self.hello_received = True
        if len(data) == 6:
            self.node_id = data[5]
            self.port = idec(data[3]) # replace connection port with listen port

        # reply with hello if not send
        if not self.hello_sent:
            self.send_Hello()

        signals.peer_handshake_success.send(sender=Peer, peer=self)
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:27,代码来源:peer.py

示例6: dump_packet

def dump_packet(packet):
    try:
        header = idec(packet[:4])
        payload_len = idec(packet[4:8])
        data = lrlp_decode(packet[8:8 + payload_len])
        cmd = WireProtocol.cmd_map.get(
            idec(data[0]), 'unknown %s' % idec(data[0]))
        return [header, payload_len, cmd] + data[1:]
    except Exception as e:
        return ['DUMP failed', packet, e]
开发者ID:ConceptPending,项目名称:pyethereum,代码行数:10,代码来源:wire.py

示例7: _rcv_Hello

    def _rcv_Hello(self, peer, data):
        """
        [0x00, PROTOCOL_VERSION, NETWORK_ID, CLIENT_ID, CAPABILITIES,
        LISTEN_PORT, NODE_ID]
        First packet sent over the connection, and sent once by both sides.
        No other messages may be sent until a Hello is received.
        PROTOCOL_VERSION is one of:
            0x00 for PoC-1;
            0x01 for PoC-2;
            0x07 for PoC-3.
            0x08 sent by Ethereum(++)/v0.3.11/brew/Darwin/unknown
        NETWORK_ID should be 0.
        CLIENT_ID Specifies the client software identity, as a human-readable
            string (e.g. "Ethereum(++)/1.0.0").
        CAPABILITIES specifies the capabilities of the client as a set of
            flags; presently three bits are used:
            0x01 for peers discovery,
            0x02 for transaction relaying,
            0x04 for block-chain querying.
        LISTEN_PORT specifies the port that the client is listening on
            (on the interface that the present connection traverses).
            If 0 it indicates the client is not listening.
        NODE_ID is optional and specifies a 512-bit hash, (potentially to be
            used as public key) that identifies this node.
        """
        logger.debug(data[:-1] + [data[-1][20]])
        # check compatibility
        if idec(data[0]) != self.PROTOCOL_VERSION:
            return self.send_Disconnect(
                peer,
                reason='Incompatible network protocols')

        if idec(data[1]) != self.NETWORK_ID:
            return self.send_Disconnect(peer, reason='Wrong genesis block')

        """
        spec has CAPABILITIES after PORT, CPP client the other way round.
        emulating the latter, see  https://github.com/ethereum/cpp-ethereum
        /blob/master/libethereum/PeerNetwork.cpp#L144
        """

        # TODO add to known peers list
        peer.hello_received = True
        if len(data) == 6:
            peer.node_id = data[5]

        # reply with hello if not send
        if not peer.hello_sent:
            peer.send_packet(peer, self.packeter.dump_Hello())
            peer.hello_sent = True
开发者ID:brainbot-com,项目名称:pyethereum,代码行数:50,代码来源:wireprotocol.py

示例8: rcv_Hello

    def rcv_Hello(self, peer, data):
        """
        [0x00, PROTOCOL_VERSION, NETWORK_ID, CLIENT_ID, CAPABILITIES, LISTEN_PORT, NODE_ID]
        First packet sent over the connection, and sent once by both sides.
        No other messages may be sent until a Hello is received.
        PROTOCOL_VERSION is one of:
            0x00 for PoC-1;
            0x01 for PoC-2;
            0x07 for PoC-3.
            0x08 sent by Ethereum(++)/v0.3.11/brew/Darwin/unknown
        NETWORK_ID should be 0.
        CLIENT_ID Specifies the client software identity, as a human-readable string
                    (e.g. "Ethereum(++)/1.0.0").
        CAPABILITIES specifies the capabilities of the client as a set of flags;
                    presently three bits are used:
                    0x01 for peers discovery, 0x02 for transaction relaying, 0x04 for block-chain querying.
        LISTEN_PORT specifies the port that the client is listening on
                    (on the interface that the present connection traverses).
                    If 0 it indicates the client is not listening.
        NODE_ID is optional and specifies a 512-bit hash, (potentially to be used as public key)
                    that identifies this node.

        [574621841, 116, 'Hello', '\x08', '', 'Ethereum(++)/v0.3.11/brew/Darwin/unknown', '\x07', 'v_', "\xc5\xfe\xc6\xea\xe4TKvz\x9e\xdc\xa7\x01\xf6b?\x7fB\xe7\xfc(#t\xe9}\xafh\xf3Ot'\xe5u\x07\xab\xa3\xe5\x95\x14 |P\xb0C\xa2\xe4jU\xc8z|\x86\xa6ZV!Q6\x82\xebQ$4+"]
        [574621841, 27, 'Hello', '\x08', '\x00', 'Ethereum(py)/0.0.1', 'vb', '\x07']
        """

        # check compatibility
        if idec(data[0]) != self.PROTOCOL_VERSION:
            return self.send_Disconnect(
                peer,
                reason='Incompatible network protocols')

        if idec(data[1]) != self.NETWORK_ID:
            return self.send_Disconnect(peer, reason='Wrong genesis block')

        """
        spec has CAPABILITIES after PORT, CPP client the other way round. emulating the latter
        https://github.com/ethereum/cpp-ethereum/blob/master/libethereum/PeerNetwork.cpp#L144
        """

        # TODO add to known peers list
        peer.hello_received = True
        if len(data) == 6:
            peer.node_id = data[5]

        # reply with hello if not send
        if not peer.hello_sent:
            self.send_Hello(peer)
开发者ID:ConceptPending,项目名称:pyethereum,代码行数:48,代码来源:wire.py

示例9: _recv_Peers

 def _recv_Peers(self, data):
     for ip, port, pid in data:
         assert isinstance(ip, list)
         ip = '.'.join(str(ord(b or '\x00')) for b in ip)
         port = idec(port)
         logger.debug('received peer address: {0}:{1}'.format(ip, port))
         signals.new_peer_received.send((ip, port, pid))
开发者ID:jameservin,项目名称:pyethereum,代码行数:7,代码来源:peer.py

示例10: _recv_Peers

 def _recv_Peers(self, data):
     addresses = []
     for ip, port, pid in data:
         assert len(ip) == 4
         ip = '.'.join(str(ord(b)) for b in ip)
         port = idec(port)
         log_p2p.trace('received peer address', remote_id=self, ip=ip, port=port)
         addresses.append([ip, port, pid])
     signals.peer_addresses_received.send(sender=Peer, addresses=addresses)
开发者ID:ckeenan,项目名称:pyethereum,代码行数:9,代码来源:peer.py

示例11: _recv_Peers

 def _recv_Peers(self, data):
     addresses = []
     for ip, port, pid in data:
         assert len(ip) == 4
         ip = '.'.join(str(ord(b)) for b in ip)
         port = idec(port)
         logger.debug('received peer address: {0}:{1}'.format(ip, port))
         addresses.append([ip, port, pid])
     signals.peer_addresses_received.send(sender=Peer, addresses=addresses)
开发者ID:andregoiano,项目名称:pyethereum,代码行数:9,代码来源:peer.py

示例12: _recv_Disconnect

 def _recv_Disconnect(self, data):
     if len(data):
         reason = packeter.disconnect_reasons_map_by_id[idec(data[0])]
         forget = reason in self.reasons_to_forget
     else:
         forget = None
         reason = None
     log_p2p.debug('received disconnect', remote_id=self, reason=None)
     signals.peer_disconnect_requested.send(sender=Peer, remote_id=self, forget=forget)
开发者ID:ckeenan,项目名称:pyethereum,代码行数:9,代码来源:peer.py

示例13: _recv_Disconnect

 def _recv_Disconnect(self, data):
     if len(data):
         reason = packeter.disconnect_reasons_map_by_id[idec(data[0])]
         logger.info('%r received disconnect: %r', self, reason)
         forget = reason in self.reasons_to_forget
     else:
         forget = None
         logger.info('%r received disconnect: w/o reason', self)
     signals.peer_disconnect_requested.send(sender=Peer, peer=self, forget=forget)
开发者ID:Bitcoinzie,项目名称:pyethereum,代码行数:9,代码来源:peer.py

示例14: _recv_Disconnect

 def _recv_Disconnect(self, data):
     if len(data):
         reason = packeter.disconnect_reasons_map_by_id[idec(data[0])]
         logger.info('{0} sent disconnect, {1} '.format(repr(self), reason))
         forget = reason in self.reasons_to_forget
     else:
         forget = None
     signals.peer_disconnect_requested.send(
             sender=Peer, peer=self, forget=forget)
开发者ID:andregoiano,项目名称:pyethereum,代码行数:9,代码来源:peer.py

示例15: rcv_packet

    def rcv_packet(self, peer, packet):
        """
        Though TCP provides a connection-oriented medium, Ethereum nodes communicate
        in terms of packets. These packets are formed as a 4-byte synchronisation token
        (0x22400891), a 4-byte "payload size", to be interpreted as a big-endian integer
        and finally an N-byte RLP-serialised data structure, where N is the aforementioned
        "payload size". To be clear, the payload size specifies the number of bytes in the
        packet ''following'' the first 8.
        """

        # check header
        if not idec(packet[:4]) == self.SYNCHRONIZATION_TOKEN:
            logger.warn('check header failed, skipping message, sync token was {0}'
                        .format(idec(packet[:4])))
            return

        # unpack message
        payload_len = idec(packet[4:8])
        # assert 8 + payload_len <= len(packet) # this get's sometimes raised!?
        data = lrlp_decode(packet[8:8 + payload_len])

        # check cmd
        if (not len(data)) or (idec(data[0]) not in self.cmd_map):
            logger.warn('check cmd failed')
            return self.send_Disconnect(peer, reason='Bad protocol')

        # good peer
        peer.last_valid_packet_received = time.time()

        cmd_id = idec(data.pop(0))
        func_name = "rcv_%s" % self.cmd_map[cmd_id]
        if not hasattr(self, func_name):
            logger.warn('unknown cmd \'{0}\''.format(func_name))
            return
            """
            return self.send_Disconnect(
                peer,
                reason='Incompatible network protocols')
            raise NotImplementedError('%s not implmented')
            """
        # check Hello was sent

        # call the correspondig method
        return getattr(self, func_name)(peer, data)
开发者ID:ConceptPending,项目名称:pyethereum,代码行数:44,代码来源:wire.py


注:本文中的utils.idec函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。