Skip to content
Snippets Groups Projects
Commit a9d8ab0a authored by Vincent Texier's avatar Vincent Texier
Browse files

[fix] add missing network/peers bma request as network.peers (BREAK BC!)

peering/peers was wrapped under "network.peers" to simplify peering/peers requests.
But now, with this new request, peering/peers becomes "network.peering_peers"
parent 2fd1fa38
No related branches found
No related tags found
2 merge requests!128Release 0.62.0,!121Helper available nodes
...@@ -25,6 +25,41 @@ logger = logging.getLogger("duniter/network") ...@@ -25,6 +25,41 @@ logger = logging.getLogger("duniter/network")
MODULE = "network" MODULE = "network"
PEERS_SCHEMA = {
"type": "object",
"properties": {
"peers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"version": {"type": ["number", "string"]},
"currency": {"type": "string"},
"status": {"type": "string"},
"first_down": {"type": ["null", "integer"]},
"last_try": {"type": ["null", "integer"]},
"pubkey": {"type": "string"},
"block": {"type": "string"},
"signature": {"type": "string"},
"endpoints": {"type": "array", "items": {"type": "string"}},
},
"required": [
"version",
"currency",
"status",
"first_down",
"last_try",
"pubkey",
"block",
"signature",
"endpoints",
],
},
}
},
"required": ["peers"],
}
PEERING_SCHEMA = { PEERING_SCHEMA = {
"type": "object", "type": "object",
"properties": { "properties": {
...@@ -37,7 +72,7 @@ PEERING_SCHEMA = { ...@@ -37,7 +72,7 @@ PEERING_SCHEMA = {
"required": ["version", "currency", "pubkey", "endpoints", "signature"], "required": ["version", "currency", "pubkey", "endpoints", "signature"],
} }
PEERS_SCHEMA = schema = { PEERING_PEERS_SCHEMA = {
"type": ["object"], "type": ["object"],
"properties": { "properties": {
"depth": {"type": "number"}, "depth": {"type": "number"},
...@@ -85,6 +120,17 @@ WS2P_HEADS_SCHEMA = { ...@@ -85,6 +120,17 @@ WS2P_HEADS_SCHEMA = {
} }
async def peers(client: Client) -> dict:
"""
GET the exhaustive list of peers known by the node
:param client: Client to connect to the api
:return:
"""
return await client.get(MODULE + "/peers", schema=PEERS_SCHEMA)
async def peering(client: Client) -> dict: async def peering(client: Client) -> dict:
""" """
GET peering information about a peer GET peering information about a peer
...@@ -95,7 +141,7 @@ async def peering(client: Client) -> dict: ...@@ -95,7 +141,7 @@ async def peering(client: Client) -> dict:
return await client.get(MODULE + "/peering", schema=PEERING_SCHEMA) return await client.get(MODULE + "/peering", schema=PEERING_SCHEMA)
async def peers(client: Client, leaves: bool = False, leaf: str = "") -> dict: async def peering_peers(client: Client, leaves: bool = False, leaf: str = "") -> dict:
""" """
GET peering entries of every node inside the currency network GET peering entries of every node inside the currency network
...@@ -106,11 +152,11 @@ async def peers(client: Client, leaves: bool = False, leaf: str = "") -> dict: ...@@ -106,11 +152,11 @@ async def peers(client: Client, leaves: bool = False, leaf: str = "") -> dict:
""" """
if leaves is True: if leaves is True:
response = await client.get( response = await client.get(
MODULE + "/peering/peers", {"leaves": "true"}, schema=PEERS_SCHEMA MODULE + "/peering/peers", {"leaves": "true"}, schema=PEERING_PEERS_SCHEMA
) )
else: else:
response = await client.get( response = await client.get(
MODULE + "/peering/peers", {"leaf": leaf}, schema=PEERS_SCHEMA MODULE + "/peering/peers", {"leaf": leaf}, schema=PEERING_PEERS_SCHEMA
) )
return response return response
......
...@@ -27,6 +27,32 @@ from tests.api.webserver import WebFunctionalSetupMixin, web ...@@ -27,6 +27,32 @@ from tests.api.webserver import WebFunctionalSetupMixin, web
class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase): class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase):
def test_peers(self):
json_sample = {
"peers": [
{
"version": "1",
"currency": "beta_brouzouf",
"status": "UP",
"first_down": None,
"last_try": 1607180847,
"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY",
"block": "378529-00028D6F71E384565A1A106C1247E5F4B0392645A84EDB121173AC930540D552",
"signature": "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r",
"endpoints": [
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9001",
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9002",
"OTHER_PROTOCOL 88.77.66.55 9001",
],
}
]
}
try:
jsonschema.validate(json_sample, network.PEERS_SCHEMA)
except (SchemaError, ValidationError) as e:
raise self.failureException from e
def test_peering(self): def test_peering(self):
json_sample = { json_sample = {
"version": "1", "version": "1",
...@@ -58,7 +84,7 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase): ...@@ -58,7 +84,7 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase):
self.loop.run_until_complete(go()) self.loop.run_until_complete(go())
def test_peers_root(self): def test_peering_peers_root(self):
json_sample = { json_sample = {
"depth": 3, "depth": 3,
"nodesCount": 6, "nodesCount": 6,
...@@ -66,11 +92,11 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase): ...@@ -66,11 +92,11 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase):
"root": "114B6E61CB5BB93D862CA3C1DFA8B99E313E66E9", "root": "114B6E61CB5BB93D862CA3C1DFA8B99E313E66E9",
} }
try: try:
jsonschema.validate(json_sample, network.PEERS_SCHEMA) jsonschema.validate(json_sample, network.PEERING_PEERS_SCHEMA)
except (SchemaError, ValidationError) as e: except (SchemaError, ValidationError) as e:
raise self.failureException from e raise self.failureException from e
def test_peers_leaf(self): def test_peering_peers_leaf(self):
json_sample = { json_sample = {
"hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", "hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C",
"value": { "value": {
...@@ -86,11 +112,11 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase): ...@@ -86,11 +112,11 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase):
}, },
} }
try: try:
jsonschema.validate(json_sample, network.PEERS_SCHEMA) jsonschema.validate(json_sample, network.PEERING_PEERS_SCHEMA)
except (SchemaError, ValidationError) as e: except (SchemaError, ValidationError) as e:
raise self.failureException from e raise self.failureException from e
def test_peers_bad(self): def test_peering_peers_bad(self):
async def handler(request): async def handler(request):
await request.read() await request.read()
return web.Response(body=b"{}", content_type="application/json") return web.Response(body=b"{}", content_type="application/json")
...@@ -101,7 +127,7 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase): ...@@ -101,7 +127,7 @@ class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase):
) )
with self.assertRaises(jsonschema.exceptions.ValidationError): with self.assertRaises(jsonschema.exceptions.ValidationError):
client = Client(BMAEndpoint("127.0.0.1", "", "", port)) client = Client(BMAEndpoint("127.0.0.1", "", "", port))
await client(network.peers) await client(network.peering_peers)
await client.close() await client.close()
self.loop.run_until_complete(go()) self.loop.run_until_complete(go())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment