1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-19 02:17:38 +03:00

Added fake EDDN Listener

A simple HTTP handler has been added that will dump any and all POST
data it gets to EDMC's log.

Additionally, a new command line argument to switch EDMC to using this
as its EDDN target has been added.
This commit is contained in:
A_D 2021-05-21 09:10:26 +02:00
parent 108205458b
commit 4ef153b1b2
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4
4 changed files with 49 additions and 1 deletions

View File

@ -93,6 +93,8 @@ if __name__ == '__main__': # noqa: C901
action='store_true'
)
parser.add_argument('--eddn-local', help='Redirect EDDN requests to a local webserver', action='store_true')
auth_options = parser.add_mutually_exclusive_group(required=False)
auth_options.add_argument('--force-localserver-for-auth',
help='Force EDMC to use a localhost webserver for Frontier Auth callback',
@ -129,6 +131,12 @@ if __name__ == '__main__': # noqa: C901
parser.print_help()
exit(1)
if args.eddn_local:
import eddnListener
import edmc_data
eddnListener.run_listener()
edmc_data.EDDN_DEBUG_SERVER = True
def handle_edmc_callback_or_foregrounding() -> None: # noqa: CCR001
"""Handle any edmc:// auth callback, else foreground existing window."""
logger.trace('Begin...')

34
eddnListener.py Normal file
View File

@ -0,0 +1,34 @@
"""Simple HTTP listener to be used with debugging EDDN sends."""
import threading
from http import server
from typing import Any
from EDMCLogging import get_main_logger
logger = get_main_logger()
class LoggingHandler(server.BaseHTTPRequestHandler):
"""HTTP Handler implementation that logs to EDMCs logger."""
def log_message(self, format: str, *args: Any) -> None:
"""Override default handler logger with EDMC logger."""
logger.info(format % args)
def do_POST(self) -> None: # noqa: N802 # I cant change it
"""Handle POST."""
logger.info("Received a POST!")
data = self.rfile.read(int(self.headers['Content-Length']))
logger.info(f"POST DATA FOLLOWS\n{data.decode('utf-8', errors='replace')}")
self.send_response(200, "OK")
def run_listener(port: int = 9090) -> None:
"""Run a listener thread."""
logger.info('Starting HTTP listener on 127.0.0.1:{port}!')
listener = server.HTTPServer(("127.0.0.1", port), LoggingHandler)
threading.Thread(target=listener.serve_forever, daemon=True)
if __name__ == "__main__":
server.HTTPServer(("127.0.0.1", 8080), LoggingHandler).serve_forever()

View File

@ -570,3 +570,5 @@ edmc_suit_symbol_localised = {
'utilitysuit': 'Traje Maverick',
},
}
EDDN_DEBUG_SERVER = False # Are we using a local server for debugging?

View File

@ -19,6 +19,7 @@ import requests
import killswitch
import myNotebook as nb # noqa: N813
import plug
import edmc_data
from companion import CAPIData, category_map
from config import applongname, appversion_nobuild, config
from EDMCLogging import get_main_logger
@ -87,9 +88,12 @@ HORIZ_SKU = 'ELITE_HORIZONS_V_PLANETARY_LANDINGS'
class EDDN:
"""EDDN Data export."""
# SERVER = 'http://localhost:8081' # testing
SERVER = 'https://eddn.edcd.io:4430'
if edmc_data.EDDN_DEBUG_SERVER:
SERVER = '127.0.0.1:9090'
UPLOAD = f'{SERVER}/upload/'
REPLAYPERIOD = 400 # Roughly two messages per second, accounting for send delays [ms]
REPLAYFLUSH = 20 # Update log on disk roughly every 10 seconds
TIMEOUT = 10 # requests timeout