finished block list endpoint for lan and added get data endpoint
This commit is contained in:
parent
e90d7e96f4
commit
d4f4487fb6
@ -7,11 +7,13 @@ from flask import Flask
|
|||||||
from flask import Response
|
from flask import Response
|
||||||
from gevent import sleep
|
from gevent import sleep
|
||||||
|
|
||||||
|
from onionrblocks.onionrblockapi import Block
|
||||||
from httpapi.fdsafehandler import FDSafeHandler
|
from httpapi.fdsafehandler import FDSafeHandler
|
||||||
from netcontroller import get_open_port
|
from netcontroller import get_open_port
|
||||||
import config
|
import config
|
||||||
from coredb.blockmetadb import get_block_list
|
from coredb.blockmetadb import get_block_list
|
||||||
from lan.getip import lan_ips, best_ip
|
from lan.getip import lan_ips, best_ip
|
||||||
|
from onionrutils import stringvalidators
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -40,7 +42,13 @@ class LANServer:
|
|||||||
|
|
||||||
@app.route('/blist/<time>')
|
@app.route('/blist/<time>')
|
||||||
def get_block_list_for_lan(time):
|
def get_block_list_for_lan(time):
|
||||||
return Response(get_block_list(dateRec=time).split('\n'))
|
return Response('\n'.join(get_block_list(dateRec=time)))
|
||||||
|
|
||||||
|
@app.route('/get/<block>')
|
||||||
|
def get_block_data(block):
|
||||||
|
if not stringvalidators.validate_hash(block):
|
||||||
|
raise ValueError
|
||||||
|
return Response(Block(block).raw, mimetype='application/octet-stream')
|
||||||
|
|
||||||
@app.route("/ping")
|
@app.route("/ping")
|
||||||
def ping():
|
def ping():
|
||||||
|
@ -2,11 +2,18 @@ import requests
|
|||||||
|
|
||||||
from lan.getip import best_ip
|
from lan.getip import best_ip
|
||||||
|
|
||||||
|
from onionrblocks import insert, onionrblockapi
|
||||||
|
|
||||||
def test_lan_server(testmanager):
|
def test_lan_server(testmanager):
|
||||||
|
|
||||||
for i in range(1024, 65536):
|
for i in range(1024, 65536):
|
||||||
try:
|
try:
|
||||||
if requests.get(f"http://{best_ip}:{i}/ping").text == 'pong!':
|
if requests.get(f"http://{best_ip}:{i}/ping").text == 'pong!':
|
||||||
|
bl = insert('test data')
|
||||||
|
if bl not in requests.get(f"http://{best_ip}:{i}/blist/0").text:
|
||||||
|
raise ValueError
|
||||||
|
if onionrblockapi.Block(bl).raw != requests.get(f"http://{best_ip}:{i}/get/{bl}").content:
|
||||||
|
raise ValueError
|
||||||
break
|
break
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user