2 @unnumbered Integration with existing software
4 Here is some examples of how you can solve popular tasks with NNCP,
5 making them store-and-forward friendly.
8 * Index files for freqing: FreqIndex.
13 * BitTorrent and huge files: BitTorrent.
14 * Downloading service: DownloadService.
16 * Multimedia streaming: Multimedia.
20 @section Index files for freqing
22 In many cases you do not know exact files list on remote machine you
23 want to freq from. Because files can be updated there. It is useful to
24 run cron-ed job on it to create files listing you can freq and search
28 0 4 * * * cd /storage ; tmp=`mktemp` ; \
29 tree -f -h -N --du --timefmt \%Y-\%m-\%d |
30 zstdmt -19 > $tmp && chmod 644 $tmp && mv $tmp TREE.txt.zst ; \
31 tree -J -f --timefmt \%Y-\%m-\%d |
32 zstdmt -19 > $tmp && chmod 644 $tmp && mv $tmp TREE.json.zst
36 @section Integration with Postfix
38 This section is taken from @url{http://www.postfix.org/UUCP_README.html,
39 Postfix and UUCP} manual and just replaces UUCP-related calls with NNCP
42 @strong{Setting up a Postfix Internet to NNCP gateway}
44 Here is how to set up a machine that sits on the Internet and that forwards
45 mail to a LAN that is connected via NNCP.
49 @item You need an @ref{nncp-exec} program that extracts the sender
50 address from mail that arrives via NNCP, and that feeds the mail into
51 the Postfix @command{sendmail} command.
53 @item Define a @command{pipe(8)} based mail delivery transport for
56 /usr/local/etc/postfix/master.cf:
57 nncp unix - n n - - pipe
58 flags=F user=nncp argv=nncp-exec -quiet $nexthop sendmail $recipient
61 This runs the @command{nncp-exec} command to place outgoing mail into
62 the NNCP queue after replacing @var{$nexthop} by the the receiving NNCP
63 node and after replacing @var{$recipient} by the recipients. The
64 @command{pipe(8)} delivery agent executes the @command{nncp-exec}
65 command without assistance from the shell, so there are no problems with
66 shell meta characters in command-line parameters.
68 @item Specify that mail for @emph{example.com}, should be delivered via
69 NNCP, to a host named @emph{nncp-host}:
72 /usr/local/etc/postfix/transport:
73 example.com nncp:nncp-host
74 .example.com nncp:nncp-host
77 See the @command{transport(5)} manual page for more details.
79 @item Execute the command @command{postmap /etc/postfix/transport}
80 whenever you change the @file{transport} file.
82 @item Enable @file{transport} table lookups:
85 /usr/local/etc/postfix/main.cf:
86 transport_maps = hash:$config_directory/transport
89 @item Add @emph{example.com} to the list of domains that your site is
90 willing to relay mail for.
93 /usr/local/etc/postfix/main.cf:
94 relay_domains = example.com ...other relay domains...
97 See the @option{relay_domains} configuration parameter description for
100 @item Execute the command @command{postfix reload} to make the changes
105 @strong{Setting up a Postfix LAN to NNCP gateway}
107 Here is how to relay mail from a LAN via NNCP to the Internet.
111 @item You need an @ref{nncp-exec} program that extracts the sender
112 address from mail that arrives via NNCP, and that feeds the mail into
113 the Postfix @command{sendmail} command.
115 @item Specify that all remote mail must be sent via the @command{nncp}
116 mail transport to your NNCP gateway host, say, @emph{nncp-gateway}:
119 /usr/local/etc/postfix/main.cf:
120 relayhost = nncp-gateway
121 default_transport = nncp
124 Postfix 2.0 and later also allows the following more succinct form:
127 /usr/local/etc/postfix/main.cf:
128 default_transport = nncp:nncp-gateway
131 @item Define a @command{pipe(8)} based message delivery transport for
132 mail delivery via NNCP:
135 /usr/local/etc/postfix/master.cf:
136 nncp unix - n n - - pipe
137 flags=F user=nncp argv=nncp-exec -quiet $nexthop sendmail $recipient
140 This runs the @command{nncp-exec} command to place outgoing mail into
141 the NNCP queue. It substitutes the hostname (@emph{nncp-gateway}, or
142 whatever you specified) and the recipients before execution of the
143 command. The @command{nncp-exec} command is executed without assistance
144 from the shell, so there are no problems with shell meta characters.
146 @item Execute the command @command{postfix reload} to make the changes
152 @section Integration with Exim
154 This section is unaltered copy-paste of
155 @url{https://changelog.complete.org/archives/10165-asynchronous-email-exim-over-nncp-or-uucp, Asynchronous Email: Exim over NNCP (or UUCP)}
156 article by John Goerzen, with his permission.
158 @strong{Sending from Exim to a smarthost}
160 One common use for async email is from a satellite system: one that
161 doesn't receive mail, or have local mailboxes, but just needs to get
162 email out to the Internet. This is a common situation even for
163 conventionally-connected systems; in Exim speak, this is a "satellite
164 system that routes mail via a smarthost". That is, every outbound
165 message goes to a specific target, which then is responsible for
166 eventual delivery (over the Internet, LAN, whatever).
168 This is fairly simple in Exim.
170 We actually have two choices for how to do this: bsmtp or rmail mode.
171 bsmtp (batch SMTP) is the more modern way, and is essentially a
172 derivative of SMTP that explicitly can be queued asynchronously.
173 Basically it's a set of SMTP commands that can be saved in a file. The
174 alternative is "rmail" (which is just an alias for sendmail these days),
175 where the data is piped to rmail/sendmail with the recipients given on
176 the command line. Both can work with Exim and NNCP, but because we're
177 doing shiny new things, we'll use bsmtp.
179 These instructions are loosely based on the
180 @url{https://people.debian.org/~jdg/bsmtp.html, Using outgoing BSMTP with Exim HOWTO}.
181 Some of these may assume Debianness in the configuration, but should be
182 easily enough extrapolated to other configs as well.
184 First, configure Exim to use satellite mode with minimal DNS lookups
185 (assuming that you may not have working DNS anyhow).
187 Then, in the Exim primary router section for smarthost
188 (@file{router/200_exim4-config_primary} in Debian split configurations),
189 just change @code{transport = remote_smtp_smarthost to transport = nncp}.
191 Now, define the NNCP transport. If you are on Debian, you might name this
192 @file{transports/40_exim4-config_local_nncp}:
196 debug_print = "T: nncp transport for $local_part@@$domain"
201 command = /usr/local/nncp/bin/nncp-exec -noprogress -quiet hostname_goes_here rsmtp
202 .ifdef REMOTE_SMTP_HEADERS_REWRITE
203 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
205 .ifdef REMOTE_SMTP_RETURN_PATH
206 return_path = REMOTE_SMTP_RETURN_PATH
210 This is pretty straightforward. We pipe to @command{nncp-exec}, run it
211 as the nncp user. @command{nncp-exec} sends it to a target node and runs
212 whatever that node has called @command{rsmtp} (the command to receive
213 bsmtp data). When the target node processes the request, it will run the
214 configured command and pipe the data in to it.
216 @strong{More complicated: Routing to various NNCP nodes}
218 Perhaps you would like to be able to send mail directly to various NNCP
219 nodes. There are a lot of ways to do that.
221 Fundamentally, you will need a setup similar to the UUCP example in
222 @url{https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_manualroute_router.html,
223 Exim's manualroute manual}, which lets you define how to reach various
224 hosts via UUCP/NNCP. Perhaps you have a star topology (every NNCP node
225 exchanges email with a central hub). In the NNCP world, you have two
226 choices of how you do this. You could, at the Exim level, make the
227 central hub the smarthost for all the side nodes, and let it
228 redistribute mail. That would work, but requires decrypting messages at
229 the hub to let Exim process. The other alternative is to configure NNCP
230 to just send to the destinations via the central hub; that takes
231 advantage of onion routing and doesn't require any Exim processing at
232 the central hub at all.
234 @strong{Receiving mail from NNCP}
236 On the receiving side, first you need to configure NNCP to authorize the
237 execution of a mail program. In the section of your receiving host where
238 you set the permissions for the client, include something like this:
242 rsmtp: ["/usr/sbin/sendmail", "-bS"]
246 The -bS option is what tells Exim to receive BSMTP on stdin.
248 Now, you need to tell Exim that nncp is a trusted user (able to set From
249 headers arbitrarily). Assuming you are running NNCP as the nncp user,
250 then add @code{MAIN_TRUSTED_USERS = nncp} to a file such as
251 @file{/etc/exim4/conf.d/main/01_exim4-config_local-nncp}. That's it!
253 Some hosts, of course, both send and receive mail via NNCP and will need
254 configurations for both.
257 @section Integration with Web feeds
259 RSS and Atom feeds could be collected using
260 @url{https://github.com/wking/rss2email, rss2email} program. It converts
261 all incoming feed entries to email messages. Read about how to integrate
262 @ref{Postfix}/@ref{Exim} with email. @command{rss2email} could be run in
263 a cron, to collect feeds without any user interaction. Also this program
264 supports ETags and won't pollute the channel if remote server supports
267 After installing @command{rss2email}, create configuration file:
270 $ r2e new rss-robot@@address.com
273 and add feeds you want to retrieve:
276 $ r2e add http://www.git.cypherpunks.ru/?p=nncp.git;a=atom
286 @section Integration with Web pages
288 Simple HTML web page can be downloaded very easily for sending and
289 viewing it offline after:
292 $ wget http://www.example.com/page.html
295 But most web pages contain links to images, CSS and JavaScript files,
296 required for complete rendering.
297 @url{https://www.gnu.org/software/wget/, GNU Wget} supports that
298 documents parsing and understanding page dependencies. You can download
299 the whole page with dependencies the following way:
306 --restrict-file-names=ascii \
309 --execute robots=off \
310 http://www.example.com/page.html
313 that will create @file{www.example.com} directory with all files
314 necessary to view @file{page.html} web page. You can create single file
315 compressed tarball with that directory and send it to remote node:
318 $ tar cf - www.example.com | zstd |
319 nncp-file - remote.node:www.example.com-page.tar.zst
322 But there are multi-paged articles, there are the whole interesting
323 sites you want to get in a single package. You can mirror the whole web
324 site by utilizing @command{wget}'s recursive feature:
331 --no-remove-listing \
334 http://www.example.com/
337 There is a standard for creating
338 @url{https://en.wikipedia.org/wiki/Web_ARChive, Web ARChives}:
339 @strong{WARC}. Fortunately again, @command{wget} supports it as an
344 --warc-file www.example_com-$(date '+%Y%M%d%H%m%S') \
345 --no-warc-compression \
348 http://www.example.com/
351 That command will create uncompressed @file{www.example_com-XXX.warc}
352 web archive. By default, WARCs are compressed using
353 @url{https://en.wikipedia.org/wiki/Gzip, gzip}, but, in example above,
354 we have disabled it to compress with stronger and faster
355 @url{https://en.wikipedia.org/wiki/Zstd, zstd}, before sending via
358 There are plenty of software acting like HTTP proxy for your browser,
359 allowing to view that WARC files. However you can extract files from
360 that archive using @url{https://pypi.python.org/pypi/Warcat, warcat}
361 utility, producing usual directory hierarchy:
364 $ python3 -m warcat extract \
365 www.example_com-XXX.warc \
366 --output-dir www.example.com-XXX \
371 @section BitTorrent and huge files
373 If dealing with @ref{Git}, @ref{Feeds, web feeds} and @ref{Multimedia,
374 multimedia} goes relatively fast, then BitTorrent and huge files
375 consumes much time. You can not wait for downloads finish, but want to
378 @url{http://aria2.github.io/, aria2} multi-protocol download utility
379 could be used for solving that issue conveniently. It supports HTTP,
380 HTTPS, FTP, SFTP and BitTorrent protocols, together with
381 @url{http://tools.ietf.org/html/rfc5854, Metalink} format. BitTorrent
382 support is fully-featured: UDP trackers, DHT, PEX, encryption, magnet
383 URIs, Web-seeding, selective downloads, LPD. @command{aria2} can
384 accelerate HTTP*/*FTP downloads by segmented multiple parallel
387 You can queue you files after they are completely downloaded.
388 @file{aria2-downloaded.sh} contents:
390 @verbatiminclude aria2-downloaded.sh
393 @url{http://aria2.github.io/manual/en/html/aria2c.html#files, input file}
394 with the jobs you want to download:
398 http://www.nncpgo.org/download/nncp-0.11.tar.xz
400 http://www.nncpgo.org/download/nncp-0.11.tar.xz.sig
403 --on-download-complete aria2-downloaded.sh \
407 and all that downloaded (@file{nncp.txz}, @file{nncp.txz.sig}) files
408 will be sent to @file{remote.node} when finished.
410 @node DownloadService
411 @section Downloading service
413 Previous sections tell about manual downloading and sending results to
414 remote node. But one wish to remotely initiate downloading. That can be
415 easily solved with @ref{CfgExec, exec} handles.
419 warcer: ["/bin/sh", "/path/to/warcer.sh"]
420 wgeter: ["/bin/sh", "/path/to/wgeter.sh"]
422 "/usr/local/bin/aria2c",
423 "--on-download-complete", "aria2-downloaded.sh",
424 "--on-bt-download-complete", "aria2-downloaded.sh"
429 @file{warcer.sh} contents:
431 @verbatiminclude warcer.sh
433 @file{wgeter.sh} contents:
435 @verbatiminclude wgeter.sh
437 Now you can queue that node to send you some website's page, file or
441 $ echo http://www.nncpgo.org/Postfix.html |
442 nncp-exec remote.node warcer postfix-whole-page
443 $ echo http://www.nncpgo.org/Postfix.html |
444 nncp-exec remote.node wgeter postfix-html-page
446 http://www.nncpgo.org/download/nncp-0.11.tar.xz
447 http://www.nncpgo.org/download/nncp-0.11.tar.xz.sig |
448 nncp-exec remote.node aria2c
452 @section Integration with Git
454 @url{https://git-scm.com/, Git} version control system already has all
455 necessary tools for store-and-forward networking.
456 @url{https://git-scm.com/docs/git-bundle, git-bundle} command is
459 Use it to create bundles containing all required blobs/trees/commits and tags:
462 $ git bundle create repo-initial.bundle master --tags --branches
463 $ git tag -f last-bundle
464 $ nncp-file repo-initial.bundle remote.node:repo-$(date % '+%Y%M%d%H%m%S').bundle
467 Do usual working with the Git: commit, add, branch, checkout, etc. When
468 you decide to queue your changes for sending, create diff-ed bundle and
472 $ git bundle create repo-$(date '+%Y%M%d%H%m%S').bundle last-bundle..master
474 $ git bundle create repo-$(date '+%Y%M%d').bundle --since=10.days master
477 Received bundle on remote machine acts like usual remote:
480 $ git clone -b master repo-XXX.bundle
483 overwrite @file{repo.bundle} file with newer bundles you retrieve and
484 fetch all required branches and commits:
487 $ git pull # assuming that origin remote points to repo.bundle
488 $ git fetch repo.bundle master:localRef
489 $ git ls-remote repo.bundle
492 Bundles are also useful when cloning huge repositories (like Linux has).
493 Git's native protocol does not support any kind of interrupted download
494 resuming, so you will start from the beginning if connection is lost.
495 Bundles, being an ordinary files, can be downloaded with native
496 HTTP/FTP/NNCP resuming capabilities. After you fetch repository via the
497 bundle, you can add an ordinary @file{git://} remote and fetch the
500 Also you can find the following exec-handler useful:
502 @verbatiminclude git-bundler.sh
504 And it allows you to request for bundles like that:
505 @code{echo some-old-commit..master | nncp-exec REMOTE bundler REPONAME}.
508 @section Integration with multimedia streaming
510 Many video and audio streams could be downloaded using
511 @url{http://yt-dl.org/, youtube-dl} program.
512 @url{https://rg3.github.io/youtube-dl/supportedsites.html, Look} how
513 many of them are supported, including @emph{Dailymotion}, @emph{Vimeo}
516 When you multimedia becomes an ordinary file, you can transfer it easily.
520 --exec 'nncp-file @{@} remote.node:' \
521 'https://www.youtube.com/watch?list=PLd2Cw8x5CytxPAEBwzilrhQUHt_UN10FJ'