aboutsummaryrefslogtreecommitdiff
path: root/gnu/gnunet/util/struct.scm
blob: f4c3cbb9422022e8fb7fa1a0f37a1d5a7d8b2ffc (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;; This file is part of GNUnet.
;; Copyright (C) 2006-2021 GNUnet e.V.
;;
;; GNUnet is free software: you can redistribute it and/or modify it
;; under the terms of the GNU Affero General Public License as published
;; by the Free Software Foundation, either version 3 of the License,
;; or (at your option) any later version.
;;
;; GNUnet 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
;; Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
;;
;; SPDX-License-Identifier: AGPL3.0-or-later

;; Brief: many network structures, that would otherwise result in very
;; small source files if each was put in their own module.
(define-library (gnu gnunet util struct)
  (export /uuid /time-absolute
	  /:message-header /:operation-result /async-scope-id)
  (import (only (gnu gnunet netstruct syntactic)
		define-type structure/packed)
	  (only (gnu gnunet netstruct procedural)
		u8vector u16/big u32/big u64/big)
	  (only (rnrs base) begin))
  (begin
    ;; Absolute time (in GNUnet), in microseconds
    (define-type /time-absolute u64/big)

    (define-type /uuid
      (structure/packed
       (synopsis "A UUID, a 128 bit random value")
       (field (value/u8 (u8vector 16))
	      (synopsis "128 random bits")
	      (documentation
	       "This is represented as an array of uint32 in GNUnet"))))

    ;; If this definition is ever changed (breaking compatibility with
    ;; C GNUnet), make sure to change (gnu gnunet utils tokeniser)
    ;; appropriately as well -- the field types and positions are
    ;; hardcoded there.
    (define-type /:message-header
      (structure/packed
       (synopsis "Header for all communications")
       (field (size u16/big)
	      (documentation
	       "The length of the struct (in bytes, including the length
field itself), in big-endian format."))
       (field (type u16/big)
	      (synopsis "The type of the message")
	      (documentation
	       "The type of the message (GNUNET_MESSAGE_TYPE_XXXX in the C
implementation and msg:XXX:YYY:... in the Scheme implementation),
in big-endian format."))))

    (define-type /:operation-result
      (structure/packed
       (synopsis "Answer from service to client about last operation")
       (documentation "Possibly followed by data")
       (field (header /:message-header))
       (field (reserved u32/big))
       (field (operation-id u64/big)
	      (synopsis "Operation ID"))
       (field (result-code u64/big)
	      (synopsis "Status code for the operation"))))

    (define-type /async-scope-id
      (structure/packed
       (synopsis "Identifier for an asynchronous execution context")
       (documentation
	"This is represented as an array of uint32_t in GNUnet.")
       (field (bits/u8 (u8vector 16)))))))