~pepe/hemple

badb3d5f3627461b3eee2bc1d4908cc85c59a0b9 — Josef Pospíšil 2 months ago 450f4d1 master
Do not error on handshake
1 files changed, 24 insertions(+), 26 deletions(-)

M hemple/init.janet
M hemple/init.janet => hemple/init.janet +24 -26
@@ 5,7 5,7 @@
###
### Crypto RPC server and client tailored to Janet.
###
### Blatantly stolen from janet-lang/spork/rpc
### Parts blatantly stolen from janet-lang/spork/rpc

### Limitations: ????
###


@@ 32,14 32,6 @@
        z/decompress
        unmarshal)))

# RPC Protocol
#
# 1. server <- {user specified name of client} <- client
# 2. server -> {marshalled tuple of supported keys in marshal dict (capabilites)} -> client
# 3. server <- {marshalled function call: [fnname args]} <- client
# 4. server -> {result of unmarshalled call: [status result]} -> client
# 5. go back to 3.

(defn default-supervisor
  ```
  Default supervisor.


@@ 88,23 80,29 @@
      (def packet3 (hrecv))
      (jh/kx/xx4 state packet3 psk))

    (def session-pair (handshake))
    (var msg-id 0)
    (def recv (make-recv connection (decode msg-id session-pair)))
    (def send (make-send connection (encode msg-id session-pair)))
    (send keys-msg)
    (forever
      (match (protect (recv))
        [true (msg (not (nil? msg)))]
        (let [[fnname args] msg
              f (handler fnname)]
          (++ msg-id)
          (if-not f
            (send [false (string "no function " fnname " supported")])
            (send (protect (f handler ;args)))))
        (do
          (ev/give-supervisor :close connection)
          (break))))))
    (match (protect (handshake))
      [false err]
      (do
        (ev/give-supervisor :close connection)
        (break))
      [true session-pair]
      (do
        (var msg-id 0)
        (def recv (make-recv connection (decode msg-id session-pair)))
        (def send (make-send connection (encode msg-id session-pair)))
        (send keys-msg)
        (forever
          (match (protect (recv))
            [true (msg (not (nil? msg)))]
            (let [[fnname args] msg
                  f (handler fnname)]
              (++ msg-id)
              (if-not f
                (send [false (string "no function " fnname " supported")])
                (send (protect (f handler ;args)))))
            (do
              (ev/give-supervisor :close connection)
              (break))))))))

(defn client
  ```