2019-03-18 15:34:14 +00:00
|
|
|
#lang imperative-syndicate
|
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(provide (struct-out server-poa)
|
|
|
|
(struct-out message-poa->server)
|
|
|
|
(struct-out message-server->poa)
|
2019-05-05 11:55:16 +00:00
|
|
|
(struct-out server-proposal)
|
2019-03-25 11:44:12 +00:00
|
|
|
(struct-out server-envelope))
|
2019-03-18 15:34:14 +00:00
|
|
|
|
|
|
|
(require "wire-protocol.rkt")
|
2019-03-25 11:44:12 +00:00
|
|
|
(require racket/set)
|
|
|
|
|
|
|
|
;; Internal connection protocol
|
2019-05-05 15:37:03 +00:00
|
|
|
(assertion-struct server-poa (connection-id scope)) ;; "Point of Attachment"
|
|
|
|
(assertion-struct message-poa->server (connection-id body))
|
|
|
|
(assertion-struct message-server->poa (connection-id body))
|
2019-03-25 11:44:12 +00:00
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
;; Internal isolation -- these are isomorphic to `to-server` and `from-server`!
|
|
|
|
;; (and, for that matter, to `outbound` and `inbound`!)
|
2019-05-05 11:55:16 +00:00
|
|
|
(assertion-struct server-proposal (scope body)) ;; suggestions (~ actions)
|
|
|
|
(assertion-struct server-envelope (scope body)) ;; decisions (~ events)
|
2019-03-25 11:44:12 +00:00
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(spawn #:name 'server-factory
|
2019-05-05 11:55:16 +00:00
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(during/spawn (server-poa _ _)
|
2019-05-05 11:55:16 +00:00
|
|
|
;; Previously, we just had server-envelope. Now, we have both
|
|
|
|
;; server-envelope and server-proposal. While not everything
|
|
|
|
;; decided is (locally) suggested, it is true that everything
|
|
|
|
;; suggested is decided (in this implementation at least),
|
|
|
|
;; and the following clause reflects this:
|
|
|
|
(during (server-proposal $scope $assertion)
|
|
|
|
(assert (server-envelope scope assertion))))
|
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(during/spawn (server-poa $id $scope)
|
2019-03-25 11:44:12 +00:00
|
|
|
(define endpoints (set))
|
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(on (message (message-poa->server id (Assert $ep $a)))
|
2019-03-25 11:44:12 +00:00
|
|
|
(when (not (set-member? endpoints ep))
|
|
|
|
(set! endpoints (set-add endpoints ep))
|
|
|
|
(react
|
|
|
|
(on-stop (set! endpoints (set-remove endpoints ep)))
|
|
|
|
|
|
|
|
(field [assertion a])
|
|
|
|
|
2019-05-05 11:55:16 +00:00
|
|
|
(assert (server-proposal scope (assertion)))
|
2019-05-03 16:53:24 +00:00
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(let ((! (lambda (ctor) (lambda (cs) (send! (message-server->poa id (ctor ep cs)))))))
|
2019-05-04 21:58:45 +00:00
|
|
|
(add-observer-endpoint! (lambda ()
|
|
|
|
(let ((a (assertion)))
|
|
|
|
(when (observe? a)
|
|
|
|
(server-envelope scope (observe-specification a)))))
|
|
|
|
#:on-add (! Add)
|
|
|
|
#:on-remove (! Del)
|
|
|
|
#:on-message (! Msg)))
|
2019-03-25 11:44:12 +00:00
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(on (message (message-poa->server id (Assert ep $new-a)))
|
2019-03-25 11:44:12 +00:00
|
|
|
(assertion new-a))
|
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(stop-when (message (message-poa->server id (Clear ep)))))))
|
2019-03-25 11:44:12 +00:00
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(on (message (message-poa->server id (Message $body)))
|
2019-03-25 11:44:12 +00:00
|
|
|
(send! (server-envelope scope body)))
|
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(on (message (message-poa->server id (Ping)))
|
|
|
|
(send! (message-server->poa id (Pong))))))
|