make transit mostly work, but the race condition kills it
This commit is contained in:
parent
f459d59b48
commit
ae68dad441
|
@ -1,9 +1,8 @@
|
|||
from __future__ import print_function
|
||||
import os, sys, json
|
||||
import os, json
|
||||
from binascii import unhexlify
|
||||
from nacl.secret import SecretBox
|
||||
from wormhole.blocking.transcribe import Receiver
|
||||
from wormhole.codes import input_code_with_completion
|
||||
from wormhole.blocking.transit import TransitReceiver
|
||||
|
||||
APPID = "lothar.com/wormhole/file-xfer"
|
||||
|
@ -18,7 +17,7 @@ mydata = json.dumps({
|
|||
},
|
||||
}).encode("utf-8")
|
||||
r = Receiver(APPID, mydata)
|
||||
r.set_code(r.input_code("Enter receive-text wormhole code: "))
|
||||
r.set_code(r.input_code("Enter receive-file wormhole code: "))
|
||||
|
||||
data = json.loads(r.get_data().decode("utf-8"))
|
||||
print("their data: %r" % (data,))
|
||||
|
@ -30,11 +29,12 @@ filesize = file_data["filesize"]
|
|||
|
||||
# now receive the rest of the owl
|
||||
tdata = data["transit"]
|
||||
print("calling tr.set_transit_key()")
|
||||
transit_receiver.set_transit_key(tdata["key"])
|
||||
transit_receiver.add_sender_direct_hints(tdata["direct_connection_hints"])
|
||||
transit_receiver.add_sender_relay_hints(tdata["relay_connection_hints"])
|
||||
transit_receiver.establish_connection()
|
||||
encrypted = transit_receiver.receive()
|
||||
skt = transit_receiver.establish_connection()
|
||||
encrypted = skt.recv(filesize)
|
||||
|
||||
decrypted = SecretBox(xfer_key).decrypt(encrypted)
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from __future__ import print_function
|
||||
import time, json
|
||||
from wormhole.blocking.transcribe import Receiver
|
||||
from wormhole.codes import input_code_with_completion
|
||||
|
||||
APPID = "lothar.com/wormhole/text-xfer"
|
||||
|
||||
|
|
|
@ -41,12 +41,13 @@ print("them: %r" % (them_d,))
|
|||
box = SecretBox(xfer_key)
|
||||
with open(filename, "rb") as f:
|
||||
plaintext = f.read()
|
||||
nonce = utils.random(SecretBox.NONCE_SIZE)
|
||||
nonce = os.urandom(SecretBox.NONCE_SIZE)
|
||||
encrypted = box.encrypt(plaintext, nonce)
|
||||
|
||||
transit_sender.add_receiver_hints(them_d["direct_connection_hints"])
|
||||
transit_sender.establish_connection()
|
||||
transit_sender.write(encrypted)
|
||||
transit_sender.close()
|
||||
tdata = them_d["transit"]
|
||||
transit_sender.add_receiver_hints(tdata["direct_connection_hints"])
|
||||
skt = transit_sender.establish_connection()
|
||||
skt.write(encrypted)
|
||||
skt.close()
|
||||
|
||||
print("file sent")
|
||||
|
|
|
@ -116,6 +116,8 @@ class BadHandshake(Exception):
|
|||
pass
|
||||
|
||||
def connector(owner, hint, send_handshake, expected_handshake):
|
||||
if isinstance(hint, type(u"")):
|
||||
hint = hint.encode("ascii")
|
||||
addr,port = hint.split(",")
|
||||
skt = socket.create_connection((addr,port)) # timeout here
|
||||
skt.settimeout(TIMEOUT)
|
||||
|
@ -168,7 +170,7 @@ class MyTCPServer(SocketServer.TCPServer):
|
|||
allow_reuse_address = True
|
||||
def process_request(self, request, client_address):
|
||||
if not self.owner.key:
|
||||
raise BadHandshake("connection received before set_key()")
|
||||
raise BadHandshake("connection received before set_transit_key()")
|
||||
t = threading.Thread(target=handle,
|
||||
args=(request, client_address,
|
||||
self.owner,
|
||||
|
@ -181,6 +183,7 @@ class TransitReceiver:
|
|||
def __init__(self):
|
||||
self.winning = threading.Event()
|
||||
self._negotiation_check_lock = threading.Lock()
|
||||
self.key = None
|
||||
server = MyTCPServer(("",9999), None)
|
||||
_, port = server.server_address
|
||||
self.my_direct_hints = ["%s,%d" % (addr, port)
|
||||
|
|
Loading…
Reference in New Issue
Block a user