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