🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #43841

Re: need source a/o algorithm for freenix 'inpaths' path stats program, for use with DIABLO

#43841
From: William H
Date: Wed, 02 Feb 2000 00:00
189 lines
5615 bytes
In article <38982884$1@news.cwnet.com>, "Erik Schorr" says...
> What I'd like to do, is write a program that listens on a local socket
> (ie port 1019/tcp, bound only to the localhost address), for diablo to
> send a header-only feed to.  This program will keep tallies on Path:
> elements, as the article headers are fed into it, instead of having to
> read through existing spool files occasionally.  This should save a LOT
> of disk usage.  Unfortunately, I'm missing the algorithm that the original
> inpaths program used to tally up the path elements.  Someone told me the
> value of each element is weighted, depending on its position in the Path:
> header, so I can't just increment a value of an associative array using
> the path element as the key.  The old (1980's/early 90's) inpaths.c source
> is convoluted to the point where the way it weights by position in the
> path line isn't apparent.  In addition, the program doesn't compile
> cleanly without modifications.


I have a set of programs that works sort of like that. It has two parts: 
The first part runs out of inetd and accepts a header feed from diablo, 
storing the paths in gzipped files. I run it on the 5 minute queue 
schedule on another lightly loaded box so that it doesn't affect the news 
server's performance. The second part runs once monthly, piping the 
previously stored files into the standard inpaths program. You will have 
to set the server name values to settings appropriate for your server.


#!/usr/bin/perl

# Receive a diablo header feed on stdin and parse out the Path: headers 
# for later processing by inpaths. For use as a daemon run out of inetd.
#
# v0.1  1999/10/17   William Herrin    herrin@crosslink.net

setpriority PRIO_PROCESS, $$, 20;

$| = 1;

$now = time();
$pathdir = "/home/herrin/src/usenet/paths";
$localpath = "nntp.newsfirst.net";

open PATH, "|/bin/gzip --stdout - >>$pathdir/$now.$$.gz";

print STDOUT "200 shade.corp.crosslink.net News server InPathFeed 0.1 
ready\r\n";

while ($line = <STDIN>) {

  $line =~ s/[\r\n]//g;
  $command = $line;
  $command =~ s/ .*$//;
  lc $command;
  $line =~ s/^[^ ]* //;

  if ($command eq "takethis") {
    article($line);
    print "239 article transferred ok $line\r\n";
    next;
  }
  if ($command eq "check") {
    print "238 no such article found, please send it to me $line\r\n";
    next;
  }
  if (($command eq "mode")&&($line eq "headfeed")) {
    print "250 Mode Command OK.\r\n";
    next;
  }
  if (($command eq "mode")&&($line eq "stream")) {
    print "203 StreamOK.\r\n";
    next;
  }
  if ($command eq "quit") {
    print "205 See ya later.\r\n";
    close HEADERS;
    exit 0;
  }
  print "500 Syntax Error: $command\r\n";
}

close HEADERS;
exit 0;

sub article {
  my ($msgid) = @_;
  my $line;

  while ($line = <STDIN>) {
    $line =~ s/[\r\n]//g;
    return if $line eq ".";

    $header = $line;
    $header =~ s/ .*$//;
    lc $header;
    $line =~ s/^[^ ]* //;

    if ($header eq "Path:") {
      $line =~ s/$localpath!//;

      print PATH "$line\n";
    }
  }
  
}


The second part is a simple shell script:

#!/bin/sh

DIR="${1}"

if [ "${DIR}" = "" ] ;then
  DIR="paths"
fi

nice -20 zcat ${DIR}/* | sed '
	s/^/Path: shade.corp.crosslink.net!nntp.newsfirst.net!/
	' | nice -20 inpaths/inpaths -p shade.corp.crosslink.net \
	> inpaths.${DIR}




And, since I'm posting happy fun usenet scripts, here's a short hack that 
compiles an eight month Freenix history:

#!/usr/bin/perl

@files = ( "199912-top1000.txt", "199911-top1000.txt", 
"199910-top1000.txt", 
"199909-top1000.txt", "199908-top1000.txt", "199907-top1000.txt", 
"199906-top1000.txt", "199905-top1000.txt");

$fn = $files[0];

open F, "<$fn";

$count = 1;
$line=<F>;
$line=<F>;
@servers = ();
%ranks = ();
while ($line = <F>) {
  chop $line;
  $line =~ s/  */ /g;
  $line =~ s/^ //;

  ($rank, $percent, $server) = split / /, $line;
  $servers[$count] = sprintf "%-31s%5d", $server, $rank;
  $ranks{"$server"} = $count;
  $count ++;
}
close F;


for ($count=1; $count<=$#files; $count++) {
  @month=();
  open F, "<$files[$count]";
  while ($line = <F>) {
    chop $line;
    $line =~ s/  */ /g;
    $line =~ s/^ //;

    ($rank, $percent, $server) = split / /, $line;
    $whichone = $ranks{$server};
    $month[$whichone] = sprintf "%5d", $rank if $whichone;
  }
  close F;
  for ($i=1; $i<=$#servers; $i++) {
    if ($month[$i]) {
      $servers[$i] .= " " . $month[$i];
    } else {
      $servers[$i] .= "     -";
    }
  }
}

print "Server                      1999 Dec   Nov   Oct   Sep   Aug   Jul   
Jun   May\n";
print "------------------------------+-----------------------------------
------------\n";

for ($i=1; $i<=$#servers; $i++) {
  print "$servers[$i]\n";
}


-Bill Herrin

Technical Details
Message-ID: <MPG.13026d0c5f0c837d98969e@dingus.crosslink.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <38982884$1@news.cwnet.com>

Show Full Headers
Complete Article Headers
Message-ID: <MPG.13026d0c5f0c837d98969e@dingus.crosslink.net>
Subject: Re: need source a/o algorithm for freenix 'inpaths' path stats program, for use with DIABLO
Date: Wed, 02 Feb 2000 00:00:00 +0000
From: herrin@crosslink.net (William H)
References: <38982884$1@news.cwnet.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 580973195
X-Trace: dingus.crosslink.net 949527138 20580 207.199.154.10
Organization: CrossLink Internet Services
Newsgroups: news.software.nntp