rwh@aesat.UUCP (Russell Herman) (04/03/84)
...___> .\" %M% %I% %E% .TH UNETpaths 8 .SH NAME UNETpaths - derive routes to USENET sites .SH SYNOPSIS UNETpaths [-o result] [-c cut_script] [-d basedir] -t .SH DESCRIPTION This script generates reasonably short (but not optimally short) paths from your site to other sites on USENET. It does this by examining the paths taken by those messages which have been received by your site. .PP Options are .TP .B \-o This is the file that receives the results (default NETPATHS). The paths in it are merged with those derived from the current net traffic, thus providing a cumulative store of information. The syntax of each entry is .ce 1 <dest_node> <path> Entries may be added manually to this file if desired. The first time this shell is executed, it is recommended that this file be initialized to contain entries for all your possible 1-hops if you are a relay, or 2-hops if you are a leaf. Obviously, since this is a primitive learning program, the more initial information given, the better the results are likely to be. .TP .B \-c This file is used when links or entire nodes are deleted from the network. It is, in fact an .IR awk (1) script. Two lines compose each cut_script entry. To delete the path A!B, include the entries .nf /A!B!/{next} /A!B$/{next} .fi To delete node A, use .nf /!A!/{next} /!A$/{next} .fi The last line of the script must be .nf {print $0} .fi The default is not to use a cut script. Notice that when a net change occurs, it is not sufficient to apply the relevant cuts for only one .I UNETpaths invocation. Until every item containing that path has been removed by the expiry cleanup function, that path will be rederived. A period of a couple months should probably allowed for the life of each cut script entry. .TP .B \-d This restricts examination of messages to a subdirectory of /usr/spool/new/net. E.g, "-d jokes/d" would look only at "net.jokes.d" for routes. Normally, the entire contents of /usr/spool/new/net is examined. .TP .B \-t This flag indicates test mode. Numerous scratch files are built in /tmp; in test mode, they will not be removed on completion. .SH FILES /etc/UNET/UNET.thishost - your site id .SH SEE ALSO .SH AUTHOR Russ Herman (aesat!rwh) .SH DIAGNOSTICS self-explanatory .SH BUGS None known. .SH CHANGES Initial Release ------------------------------------------------------------------------------ basedir=/usr/spool/news/net oldpath=NETPATHS mysite=`cat /etc/UNET/UNET.thishost` cuts= tst=n t=/tmp/$$? ta=/tmp/$$a tb=/tmp/$$b tc=/tmp/$$c td=/tmp/$$d te=/tmp/$$e ty=/tmp/$$y tz=/tmp/$$z while test -n "$1" do case $1 in -c) shift; cuts=$1;; -d) shift; basedir=/usr/spool/news/net/$1;; -o) shift; oldpath=$1;; -t) tst=y;; *) echo Usage: netpaths [-d searchdir] [-o result] [-c cut.awkin] [-t] 1>&2; exit 1;; esac shift done if test -d $basedir; then : else echo netpaths: $basedir not directory 1>&2; exit 1 fi if test -f $oldpath; then : merge the existing derived paths with the new sed -e "s/ / !$mysite!/" $oldpath >$te else touch $te fi cat >$ta <<! BEGIN{FS="!";k=2} {if (NF < k+1) next for (j=k; j<NF; j++) { printf "%s ", \$j printf "!$mysite" for (i=k; i<=j; i++) printf "!%s",\$i printf "\n" } } ! : collect raw data from net traffic find $basedir -type f -exec awk "/^Path: $mysite!/{print \$0; exit}" {} \;|sort -u -o $tz : the next stage generates one copy of every extant path, then : minhops selects the one with the shortest number of hops to each destination case :$cuts:$tst in ::n) awk -f $ta $tz|cat $te -|sort -u |minhops >$tb;; :*:n) awk -f $ta $tz|cat $te -|awk -f $cuts -|sort -u |minhops >$tb;; ::y) awk -f $ta $tz|cat $te -|sort -u -o $ty minhops <$ty >$tb;; :*:y) awk -f $ta $tz|cat $te -|awk -f $cuts -|sort -u -o $ty minhops <$ty >$tb;; esac : apply the minimum hop list to itself to shorten further sort +2nr -3 $tb|awk "{printf \"/!$mysite!.*!%s/s//%s/\n\",\$1,\$2}" >$tc : sed blows up when the pattern script is too long, so split it up split -50 $tc $tc list=`ls $tc??` for i in $list do sed -f $i $tb >$td mv $td $tb done rm -f $tc?? : end of sed kludge awk "{print \$1 \" \" \$2}" $tb|sed -e "s/ !$mysite!/ /" >$oldpath if test "$tst" = "n"; then rm /tmp/$$? fi ------------------------------------------------------------------------------- /*$title minhops.c*/ /*M************************************************************************** **************************************************************************** Program name: minhops.c File name: minhops.c Version: 1.3 Date: 84/03/29 11:04:55 Author: R. Herman (aesat!rwh) Function: Used in the netpaths procedure. Takes a sorted list of records of the format <dest> <path> and outputs, for each <dest>, the record with the path containing the fewest hops in the format <dest> <path> <hop-count> **************************************************************************** ****************************************************************************/ static char sccs_id[] = {"@(#)minhops.c 1.3 84/03/29"}; #include <stdio.h> struct rec { int hopcnt; char dest[17]; char path [513]; } s[2]; int base = 0; /*$sttl main*/ main() { int eofsw; char c, *pathp; /* prime the input buffer */ if (scanf("%s %s", &s[1].dest[0], &s[1].path[0]) == EOF) exit(0); else { s[1].hopcnt = 0; pathp = &s[1].path[0]; while (c= *pathp++) if (c == '!') s[1].hopcnt++; } /* here to process next record */ while (EOF != scanf("%s %s", &s[base].dest[0], &s[base].path[0])) { pathp = &s[base].path[0]; s[base].hopcnt = 0; while (c= *pathp++) if (c == '!') s[base].hopcnt++; if (strcmp(&s[base].dest[0], &s[1-base].dest[0])) { printf("%s %s %d\n", &s[1-base].dest[0], &s[1-base].path[0], s[1-base].hopcnt); base = 1 - base; } else if (s[base].hopcnt < s[1-base].hopcnt) base = 1 - base; } printf("%s %s %d\n", &s[1-base].dest[0], &s[1-base].path[0], s[1-base].hopcnt); exit(0); } -- ______ / \ Russ Herman @( [1;5m? ?[0m )@ 416-821-9190 ( || ) {allegra,ihnp4,linus,decvax}!utzoo!aesat!rwh ( [5m\[m__[5m/[m ) AES Data Inc. \____/ Mississauga, Ont. CANADA