Megatest

Check-in [0c8e6ec6fd]
Login
Overview
Comment:outline of the task dispatcher coded
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.65-multi-db
Files: files | file ages | folders
SHA1: 0c8e6ec6fdc3c7fbab8ca602f6aeb6cf430add71
User & Date: matt on 2019-02-06 22:24:12
Other Links: branch diff | manifest | tags
Context
2019-02-07
10:19
Tidy up of mtut formating check-in: e52f8b2513 user: matt tags: v1.65-multi-db
2019-02-06
22:24
outline of the task dispatcher coded check-in: 0c8e6ec6fd user: matt tags: v1.65-multi-db
17:00
Print out recieved/sent data at server end. check-in: bea6ae9a16 user: mrwellan tags: v1.65-multi-db
Changes

Modified server.scm from [4a0ee391d0] to [afd098704f].

59
60
61
62
63
64
65


66
67
68
69
70
71
72
;; P K T S   S T U F F 
;;======================================================================

;;======================================================================
;;  N A N O M S G   B A S E D   S E R V E R
;;======================================================================



(defstruct area
  (conn  #f)
  (port  #f)
  (myaddr #f)
  (hosts (make-hash-table))
  pktid  ;; get pkt from hosts table if needed
  pktfile







>
>







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;; P K T S   S T U F F 
;;======================================================================

;;======================================================================
;;  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))
  pktid  ;; get pkt from hosts table if needed
  pktfile
144
145
146
147
148
149
150







151
152










153
154






155
156
157
158
159
160
161
	  (area-pktsdir-set! *area-info* pktdir)
	  (area-mtrah-set!   *area-info* mtdir)
	  (area-conn-set!    *area-info* area-conn)
	  (area-port-set!    *area-info* port-num)
	  (mutex-unlock! (area-mutex *area-info*))
	  area-conn))))








(define (server:std-handler dat)
  ;; (let* ((from-host (alist-ref 'hostname dat))










  dat)
	 







;; Call this to start the actual server
;;
;; start_server
;;
;;   mode: '
;;   handler: proc which takes pktrecieved as argument







>
>
>
>
>
>
>

|
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
	  (area-pktsdir-set! *area-info* pktdir)
	  (area-mtrah-set!   *area-info* mtdir)
	  (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))
	 (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
;;
;;   mode: '
;;   handler: proc which takes pktrecieved as argument
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
  (pid . "28748")
  (hostname . "zeus")
  (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)
  (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
	 (myport (area-port *area-info*))
	 (myhost (area-myaddr *area-info*))
	 (mykey  (area-pktid  *area-info*))
	 (msg    (with-output-to-string
		   (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
			      (data     . ,data))
			    ;; *pktspec*
			    ;; ptype: 'data))
			    )))))
    (print "msg: " msg)
    (if (and port host)
	(begin







|














|







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
  (pid . "28748")
  (hostname . "zeus")
  (T . "server")
  (D . "1549427032.0"))

;; srvpkt is the info for the server we wish to send the message to
;;
(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
	 (myport (area-port *area-info*))
	 (myhost (area-myaddr *area-info*))
	 (mykey  (area-pktid  *area-info*))
	 (msg    (with-output-to-string
		   (lambda ()
		     (write `((hostname . ,myhost)
			      (port     . ,myport)
			      (servkey  . ,hkey)     ;; server looks at this to ensure message is for them
			      (hostkey  . ,mykey)
			      (action   . ,action)    ;; formating of the message
			      (data     . ,data))
			    ;; *pktspec*
			    ;; ptype: 'data))
			    )))))
    (print "msg: " msg)
    (if (and port host)
	(begin
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
;; "Client side" operations
;;======================================================================

;; is the server alive?
;;
(define (server:ping servpkt)
  (let* ((start-time (current-milliseconds))
	 (res        (server:send servpkt "ping" "t")))
    (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*
;;
(define (server:get-all)







|







295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
;; "Client side" operations
;;======================================================================

;; is the server alive?
;;
(define (server:ping servpkt)
  (let* ((start-time (current-milliseconds))
	 (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*
;;
(define (server:get-all)