Commit dfb321fa authored by  Hayley Patton's avatar Hayley Patton 🐢

fix syncing

parent b12de5a5
(defsystem decentralise-example
:depends-on (:decentralise)
:components ((:file "example")))
:components ((:module example
:components (:file "example"))))
......@@ -62,13 +62,12 @@
(defmethod handle-others-listing ((system system) data meta)
(let* ((lock (connection-meta-lock meta))
(connection (connection-meta-socket system))
(connection (connection-meta-socket meta))
(our-data (get-every-list (listing-generator system)))
(their-data
(loop
with table = (make-hash-table :test 'equal
:size (hash-table-size our-data))
for item in (split-sequence #\Newline data)
with table = (make-hash-table :test 'equal)
for item in (split-sequence #\Newline data :remove-empty-subseqs t)
do (destructuring-bind (name version)
(split-sequence #\Space item)
(setf (gethash name table)
......@@ -89,7 +88,7 @@
(> their-version our-version))
collect name)))
(push-all give (connection-meta-stack meta))
(bt:with-lock-held ((connection-meta-lock lock))
(bt:with-lock-held (lock)
(get-blocks connection take))))
(defmethod handle-others-nodes (system text)
......@@ -120,6 +119,8 @@
(cond
((string= name "list")
(handle-others-listing system text meta))
((string= name "nodes")
(handle-others-nodes system text))
(t
(let ((err (stop-put-p system name text version channels)))
(cond
......@@ -167,8 +168,8 @@
(defmethod repl (connection (system system))
(let* ((lock (bt:make-lock "Write lock"))
(meta (make-connection-meta :socket connection
:stack nil
:lock lock)))
:stack nil
:lock lock)))
(push meta
(slot-value system 'connection-list))
(handler-case
......@@ -215,7 +216,11 @@
(get-peer-address connection)
(get-peer-port connection))))))
(defmethod connect-to ((system system) host &key (port 1892) (timeout 5) (announcep t))
(defmethod connect-to ((system system) host &key
(port (system-port system))
(timeout 5)
(announcep t)
(subscriptions nil))
(let* ((socket (socket-connect host port :timeout timeout))
(raw-conn (socket-stream socket))
(conn (make-instance 'connection
......@@ -226,6 +231,7 @@
(get-blocks conn '("list" "nodes"))
(when announcep
(announce conn t))
(subscribe-channels conn subscriptions)
(finish-output raw-conn)
(unwind-protect
(repl conn system)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment