Onionr/static-data/default-plugins/torgossip/clientfuncs/__init__.py

29 lines
827 B
Python
Raw Normal View History

2021-02-08 07:32:31 +00:00
from typing import TYPE_CHECKING
2021-02-09 23:02:19 +00:00
import sys
import os
import logger
from blockio import store_block, subprocvalidate
import onionrblocks
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
from commands import GossipCommands
2021-02-08 07:32:31 +00:00
if TYPE_CHECKING:
from socket import socket
2021-02-09 23:02:19 +00:00
def download_blocks(sock: 'socket', offset: int, block_type: str):
sock.sendall(
2021-02-15 09:11:16 +00:00
str(int(GossipCommands.LIST_BLOCKS_BY_TYPE_OFFSET)).encode('utf-8') + str(offset).encode('utf-8') + b',' +
2021-02-09 23:02:19 +00:00
block_type.encode('utf-8'))
bl_hashs = sock.recv(600000)
hash = None
for i in range(len(bl_hashs)//64):
2021-02-15 09:11:16 +00:00
hash = bl_hashs[:(i*64) + 64]
2021-02-09 23:02:19 +00:00
sock.sendall(
2021-02-15 09:11:16 +00:00
str(int(GossipCommands.GET_BLOCK)).encode('utf-8') + hash)
2021-02-09 23:02:19 +00:00
bl_content = sock.recv(10**6)
2021-02-15 09:11:16 +00:00
print('got block', bl_content)
2021-02-09 23:02:19 +00:00