configuration.tm 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <TeXmacs|2.1>
  2. <project|scheme-gnunet.tm>
  3. <style|tmmanual>
  4. <\body>
  5. There are a number of modules for accessing GNUnet
  6. configurations<index|configuration>.<space|1em>Firstly, there is <scm|(gnu
  7. gnunet config db)><index|(gnu gnunet config db)>, which is the module
  8. library code would typically use.<space|1em>For testing, one can create an
  9. empty configuration with the procedure <scm|hash-\<gtr\>configuration><index|hash-\<gtr\>configuration>
  10. from that module and <scm|make-hashtable> from <scm|(rnrs hashtables)>,
  11. using <scm|hash-key><index|hash-key> as hash function and
  12. <scm|key=?><index|key=?> as comparison function:
  13. <\scm-code>
  14. (import (gnu gnunet config db)
  15. \ \ \ \ \ \ \ \ (gnu gnunet config value-parser)
  16. \ \ \ \ \ \ \ \ (rnrs hashtables))
  17. (define config (hash-\<gtr\>configuration (make-hashtable hash-key
  18. key=?))
  19. </scm-code>
  20. The resulting configuration <scm|config> is initially empty, so set some
  21. <with|font-shape|italic|keys> in the <with|font-shape|italic|section>
  22. <verbatim|nse>, to configure the network-size estimation service:
  23. <\scm-code>
  24. (set-value! identity config "nse" "UNIXPATH"
  25. "/tmp/nse.sock")<index|set-value!>
  26. (set-value! number-\<gtr\>string config "cadet" "MAX_ROUTES" 5000)
  27. ;; TODO: IP address, time durations, booleans, ...
  28. </scm-code>
  29. Now read these values back:
  30. <\scm-code>
  31. (read-value value-\<gtr\>file-name config "nse"
  32. "UNIXPATH")<index|read-value>
  33. ;; -\<gtr\> /tmp/nse.sock
  34. (read-value value-\<gtr\>natural config "cadet" "MAX_ROUTES")
  35. ;; -\<gtr\> 5000
  36. </scm-code>
  37. What if the configuration doesn't have a value for the specified section
  38. and key?<space|1em>Then an <scm|&undefined-key-error><index|&undefined-key-error>
  39. results:
  40. <\scm-code>
  41. (read-value value-\<gtr\>natural config "kated" "MAX_ROUTES")
  42. ;; -\<gtr\>
  43. ;; ice-9/boot-9.scm:1685:16: In procedure raise-exception:
  44. ;; ERROR:
  45. ;; \ \ 1. &undefined-key-error:
  46. ;; \ \ \ \ \ \ section: "kated"
  47. ;; \ \ \ \ \ \ key: "MAX_ROUTES"
  48. </scm-code>
  49. <section|Locating configuration files>
  50. There are two \U possibly non-existent \U configuration files: the
  51. <with|font-shape|italic|user> configuration<subindex|configuration|user>
  52. and the <with|font-shape|italic|system>
  53. configuration<subindex|configuration|system>.<space|1em>The
  54. <with|font-shape|italic|system> configuration typically contains the paths
  55. for services like NSE, CORE, <text-dots><space|1em>A user may choose not to
  56. use the services by the system and instead use their own.<space|1em>To do
  57. so, the user needs to override the paths in the
  58. <with|font-shape|italic|user> configuration.<space|1em><todo|defaults?> The
  59. module <scm|(gnu gnunet config fs)><index|(gnu gnunet config fs)> is
  60. responsible for determining the location of the configuration files to load
  61. and actually load configuration files.<space|1em>For determining the
  62. location of the configuration files, the procedures
  63. <scm|locate-user-configuration> and <scm|locate-system-configuration> can
  64. be used.
  65. <\warning>
  66. The C implementation's mechanism for user-system separation seems to work
  67. differently.
  68. </warning>
  69. <\explain>
  70. <scm|(locate-user-configuration <scm|#:getenv=getenv>)><index|locate-user-configuration>
  71. <|explain>
  72. This procedure determines the location of the user configuration file, as
  73. a string, or <scm|#false> if it could not be determined.<space|1em>If the
  74. location of the user configuration file is known, but the file does not
  75. exist, it is returned anyway, as a string.
  76. If the environment variable <shell|XDG_CONFIG_HOME> is set, the location
  77. of the file <verbatim|gnunet.conf> in the directory
  78. <shell|$XDG_CONFIG_HOME> is returned.<space|1em>If the environment
  79. variable is not set, the location of the file at
  80. <verbatim|.config/gnunet.conf><index|~/.config/gnunet.conf> in the home
  81. directory specified by the environment variable <verbatim|HOME> is
  82. returned, if that environment variable exists.<space|1em>If both are
  83. unset, <scm|#false> is returned.
  84. The values of environment variables is determined with the procedure
  85. <scm|getenv>.
  86. </explain>
  87. <\explain>
  88. <scm|(locate-system-configuration)><index|locate-system-configuration>
  89. <|explain>
  90. This procedure determines the location of the system configuration file,
  91. as a string.
  92. Currently, this is always <verbatim|/etc/gnunet.conf><index|/etc/gnunet.conf>.
  93. </explain>
  94. <section|Loading configuration files>
  95. Once the location of the configuration file is known, the file can be
  96. opened with the Scheme procedure <scm|open-input-file>, which returns an
  97. input port.<space|1em>Then the procedure <scm|load-configuration/port!> can
  98. be used to determine all section-key-values triples in the configuration.
  99. <\explain>
  100. <scm|(load-configuration/port! <var|set-value!>
  101. <var|port>)><index|load-configuration/port!>
  102. <|explain>
  103. Load the configuration from the input port <var|port>.
  104. For each variable, call <var|set-value!> with the section name, variable
  105. name and a vector of the form <scm|#(line line-number value)>, where
  106. <var|value> a list of expansible objects.
  107. <todo|document expansible objects><todo|error reporting>
  108. </explain>
  109. A variable assignment<index|variable assignment> <verbatim|[section]
  110. key=value${var}> can refer to variables defined in the <verbatim|PATHS>
  111. section and variables from the environment.<space|1em>The previously
  112. described procedure <scm|load-configuration/port!> will <em|not> expand
  113. such assignements. \ To expand variable assignments, use the procedure
  114. <scm|make-expanded-configuration> instead.
  115. <\explain>
  116. <scm|(make-expanded-configuration <var|load!>
  117. #:getenv=<var|getenv>)><index|make-expanded-configuration>
  118. <|explain>
  119. Make a configuration object.<space|1em>To populate the configuration, all
  120. the procedure <var|load!> with a <scm|set-value!> procedure as expected
  121. by <scm|load-configuration/port!>.<space|1em>The values from
  122. <scm|set-value!> are added to the confoiguration and every variable is
  123. expanded.
  124. </explain>
  125. To automatically load the defaults, the system configuration and the user
  126. configuration, use the thunk <scm|load-configuration>:
  127. <\explain>
  128. <scm|(load-configuration #:getenv=<var|getenv>
  129. #:files=<text-dots>)><index|load-configuration>
  130. </explain|Load the defaults, the system configuration and the user
  131. configuration and return the resulting configuration object.<space|1em>The
  132. list of files to load can be overriden by setting the undocumented
  133. <var|files> keyword argument.>
  134. Applications (whether graphical or textual) are recommended to use
  135. <scm|load-configuration> by default, as it largely just works.
  136. </body>
  137. <\initial>
  138. <\collection>
  139. <associate|page-medium|paper>
  140. <associate|save-aux|false>
  141. </collection>
  142. </initial>