2 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
5 # Standalone NNTP server for public-inbox.
8 require PublicInbox::Daemon;
9 require PublicInbox::NewsGroup;
10 require PublicInbox::NNTP;
11 require PublicInbox::Config;
12 my $nntpd = PublicInbox::NNTPD->new;
13 daemon_run('0.0.0.0:119',
14 sub { $nntpd->refresh_groups }, # refresh
15 sub ($$$) { PublicInbox::NNTP->new($_[0], $nntpd) }); # post_accept
18 package PublicInbox::NNTPD;
32 sub refresh_groups () {
34 my $pi_config = PublicInbox::Config->new;
37 foreach my $k (keys %$pi_config) {
38 $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
40 my $git_dir = $pi_config->{$k};
41 my $addr = $pi_config->{"publicinbox.$g.address"};
42 my $ngname = $pi_config->{"publicinbox.$g.newsgroup"};
43 if (defined $ngname) {
44 next if ($ngname eq ''); # disabled
47 my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $addr);
48 my $old_ng = $self->{groups}->{$g};
50 # Reuse the old one if possible since it can hold
51 # references to valid mm and gcf objects
57 # Only valid if msgmap and search works
63 @list = sort { $a->{name} cmp $b->{name} } @list;
64 $self->{grouplist} = \@list;
65 # this will destroy old groups that got deleted
66 %{$self->{groups}} = %$new;