Support three levels of interest-type for a topic: participant/ordinary, monitor/observer, and "super-monitor".

This commit is contained in:
Tony Garnock-Jones 2012-07-04 17:13:48 -04:00
parent bee4834ed6
commit 5efa0c4061
6 changed files with 33 additions and 23 deletions

View File

@ -36,8 +36,8 @@
(w 'absence)
(w 'message)))
(transition 'spy-state
(add-role 's->p (topic-publisher (wild) #:monitor? #t) (hs 'subscriber->publisher))
(add-role 'p->s (topic-subscriber (wild) #:monitor? #t) (hs 'publisher->subscriber)))))
(add-role 's->p (topic-publisher (wild) #:monitor? 'everything) (hs 'subscriber->publisher))
(add-role 'p->s (topic-subscriber (wild) #:monitor? 'everything) (hs 'publisher->subscriber)))))
(ground-vm (lambda (boot-pid)
(transition 'no-state

View File

@ -22,11 +22,6 @@
#:state state
#:topic t
#:on-presence (match t
[(topic 'publisher (tcp-channel remote-addr (== local-addr) _) #t)
;; Ignore monitor flows. They just mean there's
;; someone willing to supply connections to us
;; at some point in the future.
state]
[(topic 'publisher (tcp-channel remote-addr (== local-addr) _) #f)
(transition state (spawn (connection-handler local-addr remote-addr)))]))))

View File

@ -28,11 +28,6 @@
#:state state
#:topic t
#:on-presence (match t
[(topic 'publisher (tcp-channel remote-addr (== local-addr) _) #t)
;; Ignore monitor flows. They just mean there's
;; someone willing to supply connections to us
;; at some point in the future.
state]
[(topic 'publisher (tcp-channel remote-addr (== local-addr) _) #f)
(transition state (spawn (connection-handler local-addr remote-addr)))]))))

View File

@ -84,8 +84,8 @@
(define tcp-driver
(transition (set)
(role 'tcp-listener-factory
(set (topic-subscriber (tcp-channel any-listener any-remote (wild)) #:monitor? #t)
(topic-publisher (tcp-channel any-remote any-listener (wild)) #:monitor? #t))
(set (topic-subscriber (tcp-channel any-listener any-remote (wild)) #:monitor? 'everything)
(topic-publisher (tcp-channel any-remote any-listener (wild)) #:monitor? 'everything))
#:state active-handles
#:topic t
#:on-presence (maybe-spawn-socket t active-handles tcp-listener-manager)
@ -128,8 +128,8 @@
(define listener (tcp:tcp-listen port 4 #t))
(transition 'listener-is-running
(role 'closer
(set (topic-subscriber (tcp-channel local-addr any-remote (wild)) #:monitor? #t)
(topic-publisher (tcp-channel any-remote local-addr (wild)) #:monitor? #t))
(set (topic-subscriber (tcp-channel local-addr any-remote (wild)) #:monitor? 'everything)
(topic-publisher (tcp-channel any-remote local-addr (wild)) #:monitor? 'everything))
#:state state
#:topic t
;; Hey, what if the presence we need went away between our

View File

@ -56,9 +56,8 @@
#:state active-handles
#:topic t
#:on-presence (match t
[(topic _ (udp-packet _ local-addr _) counterparty-monitor?)
[(topic _ (udp-packet _ local-addr _) #f)
(cond
[counterparty-monitor? active-handles]
[(set-member? active-handles local-addr) active-handles]
[else
(transition (set-add active-handles local-addr)

31
os2.rkt
View File

@ -138,7 +138,13 @@
meta-endpoints ;; Set<EID>
) #:transparent)
;; A Topic is a (topic Role Pattern Boolean), describing an Endpoint's
;; An InterestType is one of
;; -- #f, representing an ordinary *participant* in a conversation;
;; -- #t, representing a *monitor* or *observer* of a conversation; or
;; -- 'everything, representing a monitor that is also interested in
;; the existence of other monitors of the conversation.
;; A Topic is a (topic Role Pattern InterestType), describing an Endpoint's
;; role in a conversation.
(struct topic (role pattern monitor?) #:prefab)
@ -341,11 +347,26 @@
;; True iff the flow between remote-topic and local-topic should be
;; visible to the local peer. This is the case when either local-topic
;; is a monitor (in which case everything is seen) or otherwise if
;; remote-topic is also not a monitor.
;; is monitoring 'everything or otherwise if remote-topic is an
;; ordinary topic only.
;;
;; |--------------+--------------+------------------------|
;; | local-topic | remote-topic | visible to local peer? |
;; |--------------+--------------+------------------------|
;; | #f | #f | yes |
;; | #f | #t | no |
;; | #f | 'everything | no |
;; | #t | #f | yes |
;; | #t | #t | no |
;; | #t | 'everything | no |
;; | 'everything | #f | yes |
;; | 'everything | #t | yes |
;; | 'everything | 'everything | yes |
;; |--------------+--------------+------------------------|
;;
(define (flow-visible? local-topic remote-topic)
(or (topic-monitor? local-topic)
(not (topic-monitor? remote-topic))))
(or (not (topic-monitor? remote-topic))
(eq? (topic-monitor? local-topic) 'everything)))
;;---------------------------------------------------------------------------
;; Composing state transitions and action emissions.