80 lines
2.8 KiB
Scheme
Executable File
80 lines
2.8 KiB
Scheme
Executable File
#!/usr/bin/guile \
|
||
-e (@\ (gnunet-search)\ main) -L . -s
|
||
!#
|
||
;;;; Copyright © 2015 Rémi Delrue <asgeir@free.fr>
|
||
;;;;
|
||
;;;; This program is free software: you can redistribute it and/or modify
|
||
;;;; it under the terms of the GNU General Public License as published by
|
||
;;;; the Free Software Foundation, either version 3 of the License, or
|
||
;;;; (at your option) any later version.
|
||
;;;;
|
||
;;;; This program is distributed in the hope that it will be useful,
|
||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
;;;; GNU General Public License for more details.
|
||
;;;;
|
||
;;;; You should have received a copy of the GNU General Public License
|
||
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
||
(define-module (gnunet-search)
|
||
#:use-module (ice-9 match)
|
||
#:use-module (system foreign)
|
||
#:use-module (gnu gnunet container metadata)
|
||
#:use-module (gnu gnunet fs)
|
||
#:use-module (gnu gnunet fs uri)
|
||
#:use-module (gnu gnunet fs progress-info)
|
||
#:use-module (gnu gnunet configuration)
|
||
#:use-module (gnu gnunet scheduler)
|
||
#:export (main))
|
||
|
||
;; (use-modules (ice-9 match))
|
||
;; (use-modules (system foreign))
|
||
;; (use-modules (gnu gnunet container metadata))
|
||
;; (use-modules (gnu gnunet fs))
|
||
;; (use-modules (gnu gnunet fs uri))
|
||
;; (use-modules (gnu gnunet fs progress-info))
|
||
;; (use-modules (gnu gnunet configuration))
|
||
;; (use-modules (gnu gnunet scheduler))
|
||
|
||
(define config-file "~/.gnunet/gnunet.conf")
|
||
(define count-limit 10)
|
||
|
||
|
||
(define (result-cb %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)))))))))
|
||
|
||
(define (main args)
|
||
(let ((config (load-configuration config-file)))
|
||
(define (first-task _)
|
||
(let ((search-service
|
||
(search-service-open config #:result result-cb)))
|
||
(let ((current-search (start-ksk-search search-service (cdr args))))
|
||
;; adds a timeout in 5 seconds
|
||
(add-task! (lambda (_)
|
||
(stop-search current-search))
|
||
#:delay (* 5 1000 1000)))))
|
||
(call-with-scheduler config first-task)))
|