kibi-swipl-linux-x64-gnu 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (550) hide show
  1. package/README.md +29 -0
  2. package/bin/swipl +0 -0
  3. package/bin/swipl-win +0 -0
  4. package/build-manifest.json +70 -0
  5. package/lib/cmake/swipl/SWIPLConfig.cmake +21 -0
  6. package/lib/cmake/swipl/SWIPLConfigVersion.cmake +65 -0
  7. package/lib/cmake/swipl/SWIPLTargets-release.cmake +28 -0
  8. package/lib/cmake/swipl/SWIPLTargets.cmake +109 -0
  9. package/lib/swipl/ABI +1 -0
  10. package/lib/swipl/LICENSE +41 -0
  11. package/lib/swipl/README.md +116 -0
  12. package/lib/swipl/app/README.md +25 -0
  13. package/lib/swipl/app/app.pl +87 -0
  14. package/lib/swipl/app/pack.pl +350 -0
  15. package/lib/swipl/app/qlf.pl +521 -0
  16. package/lib/swipl/app/splfr.pl +177 -0
  17. package/lib/swipl/app/sys.pl +310 -0
  18. package/lib/swipl/bin/swipl.home +1 -0
  19. package/lib/swipl/boot/apply.pl +73 -0
  20. package/lib/swipl/boot/attvar.pl +344 -0
  21. package/lib/swipl/boot/autoload.pl +1226 -0
  22. package/lib/swipl/boot/bags.pl +283 -0
  23. package/lib/swipl/boot/dcg.pl +388 -0
  24. package/lib/swipl/boot/dicts.pl +193 -0
  25. package/lib/swipl/boot/dwim.pl +485 -0
  26. package/lib/swipl/boot/engines.pl +152 -0
  27. package/lib/swipl/boot/expand.pl +1628 -0
  28. package/lib/swipl/boot/gc.pl +65 -0
  29. package/lib/swipl/boot/history.pl +304 -0
  30. package/lib/swipl/boot/init.pl +4682 -0
  31. package/lib/swipl/boot/iri.pl +64 -0
  32. package/lib/swipl/boot/license.pl +390 -0
  33. package/lib/swipl/boot/load.pl +81 -0
  34. package/lib/swipl/boot/messages.pl +2521 -0
  35. package/lib/swipl/boot/packs.pl +306 -0
  36. package/lib/swipl/boot/predopts.pl +154 -0
  37. package/lib/swipl/boot/qlf.pl +141 -0
  38. package/lib/swipl/boot/rc.pl +263 -0
  39. package/lib/swipl/boot/syspred.pl +1634 -0
  40. package/lib/swipl/boot/tabling.pl +2321 -0
  41. package/lib/swipl/boot/threads.pl +42 -0
  42. package/lib/swipl/boot/toplevel.pl +2248 -0
  43. package/lib/swipl/boot/topvars.pl +261 -0
  44. package/lib/swipl/boot.prc +0 -0
  45. package/lib/swipl/cmake/swipl.cmake +131 -0
  46. package/lib/swipl/customize/README.md +23 -0
  47. package/lib/swipl/customize/edit +101 -0
  48. package/lib/swipl/customize/init.pl +164 -0
  49. package/lib/swipl/demo/README.md +33 -0
  50. package/lib/swipl/demo/likes.pl +44 -0
  51. package/lib/swipl/doc/packages/examples/chr/bool.chr +281 -0
  52. package/lib/swipl/doc/packages/examples/chr/chrdif.chr +87 -0
  53. package/lib/swipl/doc/packages/examples/chr/chrfreeze.chr +6 -0
  54. package/lib/swipl/doc/packages/examples/chr/family.chr +116 -0
  55. package/lib/swipl/doc/packages/examples/chr/fib.chr +24 -0
  56. package/lib/swipl/doc/packages/examples/chr/fibonacci.chr +31 -0
  57. package/lib/swipl/doc/packages/examples/chr/gcd.chr +28 -0
  58. package/lib/swipl/doc/packages/examples/chr/leq.chr +34 -0
  59. package/lib/swipl/doc/packages/examples/chr/listdom.chr +138 -0
  60. package/lib/swipl/doc/packages/examples/chr/primes.chr +29 -0
  61. package/lib/swipl/doc/packages/examples/http/README.md +98 -0
  62. package/lib/swipl/doc/packages/examples/http/calc.pl +92 -0
  63. package/lib/swipl/doc/packages/examples/http/demo_body.pl +232 -0
  64. package/lib/swipl/doc/packages/examples/http/demo_client.pl +165 -0
  65. package/lib/swipl/doc/packages/examples/http/demo_daemon.pl +38 -0
  66. package/lib/swipl/doc/packages/examples/http/demo_files.pl +50 -0
  67. package/lib/swipl/doc/packages/examples/http/demo_hello.pl +15 -0
  68. package/lib/swipl/doc/packages/examples/http/demo_login.pl +280 -0
  69. package/lib/swipl/doc/packages/examples/http/demo_openid.pl +177 -0
  70. package/lib/swipl/doc/packages/examples/http/demo_pwp.pl +20 -0
  71. package/lib/swipl/doc/packages/examples/http/demo_rest.pl +56 -0
  72. package/lib/swipl/doc/packages/examples/http/demo_threads.pl +52 -0
  73. package/lib/swipl/doc/packages/examples/http/linux-init-script +126 -0
  74. package/lib/swipl/doc/packages/examples/http/pwp/context.pwp +23 -0
  75. package/lib/swipl/doc/packages/examples/http/pwp/index.pwp +25 -0
  76. package/lib/swipl/doc/packages/examples/http/pwp/pwp1.pwp +12 -0
  77. package/lib/swipl/doc/packages/examples/http/pwp/pwp2.pwp +10 -0
  78. package/lib/swipl/doc/packages/examples/http/pwp/pwp3.pwp +25 -0
  79. package/lib/swipl/doc/packages/examples/http/pwp/pwp4.pwp +23 -0
  80. package/lib/swipl/doc/packages/examples/http/pwp/pwp5.pwp +11 -0
  81. package/lib/swipl/doc/packages/examples/http/pwp/pwp6.pwp +3 -0
  82. package/lib/swipl/doc/packages/examples/http/pwp/pwp7.pwp +3 -0
  83. package/lib/swipl/doc/packages/examples/http/pwp/pwp8.pwp +3 -0
  84. package/lib/swipl/doc/packages/examples/http/pwp/pwpdb.pl +12 -0
  85. package/lib/swipl/doc/packages/examples/http/systemd-script.service +18 -0
  86. package/lib/swipl/doc/packages/examples/http/upstart-script.conf +20 -0
  87. package/lib/swipl/doc/packages/examples/plunit/read.pl +17 -0
  88. package/lib/swipl/doc/packages/examples/plunit/simple.pl +33 -0
  89. package/lib/swipl/doc/packages/examples/ssl/client.pl +83 -0
  90. package/lib/swipl/doc/packages/examples/ssl/etc/README +52 -0
  91. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.p12 +0 -0
  92. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.pem +85 -0
  93. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-key.pem +30 -0
  94. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/cacert.pem +82 -0
  95. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/careq.pem +18 -0
  96. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/crlnumber +1 -0
  97. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt +3 -0
  98. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt.attr +1 -0
  99. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7C.pem +85 -0
  100. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7D.pem +85 -0
  101. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/private/cakey.pem +30 -0
  102. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/serial +1 -0
  103. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-cert.pem +85 -0
  104. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-key.pem +30 -0
  105. package/lib/swipl/doc/packages/examples/ssl/https.pl +267 -0
  106. package/lib/swipl/doc/packages/examples/ssl/server.pl +106 -0
  107. package/lib/swipl/include/SWI-Prolog.h +1544 -0
  108. package/lib/swipl/include/SWI-Stream.h +537 -0
  109. package/lib/swipl/include/Yap/YapInterface.h +283 -0
  110. package/lib/swipl/include/sicstus/sicstus.h +452 -0
  111. package/lib/swipl/lib/x86_64-linux/cgi.so +0 -0
  112. package/lib/swipl/lib/x86_64-linux/crypt.so +0 -0
  113. package/lib/swipl/lib/x86_64-linux/crypto4pl.so +0 -0
  114. package/lib/swipl/lib/x86_64-linux/double_metaphone.so +0 -0
  115. package/lib/swipl/lib/x86_64-linux/files.so +0 -0
  116. package/lib/swipl/lib/x86_64-linux/hashstream.so +0 -0
  117. package/lib/swipl/lib/x86_64-linux/http_stream.so +0 -0
  118. package/lib/swipl/lib/x86_64-linux/isub.so +0 -0
  119. package/lib/swipl/lib/x86_64-linux/json.so +0 -0
  120. package/lib/swipl/lib/x86_64-linux/libswipl.so.10 +0 -0
  121. package/lib/swipl/lib/x86_64-linux/mallocinfo.so +0 -0
  122. package/lib/swipl/lib/x86_64-linux/md54pl.so +0 -0
  123. package/lib/swipl/lib/x86_64-linux/memfile.so +0 -0
  124. package/lib/swipl/lib/x86_64-linux/ntriples.so +0 -0
  125. package/lib/swipl/lib/x86_64-linux/pcre4pl.so +0 -0
  126. package/lib/swipl/lib/x86_64-linux/porter_stem.so +0 -0
  127. package/lib/swipl/lib/x86_64-linux/process.so +0 -0
  128. package/lib/swipl/lib/x86_64-linux/prolog_stream.so +0 -0
  129. package/lib/swipl/lib/x86_64-linux/rdf_db.so +0 -0
  130. package/lib/swipl/lib/x86_64-linux/readutil.so +0 -0
  131. package/lib/swipl/lib/x86_64-linux/rlimit.so +0 -0
  132. package/lib/swipl/lib/x86_64-linux/sched.so +0 -0
  133. package/lib/swipl/lib/x86_64-linux/sgml2pl.so +0 -0
  134. package/lib/swipl/lib/x86_64-linux/sha4pl.so +0 -0
  135. package/lib/swipl/lib/x86_64-linux/snowball.so +0 -0
  136. package/lib/swipl/lib/x86_64-linux/socket.so +0 -0
  137. package/lib/swipl/lib/x86_64-linux/ssl4pl.so +0 -0
  138. package/lib/swipl/lib/x86_64-linux/streaminfo.so +0 -0
  139. package/lib/swipl/lib/x86_64-linux/syslog.so +0 -0
  140. package/lib/swipl/lib/x86_64-linux/time.so +0 -0
  141. package/lib/swipl/lib/x86_64-linux/turtle.so +0 -0
  142. package/lib/swipl/lib/x86_64-linux/uid.so +0 -0
  143. package/lib/swipl/lib/x86_64-linux/unix.so +0 -0
  144. package/lib/swipl/lib/x86_64-linux/uri.so +0 -0
  145. package/lib/swipl/lib/x86_64-linux/websocket.so +0 -0
  146. package/lib/swipl/lib/x86_64-linux/zlib4pl.so +0 -0
  147. package/lib/swipl/library/INDEX.pl +1020 -0
  148. package/lib/swipl/library/aggregate.pl +755 -0
  149. package/lib/swipl/library/ansi_term.pl +653 -0
  150. package/lib/swipl/library/apply.pl +426 -0
  151. package/lib/swipl/library/apply_macros.pl +497 -0
  152. package/lib/swipl/library/arithmetic.pl +320 -0
  153. package/lib/swipl/library/assoc.pl +522 -0
  154. package/lib/swipl/library/atom.pl +169 -0
  155. package/lib/swipl/library/backcomp.pl +688 -0
  156. package/lib/swipl/library/base32.pl +291 -0
  157. package/lib/swipl/library/base64.pl +441 -0
  158. package/lib/swipl/library/broadcast.pl +161 -0
  159. package/lib/swipl/library/build/cmake.pl +137 -0
  160. package/lib/swipl/library/build/conan.pl +232 -0
  161. package/lib/swipl/library/build/make.pl +168 -0
  162. package/lib/swipl/library/build/tools.pl +825 -0
  163. package/lib/swipl/library/charsio.pl +195 -0
  164. package/lib/swipl/library/check.pl +1097 -0
  165. package/lib/swipl/library/check_installation.pl +912 -0
  166. package/lib/swipl/library/clp/INDEX.pl +157 -0
  167. package/lib/swipl/library/clp/bounds.pl +2036 -0
  168. package/lib/swipl/library/clp/clp_distinct.pl +263 -0
  169. package/lib/swipl/library/clp/clp_events.pl +92 -0
  170. package/lib/swipl/library/clp/clpb.pl +1896 -0
  171. package/lib/swipl/library/clp/clpfd.pl +7906 -0
  172. package/lib/swipl/library/clp/simplex.pl +1580 -0
  173. package/lib/swipl/library/codesio.pl +182 -0
  174. package/lib/swipl/library/coinduction.pl +183 -0
  175. package/lib/swipl/library/console_input.pl +289 -0
  176. package/lib/swipl/library/csv.pl +611 -0
  177. package/lib/swipl/library/ctypes.pl +161 -0
  178. package/lib/swipl/library/date.pl +370 -0
  179. package/lib/swipl/library/dcg/INDEX.pl +35 -0
  180. package/lib/swipl/library/dcg/basics.pl +514 -0
  181. package/lib/swipl/library/dcg/high_order.pl +227 -0
  182. package/lib/swipl/library/debug.pl +499 -0
  183. package/lib/swipl/library/dialect/bim.pl +186 -0
  184. package/lib/swipl/library/dialect/commons.pl +77 -0
  185. package/lib/swipl/library/dialect/eclipse/test_util_iso.pl +355 -0
  186. package/lib/swipl/library/dialect/hprolog/format.pl +44 -0
  187. package/lib/swipl/library/dialect/hprolog.pl +314 -0
  188. package/lib/swipl/library/dialect/ifprolog.pl +1317 -0
  189. package/lib/swipl/library/dialect/iso/iso_predicates.pl +277 -0
  190. package/lib/swipl/library/dialect/sicstus/README.TXT +1 -0
  191. package/lib/swipl/library/dialect/sicstus/arrays.pl +121 -0
  192. package/lib/swipl/library/dialect/sicstus/block.pl +278 -0
  193. package/lib/swipl/library/dialect/sicstus/lists.pl +167 -0
  194. package/lib/swipl/library/dialect/sicstus/ordsets.pl +52 -0
  195. package/lib/swipl/library/dialect/sicstus/sockets.pl +174 -0
  196. package/lib/swipl/library/dialect/sicstus/system.pl +262 -0
  197. package/lib/swipl/library/dialect/sicstus/terms.pl +57 -0
  198. package/lib/swipl/library/dialect/sicstus/timeout.pl +92 -0
  199. package/lib/swipl/library/dialect/sicstus.pl +582 -0
  200. package/lib/swipl/library/dialect/sicstus4/aggregate.pl +60 -0
  201. package/lib/swipl/library/dialect/sicstus4/between.pl +62 -0
  202. package/lib/swipl/library/dialect/sicstus4/clpfd.pl +75 -0
  203. package/lib/swipl/library/dialect/sicstus4/file_systems.pl +413 -0
  204. package/lib/swipl/library/dialect/sicstus4/lists.pl +274 -0
  205. package/lib/swipl/library/dialect/sicstus4/ordsets.pl +54 -0
  206. package/lib/swipl/library/dialect/sicstus4/samsort.pl +86 -0
  207. package/lib/swipl/library/dialect/sicstus4/sets.pl +124 -0
  208. package/lib/swipl/library/dialect/sicstus4/sockets.pl +164 -0
  209. package/lib/swipl/library/dialect/sicstus4/system.pl +80 -0
  210. package/lib/swipl/library/dialect/sicstus4/terms.pl +89 -0
  211. package/lib/swipl/library/dialect/sicstus4/timeout.pl +43 -0
  212. package/lib/swipl/library/dialect/sicstus4/types.pl +103 -0
  213. package/lib/swipl/library/dialect/sicstus4.pl +200 -0
  214. package/lib/swipl/library/dialect/swi/syspred_options.pl +250 -0
  215. package/lib/swipl/library/dialect/xsb/README.md +20 -0
  216. package/lib/swipl/library/dialect/xsb/basics.pl +318 -0
  217. package/lib/swipl/library/dialect/xsb/consult.pl +87 -0
  218. package/lib/swipl/library/dialect/xsb/curr_sym.pl +57 -0
  219. package/lib/swipl/library/dialect/xsb/error_handler.pl +111 -0
  220. package/lib/swipl/library/dialect/xsb/gensym.pl +53 -0
  221. package/lib/swipl/library/dialect/xsb/gpp.pl +138 -0
  222. package/lib/swipl/library/dialect/xsb/intern.pl +48 -0
  223. package/lib/swipl/library/dialect/xsb/lists.pl +47 -0
  224. package/lib/swipl/library/dialect/xsb/machine.pl +295 -0
  225. package/lib/swipl/library/dialect/xsb/ordsets.pl +53 -0
  226. package/lib/swipl/library/dialect/xsb/setof.pl +54 -0
  227. package/lib/swipl/library/dialect/xsb/source.pl +308 -0
  228. package/lib/swipl/library/dialect/xsb/standard.pl +169 -0
  229. package/lib/swipl/library/dialect/xsb/storage.pl +70 -0
  230. package/lib/swipl/library/dialect/xsb/string.pl +76 -0
  231. package/lib/swipl/library/dialect/xsb/thread.pl +62 -0
  232. package/lib/swipl/library/dialect/xsb/timed_call.pl +158 -0
  233. package/lib/swipl/library/dialect/xsb.pl +688 -0
  234. package/lib/swipl/library/dialect/yap/README.TXT +8 -0
  235. package/lib/swipl/library/dialect/yap.pl +283 -0
  236. package/lib/swipl/library/dialect.pl +123 -0
  237. package/lib/swipl/library/dicts.pl +399 -0
  238. package/lib/swipl/library/dif.pl +426 -0
  239. package/lib/swipl/library/edinburgh.pl +138 -0
  240. package/lib/swipl/library/edit.pl +783 -0
  241. package/lib/swipl/library/error.pl +495 -0
  242. package/lib/swipl/library/exceptions.pl +231 -0
  243. package/lib/swipl/library/explain.pl +543 -0
  244. package/lib/swipl/library/ext/RDF/INDEX.pl +25 -0
  245. package/lib/swipl/library/ext/RDF/rdf.pl +450 -0
  246. package/lib/swipl/library/ext/RDF/rdf_parser.pl +649 -0
  247. package/lib/swipl/library/ext/RDF/rdf_triple.pl +448 -0
  248. package/lib/swipl/library/ext/RDF/rdf_write.pl +701 -0
  249. package/lib/swipl/library/ext/RDF/rewrite_term.pl +177 -0
  250. package/lib/swipl/library/ext/chr/chr/a_star.pl +80 -0
  251. package/lib/swipl/library/ext/chr/chr/binomialheap.pl +142 -0
  252. package/lib/swipl/library/ext/chr/chr/builtins.pl +629 -0
  253. package/lib/swipl/library/ext/chr/chr/chr_compiler_errors.pl +179 -0
  254. package/lib/swipl/library/ext/chr/chr/chr_compiler_options.pl +382 -0
  255. package/lib/swipl/library/ext/chr/chr/chr_compiler_utility.pl +338 -0
  256. package/lib/swipl/library/ext/chr/chr/chr_debug.pl +59 -0
  257. package/lib/swipl/library/ext/chr/chr/chr_hashtable_store.pl +425 -0
  258. package/lib/swipl/library/ext/chr/chr/chr_integertable_store.pl +139 -0
  259. package/lib/swipl/library/ext/chr/chr/chr_messages.pl +176 -0
  260. package/lib/swipl/library/ext/chr/chr/chr_op.pl +53 -0
  261. package/lib/swipl/library/ext/chr/chr/chr_runtime.pl +1016 -0
  262. package/lib/swipl/library/ext/chr/chr/chr_translate.pl +25424 -0
  263. package/lib/swipl/library/ext/chr/chr/clean_code.pl +252 -0
  264. package/lib/swipl/library/ext/chr/chr/find.pl +78 -0
  265. package/lib/swipl/library/ext/chr/chr/guard_entailment.pl +19432 -0
  266. package/lib/swipl/library/ext/chr/chr/listmap.pl +108 -0
  267. package/lib/swipl/library/ext/chr/chr/pairlist.pl +78 -0
  268. package/lib/swipl/library/ext/chr/chr.pl +686 -0
  269. package/lib/swipl/library/ext/clib/INDEX.pl +158 -0
  270. package/lib/swipl/library/ext/clib/cgi.pl +86 -0
  271. package/lib/swipl/library/ext/clib/crypt.pl +44 -0
  272. package/lib/swipl/library/ext/clib/filesex.pl +644 -0
  273. package/lib/swipl/library/ext/clib/hash_stream.pl +119 -0
  274. package/lib/swipl/library/ext/clib/mallocinfo.pl +138 -0
  275. package/lib/swipl/library/ext/clib/md5.pl +68 -0
  276. package/lib/swipl/library/ext/clib/memfile.pl +61 -0
  277. package/lib/swipl/library/ext/clib/process.pl +573 -0
  278. package/lib/swipl/library/ext/clib/prolog_server.pl +157 -0
  279. package/lib/swipl/library/ext/clib/prolog_stream.pl +80 -0
  280. package/lib/swipl/library/ext/clib/rlimit.pl +54 -0
  281. package/lib/swipl/library/ext/clib/sched.pl +85 -0
  282. package/lib/swipl/library/ext/clib/sha.pl +162 -0
  283. package/lib/swipl/library/ext/clib/socket.pl +1102 -0
  284. package/lib/swipl/library/ext/clib/streaminfo.pl +103 -0
  285. package/lib/swipl/library/ext/clib/streampool.pl +136 -0
  286. package/lib/swipl/library/ext/clib/syslog.pl +180 -0
  287. package/lib/swipl/library/ext/clib/time.pl +194 -0
  288. package/lib/swipl/library/ext/clib/udp_broadcast.pl +975 -0
  289. package/lib/swipl/library/ext/clib/uid.pl +220 -0
  290. package/lib/swipl/library/ext/clib/unix.pl +317 -0
  291. package/lib/swipl/library/ext/clib/uri.pl +530 -0
  292. package/lib/swipl/library/ext/clib/uuid.pl +207 -0
  293. package/lib/swipl/library/ext/http/http/INDEX.pl +266 -0
  294. package/lib/swipl/library/ext/http/http/README.md +34 -0
  295. package/lib/swipl/library/ext/http/http/ax.pl +189 -0
  296. package/lib/swipl/library/ext/http/http/dcg_basics.pl +49 -0
  297. package/lib/swipl/library/ext/http/http/graphql.pl +1367 -0
  298. package/lib/swipl/library/ext/http/http/html_decl.pl +416 -0
  299. package/lib/swipl/library/ext/http/http/html_head.pl +654 -0
  300. package/lib/swipl/library/ext/http/http/html_quasiquotations.pl +120 -0
  301. package/lib/swipl/library/ext/http/http/html_write.pl +1425 -0
  302. package/lib/swipl/library/ext/http/http/htmx.pl +139 -0
  303. package/lib/swipl/library/ext/http/http/http_authenticate.pl +364 -0
  304. package/lib/swipl/library/ext/http/http/http_client.pl +412 -0
  305. package/lib/swipl/library/ext/http/http/http_cookie.pl +245 -0
  306. package/lib/swipl/library/ext/http/http/http_cors.pl +176 -0
  307. package/lib/swipl/library/ext/http/http/http_digest.pl +820 -0
  308. package/lib/swipl/library/ext/http/http/http_dirindex.pl +296 -0
  309. package/lib/swipl/library/ext/http/http/http_dispatch.pl +1552 -0
  310. package/lib/swipl/library/ext/http/http/http_dyn_workers.pl +214 -0
  311. package/lib/swipl/library/ext/http/http/http_error.pl +126 -0
  312. package/lib/swipl/library/ext/http/http/http_exception.pl +225 -0
  313. package/lib/swipl/library/ext/http/http/http_files.pl +163 -0
  314. package/lib/swipl/library/ext/http/http/http_header.pl +2820 -0
  315. package/lib/swipl/library/ext/http/http/http_hook.pl +106 -0
  316. package/lib/swipl/library/ext/http/http/http_host.pl +204 -0
  317. package/lib/swipl/library/ext/http/http/http_load.pl +113 -0
  318. package/lib/swipl/library/ext/http/http/http_log.pl +738 -0
  319. package/lib/swipl/library/ext/http/http/http_multipart_plugin.pl +232 -0
  320. package/lib/swipl/library/ext/http/http/http_open.pl +1821 -0
  321. package/lib/swipl/library/ext/http/http/http_openid.pl +1561 -0
  322. package/lib/swipl/library/ext/http/http/http_parameters.pl +504 -0
  323. package/lib/swipl/library/ext/http/http/http_path.pl +380 -0
  324. package/lib/swipl/library/ext/http/http/http_proxy.pl +80 -0
  325. package/lib/swipl/library/ext/http/http/http_pwp.pl +351 -0
  326. package/lib/swipl/library/ext/http/http/http_redis_plugin.pl +332 -0
  327. package/lib/swipl/library/ext/http/http/http_server.pl +105 -0
  328. package/lib/swipl/library/ext/http/http/http_server_files.pl +126 -0
  329. package/lib/swipl/library/ext/http/http/http_server_health.pl +186 -0
  330. package/lib/swipl/library/ext/http/http/http_session.pl +1040 -0
  331. package/lib/swipl/library/ext/http/http/http_sgml_plugin.pl +137 -0
  332. package/lib/swipl/library/ext/http/http/http_stream.pl +376 -0
  333. package/lib/swipl/library/ext/http/http/http_unix_daemon.pl +989 -0
  334. package/lib/swipl/library/ext/http/http/http_wrapper.pl +559 -0
  335. package/lib/swipl/library/ext/http/http/hub.pl +600 -0
  336. package/lib/swipl/library/ext/http/http/js_write.pl +461 -0
  337. package/lib/swipl/library/ext/http/http/mimepack.pl +224 -0
  338. package/lib/swipl/library/ext/http/http/mimetype.pl +276 -0
  339. package/lib/swipl/library/ext/http/http/term_html.pl +797 -0
  340. package/lib/swipl/library/ext/http/http/thread_httpd.pl +1181 -0
  341. package/lib/swipl/library/ext/http/http/web/css/dirindex.css +24 -0
  342. package/lib/swipl/library/ext/http/http/web/css/openid.css +57 -0
  343. package/lib/swipl/library/ext/http/http/web/icons/back.png +0 -0
  344. package/lib/swipl/library/ext/http/http/web/icons/c.png +0 -0
  345. package/lib/swipl/library/ext/http/http/web/icons/compressed.png +0 -0
  346. package/lib/swipl/library/ext/http/http/web/icons/folder.png +0 -0
  347. package/lib/swipl/library/ext/http/http/web/icons/generic.png +0 -0
  348. package/lib/swipl/library/ext/http/http/web/icons/layout.png +0 -0
  349. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-square.png +0 -0
  350. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-tiny.png +0 -0
  351. package/lib/swipl/library/ext/http/http/websocket.pl +729 -0
  352. package/lib/swipl/library/ext/http/http/yadis.pl +205 -0
  353. package/lib/swipl/library/ext/json/INDEX.pl +36 -0
  354. package/lib/swipl/library/ext/json/http/INDEX.pl +16 -0
  355. package/lib/swipl/library/ext/json/http/http_json.pl +490 -0
  356. package/lib/swipl/library/ext/json/http/js_grammar.pl +53 -0
  357. package/lib/swipl/library/ext/json/http/json.pl +48 -0
  358. package/lib/swipl/library/ext/json/http/json_convert.pl +48 -0
  359. package/lib/swipl/library/ext/json/json.pl +1215 -0
  360. package/lib/swipl/library/ext/json/json_convert.pl +681 -0
  361. package/lib/swipl/library/ext/json/json_grammar.pl +349 -0
  362. package/lib/swipl/library/ext/json/json_rpc_client.pl +423 -0
  363. package/lib/swipl/library/ext/json/json_rpc_common.pl +104 -0
  364. package/lib/swipl/library/ext/json/json_rpc_server.pl +489 -0
  365. package/lib/swipl/library/ext/json/json_schema.pl +2111 -0
  366. package/lib/swipl/library/ext/nlp/INDEX.pl +15 -0
  367. package/lib/swipl/library/ext/nlp/double_metaphone.pl +86 -0
  368. package/lib/swipl/library/ext/nlp/isub.pl +162 -0
  369. package/lib/swipl/library/ext/nlp/porter_stem.pl +50 -0
  370. package/lib/swipl/library/ext/nlp/snowball.pl +97 -0
  371. package/lib/swipl/library/ext/pcre/INDEX.pl +17 -0
  372. package/lib/swipl/library/ext/pcre/pcre.pl +974 -0
  373. package/lib/swipl/library/ext/plunit/INDEX.pl +20 -0
  374. package/lib/swipl/library/ext/plunit/plunit.pl +2631 -0
  375. package/lib/swipl/library/ext/plunit/test_wizard.pl +249 -0
  376. package/lib/swipl/library/ext/semweb/semweb/INDEX.pl +288 -0
  377. package/lib/swipl/library/ext/semweb/semweb/rdf11.pl +2106 -0
  378. package/lib/swipl/library/ext/semweb/semweb/rdf11_containers.pl +299 -0
  379. package/lib/swipl/library/ext/semweb/semweb/rdf_cache.pl +278 -0
  380. package/lib/swipl/library/ext/semweb/semweb/rdf_compare.pl +132 -0
  381. package/lib/swipl/library/ext/semweb/semweb/rdf_db.pl +3468 -0
  382. package/lib/swipl/library/ext/semweb/semweb/rdf_edit.pl +1145 -0
  383. package/lib/swipl/library/ext/semweb/semweb/rdf_http_plugin.pl +274 -0
  384. package/lib/swipl/library/ext/semweb/semweb/rdf_library.pl +1021 -0
  385. package/lib/swipl/library/ext/semweb/semweb/rdf_litindex.pl +1035 -0
  386. package/lib/swipl/library/ext/semweb/semweb/rdf_ntriples.pl +422 -0
  387. package/lib/swipl/library/ext/semweb/semweb/rdf_persistency.pl +1576 -0
  388. package/lib/swipl/library/ext/semweb/semweb/rdf_portray.pl +182 -0
  389. package/lib/swipl/library/ext/semweb/semweb/rdf_prefixes.pl +681 -0
  390. package/lib/swipl/library/ext/semweb/semweb/rdf_sandbox.pl +153 -0
  391. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle.pl +54 -0
  392. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle_write.pl +1587 -0
  393. package/lib/swipl/library/ext/semweb/semweb/rdf_zlib_plugin.pl +52 -0
  394. package/lib/swipl/library/ext/semweb/semweb/rdfa.pl +1510 -0
  395. package/lib/swipl/library/ext/semweb/semweb/rdfs.pl +475 -0
  396. package/lib/swipl/library/ext/semweb/semweb/sparql_client.pl +643 -0
  397. package/lib/swipl/library/ext/semweb/semweb/turtle.pl +455 -0
  398. package/lib/swipl/library/ext/sgml/DTD/HTML4.dcl +88 -0
  399. package/lib/swipl/library/ext/sgml/DTD/HTML4.dtd +1092 -0
  400. package/lib/swipl/library/ext/sgml/DTD/HTML4.soc +6 -0
  401. package/lib/swipl/library/ext/sgml/DTD/HTML5.dtd +906 -0
  402. package/lib/swipl/library/ext/sgml/DTD/HTMLlat1.ent +195 -0
  403. package/lib/swipl/library/ext/sgml/DTD/HTMLspec.ent +77 -0
  404. package/lib/swipl/library/ext/sgml/DTD/HTMLsym.ent +241 -0
  405. package/lib/swipl/library/ext/sgml/INDEX.pl +64 -0
  406. package/lib/swipl/library/ext/sgml/c14n2.pl +203 -0
  407. package/lib/swipl/library/ext/sgml/iso_639.pl +631 -0
  408. package/lib/swipl/library/ext/sgml/pwp.pl +705 -0
  409. package/lib/swipl/library/ext/sgml/sgml.pl +815 -0
  410. package/lib/swipl/library/ext/sgml/sgml_write.pl +1003 -0
  411. package/lib/swipl/library/ext/sgml/xpath.pl +620 -0
  412. package/lib/swipl/library/ext/sgml/xsdp_types.pl +232 -0
  413. package/lib/swipl/library/ext/ssl/INDEX.pl +60 -0
  414. package/lib/swipl/library/ext/ssl/crypto.pl +1015 -0
  415. package/lib/swipl/library/ext/ssl/http/INDEX.pl +5 -0
  416. package/lib/swipl/library/ext/ssl/http/http_ssl_plugin.pl +296 -0
  417. package/lib/swipl/library/ext/ssl/saml.pl +609 -0
  418. package/lib/swipl/library/ext/ssl/ssl.pl +647 -0
  419. package/lib/swipl/library/ext/ssl/xmldsig.pl +391 -0
  420. package/lib/swipl/library/ext/ssl/xmlenc.pl +354 -0
  421. package/lib/swipl/library/ext/zlib/INDEX.pl +8 -0
  422. package/lib/swipl/library/ext/zlib/zlib.pl +112 -0
  423. package/lib/swipl/library/fastrw.pl +105 -0
  424. package/lib/swipl/library/files.pl +80 -0
  425. package/lib/swipl/library/gensym.pl +111 -0
  426. package/lib/swipl/library/git.pl +1027 -0
  427. package/lib/swipl/library/hashtable.pl +365 -0
  428. package/lib/swipl/library/heaps.pl +252 -0
  429. package/lib/swipl/library/hotfix.pl +239 -0
  430. package/lib/swipl/library/http/jquery.pl +103 -0
  431. package/lib/swipl/library/http/web/js/jquery-3.6.0.min.js +2 -0
  432. package/lib/swipl/library/increval.pl +217 -0
  433. package/lib/swipl/library/intercept.pl +263 -0
  434. package/lib/swipl/library/iostream.pl +237 -0
  435. package/lib/swipl/library/iri_scheme/file.pl +70 -0
  436. package/lib/swipl/library/lazy_lists.pl +481 -0
  437. package/lib/swipl/library/listing.pl +1362 -0
  438. package/lib/swipl/library/lists.pl +860 -0
  439. package/lib/swipl/library/lynx/INDEX.pl +14 -0
  440. package/lib/swipl/library/lynx/format.pl +380 -0
  441. package/lib/swipl/library/lynx/html_style.pl +129 -0
  442. package/lib/swipl/library/lynx/html_text.pl +865 -0
  443. package/lib/swipl/library/lynx/pldoc_style.pl +87 -0
  444. package/lib/swipl/library/macros.pl +451 -0
  445. package/lib/swipl/library/main.pl +1200 -0
  446. package/lib/swipl/library/make.pl +197 -0
  447. package/lib/swipl/library/modules.pl +129 -0
  448. package/lib/swipl/library/nb_rbtrees.pl +267 -0
  449. package/lib/swipl/library/nb_set.pl +203 -0
  450. package/lib/swipl/library/obfuscate.pl +115 -0
  451. package/lib/swipl/library/occurs.pl +241 -0
  452. package/lib/swipl/library/operators.pl +182 -0
  453. package/lib/swipl/library/option.pl +388 -0
  454. package/lib/swipl/library/optparse.pl +966 -0
  455. package/lib/swipl/library/ordsets.pl +518 -0
  456. package/lib/swipl/library/oset.pl +160 -0
  457. package/lib/swipl/library/pairs.pl +187 -0
  458. package/lib/swipl/library/persistency.pl +713 -0
  459. package/lib/swipl/library/pio.pl +47 -0
  460. package/lib/swipl/library/portray_text.pl +277 -0
  461. package/lib/swipl/library/pprint.pl +940 -0
  462. package/lib/swipl/library/predicate_options.pl +975 -0
  463. package/lib/swipl/library/prolog_autoload.pl +233 -0
  464. package/lib/swipl/library/prolog_breakpoints.pl +396 -0
  465. package/lib/swipl/library/prolog_clause.pl +1104 -0
  466. package/lib/swipl/library/prolog_code.pl +416 -0
  467. package/lib/swipl/library/prolog_codewalk.pl +1248 -0
  468. package/lib/swipl/library/prolog_colour.pl +3301 -0
  469. package/lib/swipl/library/prolog_colour.qlf +0 -0
  470. package/lib/swipl/library/prolog_config.pl +154 -0
  471. package/lib/swipl/library/prolog_coverage.pl +1333 -0
  472. package/lib/swipl/library/prolog_debug.pl +404 -0
  473. package/lib/swipl/library/prolog_deps.pl +675 -0
  474. package/lib/swipl/library/prolog_evaluable.pl +234 -0
  475. package/lib/swipl/library/prolog_format.pl +219 -0
  476. package/lib/swipl/library/prolog_history.pl +161 -0
  477. package/lib/swipl/library/prolog_jiti.pl +333 -0
  478. package/lib/swipl/library/prolog_locale.pl +61 -0
  479. package/lib/swipl/library/prolog_metainference.pl +307 -0
  480. package/lib/swipl/library/prolog_pack.pl +3906 -0
  481. package/lib/swipl/library/prolog_profile.pl +346 -0
  482. package/lib/swipl/library/prolog_qlfmake.pl +533 -0
  483. package/lib/swipl/library/prolog_source.pl +1188 -0
  484. package/lib/swipl/library/prolog_stack.pl +794 -0
  485. package/lib/swipl/library/prolog_trace.pl +365 -0
  486. package/lib/swipl/library/prolog_versions.pl +347 -0
  487. package/lib/swipl/library/prolog_wrap.pl +164 -0
  488. package/lib/swipl/library/prolog_xref.pl +3090 -0
  489. package/lib/swipl/library/prolog_xref.qlf +0 -0
  490. package/lib/swipl/library/pure_input.pl +266 -0
  491. package/lib/swipl/library/qpforeign.pl +695 -0
  492. package/lib/swipl/library/qsave.pl +1516 -0
  493. package/lib/swipl/library/quasi_quotations.pl +300 -0
  494. package/lib/swipl/library/quintus.pl +437 -0
  495. package/lib/swipl/library/random.pl +459 -0
  496. package/lib/swipl/library/rbtrees.pl +1153 -0
  497. package/lib/swipl/library/readln.pl +256 -0
  498. package/lib/swipl/library/readutil.pl +304 -0
  499. package/lib/swipl/library/record.pl +544 -0
  500. package/lib/swipl/library/rwlocks.pl +172 -0
  501. package/lib/swipl/library/sandbox.pl +1384 -0
  502. package/lib/swipl/library/semweb/dc.rdfs +198 -0
  503. package/lib/swipl/library/semweb/eor.rdfs +95 -0
  504. package/lib/swipl/library/semweb/owl.owl +287 -0
  505. package/lib/swipl/library/semweb/rdf_library.ttl +90 -0
  506. package/lib/swipl/library/semweb/rdfs.rdfs +251 -0
  507. package/lib/swipl/library/settings.pl +755 -0
  508. package/lib/swipl/library/shell.pl +462 -0
  509. package/lib/swipl/library/shlib.pl +670 -0
  510. package/lib/swipl/library/solution_sequences.pl +439 -0
  511. package/lib/swipl/library/sort.pl +119 -0
  512. package/lib/swipl/library/statistics.pl +541 -0
  513. package/lib/swipl/library/streams.pl +118 -0
  514. package/lib/swipl/library/strings.pl +469 -0
  515. package/lib/swipl/library/system.pl +95 -0
  516. package/lib/swipl/library/tables.pl +381 -0
  517. package/lib/swipl/library/tableutil.pl +771 -0
  518. package/lib/swipl/library/tabling.pl +42 -0
  519. package/lib/swipl/library/terms.pl +457 -0
  520. package/lib/swipl/library/theme/auto.pl +61 -0
  521. package/lib/swipl/library/theme/dark.pl +455 -0
  522. package/lib/swipl/library/theme/light.pl +45 -0
  523. package/lib/swipl/library/thread.pl +810 -0
  524. package/lib/swipl/library/thread_pool.pl +508 -0
  525. package/lib/swipl/library/threadutil.pl +574 -0
  526. package/lib/swipl/library/tty.pl +316 -0
  527. package/lib/swipl/library/ugraphs.pl +644 -0
  528. package/lib/swipl/library/unicode/INDEX.pl +6 -0
  529. package/lib/swipl/library/unicode/blocks.pl +414 -0
  530. package/lib/swipl/library/url.pl +1129 -0
  531. package/lib/swipl/library/utf8.pl +145 -0
  532. package/lib/swipl/library/varnumbers.pl +221 -0
  533. package/lib/swipl/library/vm.pl +251 -0
  534. package/lib/swipl/library/wfs.pl +205 -0
  535. package/lib/swipl/library/when.pl +263 -0
  536. package/lib/swipl/library/writef.pl +278 -0
  537. package/lib/swipl/library/www_browser.pl +251 -0
  538. package/lib/swipl/library/yall.pl +574 -0
  539. package/lib/swipl/library/zip.pl +211 -0
  540. package/lib/swipl/swipl.home +1 -0
  541. package/lib/vendor/libcrypto.so.3 +0 -0
  542. package/lib/vendor/libpcre2-8.so.0 +0 -0
  543. package/lib/vendor/libssl.so.3 +0 -0
  544. package/lib/vendor/libz.so.1 +0 -0
  545. package/licenses/OpenSSL-LICENSE.txt +177 -0
  546. package/licenses/PCRE2-COPYING +5 -0
  547. package/licenses/README.md +12 -0
  548. package/licenses/SWI-Prolog-LICENSE +41 -0
  549. package/licenses/zlib-LICENSE +22 -0
  550. package/package.json +27 -0
@@ -0,0 +1,975 @@
1
+ /* Part of SWI-Prolog
2
+
3
+ Author: Jeffrey Rosenwald and Jan Wielemaker
4
+ E-mail: jeffrose@acm.org
5
+ WWW: http://www.swi-prolog.org
6
+ Copyright (c) 2012-2013, Jeffrey Rosenwald
7
+ 2018-2020, CWI Amsterdam
8
+ All rights reserved.
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions
12
+ are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright
15
+ notice, this list of conditions and the following disclaimer.
16
+
17
+ 2. Redistributions in binary form must reproduce the above copyright
18
+ notice, this list of conditions and the following disclaimer in
19
+ the documentation and/or other materials provided with the
20
+ distribution.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
+ POSSIBILITY OF SUCH DAMAGE.
34
+ */
35
+
36
+ :- module(udp_broadcast,
37
+ [ udp_broadcast_initialize/2, % +IPAddress, +Options
38
+ udp_broadcast_close/1, % +Scope
39
+
40
+ udp_peer_add/2, % +Scope, +IP
41
+ udp_peer_del/2, % +Scope, ?IP
42
+ udp_peer/2 % +Scope, -IP
43
+ ]).
44
+ :- autoload(library(apply),[maplist/2,maplist/3]).
45
+ :- autoload(library(backcomp),[thread_at_exit/1]).
46
+ :- autoload(library(broadcast),
47
+ [broadcast_request/1,broadcast/1,listening/3,listen/3]).
48
+ :- use_module(library(debug),[debug/3]).
49
+ :- autoload(library(error),
50
+ [must_be/2,syntax_error/1,domain_error/2,existence_error/2]).
51
+ :- autoload(library(option),[option/3]).
52
+ :- autoload(library(socket),
53
+ [ tcp_close_socket/1,
54
+ udp_socket/1,
55
+ tcp_bind/2,
56
+ tcp_getopt/2,
57
+ tcp_setopt/2,
58
+ udp_receive/4,
59
+ udp_send/4
60
+ ]).
61
+
62
+
63
+ % :- debug(udp(broadcast)).
64
+
65
+ /** <module> A UDP broadcast proxy
66
+
67
+ SWI-Prolog's broadcast library provides a means that may be used to
68
+ facilitate publish and subscribe communication regimes between anonymous
69
+ members of a community of interest. The members of the community are
70
+ however, necessarily limited to a single instance of Prolog. The UDP
71
+ broadcast library removes that restriction. With this library loaded,
72
+ any member on your local IP subnetwork that also has this library loaded
73
+ may hear and respond to your broadcasts.
74
+
75
+ This library support three styles of networking as described below. Each
76
+ of these networks have their own advantages and disadvantages. Please
77
+ study the literature to understand the consequences.
78
+
79
+ $ broadcast :
80
+ Broadcast messages are sent to the LAN subnet. The broadcast
81
+ implementation uses two UDP ports: a public to address the whole
82
+ group and a private one to address a specific node. Broadcasting
83
+ is generally a good choice if the subnet is small and traffic is
84
+ low.
85
+
86
+ $ unicast :
87
+ Unicast sends copies of packages to known peers. Unicast networks
88
+ can easily be routed. The unicast version uses a single UDP port
89
+ per node. Unicast is generally a good choice for a small party,
90
+ in particular if the peers are in different networks.
91
+
92
+ $ multicast :
93
+ Multicast is like broadcast, but it can be configured to
94
+ work accross networks and may work more efficiently on VLAN networks.
95
+ Like the broadcast setup, two UDP ports are used. Multicasting can
96
+ in general deliver the most efficient LAN and WAN networks, but
97
+ requires properly configured routing between the peers.
98
+
99
+ After initialization and, in the case of a _unicast_ network managing
100
+ the set of peers, communication happens through broadcast/1,
101
+ broadcast_request/1 and listen/1,2,3.
102
+
103
+ A broadcast/1 or broadcast_request/1 of the shape udp(Scope, Term) or
104
+ udp(Scope, Term, TimeOut) is forwarded over the UDP network to all peers
105
+ that joined the same `Scope`. To prevent the potential for feedback
106
+ loops, only the plain `Term` is broadcasted locally. The timeout is
107
+ optional. It specifies the amount to time to wait for replies to arrive
108
+ in response to a broadcast_request/1. The default period is 0.250
109
+ seconds. The timeout is ignored for broadcasts.
110
+
111
+ An example of three separate processes cooperating in the same _scope_
112
+ called `peers`:
113
+
114
+ ==
115
+ Process A:
116
+
117
+ ?- listen(number(X), between(1, 5, X)).
118
+ true.
119
+
120
+ ?-
121
+
122
+ Process B:
123
+
124
+ ?- listen(number(X), between(7, 9, X)).
125
+ true.
126
+
127
+ ?-
128
+
129
+ Process C:
130
+
131
+ ?- findall(X, broadcast_request(udp(peers, number(X))), Xs).
132
+ Xs = [1, 2, 3, 4, 5, 7, 8, 9].
133
+
134
+ ?-
135
+ ==
136
+
137
+ It is also possible to carry on a private dialog with a single
138
+ responder. To do this, you supply a compound of the form, Term:PortId,
139
+ to a UDP scoped broadcast/1 or broadcast_request/1, where PortId is the
140
+ ip-address and port-id of the intended listener. If you supply an
141
+ unbound variable, PortId, to broadcast_request, it will be unified with
142
+ the address of the listener that responds to Term. You may send a
143
+ directed broadcast to a specific member by simply providing this address
144
+ in a similarly structured compound to a UDP scoped broadcast/1. The
145
+ message is sent via unicast to that member only by way of the member's
146
+ broadcast listener. It is received by the listener just as any other
147
+ broadcast would be. The listener does not know the difference.
148
+
149
+ For example, in order to discover who responded with a particular value:
150
+
151
+ ==
152
+ Host B Process 1:
153
+
154
+ ?- listen(number(X), between(1, 5, X)).
155
+ true.
156
+
157
+ ?-
158
+
159
+ Host A Process 1:
160
+
161
+
162
+ ?- listen(number(X), between(7, 9, X)).
163
+ true.
164
+
165
+ ?-
166
+
167
+ Host A Process 2:
168
+
169
+ ?- listen(number(X), between(1, 5, X)).
170
+ true.
171
+
172
+ ?- bagof(X, broadcast_request(udp(peers,number(X):From,1)), Xs).
173
+ From = ip(192, 168, 1, 103):34855,
174
+ Xs = [7, 8, 9] ;
175
+ From = ip(192, 168, 1, 103):56331,
176
+ Xs = [1, 2, 3, 4, 5] ;
177
+ From = ip(192, 168, 1, 104):3217,
178
+ Xs = [1, 2, 3, 4, 5].
179
+ ==
180
+
181
+ All incomming trafic is handled by a single thread with the alias
182
+ `udp_inbound_proxy`. This thread also performs the internal dispatching
183
+ using broadcast/1 and broadcast_request/1. Future versions may provide
184
+ for handling these requests in separate threads.
185
+
186
+
187
+ ## Caveats {#udp-broadcase-caveats}
188
+
189
+ While the implementation is mostly transparent, there are some important
190
+ and subtle differences that must be taken into consideration:
191
+
192
+ * UDP broadcast requires an initialization step in order to
193
+ launch the broadcast listener proxy. See
194
+ udp_broadcast_initialize/2.
195
+
196
+ * Prolog's broadcast_request/1 is nondet. It sends the request,
197
+ then evaluates the replies synchronously, backtracking as needed
198
+ until a satisfactory reply is received. The remaining potential
199
+ replies are not evaluated. With UDP, all peers will send all
200
+ answers to the query. The receiver may however stop listening.
201
+
202
+ * A UDP broadcast/1 is completely asynchronous.
203
+
204
+ * A UDP broadcast_request/1 is partially synchronous. A
205
+ broadcast_request/1 is sent, then the sender balks for a period of
206
+ time (default: 250 ms) while the replies are collected. Any reply
207
+ that is received after this period is silently discarded. A
208
+ optional second argument is provided so that a sender may specify
209
+ more (or less) time for replies.
210
+
211
+ * Replies are presented to the user as a choice point on arrival,
212
+ until the broadcast request timer finally expires. This
213
+ allows traffic to propagate through the system faster and provides
214
+ the requestor with the opportunity to terminate a broadcast request
215
+ early if desired, by simply cutting choice points.
216
+
217
+ * Please beware that broadcast request transactions remain active
218
+ and resources consumed until broadcast_request finally fails on
219
+ backtracking, an uncaught exception occurs, or until choice points
220
+ are cut. Failure to properly manage this will likely result in
221
+ chronic exhaustion of UDP sockets.
222
+
223
+ * If a listener is connected to a generator that always succeeds
224
+ (e.g. a random number generator), then the broadcast request will
225
+ never terminate and trouble is bound to ensue.
226
+
227
+ * broadcast_request/1 with =|udp_subnet|= scope is _not_ reentrant.
228
+ If a listener performs a broadcast_request/1 with UDP scope
229
+ recursively, then disaster looms certain. This caveat does not apply
230
+ to a UDP scoped broadcast/1, which can safely be performed from a
231
+ listener context.
232
+
233
+ * UDP broadcast's capacity is not infinite. While it can tolerate
234
+ substantial bursts of activity, it is designed for short bursts of
235
+ small messages. Unlike TIPC, UDP is unreliable and has no QOS
236
+ protections. Congestion is likely to cause trouble in the form of
237
+ non-Byzantine failure. That is, late, lost (e.g. infinitely late),
238
+ or duplicate datagrams. Caveat emptor.
239
+
240
+ * A UDP broadcast_request/1 term that is grounded is considered to
241
+ be a broadcast only. No replies are collected unless the there is at
242
+ least one unbound variable to unify.
243
+
244
+ * A UDP broadcast/1 always succeeds, even if there are no
245
+ listeners.
246
+
247
+ * A UDP broadcast_request/1 that receives no replies will fail.
248
+
249
+ * Replies may be coming from many different places in the network
250
+ (or none at all). No ordering of replies is implied.
251
+
252
+ * Prolog terms are sent to others after first converting them to
253
+ atoms using term_string/3. Serialization does not deal with cycles,
254
+ attributes or sharing. The hook udp_term_string_hook/3 may be
255
+ defined to change the message serialization and support different
256
+ message formats and/or encryption.
257
+
258
+ * The broadcast model is based on anonymity and a presumption of
259
+ trust--a perfect recipe for compromise. UDP is an Internet protocol.
260
+ A UDP broadcast listener exposes a public port, which is
261
+ static and shared by all listeners, and a private port, which is
262
+ semi-static and unique to the listener instance. Both can be seen
263
+ from off-cluster nodes and networks. Usage of this module exposes
264
+ the node and consequently, the cluster to significant security
265
+ risks. So have a care when designing your application. You must talk
266
+ only to those who share and contribute to your concerns using a
267
+ carefully prescribed protocol.
268
+
269
+ * UDP broadcast categorically and silently ignores all message
270
+ traffic originating from or terminating on nodes that are not
271
+ members of the local subnet. This security measure only keeps honest
272
+ people honest!
273
+
274
+ @author Jeffrey Rosenwald (JeffRose@acm.org), Jan Wielemaker
275
+ @license BSD-2
276
+ @see tipc.pl
277
+ */
278
+
279
+ :- multifile
280
+ udp_term_string_hook/3, % +Scope, ?Term, ?String
281
+ udp_unicast_join_hook/3, % +Scope, +From, +Data
282
+ black_list/1. % +Term
283
+
284
+ :- meta_predicate
285
+ safely(0),
286
+ safely_det(0).
287
+
288
+ safely(Predicate) :-
289
+ Err = error(_,_),
290
+ catch(Predicate, Err,
291
+ print_message_fail(Err)).
292
+
293
+ safely_det(Predicate) :-
294
+ Err = error(_,_),
295
+ catch(Predicate, Err,
296
+ print_message_fail(Err)),
297
+ !.
298
+ safely_det(_).
299
+
300
+ print_message_fail(Term) :-
301
+ print_message(error, Term),
302
+ fail.
303
+
304
+ udp_broadcast_address(IPAddress, Subnet, BroadcastAddress) :-
305
+ IPAddress = ip(A1, A2, A3, A4),
306
+ Subnet = ip(S1, S2, S3, S4),
307
+ BroadcastAddress = ip(B1, B2, B3, B4),
308
+
309
+ B1 is A1 \/ (S1 xor 255),
310
+ B2 is A2 \/ (S2 xor 255),
311
+ B3 is A3 \/ (S3 xor 255),
312
+ B4 is A4 \/ (S4 xor 255).
313
+
314
+ %! udp_broadcast_service(?Scope, ?Address) is nondet.
315
+ %
316
+ % provides the UDP broadcast address for a given Scope. At present,
317
+ % only one scope is supported, =|udp_subnet|=.
318
+
319
+ %! udp_scope(?ScopeName, ?ScopeDef)
320
+
321
+ :- dynamic
322
+ udp_scope/2,
323
+ udp_scope_peer/2.
324
+ :- volatile
325
+ udp_scope/2,
326
+ udp_scope_peer/2.
327
+ %
328
+ % Here's a UDP proxy to Prolog's broadcast library
329
+ %
330
+ % A sender may extend a broadcast to a subnet of a UDP network by
331
+ % specifying a =|udp_subnet|= scoping qualifier in his/her broadcast.
332
+ % The qualifier has the effect of selecting the appropriate multi-cast
333
+ % address for the transmission. Thus, the sender of the message has
334
+ % control over the scope of his/her traffic on a per-message basis.
335
+ %
336
+ % All in-scope listeners receive the broadcast and simply rebroadcast
337
+ % the message locally. All broadcast replies, if any, are sent directly
338
+ % to the sender via the port-id that was received with the broadcast.
339
+ %
340
+ % Each listener exposes two UDP ports, a shared public port that is
341
+ % bound to a well-known port number and a private port that uniquely
342
+ % indentifies the listener. Broadcasts are received on the public port
343
+ % and replies are sent on the private port. Directed broadcasts
344
+ % (unicasts) are received on the private port and replies are sent on
345
+ % the private port.
346
+
347
+ % Thread 1 listens for directed traffic on the private port.
348
+ %
349
+
350
+ :- dynamic
351
+ udp_private_socket/3, % Port, Socket, FileNo
352
+ udp_public_socket/4, % Scope, Port, Socket, FileNo
353
+ udp_closed/1. % Scope
354
+
355
+ udp_inbound_proxy(Master) :-
356
+ thread_at_exit(inbound_proxy_died),
357
+ make_private_socket,
358
+ thread_send_message(Master, udp_inbound_ready),
359
+ udp_inbound_proxy_loop.
360
+
361
+ udp_inbound_proxy_loop :-
362
+ forall(udp_scope(Scope, ScopeData),
363
+ make_public_socket(ScopeData, Scope)),
364
+ retractall(udp_closed(_)),
365
+ findall(FileNo, udp_socket_file_no(FileNo), FileNos),
366
+ catch(dispatch_inbound(FileNos),
367
+ E, dispatch_exception(E)),
368
+ udp_inbound_proxy_loop.
369
+
370
+ dispatch_exception(E) :-
371
+ E = error(_,_),
372
+ !,
373
+ print_message(warning, E).
374
+ dispatch_exception(_).
375
+
376
+
377
+ %! make_private_socket is det.
378
+ %
379
+ % Create our private socket. This socket is used for messages that are
380
+ % directed to me. Note that we only need this for broadcast networks.
381
+ % If we use a unicast network we use our public port to contact this
382
+ % specific server.
383
+
384
+ make_private_socket :-
385
+ udp_private_socket(_Port, S, _F),
386
+ !,
387
+ ( ( udp_scope(Scope, broadcast(_,_,_))
388
+ ; udp_scope(Scope, multicast(_,_))
389
+ ),
390
+ \+ udp_closed(Scope)
391
+ -> true
392
+ ; tcp_close_socket(S),
393
+ retractall(udp_private_socket(_,_,_))
394
+ ).
395
+ make_private_socket :-
396
+ udp_scope(_, broadcast(_,_,_)),
397
+ !,
398
+ udp_socket(S),
399
+ tcp_bind(S, Port),
400
+ tcp_getopt(S, file_no(F)),
401
+ tcp_setopt(S, broadcast),
402
+ assertz(udp_private_socket(Port, S, F)).
403
+ make_private_socket :-
404
+ udp_scope(_, multicast(_,_)),
405
+ !,
406
+ udp_socket(S),
407
+ tcp_bind(S, Port),
408
+ tcp_getopt(S, file_no(F)),
409
+ assertz(udp_private_socket(Port, S, F)).
410
+ make_private_socket.
411
+
412
+ %! make_public_socket(+ScopeData, +Scope)
413
+ %
414
+ % Create the public port Scope.
415
+
416
+ make_public_socket(_, Scope) :-
417
+ udp_public_socket(Scope, _Port, S, _),
418
+ !,
419
+ ( udp_closed(Scope)
420
+ -> tcp_close_socket(S),
421
+ retractall(udp_public_socket(Scope, _, _, _))
422
+ ; true
423
+ ).
424
+ make_public_socket(broadcast(_SubNet, _Broadcast, Port), Scope) :-
425
+ udp_socket(S),
426
+ tcp_setopt(S, reuseaddr),
427
+ tcp_bind(S, Port),
428
+ tcp_getopt(S, file_no(F)),
429
+ assertz(udp_public_socket(Scope, Port, S, F)).
430
+ make_public_socket(multicast(Group, Port), Scope) :-
431
+ udp_socket(S),
432
+ tcp_setopt(S, reuseaddr),
433
+ tcp_bind(S, Port),
434
+ tcp_setopt(S, ip_add_membership(Group)),
435
+ tcp_getopt(S, file_no(F)),
436
+ assertz(udp_public_socket(Scope, Port, S, F)).
437
+ make_public_socket(unicast(Port), Scope) :-
438
+ udp_socket(S),
439
+ tcp_bind(S, Port),
440
+ tcp_getopt(S, file_no(F)),
441
+ assertz(udp_public_socket(Scope, Port, S, F)).
442
+
443
+ udp_socket_file_no(FileNo) :-
444
+ udp_private_socket(_,_,FileNo).
445
+ udp_socket_file_no(FileNo) :-
446
+ udp_public_socket(_,_,_,FileNo).
447
+
448
+ %! dispatch_inbound(+FileNos)
449
+ %
450
+ % Dispatch inbound traffic. This loop uses wait_for_input/3 to wait
451
+ % for one or more UDP sockets and dispatches the requests using the
452
+ % internal broadcast service. For an incomming broadcast _request_ we
453
+ % send the reply only to the requester and therefore we must use a
454
+ % socket that is not in broadcast mode.
455
+
456
+ dispatch_inbound(FileNos) :-
457
+ debug(udp(broadcast), 'Waiting for ~p', [FileNos]),
458
+ wait_for_input(FileNos, Ready, infinite),
459
+ debug(udp(broadcast), 'Ready: ~p', [Ready]),
460
+ maplist(dispatch_ready, Ready),
461
+ dispatch_inbound(FileNos).
462
+
463
+ dispatch_ready(FileNo) :-
464
+ udp_private_socket(_Port, Private, FileNo),
465
+ !,
466
+ udp_receive(Private, Data, From, [max_message_size(65535)]),
467
+ debug(udp(broadcast), 'Inbound on private port', []),
468
+ ( in_scope(Scope, From),
469
+ udp_term_string(Scope, Term, Data) % only accept valid data
470
+ -> ld_dispatch(Private, Term, From, Scope)
471
+ ; true
472
+ ).
473
+ dispatch_ready(FileNo) :-
474
+ udp_public_socket(Scope, _PublicPort, Public, FileNo),
475
+ !,
476
+ udp_receive(Public, Data, From, [max_message_size(65535)]),
477
+ debug(udp(broadcast), 'Inbound on public port from ~p for scope ~p',
478
+ [From, Scope]),
479
+ ( in_scope(Scope, From),
480
+ udp_term_string(Scope, Term, Data) % only accept valid data
481
+ -> ( udp_scope(Scope, unicast(_))
482
+ -> ld_dispatch(Public, Term, From, Scope)
483
+ ; udp_private_socket(_PrivatePort, Private, _FileNo),
484
+ ld_dispatch(Private, Term, From, Scope)
485
+ )
486
+ ; udp_scope(Scope, unicast(_)),
487
+ udp_term_string(Scope, Term, Data),
488
+ unicast_out_of_scope_request(Scope, From, Term)
489
+ -> true
490
+ ; true
491
+ ).
492
+
493
+ in_scope(Scope, Address) :-
494
+ udp_scope(Scope, ScopeData),
495
+ in_scope(ScopeData, Scope, Address),
496
+ !.
497
+ in_scope(Scope, From) :-
498
+ debug(udp(broadcast), 'Out-of-scope ~p datagram from ~p',
499
+ [Scope, From]),
500
+ fail.
501
+
502
+ in_scope(broadcast(Subnet, Broadcast, _PublicPort), _Scope, IP:_FromPort) :-
503
+ udp_broadcast_address(IP, Subnet, Broadcast).
504
+ in_scope(multicast(_Group, _Port), _Scope, _From).
505
+ in_scope(unicast(_PublicPort), Scope, IP:_) :-
506
+ udp_peer(Scope, IP:_).
507
+
508
+
509
+ %! ld_dispatch(+PrivateSocket, +Term, +From, +Scope)
510
+ %
511
+ % Locally dispatch Term received from From. If it concerns a broadcast
512
+ % request, send the replies to PrivateSocket to From. The multifile
513
+ % hook black_list/1 can be used to ignore certain messages.
514
+
515
+ ld_dispatch(_S, Term, From, _Scope) :-
516
+ debug(udp(broadcast), 'ld_dispatch(~p) from ~p', [Term, From]),
517
+ fail.
518
+ ld_dispatch(_S, Term, _From, _Scope) :-
519
+ blacklisted(Term), !.
520
+ ld_dispatch(S, request(Key, Term), From, Scope) :-
521
+ !,
522
+ forall(safely(broadcast_request(Term)),
523
+ safely((udp_term_string(Scope, reply(Key,Term), Message),
524
+ udp_send(S, Message, From, [])))).
525
+ ld_dispatch(_S, send(Term), _From, _Scope) :-
526
+ !,
527
+ safely_det(broadcast(Term)).
528
+ ld_dispatch(_S, reply(Key, Term), From, _Scope) :-
529
+ ( reply_queue(Key, Queue)
530
+ -> safely(thread_send_message(Queue, Term:From))
531
+ ; true
532
+ ).
533
+
534
+ blacklisted(send(Term)) :- black_list(Term).
535
+ blacklisted(request(_,Term)) :- black_list(Term).
536
+ blacklisted(reply(_,Term)) :- black_list(Term).
537
+
538
+
539
+ %! reload_udp_proxy
540
+ %
541
+ % Update the UDP relaying proxy service. The proxy consists of three
542
+ % forwarding mechanisms:
543
+ %
544
+ % - Listen on our _scope_. If any messages are received, hand them
545
+ % to udp_broadcast/3 to be broadcasted to _scope_ or sent to a
546
+ % specific recipient.
547
+ % - Listen on the _scope_ public port. Incomming messages are
548
+ % relayed to the internal broadcast mechanism and replies are sent
549
+ % to from our private socket.
550
+ % - Listen on our private port and reply using the same port.
551
+
552
+ reload_udp_proxy :-
553
+ reload_outbound_proxy,
554
+ reload_inbound_proxy.
555
+
556
+ reload_outbound_proxy :-
557
+ listening(udp_broadcast, udp(_,_), _),
558
+ !.
559
+ reload_outbound_proxy :-
560
+ listen(udp_broadcast, udp(Scope,Message),
561
+ udp_broadcast(Message, Scope, 0.25)),
562
+ listen(udp_broadcast, udp(Scope,Message,Timeout),
563
+ udp_broadcast(Message, Scope, Timeout)),
564
+ listen(udp_broadcast, udp_subnet(Message), % backward compatibility
565
+ udp_broadcast(Message, subnet, 0.25)),
566
+ listen(udp_broadcast, udp_subnet(Message,Timeout),
567
+ udp_broadcast(Message, subnet, Timeout)).
568
+
569
+ reload_inbound_proxy :-
570
+ catch(thread_signal(udp_inbound_proxy, throw(udp_reload)),
571
+ error(existence_error(thread, _),_),
572
+ fail),
573
+ !.
574
+ reload_inbound_proxy :-
575
+ thread_self(Me),
576
+ thread_create(udp_inbound_proxy(Me), _,
577
+ [ alias(udp_inbound_proxy),
578
+ detached(true)
579
+ ]),
580
+ thread_get_message(Me, udp_inbound_ready, [timeout(10)]).
581
+
582
+ inbound_proxy_died :-
583
+ thread_self(Self),
584
+ thread_property(Self, status(Status)),
585
+ ( catch(recreate_proxy(Status), _, fail)
586
+ -> print_message(informational,
587
+ httpd_restarted_worker(Self))
588
+ ; done_status_message_level(Status, Level),
589
+ print_message(Level,
590
+ httpd_stopped_worker(Self, Status))
591
+ ).
592
+
593
+ recreate_proxy(exception(Error)) :-
594
+ recreate_on_error(Error),
595
+ reload_inbound_proxy.
596
+
597
+ recreate_on_error('$aborted'). % old
598
+ recreate_on_error(unwind(abort)).
599
+ recreate_on_error(time_limit_exceeded).
600
+
601
+ done_status_message_level(true, silent) :- !.
602
+ done_status_message_level(exception('$aborted'), silent) :- !.
603
+ done_status_message_level(exception(unwind(abort)), silent) :- !.
604
+ done_status_message_level(_, informational).
605
+
606
+
607
+ %! udp_broadcast_close(+Scope)
608
+ %
609
+ % Close a UDP broadcast scope.
610
+
611
+ udp_broadcast_close(Scope) :-
612
+ udp_scope(Scope, _ScopeData),
613
+ !,
614
+ assert(udp_closed(Scope)),
615
+ reload_udp_proxy.
616
+ udp_broadcast_close(_).
617
+
618
+
619
+ %! udp_broadcast(+What, +Scope, +TimeOut)
620
+ %
621
+ % Send a broadcast request to my UDP peers in Scope. What is either of
622
+ % the shape `Term:Address` to send Term to a specific address or query
623
+ % the address from which term is answered or it is a plain `Term`.
624
+ %
625
+ % If `Term` is nonground, it is considered is a _request_ (see
626
+ % broadcast_request/1) and the predicate succeeds for each answer
627
+ % received within TimeOut seconds. If Term is ground it is considered
628
+ % an asynchronous broadcast and udp_broadcast/3 is deterministic.
629
+
630
+ udp_broadcast(Term:To, Scope, _Timeout) :-
631
+ ground(Term), ground(To), % broadcast to single listener
632
+ !,
633
+ udp_basic_broadcast(send(Term), Scope, single(To)).
634
+ udp_broadcast(Term, Scope, _Timeout) :-
635
+ ground(Term), % broadcast to all listeners
636
+ !,
637
+ udp_basic_broadcast(send(Term), Scope, broadcast).
638
+ udp_broadcast(Term:To, Scope, Timeout) :-
639
+ ground(To), % request to single listener
640
+ !,
641
+ setup_call_cleanup(
642
+ request_queue(Id, Queue),
643
+ ( udp_basic_broadcast(request(Id, Term), Scope, single(To)),
644
+ udp_br_collect_replies(Queue, Timeout, Term:To)
645
+ ),
646
+ destroy_request_queue(Queue)).
647
+ udp_broadcast(Term:From, Scope, Timeout) :-
648
+ !, % request to all listeners, collect sender
649
+ setup_call_cleanup(
650
+ request_queue(Id, Queue),
651
+ ( udp_basic_broadcast(request(Id, Term), Scope, broadcast),
652
+ udp_br_collect_replies(Queue, Timeout, Term:From)
653
+ ),
654
+ destroy_request_queue(Queue)).
655
+ udp_broadcast(Term, Scope, Timeout) :- % request to all listeners
656
+ udp_broadcast(Term:_, Scope, Timeout).
657
+
658
+ :- dynamic
659
+ reply_queue/2.
660
+
661
+ request_queue(Id, Queue) :-
662
+ Id is random(1<<63),
663
+ message_queue_create(Queue),
664
+ asserta(reply_queue(Id, Queue)).
665
+
666
+ destroy_request_queue(Queue) :- % leave queue to GC
667
+ retractall(reply_queue(_, Queue)).
668
+
669
+
670
+ %! udp_basic_broadcast(+Term, +Dest) is multi.
671
+ %
672
+ % Create a UDP private socket and use it to send Term to Address. If
673
+ % Address is our broadcast address, set the socket in broadcast mode.
674
+ %
675
+ % This predicate succeeds with a choice point. Committing the choice
676
+ % point closes S.
677
+ %
678
+ % @arg Dest is one of single(Target) or `broadcast`.
679
+
680
+ udp_basic_broadcast(Term, Scope, Dest) :-
681
+ debug(udp(broadcast), 'UDP proxy outbound ~p to ~p', [Term, Dest]),
682
+ udp_term_string(Scope, Term, String),
683
+ udp_send_message(Dest, String, Scope).
684
+
685
+ udp_send_message(single(Address), String, Scope) :-
686
+ ( udp_scope(Scope, unicast(_))
687
+ -> udp_public_socket(Scope, _Port, S, _)
688
+ ; udp_private_socket(_Port, S, _F)
689
+ ),
690
+ safely(udp_send(S, String, Address, [])).
691
+ udp_send_message(broadcast, String, Scope) :-
692
+ ( udp_scope(Scope, unicast(_))
693
+ -> udp_public_socket(Scope, _Port, S, _),
694
+ forall(udp_peer(Scope, Address),
695
+ ( debug(udp(broadcast), 'Unicast to ~p', [Address]),
696
+ safely(udp_send(S, String, Address, []))))
697
+ ; udp_scope(Scope, broadcast(_SubNet, Broadcast, Port))
698
+ -> udp_private_socket(_PrivatePort, S, _F),
699
+ udp_send(S, String, Broadcast:Port, [])
700
+ ; udp_scope(Scope, multicast(Group, Port))
701
+ -> udp_private_socket(_PrivatePort, S, _F),
702
+ udp_send(S, String, Group:Port, [])
703
+ ).
704
+
705
+ % ! udp_br_collect_replies(+Queue, +TimeOut, -TermAndFrom) is nondet.
706
+ %
707
+ % Collect replies on Socket for TimeOut seconds. Succeed for each
708
+ % received message.
709
+
710
+ udp_br_collect_replies(Queue, Timeout, Reply) :-
711
+ get_time(Start),
712
+ Deadline is Start+Timeout,
713
+ repeat,
714
+ ( thread_get_message(Queue, Reply,
715
+ [ deadline(Deadline)
716
+ ])
717
+ -> true
718
+ ; !,
719
+ fail
720
+ ).
721
+
722
+ %! udp_broadcast_initialize(+IPAddress, +Options) is semidet.
723
+ %
724
+ % Initialized UDP broadcast bridge. IPAddress is the IP address on the
725
+ % network we want to broadcast on. IP addresses are terms ip(A,B,C,D)
726
+ % or an atom or string of the format =|A.B.C.D|=. Options processed:
727
+ %
728
+ % - scope(+ScopeName)
729
+ % Name of the scope. Default is `subnet`.
730
+ % - subnet_mask(+SubNet)
731
+ % Subnet to broadcast on. This uses the same syntax as IPAddress.
732
+ % Default classifies the network as class A, B or C depending on
733
+ % the the first octet and applies the default mask.
734
+ % - port(+Port)
735
+ % Public port to use. Default is 20005.
736
+ % - method(+Method)
737
+ % Method to send a message to multiple peers. One of
738
+ % - broadcast
739
+ % Use UDP broadcast messages to the LAN. This is the
740
+ % default
741
+ % - multicast
742
+ % Use UDP multicast messages. This can be used on WAN networks,
743
+ % provided the intermediate routers understand multicast.
744
+ % - unicast
745
+ % Send the messages individually to all registered peers.
746
+ %
747
+ % For compatibility reasons Options may be the subnet mask.
748
+
749
+ udp_broadcast_initialize(IP, Options) :-
750
+ with_mutex(udp_broadcast,
751
+ udp_broadcast_initialize_sync(IP, Options)).
752
+
753
+ udp_broadcast_initialize_sync(IP, Options) :-
754
+ nonvar(Options),
755
+ Options = ip(_,_,_,_),
756
+ !,
757
+ udp_broadcast_initialize(IP, [subnet_mask(Options)]).
758
+ udp_broadcast_initialize_sync(IP, Options) :-
759
+ to_ip4(IP, IPAddress),
760
+ option(method(Method), Options, broadcast),
761
+ must_be(oneof([broadcast, multicast, unicast]), Method),
762
+ udp_broadcast_initialize_sync(Method, IPAddress, Options),
763
+ reload_udp_proxy.
764
+
765
+ udp_broadcast_initialize_sync(broadcast, IPAddress, Options) :-
766
+ option(subnet_mask(Subnet), Options, _),
767
+ mk_subnet(Subnet, IPAddress, Subnet4),
768
+ option(port(Port), Options, 20005),
769
+ option(scope(Scope), Options, subnet),
770
+
771
+ udp_broadcast_address(IPAddress, Subnet4, Broadcast),
772
+ udp_broadcast_close(Scope),
773
+ assertz(udp_scope(Scope, broadcast(Subnet4, Broadcast, Port))).
774
+ udp_broadcast_initialize_sync(unicast, _IPAddress, Options) :-
775
+ option(port(Port), Options, 20005),
776
+ option(scope(Scope), Options, subnet),
777
+ udp_broadcast_close(Scope),
778
+ assertz(udp_scope(Scope, unicast(Port))).
779
+ udp_broadcast_initialize_sync(multicast, IPAddress, Options) :-
780
+ option(port(Port), Options, 20005),
781
+ option(scope(Scope), Options, subnet),
782
+ udp_broadcast_close(Scope),
783
+ multicast_address(IPAddress),
784
+ assertz(udp_scope(Scope, multicast(IPAddress, Port))).
785
+
786
+ to_ip4(Atomic, ip(A,B,C,D)) :-
787
+ atomic(Atomic),
788
+ !,
789
+ ( split_string(Atomic, ".", "", Strings),
790
+ maplist(number_string, [A,B,C,D], Strings)
791
+ -> true
792
+ ; syntax_error(illegal_ip_address)
793
+ ).
794
+ to_ip4(IP, IP).
795
+
796
+ mk_subnet(Var, IP, Subnet) :-
797
+ var(Var),
798
+ !,
799
+ ( default_subnet(IP, Subnet)
800
+ -> true
801
+ ; domain_error(ip_with_subnet, IP)
802
+ ).
803
+ mk_subnet(Subnet, _, Subnet4) :-
804
+ to_ip4(Subnet, Subnet4).
805
+
806
+ %! default_subnet(+IP, -NetWork)
807
+ %
808
+ % Determine the default network address from an IP address. This
809
+ % classifies the network as class A, B or C.
810
+ %
811
+ % @see https://docs.oracle.com/cd/E19504-01/802-5753/planning3-78185/index.html
812
+
813
+ default_subnet(ip(A,_,_,_), ip(A,0,0,0)) :-
814
+ between(0,127, A), !.
815
+ default_subnet(ip(A,B,_,_), ip(A,B,0,0)) :-
816
+ between(128,191, A), !.
817
+ default_subnet(ip(A,B,C,_), ip(A,B,C,0)) :-
818
+ between(192,223, A), !.
819
+
820
+ multicast_address(ip(A,_,_,_)) :-
821
+ between(224, 239, A),
822
+ !.
823
+ multicast_address(IP) :-
824
+ domain_error(multicast_network, IP).
825
+
826
+
827
+ /*******************************
828
+ * UNICAST PEERS *
829
+ *******************************/
830
+
831
+ %! udp_peer_add(+Scope, +Address) is det.
832
+ %! udp_peer_del(+Scope, ?Address) is det.
833
+ %! udp_peer(?Scope, ?Address) is nondet.
834
+ %
835
+ % Manage and query the set of known peers for a unicast network.
836
+ % Address is either a term IP:Port or a plain IP address. In the
837
+ % latter case the default port registered with the scope is used.
838
+ %
839
+ % @arg Address has canonical form ip(A,B,C,D):Port.
840
+
841
+ udp_peer_add(Scope, Address) :-
842
+ must_be(ground, Address),
843
+ peer_address(Address, Scope, Canonical),
844
+ ( udp_scope_peer(Scope, Canonical)
845
+ -> true
846
+ ; assertz(udp_scope_peer(Scope, Canonical))
847
+ ).
848
+
849
+ udp_peer_del(Scope, Address) :-
850
+ peer_address(Address, Scope, Canonical),
851
+ retractall(udp_scope_peer(Scope, Canonical)).
852
+
853
+ udp_peer(Scope, IPAddress) :-
854
+ udp_scope_peer(Scope, IPAddress).
855
+
856
+ peer_address(IP:Port, _Scope, IPAddress:Port) :-
857
+ !,
858
+ to_ip4(IP, IPAddress).
859
+ peer_address(IP, Scope, IPAddress:Port) :-
860
+ ( udp_scope(Scope, unicast(Port))
861
+ -> true
862
+ ; existence_error(udp_scope, Scope)
863
+ ),
864
+ to_ip4(IP, IPAddress).
865
+
866
+
867
+
868
+ /*******************************
869
+ * HOOKS *
870
+ *******************************/
871
+
872
+ %! udp_term_string_hook(+Scope, +Term, -String) is det.
873
+ %! udp_term_string_hook(+Scope, -Term, +String) is semidet.
874
+ %
875
+ % Hook for serializing the message Term. The default writes
876
+ % =|%prolog\n|=, followed by the Prolog term in quoted notation while
877
+ % ignoring operators. This hook may use alternative serialization such
878
+ % as fast_term_serialized/2, use library(ssl) to realise encrypted
879
+ % messages, etc.
880
+ %
881
+ % @arg Scope is the scope for which the message is broadcasted. This
882
+ % can be used to use different serialization for different scopes.
883
+ % @arg Term encapsulates the term broadcasted by the application as
884
+ % follows:
885
+ %
886
+ % - send(ApplTerm)
887
+ % Is sent by broadcast(udp(Scope, ApplTerm))
888
+ % - request(Id,ApplTerm)
889
+ % Is sent by broadcast_request/1, where Id is a unique large
890
+ % (64 bit) integer.
891
+ % - reply(Id,ApplTerm)
892
+ % Is sent to reply on a broadcast_request/1 request that has
893
+ % been received. Arguments are the same as above.
894
+ %
895
+ % @throws The hook may throw udp(invalid_message) to stop processing
896
+ % the message.
897
+
898
+ %! udp_term_string(+Scope, +Term, -String) is det.
899
+ %! udp_term_string(+Scope, -Term, +String) is semidet.
900
+ %
901
+ % Serialize an arbitrary Prolog term as a string. The string is
902
+ % prefixed by a magic key to ensure we only accept messages that are
903
+ % meant for us.
904
+ %
905
+ % In mode (+,-), Term is written with the options ignore_ops(true) and
906
+ % quoted(true).
907
+ %
908
+ % This predicate first calls udp_term_string_hook/3.
909
+
910
+ udp_term_string(Scope, Term, String) :-
911
+ catch(udp_term_string_hook(Scope, Term, String), udp(Error), true),
912
+ !,
913
+ ( var(Error)
914
+ -> true
915
+ ; Error == invalid_message
916
+ -> fail
917
+ ; throw(udp(Error))
918
+ ).
919
+ udp_term_string(_Scope, Term, String) :-
920
+ ( var(String)
921
+ -> format(string(String), '%-prolog-\n~W',
922
+ [ Term,
923
+ [ ignore_ops(true),
924
+ quoted(true)
925
+ ]
926
+ ])
927
+ ; sub_string(String, 0, _, _, '%-prolog-\n'),
928
+ term_string(Term, String,
929
+ [ syntax_errors(quiet)
930
+ ])
931
+ ).
932
+
933
+ %! unicast_out_of_scope_request(+Scope, +From, +Data) is semidet.
934
+
935
+ %! udp_unicast_join_hook(+Scope, +From, +Data) is semidet.
936
+ %
937
+ % This multifile hook is called if an UDP package is received on the
938
+ % port of the unicast network identified by Scope. From is the origin
939
+ % IP and port and Data is the message data that is deserialized as
940
+ % defined for the scope (see udp_term_string/3).
941
+ %
942
+ % This hook is intended to initiate a new node joining the network of
943
+ % peers. We could in theory also omit the in-scope test and use a
944
+ % normal broadcast to join. Using a different channal however provides
945
+ % a basic level of security. A possibe implementation is below. The
946
+ % first fragment is a hook added to the server, the second is a
947
+ % predicate added to a client and the last initiates the request in
948
+ % the client. The excanged term (join(X)) can be used to exchange a
949
+ % welcome handshake.
950
+ %
951
+ %
952
+ % ```
953
+ % :- multifile udp_broadcast:udp_unicast_join_hook/3.
954
+ % udp_broadcast:udp_unicast_join_hook(Scope, From, join(welcome)) :-
955
+ % udp_peer_add(Scope, From),
956
+ % ```
957
+ %
958
+ % ```
959
+ % join_request(Scope, Address, Reply) :-
960
+ % udp_peer_add(Scope, Address),
961
+ % broadcast_request(udp(Scope, join(X))).
962
+ % ```
963
+ %
964
+ % ```
965
+ % ?- join_request(myscope, "1.2.3.4":10001, Reply).
966
+ % Reply = welcome.
967
+ % ```
968
+
969
+ unicast_out_of_scope_request(Scope, From, send(Term)) :-
970
+ udp_unicast_join_hook(Scope, From, Term).
971
+ unicast_out_of_scope_request(Scope, From, request(Key, Term)) :-
972
+ udp_unicast_join_hook(Scope, From, Term),
973
+ udp_public_socket(Scope, _Port, Socket, _FileNo),
974
+ safely((udp_term_string(Scope, reply(Key,Term), Message),
975
+ udp_send(Socket, Message, From, []))).