add CLI args to override the relay hosts (rendezvous and transit)
This commit is contained in:
parent
84aa7ff248
commit
cc37d2dc2f
|
@ -5,9 +5,8 @@ from spake2 import SPAKE2_A, SPAKE2_B
|
||||||
from nacl.secret import SecretBox
|
from nacl.secret import SecretBox
|
||||||
from nacl.exceptions import CryptoError
|
from nacl.exceptions import CryptoError
|
||||||
from nacl import utils
|
from nacl import utils
|
||||||
from .. import codes
|
from .. import codes, const
|
||||||
from ..util.hkdf import HKDF
|
from ..util.hkdf import HKDF
|
||||||
from ..const import RENDEZVOUS_RELAY
|
|
||||||
|
|
||||||
SECOND = 1
|
SECOND = 1
|
||||||
MINUTE = 60*SECOND
|
MINUTE = 60*SECOND
|
||||||
|
@ -164,11 +163,11 @@ class Common:
|
||||||
return HKDF(self.key, length, CTXinfo=purpose)
|
return HKDF(self.key, length, CTXinfo=purpose)
|
||||||
|
|
||||||
class Initiator(Common):
|
class Initiator(Common):
|
||||||
def __init__(self, appid, data, relay=RENDEZVOUS_RELAY):
|
def __init__(self, appid, data, relay=None):
|
||||||
self.appid = appid
|
self.appid = appid
|
||||||
self.data = data
|
self.data = data
|
||||||
assert relay.endswith("/")
|
self.relay = relay or const.RENDEZVOUS_RELAY
|
||||||
self.relay = relay
|
assert self.relay.endswith("/")
|
||||||
self.started = time.time()
|
self.started = time.time()
|
||||||
self.wait = 0.5*SECOND
|
self.wait = 0.5*SECOND
|
||||||
self.timeout = 3*MINUTE
|
self.timeout = 3*MINUTE
|
||||||
|
@ -204,11 +203,11 @@ class Initiator(Common):
|
||||||
|
|
||||||
|
|
||||||
class Receiver(Common):
|
class Receiver(Common):
|
||||||
def __init__(self, appid, data, relay=RENDEZVOUS_RELAY):
|
def __init__(self, appid, data, relay=None):
|
||||||
self.appid = appid
|
self.appid = appid
|
||||||
self.data = data
|
self.data = data
|
||||||
self.relay = relay
|
self.relay = relay or const.RENDEZVOUS_RELAY
|
||||||
assert relay.endswith("/")
|
assert self.relay.endswith("/")
|
||||||
self.started = time.time()
|
self.started = time.time()
|
||||||
self.wait = 0.5*SECOND
|
self.wait = 0.5*SECOND
|
||||||
self.timeout = 3*MINUTE
|
self.timeout = 3*MINUTE
|
||||||
|
|
|
@ -2,9 +2,9 @@ from __future__ import print_function
|
||||||
import re, time, threading, socket, SocketServer
|
import re, time, threading, socket, SocketServer
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from nacl.secret import SecretBox
|
from nacl.secret import SecretBox
|
||||||
|
from .. import const
|
||||||
from ..util import ipaddrs
|
from ..util import ipaddrs
|
||||||
from ..util.hkdf import HKDF
|
from ..util.hkdf import HKDF
|
||||||
from ..const import TRANSIT_RELAY
|
|
||||||
|
|
||||||
class TransitError(Exception):
|
class TransitError(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -270,7 +270,8 @@ class RecordPipe:
|
||||||
self.skt.close()
|
self.skt.close()
|
||||||
|
|
||||||
class Common:
|
class Common:
|
||||||
def __init__(self):
|
def __init__(self, transit_relay=None):
|
||||||
|
self._transit_relay = transit_relay or const.TRANSIT_RELAY
|
||||||
self.winning = threading.Event()
|
self.winning = threading.Event()
|
||||||
self._negotiation_check_lock = threading.Lock()
|
self._negotiation_check_lock = threading.Lock()
|
||||||
self._have_transit_key = threading.Condition()
|
self._have_transit_key = threading.Condition()
|
||||||
|
@ -291,7 +292,7 @@ class Common:
|
||||||
def get_direct_hints(self):
|
def get_direct_hints(self):
|
||||||
return self.my_direct_hints
|
return self.my_direct_hints
|
||||||
def get_relay_hints(self):
|
def get_relay_hints(self):
|
||||||
return [TRANSIT_RELAY]
|
return [self._transit_relay]
|
||||||
|
|
||||||
def add_their_direct_hints(self, hints):
|
def add_their_direct_hints(self, hints):
|
||||||
self._their_direct_hints = [force_ascii(h) for h in hints]
|
self._their_direct_hints = [force_ascii(h) for h in hints]
|
||||||
|
|
|
@ -8,7 +8,7 @@ APPID = "lothar.com/wormhole/file-xfer"
|
||||||
|
|
||||||
def receive_file(so):
|
def receive_file(so):
|
||||||
# we're receiving
|
# we're receiving
|
||||||
transit_receiver = TransitReceiver()
|
transit_receiver = TransitReceiver(transit_relay=so.parent["transit-helper"])
|
||||||
|
|
||||||
mydata = json.dumps({
|
mydata = json.dumps({
|
||||||
"transit": {
|
"transit": {
|
||||||
|
@ -16,7 +16,7 @@ def receive_file(so):
|
||||||
"relay_connection_hints": transit_receiver.get_relay_hints(),
|
"relay_connection_hints": transit_receiver.get_relay_hints(),
|
||||||
},
|
},
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
r = Receiver(APPID, mydata)
|
r = Receiver(APPID, mydata, so.parent["relay-url"])
|
||||||
code = so["code"]
|
code = so["code"]
|
||||||
if not code:
|
if not code:
|
||||||
code = r.input_code("Enter receive-file wormhole code: ")
|
code = r.input_code("Enter receive-file wormhole code: ")
|
||||||
|
|
|
@ -7,7 +7,7 @@ APPID = "lothar.com/wormhole/text-xfer"
|
||||||
def receive_text(so):
|
def receive_text(so):
|
||||||
# we're receiving
|
# we're receiving
|
||||||
data = json.dumps({"message": "ok"}).encode("utf-8")
|
data = json.dumps({"message": "ok"}).encode("utf-8")
|
||||||
r = Receiver(APPID, data)
|
r = Receiver(APPID, data, so.parent["relay-url"])
|
||||||
code = so["code"]
|
code = so["code"]
|
||||||
if not code:
|
if not code:
|
||||||
code = r.input_code("Enter receive-text wormhole code: ")
|
code = r.input_code("Enter receive-text wormhole code: ")
|
||||||
|
|
|
@ -10,7 +10,7 @@ def send_file(so):
|
||||||
# we're sending
|
# we're sending
|
||||||
filename = so["filename"]
|
filename = so["filename"]
|
||||||
assert os.path.isfile(filename)
|
assert os.path.isfile(filename)
|
||||||
transit_sender = TransitSender()
|
transit_sender = TransitSender(transit_relay=so.parent["transit-helper"])
|
||||||
|
|
||||||
filesize = os.stat(filename).st_size
|
filesize = os.stat(filename).st_size
|
||||||
data = json.dumps({
|
data = json.dumps({
|
||||||
|
@ -24,7 +24,7 @@ def send_file(so):
|
||||||
},
|
},
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
|
|
||||||
i = Initiator(APPID, data)
|
i = Initiator(APPID, data, so.parent["relay-url"])
|
||||||
code = i.get_code()
|
code = i.get_code()
|
||||||
print("On the other computer, please run: wormhole receive-file")
|
print("On the other computer, please run: wormhole receive-file")
|
||||||
print("Wormhole code is '%s'" % code)
|
print("Wormhole code is '%s'" % code)
|
||||||
|
|
|
@ -9,7 +9,7 @@ def send_text(so):
|
||||||
message = so["text"]
|
message = so["text"]
|
||||||
data = json.dumps({"message": message,
|
data = json.dumps({"message": message,
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
i = Initiator(APPID, data)
|
i = Initiator(APPID, data, so.parent["relay-url"])
|
||||||
code = i.get_code()
|
code = i.get_code()
|
||||||
print("On the other computer, please run: wormhole receive-text")
|
print("On the other computer, please run: wormhole receive-text")
|
||||||
print("Wormhole code is: %s" % code)
|
print("Wormhole code is: %s" % code)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
from twisted.python import usage
|
from twisted.python import usage
|
||||||
|
from .. import const
|
||||||
|
|
||||||
class SendTextOptions(usage.Options):
|
class SendTextOptions(usage.Options):
|
||||||
def parseArgs(self, text):
|
def parseArgs(self, text):
|
||||||
|
@ -26,6 +27,12 @@ class ReceiveFileOptions(usage.Options):
|
||||||
|
|
||||||
class Options(usage.Options):
|
class Options(usage.Options):
|
||||||
synopsis = "\nUsage: wormhole <command>"
|
synopsis = "\nUsage: wormhole <command>"
|
||||||
|
optParameters = [
|
||||||
|
["relay-url", None, const.RENDEZVOUS_RELAY,
|
||||||
|
"rendezvous relay to use (URL)"],
|
||||||
|
["transit-helper", None, const.TRANSIT_RELAY,
|
||||||
|
"transit relay to use (tcp:HOST:PORT)"],
|
||||||
|
]
|
||||||
subCommands = [("send-text", None, SendTextOptions, "Send a text message"),
|
subCommands = [("send-text", None, SendTextOptions, "Send a text message"),
|
||||||
("send-file", None, SendFileOptions, "Send a file"),
|
("send-file", None, SendFileOptions, "Send a file"),
|
||||||
("receive-text", None, ReceiveTextOptions, "Receive a text message"),
|
("receive-text", None, ReceiveTextOptions, "Receive a text message"),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user