Compare commits
5 commits
master
...
named-pipe
Author | SHA1 | Date | |
---|---|---|---|
|
b110ab84fb | ||
|
dc209e6b8f | ||
|
c703f8bbe6 | ||
|
e6240b14ee | ||
|
0b032c5346 |
3 changed files with 36 additions and 3 deletions
|
@ -29,6 +29,14 @@ HEADERS_FILE_SHA256_CHECKSUM = (
|
||||||
366295, 'b0c8197153a33ccbc52fb81a279588b6015b68b7726f73f6a2b81f7e25bfe4b9'
|
366295, 'b0c8197153a33ccbc52fb81a279588b6015b68b7726f73f6a2b81f7e25bfe4b9'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if sys.platform == "win32":
|
||||||
|
PIPE_NAME = r'\\.\pipe\lbrypipe'
|
||||||
|
else:
|
||||||
|
PIPE_NAME = './lbrypipe'
|
||||||
|
|
||||||
|
|
||||||
|
IS_THE_SPECIAL_CYTHON_PR_MERGED = True
|
||||||
|
|
||||||
|
|
||||||
class Setting(typing.Generic[T]):
|
class Setting(typing.Generic[T]):
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ from aiohttp.web import GracefulExit
|
||||||
|
|
||||||
from lbrynet import __name__ as lbrynet_name, __version__ as lbrynet_version
|
from lbrynet import __name__ as lbrynet_name, __version__ as lbrynet_version
|
||||||
from lbrynet.extras.daemon.loggly_handler import get_loggly_handler
|
from lbrynet.extras.daemon.loggly_handler import get_loggly_handler
|
||||||
from lbrynet.conf import Config, CLIConfig
|
from lbrynet.conf import Config, CLIConfig, PIPE_NAME, IS_THE_SPECIAL_CYTHON_PR_MERGED
|
||||||
from lbrynet.extras.daemon.Daemon import Daemon
|
from lbrynet.extras.daemon.Daemon import Daemon
|
||||||
|
|
||||||
log = logging.getLogger(lbrynet_name)
|
log = logging.getLogger(lbrynet_name)
|
||||||
|
@ -25,7 +25,11 @@ def display(data):
|
||||||
|
|
||||||
|
|
||||||
async def execute_command(conf, method, params):
|
async def execute_command(conf, method, params):
|
||||||
async with aiohttp.ClientSession() as session:
|
conn = None
|
||||||
|
if sys.platform == "win32" and IS_THE_SPECIAL_CYTHON_PR_MERGED:
|
||||||
|
conn = aiohttp.NamedPipeConnector(path=PIPE_NAME)
|
||||||
|
|
||||||
|
async with aiohttp.ClientSession(connector=conn) as session:
|
||||||
try:
|
try:
|
||||||
message = {'method': method, 'params': params}
|
message = {'method': method, 'params': params}
|
||||||
async with session.get(conf.api_connection_url, json=message) as resp:
|
async with session.get(conf.api_connection_url, json=message) as resp:
|
||||||
|
@ -224,6 +228,9 @@ def ensure_directory_exists(path: str):
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
|
if sys.platform == 'win32' and IS_THE_SPECIAL_CYTHON_PR_MERGED:
|
||||||
|
asyncio.set_event_loop(asyncio.ProactorEventLoop())
|
||||||
|
|
||||||
argv = argv or sys.argv[1:]
|
argv = argv or sys.argv[1:]
|
||||||
parser = get_argument_parser()
|
parser = get_argument_parser()
|
||||||
args, command_args = parser.parse_known_args(argv)
|
args, command_args = parser.parse_known_args(argv)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
@ -16,7 +17,7 @@ from functools import wraps
|
||||||
from torba.client.baseaccount import SingleKey, HierarchicalDeterministic
|
from torba.client.baseaccount import SingleKey, HierarchicalDeterministic
|
||||||
|
|
||||||
from lbrynet import __version__, utils
|
from lbrynet import __version__, utils
|
||||||
from lbrynet.conf import Config, Setting, SLACK_WEBHOOK
|
from lbrynet.conf import Config, Setting, PIPE_NAME, IS_THE_SPECIAL_CYTHON_PR_MERGED
|
||||||
from lbrynet.blob.blob_file import is_valid_blobhash
|
from lbrynet.blob.blob_file import is_valid_blobhash
|
||||||
from lbrynet.blob_exchange.downloader import download_blob
|
from lbrynet.blob_exchange.downloader import download_blob
|
||||||
from lbrynet.error import InsufficientFundsError, DownloadSDTimeout, ComponentsNotStarted
|
from lbrynet.error import InsufficientFundsError, DownloadSDTimeout, ComponentsNotStarted
|
||||||
|
@ -262,6 +263,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
logging.getLogger('aiohttp.access').setLevel(logging.WARN)
|
logging.getLogger('aiohttp.access').setLevel(logging.WARN)
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
app.router.add_get('/lbryapi', self.handle_old_jsonrpc)
|
app.router.add_get('/lbryapi', self.handle_old_jsonrpc)
|
||||||
|
app.router.add_get('/', self.handle_old_jsonrpc)
|
||||||
app.router.add_post('/lbryapi', self.handle_old_jsonrpc)
|
app.router.add_post('/lbryapi', self.handle_old_jsonrpc)
|
||||||
app.router.add_post('/', self.handle_old_jsonrpc)
|
app.router.add_post('/', self.handle_old_jsonrpc)
|
||||||
self.runner = web.AppRunner(app)
|
self.runner = web.AppRunner(app)
|
||||||
|
@ -382,6 +384,19 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
await self.update_connection_status()
|
await self.update_connection_status()
|
||||||
return CONNECTION_STATUS_CONNECTED if self._connection_status[1] else CONNECTION_STATUS_NETWORK
|
return CONNECTION_STATUS_CONNECTED if self._connection_status[1] else CONNECTION_STATUS_NETWORK
|
||||||
|
|
||||||
|
async def start_named_pipe_server(self) -> None:
|
||||||
|
try:
|
||||||
|
print(asyncio.get_event_loop())
|
||||||
|
site = web.NamedPipeSite(self.runner, PIPE_NAME)
|
||||||
|
await site.start()
|
||||||
|
log.info('lbrynet API listening on pipe %s', site.name)
|
||||||
|
except (PermissionError, RuntimeError) as e:
|
||||||
|
log.error('lbrynet API failed to open Named Pipe %s for listening. Daemon is already running '
|
||||||
|
'or this Named Pipe is being used by another application.', PIPE_NAME)
|
||||||
|
log.error(str(e))
|
||||||
|
# await self.analytics_manager.send_server_startup_error(str(e))
|
||||||
|
raise SystemExit()
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
log.info("Starting LBRYNet Daemon")
|
log.info("Starting LBRYNet Daemon")
|
||||||
log.debug("Settings: %s", json.dumps(self.conf.settings_dict, indent=2))
|
log.debug("Settings: %s", json.dumps(self.conf.settings_dict, indent=2))
|
||||||
|
@ -389,6 +404,9 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
await self.analytics_manager.send_server_startup()
|
await self.analytics_manager.send_server_startup()
|
||||||
await self.runner.setup()
|
await self.runner.setup()
|
||||||
|
|
||||||
|
if sys.platform == "win32" and IS_THE_SPECIAL_CYTHON_PR_MERGED:
|
||||||
|
await self.start_named_pipe_server()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
site = web.TCPSite(self.runner, self.conf.api_host, self.conf.api_port)
|
site = web.TCPSite(self.runner, self.conf.api_host, self.conf.api_port)
|
||||||
await site.start()
|
await site.start()
|
||||||
|
|
Loading…
Add table
Reference in a new issue