Start working on local api

This commit is contained in:
Mariano Sorgente
2019-11-25 10:16:56 +09:00
parent 493cb4aab2
commit 70ccca0ba9
5 changed files with 92 additions and 5 deletions
+1
View File
@@ -10,6 +10,7 @@ __pycache__/
# Database
nohup.out
mongod.log
# Keys and plot files
config/keys.yaml
-4
View File
@@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
+3
View File
@@ -175,11 +175,14 @@ class FullNode:
async def introducer_client():
async def on_connect():
log.info("on connect")
msg = Message("request_peers", peer_protocol.RequestPeers())
yield OutboundMessage(NodeType.INTRODUCER, msg, Delivery.RESPOND)
while not self._shut_down:
log.info("looping")
if self._num_needed_peers():
log.info("Conncting")
if not await self.server.start_client(
introducer_peerinfo, on_connect
):
+87
View File
@@ -0,0 +1,87 @@
from dataclasses import dataclass
from typing import List
from src.types.full_block import FullBlock
from src.types.header_block import HeaderBlock
from src.types.peer_info import PeerInfo
from src.server.connection import NodeType
from src.util.cbor_message import cbor_message
from src.types.sized_bytes import bytes32
from src.util.ints import uint16, uint64
@dataclass(frozen=True)
@cbor_message
class StopNodeRequest:
pass
@dataclass(frozen=True)
@cbor_message
class StopNodeResponse:
pass
@dataclass(frozen=True)
@cbor_message
class GetConnectionsRequest:
pass
@dataclass(frozen=True)
@cbor_message
class GetConnectionsResponse:
peer_info: PeerInfo
node_type: NodeType
node_id: bytes32
@dataclass(frozen=True)
@cbor_message
class AddConnectionRequest:
host: str
port: uint16
@dataclass(frozen=True)
@cbor_message
class AddConnectionResponse:
pass
@dataclass(frozen=True)
@cbor_message
class GetBlockchainInfoRequest:
pass
@dataclass(frozen=True)
@cbor_message
class GetBlockchainInfoResponse:
lca_header_hash: bytes32
next_difficulty: uint64
next_ips: uint64
tips_header_hashes: List[bytes32]
@dataclass(frozen=True)
@cbor_message
class GetBlockRequest:
header_hash: bytes32
@dataclass(frozen=True)
@cbor_message
class GetBlockResponse:
block: FullBlock
@dataclass(frozen=True)
@cbor_message
class GetHeaderBlockRequest:
header_hash: bytes32
@dataclass(frozen=True)
@cbor_message
class GetHeaderBlockResponse:
header_block: HeaderBlock
+1 -1
View File
@@ -131,7 +131,7 @@ class ChiaServer:
asyncio.TimeoutError,
) as e:
log.warning(
f"Could not connct to {target_node}. {type(e)}{e}. Retrying."
f"Could not connect to {target_node}. {type(e)}{e}. Retrying."
)
open_con_task.cancel()
await asyncio.sleep(RETRY_INTERVAL)