diff options
author | Anonymized <anonymous@example.com> | 2018-01-19 22:24:45 +0100 |
---|---|---|
committer | Anonymized <anonymous@example.com> | 2018-01-19 22:24:45 +0100 |
commit | 181af609eb4065d8e2393aca41520c9d1be0538d (patch) | |
tree | e351f798f6a0d8eb255b544af94658760c4be37f | |
parent | 199fdf1337f2377ea3925efc249181cb36900705 (diff) | |
download | gnunet-guile2-181af609eb4065d8e2393aca41520c9d1be0538d.tar.gz gnunet-guile2-181af609eb4065d8e2393aca41520c9d1be0538d.zip |
add gnunet-guile search
-rwxr-xr-x | gnunet-guile | 39 | ||||
-rw-r--r-- | gnunet.scm | 18 |
2 files changed, 55 insertions, 2 deletions
diff --git a/gnunet-guile b/gnunet-guile index 0edde50..ea6701b 100755 --- a/gnunet-guile +++ b/gnunet-guile | |||
@@ -151,7 +151,7 @@ Download the URI to FILENAME using CONFIGURATION. | |||
151 | (define (publish args) | 151 | (define (publish args) |
152 | "gnunet-guile publish CONFIGURATION FILE [KEYWORDS...] | 152 | "gnunet-guile publish CONFIGURATION FILE [KEYWORDS...] |
153 | 153 | ||
154 | Publish on gnunet FILE using CONFIGURATION using KEYWORDS | 154 | Publish on gnunet FILE using CONFIGURATION using KEYWORDS. |
155 | " | 155 | " |
156 | (let ((options (getopt-long (cons "gnunet-guile publish" args) | 156 | (let ((options (getopt-long (cons "gnunet-guile publish" args) |
157 | %download-options | 157 | %download-options |
@@ -162,10 +162,45 @@ Publish on gnunet FILE using CONFIGURATION using KEYWORDS | |||
162 | ((configuration file keywords ...) | 162 | ((configuration file keywords ...) |
163 | (publish-exec configuration file keywords)))))) | 163 | (publish-exec configuration file keywords)))))) |
164 | 164 | ||
165 | ;;; search | ||
166 | |||
167 | (define (search/progress info) | ||
168 | (let ((status (fs-progress-info-status info))) | ||
169 | (cond | ||
170 | ((eq? status %fs-status-search-start) | ||
171 | (format #t "* Search in progress...\n")) | ||
172 | ((eq? status %fs-status-search-result) | ||
173 | (format #t "** ~a\n" (uri->string (fs-progress-info-search-result-uri info)))) | ||
174 | ((eq? status %fs-status-search-error) | ||
175 | (format #t "* Error searching: ~a\n" (fs-progress-info-search-error-message info)))))) | ||
176 | |||
177 | (define (search/task configuration uri) | ||
178 | (lambda () | ||
179 | (let ((fs (fs-start configuration "gnunet-guile" search/progress))) | ||
180 | (fs-search-start fs uri 1 %fs-search-option-none)))) | ||
181 | |||
182 | (define (search-exec configuration keywords) | ||
183 | (let ((configuration* (configuration-create)) | ||
184 | (uri (apply fs-uri-ksk-create keywords))) | ||
185 | (configuration-load! configuration* configuration) | ||
186 | (scheduler-run (search/task configuration* uri)))) | ||
187 | |||
188 | (define (search args) | ||
189 | "gnunet-guile search CONFIGURATION KEYWORDS... | ||
190 | |||
191 | Lookup files in gnunet that match KEYWORDS query using CONFIGURATION. | ||
192 | " | ||
193 | (match args | ||
194 | ((configuration keywords ...) | ||
195 | (if (null? keywords) | ||
196 | (format #t "No keywords provided!\n") | ||
197 | (search-exec configuration keywords))))) | ||
198 | |||
165 | ;;; cli | 199 | ;;; cli |
166 | 200 | ||
167 | (define %cli `((download ,download) | 201 | (define %cli `((download ,download) |
168 | (publish ,publish))) | 202 | (publish ,publish) |
203 | (search ,search))) | ||
169 | 204 | ||
170 | (define-public (main args) | 205 | (define-public (main args) |
171 | (subcommand 'gnunet-guile %cli (cdr args))) | 206 | (subcommand 'gnunet-guile %cli (cdr args))) |
@@ -530,6 +530,14 @@ Return unique task identifier for the job, valid until THUNK is started." | |||
530 | (ffi:make-pointer | 530 | (ffi:make-pointer |
531 | (bytestructure-ref info 'value 'publish 'specifics 'completed 'chk-uri))) | 531 | (bytestructure-ref info 'value 'publish 'specifics 'completed 'chk-uri))) |
532 | 532 | ||
533 | (define-public (fs-progress-info-search-result-uri info) | ||
534 | (ffi:make-pointer | ||
535 | (bytestructure-ref info 'value 'search 'specifics 'result 'uri))) | ||
536 | |||
537 | (define-public (fs-progress-info-search-error-message info) | ||
538 | (ffi:pointer->string | ||
539 | (bytestructure-ref info 'value 'search 'specifics 'error 'message))) | ||
540 | |||
533 | (define (progress-callback-wrapper callback) | 541 | (define (progress-callback-wrapper callback) |
534 | (lambda (_ info) | 542 | (lambda (_ info) |
535 | (callback (pointer->bytestructure %fs-progress-info info)))) | 543 | (callback (pointer->bytestructure %fs-progress-info info)))) |
@@ -791,6 +799,16 @@ with + if it must be mandatory" | |||
791 | (let ((path (string-join (map uri-encode keywords) "+"))) | 799 | (let ((path (string-join (map uri-encode keywords) "+"))) |
792 | (string->uri (string-append "gnunet://fs/ksk/" path))))) | 800 | (string->uri (string-append "gnunet://fs/ksk/" path))))) |
793 | 801 | ||
802 | ;;; search | ||
803 | |||
804 | (define-public %fs-search-option-none 0) | ||
805 | (define-public %fs-search-option-loopback-only 1) | ||
806 | |||
807 | (define-public fs-search-start | ||
808 | (let ((func (fs '* "GNUNET_FS_search_start" '* '* ffi:uint32 ffi:int '*))) | ||
809 | (lambda (fs uri anonymity options) | ||
810 | (func fs uri anonymity options ffi:%null-pointer)))) | ||
811 | |||
794 | ;; gnunet-identity bindings | 812 | ;; gnunet-identity bindings |
795 | 813 | ||
796 | (define identity (dynamic-link* %libgnunet-identity)) | 814 | (define identity (dynamic-link* %libgnunet-identity)) |