1 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # represents an NNTPD (currently a singleton),
5 # see script/public-inbox-nntpd for how it is used
6 package PublicInbox::NNTPD;
10 use PublicInbox::Config;
11 use PublicInbox::InboxIdle;
15 my $pi_cfg = PublicInbox::Config->new;
16 my $name = $pi_cfg->{'publicinbox.nntpserver'};
17 if (!defined($name) or $name eq '') {
19 } elsif (ref($name) eq 'ARRAY') {
29 greet => \"201 $name ready - post via email\r\n",
30 # accept_tls => { SSL_server => 1, ..., SSL_reuse_ctx => ... }
31 # idler => PublicInbox::InboxIdle
36 my ($self, $sig) = @_;
37 my $pi_cfg = $sig ? PublicInbox::Config->new : $self->{pi_cfg};
38 my $groups = $pi_cfg->{-by_newsgroup}; # filled during each_inbox
39 my $cache = eval { $pi_cfg->ALL->misc->nntpd_cache_load } // {};
40 $pi_cfg->each_inbox(sub {
42 my $ngname = $ibx->{newsgroup} // return;
43 my $ce = $cache->{$ngname};
44 if (($ce and (%$ibx = (%$ibx, %$ce))) || $ibx->nntp_usable) {
45 # only valid if msgmap and over works
46 # preload to avoid fragmentation:
50 delete $groups->{$ngname};
51 delete $ibx->{newsgroup};
52 # Note: don't be tempted to delete more for memory
53 # savings just yet: NNTP, IMAP, and WWW may all
54 # run in the same process someday.
57 $self->{groupnames} = [ sort(keys %$groups) ];
58 # this will destroy old groups that got deleted
59 $self->{pi_cfg} = $pi_cfg;
63 $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_cfg});