Add `time-rel` to replace all ad-hoc time calculations.

This commit is contained in:
Rémi Birot-Delrue 2015-08-03 15:57:09 +02:00
parent ff8e19b523
commit 12e8a31b23
8 changed files with 42 additions and 35 deletions

View File

@ -75,5 +75,5 @@
;; add a timeout in 5 seconds
(simple-format *stderr* "scheduler add: timeout\n")
(force-output *stderr*)
(add-task! shutdown-task #:delay (* 5 1000 1000))))))
(add-task! shutdown-task #:delay (time-rel #:seconds 5))))))
(call-with-scheduler config first-task)))

View File

@ -42,7 +42,7 @@
(define (first-task _)
(set! *handle* (start-ego-lookup *config* "testremi" print-ego))
(set! *kill-task* (add-task! shutdown-task #:delay (* 5 1000 1000))))
(set! *kill-task* (add-task! shutdown-task #:delay (time-rel #:seconds 5))))
(define (main args)
(set! *config* (load-configuration "~/.gnunet/gnunet.conf"))

View File

@ -42,7 +42,7 @@
(define (first-task _)
(set! *handle* (open-identity-service *config* print-ego))
(set! *kill-task* (add-task! shutdown-task #:delay (* 5 1000 1000))))
(set! *kill-task* (add-task! shutdown-task #:delay (time-rel #:seconds 5))))
(define (main args)
(set! *config* (load-configuration "~/.gnunet/gnunet.conf"))

View File

@ -74,7 +74,7 @@ demanded ego or call IDENTITY-CONTINUATION."
(set! *kill-task*
(add-task! (lambda (_)
(close-identity-service *identity-handle*))
#:delay (* 5 1000 1000))))
#:delay (time-rel #:seconds 5))))
((binary file-name)
(set! *binary-name* binary)
(set! *filename* file-name)
@ -111,7 +111,7 @@ scan on *FILENAME*."
(set! *kill-task* (add-task! (lambda (_)
(display "Stopping directory scan (unexpected)\n")
(stop-directory-scan *dir-scanner*))
#:delay (* 5 1000 1000))))
#:delay (time-rel #:seconds 5))))
(else
(simple-format #t "Error: no ego named ~a has been found!\n"
*namespace-name*)
@ -145,7 +145,7 @@ start the publication by calling DIRSCAN-CONTINUATION."
(set! *kill-task* (add-task! (lambda (_)
(display "Stopping publication (unexpected)\n")
(stop-publish *publish-handle*))
#:delay (* 5 1000 1000))))
#:delay (time-rel #:seconds 5))))
(define (progress-callback %info)
"The third callback, called repeteadly by the publishing tasks once the

View File

@ -19,6 +19,7 @@
(define-module (gnunet-search)
#:use-module (ice-9 match)
#:use-module (system foreign)
#:use-module (gnu gnunet common)
#:use-module (gnu gnunet configuration)
#:use-module (gnu gnunet scheduler)
#:use-module (gnu gnunet identity)
@ -57,7 +58,7 @@
(start-ego-lookup *config* *ns-name* ego-callback))
(set! *kill-task*
(add-task! (lambda (_) (stop-ego-lookup! *lookup-op*))
#:delay (* 5 1000 1000))))
#:delay (time-rel #:seconds 5))))
(define (ego-callback ego)
(cancel-task! *kill-task*)
@ -74,7 +75,7 @@
(set! *search-handle* (start-search *fs-handle* *uri*))
(set! *kill-task* (add-task! (lambda (_)
(stop-search *search-handle*))
#:delay (* 5 1000 1000)))
#:delay (time-rel #:seconds 5)))
(simple-format #t "Searching ~a\n" (uri->string *uri*)))))
(define (progress-callback %info)

View File

@ -19,6 +19,7 @@
(define-module (gnunet-search)
#:use-module (ice-9 match)
#:use-module (system foreign)
#:use-module (gnu gnunet common)
#:use-module (gnu gnunet container metadata)
#:use-module (gnu gnunet fs)
#:use-module (gnu gnunet fs uri)
@ -33,28 +34,26 @@
(define (progress-cb %info)
(when (equal? '(#:search #:result) (progress-info-status %info))
(match (parse-c-progress-info %info)
(((context cctx pctx query duration anonymity
(metadata uri result applicability-rank)) status handle)
(match (parse-c-struct result '(* * * *)) ; incomplete parse of result
((_ _ %uri %metadata)
(let* ((uri (uri->string (wrap-uri %uri)))
(meta (wrap-metadata %metadata))
(result-directory? (is-directory? meta))
(result-filename (metadata-ref meta #:original-filename)))
(cond ((and result-directory?
(string-null? result-filename))
(simple-format
#t "gnunet-download -o \"collection.gnd\" -R ~a\n" uri))
(result-directory?
(simple-format #t
"gnunet-download -o \"~a.gnd\" -R ~a\n"
result-filename uri))
((string-null? result-filename)
(simple-format #t "gnunet-download ~a\n"
uri))
(else
(simple-format #t "gnunet-download -o \"~a\" ~a\n"
result-filename uri))))))))))
(((context _ _ query duration anonymity
(%metadata %uri %result applicability-rank)) _ _)
(let* ((uri (uri->string (wrap-uri %uri)))
(meta (wrap-metadata %metadata))
(result-directory? (is-directory? meta))
(result-filename (metadata-ref meta #:original-filename)))
(cond ((and result-directory?
(string-null? result-filename))
(simple-format
#t "gnunet-download -o \"collection.gnd\" -R ~a\n" uri))
(result-directory?
(simple-format #t
"gnunet-download -o \"~a.gnd\" -R ~a\n"
result-filename uri))
((string-null? result-filename)
(simple-format #t "gnunet-download ~a\n"
uri))
(else
(simple-format #t "gnunet-download -o \"~a\" ~a\n"
result-filename uri))))))))
(define (main args)
(let ((config (load-configuration config-file)))
@ -65,5 +64,5 @@
(search (start-search fs-service uri)))
;; adds a timeout in 5 seconds
(add-task! (lambda (_) (stop-search search))
#:delay (* 5 1000 1000))))
#:delay (time-rel #:seconds 5))))
(call-with-scheduler config first-task)))

View File

@ -29,6 +29,8 @@
time-relative
time-absolute
time-rel
ecdsa-public-key
ecdsa-public-key?
eddsa-public-key
@ -59,6 +61,14 @@
(define time-relative uint64)
(define time-absolute uint64)
(define* (time-rel #:key (hours 0) (minutes 0) (seconds 0) (milli 0) (micro 0))
(let* ((minutes* (+ (* hours 60) minutes))
(seconds* (+ (* minutes* 60) seconds))
(milli* (+ (* seconds* 1000) milli))
(micro* (+ (* milli* 1000) micro)))
micro*))
(define ecdsa-public-key (generate (/ 256 8 4) uint32))
(define eddsa-public-key ecdsa-public-key)
(define eddsa-signature (list eddsa-public-key

View File

@ -241,9 +241,6 @@ callback."
;;
;;+TODO: dynamically allocate the entire structure & client-name, so that we can
;; call GNUNET_FS_stop on the returned handle.
;;
;;+TODO: replace value for avg_block_latency with a call to a function
;; akin `(time-relative #:minutes 1)`
(define (%fs-start %config %client-name %progress-callback)
(make-c-struct struct-fs-handle
(list %config
@ -260,7 +257,7 @@ callback."
%null-pointer ; probes_tail
%null-pointer ; queue_job
%null-pointer ; probe_ping_task
(* 60 1000 1000) ; avg_block_latency (1 minute)
(time-rel #:minutes 1) ; avg_block_latency
0 ; active_downloads
0 ; active_blocks
0 ; flags