aboutsummaryrefslogtreecommitdiff
path: root/src/cljs/gnunet_web/hello.cljs
blob: 83efd3eb270d4604f14766a55af6b4f44d0e44ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;; hello.cljs - HELLO parser for gnunet-web website
;; Copyright (C) 2013,2014  David Barksdale <amatus@amatus.name>
;;
;; This program 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.
;;
;; This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

(ns gnunet-web.hello
  (:use [gnunet-web.parser :only (items none-or-more parser parse-date
                                        parse-uint16 parse-uint32 parse-utf8)])
  (:require-macros [monads.macros :as monadic]))

(def message-type-hello 17)

(def parse-transport-address
  (monadic/do parser
              [transport parse-utf8
               address-length parse-uint16
               expiration parse-date
               encoded-address (items address-length)]
              {:transport transport
               :expiration expiration
               :encoded-address (.apply js/Array nil encoded-address)}))

(def parse-hello
  (with-meta
    (monadic/do parser
                [friend-only parse-uint32
                 public-key (items 32)
                 addresses (none-or-more parse-transport-address)]
                {:friend-only friend-only
                 :public-key (.apply js/Array nil public-key)
                 :transport-addresses
                 (reduce (fn [map address]
                           (assoc-in map [(:transport address)
                                          (:encoded-address address)]
                                     (:expiration address)))
                         nil
                         addresses)})
    {:message-type message-type-hello}))

(defn merge-hello
  [a b]
  )

(defn equals-hello
  [a b expiration]
  )

(defn update-friend-hello
  [a b]
  )