]> Cypherpunks.ru repositories - nncp.git/blob - doc/integration.texi
a8a8b9ea4cc606d73a1fb7df2e9dac25a85f1a27
[nncp.git] / doc / integration.texi
1 @node Integration
2 @unnumbered Integration with existing software
3
4 Here is some examples of how you can solve popular tasks with NNCP,
5 making them store-and-forward friendly.
6
7 @menu
8 * Index files for freqing: FreqIndex.
9 * Postfix::
10 * Web feeds: Feeds.
11 * Web pages: WARCs.
12 * BitTorrent and huge files: BitTorrent.
13 * Downloading service: DownloadService.
14 * Git::
15 * Multimedia streaming: Multimedia.
16 @end menu
17
18 @node FreqIndex
19 @section Index files for freqing
20
21 In many cases you do not know exact files list on remote machine you
22 want to freq from. Because files can be updated there. It is useful to
23 run cron-ed job on it to create files listing you can freq and search
24 for files in it:
25
26 @example
27 0  4  *  *  *  cd /storage ; tmp=`mktemp` ; \
28     tree -f -h -N --du --timefmt \%Y-\%m-\%d |
29     zstdmt -19 > $tmp && chmod 644 $tmp && mv $tmp TREE.txt.zst ; \
30     tree -J -f --timefmt \%Y-\%m-\%d |
31     zstdmt -19 > $tmp && chmod 644 $tmp && mv $tmp TREE.json.zst
32 @end example
33
34 @node Postfix
35 @section Integration with Postfix
36
37 This section is taken from @url{http://www.postfix.org/UUCP_README.html,
38 Postfix and UUCP} manual and just replaces UUCP-related calls with NNCP
39 ones.
40
41 @strong{Setting up a Postfix Internet to NNCP gateway}
42
43 Here is how to set up a machine that sits on the Internet and that forwards
44 mail to a LAN that is connected via NNCP.
45
46 @itemize
47
48 @item You need an @ref{nncp-exec} program that extracts the sender
49 address from mail that arrives via NNCP, and that feeds the mail into
50 the Postfix @command{sendmail} command.
51
52 @item Define a @command{pipe(8)} based mail delivery transport for
53 delivery via NNCP:
54 @example
55 /usr/local/etc/postfix/master.cf:
56 nncp      unix  -       n       n       -       -       pipe
57           flags=F user=nncp argv=nncp-exec -quiet $nexthop sendmail $recipient
58 @end example
59
60 This runs the @command{nncp-exec} command to place outgoing mail into
61 the NNCP queue after replacing @var{$nexthop} by the the receiving NNCP
62 node and after replacing @var{$recipient} by the recipients. The
63 @command{pipe(8)} delivery agent executes the @command{nncp-exec}
64 command without assistance from the shell, so there are no problems with
65 shell meta characters in command-line parameters.
66
67 @item Specify that mail for @emph{example.com}, should be delivered via
68 NNCP, to a host named @emph{nncp-host}:
69
70 @example
71 /usr/local/etc/postfix/transport:
72     example.com     nncp:nncp-host
73     .example.com    nncp:nncp-host
74 @end example
75
76 See the @command{transport(5)} manual page for more details.
77
78 @item Execute the command @command{postmap /etc/postfix/transport}
79 whenever you change the @file{transport} file.
80
81 @item Enable @file{transport} table lookups:
82
83 @example
84 /usr/local/etc/postfix/main.cf:
85     transport_maps = hash:$config_directory/transport
86 @end example
87
88 @item Add @emph{example.com} to the list of domains that your site is
89 willing to relay mail for.
90
91 @example
92 /usr/local/etc/postfix/main.cf:
93     relay_domains = example.com ...other relay domains...
94 @end example
95
96 See the @option{relay_domains} configuration parameter description for
97 details.
98
99 @item Execute the command @command{postfix reload} to make the changes
100 effective.
101
102 @end itemize
103
104 @strong{Setting up a Postfix LAN to NNCP gateway}
105
106 Here is how to relay mail from a LAN via NNCP to the Internet.
107
108 @itemize
109
110 @item You need an @ref{nncp-exec} program that extracts the sender
111 address from mail that arrives via NNCP, and that feeds the mail into
112 the Postfix @command{sendmail} command.
113
114 @item Specify that all remote mail must be sent via the @command{nncp}
115 mail transport to your NNCP gateway host, say, @emph{nncp-gateway}:
116
117 @example
118 /usr/local/etc/postfix/main.cf:
119     relayhost = nncp-gateway
120     default_transport = nncp
121 @end example
122
123 Postfix 2.0 and later also allows the following more succinct form:
124
125 @example
126 /usr/local/etc/postfix/main.cf:
127     default_transport = nncp:nncp-gateway
128 @end example
129
130 @item Define a @command{pipe(8)} based message delivery transport for
131 mail delivery via NNCP:
132
133 @example
134 /usr/local/etc/postfix/master.cf:
135 nncp      unix  -       n       n       -       -       pipe
136           flags=F user=nncp argv=nncp-exec -quiet $nexthop sendmail $recipient
137 @end example
138
139 This runs the @command{nncp-exec} command to place outgoing mail into
140 the NNCP queue. It substitutes the hostname (@emph{nncp-gateway}, or
141 whatever you specified) and the recipients before execution of the
142 command. The @command{nncp-exec} command is executed without assistance
143 from the shell, so there are no problems with shell meta characters.
144
145 @item Execute the command @command{postfix reload} to make the changes
146 effective.
147
148 @end itemize
149
150 @node Feeds
151 @section Integration with Web feeds
152
153 RSS and Atom feeds could be collected using
154 @url{https://github.com/wking/rss2email, rss2email} program. It
155 converts all incoming feed entries to email messages. Read about how to
156 integration @ref{Postfix} with email. @command{rss2email} could be run
157 in a cron, to collect feeds without any user interaction. Also this
158 program supports ETags and won't pollute the channel if remote server
159 supports them too.
160
161 After installing @command{rss2email}, create configuration file:
162
163 @example
164 $ r2e new rss-robot@@address.com
165 @end example
166
167 and add feeds you want to retrieve:
168
169 @example
170 $ r2e add https://git.cypherpunks.ru/cgit.cgi/nncp.git/atom/?h=master
171 @end example
172
173 and run the process:
174
175 @example
176 $ r2e run
177 @end example
178
179 @node WARCs
180 @section Integration with Web pages
181
182 Simple HTML web page can be downloaded very easily for sending and
183 viewing it offline after:
184
185 @example
186 $ wget http://www.example.com/page.html
187 @end example
188
189 But most web pages contain links to images, CSS and JavaScript files,
190 required for complete rendering.
191 @url{https://www.gnu.org/software/wget/, GNU Wget} supports that
192 documents parsing and understanding page dependencies. You can download
193 the whole page with dependencies the following way:
194
195 @example
196 $ wget \
197     --page-requisites \
198     --convert-links \
199     --adjust-extension \
200     --restrict-file-names=ascii \
201     --span-hosts \
202     --random-wait \
203     --execute robots=off \
204     http://www.example.com/page.html
205 @end example
206
207 that will create @file{www.example.com} directory with all files
208 necessary to view @file{page.html} web page. You can create single file
209 compressed tarball with that directory and send it to remote node:
210
211 @example
212 $ tar cf - www.example.com | zstd |
213     nncp-file - remote.node:www.example.com-page.tar.zst
214 @end example
215
216 But there are multi-paged articles, there are the whole interesting
217 sites you want to get in a single package. You can mirror the whole web
218 site by utilizing @command{wget}'s recursive feature:
219
220 @example
221 $ wget \
222     --recursive \
223     --timestamping \
224     -l inf \
225     --no-remove-listing \
226     --no-parent \
227     [...]
228     http://www.example.com/
229 @end example
230
231 There is a standard for creating
232 @url{https://en.wikipedia.org/wiki/Web_ARChive, Web ARChives}:
233 @strong{WARC}. Fortunately again, @command{wget} supports it as an
234 output format.
235
236 @example
237 $ wget \
238     --warc-file www.example_com-$(date '+%Y%M%d%H%m%S') \
239     --no-warc-compression \
240     --no-warc-keep-log \
241     [...]
242     http://www.example.com/
243 @end example
244
245 That command will create uncompressed @file{www.example_com-XXX.warc}
246 web archive. By default, WARCs are compressed using
247 @url{https://en.wikipedia.org/wiki/Gzip, gzip}, but, in example above,
248 we have disabled it to compress with stronger and faster
249 @url{https://en.wikipedia.org/wiki/Zstd, zstd}, before sending via
250 @command{nncp-file}.
251
252 There are plenty of software acting like HTTP proxy for your browser,
253 allowing to view that WARC files. However you can extract files from
254 that archive using @url{https://pypi.python.org/pypi/Warcat, warcat}
255 utility, producing usual directory hierarchy:
256
257 @example
258 $ python3 -m warcat extract \
259     www.example_com-XXX.warc \
260     --output-dir www.example.com-XXX \
261     --progress
262 @end example
263
264 @node BitTorrent
265 @section BitTorrent and huge files
266
267 If dealing with @ref{Git}, @ref{Feeds, web feeds} and @ref{Multimedia,
268 multimedia} goes relatively fast, then BitTorrent and huge files
269 consumes much time. You can not wait for downloads finish, but want to
270 queue them after.
271
272 @url{http://aria2.github.io/, aria2} multi-protocol download utility
273 could be used for solving that issue conveniently. It supports HTTP,
274 HTTPS, FTP, SFTP and BitTorrent protocols, together with
275 @url{http://tools.ietf.org/html/rfc5854, Metalink} format. BitTorrent
276 support is fully-featured: UDP trackers, DHT, PEX, encryption, magnet
277 URIs, Web-seeding, selective downloads, LPD. @command{aria2} can
278 accelerate HTTP*/*FTP downloads by segmented multiple parallel
279 connections.
280
281 You can queue you files after they are completely downloaded.
282 @file{aria2-downloaded.sh} contents:
283
284 @verbatiminclude aria2-downloaded.sh
285
286 Also you can prepare
287 @url{http://aria2.github.io/manual/en/html/aria2c.html#files, input file}
288 with the jobs you want to download:
289
290 @example
291 $ cat jobs
292 http://www.nncpgo.org/download/nncp-0.11.tar.xz
293     out=nncp.txz
294 http://www.nncpgo.org/download/nncp-0.11.tar.xz.sig
295     out=nncp.txz.sig
296 $ aria2c \
297     --on-download-complete aria2-downloaded.sh \
298     --input-file jobs
299 @end example
300
301 and all that downloaded (@file{nncp.txz}, @file{nncp.txz.sig}) files
302 will be sent to @file{remote.node} when finished.
303
304 @node DownloadService
305 @section Downloading service
306
307 Previous sections tell about manual downloading and sending results to
308 remote node. But one wish to remotely initiate downloading. That can be
309 easily solved with @ref{CfgExec, exec} handles.
310
311 @verbatim
312 exec: {
313   warcer: ["/bin/sh", "/path/to/warcer.sh"]
314   wgeter: ["/bin/sh", "/path/to/wgeter.sh"]
315   aria2c: [
316     "/usr/local/bin/aria2c",
317     "--on-download-complete", "aria2-downloaded.sh",
318     "--on-bt-download-complete", "aria2-downloaded.sh"
319   ]
320 }
321 @end verbatim
322
323 @file{warcer.sh} contents:
324
325 @verbatiminclude warcer.sh
326
327 @file{wgeter.sh} contents:
328
329 @verbatiminclude wgeter.sh
330
331 Now you can queue that node to send you some website's page, file or
332 BitTorrents:
333
334 @example
335 $ echo http://www.nncpgo.org/Postfix.html |
336     nncp-exec remote.node warcer postfix-whole-page
337 $ echo http://www.nncpgo.org/Postfix.html |
338     nncp-exec remote.node wgeter postfix-html-page
339 $ echo \
340     http://www.nncpgo.org/download/nncp-0.11.tar.xz
341     http://www.nncpgo.org/download/nncp-0.11.tar.xz.sig |
342     nncp-exec remote.node aria2c
343 @end example
344
345 @node Git
346 @section Integration with Git
347
348 @url{https://git-scm.com/, Git} version control system already has all
349 necessary tools for store-and-forward networking.
350 @url{https://git-scm.com/docs/git-bundle, git-bundle} command is
351 everything you need.
352
353 Use it to create bundles containing all required blobs/trees/commits and tags:
354
355 @example
356 $ git bundle create repo-initial.bundle master --tags --branches
357 $ git tag -f last-bundle
358 $ nncp-file repo-initial.bundle remote.node:repo-$(date % '+%Y%M%d%H%m%S').bundle
359 @end example
360
361 Do usual working with the Git: commit, add, branch, checkout, etc. When
362 you decide to queue your changes for sending, create diff-ed bundle and
363 transfer them:
364
365 @example
366 $ git bundle create repo-$(date '+%Y%M%d%H%m%S').bundle last-bundle..master
367 or maybe
368 $ git bundle create repo-$(date '+%Y%M%d').bundle --since=10.days master
369 @end example
370
371 Received bundle on remote machine acts like usual remote:
372
373 @example
374 $ git clone -b master repo-XXX.bundle
375 @end example
376
377 overwrite @file{repo.bundle} file with newer bundles you retrieve and
378 fetch all required branches and commits:
379
380 @example
381 $ git pull # assuming that origin remote points to repo.bundle
382 $ git fetch repo.bundle master:localRef
383 $ git ls-remote repo.bundle
384 @end example
385
386 Bundles are also useful when cloning huge repositories (like Linux has).
387 Git's native protocol does not support any kind of interrupted download
388 resuming, so you will start from the beginning if connection is lost.
389 Bundles, being an ordinary files, can be downloaded with native
390 HTTP/FTP/NNCP resuming capabilities. After you fetch repository via the
391 bundle, you can add an ordinary @file{git://} remote and fetch the
392 difference.
393
394 Also you can find the following exec-handler useful:
395
396 @verbatiminclude git-bundler.sh
397
398 And it allows you to request for bundles like that:
399 @code{echo some-old-commit..master | nncp-exec REMOTE bundler REPONAME}.
400
401 @node Multimedia
402 @section Integration with multimedia streaming
403
404 Many video and audio streams could be downloaded using
405 @url{http://yt-dl.org/, youtube-dl} program.
406 @url{https://rg3.github.io/youtube-dl/supportedsites.html, Look} how
407 many of them are supported, including @emph{Dailymotion}, @emph{Vimeo}
408 and @emph{YouTube}.
409
410 When you multimedia becomes an ordinary file, you can transfer it easily.
411
412 @example
413 $ youtube-dl \
414     --exec 'nncp-file @{@} remote.node:' \
415     'https://www.youtube.com/watch?list=PLd2Cw8x5CytxPAEBwzilrhQUHt_UN10FJ'
416 @end example