Index: server.scm ================================================================== --- server.scm +++ server.scm @@ -61,10 +61,12 @@ ;;====================================================================== ;; N A N O M S G B A S E D S E R V E R ;;====================================================================== +;; information about me as a server +;; (defstruct area (conn #f) (port #f) (myaddr #f) (hosts (make-hash-table)) @@ -146,14 +148,37 @@ (area-conn-set! *area-info* area-conn) (area-port-set! *area-info* port-num) (mutex-unlock! (area-mutex *area-info*)) area-conn)))) +;; action: +;; immediate - quick actions, no need to put in queues +;; dbwrite - put in dbwrite queue +;; dbread - put in dbread queue +;; oslong - os actions, e.g. du, that could take a long time +;; osshort - os actions that should be quick, e.g. df +;; (define (server:std-handler dat) - ;; (let* ((from-host (alist-ref 'hostname dat)) - dat) - + (let* ((from-host (alist-ref 'hostname dat)) + (from-port (alist-ref 'port dat)) + (servkey (alist-ref 'servkey dat)) + (hostkey (alist-ref 'hostkey dat)) + (data (alist-ref 'data dat)) + (action (alist-ref 'action dat))) + ;; first, if you don't know who I am then I'm ignoring you + (if (not (equal? servkey (area-pktid *area-info*))) + `(#f . "I don't know you") ;; immediately return this + (case action ;; else carry on + ((immediate) + (case data + ((ping) `(#t "success")) + (else `(#t "I didn't recognise " data)))) + ((dbwrite) `(#t "db write submitted")) + ((dbread) `(#t "db read submitted")) + ((oslong) `(#t "os long submitted")) + ((dbwrite) `(#t "os short submitted")) + (else `(#f "unrecognised action" action)))))) ;; Call this to start the actual server ;; ;; start_server ;; @@ -227,11 +252,11 @@ (T . "server") (D . "1549427032.0")) ;; srvpkt is the info for the server we wish to send the message to ;; -(define (server:send servpkt data dtype) +(define (server:send servpkt data action) (let* ((port (alist-ref 'port servpkt)) (host (alist-ref 'hostname servpkt)) (ip (alist-ref 'ip servpkt)) (hkey (alist-ref 'Z servpkt)) (addr (conc (or ip host) ":" port)) ;; fall back to host if ip not provided @@ -242,11 +267,11 @@ (lambda () (write `((hostname . ,myhost) (port . ,myport) (servkey . ,hkey) ;; server looks at this to ensure message is for them (hostkey . ,mykey) - (format . ,dtype) ;; formating of the message + (action . ,action) ;; formating of the message (data . ,data)) ;; *pktspec* ;; ptype: 'data)) ))))) (print "msg: " msg) @@ -272,11 +297,11 @@ ;; is the server alive? ;; (define (server:ping servpkt) (let* ((start-time (current-milliseconds)) - (res (server:send servpkt "ping" "t"))) + (res (server:send servpkt 'ping 'immediate))) (cons (- (current-milliseconds) start-time) res))) ;; (equal? res "got ping")))) ;; look up all pkts and get the server id (the hash), port, host/ip ;; store this info in the global struct *area-info*