mirror of https://github.com/nucypher/nucypher.git
Add ping endpoint for checking if an Ursula is accessible from another Ursula
parent
e0233dc8ac
commit
b21fea8023
|
@ -21,18 +21,15 @@ import ssl
|
|||
|
||||
import requests
|
||||
import time
|
||||
from bytestring_splitter import BytestringSplitter, VariableLengthBytestring
|
||||
from constant_sorrow.constants import CERTIFICATE_NOT_SAVED, EXEMPT_FROM_VERIFICATION
|
||||
|
||||
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from twisted.logger import Logger
|
||||
|
||||
from umbral.cfrags import CapsuleFrag
|
||||
from umbral.signing import Signature
|
||||
|
||||
from bytestring_splitter import BytestringSplitter, VariableLengthBytestring
|
||||
|
||||
|
||||
EXEMPT_FROM_VERIFICATION.bool_value(False)
|
||||
|
||||
|
||||
|
@ -234,6 +231,22 @@ class RestMiddleware:
|
|||
path=f"kFrag/{id_as_hex}/reencrypt",
|
||||
data=payload, timeout=2)
|
||||
|
||||
def node_information(self, host, port, certificate_filepath=None):
|
||||
response = self.client.get(host=host, port=port,
|
||||
path="public_information",
|
||||
timeout=2,
|
||||
certificate_filepath=certificate_filepath)
|
||||
return response.content
|
||||
|
||||
def ping(self, host, port, certificate_filepath=None):
|
||||
response = self.client.get(host=host, port=port,
|
||||
path="ping",
|
||||
timeout=2,
|
||||
certificate_filepath=certificate_filepath)
|
||||
if response.status_code != 200:
|
||||
raise RuntimeError("Your node could not successfully be pinged from the remote node.")
|
||||
return True
|
||||
|
||||
def get_nodes_via_rest(self,
|
||||
node,
|
||||
announce_nodes=None,
|
||||
|
|
|
@ -19,14 +19,18 @@ import binascii
|
|||
import os
|
||||
from typing import Tuple
|
||||
|
||||
import requests
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
from constant_sorrow import constants
|
||||
from constant_sorrow.constants import FLEET_STATES_MATCH, NO_KNOWN_NODES, NO_BLOCKCHAIN_CONNECTION
|
||||
from flask import Flask, Response, jsonify
|
||||
from flask import request
|
||||
from constant_sorrow.constants import FLEET_STATES_MATCH, NO_KNOWN_NODES
|
||||
from constant_sorrow.constants import NO_BLOCKCHAIN_CONNECTION
|
||||
from flask import Flask, Response, request
|
||||
from flask import jsonify
|
||||
from hendrix.experience import crosstown_traffic
|
||||
from jinja2 import Template, TemplateError
|
||||
from twisted.logger import Logger
|
||||
from umbral.keys import UmbralPublicKey
|
||||
from umbral.kfrags import KFrag
|
||||
from web3.exceptions import TimeExhausted
|
||||
|
||||
import nucypher
|
||||
|
@ -41,8 +45,6 @@ from nucypher.datastore.threading import ThreadedSession
|
|||
from nucypher.network import LEARNING_LOOP_VERSION
|
||||
from nucypher.network.exceptions import NodeSeemsToBeDown
|
||||
from nucypher.network.protocols import InterfaceInfo
|
||||
from umbral.keys import UmbralPublicKey
|
||||
from umbral.kfrags import KFrag
|
||||
|
||||
HERE = BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
TEMPLATES_DIR = os.path.join(HERE, "templates")
|
||||
|
@ -121,6 +123,26 @@ def make_rest_app(
|
|||
|
||||
return response
|
||||
|
||||
@rest_app.route("/ping")
|
||||
def ping():
|
||||
"""
|
||||
Returns network information about the accessor's connection to
|
||||
the node.
|
||||
TODO: Parameterize the port.
|
||||
TODO: Fix certificate verification check so we don't pass verify=False
|
||||
TODO: Figure out how to test this.
|
||||
"""
|
||||
node_ip = request.environ['REMOTE_ADDR']
|
||||
|
||||
try:
|
||||
result = requests.get(f"https://{node_ip}:9151/public_information", verify=False)
|
||||
except requests.exceptions.ConnectionError:
|
||||
return Response(status=400)
|
||||
|
||||
if result.status_code != 200:
|
||||
return Response(status=400)
|
||||
return Response(status=200)
|
||||
|
||||
@rest_app.route('/node_metadata', methods=["GET"])
|
||||
def all_known_nodes():
|
||||
headers = {'Content-Type': 'application/octet-stream'}
|
||||
|
|
Loading…
Reference in New Issue