81 lines
2.8 KiB
Plaintext
81 lines
2.8 KiB
Plaintext
#!@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 common)
|
||
#: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))
|
||
|
||
(define *config-file* "~/.gnunet/gnunet.conf")
|
||
(define *config* (load-configuration *config-file*))
|
||
|
||
(define *fs-handle* #f)
|
||
(define *search-uri* #f)
|
||
(define *search-handle* #f)
|
||
|
||
|
||
(define (main args)
|
||
(if (= 1 (length args))
|
||
(simple-format #t "Usage: ~a KEY...\n" (car args))
|
||
(call-with-scheduler *config* (first-task args))))
|
||
|
||
(define (first-task args)
|
||
(lambda (_)
|
||
(set! *fs-handle* (open-filesharing-service *config* (car args)
|
||
progress-cb))
|
||
(set! *search-uri* (apply make-ksk-uri (cdr args)))
|
||
(set! *search-handle* (start-search *fs-handle* *search-uri*))
|
||
;; add a timeout in 5 seconds
|
||
(add-task! (lambda (_) (stop-search *search-handle*))
|
||
#:delay (time-rel #:seconds 5))))
|
||
|
||
(define (progress-cb info status)
|
||
(when (equal? '(#:search #:result) status)
|
||
(let* ((meta (pinfo-search-metadata info))
|
||
(uri (uri->string (pinfo-search-uri info)))
|
||
(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)))))
|
||
(when (equal? '(#:search #:stopped) status)
|
||
(add-task! (lambda (_)
|
||
(close-filesharing-service! *fs-handle*)))))
|
||
|
||
;; Local Variables:
|
||
;; mode: scheme
|
||
;; End:
|