Esempio n. 1
0
 def connect(self):
     tor = None
     if self.use_tor:
         tor = yield get_tor(reactor)
         if not tor:
             raise TorError("Could not connect to a running Tor daemon")
         self._wormhole = wormhole.create(APPID, RELAY, reactor, tor=tor)
     else:
         self._wormhole = wormhole.create(APPID, RELAY, reactor)
     logging.debug("Connecting to %s (tor=%s)...", RELAY, tor)
     welcome = yield self._wormhole.get_welcome()
     logging.debug("Connected to wormhole server; got welcome: %s", welcome)
     self.got_welcome.emit(welcome)
Esempio n. 2
0
def _get_config_via_wormhole(config):
    out = config.stdout
    print >> out, "Opening wormhole with code '{}'".format(config['join'])
    relay_url = config.parent['wormhole-server']
    print >> out, "Connecting to '{}'".format(relay_url)

    wh = wormhole.create(
        appid=config.parent['wormhole-invite-appid'],
        relay_url=relay_url,
        reactor=reactor,
    )
    code = unicode(config['join'])
    wh.set_code(code)
    yield wh.get_welcome()
    print >> out, "Connected to wormhole server"

    intro = {
        u"abilities": {
            "client-v1": {},
        }
    }
    wh.send_message(json.dumps(intro))

    server_intro = yield wh.get_message()
    server_intro = json.loads(server_intro)

    print >> out, "  received server introduction"
    if u'abilities' not in server_intro:
        raise RuntimeError("  Expected 'abilities' in server introduction")
    if u'server-v1' not in server_intro['abilities']:
        raise RuntimeError("  Expected 'server-v1' in server abilities")

    remote_data = yield wh.get_message()
    print >> out, "  received configuration"
    defer.returnValue(json.loads(remote_data))
Esempio n. 3
0
def _send_config_via_wormhole(options, config):
    out = options.stdout
    err = options.stderr
    relay_url = options.parent['wormhole-server']
    print("Connecting to '{}'...".format(relay_url), file=out)
    wh = wormhole.create(
        appid=options.parent['wormhole-invite-appid'],
        relay_url=relay_url,
        reactor=reactor,
    )
    yield wh.get_welcome()
    print("Connected to wormhole server", file=out)

    # must call allocate_code before get_code will ever succeed
    wh.allocate_code()
    code = yield wh.get_code()
    print("Invite Code for client: {}".format(code), file=out)

    wh.send_message(json.dumps({u"abilities": {
        u"server-v1": {},
    }}))

    client_intro = yield wh.get_message()
    print("  received client introduction", file=out)
    client_intro = json.loads(client_intro)
    if not u'abilities' in client_intro:
        print("No 'abilities' from client", file=err)
        defer.returnValue(1)
    if not u'client-v1' in client_intro[u'abilities']:
        print("No 'client-v1' in abilities from client", file=err)
        defer.returnValue(1)

    print("  transmitting configuration", file=out)
    wh.send_message(json.dumps(config))
    yield wh.close()
Esempio n. 4
0
def _get_config_via_wormhole(config):
    out = config.stdout
    print >>out, "Opening wormhole with code '{}'".format(config['join'])
    relay_url = config.parent['wormhole-server']
    print >>out, "Connecting to '{}'".format(relay_url)

    wh = wormhole.create(
        appid=config.parent['wormhole-invite-appid'],
        relay_url=relay_url,
        reactor=reactor,
    )
    code = unicode(config['join'])
    wh.set_code(code)
    yield wh.get_welcome()
    print >>out, "Connected to wormhole server"

    intro = {
        u"abilities": {
            "client-v1": {},
        }
    }
    wh.send_message(json.dumps(intro))

    server_intro = yield wh.get_message()
    server_intro = json.loads(server_intro)

    print >>out, "  received server introduction"
    if u'abilities' not in server_intro:
        raise RuntimeError("  Expected 'abilities' in server introduction")
    if u'server-v1' not in server_intro['abilities']:
        raise RuntimeError("  Expected 'server-v1' in server abilities")

    remote_data = yield wh.get_message()
    print >>out, "  received configuration"
    defer.returnValue(json.loads(remote_data))
Esempio n. 5
0
def _send_config_via_wormhole(options, config):
    out = options.stdout
    err = options.stderr
    relay_url = options.parent['wormhole-server']
    print("Connecting to '{}'...".format(relay_url), file=out)
    wh = wormhole.create(
        appid=options.parent['wormhole-invite-appid'],
        relay_url=relay_url,
        reactor=reactor,
    )
    yield wh.get_welcome()
    print("Connected to wormhole server", file=out)

    # must call allocate_code before get_code will ever succeed
    wh.allocate_code()
    code = yield wh.get_code()
    print("Invite Code for client: {}".format(code), file=out)

    wh.send_message(json.dumps({
        u"abilities": {
            u"server-v1": {},
        }
    }))

    client_intro = yield wh.get_message()
    print("  received client introduction", file=out)
    client_intro = json.loads(client_intro)
    if not u'abilities' in client_intro:
        print("No 'abilities' from client", file=err)
        defer.returnValue(1)
    if not u'client-v1' in client_intro[u'abilities']:
        print("No 'client-v1' in abilities from client", file=err)
        defer.returnValue(1)

    print("  transmitting configuration", file=out)
    wh.send_message(json.dumps(config))
    yield wh.close()
Esempio n. 6
0
 def __init__(self, use_tor=False):
     super(Wormhole, self).__init__()
     self.use_tor = use_tor
     self._wormhole = wormhole.create(APPID, RELAY, reactor)
Esempio n. 7
0
 def __init__(self):
     super(Wormhole, self).__init__()
     self._wormhole = wormhole.create(APPID, RELAY, reactor)