Print the search-mode into the info-file.
[doldaconnect.git] / lib / guile / autodl
index f57423f..b70fa8f 100755 (executable)
@@ -62,7 +62,9 @@
 
 (define (wanttosearch)
   (> (- (current-time) lastsearch)
-     (if (> (length trans) 0) 300 60))
+     (if (eq? (cdr (assoc 'search-mode session)) 'wait)
+        7200
+        (if (> (length trans) 0) 300 60)))
   )
 
 (define defspeed '())
                      (cadr (cdr (assoc 'peer sr)))
                      (cdr (assoc 'filename sr))
                      (cdr (assoc 'size sr)))))
+      (let ((hash (assoc 'hash sr)))
+       (if (and hash (not (equal? (cdr hash) ""))) (set! args (append args (list "hash" (cdr hash))))))
       (let ((tag (assoc 'tag session)))
        (if tag (set! args (append args (list "tag" (cdr tag))))))
       (let ((uarg (assoc 'uarg session)))
                    (begin (logf (string-append "transfer " (number->string (car o)) " timing out"))
                           (dc-ecmd-assert 200 "cancel" (car o))
                           (disablepeer (cdr (assoc 'peer (cdr o))))
-                          (set! trans (assq-remove! trans (car o)))))
+                          (set! trans (assq-remove! trans (car o)))
+                          (write-info-file)))
                (if (and (eq? (cdr (assoc 'state (cdr o))) 'main)
                         (> (- time (cdr (assoc 'lastprog (cdr o)))) 60))
                    (begin (logf (string-append "transfer " (number->string (car o)) " seems to have stalled"))
                           (dc-ecmd-assert 200 "cancel" (car o))
-                          (set! trans (assq-remove! trans (car o)))))
+                          (set! trans (assq-remove! trans (car o)))
+                          (write-info-file)))
                (if (and (eq? (cdr (assoc 'state (cdr o))) 'main)
                         (> (- (cdr (assoc 'lastprog (cdr o))) (cdr (assoc 'lasttime (cdr o)))) 20))
                    (begin (set-cdr! (assoc 'curspeed (cdr o))
                                     (/ (- (cdr (assoc 'curpos (cdr o))) (cdr (assoc 'lastpos (cdr o))))
                                        (- (cdr (assoc 'lastprog (cdr o))) (cdr (assoc 'lasttime (cdr o))))))
                           (set-cdr! (assoc 'lastpos (cdr o)) (cdr (assoc 'curpos (cdr o))))
-                          (set-cdr! (assoc 'lasttime (cdr o)) (cdr (assoc 'lastprog (cdr o)))))))
+                          (set-cdr! (assoc 'lasttime (cdr o)) (cdr (assoc 'lastprog (cdr o))))
+                          (write-info-file))))
                trans))
   )
 
                     (cons 'realsr info-numreal)
                     (cons 'totalsr info-numtotal)
                     (cons 'lastsrch lastsearch)
-                    (cons 'srcheta info-searcheta))
+                    (cons 'srcheta info-searcheta)
+                    (cons 'srchmode (cdr (assoc 'search-mode session))))
               op)
        (newline op)
        (close-port op))))
     (set! info-numavail numavail)
     (set! info-numreal numreal)
     (set! info-numtotal numtotal)
+    (write-info-file)
     retval)
   )
 
-(define (handlesr filename fnet peer size slots resptime)
+(define (handlesr filename fnet peer size slots resptime hash)
   (let ((cl (or (assoc size sr)
                (let ((newp (cons size '()))) (set! sr (append sr (list newp))) newp)))
        (newsr (list
                (cons 'slots slots)
                (cons 'resptime resptime)
                (cons 'speed (getspeed peer))
+               (cons 'hash hash)
                (cons 'recvtime (current-time))
                (cons 'dis #f)))
        (newlist '()))
       (do ((arg (getopt) (getopt))) ((not (and (pair? arg) (char? (car arg)))) (set! args arg))
        (cond ((eq? (car arg) #\h)
               (begin (display "usage: autodl [-s server] -S sessfile\n" (current-error-port))
-                     (display "       autodl [-s server] -e search-expression [-p prio] [-t tag] [-a userarg]\n" (current-error-port))
+                     (display "       autodl [-w] [-s server] -e search-expression [-p prio] [-t tag] [-a userarg]\n" (current-error-port))
                      (display "       autodl [-s server]\n" (current-error-port))
                      (display "       autodl -h\n" (current-error-port))
                      (exit 0)))
                     (set! session (cons (cons 'info-file (cdr arg)) session)))))
              ((eq? (car arg) #\e)
               (set! session (cons (cons 'sexpr (dc-lexsexpr (cdr arg))) session)))
+             ((eq? (car arg) #\w)
+              (set! session (cons '(search-mode . wait) session)))
              )
        )
       )
        (set! session (cons '(prio . 10) session)))
     (if (not (assoc 'maxtrans session))
        (set! session (cons '(maxtrans . 1) session)))
+    (if (not (assoc 'search-mode session))
+       (set! session (cons '(search-mode . wait) session)))
     (if (not (validate-session session)) (begin (display "Invalid session!\n" (current-error-port)) (exit 1)))
     (if (not dc-server) (set! dc-server (getenv "DCSERVER")))
     (if (not dc-server) (set! dc-server "localhost"))
                               (begin (set! srchid (car ires))
                                      (logf (string-append "search scheduled in " (number->string (cadr ires)) " seconds (id " (number->string srchid) ")"))
                                      (set! info-searcheta (+ (current-time) (cadr ires)))
-                                     (set! lastsearch -1)))
+                                     (set! lastsearch -1)
+                                     (write-info-file)))
                              ((501)
                               (begin (set! srchid -1)
                                      (logf (string-append "no fnetnodes available to search on"))
                    (if (> (- (current-time) lastparse) 20)
                        (begin (parseresults)
                               (set! lastparse (current-time))))
-                   (write-info-file)
                    (dc-select 10000)
                    (while (let ((resp (dc-getresp)))
                             (if resp
                                           (let ((ires (dc-intresp resp)))
                                             (if (and ires (= (car ires) srchid))
                                                 (begin (set! info-searcheta (+ (current-time) (cadr ires)))
-                                                       (logf (string-append "search rescheduled to T+" (number->string (cadr ires))))))))
+                                                       (logf (string-append "search rescheduled to T+" (number->string (cadr ires))))
+                                                       (write-info-file)))))
                                          ((621) ; Search committed
                                           (let ((ires (dc-intresp resp)))
                                             (if (and ires (= (car ires) srchid))
                                                 (begin (logf "search committed")
                                                        (set! info-searcheta 0)
-                                                       (set! lastsearch (current-time))))))
+                                                       (set! lastsearch (current-time))
+                                                       (write-info-file)))))
                                          ((622) ; Search result
                                           (let ((ires (list->vector (dc-intresp resp))))
-                                            (if (and ires (= (vector-ref ires 0) srchid)) (apply handlesr (map (lambda (n) (vector-ref ires n)) '(1 2 3 4 5 7))))))
+                                            (if (eq? (cdr (assoc 'search-mode session)) 'wait)
+                                                (set-cdr! (assoc 'search-mode session) 'normal))
+                                            (if (and ires (= (vector-ref ires 0) srchid)) (apply handlesr (map (lambda (n) (vector-ref ires n)) '(1 2 3 4 5 7 8))))))
                                          
                                          )
                                        )