dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 5ae349790023c4da43379bda761698680bcb1b3b
parent 49f3d8849365fbf43c7697e2fea38d9d349116af
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 31 Jan 2023 02:05:48 -0800

check if server already has a chunk

Diffstat:
Mcmd/dkfupload/main.go | 25++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/cmd/dkfupload/main.go b/cmd/dkfupload/main.go @@ -165,10 +165,33 @@ func work(i int, wg *sync.WaitGroup, chunksCh chan int64, isLocal, dry bool, max logrus.Infof("Thread #%03d | chunk #%03d | read %d | from %d to %d\n", i, chunkNum, n, offset, offset+int64(n)) if !dry { hasToSucceed(func() error { + partFileName := fmt.Sprintf("part_%d", chunkNum) + + // Ask server if he already has the chunk + { + body := url.Values{} + body.Set("fileName", partFileName) + req, _ := http.NewRequest(http.MethodPost, baseUrl+"/file-drop/"+filedropUUID+"/tmp", strings.NewReader(body.Encode())) + req.Header.Set("User-Agent", userAgent) + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + resp, err := client.Do(req) + if err != nil { + if os.IsTimeout(err) { + logrus.Infof("Thread #%03d gets a new client\n", i) + client = doGetClient(isLocal, httpTimeout) + } + return err + } + defer resp.Body.Close() + if resp.StatusCode == http.StatusTeapot { + logrus.Infof("Thread #%03d | server already has chunk #%03d; skip", i, chunkNum) + return nil + } + } + start = time.Now() body := new(bytes.Buffer) w := multipart.NewWriter(body) - partFileName := fmt.Sprintf("part_%d", chunkNum) part, err := w.CreateFormFile("file", partFileName) if err != nil { return err