1 #lang typed/racket/no-check
10 (require (prefix-in info: "info.rkt"))
18 (define-type Out-Format
22 (define-type Timeline-Order
27 (∀ (α β) (U (cons 'ok α)
33 [nick : (Option String)]
36 [mentions : (Listof Peer)]))
39 ([nick : (Option String)]
42 [comment : (Option String)])
46 ([status-line : String]
47 [headers : (Listof Bytes)]
48 [body-input : Input-Port])
51 (define-custom-set-types peers
54 (equal? (Peer-uri-str p1)
57 (equal-hash-code (Peer-uri-str p))))
58 ; XXX Without supplying above explicit hash procedure, we INTERMITTENTLY get
59 ; the following contract violations:
61 ; custom-elem-contents: contract violation
62 ; expected: custom-elem?
65 ; /usr/share/racket/collects/racket/private/set-types.rkt:104:0: custom-set->list
66 ; /home/siraaj/proj/pub/tt/tt.rkt:716:0: crawl
67 ; /usr/share/racket/collects/racket/cmdline.rkt:191:51
68 ; body of (submod "/home/siraaj/proj/pub/tt/tt.rkt" main)
70 ; TODO Investigate why and make a minimal reproducible test case.
72 (: tt-home-dir Path-String)
73 (define tt-home-dir (build-path (expand-user-path "~") ".tt"))
75 (: concurrent-filter-map (∀ (α β) (-> Natural (-> α β) (Listof α) (Listof β))))
76 (define (concurrent-filter-map num-workers f xs)
77 ; TODO preserve order of elements OR communicate that reorder is expected
78 ; TODO switch from mailboxes to channels
79 (define (make-worker id f)
80 (define parent (current-thread))
82 (define self : Thread (current-thread))
83 (: work (∀ (α) (-> α)))
85 (thread-send parent (cons 'next self))
86 (match (thread-receive)
87 ['done (thread-send parent (cons 'exit id))]
88 [(cons 'unit x) (begin
90 (when y (thread-send parent (cons 'result y)))
93 (: dispatch (∀ (α β) (-> (Listof Nonnegative-Integer) (Listof α) (Listof β))))
94 (define (dispatch ws xs ys)
97 (match (thread-receive)
98 [(cons 'exit w) (dispatch (remove w ws =) xs ys)]
99 [(cons 'result y) (dispatch ws xs (cons y ys))]
100 [(cons 'next thd) (match xs
102 (thread-send thd 'done)
103 (dispatch ws xs ys))]
105 (thread-send thd (cons 'unit x))
106 (dispatch ws xs ys))])])))
107 (define workers (range num-workers))
108 (define threads (map (λ (id) (thread (make-worker id f))) workers))
109 (define results (dispatch workers xs '()))
110 (for-each thread-wait threads)
114 (let* ([f (λ (x) (if (even? x) x #f))]
116 [actual (sort (concurrent-filter-map 10 f xs) <)]
117 [expected (sort ( filter-map f xs) <)])
118 (check-equal? actual expected "concurrent-filter-map")))
120 (: msg-print (-> Out-Format Integer Msg Void))
122 (let* ([colors (vector 36 33)]
123 [n (vector-length colors)])
124 (λ (out-format color-i msg)
125 (let ([color (vector-ref colors (modulo color-i n))]
126 [nick (Msg-nick msg)]
127 [uri (url->string (Msg-uri msg))]
128 [text (Msg-text msg)]
129 [mentions (Msg-mentions msg)])
132 (let ([nick (if nick nick uri)])
133 (printf "~a \033[1;37m<~a>\033[0m \033[0;~am~a\033[0m~n"
135 ([date-display-format 'iso-8601])
136 (date->string (seconds->date (Msg-ts-epoch msg)) #t))
139 (let ([nick (if nick (string-append nick " ") "")])
140 (printf "~a (~a)~n\033[1;37m<~a~a>\033[0m~n\033[0;~am~a\033[0m~n~n"
142 ([date-display-format 'rfc2822])
143 (date->string (seconds->date (Msg-ts-epoch msg)) #t))
145 nick uri color text))])))))
147 (: rfc3339->epoch (-> String (Option Nonnegative-Integer)))
148 (define rfc3339->epoch
149 (let ([re (pregexp "^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(:([0-9]{2}))?(\\.[0-9]+)?(Z|([+-])([0-9]{1,2}):?([0-9]{2}))?$")])
151 (match (regexp-match re ts)
152 [(list _wholething yyyy mm dd HH MM _:SS SS _fractional tz-whole tz-sign tz-HH tz-MM)
155 (match* (tz-whole tz-sign tz-HH tz-MM)
158 [(_ (or "-" "+") (? identity h) (? identity m))
159 (let ([h (string->number h)]
160 [m (string->number m)]
161 ; Reverse to get back to UTC:
162 [op (match tz-sign ["+" -] ["-" +])])
163 (op 0 (+ (* 60 m) (* 60 (* 60 h)))))]
165 (log-warning "Impossible TZ string: ~v, components: ~v ~v ~v ~v" tz-whole a b c d)
169 [ts-epoch (find-seconds (if SS (string->number SS) 0)
174 (string->number yyyy)
176 (+ ts-epoch tz-offset))]
178 (log-debug "Invalid timestamp: ~v" ts)
181 (: str->msg (-> (Option String) Url String (Option Msg)))
183 (let ([re (pregexp "^([^\\s\t]+)[\\s\t]+(.*)$")])
185 (define str-head (substring str 0 (min 100 (string-length str))))
190 "Failed to parse msg: ~v, from: ~v, at: ~v, because: ~v"
191 str-head nick (url->string uri) e)
193 (match (regexp-match re str)
194 [(list _wholething ts-orig text)
195 (let ([ts-epoch (rfc3339->epoch ts-orig)])
199 (λ (m) (match (regexp-match #px"@<([^>]+)>" m)
200 [(list _wholething nick-uri)
201 (str->peer nick-uri)]))
202 (regexp-match* #px"@<[^\\s]+([\\s]+)?[^>]+>" text))])
203 (Msg ts-epoch ts-orig nick uri text mentions))
206 "Msg rejected due to invalid timestamp: ~v, nick:~v, uri:~v"
207 str-head nick (url->string uri))
210 (log-debug "Non-msg line from nick:~v, line:~a" nick str-head)
214 ; TODO Test for when missing-nick case
215 (let* ([tzs (for*/list ([d '("-" "+")]
217 [m '("00" ":00" "57" ":57")])
218 (string-append d h m))]
219 [tzs (list* "" "Z" tzs)])
220 (for* ([n '("fake-nick")]
225 [sep (list "\t" " ")]
226 [txt '("foo bar baz" "'jaz poop bear giraffe / tea" "@*\"``")])
227 (let* ([ts (string-append "2020-11-18T22:22"
228 (if (non-empty-string? s) s ":00")
230 [m (str->msg n u (string-append ts sep txt))])
232 (check-equal? (Msg-nick m) n)
233 (check-equal? (Msg-uri m) u)
234 (check-equal? (Msg-text m) txt)
235 (check-equal? (Msg-ts-orig m) ts (format "Given: ~v" ts))
238 (let* ([ts "2020-11-18T22:22:09-0500"]
243 [actual (str->msg nick uri (string-append ts tab text))]
244 [expected (Msg 1605756129 ts nick uri text '())])
246 (Msg-ts-epoch actual)
247 (Msg-ts-epoch expected)
251 (Msg-ts-orig expected)
266 (: str->lines (-> String (Listof String)))
267 (define (str->lines str)
268 (string-split str (regexp "[\r\n]+")))
271 (check-equal? (str->lines "abc\ndef\n\nghi") '("abc" "def" "ghi")))
273 (: str->msgs (-> (Option String) Url String (Listof Msg)))
274 (define (str->msgs nick uri str)
275 (filter-map (λ (line) (str->msg nick uri line)) (filter-comments (str->lines str))))
277 (: cache-dir Path-String)
278 (define cache-dir (build-path tt-home-dir "cache"))
280 (define cache-object-dir (build-path cache-dir "objects"))
282 (: url->cache-file-path-v1 (-> Url Path-String))
283 (define (url->cache-file-path-v1 uri)
284 (define (hash-sha1 str) : (-> String String)
285 (define in (open-input-string str))
286 (define digest (sha1 in))
287 (close-input-port in)
289 (build-path cache-object-dir (hash-sha1 (url->string uri))))
291 (: url->cache-file-path-v2 (-> Url Path-String))
292 (define (url->cache-file-path-v2 uri)
293 (build-path cache-object-dir (uri-encode (url->string uri))))
295 (define url->cache-object-path url->cache-file-path-v2)
297 (: cache-object-filename->url (-> Path-String Url))
298 (define (cache-object-filename->url name)
299 (string->url (uri-decode (path->string name))))
301 (define (url->cache-etag-path uri)
302 (build-path cache-dir "etags" (uri-encode (url->string uri))))
304 (define (url->cache-lmod-path uri)
305 (build-path cache-dir "lmods" (uri-encode (url->string uri))))
307 (: uri-read-cached (-> Url (Option String)))
308 (define (uri-read-cached uri)
309 (define path-v1 (url->cache-file-path-v1 uri))
310 (define path-v2 (url->cache-file-path-v2 uri))
311 (when (file-exists? path-v1)
312 (rename-file-or-directory path-v1 path-v2 #t))
313 (if (file-exists? path-v2)
314 (file->string path-v2)
316 (log-debug "Cache file not found for URI: ~a" (url->string uri))
319 (: str->url (-> String (Option String)))
322 ([exn:fail? (λ (e) #f)])
325 (: str->peer (String (Option Peer)))
326 (define (str->peer str)
327 (log-debug "Parsing peer string: ~v" str)
330 #px"(([^\\s\t]+)[\\s\t]+)?([a-zA-Z]+://[^\\s\t]*)[\\s\t]*(#\\s*(.*))?"
338 (match (str->url url)
340 (log-error "Invalid URI in peer string: ~v" str)
343 (Peer nick url (url->string url) comment)])]
345 (log-debug "Invalid peer string: ~v" str)
350 (str->peer "foo http://bar/file.txt # some rando")
351 (Peer "foo" (str->url "http://bar/file.txt") "http://bar/file.txt" "some rando"))
353 (str->peer "http://bar/file.txt # some rando")
354 (Peer #f (str->url "http://bar/file.txt") "http://bar/file.txt" "some rando"))
356 (str->peer "http://bar/file.txt #")
357 (Peer #f (str->url "http://bar/file.txt") "http://bar/file.txt" ""))
359 (str->peer "http://bar/file.txt#") ; XXX URLs can have #s
360 (Peer #f (str->url "http://bar/file.txt#") "http://bar/file.txt#" #f))
362 (str->peer "http://bar/file.txt")
363 (Peer #f (str->url "http://bar/file.txt") "http://bar/file.txt" #f))
365 (str->peer "foo http://bar/file.txt")
366 (Peer "foo" (str->url "http://bar/file.txt") "http://bar/file.txt" #f))
368 (str->peer "foo bar # baz")
371 (str->peer "foo bar://baz # quux")
372 (Peer "foo" (str->url "bar://baz") "bar://baz" "quux"))
374 (str->peer "foo bar//baz # quux")
377 (: filter-comments (-> (Listof String) (Listof String)))
378 (define (filter-comments lines)
379 (filter-not (λ (line) (string-prefix? line "#")) lines))
381 (: str->peers (-> String (Setof Peer)))
382 (define (str->peers str)
383 (make-immutable-peers (filter-map str->peer (filter-comments (str->lines str)))))
385 (: peers->file (-> (Setof Peers) Path-String Void))
386 (define (peers->file peers path)
387 (display-lines-to-file
391 (if n (format "~a " n) "")
393 (if c (format " # ~a" c) ""))])
394 (sort (set->list peers)
396 [((Peer n1 _ _ _) (Peer n2 _ _ _))
397 (string<? (if n1 n1 "")
402 (: file->peers (-> Path-String (Setof Peer)))
403 (define (file->peers file-path)
404 (if (file-exists? file-path)
405 (str->peers (file->string file-path))
407 (log-warning "File does not exist: ~v" (path->string file-path))
408 (make-immutable-peers))))
411 #px"^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-9]{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([0-9]{4}) ([0-2][0-9]):([0-6][0-9]):([0-6][0-9]) GMT")
413 (: b->n (-> Bytes (Option Number)))
415 (string->number (bytes->string/utf-8 b)))
417 (: mon->num (-> Bytes Natural))
418 (define/match (mon->num mon)
432 (: rfc2822->epoch (-> Bytes (Option Nonnegative-Integer)))
433 (define (rfc2822->epoch timestamp)
434 (match (regexp-match re-rfc2822 timestamp)
435 [(list _ _ dd mo yyyy HH MM SS)
436 #:when (and dd mo yyyy HH MM SS)
437 (find-seconds (b->n SS)
447 (: user-agent String)
451 [prog-version (info:#%info-lookup 'version)]
452 [prog-uri "https://github.com/xandkar/tt"]
453 [user-peer-file (build-path tt-home-dir "me")]
455 (if (file-exists? user-peer-file)
456 (match (set-first (file->peers user-peer-file))
457 [(Peer #f _ u _) (format "+~a" u )]
458 [(Peer n _ u _) (format "+~a; @~a" u n)])
459 (format "+~a" prog-uri))])
460 (format "~a/~a (~a)" prog-name prog-version user)))
462 (: header-get (-> (Listof Bytes) Bytes (Option Bytes)))
463 (define (header-get headers name)
464 (match (filter-map (curry extract-field name) headers)
468 (: uri-download-from-port
469 (-> Url (Listof (U Bytes String)) Input-Port
470 (U 'skipped-cached 'downloaded-new))) ; TODO 'ok|'error ?
471 (define (uri-download-from-port u headers body-input)
472 (define u-str (url->string u))
473 (log-debug "uri-download-from-port ~v into ~v" u-str cached-object-path)
474 (define cached-object-path (url->cache-object-path u))
475 (define cached-etag-path (url->cache-etag-path u))
476 (define cached-lmod-path (url->cache-lmod-path u))
477 (define etag (header-get headers #"ETag"))
478 (define lmod (header-get headers #"Last-Modified"))
479 (define lmod-curr (if lmod (rfc2822->epoch lmod) #f))
480 (define lmod-prev (if (file-exists? cached-lmod-path)
481 (rfc2822->epoch (file->bytes cached-lmod-path))
483 (log-debug "lmod-curr:~v lmod-prev:~v" lmod-curr lmod-prev)
486 (file-exists? cached-etag-path)
487 (bytes=? etag (file->bytes cached-etag-path))
489 (log-debug "ETags match, skipping the rest of ~v" u-str)
493 (<= lmod-curr lmod-prev)
495 (log-debug "Last-Modified <= current skipping the rest of ~v" u-str)
500 "Downloading the rest of ~v. ETag: ~a, Last-Modified: ~v"
502 (make-parent-directory* cached-object-path)
503 (make-parent-directory* cached-etag-path)
504 (make-parent-directory* cached-lmod-path)
505 (call-with-output-file cached-object-path
506 (curry copy-port body-input)
509 (display-to-file etag cached-etag-path #:exists 'replace))
511 (display-to-file lmod cached-lmod-path #:exists 'replace))
516 (-> Positive-Float Url
517 (Result (U 'skipped-cached 'downloaded-new)
518 Any))) ; TODO Maybe more-precise error type?
519 (define (uri-download timeout u)
520 (define u-str (url->string u))
521 (define timeout-chan (make-channel))
522 (define result-chan (make-channel))
523 (define timeout-thread
525 ; Doing this instead of sync/timeout to distinguish error values,
526 ; rather than just have #f to work with.
528 (channel-put timeout-chan '(error . timeout)))))
529 (define result-thread
531 ; XXX We timeout getting a response, but body download could
532 ; also take a long time and we might want to time that out as
533 ; well, but then we may end-up with partially downloaded
534 ; objects. But that could happen anyway if the server drops the
535 ; connection for whatever reason.
537 ; Maybe that is OK once we start treating the
538 ; downloaded object as an addition to the stored set of
539 ; messages, rather than the final set of messages.
542 ; - 1st try can just be an in-memory set that gets written-to
543 ; and read-from disk as a whole.
546 ; TODO Maybe name each known errno? (exn:fail:network:errno-errno e)
548 (λ (e) `(error . (net-error . ,e)))]
550 (λ (e) `(error . (other . ,e)))])
551 (define-values (status-line headers body-input)
554 #:headers (list (format "User-Agent: ~a" user-agent))))
555 `(ok . ,(Resp status-line headers body-input))))
556 (channel-put result-chan result))))
560 (kill-thread result-thread)
561 (kill-thread timeout-thread)
565 [(cons 'ok (Resp status-line headers body-input))
566 (log-debug "headers: ~v" headers)
567 (log-debug "status-line: ~v" status-line)
569 (string->number (second (string-split (bytes->string/utf-8 status-line)))))
570 (log-debug "status: ~v" status)
571 ; TODO Handle redirects. Should be within same timeout as req and body.
575 `(ok . ,(uri-download-from-port u headers body-input))]
577 `(error . (http . ,status))])])
578 (close-input-port body-input)
581 (: timeline-print (-> Out-Format (Listof Msg) Void))
582 (define (timeline-print out-format timeline)
583 (void (foldl (match-lambda**
584 [((and m (Msg _ _ nick _ _ _)) (cons prev-nick i))
585 (let ([i (if (equal? prev-nick nick) i (+ 1 i))])
586 (msg-print out-format i m)
591 (: peer->msgs (-> Peer (Listof Msg)))
592 (define (peer->msgs peer)
593 (match-define (Peer nick uri uri-str _) peer)
594 (log-debug "Reading peer nick:~v uri:~v" nick uri-str)
595 (define msgs-data (uri-read-cached uri))
598 (str->msgs nick uri msgs-data)
602 (-> Positive-Float Peer
603 (Result (U 'skipped-cached 'downloaded-new)
605 (define (peer-download timeout peer)
606 (match-define (Peer nick uri u _) peer)
607 (log-info "Download BEGIN URL:~a" u)
608 (define-values (results _tm-cpu-ms tm-real-ms _tm-gc-ms)
609 (time-apply uri-download (list timeout uri)))
610 (define result (car results))
611 (log-info "Download END in ~a seconds, URL:~a, result:~s"
612 (/ tm-real-ms 1000.0)
617 (: timeline-download (-> Integer Positive-Float (Setof Peer) Void))
618 (define (timeline-download num-workers timeout peers)
620 (concurrent-filter-map num-workers
621 (λ (p) (cons p (peer-download timeout p)))
624 (filter-map (match-lambda
625 [(cons p (cons 'ok _)) p]
626 [(cons _ (cons 'error e)) #f])
629 (filter-map (match-lambda
630 [(cons _ (cons 'ok _))
632 [(cons p (cons 'error e))
633 (struct-copy Peer p [comment (format "~s" e)])])
635 (peers->file peers-ok (build-path tt-home-dir "peers-last-downloaded-ok"))
636 (peers->file peers-err (build-path tt-home-dir "peers-last-downloaded-err")))
638 (: peers->timeline (-> (Listof Peer) (Listof Msg)))
639 (define (peers->timeline peers)
640 (append* (filter-map peer->msgs (set->list peers))))
642 (: timeline-sort (-> (Listof Msg) timeline-order (Listof Msgs)))
643 (define (timeline-sort msgs order)
644 (define cmp (match order
647 (sort msgs (λ (a b) (cmp (Msg-ts-epoch a)
650 (: paths->peers (-> (Listof String) (Setof Peer)))
651 (define (paths->peers paths)
652 (let* ([paths (match paths
654 (let ([peer-refs-file (build-path tt-home-dir "peers")])
656 "No peer ref file paths provided, defaulting to ~v"
657 (path->string peer-refs-file))
658 (list peer-refs-file))]
660 (log-debug "Peer ref file paths provided: ~v" paths)
661 (map string->path paths)])]
662 [peers (apply set-union (map file->peers paths))])
663 (log-info "Read-in ~a peers." (set-count peers))
666 (: mentioned-peers-in-cache (-> (Setof Peer)))
667 (define (mentioned-peers-in-cache)
670 (append* (map (λ (filename)
671 (define path (build-path cache-object-dir filename))
672 (define size (/ (file-size path) 1000000.0))
673 (log-debug "BEGIN parsing ~a MB from file: ~v"
676 (define t0 (current-inexact-milliseconds))
677 (define m (filter-map
679 (str->msg #f (cache-object-filename->url filename) line))
681 (file->lines path))))
682 (define t1 (current-inexact-milliseconds))
683 (log-debug "END parsing ~a MB in ~a seconds from file: ~v."
688 (log-debug "No messages found in ~a" (path->string path)))
690 (directory-list cache-object-dir))))
691 (make-immutable-peers (append* (map Msg-mentions msgs))))
693 (: log-writer-stop (-> Thread Void))
694 (define (log-writer-stop log-writer)
695 (log-message (current-logger) 'fatal 'stop "Exiting." #f)
696 (thread-wait log-writer))
698 (: log-writer-start (-> Log-Level Thread))
699 (define (log-writer-start level)
701 (make-logger #f #f level #f)]
703 (make-log-receiver logger level)]
708 ([date-display-format 'iso-8601])
710 (match-define (vector level msg _ topic) (sync log-receiver))
711 (unless (equal? topic 'stop)
712 (eprintf "~a [~a] ~a~n" (date->string (current-date) #t) level msg)
714 (current-logger logger)
719 (let* ([peers-all-file
720 (build-path tt-home-dir "peers-all")]
721 [peers-mentioned-file
722 (build-path tt-home-dir "peers-mentioned")]
724 (build-path tt-home-dir "peers-parsed")]
725 [peers-mentioned-curr
726 (mentioned-peers-in-cache)]
727 [peers-mentioned-prev
728 (file->peers peers-mentioned-file)]
730 (set-union peers-mentioned-prev
731 peers-mentioned-curr)]
733 (file->peers peers-all-file)]
735 (set-union peers-mentioned
738 (set-subtract peers-all
741 (for/set ([p peers-all] #:when (> (length (peer->msgs p)) 0)) p)])
742 ; TODO Deeper de-duping
743 (log-info "Known peers mentioned: ~a" (set-count peers-mentioned))
744 (log-info "Known peers parsed ~a" (set-count peers-parsed))
745 (log-info "Known peers total: ~a" (set-count peers-all))
746 (log-info "Discovered ~a new peers:~n~a"
747 (set-count peers-discovered)
750 [(Peer n _ u c) (list n u c)])
751 (set->list peers-discovered))))
752 (peers->file peers-mentioned
753 peers-mentioned-file)
754 (peers->file peers-parsed
756 (peers->file peers-all
759 (: read (-> (Listof String) Number Number Timeline-Order Out-Format Void))
760 (define (read file-paths ts-min ts-max order out-format)
762 (paths->peers file-paths)]
764 (timeline-sort (peers->timeline peers) order)]
767 (and (or (not ts-min) (>= (Msg-ts-epoch m) ts-min))
768 (or (not ts-max) (<= (Msg-ts-epoch m) ts-max))))])
769 (timeline-print out-format (filter include? msgs))))
773 ; FIXME Should not exit from here, but only after cleanup/logger-stoppage.
774 (if (system (path->string (build-path tt-home-dir "hooks" "upload")))
778 (: download (-> (Listof String) Positive-Integer Positive-Float Void))
779 (define (download file-paths num-workers timeout)
780 (let ([peers (paths->peers file-paths)])
781 (define-values (_res _cpu real-ms _gc)
782 (time-apply timeline-download (list num-workers timeout peers)))
783 (log-info "Downloaded timelines from ~a peers in ~a seconds."
785 (/ real-ms 1000.0))))
787 (: dispatch (-> String Void))
788 (define (dispatch command)
791 ; Initially, 15 was fastest out of the tried: 1, 5, 10, 20. Then I
792 ; started noticing significant slowdowns. Reducing to 5 seems to help.
793 (let ([num-workers 5]
796 #:program "tt download"
799 njobs "Number of concurrent jobs."
800 (set! num-workers (string->number njobs))]
802 seconds "Timeout seconds per request."
803 (set! timeout (string->number seconds))]
805 (download file-paths num-workers timeout)))]
808 #:program "tt upload" #:args () (upload))]
810 (let ([out-format 'multi-line]
818 "Reverse displayed timeline order."
819 (set! order 'new->old)]
821 m "Earliest time to display (ignore anything before it)."
822 (set! ts-min (rfc3339->epoch m))]
824 x "Latest time to display (ignore anything after it)."
825 (set! ts-max (rfc3339->epoch x))]
828 "Short output format"
829 (set! out-format 'single-line)]
832 (set! out-format 'multi-line)]
834 (read file-paths ts-min ts-max order out-format)))]
837 #:program "tt crawl" #:args () (crawl))]
839 (eprintf "Error: invalid command: ~v\n" command)
840 (eprintf "Please use the \"--help\" option to see a list of available commands.\n")
844 (let ([log-level 'info])
850 "Enable debug log level."
851 (set! log-level 'debug)]
854 "and <command> is one of"
855 "r, read : Read the timeline (offline operation)."
856 "d, download : Download the timeline."
857 ; TODO Add path dynamically
858 "u, upload : Upload your twtxt file (alias to execute ~/.tt/hooks/upload)."
859 "c, crawl : Discover new peers mentioned by known peers (offline operation)."
861 #:args (command . args)
862 (define log-writer (log-writer-start log-level))
863 (current-command-line-arguments (list->vector args))
864 ; TODO dispatch should return status with which we should exit after cleanups
866 (log-writer-stop log-writer))))