ok, you might want to send files larger than your MTU

This commit is contained in:
Brian Warner 2015-02-19 17:04:52 -08:00
parent 50e466b581
commit 40e78ca839
2 changed files with 13 additions and 5 deletions

View File

@ -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)

View File

@ -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