chiark / gitweb /
use libinn logging where applicable - compiles
[inn-innduct.git] / innfeed / host.h
1 /*  $Id: host.h 7778 2008-04-17 21:27:22Z iulius $
2 **
3 **  The public interface to the Host class.
4 **
5 **  Written by James Brister <brister@vix.com>
6 **
7 **  The Host class represents the remote news system that we're feeding.  A
8 **  Host object has possibly multiple connections to the remote system which
9 **  it sends articles down.  It is given the articles by other objects
10 **  (typically the InnListener), and once taken it assumes all responsibility
11 **  for transmission or temporary storage on network failures etc.
12 */
13
14 #if ! defined ( host_h__ )
15 #define host_h__
16
17
18 #include <stdio.h>
19
20 #include "misc.h"
21
22 /*
23  * Functions from elsewhere used by host.c
24  */
25
26 extern void mainLogStatus (FILE *fp) ;
27
28
29 /*
30  * Functions used by the InnListener
31  */
32
33
34 /*
35  * Create a new Host object.
36  *
37  * NAME is the name that INN uses.
38  * IPNAME is the name the networking code uses (or the ascii dotted quad
39  *    IP address).
40  * ARTTIMEOUT is the max amount of time we'll wait for a new article
41  *    from INN before considering the connection unused and we'll close
42  *    down.
43  * RESPTIMEOUT is the max amount of time we'll wait for any reponse
44  *    from a remote. Past this we'll close down the network connection.
45  * INITIALCXNS is the number of Connections to create at Host creation time.
46  * MAXCXNS is the maximum number of parallel connections to the
47  *    remote host we can run at any one time.
48  * MAXCHECK is the maximum number of nntp CHECK commands to be outstanding
49  *    on a connection before opening up a new connection (or refusing
50  *    new articles if we get to MAXCXNS).
51  * PORTNUM is the port number on the remote host we should talk to.
52  * CLOSEPERIOD is the number of seconds after connecting that the
53  *     connections should be closed down and reinitialized (due to problems
54  *     with old NNTP servers that hold history files open. Value of 0 means
55  *     dont close down.
56  * STREAMING is a boolean flag to tell if the Host wants its Connections to
57  *     do streaming or not.
58  * LOWPASSHIGH is the high value for the low-pass filter.
59  * LOWPASSLOW is the low value for the low-pass filter.
60  */
61
62 void configHosts (bool talkSelf) ;
63
64 /* print some debugging info. */
65 void gPrintHostInfo (FILE *fp, unsigned int indentAmt) ;
66 void printHostInfo (Host host, FILE *fp, unsigned int indentAmt) ;
67
68 /* Delete the host object. Drops all the active connections immediately
69    (i.e. no QUIT) . */
70 void delHost (Host host) ;
71
72 /* Get a new default host object */
73 Host newDefaultHost (InnListener listener,
74                      const char *name); 
75
76 /* gently close down all the host's connections (issue QUITs). */
77 void hostClose (Host host) ;
78
79 /* gently close down all active connections (issue QUITs) and recreate
80    them immediately */
81 void hostFlush (Host host) ;
82
83 /* have the HOST transmit the ARTICLE, or, failing that, store article
84    information for later attempts. */
85 void hostSendArticle (Host host, Article article) ;
86
87 /* return an IP address for the host */
88 struct sockaddr *hostIpAddr (Host host, int family) ;
89
90 /* Delete all IPv4 addresses from the address list */
91 void hostDeleteIpv4Addr (Host host);
92
93 /* mark the current IP address as failed and rotate to the next one */
94 void hostIpFailed (Host host) ;
95
96 /*
97  * Functions used by the Connection to indicate Connection state.
98  */
99
100 /* called by the Host's connection when the remote is refusing
101    postings. Code 400 in the banner */
102 void hostCxnBlocked (Host host, Connection cxn, char *reason) ;
103
104 /* called by the Connection when it has determined if the remote supports
105    the streaming extension or not. */
106 void hostRemoteStreams (Host host, Connection cxn, bool doesStream) ;
107
108 /* Called by the connection when it is no longer connected to the
109    remote. Perhaps due to getting a code 400 to an IHAVE. */
110 void hostCxnDead (Host host, Connection cxn) ;
111
112 /* Called when the Connection deletes itself */
113 bool hostCxnGone (Host host, Connection cxn) ;
114
115 /* Called when the Connection goes to sleep. */
116 void hostCxnSleeping (Host host, Connection cxn) ;
117
118 /* Called when the Connection starts waiting for articles. */
119 void hostCxnWaiting (Host host, Connection cxn) ;
120
121
122
123 /* Called when the connection has sent an IHAVE or a CHECK, or a TAKETHIS
124    when in no-check mode.*/
125 void hostArticleOffered (Host host, Connection cxn) ;
126
127 /* called by the Connection when the article was transferred. */
128 void hostArticleAccepted (Host host, Connection cxn, Article article) ;
129
130 /* Called by the connection when the remote answered 435 or 438 */
131 void hostArticleNotWanted (Host host, Connection cxn, Article article) ;
132
133 /* Called by the connection when the remote answered 437 or 439 */
134 void hostArticleRejected (Host host, Connection cxn, Article article) ;
135
136 /* Called when the connection when the remote answered 400 or 431 or 436 */
137 void hostArticleDeferred (Host host, Connection cxn, Article article) ;
138
139 /* Called by the connection if it discovers the file is gone. */
140 void hostArticleIsMissing (Host host, Connection cxn, Article article) ;
141
142
143 /* Called by the connection when it wants to defer articles, but it
144    doesn't want the Host to queue any news on it. */
145 void hostTakeBackArticle (Host host, Connection cxn, Article article) ;
146
147
148 /* called by the Connection when it is idle and wants to get things
149    moving. Returns true if there was something to do and the Host called
150    cxnQueueArticle() . */
151 bool hostGimmeArticle (Host host, Connection cxn) ;
152
153 /* get the name that INN uses for this host */
154 const char *hostPeerName (Host host) ;
155
156 /* get the bindaddress */
157 const struct sockaddr_in *hostBindAddr(Host host) ;
158 #ifdef HAVE_INET6
159 const struct sockaddr_in6 *hostBindAddr6(Host host) ;
160 int hostAddrFamily (Host host);
161 #endif
162
163 /* get the username and password for authentication */
164 const char *hostUsername (Host host) ;
165 const char *hostPassword (Host host) ;
166
167 /* if VAL is true then each time the host logs its stats all its
168    connections will too. */
169 void hostLogConnectionStats (bool val) ;
170 bool hostLogConnectionStatsP (void) ;
171
172 #if 0
173 /* Set the frequency (in seconds) with which we log statistics */
174 void hostSetStatsPeriod (unsigned int period) ;
175 #endif
176
177 /* return whether or not the Connections should attempt to stream. */
178 bool hostWantsStreaming (Host host) ;
179
180 /* return maxChecks */
181 unsigned int hostmaxChecks (Host host);
182
183 /* return if we should drop deferred articles */
184 bool hostDropDeferred (Host host);
185
186 /* return the maximum number of CHECKs that can be outstanding */
187 unsigned int hostMaxChecks (Host host) ;
188
189 /* Called by the Host's connections when they go into (true) or out of
190    (false) no-CHECK mode. */
191 void hostLogNoCheckMode (Host host, bool on, double low, double cur, double high) ;
192
193 /* calculate host backlog statistics */
194 void gCalcHostBlStat (void) ;
195
196 /* calculate host global statistics */
197 void gHostStats (void) ;
198
199 /* set the pathname of the file to use instead of innfeed.status */
200 void hostSetStatusFile (const char *filename) ;
201
202 /* function called when config file is loaded. */
203 int hostConfigLoadCbk (void *data) ;
204
205 void hostChkCxns(TimeoutId tid, void *data);
206
207 #endif /* host_h__ */