Rename host/client to initiator/joiner

This commit is contained in:
Vivianne 2023-07-06 20:05:42 -07:00
parent 610e09b2a6
commit 493ad2349c
7 changed files with 27 additions and 27 deletions

View file

@ -1,5 +1,5 @@
bin_SCRIPTS = scripts/make-client \
scripts/make-host
bin_SCRIPTS = scripts/make-joiner \
scripts/make-initiator
# Handle substitution of fully-expanded Autoconf variables.
do_subst = $(SED) \

View file

@ -12,8 +12,8 @@ AM_SILENT_RULES([yes])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([pre-inst-env], [chmod +x pre-inst-env])
AC_CONFIG_FILES([scripts/make-client],[chmod +x scripts/make-client])
AC_CONFIG_FILES([scripts/make-host],[chmod +x scripts/make-host])
AC_CONFIG_FILES([scripts/make-joiner],[chmod +x scripts/make-joiner])
AC_CONFIG_FILES([scripts/make-initiator],[chmod +x scripts/make-initiator])
dnl Search for 'guile' and 'guild'. This macro defines
dnl 'GUILE_EFFECTIVE_VERSION'.
GUILE_PKG([3.0 2.2 2.0])

View file

@ -6,7 +6,7 @@
#:use-module (goblins ocapn captp)
#:use-module (goblins ocapn ids)
#:use-module (goblins ocapn netlayer testuds)
#:export (make-host make-client))
#:export (make-initiator make-joiner))
;;
;; Helper to use testuds netlayer
@ -17,16 +17,16 @@
(spawn ^testuds-netlayer tmp))
;;
;; Host logic
;; Initiator logic
;;
(define (make-host ^game-controller)
(define (make-initiator ^game-controller)
(with-vat (spawn-vat)
(define lobby (spawn ^game-lobby ^game-controller))
(define initiator (spawn ^game-initiator ^game-controller))
(define mycapn (spawn-mycapn (new-testuds-netlayer)))
(define lobby-sref ($ mycapn 'register lobby 'testuds))
(format #t "Connect to: ~a\n" (ocapn-id->string lobby-sref))))
(define init-sref ($ mycapn 'register initiator 'testuds))
(format #t "Connect to: ~a\n" (ocapn-id->string init-sref))))
(define (^game-lobby bcom ^game-controller)
(define (^game-initiator bcom ^game-controller)
(define pick (pick-rps))
(methods
@ -39,21 +39,21 @@
(bcom (^game-controller bcom won? peer))))]))
;;
;; Client logic
;; Joiner logic
;;
(define (make-client ^game-controller user-name addr)
(define (make-joiner ^game-controller user-name addr)
(pk user-name)
(pk addr)
(pk ^game-controller)
(with-vat (spawn-vat)
(define mycapn (spawn-mycapn (new-testuds-netlayer)))
(define lobby-sref (string->ocapn-id addr))
(define lobby ($ mycapn 'enliven lobby-sref))
(define client-picker (spawn ^client-picker lobby ^game-controller))
(on (<- lobby 'register-opponent user-name client-picker ($ client-picker 'get-sealed-pick))
(define init-sref (string->ocapn-id addr))
(define initiator ($ mycapn 'enliven init-sref))
(define joiner (spawn ^game-joiner initiator ^game-controller))
(on (<- initiator 'register-opponent user-name joiner ($ joiner 'get-sealed-pick))
(λ (_) (format #t "~a finished the game.\n" user-name)))))
(define (^client-picker bcom lobby ^game-controller)
(define (^game-joiner bcom initiator ^game-controller)
(define-values (seal-pick unseal-pick my-pick?)
(spawn-sealer-triplet))
(define pick (pick-rps))
@ -62,10 +62,10 @@
[(pick->unsealer peer-pick)
(define won? (rps-winner pick peer-pick))
(format #t "Peer picked ~a... a bold choice (do I win? ~a), I will become a controller and send my unsealer.\n" peer-pick won?)
;; We make the assumption that lobby is to become a controller.
;; We make the assumption that initiator is to become a controller.
;; Note second arg to bcom which will return the value (this is confusing to me)
;; see https://spritely.institute/files/docs/guile-goblins/0.11.0/Object-construction.html
(bcom (^game-controller bcom won? lobby) unseal-pick)]))
(bcom (^game-controller bcom won? initiator) unseal-pick)]))
;;
;; Standard rock paper scissors logic follows!

View file

@ -69,7 +69,7 @@
"GUILE_LOAD_COMPILED_PATH"
(compiled-dir out version)
(compiled-dir "" version))))
,''("make-client" "make-host"))
,''("make-joiner" "make-initiator"))
#t))))))))
(native-inputs
`(("autoconf" ,autoconf)

View file

@ -26,10 +26,10 @@
(programs
((directory
"scripts"
((in-file "make-client")
(in-file "make-host")
(text-file "make-host")
(text-file "make-client")))))
((in-file "make-joiner")
(in-file "make-initiator")
(text-file "make-initiator")
(text-file "make-joiner")))))
(documentation ((org-file "README")))
(infrastructure
((in-file "pre-inst-env")

View file

@ -5,6 +5,6 @@
(use-modules
(gib-gab-gob rps)
(gib-gab-gob game))
(make-host ^ggg-controller)
(make-initiator ^ggg-controller)
(while #t #f) ;; indefinitely

View file

@ -5,6 +5,6 @@
(use-modules
(gib-gab-gob rps)
(gib-gab-gob game))
(apply make-client (cons ^ggg-controller (cdr (command-line))))
(apply make-joiner (cons ^ggg-controller (cdr (command-line))))
(while #t #f) ;; indefinitely