diff options
author | Anonymized <anonymous@example.com> | 2018-01-19 07:35:15 +0100 |
---|---|---|
committer | Anonymized <anonymous@example.com> | 2018-01-19 07:41:53 +0100 |
commit | b57b4df2fcc4e72a73c1501e39810a94b6a1f9cd (patch) | |
tree | 0b6d0baea43925273b593df1be9a7d8e0c7eceab | |
parent | 012fc11c9ed68df7f64f39f5a3afde074d5acf2b (diff) | |
download | gnunet-guile2-b57b4df2fcc4e72a73c1501e39810a94b6a1f9cd.tar.gz gnunet-guile2-b57b4df2fcc4e72a73c1501e39810a94b6a1f9cd.zip |
wip keywords publish
-rwxr-xr-x | gnunet-guile | 70 | ||||
-rw-r--r-- | gnunet.scm | 41 |
2 files changed, 84 insertions, 27 deletions
diff --git a/gnunet-guile b/gnunet-guile index d1566c6..e806f8d 100755 --- a/gnunet-guile +++ b/gnunet-guile | |||
@@ -90,20 +90,41 @@ Download the URI to FILENAME using CONFIGURATION. | |||
90 | ;; directory-scan callback aka. publish/task/directory-scan | 90 | ;; directory-scan callback aka. publish/task/directory-scan |
91 | (define %directory-scanner #f) | 91 | (define %directory-scanner #f) |
92 | 92 | ||
93 | (define (publish/progress info) | 93 | (define (publish/keywords-callback uri error) |
94 | (let ((status (fs-progress-info-status info))) | 94 | (if error |
95 | (cond | 95 | (format #t "* Error while publishing keywords: ~a\n" error) |
96 | ((eq? status %fs-status-publish-start) | 96 | (format #t "* Keywords published\n")) |
97 | (format #t "* Publishing started!\n")) | 97 | (scheduler-shutdown)) |
98 | ((eq? status %fs-status-publish-progress) | 98 | |
99 | (format #t "* Publishing in progress...\n")) | 99 | (define (publish/keywords fs keywords uri) |
100 | ((eq? status %fs-status-publish-error) | 100 | (fs-publish-ksk fs |
101 | (format #t "* Error publishing: ~a!\n" (fs-progress-info-publish-error info)) | 101 | (apply fs-uri-ksk-create keywords) |
102 | (scheduler-shutdown)) | 102 | uri |
103 | ((eq? status %fs-status-publish-completed) | 103 | (fs-block-options) |
104 | (format #t "* Publishing '~a' done.\n" (fs-progress-info-publish-filename info)) | 104 | %fs-publish-option-none |
105 | (format #t "* URI is '~a'\n" (fs-progress-info-publish-chk-uri info)) | 105 | publish/keywords-callback)) |
106 | (scheduler-shutdown))))) | 106 | |
107 | (define (publish/progress keywords) | ||
108 | (lambda (info) | ||
109 | (let ((status (fs-progress-info-status info))) | ||
110 | (cond | ||
111 | ((eq? status %fs-status-publish-start) | ||
112 | (format #t "* Publishing started!\n")) | ||
113 | ((eq? status %fs-status-publish-progress) | ||
114 | (format #t "* Publishing in progress...\n")) | ||
115 | ((eq? status %fs-status-publish-error) | ||
116 | (format #t "* Error publishing: ~a!\n" (fs-progress-info-publish-error info)) | ||
117 | (scheduler-shutdown)) | ||
118 | ((eq? status %fs-status-publish-completed) | ||
119 | (format #t "* Publishing '~a' done.\n" (fs-progress-info-publish-filename info)) | ||
120 | (format #t | ||
121 | "* URI is '~a'\n" | ||
122 | (uri->string (fs-progress-info-publish-chk-uri info))) | ||
123 | (if (null? keywords) | ||
124 | (scheduler-shutdown) | ||
125 | (publish/keywords (fs-progress-info-fs info) | ||
126 | keywords | ||
127 | (fs-progress-info-publish-chk-uri info)))))))) | ||
107 | 128 | ||
108 | (define (publish/task/shutdown publish-context) | 129 | (define (publish/task/shutdown publish-context) |
109 | (lambda () | 130 | (lambda () |
@@ -125,7 +146,8 @@ Download the URI to FILENAME using CONFIGURATION. | |||
125 | (let ((fi (fs-file-information-create-from-file | 146 | (let ((fi (fs-file-information-create-from-file |
126 | fs | 147 | fs |
127 | (fs-share-tree-item-filename share-tree) | 148 | (fs-share-tree-item-filename share-tree) |
128 | (fs-share-tree-item-ksk-uri share-tree) | 149 | ;; XXX: force keyword to be 'jjj' |
150 | (fs-uri-ksk-create "jjj") ;; (fs-share-tree-item-ksk-uri share-tree) | ||
129 | (fs-share-tree-item-meta share-tree) | 151 | (fs-share-tree-item-meta share-tree) |
130 | %gnunet-yes | 152 | %gnunet-yes |
131 | (fs-block-options)))) | 153 | (fs-block-options)))) |
@@ -136,35 +158,35 @@ Download the URI to FILENAME using CONFIGURATION. | |||
136 | (scheduler-shutdown)) | 158 | (scheduler-shutdown)) |
137 | (else (error "should not happen"))))) | 159 | (else (error "should not happen"))))) |
138 | 160 | ||
139 | (define (publish/task configuration filename) | 161 | (define (publish/task configuration filename keywords) |
140 | (lambda () | 162 | (lambda () |
141 | (let ((fs (fs-start configuration "gnunet-guile" publish/progress))) | 163 | (let ((fs (fs-start configuration "gnunet-guile" (publish/progress keywords)))) |
142 | (set! %directory-scanner | 164 | (set! %directory-scanner |
143 | (fs-directory-scan-start filename | 165 | (fs-directory-scan-start filename |
144 | #t | 166 | #t |
145 | (publish/task/directory-scan fs)))))) | 167 | (publish/task/directory-scan fs)))))) |
146 | 168 | ||
147 | (define (publish-exec configuration filename) | 169 | (define (publish-exec configuration filename keywords) |
148 | (let ((configuration* (configuration-create))) | 170 | (let ((configuration* (configuration-create))) |
149 | (configuration-load! configuration* configuration) | 171 | (configuration-load! configuration* configuration) |
150 | (scheduler-run (publish/task configuration* filename)))) | 172 | (scheduler-run (publish/task configuration* filename keywords)))) |
151 | 173 | ||
152 | (define %publish-options | 174 | (define %publish-options |
153 | '((help (single-char #\h) (value #f)))) | 175 | '((help (single-char #\h) (value #f)))) |
154 | 176 | ||
155 | (define (publish args) | 177 | (define (publish args) |
156 | "gnunet-guile publish CONFIGURATION FILE | 178 | "gnunet-guile publish CONFIGURATION FILE [KEYWORDS...] |
157 | 179 | ||
158 | Publish on gnunet FILE using CONFIGURATION | 180 | Publish on gnunet FILE using CONFIGURATION using KEYWORDS |
159 | " | 181 | " |
160 | (let ((options (getopt-long (cons "gnunet-guile publish" args) | 182 | (let ((options (getopt-long (cons "gnunet-guile publish" args) |
161 | %download-options | 183 | %download-options |
162 | #:stop-at-first-non-option #f))) | 184 | #:stop-at-first-non-option #f))) |
163 | (if (option-ref options 'help #f) | 185 | (if (option-ref options 'help #f) |
164 | (display (procedure-documentation download)) | 186 | (display (procedure-documentation publish)) |
165 | (match args | 187 | (match args |
166 | ((configuration file) | 188 | ((configuration file keywords ...) |
167 | (publish-exec configuration file)))))) | 189 | (publish-exec configuration file keywords)))))) |
168 | 190 | ||
169 | ;;; cli | 191 | ;;; cli |
170 | 192 | ||
@@ -16,6 +16,7 @@ | |||
16 | ;;;; along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | ;;;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | (define-module (gnunet)) | 17 | (define-module (gnunet)) |
18 | 18 | ||
19 | (use-modules ((web uri))) | ||
19 | (use-modules ((ice-9 iconv))) | 20 | (use-modules ((ice-9 iconv))) |
20 | (use-modules ((rnrs bytevectors))) | 21 | (use-modules ((rnrs bytevectors))) |
21 | (use-modules ((system foreign) #:prefix ffi:)) | 22 | (use-modules ((system foreign) #:prefix ffi:)) |
@@ -107,6 +108,13 @@ defaults." | |||
107 | (check (func configuration (ffi:string->pointer filename)) | 108 | (check (func configuration (ffi:string->pointer filename)) |
108 | (format #f "Impossible to load configuration at ~a" filename))))) | 109 | (format #f "Impossible to load configuration at ~a" filename))))) |
109 | 110 | ||
111 | ;; container, gnunet_container_lib.h | ||
112 | |||
113 | (define-public container-meta-data-create | ||
114 | (let ((func (util '* "GNUNET_CONTAINER_meta_data_create"))) | ||
115 | (lambda () | ||
116 | (func)))) | ||
117 | |||
110 | ;; crypto, gnunet_crypto_lib.h | 118 | ;; crypto, gnunet_crypto_lib.h |
111 | 119 | ||
112 | (define %crypto-hash-code (bs:struct `((bits ,(bs:vector 16 uint32))))) | 120 | (define %crypto-hash-code (bs:struct `((bits ,(bs:vector 16 uint32))))) |
@@ -519,9 +527,8 @@ Return unique task identifier for the job, valid until THUNK is started." | |||
519 | (bytestructure-ref info 'value 'publish 'filename)))) | 527 | (bytestructure-ref info 'value 'publish 'filename)))) |
520 | 528 | ||
521 | (define-public (fs-progress-info-publish-chk-uri info) | 529 | (define-public (fs-progress-info-publish-chk-uri info) |
522 | (uri->string | 530 | (ffi:make-pointer |
523 | (ffi:make-pointer | 531 | (bytestructure-ref info 'value 'publish 'specifics 'completed 'chk-uri))) |
524 | (bytestructure-ref info 'value 'publish 'specifics 'completed 'chk-uri)))) | ||
525 | 532 | ||
526 | (define (progress-callback-wrapper callback) | 533 | (define (progress-callback-wrapper callback) |
527 | (lambda (_ info) | 534 | (lambda (_ info) |
@@ -755,6 +762,34 @@ fs-directory-scan-start" | |||
755 | do-index | 762 | do-index |
756 | (bytestructure->pointer options))))) | 763 | (bytestructure->pointer options))))) |
757 | 764 | ||
765 | (define (callback->publish-continuation callback) | ||
766 | (ffi:procedure->pointer ffi:void | ||
767 | (lambda (_ uri error) | ||
768 | (callback uri | ||
769 | (if (eq? ffi:%null-pointer) | ||
770 | #f | ||
771 | (ffi:pointer->string error)))) | ||
772 | '(* * *))) | ||
773 | |||
774 | (define-public fs-publish-ksk | ||
775 | (let ((func (fs '* "GNUNET_FS_publish_ksk" '* '* '* '* '* ffi:int '* '*))) | ||
776 | (lambda (fs ksk-uri uri block-options publish-options callback) | ||
777 | "Publish a KBlock on GNUnet." | ||
778 | (func fs | ||
779 | ksk-uri | ||
780 | (container-meta-data-create) ;; ffi:%null-pointer ;; meta | ||
781 | uri | ||
782 | (bytestructure->pointer block-options) | ||
783 | publish-options | ||
784 | (callback->publish-continuation callback) | ||
785 | ffi:%null-pointer)))) | ||
786 | |||
787 | (define-public (fs-uri-ksk-create keyword . keywords) | ||
788 | "Build a KSK uri from KEYWORD and KEYWORDS. Prefix the keyword | ||
789 | with + if it must be mandatory" | ||
790 | (let ((keywords (cons keyword keywords))) | ||
791 | (let ((path (string-join (map uri-encode keywords) "+"))) | ||
792 | (string->uri (string-append "gnunet://fs/ksk/" path))))) | ||
758 | 793 | ||
759 | ;; gnunet-identity bindings | 794 | ;; gnunet-identity bindings |
760 | 795 | ||