1 # Copyright (C) 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;
12 use PublicInbox::NNTPdeflate; # loads PublicInbox::NNTP
16 my $pi_cfg = PublicInbox::Config->new;
17 my $name = $pi_cfg->{'publicinbox.nntpserver'};
18 if (!defined($name) or $name eq '') {
20 } elsif (ref($name) eq 'ARRAY') {
30 greet => \"201 $name ready - post via email\r\n",
31 # accept_tls => { SSL_server => 1, ..., SSL_reuse_ctx => ... }
32 # idler => PublicInbox::InboxIdle
37 my ($self, $sig) = @_;
38 my $pi_cfg = $sig ? PublicInbox::Config->new : $self->{pi_cfg};
39 my $groups = $pi_cfg->{-by_newsgroup}; # filled during each_inbox
40 my $cache = eval { $pi_cfg->ALL->misc->nntpd_cache_load } // {};
41 $pi_cfg->each_inbox(sub {
43 my $ngname = $ibx->{newsgroup} // return;
44 my $ce = $cache->{$ngname};
45 if (($ce and (%$ibx = (%$ibx, %$ce))) || $ibx->nntp_usable) {
46 # only valid if msgmap and over works
47 # preload to avoid fragmentation:
51 delete $groups->{$ngname};
52 delete $ibx->{newsgroup};
53 # Note: don't be tempted to delete more for memory
54 # savings just yet: NNTP, IMAP, and WWW may all
55 # run in the same process someday.
58 $self->{groupnames} = [ sort(keys %$groups) ];
59 # this will destroy old groups that got deleted
60 $self->{pi_cfg} = $pi_cfg;
64 $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_cfg});