Packets
;; Copyright 2006-2017, Matthew Welland.
;;
;; This file is part of Pkts
;;
;; Pkts is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Pkts is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Pkts. If not, see <http://www.gnu.org/licenses/>.
;;
;; CARDS:
;;
;; A card is a line of text, the first two characters are a letter followed by a
;; space. The letter is the card type.
;;
;; PKTS:
;;
;; A pkt is a sorted list of cards with a final card Z that contains the shar1 hash
;; of all of the preceding cards.
;;
;; APKT:
;;
;; An alist mapping card types to card data
;; '((T . "pkttype")
;; (a . "some content"))
;;
;; EPKT:
;;
;; Extended packet using friendly keys. Must use a pktspec to convert to/from epkts
;; '((ptype . "pkttype")
;; (adata . "some content))
;;
;; DPKT:
;;
;; pkts pulled from the database have this format:
;;
;;((apkt (Z . "7de89c09ac024b3832c93e16cd78d11e2e28733b") <= this is a the alist
;; (t . "v1.63/tip/dev")
;; (c . "QUICKPATT")
;; (T . "runstart")
;; (P . "354eeb67120a921e3e33155ecab1b522ac10b6bd")
;; (D . "1488995096.0"))
;; (id . 8)
;; (group-id . 0)
;; (uuid . "7de89c09ac024b3832c93e16cd78d11e2e28733b")
;; (parent . "")
;; (pkt-type . "runstart")
;; (pkt . "D 1488995096.0\nP 354eeb67120a921e3e33155ecab1b522ac10b6bd\nT runstart\nc QUICKPATT\nt v1.63/tip/dev\nZ 7de89c09ac024b3832c93e16cd78d11e2e28733b"))
;;
;; pktspec is alist of alists mapping types and nicekeys to keys
;;
;; '((posting . ((title . t)
;; (url . u)
;; (blurb . b)))
;; (comment . ((comment . c)
;; (score . s))))
;; Reserved cards:
;; P : pkt parent
;; R : reference pkt containing mapping of short string -> sha1sum strings
;; T : pkt type
;; D : current time from (current-time), unless provided
;; Z : shar1 hash of the packet
;; Example usage:
;;
;; Create a pkt:
;;
;; (use pkts)
;; (define-values (uuid pkt)
;; (alist->pkt
;; '((fruit . "apple") (meat . "beef")) ;; this is the data to convert
;; '((foods (fruit . f) (meat . m))) ;; this is the pkt spec
;; ptype:
;; 'foods))
;;
;; Add to pkt queue:
;;
;; (define db (open-queue-db "/tmp/pkts" "pkts.db"))
;; (add-to-queue db pkt uuid 'foods #f 0) ;; no parent and use group_id of 0
;;
;; Retrieve the packet from the db and extract a value:
;;
;; (alist-ref
;; 'meat
;; (dpkt->alist
;; (car (get-dpkts db #f 0 #f))
;; '((foods (fruit . f)
;; (meat . m)))))
;; => "beef"
;;