🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #14843

Re: Needed: Beginner's guide to writing newsreader

#14843
From: Thomas 'Mike' Michlmayr
Date: Fri, 07 Feb 1997 00:00
369 lines
20509 bytes
[ posted and emailed ]

According to Lindsay McCann <lindsay@interlog.com>:
> I would like to explore the creation of a personal newsreader for
> Win95.  I am in need of advice as to how such a project could be
> undertaken.  I am a Win95 programmer with little NNTP knowledge.  I
> have read a couple of FAQ's, but the concentration is heavily on UNIX.

i appened a document written by tom limoncelli, which you should read in
any case before starting to write a newsreader.

-mike


Read This Before You Write a Newsreader, News Transport System, etc.
--------------------------------------------------------------------
                By Tom Limoncelli

Version 1.2. Updated 1994-11-23

This document is not a FAQ.  A FAQ implies that someone asked questions
and someone else answered said questions.  That's not what this
document is about.  This document is written because of all the people
that didn't ask, or didn't know to ask, and got in trouble because of
it.  People constantly post to the net that they are writing some kind
of software and in the process of asking other questions they reveal
that they are doing something else that is, well, stupid.  This
document attempts to point out common stupid mistakes so that you can
avoid them.  Wow!  How amazingly useful!  Isn't that nice of Tom?
Well, actually it's a sad statement on the understanding of netnews
technology that makes these stupid mistakes are common.  Very common.
Common enough to make this document useful.  So, this is not a FAQ,
this is a warning.

Point #1:
"I think I'll write a newsreader!"
Stop.  Stop right there.  I have a suggestion that will save you a lot
of time:  Go to a movie.  Rent a video.  Volunteer with a local
first-aid squad.  Feed the homeless.  Make a God damn sandwich, walk
onto the street and when you see a homeless person say, "HERE!"
Just do anything other than write a newsreader.  There are enough
already.  We should have started neutering newsreader authors a long
time ago.

"...but I'm going to write one that does something nobody has done before!"
Yeah, right.  Before you say that, learn all the features of nn, trn,
strn, gnus, and tin.  Now tell me you've thought of something new.  Can
you add this new feature to one of the old newsreaders?  Yes you can.
Plus, you'll save a million sysadmins grief when they have to go and
install yet another newsreader and figure out how to build it.  It's
much easier to install a updated version of an old newsreader.

"...well I could, but I really want to make my system stand-alone".
Then go stand alone in a corner until you've changed your mind.  If you
don't, you'll spend all of your time writing silly parts like user
interfaces, figuring out your command structure, getting it to compile
on every kind of Unix in the world, etc.  Heck, you'll waste most of
your time just writing the install script.  Really!  Just add your
feature to some other newsreader.  All the boring parts are written
for you.

For example, a scoring system for articles could be the basis for an
entire newsreader.  However, by adding this feature to trn (creating
strn), the author was able to build an entire newsreader with all those
great trn features, but concentrate on what he considered "fun" (i.e.
the scoring system).

Here's another example:  TMNN was an attempt to make an entirely new
netnews system where things would be a lot more hypertext'ish.  Rather
than just add these brilliant ideas to a newsreader (or to C News and
modify a newsreader to take advantage of the new data), the author
tried to re-invent the entire newstransport.  The project was never
completed.  I'm sure the author didn't get to spend much time on that
part that really interested him either.

Point #2:
If you are writing a newsreader or transport from scratch, here's what
I think the areas of interesting research would be:

Wait a second, you aren't sure what's a transport and what's a
newsreader?  Well, that's a sure sign that you shouldn't be writing
this software just yet.  Much of the work of writing any software that
interacts with netnews can be avoided if you KNOW THE CURRENT
TECHNOLOGY FIRST.  Read all the RFC's (822, 977, 1036), install C News
or INN once or twice.  Install tin, trn, nn, and readnews.  Read the
O'Reilly book.  If anything, read the 2 Usenix papers about C News
(same place you'll find the C News code), Rich's Usenix paper on INN
(stored where INN is stored), and Kurt Lidl's paper on Muse
(distributing netnews via MBONE multicast)
ftp::/ftp.uu.net/networking/news/muse/usenix-muse.ps.gz).  Heck,
they're just plain good reading for anyone that writes software.

Point #2.5:
If you are writing news software (transport or reader) for a non-Unix
system then it's still important to have experience with the Unix
systems that area available.  In fact, considering the horrible I/O
systems on most Intel-based computers you have 2x the reason to have
studied the Unix transports because they have optimized the amount of
I/O to a minimum.  If you are writing a newsreader you have 10x the
reason to learn a number of Unix newsreaders.  There is over 100 years
of combined software engineering experience in those readers.  Where
else do you have the opportunity to learn from that much experience?
Maybe while writing accounting software but who would want to do that?
Also, PC news posting agents are NOTORIOUS for not following the RFCs
and making the mistakes listed here.  So, go slowly, read the
resources, do your homework, get lots of advice, and then go for it.

Point #3:
If you are writing a newsreader or transport from scratch, here's what
I think the areas of interesting research would be:

Advanced user interfaces -- I don't mean Athena Widgets vs. MOTIF vs.
OpenWindows, etc.  All those damn GUI-based newsreaders add ABSOLUTELY
nothing to the state of the art... except maybe permitting the
mouse-generation to access the technically elite Usenet (which, being a
"More Power To The People"-kind-of-guy, I feel this is a good thing).
However, I think an advanced UI is something that reads news for you.
Read the Usenix papers on RightPages or Ferret.  Or, how about
something that lets me post articles in a way that lets me communicate
better (for some definition of "better").  Something that
cross-references articles in a way that is more useful than currently
available.

Disconnected Mode -- Every pissant BBS user uses QWK and has all sorts
of fancy QWK newsreaders.  Nobody has invented something as nice as
this for netnews.  On the other hand, QWK *SUCKS*.  Boy does it suck!
It is the embodiment of BAD SOFTWARE DESIGN.  It is the best example of
everything wrong with the way PC software authors create systems.  Why
not take the idea of QWK (but not the bad implementation) and apply it
to netnews and you've on your way to fame.

Better posting -- Wanna be famous?  Make a seriously amazing MIME
posting tool.  You could be responsible for the next explosion of
netnews bandwith as everyone uses your MIME authoring tool to make
mega-byte posts full of text, sounds, and graphics.  Or, make a
idiot-proof, GUI-based, bullet-proof posting system that doesn't lock
you into just the standard headers.  Want real fame?  Separate the
posting mechanism from the newsreader.  Define an interface between
newsreaders and newsposters and then make a couple newsposters.  Try to
get every newsreader to add support to your newsposter.  Then we'll
hear things like, "I use trn with FreshPost" and "Oh, I use trn too but
I use MagicPost, it has better MIME capabilities".  Fame and fortune
await you!

New storage systems -- Everyone talks about storing netnews in a
compressed form, as a database, as a flat-file, on a special "newsfs"
filesystem, etc.  etc.  Nobody actually implements it.  What's stopping
you?  How about a storage system that makes expires happen blindingly
fast?  How about a storage system that makes reading the "next article"
a fast operation (note: the next article is not numerically next if you
are using a threaded newsreader).  INN has hooks for these kinds of
things and all INN utilities uses these hooks.  Make the change once in
the right place and all (most) INN code supports it.  Time after time
people have suggested using an SQL database to store articles, the
history file, the kill file, the X-Files, etc.  Why not actually
implement it?

HypertextNews -- Why store quoted text?  Why not just store a code
which specifies the quoted article and which lines?  Newsreaders that
support it could let you click on the quoted text and view the lines
specified, the whole article, or whatever!  Make a system that is also
backwards compatible or figure out how to expire such a news
database and you'll win the nobel prize!

There are plenty of ideas where those came from.  Please don't just
write yet another newsreader

Point #4:
Never re-invent the wheel.  Why write a text editor when you can just
call $EDITOR?  (Unless your amazing new feature is a better editor...
in which case you shouldn't be writing a newsreader, you should be
writing something that all newsreaders could be calling as $EDITOR.

Why get bogged down writting tons of NNTP code when you can link to a
pre-written client library?  NNTP-t5 and INN both generate pre-written
client libraries that anyone can link to and they do all the work for
you.  Best of all, they are similar enough that you can write your code
so that it works when linked to either.  It would be nice if someone
wrote a library with all the same calls that read everything off the
disk instead of via NNTP.  Then you could link a NNTP-based newsreader
to this library and turn it into a non-NNTP-based newsreader.  Why not
write a new library that checks a flag and reads news via either NNTP,
the file system, on a special compressed system, or by smoke signals.


Point #5:
                          THINGS TO DO OR NOT TO DO:
                          --------------------------

DO USE "MODE READER": When you talk to an NNTP port, the first thing
you should do is send the command "mode reader".  Pay attention to the
error messages.  "500" means "I don't know that command" (proceed as
normal), "200" means "good".  Anything else and you don't want to talk
to this server.

DO USE A PRE-WRITTEN DATABASE: Don't use your own database, use NOV.
Link to the NOV library so you don't have to implement any of it.  It
does all the work for you.  Kill your sysadmin if they want to install
tin's database,  trn's database, nn's database, etc. (unless you get
your hard disks for free).

POSTING: DON'T VALIDATE HEADERS: When the user wants to post an
article, give them an editor with the minimum headers and accept
whatever you get back.  If any changes were made, send everything
verbatim to "inews -h".  "inews"'s job is to validate the headers,
insert missing ones, silently delete certain ones, etc.  Don't try to
do all this work in the newsreader.  Sysadmins often hack their inews
to add some special feature... don't undo their work or require them to
re-add this hack to every newsreader they install!  (The NNTP POST
command is the same as piping to "inews -h" except you must include a
"From:" header).

POSTING: DON'T WORK TOO HARD #1: The "inews -h" command requires only
two valid headers:  "Subject:" and "Newsgroups:".  Don't send it
anything else (unless the user inserts it him/her self).  For example,
why figure out how to format the date properly?  The format is very
specific and if you get it wrong, the transport silently drops the
article.  Why try at all when you know that "inews -h" generates a
perfect one for you?  Also, if the user inserts a "Reply-To: foo@bar",
let them.  Don't try to validate it, if they put in a non-functioning
address it's not your job to care.

POSTING:  DON'T WORK TOO HARD #2: The NNTP "POST" command requires only
3 valid headers:  "Subject:", "Newsgroups:", and "From:".  It will
generate the rest if they are left out.  Don't do the work yourself.

POSTING:  DON'T GENERATE A PATH HEADER:  Don't generate a Path: header.
With networks changing so often, it is impossible to generate
one that is correct for all sites.  Let "inews" or NNTP's "POST"
command generate it for you.  They will generate it properly
because they were installed (and maybe modified) by someone that
understands the site's special configuration.  The person that installs
the newsreader is often someone different, and is often installed by
joe loser that thinks netnews was invented 3 months ago when he
first discovered alt.sex.

POSTING:  MORE HEADERS NOT TO GENERATE:  When generating a post's
headers, don't insert the Date: header, munge the Sender:, From:
header, etc.  That is inews's job.  "inews"'s only purpose in life is
to take the crap that the user input, add the missing required headers,
check and fix obvious errors, and reject what it can't fix.  inews will
send it to the spool or post it via NNTP.  Why does everyone think they
can out-do inews by doing the work themselves?

NNTP POSTING: DON'T USE IHAVE:  Use the NNTP "POST" command, not the
NNTP "IHAVE" command.  If you use NNTP's "ihave" command then you have
done about a week duplicating all the work that inews (or NNTP's "POST"
command) does, wasted another week of programming time to get
everything "just right"... and when someone installs their software on
an INN server, they'll find that it doesn't work.  Duuuh!

WHEN YOUR USER IS IDLE, DON'T GENERATE TRAFFIC:  If your user isn't
typing, mouse'ing, clicking, etc. your newsreader shouldn't be
generating work for the server.  Imagine 5,000 users all leaving your
program running when they leave for lunch.  EXCEPTION: If you are
implementing some fancy read-ahead model, but then you shouldn't be
reading too far ahead if the user seems to have walked away from their
terminal, eh?

IF YOU LOSE YOUR CONNECTION, HANDLE IT TRANSPARENTLY:  Write your code
so that if your NNTP connection closes you handle it gracefully.  You
shouldn't go into an infinite loop, or spin in a "open->error->open"
loop chewing up CPU time.  If you can't re-open the server, tell
the user but don't core-dump.

WHEN YOUR CONNECTION IS CLOSED, RECONNECT GRACEFULLY:  Write your
code so that you reconnect without the user being warned a zillion
times.  Maybe put "Reconnecting to server" in a status line, but
don't require the user to click on "OK".  Give the user the feeling
that they always have a connection, even when they are talking to
a server that disconnects after 30 seconds of idle time.

WHEN YOUR CONNECTION IS CLOSED, DON'T RECONNECT UNTIL YOU HAVE TO:  If
your connection closed it was for a good reason.  Either you closed it
because your user was idle, or the server closed it because it felt
your user was idle, or maybe the server went down.  Don't reconnect
until you need to issue your next NNTP command.  Example: If a server
has 400 connections when it reboots, you don't want 400 clients all
pummeling it with packets trying to start new connections while it is
trying to come up.  Plus, when the service is operational again, only
those connections that are actively used should be reconnecting
anyway.  If you delay reconnecting until the user needs it, the load on
the server will be smoothed out since everyone won't be connecting at
the same time.

WHEN YOUR USER IS IDLE FOR A LONG TIME, DISCONNECT:  If your user is idle
for more than 5 minutes, why not close the NNTP connection?  If you
followed the above advice, the reconnect will be seemless and the
users will not notice.

WHEN YOUR CLIENT IS IDLE FOR A LONG TIME, DISCONNECT:  NNTP servers should
disconnect if a connection hasn't seen traffic for 5-10 minutes.
Let the newsadmin set this time limit, and let them disable
this feature if they need to.  In a perfect world, all newsreaders
disconnect after 5 minutes of idle time, all servers will disconnect
after 5 minutes of idle time, and all re-connects will be transparent
to the user.  However, since we don't live in a perfect world, we
have to do our best to do our share.

DISCONNECT EVERY 4 HOURS:  Whether idle or or not, disconnect from the
server every 4 hours.  This lets any file handle leaks on the server
get flushed out.  If you followed the above advice about reconnecting,
your users won't notice.

DON'T DISCONNECT BETWEEN EVERY COMMAND:  I don't want to embarrass
anyone but the authors of NETSCAPE MOSAIC go around claiming that the
reason their Mosaic is so much better is that it has (ta DAAA!) a
built-in netnews reader!  Guess what folks?  It closes the connection
after *every* *single* *article*.  You can just hear the system
performance DIE as your kernel locks out everything trying to fork()
fast enough to keep up with the NetScape users.

DON'T GENERATE VANITY HEADERS:  Don't include a header that identifies
what newsreader the user is using.  Son-of-RFC1036 explicitly states
that this is A Bad Thing.  If you haven't seen this header before it
basically looks like: "X-Newsreader: this was posted by a user that
uses FooReader v33.1 which is the software that I wrote and I put this
header in because I'm boring and immature and think that I can make
myself famous by adding this header when it really just shows how
shallow I am."  Well, you're not completely shallow, but you should
watch out for the neutering patrol (see Point #1 above).

EDUCATE YOURSELF:  Reading RFC1036 and RFC977 in one sitting in a quiet
library was the best investment I ever made.  Read RFC822 too, but it
might put you to sleep so read it in bed.  You learn all sorts of
requirements you may not have known of and they explain many issues.
They also tell you certain things that were tried one way but failed,
and why it is standard not to do such things.

TIPS WHEN REPLYING AND DOING A FOLLOWUP-POST:  Don't reply to the
Path: header.  The Path: header is just informational as far as you
are concerned, unless you are a news transport (C News or INN).
Don't ignore the "Reply-To:" header when doing a reply, and don't
invent some data-structure that will prevent you from using the
Reply-To: header.  FIDO sites have a From: but no Reply-To: field.
So, FIDO gateway software just drops the Reply-To: header *OR*
promotes the Reply-To: header to replace the From: header "so that
replies work right".  Well, Mr. Snoop-FIDO-Dog, first of all, to be
gramatically correct it's "work correctly".  Secondly, you've just
broken the spec.  There are other pairs of headers that work like
this.  For example, Followup-To:/Newsgroups: is similar to
Reply-To:/From:.  However, don't forget to implement the RFC1036
requirement that "Followup-To: poster" (yes, the string p-o-s-t-e-r)
means that if the user tries to do a Followup, do a Reply instead.
If this happens, don't forget to check for the existence of a
Reply-To: header!

DON'T CONFUSE THE HEADER AND THE BODY:  Between the header and the body
of an article is one blank line.  It doesn't have anything on it.  No
spaces, no tabs, no nothing.  After that blank line, don't fuss with
what you find.  I've seen FIDO software that finds headers inside the
body and treats them like real headers.  For example, such broken
software would find 3 "headers" in the above paragraph ("TIPS WHEN
REPLYING...") and try to process them.

(to be continued...)

-- 
        Tom Limoncelli -- tal@plts.org (home) -- tal@big.att.com (work)

                   "I just *LOVE* scanning for life forms!"

-- 
Thomas 'Mike' Michlmayr can not assert the truth of all statements in 
this article and still be consistent. <mike@cosy.sbg.ac.at>


Technical Details
Message-ID: <5dfmrl$2ts@esel.cosy.sbg.ac.at>
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: <32f4dc1a.4136343@news.interlog.com>

Show Full Headers
Complete Article Headers
Message-ID: <5dfmrl$2ts@esel.cosy.sbg.ac.at>
Subject: Re: Needed: Beginner's guide to writing newsreader
Date: Fri, 07 Feb 1997 00:00:00 +0000
From: mike@cosy.sbg.ac.at (Thomas 'Mike' Michlmayr)
References: <32f4dc1a.4136343@news.interlog.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: 215104441
Organization: Usenet Ground Control
Newsgroups: news.software.nntp