Basic repl over tor
This commit is contained in:
parent
22cf549c88
commit
2148ae2e8d
1 changed files with 19 additions and 7 deletions
|
@ -6,11 +6,12 @@
|
|||
#:use-module (goblins ocapn captp)
|
||||
#:use-module (goblins ocapn ids)
|
||||
#:use-module (goblins ocapn netlayer onion)
|
||||
#:export (make-initiator make-joiner ^game-initiator ^game-joiner))
|
||||
#:export (make-initiator make-joiner initiator/connect resolve-initiator ^game-initiator ^game-joiner))
|
||||
|
||||
;;
|
||||
;; Initiator logic
|
||||
;;
|
||||
;; todo: refactor?
|
||||
(define (make-initiator ^game-controller)
|
||||
(with-vat (spawn-vat)
|
||||
(define initiator (spawn ^game-initiator ^game-controller))
|
||||
|
@ -18,18 +19,24 @@
|
|||
(define init-sref ($ mycapn 'register initiator 'testuds))
|
||||
(format #t "Connect to: ~a\n" (ocapn-id->string init-sref))))
|
||||
|
||||
;; use this one
|
||||
(define (initiator/connect initiator)
|
||||
(define mycapn (spawn-mycapn (new-onion-netlayer)))
|
||||
(define init-sref ($ mycapn 'register initiator 'onion))
|
||||
(format #t "Connect to: ~a\n" (ocapn-id->string init-sref)))
|
||||
|
||||
(define (^game-initiator bcom ^game-controller)
|
||||
(define pick (pick-rps))
|
||||
(define won? #nil)
|
||||
(define peer #nil)
|
||||
(methods
|
||||
[(register-opponent name p sealed-pick)
|
||||
[(register-opponent p sealed-pick)
|
||||
(set! peer p)
|
||||
(format #t "Hey there, ~a! You sent me your pick of rock-paper-scissors; now I will send mine.\n" name)
|
||||
(format #t "Hey there! You sent me your pick of rock-paper-scissors; now I will send mine.\n")
|
||||
(on (<- (<- peer 'pick->unsealer pick) sealed-pick)
|
||||
(λ (peer-pick)
|
||||
(set! won? (rps-winner pick peer-pick))
|
||||
(format #t "Opponent ~a has picked ~a (do I win? ~a). Ready to be a controller.\n" name peer-pick won?)))]
|
||||
(format #t "Opponent has picked ~a (do I win? ~a). Ready to be a controller.\n" peer-pick won?)))]
|
||||
[(try-transition)
|
||||
(if (eq? won? #nil)
|
||||
'connecting
|
||||
|
@ -38,14 +45,19 @@
|
|||
;;
|
||||
;; Joiner logic
|
||||
;;
|
||||
(define (make-joiner ^game-controller user-name addr)
|
||||
(define (make-joiner ^game-controller addr)
|
||||
(with-vat (spawn-vat)
|
||||
(define mycapn (spawn-mycapn (new-onion-netlayer)))
|
||||
(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)))))
|
||||
(<- initiator 'register-opponent joiner ($ joiner 'get-sealed-pick))))
|
||||
|
||||
;; temp for repl stuff
|
||||
(define (resolve-initiator addr)
|
||||
(define mycapn (spawn-mycapn (new-onion-netlayer)))
|
||||
(define init-sref (string->ocapn-id addr))
|
||||
($ mycapn 'enliven init-sref))
|
||||
|
||||
(define (^game-joiner bcom initiator ^game-controller)
|
||||
(define-values (seal-pick unseal-pick my-pick?)
|
||||
|
|
Loading…
Reference in a new issue