From 40e78ca8397e867bb64086ecaebbf4268c47a045 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 19 Feb 2015 17:04:52 -0800 Subject: [PATCH] ok, you might want to send files larger than your MTU --- bin/receive_file.py | 13 +++++++++---- bin/send_file.py | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bin/receive_file.py b/bin/receive_file.py index 82441a0..466f66d 100644 --- a/bin/receive_file.py +++ b/bin/receive_file.py @@ -35,10 +35,15 @@ transit_receiver.add_sender_direct_hints(tdata["direct_connection_hints"]) transit_receiver.add_sender_relay_hints(tdata["relay_connection_hints"]) skt = transit_receiver.establish_connection() print("Receiving %d bytes.." % filesize) -encrypted = skt.recv(encrypted_filesize) -if len(encrypted) != encrypted_filesize: - print("Connection dropped before file received") - sys.exit(1) +encrypted = b"" +while len(encrypted) < encrypted_filesize: + more = skt.recv(encrypted_filesize - len(encrypted)) + if not more: + print("Connection dropped before full file received") + print("got %d bytes, wanted %d" % (len(encrypted), encrypted_filesize)) + sys.exit(1) + encrypted += more +assert len(encrypted) == encrypted_filesize decrypted = SecretBox(xfer_key).decrypt(encrypted) diff --git a/bin/send_file.py b/bin/send_file.py index 9d2ed9d..a98132d 100644 --- a/bin/send_file.py +++ b/bin/send_file.py @@ -50,7 +50,10 @@ transit_sender.add_receiver_hints(tdata["direct_connection_hints"]) skt = transit_sender.establish_connection() print("Sending %d bytes.." % filesize) -skt.send(encrypted) +sent = 0 +while sent < len(encrypted): + more = skt.send(encrypted[sent:]) + sent += more print("File sent.. waiting for confirmation") # ack is a short newline-terminated string, followed by socket close. A long