/[pkg-mixmaster]/trunk/Mix/Src/stats.c
ViewVC logotype

Diff of /trunk/Mix/Src/stats.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 107 by weaselp, Thu Jul 25 11:52:26 2002 UTC revision 500 by weaselp, Sat May 3 05:31:07 2003 UTC
# Line 6  Line 6 
6     details.     details.
7    
8     Remailer statistics     Remailer statistics
9     $Id: stats.c,v 1.6 2002/07/25 11:52:26 weaselp Exp $ */     $Id: stats.c,v 1.19 2003/05/03 05:31:07 weaselp Exp $ */
10    
11    
12  #include "mix3.h"  #include "mix3.h"
# Line 37  int stats_out(int pool) Line 37  int stats_out(int pool)
37  {  {
38    FILE *f;    FILE *f;
39    
40      if (REMAIL == 0)
41        return (0); /* don't keep statistics for the client */
42    
43    f = mix_openfile(STATS, "a");    f = mix_openfile(STATS, "a");
44    if (f == NULL) {    if (f == NULL) {
45      errlog(ERRORMSG, "Can't open %s!\n", STATS);      errlog(ERRORMSG, "Can't open %s!\n", STATS);
# Line 56  int stats(BUFFER *b) Line 59  int stats(BUFFER *b)
59    long now, today, then;    long now, today, then;
60    time_t t;    time_t t;
61    long updated = 0, havestats = 0;    long updated = 0, havestats = 0;
62    int msgd[3][24], msg[3][80];    int msgd[7][24], msg[7][80];
63      /* 0 .. Unencrypted
64       * 1 .. Type I PGP
65       * 2 .. Mix
66       *
67       * 3 .. intermediate
68       * 4 .. final hop mail
69       * 5 .. final hop news
70       * 6 .. randhopped (will get counted in intermediate again)
71       */
72    int poold[2][24], pool[2][80];    int poold[2][24], pool[2][80];
73    int i, num, type;    int i, num, type, assigned, daysum;
74      char c;
75    idlog_t idbuf;    idlog_t idbuf;
76    
77    now = (time(NULL) / (60 * 60) + 1) * 60 * 60;    now = (time(NULL) / (60 * 60) + 1) * 60 * 60;
78    today = (now / SECONDSPERDAY) * SECONDSPERDAY;    today = (now / SECONDSPERDAY) * SECONDSPERDAY;
79    
80    for (i = 0; i < 24; i++)    for (i = 0; i < 24; i++)
81      msgd[0][i] = msgd[1][i] = msgd[2][i] = poold[0][i] = poold[1][i] = 0;      msgd[0][i] = msgd[1][i] = msgd[2][i] = msgd[3][i] = msgd[4][i] = msgd[5][i] = msgd[6][i]= poold[0][i] = poold[1][i] = 0;
82    for (i = 0; i < 80; i++)    for (i = 0; i < 80; i++)
83      msg[0][i] = msg[1][i] = msg[2][i] = pool[0][i] = pool[1][i] = 0;      msg[0][i] = msg[1][i] = msg[2][i] = msg[3][i] = msg[4][i] = msg[5][i] = msg[6][i] = pool[0][i] = pool[1][i] = 0;
84    
85    s = mix_openfile(STATS, "r");    s = mix_openfile(STATS, "r");
86    if (s != NULL) {    if (s != NULL) {
# Line 78  int stats(BUFFER *b) Line 91  int stats(BUFFER *b)
91        case '0':        case '0':
92        case '1':        case '1':
93        case '2':        case '2':
94          sscanf(line, "%d %d %ld", &type, &num, &then);        case '3':
95          if (now - then < 0)        case '4':
96          case '5':
97          case '6':
98            c = '\0';
99            assigned = sscanf(line, "%d %d %ld %c", &type, &num, &then, &c);
100            daysum = (assigned == 4 && c == 'd');
101    
102            if (now - then < 0 || (daysum && today - then < 0))
103            break;                /* keep memory consistent even if the time            break;                /* keep memory consistent even if the time
104                                     suddenly goes backwards :) */                                     suddenly goes backwards :) */
105          if (now - then < SECONDSPERDAY)          if (now - then < SECONDSPERDAY && !daysum)
106            msgd[type][(now - then) / (60 * 60)] += num;            msgd[type][(now - then) / (60 * 60)] += num;
107          else if (today - then < 80 * SECONDSPERDAY)          else if (today - then < 80 * SECONDSPERDAY)
108            msg[type][(today - then) / SECONDSPERDAY] += num;            msg[type][(today - then) / SECONDSPERDAY] += num;
# Line 90  int stats(BUFFER *b) Line 110  int stats(BUFFER *b)
110            havestats = then;            havestats = then;
111          break;          break;
112        case 'p':        case 'p':
113          sscanf(line, "p %d %d %ld", &num, &i, &then);          c = '\0';
114          if (now - then < 0)          assigned = sscanf(line, "p %d %d %ld %c", &num, &i, &then, &c);
115            daysum = (assigned == 4 && c == 'd');
116    
117            if (now - then < 0 || (daysum && today - then < 0))
118            break;            break;
119          if (now - then < SECONDSPERDAY) {          if (now - then < SECONDSPERDAY && !daysum) {
120            poold[0][(now - then) / (60 * 60)] += num;            poold[0][(now - then) / (60 * 60)] += num;
121            poold[1][(now - then) / (60 * 60)] += i;            poold[1][(now - then) / (60 * 60)] += i;
122          } else if (today - then < 80 * SECONDSPERDAY) {          } else if (today - then < 80 * SECONDSPERDAY) {
# Line 136  int stats(BUFFER *b) Line 159  int stats(BUFFER *b)
159    lock(s);    lock(s);
160    fprintf(s, "%ld\n", (long) time(NULL));       /* time of stats.log update */    fprintf(s, "%ld\n", (long) time(NULL));       /* time of stats.log update */
161    for (i = 0; i < 24; i++) {    for (i = 0; i < 24; i++) {
162      for (type = 0; type < 3; type++)      for (type = 0; type < 7; type++)
163        if (msgd[type][i] > 0)        if (msgd[type][i] > 0)
164          fprintf(s, "%d %d %ld\n", type, msgd[type][i], now - i * 60 * 60);          fprintf(s, "%d %d %ld\n", type, msgd[type][i], now - i * 60 * 60);
165      if (poold[0][i] > 0)      if (poold[0][i] > 0)
166        fprintf(s, "p %d %d %ld\n", poold[0][i], poold[1][i], now - i * 60 * 60);        fprintf(s, "p %d %d %ld\n", poold[0][i], poold[1][i], now - i * 60 * 60);
167    }    }
168    for (i = 0; i < 80; i++) {    for (i = 0; i < 80; i++) {
169      for (type = 0; type < 3; type++)      for (type = 0; type < 7; type++)
170        if (msg[type][i] > 0)        if (msg[type][i] > 0)
171          fprintf(s, "%d %d %ld\n", type, msg[type][i],          fprintf(s, "%d %d %ld d\n", type, msg[type][i],
172                  today - i * 24 * 60 * 60);                  today - i * 24 * 60 * 60);
173      if (pool[0][i] > 0)      if (pool[0][i] > 0)
174        fprintf(s, "p %d %d %ld\n", pool[0][i], pool[1][i],        fprintf(s, "p %d %d %ld d\n", pool[0][i], pool[1][i],
175                today - i * 24 * 60 * 60);                today - i * 24 * 60 * 60);
176    }    }
177    unlock(s);    unlock(s);
# Line 179  int stats(BUFFER *b) Line 202  int stats(BUFFER *b)
202  #if 0  #if 0
203        else        else
204          buf_appends(b, "  [ no remailing ]");          buf_appends(b, "  [ no remailing ]");
205  #endif  #endif /* 0 */
206        buf_nl(b);        buf_nl(b);
207      }      }
208      if ((today - havestats) / SECONDSPERDAY >= 1)      if ((today - havestats) / SECONDSPERDAY >= 1)
# Line 202  int stats(BUFFER *b) Line 225  int stats(BUFFER *b)
225          buf_appendf(b, "     Unencrypted:%4d", msg[0][i]);          buf_appendf(b, "     Unencrypted:%4d", msg[0][i]);
226        if (pool[0][i] > 0)        if (pool[0][i] > 0)
227          buf_appendf(b, "  [Pool size:%4d]", pool[1][i] / pool[0][i]);          buf_appendf(b, "  [Pool size:%4d]", pool[1][i] / pool[0][i]);
228          if (STATSDETAILS) {
229            buf_appendf(b, "  Intermediate:%4d", msg[3][i]);
230            buf_appendf(b, "  Mail:%4d", msg[4][i]);
231            buf_appendf(b, "  Postings:%4d", msg[5][i]);
232            if (MIDDLEMAN)
233              buf_appendf(b, "  Randhopped:%4d", msg[6][i]);
234          }
235  #if 0  #if 0
236        else        else
237          buf_appends(b, "  [ no remailing ]");          buf_appends(b, "  [ no remailing ]");
238  #endif  #endif /* 0 */
239        buf_nl(b);        buf_nl(b);
240      }      }
241    }    }
# Line 217  int conf(BUFFER *out) Line 247  int conf(BUFFER *out)
247    FILE *f;    FILE *f;
248    BUFFER *b, *line;    BUFFER *b, *line;
249    int flag = 0;    int flag = 0;
250      REMAILER remailer[MAXREM];
251      int pgpkeyid[MAXREM];
252      int i, num;
253      char tmpline[LINELEN];
254    
255    b = buf_new();    b = buf_new();
256    line = buf_new();    line = buf_new();
257    
# Line 242  int conf(BUFFER *out) Line 277  int conf(BUFFER *out)
277    if (SIZELIMIT)    if (SIZELIMIT)
278      buf_appendf(out, "Maximum message size: %d kB\n", SIZELIMIT);      buf_appendf(out, "Maximum message size: %d kB\n", SIZELIMIT);
279    
280    /* read in dest.alw if middleman (added by Kat 11/19/2001) */    /* display destinations to which delivery is explicitly permitted
281         when in middleman mode (contents of DESTALLOW file.)  */
282    
283    if (MIDDLEMAN) {    if (MIDDLEMAN) {
284      f = mix_openfile(DESTALLOW, "r");      f = mix_openfile(DESTALLOW, "r");
285      if (f != NULL) {      if (f != NULL) {
286        buf_read(b, f);        buf_read(b, f);
287        fclose(f);        fclose(f);
288        while(buf_getline(b, line) != -1) {        while(buf_getline(b, line) != -1) {
289          if (line->length > 0 && line->data[0] != '#') {          if (line->length > 0 && line->data[0] != '#') {
290            if (flag == 0) {            if (flag == 0) {
291              buf_appends(out, "In addition to other remailers, this mixmaster also sends mail to these\n addresses directly:\n");              buf_appends(out, "In addition to other remailers, this remailer also sends mail to these\n addresses directly:\n");
292              flag = 1;              flag = 1;
293            }            }
294            buf_appendf(out, "   %b\n", line);            buf_appendf(out, "   %b\n", line);
295          }          }
296        }        }
       buf_nl(out);  
297      }      }
298    }    }
299    
# Line 272  int conf(BUFFER *out) Line 308  int conf(BUFFER *out)
308            buf_appends(out, "The following header lines will be filtered:\n");            buf_appends(out, "The following header lines will be filtered:\n");
309            flag = 1;            flag = 1;
310          }          }
311          buf_appends(out, "   ");          buf_appends(out, "   ");
312          if (line->length > 3 && streq(line->data + line->length - 2, "/q")) {          if (line->length > 3 && streq(line->data + line->length - 2, "/q")) {
313            buf_append(out, line->data, line->length - 1);            buf_append(out, line->data, line->length - 1);
314            buf_appends(out, " => delete message");            buf_appends(out, " => delete message");
# Line 305  int conf(BUFFER *out) Line 341  int conf(BUFFER *out)
341    
342    buf_nl(out);    buf_nl(out);
343    conf_premail(out);    conf_premail(out);
344    
345      if (LISTSUPPORTED) {
346       /* SUPPORTED CPUNK (TYPE I) REMAILERS
347        * 0xDC7532F9        "Heex Remailer <remailer@xmailer.ods.org>"
348        * 0x759ED311        "znar <ka5tkn@cox-internet.com>"
349        *
350        * SUPPORTED MIXMASTER (TYPE II) REMAILERS
351        * aarg remailer@aarg.net 475f3f9fe8da22896c10082695a92c2d 2.9b33 C
352        * anon mixmaster@anon.978.org 7384ba1eec585bfd7d2b0e9b307f0b1d 2.9b36 MCNm
353        */
354    
355        buf_nl(out);
356        if (PGP) {
357          buf_appends(out, "SUPPORTED CPUNK (TYPE I) REMAILERS\n");
358          num = t1_rlist(remailer, NULL);
359          pgp_rkeylist(remailer, pgpkeyid, num);
360          for (i=1; i<=num; i++) {
361            if (remailer[i].flags.pgp) {
362              snprintf(tmpline, LINELEN, "0x%08X    \"%s <%s>\"\n", pgpkeyid[i], remailer[i].name, remailer[i].addr);
363              tmpline[LINELEN-1] = '\0';
364              buf_appends(out, tmpline);
365            }
366          }
367          buf_nl(out);
368        }
369        if (MIX) {
370          buf_appends(out, "SUPPORTED MIXMASTER (TYPE II) REMAILERS\n");
371          prepare_type2list(out);
372          buf_nl(out);
373        }
374      }
375    
376    
377    if ( b ) buf_free(b);    if ( b ) buf_free(b);
378    buf_free(line);    buf_free(line);
379    return (0);    return (0);
# Line 318  void conf_premail(BUFFER *out) Line 387  void conf_premail(BUFFER *out)
387    buf_appends(out, REMAILERADDR);    buf_appends(out, REMAILERADDR);
388    buf_appendc(out, '>');    buf_appendc(out, '>');
389    if (PGP || UNENCRYPTED)    if (PGP || UNENCRYPTED)
390      buf_appends(out, " cpunk");      buf_appends(out, " cpunk max");
391    if (MIX)    if (MIX)
392      buf_appends(out, " mix");      buf_appends(out, " mix");
393    if (MIDDLEMAN)    if (MIDDLEMAN)
# Line 342  void conf_premail(BUFFER *out) Line 411  void conf_premail(BUFFER *out)
411    if (PGP) {    if (PGP) {
412  #ifdef USE_IDEA  #ifdef USE_IDEA
413      buf_appends(out, " ek");      buf_appends(out, " ek");
414  #endif  #endif /* USE_IDEA */
415      buf_appends(out, " ekx");      buf_appends(out, " ekx");
416    }    }
417  #ifdef USE_IDEA  #ifdef USE_IDEA
418    buf_appends(out, " esub");    buf_appends(out, " esub");
419  #endif  #endif /* USE_IDEA */
420  #if 0                           /* obsolete */  #if 0                           /* obsolete */
421  #ifdef USE_NSUB  #ifdef USE_NSUB
422    buf_appends(out, " nsub");    buf_appends(out, " nsub");
423  #else  #else /* end of USE_NSUB */
424    buf_appends(out, " ksub");    buf_appends(out, " ksub");
425  #endif  #endif /* else if not USE_NSUB */
426  #endif  #endif /* 0 */
427    if (INFLATEMAX)    if (INFLATEMAX)
428      buf_appendf(out, " inflt%d", INFLATEMAX);      buf_appendf(out, " inflt%d", INFLATEMAX);
429    if (MAXRANDHOPS)    if (MAXRANDHOPS)

Legend:
Removed from v.107  
changed lines
  Added in v.500

  ViewVC Help
Powered by ViewVC 1.1.5