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: |
cb68d1b734358d410ee0fb73d83a2cac |
User & Date: | matt on 2020-01-05 22:53:15 |
Other Links: | branch diff | manifest | tags |
Context
2020-01-06
| ||
17:06 | wip check-in: 0390dc30b4 user: mrwellan tags: v1.70-captain-ulex, v1.70-defunct-try | |
2020-01-05
| ||
22:53 | wip check-in: cb68d1b734 user: matt tags: v1.70-captain-ulex, v1.70-defunct-try | |
20:51 | wip check-in: cc86d81234 user: matt tags: v1.70-captain-ulex, v1.70-defunct-try | |
Changes
Modified ulex/ulex.scm from [91a15a4ec1] to [f626150792].
︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | (format . f) ;; sb=serialized-base64, t=text, sx=sexpr, j=json (data . d) ;; base64 encoded slln data ))) ;; struct for keeping track of our world (defstruct udat (captain-address #f) (captain-host #f) (captain-port #f) (captain-pid #f) (ulex-dir (conc (get-environment-variable "HOME") "/.ulex")) (cpkts-dir (conc (get-environment-variable "HOME") "/.ulex/pkts")) (cpkt-spec *captain-pktspec*) (my-cpkt-key #f) ;; put Z card here when I create a pkt for myself as captain (my-address #f) (my-hostname #f) (my-port #f) (my-pid (current-process-id)) | > > > | > > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | (format . f) ;; sb=serialized-base64, t=text, sx=sexpr, j=json (data . d) ;; base64 encoded slln data ))) ;; struct for keeping track of our world (defstruct udat ;; captain info (captain-address #f) (captain-host #f) (captain-port #f) (captain-pid #f) (ulex-dir (conc (get-environment-variable "HOME") "/.ulex")) (cpkts-dir (conc (get-environment-variable "HOME") "/.ulex/pkts")) (cpkt-spec *captain-pktspec*) ;; this processes info (my-cpkt-key #f) ;; put Z card here when I create a pkt for myself as captain (my-address #f) (my-hostname #f) (my-port #f) (my-pid (current-process-id)) ;; server and handler thread (serv-listener #f) ;; this processes server info (handler-thread #f) (handlers (make-hash-table)) (outgoing-conns (make-hash-table)) ;; host:port -> conn ;; app info (appname #f) (dbtypes (make-hash-table)) ;; this should be an alist but hash is easier. dbtype => [ initproc syncproc ] ) ;; struct for keeping track of others we are talking to (defstruct peer (addr-port #f) (hostname #f) |
︙ | ︙ | |||
299 300 301 302 303 304 305 | ;; add a proc to the handler list (define (register-handler udata key proc) (hash-table-set! (udat-handlers udata) key proc)) ;;====================================================================== | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | > > | > > > > > > > > > | | | | | | | | | | < | > > > | 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | ;; add a proc to the handler list (define (register-handler udata key proc) (hash-table-set! (udat-handlers udata) key proc)) ;;====================================================================== ;; Generic db handling ;;====================================================================== (defstruct dbconn (inmem #f) (conn #f) (sync #f) ;; sync proc (init #f) ;; init proc (lastsync (current-seconds)) ) (defstruct dbinfo (initproc #f) (syncproc #f)) ;; open inmem and disk database ;; init with initproc ;; return db struct ;; ;; appname; megatest, ulex or something else. ;; (define (setup-db-connection udata fname-in appname dbtype) (let* ((is-ulex (eq? appname 'ulex)) (dbinf (if is-ulex ;; ulex is a built-in special case (make-dbinfo initproc: ulexdb-init syncproc: ulexdb-sync) (hash-table-ref/default (udat-dbtypes udata) dbtype #f))) (initproc (dbinfo-initproc dbinf)) (syncproc (dbinfo-syncproc dbinf)) (fname (if is-ulex (conc (udat-ulex-dir udata) "/ulex.db") fname-in)) (inmem-db (open-and-initdb udata #f 'inmem (dbinfo-initproc dbinf))) (disk-db (open-and-initdb udata fname 'disk (dbinfo-initproc dbinf)))) (make-dbconn inmem: inmem-db conn: disk-db sync: syncproc init: initproc))) ;; dest='inmem or 'disk ;; (define (open-and-initdb udata filename dest init-proc) (let* ((inmem (eq? dest 'inmem)) (dbfile (if inmem ":INMEM:" filename)) (dbexists (if inmem #t (file-exists? dbfile))) (db (sqlite3:open-database dbfile))) (sqlite3:set-busy-handler! db (sqlite3:make-busy-timeout 136000)) (if (not dbexists) (init-proc db)) db)) ;;====================================================================== ;; Ulex db ;;====================================================================== (define (ulexdb-init db inmem) (sqlite3:with-transaction db (lambda () (for-each (lambda (stmt) (if stmt (sqlite3:execute db stmt))) `("CREATE TABLE IF NOT EXISTS processes (id INTEGER PRIMARY KEY, host TEXT NOT NULL, ipadr TEXT NOT NULL, port INTEGER NOT NULL, pid INTEGER NOT NULL, regtime INTEGER DEFAULT (strftime('%s','now')), last_update INTEGER DEFAULT (strftime('%s','now')));" (if inmem "CREATE TRIGGER IF NOT EXISTS update_proces_trigger AFTER UPDATE ON processes FOR EACH ROW BEGIN UPDATE processes SET last_update=(strftime('%s','now')) WHERE id=old.id; END;" #f)))))) ;; open databases, do initial sync (define (ulexdb-sync dbconndat udata) #f) ;;====================================================================== ;; connection setup and management functions ;;====================================================================== ;; find or become the captain, return a ulex object |
︙ | ︙ |