Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -79,12 +79,13 @@ ;; (define (rmt:connect alldat dbfname) (let* ((ulexdat (let ((uconn (alldat-ulexdat alldat))) (if uconn uconn - (let* ((new-ulexdat (ulex:setup))) ;; establish connection to ulex + (let* ((new-ulexdat (ulex:setup))) ;; establish connection to ulex (alldat-ulexdat-set! alldat new-ulexdat) + (rmt:setup-ulex alldat) new-ulexdat))))) (ulex:connect ulexdat dbfname))) ;; set up a connection to the current owner of the dbfile associated with rid ;; then send the query to that dbfile owner and wait for a response. @@ -96,10 +97,16 @@ "main.db" (conc rid ".db"))) (dbfile (conc areapath "/.db/" dbfname)) (ulexconn (rmt:connect alldat dbfname))) (rmt:open-qry-close-locally cmd 0 params))) + +;; setup the remote calls +(define (rmt:setup-ulex alldat) + (let ((udata (alldat-ulexdat alldat))) + (ulex:register-handler udata 'ping common:get-full-version) + )) ;; ;; ;; #;(common:telemetry-log (conc "rmt:"(->string cmd)) ;; ;; #;(define (rmt:send-receive cmd rid params #!key (attemptnum 1)(area-dat #f)) ;; start attemptnum at 1 so the modulo below works as expected ;; ;; ;; ;; #;(common:telemetry-log (conc "rmt:"(->string cmd)) Index: ulex/ulex.scm ================================================================== --- ulex/ulex.scm +++ ulex/ulex.scm @@ -114,11 +114,11 @@ (my-hostname #f) (my-port #f) (my-pid (current-process-id)) (serv-listener #f) (handler-thread #f) - (handlers '()) + (handlers (make-hash-table)) (outgoing-conns (make-hash-table)) ;; host:port -> conn ) ;; struct for keeping track of others we are talking to @@ -243,11 +243,12 @@ (define (get-peer-ports udata host-port #!optional (hostname #f)(pid #f)) (let ((pdat (get-peer-dat udata host-port hostname pid))) (values (peer-inp pdat)(peer-oup pdat)))) -;; send back ack +;; send back ack, amusing I suppose that this looks almost like what +;; tcp itself does ... ;; (define (reply udata host-port handler qrykey data #!optional (hostname #f)(pid #f)) (let-values (((inp oup)(get-peer-ports udata host-port hostname pid))) (write-line (conc handler " " @@ -279,10 +280,14 @@ (data (read-line inp))) (match (string-split controldat) ((handlerkey host:port hostname pid qrykey params ...) (case (string->symbol handlerkey) ((ack)(print "Got ack!")) + ((ping) + (let* ((proc (hash-table-ref/default (udat-handlers udata) 'ping #f)) + (val (if proc (proc) "gotping"))) + (reply udata host:port "version" qrykey val))) ((rucaptain) (reply udata host:port "iamcaptain" qrykey (if (udat-my-cpkt-key udata) "yes" "no"))) (else @@ -289,10 +294,14 @@ (send-ack udata host:port qrykey hostname pid) (add-to-work-queue udata (get-peer-dat udata host:port) handlerkey data))) (else (print "BAD DATA? handler=" handlerkey " data=" data))))) (loop state))))) +;; add a proc to the handler list +(define (register-handler udata key proc) + (hash-table-set! (udat-handlers udata) key proc)) + ;;====================================================================== ;; connection setup and management functions ;;====================================================================== ;; find or become the captain, return a ulex object