]> Cypherpunks.ru repositories - nncp.git/blob - doc/integration.texi
8240e2fb903ff67e9dd8c5923c5e8fef79d31f5a
[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 @verbatim
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 verbatim
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 @verbatim
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 verbatim
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 @verbatim
71 /usr/local/etc/postfix/transport:
72     example.com     nncp:nncp-host
73     .example.com    nncp:nncp-host
74 @end verbatim
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 @verbatim
84 /usr/local/etc/postfix/main.cf:
85     transport_maps = hash:$config_directory/transport
86 @end verbatim
87
88 @item Add @emph{example.com} to the list of domains that your site is
89 willing to relay mail for.
90
91 @verbatim
92 /usr/local/etc/postfix/main.cf:
93     relay_domains = example.com ...other relay domains...
94 @end verbatim
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 @verbatim
118 /usr/local/etc/postfix/main.cf:
119     relayhost = nncp-gateway
120     default_transport = nncp
121 @end verbatim
122
123 Postfix 2.0 and later also allows the following more succinct form:
124
125 @verbatim
126 /usr/local/etc/postfix/main.cf:
127     default_transport = nncp:nncp-gateway
128 @end verbatim
129
130 @item Define a @command{pipe(8)} based message delivery transport for
131 mail delivery via NNCP:
132
133 @verbatim
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 verbatim
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 @verbatim
163 $ r2e new rss-robot@address.com
164 @end verbatim
165 and add feeds you want to retrieve:
166 @verbatim
167 $ r2e add https://git.cypherpunks.ru/cgit.cgi/nncp.git/atom/?h=master
168 @end verbatim
169 and run the process:
170 @verbatim
171 $ r2e run
172 @end verbatim
173
174 @node WARCs
175 @section Integration with Web pages
176
177 Simple HTML web page can be downloaded very easily for sending and
178 viewing it offline after:
179 @verbatim
180 $ wget http://www.example.com/page.html
181 @end verbatim
182
183 But most web pages contain links to images, CSS and JavaScript files,
184 required for complete rendering.
185 @url{https://www.gnu.org/software/wget/, GNU Wget} supports that
186 documents parsing and understanding page dependencies. You can download
187 the whole page with dependencies the following way:
188 @verbatim
189 $ wget \
190     --page-requisites \
191     --convert-links \
192     --adjust-extension \
193     --restrict-file-names=ascii \
194     --span-hosts \
195     --random-wait \
196     --execute robots=off \
197     http://www.example.com/page.html
198 @end verbatim
199 that will create @file{www.example.com} directory with all files
200 necessary to view @file{page.html} web page. You can create single file
201 compressed tarball with that directory and send it to remote node:
202 @verbatim
203 $ tar cf - www.example.com | zstd |
204     nncp-file - remote.node:www.example.com-page.tar.zst
205 @end verbatim
206
207 But there are multi-paged articles, there are the whole interesting
208 sites you want to get in a single package. You can mirror the whole web
209 site by utilizing @command{wget}'s recursive feature:
210 @verbatim
211 $ wget \
212     --recursive \
213     --timestamping \
214     -l inf \
215     --no-remove-listing \
216     --no-parent \
217     [...]
218     http://www.example.com/
219 @end verbatim
220
221 There is a standard for creating
222 @url{https://en.wikipedia.org/wiki/Web_ARChive, Web ARChives}:
223 @strong{WARC}. Fortunately again, @command{wget} supports it as an
224 output format.
225 @verbatim
226 $ wget \
227     --warc-file www.example_com-$(date '+%Y%M%d%H%m%S') \
228     --no-warc-compression \
229     --no-warc-keep-log \
230     [...]
231     http://www.example.com/
232 @end verbatim
233 That command will create uncompressed @file{www.example_com-XXX.warc}
234 web archive. By default, WARCs are compressed using
235 @url{https://en.wikipedia.org/wiki/Gzip, gzip}, but, in example above,
236 we have disabled it to compress with stronger and faster
237 @url{https://en.wikipedia.org/wiki/Zstd, zstd}, before sending via
238 @command{nncp-file}.
239
240 There are plenty of software acting like HTTP proxy for your browser,
241 allowing to view that WARC files. However you can extract files from
242 that archive using @url{https://pypi.python.org/pypi/Warcat, warcat}
243 utility, producing usual directory hierarchy:
244 @verbatim
245 $ python3 -m warcat extract \
246     www.example_com-XXX.warc \
247     --output-dir www.example.com-XXX \
248     --progress
249 @end verbatim
250
251 @node BitTorrent
252 @section BitTorrent and huge files
253
254 If dealing with @ref{Git}, @ref{Feeds, web feeds} and @ref{Multimedia,
255 multimedia} goes relatively fast, then BitTorrent and huge files
256 consumes much time. You can not wait for downloads finish, but want to
257 queue them after.
258
259 @url{http://aria2.github.io/, aria2} multi-protocol download utility
260 could be used for solving that issue conveniently. It supports HTTP,
261 HTTPS, FTP, SFTP and BitTorrent protocols, together with
262 @url{http://tools.ietf.org/html/rfc5854, Metalink} format. BitTorrent
263 support is fully-featured: UDP trackers, DHT, PEX, encryption, magnet
264 URIs, Web-seeding, selective downloads, LPD. @command{aria2} can
265 accelerate HTTP*/*FTP downloads by segmented multiple parallel
266 connections.
267
268 You can queue you files after they are completely downloaded.
269 @file{aria2-downloaded.sh} contents:
270 @verbatiminclude aria2-downloaded.sh
271
272 Also you can prepare
273 @url{http://aria2.github.io/manual/en/html/aria2c.html#files, input file}
274 with the jobs you want to download:
275 @verbatim
276 $ cat jobs
277 http://www.nncpgo.org/download/nncp-0.11.tar.xz
278     out=nncp.txz
279 http://www.nncpgo.org/download/nncp-0.11.tar.xz.sig
280     out=nncp.txz.sig
281 $ aria2c \
282     --on-download-complete aria2-downloaded.sh \
283     --input-file jobs
284 @end verbatim
285 and all that downloaded (@file{nncp.txz}, @file{nncp.txz.sig}) files
286 will be sent to @file{remote.node} when finished.
287
288 @node DownloadService
289 @section Downloading service
290
291 Previous sections tell about manual downloading and sending results to
292 remote node. But one wish to remotely initiate downloading. That can be
293 easily solved with @ref{CfgExec, exec} handles.
294
295 @verbatim
296 exec: {
297   warcer: ["/bin/sh", "/path/to/warcer.sh"]
298   wgeter: ["/bin/sh", "/path/to/wgeter.sh"]
299   aria2c: [
300     "/usr/local/bin/aria2c",
301     "--on-download-complete", "aria2-downloaded.sh",
302     "--on-bt-download-complete", "aria2-downloaded.sh"
303   ]
304 }
305 @end verbatim
306
307 @file{warcer.sh} contents:
308 @verbatiminclude warcer.sh
309
310 @file{wgeter.sh} contents:
311 @verbatiminclude wgeter.sh
312
313 Now you can queue that node to send you some website's page, file or
314 BitTorrents:
315
316 @verbatim
317 $ echo http://www.nncpgo.org/Postfix.html |
318     nncp-exec remote.node warcer postfix-whole-page
319 $ echo http://www.nncpgo.org/Postfix.html |
320     nncp-exec remote.node wgeter postfix-html-page
321 $ echo \
322     http://www.nncpgo.org/download/nncp-0.11.tar.xz
323     http://www.nncpgo.org/download/nncp-0.11.tar.xz.sig |
324     nncp-exec remote.node aria2c
325 @end verbatim
326
327 @node Git
328 @section Integration with Git
329
330 @url{https://git-scm.com/, Git} version control system already has all
331 necessary tools for store-and-forward networking.
332 @url{https://git-scm.com/docs/git-bundle, git-bundle} command is
333 everything you need.
334
335 Use it to create bundles containing all required blobs/trees/commits and tags:
336 @verbatim
337 $ git bundle create repo-initial.bundle master --tags --branches
338 $ git tag -f last-bundle
339 $ nncp-file repo-initial.bundle remote.node:repo-$(date % '+%Y%M%d%H%m%S').bundle
340 @end verbatim
341
342 Do usual working with the Git: commit, add, branch, checkout, etc. When
343 you decide to queue your changes for sending, create diff-ed bundle and
344 transfer them:
345 @verbatim
346 $ git bundle create repo-$(date '+%Y%M%d%H%m%S').bundle last-bundle..master
347 or maybe
348 $ git bundle create repo-$(date '+%Y%M%d').bundle --since=10.days master
349 @end verbatim
350
351 Received bundle on remote machine acts like usual remote:
352 @verbatim
353 $ git clone -b master repo-XXX.bundle
354 @end verbatim
355 overwrite @file{repo.bundle} file with newer bundles you retrieve and
356 fetch all required branches and commits:
357 @verbatim
358 $ git pull # assuming that origin remote points to repo.bundle
359 $ git fetch repo.bundle master:localRef
360 $ git ls-remote repo.bundle
361 @end verbatim
362
363 Bundles are also useful when cloning huge repositories (like Linux has).
364 Git's native protocol does not support any kind of interrupted download
365 resuming, so you will start from the beginning if connection is lost.
366 Bundles, being an ordinary files, can be downloaded with native
367 HTTP/FTP/NNCP resuming capabilities. After you fetch repository via the
368 bundle, you can add an ordinary @file{git://} remote and fetch the
369 difference.
370
371 Also you can find the following exec-handler useful:
372 @verbatiminclude git-bundler.sh
373 And it allows you to request for bundles like that:
374 @code{echo some-old-commit..master | nncp-exec REMOTE bundler REPONAME}.
375
376 @node Multimedia
377 @section Integration with multimedia streaming
378
379 Many video and audio streams could be downloaded using
380 @url{http://yt-dl.org/, youtube-dl} program.
381 @url{https://rg3.github.io/youtube-dl/supportedsites.html, Look} how
382 many of them are supported, including @emph{Dailymotion}, @emph{Vimeo}
383 and @emph{YouTube}.
384
385 When you multimedia becomes an ordinary file, you can transfer it easily.
386 @verbatim
387 $ youtube-dl \
388     --exec 'nncp-file {} remote.node:' \
389     'https://www.youtube.com/watch?list=PLd2Cw8x5CytxPAEBwzilrhQUHt_UN10FJ'
390 @end verbatim