Megatest

Check-in [852e127507]
Login
Overview
Comment:wip
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.70-captain-ulex | v1.70-defunct-try
Files: files | file ages | folders
SHA1: 852e127507766d1e196fef641e3f77a9a0bc39fd
User & Date: matt on 2020-01-01 23:28:33
Other Links: branch diff | manifest | tags
Context
2020-01-02
19:48
wip check-in: ad7092727d user: mrwellan tags: v1.70-captain-ulex, v1.70-defunct-try
2020-01-01
23:28
wip check-in: 852e127507 user: matt tags: v1.70-captain-ulex, v1.70-defunct-try
23:12
wip check-in: 0b096cbab6 user: matt tags: v1.70-captain-ulex, v1.70-defunct-try
Changes

Modified ulex/ulex.scm from [9daa591c44] to [b8061e96e6].

237
238
239
240
241
242
243
244
245
246
247
248
249
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
280
281
282
283
284
285
		     (let-values (((ninp noup)(tcp-connect host-port)))
		       (peer-inp-set! npdat ninp)
		       (peer-oup-set! npdat noup))
		     (hash-table-set! (udat-outgoing-conns udata) host-port npdat)
		     npdat))))
    pdat))

(define (get-peer-ports udata host-port hostname pid)
  (let ((pdat (get-peer-dat udata host-port hostname pid)))
    (values (peer-inp pdat)(peer-oup pdat))))

;; send back ack
;;
(define (send-ack udata qrykey oup)

  (write-line (conc
	       "ack "
	       (udat-my-address  udata) ":" (udat-my-port udata) " "
	       (udat-my-hostname udata) " "
	       (udat-my-pid      udata) " "
	       qrykey)
	      oup)
  (write-line qrykey oup)) ;; we must send a second line - for the ack let it be the qrykey 





  
;; 
;;
(define (ulex-handler udata)
  (let* ((serv-listener (udat-serv-listener udata)))
    (let-values (((inp oup)(tcp-accept serv-listener)))
      ;; data comes as two lines
      ;;   handlerkey resp-addr:resp-port hostname pid qrykey [dbpath/dbfile.db]
      ;;   data
      (let loop ((state 'start))
	(let* ((controldat (read-line inp))
	       (data       (read-line inp)))
	  (match (string-split controldat)
	    ((handlerkey host:port hostname pid qrykey params ...)
	     (case (string->symbol handlerkey)





	       (else
		(let-values (((pinp poup)(get-peer-ports udata host:port hostname pid)))
		  (send-ack udata qrykey poup))
		(add-to-work-queue (get-peer-dat udata host:port) handlerkey data))))
	    (else (print "BAD DATA? handler=" handler " data=" data))))
	(loop state)))))

;;======================================================================
;; connection setup and management functions
;;======================================================================

;; find or become the captain, return a ulex object







|





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















>
>
>
>
>

<
|
|
|







237
238
239
240
241
242
243
244
245
246
247
248
249
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
280
281
282
283
284
285

286
287
288
289
290
291
292
293
294
295
		     (let-values (((ninp noup)(tcp-connect host-port)))
		       (peer-inp-set! npdat ninp)
		       (peer-oup-set! npdat noup))
		     (hash-table-set! (udat-outgoing-conns udata) host-port npdat)
		     npdat))))
    pdat))

(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
;;
(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 " "
		 (udat-my-address  udata) ":" (udat-my-port udata) " "
		 (udat-my-hostname udata) " "
		 (udat-my-pid      udata) " "
		 qrykey)
		oup)
    (write-line data oup))) ;; we must send a second line - for the ack let it be the qrykey 
  
;; send back ack
;;
(define (send-ack udata host-port qrykey #!optional (hostname #f)(pid #f))
  (reply udata "ack" qrykey oup qrykey hostname pid)) ;; we must send a second line - for the ack let it be the qrykey 
  
;; 
;;
(define (ulex-handler udata)
  (let* ((serv-listener (udat-serv-listener udata)))
    (let-values (((inp oup)(tcp-accept serv-listener)))
      ;; data comes as two lines
      ;;   handlerkey resp-addr:resp-port hostname pid qrykey [dbpath/dbfile.db]
      ;;   data
      (let loop ((state 'start))
	(let* ((controldat (read-line inp))
	       (data       (read-line inp)))
	  (match (string-split controldat)
	    ((handlerkey host:port hostname pid qrykey params ...)
	     (case (string->symbol handlerkey)
	       ((ack)(print "Got ack!"))
	       ((rucaptain)
		(reply udata host:port "iamcaptain" qrykey (if (udat-my-cpkt-key udata)
							       "yes"
							       "no")))
	       (else

		(send-ack udata host:port qrykey hostname pid)
		(add-to-work-queue (get-peer-dat udata host:port) handlerkey data)))
	     (else (print "BAD DATA? handler=" handler " data=" data)))))
	(loop state)))))

;;======================================================================
;; connection setup and management functions
;;======================================================================

;; find or become the captain, return a ulex object