Skip to content
Chris Petersen edited this page Oct 16, 2014 · 1 revision

rupi-server creates a rupi server instance.

Parameter Description
store The data store to use to serve answers from
keyidx Encryption key index. Generally 0, unless connecting to two rupi servers simultaneously
key the u8vector encryption key used to communicate with the rupi server. (u8vector-length 8 preferred, or a multiple thereof < 64)
addr Hostname for the rupi server instance
port Port number of the rupi server instance
upiproc The UPI function which is used to answer requests with. Suggested format is (upi-cmd store cmd . arglist) if no authentication is used or (upi-cmd store pin cmd . arglist) with authentication

Example

Example 1: Make a rupi server and a client connecting to it to get some data. This example assumes that your console application has store and rupi in its MODULES file as well as libcrypto in its LIBRARIES file.

> (define rupi:key (string->u8vector "Lambda13"))
> (define rupi:port 8013)
> (define rupi:hostname "localhost")
> (define rupi:addr 
  (with-exception-catcher
    (lambda (e) #f)
    (lambda () (car(host-info-addresses (host-info rupi:hostname))))
  )
)

;; Start a RUPI server with store, key-index key, IP, port and function to parse messages
> (define store (make-store "main"))
> (store-set! store "platform" "LambdaNative")
> (define (upi-cmd store cmd . arglist)
  (let ((arg (if (fx>= (length arglist) 1) (car arglist) #f))
        (arg2 (if (fx>= (length arglist) 2) (cadr arglist) #f)))
    (cond
      ((string=? cmd "GETVALUE") (store-ref store arg))
      ((string=? cmd "SETVALUE") (store-set! store arg arg2))
      (else 
        (log-error "RUPICMD: " cmd arg arg2)
        "Invalid command"
      )
    )
  ))
> (define rs (rupi-server "main" 0 rupi:key rupi:addr rupi:port upi-cmd))

;; Make a rupi client, connect to the server and ask for some data
> (define rc (rupi-client 0 rupi:key rupi:addr rupi:port))
> (rupi-cmd rc "GETVALUE" "platform")
"LambdaNative"
> (rupi-cmd rc "GETVALUE" "version")
#f
> (rupi-cmd rc "SETVALUE" "version" 20130805)
#t
> (rupi-cmd rc "GETVALUE" "version")
20130805
> (rupi-cmd rc "SOMETHINGELSE")
"Invalid command"
Clone this wiki locally