aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnonymized <anonymous@example.com>2018-01-20 19:26:58 +0100
committerAnonymized <anonymous@example.com>2018-01-20 19:26:58 +0100
commitafa20be5af70e4dde1d883a4c131a01f1827dbfc (patch)
tree2926260e652d44634c9963c2eae4d42f9a2caa35
parent4aa02f873e3c40d10e2fdef1bba28a3d8a37bb51 (diff)
downloadgnunet-guile2-afa20be5af70e4dde1d883a4c131a01f1827dbfc.tar.gz
gnunet-guile2-afa20be5af70e4dde1d883a4c131a01f1827dbfc.zip
c3b2: use background thread to pull new messages (broken)
The program crash when trying to publish a message
-rw-r--r--gnunet/sync.scm11
-rw-r--r--guix.scm3
-rwxr-xr-xprototypes/c3b2/web.scm60
3 files changed, 48 insertions, 26 deletions
diff --git a/gnunet/sync.scm b/gnunet/sync.scm
index 93c7b88..71173ab 100644
--- a/gnunet/sync.scm
+++ b/gnunet/sync.scm
@@ -44,7 +44,7 @@
44 fs 44 fs
45 filename 45 filename
46 ;; TODO: doesn't work, see publish-keywords 46 ;; TODO: doesn't work, see publish-keywords
47 (fs-uri-ksk-create "c3b2://topic") 47 (fs-uri-ksk-create "c3b2://v1/message")
48 (container-meta-data-create) 48 (container-meta-data-create)
49 %gnunet-yes 49 %gnunet-yes
50 (fs-block-options)))) 50 (fs-block-options))))
@@ -82,8 +82,11 @@ code is non-zero; otherwise return #t."
82 82
83(define-public (publish configuration filename keywords) 83(define-public (publish configuration filename keywords)
84 "Publish FILENAME tagged with keywords" 84 "Publish FILENAME tagged with keywords"
85 (pk 1 configuration filename keywords)
85 (let ((uri (publish-file configuration filename))) 86 (let ((uri (publish-file configuration filename)))
87 (pk 2)
86 (publish-keywords configuration uri keywords) 88 (publish-keywords configuration uri keywords)
89 (pk 3)
87 uri)) 90 uri))
88 91
89;;; search 92;;; search
@@ -102,13 +105,13 @@ code is non-zero; otherwise return #t."
102(define (search/timeout) 105(define (search/timeout)
103 (scheduler-shutdown)) 106 (scheduler-shutdown))
104 107
105(define %ten-seconds (* 10 (expt 10 6))) 108(define %five-seconds (* 5 (expt 10 6)))
106 109
107(define (search/task configuration uri callback) 110(define (search/task configuration uri callback)
108 (lambda () 111 (lambda ()
109 (let ((fs (fs-start configuration "c3b2" (search/progress callback)))) 112 (let ((fs (fs-start configuration "c3b2" (search/progress callback))))
110 (let ((search-context (fs-search-start fs uri 1 %fs-search-option-none))) 113 (let ((search-context (fs-search-start fs uri 1 %fs-search-option-none)))
111 (scheduler-add-delayed %ten-seconds search/timeout) 114 (scheduler-add-delayed %five-seconds search/timeout)
112 (scheduler-add-shutdown (search/task/shutdown search-context)))))) 115 (scheduler-add-shutdown (search/task/shutdown search-context))))))
113 116
114(define (search-exec configuration keywords callback) 117(define (search-exec configuration keywords callback)
@@ -152,7 +155,7 @@ code is non-zero; otherwise return #t."
152(define (download/timeout) 155(define (download/timeout)
153 (scheduler-shutdown)) 156 (scheduler-shutdown))
154 157
155(define %one-second (* 3 (expt 10 6))) 158(define %one-second (* 1 (expt 10 6)))
156 159
157(define (download/task configuration uri callback) 160(define (download/task configuration uri callback)
158 (lambda () 161 (lambda ()
diff --git a/guix.scm b/guix.scm
index ab52ef8..b9b4cb9 100644
--- a/guix.scm
+++ b/guix.scm
@@ -141,7 +141,8 @@
141 (outputs '("out" "debug")) 141 (outputs '("out" "debug"))
142 (arguments 142 (arguments
143 `(#:configure-flags 143 `(#:configure-flags
144 (list (string-append "--with-nssdir=" %output "/lib")) 144 (list (string-append "--with-nssdir=" %output "/lib")
145 "CFLAGS=-ggdb -O0")
145 ;; AFAIK not necessary, will also regulary lead to broken 146 ;; AFAIK not necessary, will also regulary lead to broken
146 ;; GNUnet builds (experimental is what it says) 147 ;; GNUnet builds (experimental is what it says)
147 ;; "--enable-experimental") 148 ;; "--enable-experimental")
diff --git a/prototypes/c3b2/web.scm b/prototypes/c3b2/web.scm
index 20e53f1..5ced5d3 100755
--- a/prototypes/c3b2/web.scm
+++ b/prototypes/c3b2/web.scm
@@ -22,15 +22,15 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
22;; stdlib 22;; stdlib
23(use-modules ((ice-9 binary-ports))) 23(use-modules ((ice-9 binary-ports)))
24(use-modules ((ice-9 match))) 24(use-modules ((ice-9 match)))
25(use-modules ((ice-9 threads)))
25(use-modules ((rnrs bytevectors))) 26(use-modules ((rnrs bytevectors)))
26(use-modules ((web request))) 27(use-modules ((web request)))
27(use-modules ((web uri))) 28(use-modules ((web uri)))
28 29
29;; third party 30;; third party
30(use-modules ((fibers web server))) 31(use-modules ((web server)))
31(use-modules ((wiredtiger extra))) 32(use-modules ((wiredtiger extra)))
32(use-modules ((wiredtiger feature-space))) 33(use-modules ((wiredtiger feature-space)))
33(use-modules ((wiredtiger grf3)))
34(use-modules ((wiredtiger wiredtiger))) 34(use-modules ((wiredtiger wiredtiger)))
35 35
36;; local 36;; local
@@ -61,27 +61,45 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
61 61
62;;; 62;;;
63 63
64(define (maybe-message-add! body uri)
65 (when (null? (fs:find 'uri uri))
66 (fs:add! `((kind . message) (body . ,body)))))
67
68(define (discover configuration)
69 (let loop ((uris (search configuration '("c3b2://v1/message"))))
70 (unless (null? uris)
71 (let ((body (download configuration (car uris))))
72 (when body
73 (pk 'add (car uris))
74 (maybe-message-add! (utf8->string body) (car uris)))
75 (loop (cdr uris))))))
76
77(define (run-discovery configuration)
78 "Run a background thread to look for new messages"
79 (call-with-new-thread
80 (lambda ()
81 (with-context*
82 (let loop ()
83 (discover configuration)
84 (loop)
85 (sleep 1))))))
86
87;;;
88
64(define (c3b2/topics) 89(define (c3b2/topics)
65 "Return vertices of topics ie. messages without parent" 90 (map (lambda (x) (assoc-ref x 'body))
66 (map utf8->string 91 (map fs:ref*
67 (filter values 92 (fs:find 'kind 'message))))
68 (map (lambda (uri) (download %configuration uri))
69 (search %configuration '("c3b2://v1/topic"))))))
70 93
71(define (c3b2/topic-add! body) 94(define (c3b2/topic-add! body)
72 (let ((new-topic `((kind . message) 95 (let* ((payload (string->utf8 body))
73 (body . ,body) 96 (hash (make-hash payload))
74 (parent . #f)))) 97 (filepath (string-append %home "/" hash)))
75 (let ((topic (save (create-vertex new-topic)))) 98 (call-with-output-file filepath
76 (let* ((payload (vertex-ref topic 'body)) 99 (lambda (port)
77 (payload (string->utf8 payload)) 100 (put-bytevector port payload))
78 (hash (make-hash payload)) 101 #:binary #t)
79 (filepath (string-append %home "/" hash))) 102 (publish %configuration (pk filepath) '("c3b2://v1/message"))))
80 (call-with-output-file filepath
81 (lambda (port)
82 (put-bytevector port payload))
83 #:binary #t)
84 (publish %configuration filepath '("c3b2://v1/topic"))))))
85 103
86;;; web 104;;; web
87 105
@@ -129,7 +147,7 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
129(define-public (main args) 147(define-public (main args)
130 (set! %configuration (cadr args)) 148 (set! %configuration (cadr args))
131 (set! %home (caddr args)) 149 (set! %home (caddr args))
132 (pk %configuration %home)
133 (format #t "Server running @ http://localhost:8080\n") 150 (format #t "Server running @ http://localhost:8080\n")
134 (with-env (env-open* "wt" (list *feature-space*) "create,log=(enabled=true)") 151 (with-env (env-open* "wt" (list *feature-space*) "create,log=(enabled=true)")
152 (run-discovery %configuration)
135 (run-server router))) 153 (run-server router)))