Basic repl over tor

This commit is contained in:
Vivianne 2023-07-06 22:03:27 -07:00
parent 22cf549c88
commit 2148ae2e8d

View file

@ -6,11 +6,12 @@
#:use-module (goblins ocapn captp) #:use-module (goblins ocapn captp)
#:use-module (goblins ocapn ids) #:use-module (goblins ocapn ids)
#:use-module (goblins ocapn netlayer onion) #: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 ;; Initiator logic
;; ;;
;; todo: refactor?
(define (make-initiator ^game-controller) (define (make-initiator ^game-controller)
(with-vat (spawn-vat) (with-vat (spawn-vat)
(define initiator (spawn ^game-initiator ^game-controller)) (define initiator (spawn ^game-initiator ^game-controller))
@ -18,18 +19,24 @@
(define init-sref ($ mycapn 'register initiator 'testuds)) (define init-sref ($ mycapn 'register initiator 'testuds))
(format #t "Connect to: ~a\n" (ocapn-id->string init-sref)))) (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 (^game-initiator bcom ^game-controller)
(define pick (pick-rps)) (define pick (pick-rps))
(define won? #nil) (define won? #nil)
(define peer #nil) (define peer #nil)
(methods (methods
[(register-opponent name p sealed-pick) [(register-opponent p sealed-pick)
(set! peer p) (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) (on (<- (<- peer 'pick->unsealer pick) sealed-pick)
(λ (peer-pick) (λ (peer-pick)
(set! won? (rps-winner 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) [(try-transition)
(if (eq? won? #nil) (if (eq? won? #nil)
'connecting 'connecting
@ -38,14 +45,19 @@
;; ;;
;; Joiner logic ;; Joiner logic
;; ;;
(define (make-joiner ^game-controller user-name addr) (define (make-joiner ^game-controller addr)
(with-vat (spawn-vat) (with-vat (spawn-vat)
(define mycapn (spawn-mycapn (new-onion-netlayer))) (define mycapn (spawn-mycapn (new-onion-netlayer)))
(define init-sref (string->ocapn-id addr)) (define init-sref (string->ocapn-id addr))
(define initiator ($ mycapn 'enliven init-sref)) (define initiator ($ mycapn 'enliven init-sref))
(define joiner (spawn ^game-joiner initiator ^game-controller)) (define joiner (spawn ^game-joiner initiator ^game-controller))
(on (<- initiator 'register-opponent user-name joiner ($ joiner 'get-sealed-pick)) (<- initiator 'register-opponent joiner ($ joiner 'get-sealed-pick))))
(λ (_) (format #t "~a finished the game.\n" user-name)))))
;; 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 (^game-joiner bcom initiator ^game-controller)
(define-values (seal-pick unseal-pick my-pick?) (define-values (seal-pick unseal-pick my-pick?)