55 lines
1.4 KiB
Racket
55 lines
1.4 KiB
Racket
#lang racket/base
|
|
;; (Temporary) example client and server
|
|
|
|
(require racket/tcp)
|
|
(require racket/pretty)
|
|
(require racket/match)
|
|
|
|
(require "conversation.rkt")
|
|
(require "ssh-numbers.rkt")
|
|
(require "ssh-session.rkt")
|
|
(require "standard-thread.rkt")
|
|
|
|
(define (t-client)
|
|
(let-values (((i o) (tcp-connect "localhost"
|
|
2323
|
|
;;22
|
|
)))
|
|
(let ((api (ssh-session 'client i o)))
|
|
(printf "Got API ~v\n" api)
|
|
(semaphore-wait (make-semaphore 0)))))
|
|
|
|
(define (repl-channel handle)
|
|
(semaphore-wait (make-semaphore 0)))
|
|
|
|
(define (t-server)
|
|
(define s (tcp-listen 2322 4 #t "localhost"))
|
|
(printf "Accepting...\n")
|
|
(let loop ()
|
|
(let-values (((i o) (tcp-accept s)))
|
|
(standard-thread
|
|
(lambda ()
|
|
(simple-ssh-server (ssh-session 'server i o)
|
|
(lambda (channel-type extra-request-data state)
|
|
(match channel-type
|
|
(#"session"
|
|
(define channel-room (make-room 'channel))
|
|
(spy-on channel-room)
|
|
(standard-thread (lambda ()
|
|
(repl-channel
|
|
(join-room channel-room 'repl
|
|
#:break-on-departure? #t))))
|
|
(wait-for-members channel-room '(repl))
|
|
(values `(ok ,channel-room #"")
|
|
state))
|
|
(else
|
|
(values `(error ,SSH_OPEN_ADMINISTRATIVELY_PROHIBITED
|
|
"Unknown channel type")
|
|
state))))
|
|
'no-state)))
|
|
(loop))))
|
|
|
|
(if (getenv "clientmode")
|
|
(t-client)
|
|
(t-server))
|