Commit 16b05d3b authored by Luke Champine's avatar Luke Champine

extend deadlines during file transfer

parent a6c7225c
......@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strconv"
"time"
"github.com/NebulousLabs/Sia/consensus"
"github.com/NebulousLabs/Sia/encoding"
......@@ -186,6 +187,11 @@ func (h *Host) NegotiateContract(conn net.Conn) (err error) {
if err != nil {
return
}
// file transfer is going to take a while, so extend the timeout.
// This assumes a minimum transfer rate of ~1 Mbps
conn.SetDeadline(time.Now().Add(time.Duration(terms.FileSize) * 8 * time.Microsecond))
// simultaneously download file and calculate its Merkle root.
tee := io.TeeReader(
// use a LimitedReader to ensure we don't read indefinitely
......
......@@ -6,6 +6,7 @@ import (
"net"
"os"
"sync"
"time"
"github.com/NebulousLabs/Sia/consensus"
"github.com/NebulousLabs/Sia/encoding"
......@@ -108,6 +109,9 @@ func (h *Host) RetrieveFile(conn net.Conn) (err error) {
return
}
defer file.Close()
info, _ := file.Stat()
conn.SetDeadline(time.Now().Add(time.Duration(info.Size()) * 8 * time.Microsecond))
// Transmit the file.
_, err = io.Copy(conn, file)
......
......@@ -4,6 +4,7 @@ import (
"errors"
"io"
"net"
"time"
"github.com/NebulousLabs/Sia/consensus"
"github.com/NebulousLabs/Sia/encoding"
......@@ -93,6 +94,11 @@ func (r *Renter) negotiateContract(host modules.HostEntry, up modules.UploadPara
if response != modules.AcceptContractResponse {
return errors.New(response)
}
// file transfer is going to take a while, so extend the timeout.
// This assumes a minimum transfer rate of ~1 Mbps
conn.SetDeadline(time.Now().Add(time.Duration(filesize) * 8 * time.Microsecond))
// simultaneously transmit file data and calculate Merkle root
tee := io.TeeReader(up.Data, conn)
merkleRoot, err := hash.ReaderMerkleRoot(tee, filesize)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment