Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@dispatch.receiver(signals.config_ready)
def config_packeter(sender, config, **kwargs):
packeter.configure(config)
@receiver(signals.local_transaction_received)
def local_transaction_received_handler(sender, transaction, **kwargs):
"receives transaction object"
logger.debug('local_transaction_received: %r', transaction)
chain_manager.add_transaction(transaction)
@receiver(signals.peer_addresses_received)
def peer_addresses_received_handler(sender, addresses, **kwargs):
''' addresses should be (ip, port, node_id)
'''
for ip, port, node_id in addresses:
peer_manager.add_known_peer_address(ip, port, node_id)
peer_manager.save_peers()
@receiver(signals.local_chain_requested)
def handle_local_chain_requested(sender, peer, block_hashes, count, **kwargs):
"""
[0x14, Parent1, Parent2, ..., ParentN, Count]
Request the peer to send Count (to be interpreted as an integer) blocks
in the current canonical block chain that are children of Parent1
(to be interpreted as a SHA3 block hash). If Parent1 is not present in
the block chain, it should instead act as if the request were for Parent2
&c. through to ParentN.
If none of the parents are in the current
canonical block chain, then NotInChain should be sent along with ParentN
(i.e. the last Parent in the parents list).
If the designated parent is the present block chain head,
an empty reply should be sent.
@receiver(signals.getpeers_received)
def getaddress_received_handler(sender, peer, **kwargs):
with peer_manager.lock:
peers = peer_manager.get_known_peer_addresses()
assert is_valid_ip(peer_manager.local_ip)
peers.add((peer_manager.local_ip,
peer_manager.local_port,
peer_manager.local_node_id))
peer.send_Peers(peers)
@receiver(signals.remote_blocks_received)
def remote_blocks_received_handler(sender, transient_blocks, peer, **kwargs):
logger.debug("recv %d remote blocks: %r", len(
transient_blocks), transient_blocks)
if transient_blocks:
chain_manager.receive_chain(transient_blocks, peer)
@receiver(signals.config_ready)
def config_chainmanager(sender, config, **kwargs):
chain_manager.configure(config)
@receiver(signals.peer_disconnect_requested)
def disconnect_requested_handler(sender, peer, forget=False, **kwargs):
peer_manager.remove_peer(peer)
if forget:
ipn = (peer.ip, peer.port, peer.node_id)
if ipn in peer_manager._known_peers:
peer_manager.remove_known_peer_address(*ipn)
peer_manager.save_peers()
@receiver(signals.peer_connection_accepted)
def connection_accepted_handler(sender, connection, ip, port, **kwargs):
peer_manager.add_peer(connection, ip, port)
@receiver(signals.config_ready)
def config_tcp_server(sender, config, **kwargs):
tcp_server.configure(config)