Compare commits

...

5 commits

Author SHA1 Message Date
hackrush
b110ab84fb
Removed more stuff 2019-03-26 23:05:43 +05:30
hackrush
dc209e6b8f
Minimum changes needed to support Named Pipes 2019-03-26 23:03:13 +05:30
hackrush
c703f8bbe6
Something at least 2019-03-14 08:54:33 +05:30
hackrush
e6240b14ee Using NamedPipeSite(aiohttp, not committed) 2019-02-25 12:39:44 +05:30
hackrush
0b032c5346 This will blow your computer wala WIP!!! 2019-02-25 00:07:31 +05:30
3 changed files with 36 additions and 3 deletions

View file

@ -29,6 +29,14 @@ HEADERS_FILE_SHA256_CHECKSUM = (
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]):

View file

@ -13,7 +13,7 @@ from aiohttp.web import GracefulExit
from lbrynet import __name__ as lbrynet_name, __version__ as lbrynet_version
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
log = logging.getLogger(lbrynet_name)
@ -25,7 +25,11 @@ def display(data):
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:
message = {'method': method, 'params': params}
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):
if sys.platform == 'win32' and IS_THE_SPECIAL_CYTHON_PR_MERGED:
asyncio.set_event_loop(asyncio.ProactorEventLoop())
argv = argv or sys.argv[1:]
parser = get_argument_parser()
args, command_args = parser.parse_known_args(argv)

View file

@ -1,4 +1,5 @@
import os
import sys
import asyncio
import logging
import json
@ -16,7 +17,7 @@ from functools import wraps
from torba.client.baseaccount import SingleKey, HierarchicalDeterministic
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_exchange.downloader import download_blob
from lbrynet.error import InsufficientFundsError, DownloadSDTimeout, ComponentsNotStarted
@ -262,6 +263,7 @@ class Daemon(metaclass=JSONRPCServerType):
logging.getLogger('aiohttp.access').setLevel(logging.WARN)
app = web.Application()
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('/', self.handle_old_jsonrpc)
self.runner = web.AppRunner(app)
@ -382,6 +384,19 @@ class Daemon(metaclass=JSONRPCServerType):
await self.update_connection_status()
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):
log.info("Starting LBRYNet Daemon")
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.runner.setup()
if sys.platform == "win32" and IS_THE_SPECIAL_CYTHON_PR_MERGED:
await self.start_named_pipe_server()
try:
site = web.TCPSite(self.runner, self.conf.api_host, self.conf.api_port)
await site.start()