Hook-up JSON-IPC to Character CLI action entry points

pull/821/head
Kieran Prasch 2019-03-12 19:34:37 -07:00
parent 92b7a62d3a
commit ef088d8f31
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
6 changed files with 27 additions and 7 deletions

View File

@ -480,5 +480,4 @@ class Character(Learner):
crash_on_error=crash_on_error)
drone.controller = controller
rpc_control = controller.make_control_transport() # TODO
return controller

View File

@ -6,13 +6,16 @@ from typing import Callable
from flask import Response, Flask
from hendrix.deploy.base import HendrixDeploy
from twisted.internet import reactor
from twisted.internet import reactor, stdio
from twisted.logger import Logger
from nucypher.characters.control.emitters import StdoutEmitter, WebEmitter, JSONRPCStdoutEmitter
from nucypher.characters.control.interfaces import (AliceInterface, character_control_interface, EnricoInterface, \
BobInterface
)
from nucypher.characters.control.interfaces import (
AliceInterface,
character_control_interface,
EnricoInterface,
BobInterface
)
from nucypher.characters.control.serializers import (
AliceControlJSONSerializer,
BobControlJSONSerializer,
@ -201,7 +204,7 @@ class JSONRPCController(CharacterControlServer):
_emitter_class = JSONRPCStdoutEmitter
def start(self):
self.make_control_transport()
_transport = self.make_control_transport()
reactor.run() # < ------ Blocking Call (Reactor)
def test_client(self) -> JSONRPCTestClient:
@ -209,7 +212,7 @@ class JSONRPCController(CharacterControlServer):
return test_client
def make_control_transport(self):
transport = JSONRPCLineReceiver(rpc_controller=self)
transport = stdio.StandardIO(JSONRPCLineReceiver(rpc_controller=self))
return transport
def get_interface(self, name: str) -> Callable:

View File

@ -188,6 +188,7 @@ def alice(click_config,
# RPC
if click_config.json_ipc:
rpc_controller = ALICE.make_rpc_controller()
_transport = rpc_controller.make_control_transport()
rpc_controller.start()
return

View File

@ -136,6 +136,15 @@ def bob(click_config,
# Echo Public Keys
click_config.emit(message=f"Bob Verifying Key {bytes(BOB.stamp).hex()}", color='green', bold=True)
# RPC
if click_config.json_ipc:
rpc_controller = BOB.make_rpc_controller()
_transport = rpc_controller.make_control_transport()
rpc_controller.start()
return
click_config.emitter(message=f"Bob Verifying Key {bytes(BOB.stamp).hex()}", color='green', bold=True)
bob_encrypting_key = bytes(BOB.public_keys(DecryptingPower)).hex()
click_config.emit(message=f"Bob Encrypting Key {bob_encrypting_key}", color="blue", bold=True)

View File

@ -46,6 +46,14 @@ def enrico(click_config, action, policy_encrypting_key, dry_run, http_port, mess
#
if action == 'run':
# RPC
if click_config.json_ipc:
rpc_controller = ENRICO.make_rpc_controller()
_transport = rpc_controller.make_control_transport()
rpc_controller.start()
return
ENRICO.log.info('Starting HTTP Character Web Controller')
controller = ENRICO.make_web_controller()
return controller.start(http_port=http_port, dry_run=dry_run)