예제 #1
0
def run_client(reactor, o, pubkey):
    w = wormhole.create(APPID, MAILBOX_URL, reactor)
    wormhole.input_with_completion("Provisioning code: ", w.input_code(), reactor)
    cm = json.dumps({
        "pubkey": pubkey,
        })
    w.send_message(cm.encode("utf-8"))
    server_message = yield w.get_message()
    sm = json.loads(server_message.decode("utf-8"))
    print("server message is", sm)
    yield w.close()

    if not sm['ok']:
        print("error from server:", sm['error'])
        return

    BASEDIR = o['basedir']
    setIngressAndRestart(sm)
예제 #2
0
def run_client(reactor, o, pubkey):
    w = wormhole.create(APPID, MAILBOX_URL, reactor)
    # FIXME: Handle SIGINT!
    wormhole.input_with_completion("Provisioning code: ", w.input_code(), reactor)
    cm = json.dumps({
        "pubkey": pubkey,
        })
    w.send_message(cm.encode("utf-8"))
    server_message = yield w.get_message()
    sm = json.loads(server_message.decode("utf-8"))
    print("server message is", sm)
    yield w.close()

    if not sm['ok']:
        print("error from server:", sm['error'])
        return

    BASEDIR = o['basedir']
    subprocess.run([AG_SOLO, 'set-gci-ingress', '--chainID=%s' % sm['chainName'], sm['gci'], *sm['rpcAddrs']], check=True)
    os.execvp(AG_SOLO, [AG_SOLO, 'start', '--role=client'])
예제 #3
0
def run(reactor, opts):
    basedir = FilePath(os.path.expanduser(opts["basedir"]))
    controllerFurl = basedir.child("controller.furl").getContent()
    if not opts.subCommand:
        raise usage.UsageError("pick a command")
    so = opts.subOptions

    if opts.subCommand == "add-host":
        w = create(APPID, MAILBOX_URL, reactor)
        if so.code:
            w.set_code(so.code)
        else:
            input_with_completion("Invitation code: ", w.input_code(), reactor)
        yield w.get_code()
        furl = yield w.get_message()
        c = yield getController(reactor, controllerFurl)
        hostname = yield c.callRemote("accept_add_host", furl)
        print("hostname '%s' added" % hostname)
        print("if you want to configure a post-update hook, edit:")
        print("  %s" % basedir.child(hostname).child("post-update-hook").path)
        print("(and make it executable)")
        w.send_message("ok")
        yield w.close()

    if opts.subCommand == "add-dyndns":
        w = create(APPID, MAILBOX_URL, reactor)
        if so.code:
            w.set_code(so.code)
        else:
            input_with_completion("Invitation code: ", w.input_code(), reactor)
        yield w.get_code()
        furl = yield w.get_message()
        c = yield getController(reactor, controllerFurl)
        yield c.callRemote("accept_add_dyndns", furl)
        print("dyndns hostname added for this client")
        w.send_message("ok")
        yield w.close()
예제 #4
0
 def _handle_code(self, w):
     code = self.args.code
     if self.args.zeromode:
         assert not code
         code = u"0-"
     if code:
         w.set_code(code)
     else:
         prompt = "Enter receive wormhole code: "
         used_completion = yield input_with_completion(
             prompt, w.input_code(), self._reactor)
         if not used_completion:
             print(" (note: you can use <Tab> to complete words)",
                   file=self.args.stderr)
     yield w.get_code()
예제 #5
0
 def _handle_code(self, w):
     code = self.args.code
     if self.args.zeromode:
         assert not code
         code = u"0-"
     if code:
         w.set_code(code)
     else:
         prompt = "Enter receive wormhole code: "
         used_completion = yield input_with_completion(prompt,
                                                       w.input_code(),
                                                       self._reactor)
         if not used_completion:
             print(" (note: you can use <Tab> to complete words)",
                   file=self.args.stderr)
     yield w.get_code()
예제 #6
0
 def _handle_code(self, w):
     code = self.args.code
     if self.args.zeromode:
         assert not code
         code = u"0-"
     if code:
         w.set_code(code)
     else:
         prompt = "웜홀 코드를 입력하십시오: "
         used_completion = yield input_with_completion(
             prompt, w.input_code(), self._reactor)
         if not used_completion:
             print(
                 " (안내: 단어를 완성하는데 <Tab>키를 사용할 수 있습니다.)",
                 file=self.args.stderr)
     yield w.get_code()
예제 #7
0
def run_client(reactor, o, pkeyFile):
    def cleanup():
        try:
            # Delete the basedir if we failed
            shutil.rmtree(o['basedir'])
        except FileNotFoundError:
            pass

    try:
        # Try to initialize the client
        print("initializing ag-solo", o['basedir'])
        doInit(o)

        # read the pubkey out of BASEDIR/ag-cosmos-helper-address
        f = open(pkeyFile)
        pubkey = f.read()
        f.close()
        pubkey = pubkey.strip()

        # Use the provisioning code to register our pubkey.
        w = wormhole.create(APPID, MAILBOX_URL, reactor)

        # Ensure cleanup gets called before aborting
        t = reactor.addSystemEventTrigger("before", "shutdown", cleanup)
        yield wormhole.input_with_completion("Provisioning code: ",
                                             w.input_code(), reactor)
        reactor.removeSystemEventTrigger(t)

        cm = json.dumps({
            "pubkey": pubkey,
        })
        w.send_message(cm.encode("utf-8"))
        server_message = yield w.get_message()
        sm = json.loads(server_message.decode("utf-8"))
        print("server message is", sm)
        yield w.close()

        if not sm['ok']:
            raise Exception("error from server: " + sm['error'])

        BASEDIR = o['basedir']
        setIngress(sm)
    except:
        cleanup()
        raise
    restart()