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

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

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

revision 499 by weaselp, Sat May 3 05:08:53 2003 UTC revision 500 by weaselp, Sat May 3 05:31:07 2003 UTC
# Line 6  Line 6 
6     details.     details.
7    
8     Prepare messages for remailer chain     Prepare messages for remailer chain
9     $Id: chain.c,v 1.7 2003/05/03 05:08:53 weaselp Exp $ */     $Id: chain.c,v 1.8 2003/05/03 05:31:07 weaselp Exp $ */
10    
11    
12  #include "mix3.h"  #include "mix3.h"
# Line 24  void clienterr(BUFFER *msgbuf, char *err Line 24  void clienterr(BUFFER *msgbuf, char *err
24      errlog(ERRORMSG, "%s\n", err);      errlog(ERRORMSG, "%s\n", err);
25  }  }
26    
27    void parse_badchains(int badchains[MAXREM][MAXREM], char *file, char *startindicator, REMAILER *remailer, int maxrem) {
28      int i,j;
29      FILE *list;
30      char line[LINELEN];
31    
32      if (!badchains)
33        return;
34    
35      for (i = 0; i < maxrem; i++ )
36        for (j = 0; j < maxrem; j++ )
37          badchains[i][j] = 0;
38      list = mix_openfile(TYPE2REL, "r");
39      if (list != NULL) {
40        while (fgets(line, sizeof(line), list) != NULL &&
41          !strleft(line, startindicator)) ;
42        while (fgets(line, sizeof(line), list) != NULL &&
43          strleft(line, "(")) {
44          char *left, *right, *tmp;
45          int lefti, righti;
46    
47          left = line + 1;
48          while (*left == ' ')
49            left ++;
50    
51          tmp = left + 1;
52          while (*tmp != ' ' && *tmp != '\0' && *tmp != ')')
53            tmp ++;
54          if (*tmp == '\0' || *tmp == ')')
55            /* parsing this line failed */
56            continue;
57          *tmp = '\0';
58    
59          right = tmp+1;
60          while (*right == ' ')
61            right ++;
62          tmp = right + 1;
63          while (*tmp != ' ' && *tmp != '\0' && *tmp != ')')
64            tmp ++;
65          if (*tmp == '\0')
66            /* parsing this line failed */
67            continue;
68          *tmp = '\0';
69    
70          lefti = -1;
71          righti = -1;
72          for (i = 1; i < maxrem; i++) {
73            if (strcmp(remailer[i].name, left) == 0)
74              lefti = i;
75            if (strcmp(remailer[i].name, right) == 0)
76              righti = i;
77          }
78          if (strcmp(left, "*") == 0)
79            lefti = 0;
80          if (strcmp(right, "*") == 0)
81            righti = 0;
82    
83          if (lefti == -1 || righti == -1)
84            /* we don't know about one or both remailers */
85            continue;
86          badchains[lefti][righti] = 1;
87        }
88      }
89      fclose(list);
90    }
91    
92    
93  int chain_select(int hop[], char *chainstr, int maxrem, REMAILER *remailer,  int chain_select(int hop[], char *chainstr, int maxrem, REMAILER *remailer,
94                   int type, BUFFER *feedback)                   int type, BUFFER *feedback)
95  {  {
# Line 102  end: Line 168  end:
168    return len;    return len;
169  }  }
170    
171  int chain_randfinal(int type, REMAILER *remailer, int maxrem, int rtype)  int chain_randfinal(int type, REMAILER *remailer, int badchains[MAXREM][MAXREM], int maxrem, int rtype, int secondtolasthop)
172  {  {
173    int num = 0;    int num = 0;
174    int i;    int i;
175    int t;    int t;
176      int select[MAXREM];
177    
178    t = rtype;    t = rtype;
179    if (rtype == 2)    if (rtype == 2)
# Line 114  int chain_randfinal(int type, REMAILER * Line 181  int chain_randfinal(int type, REMAILER *
181    
182    /* select a random final hop */    /* select a random final hop */
183    for (i = 1; i < maxrem; i++) {    for (i = 1; i < maxrem; i++) {
184      if (((remailer[i].flags.mix && rtype == 0) ||      select[i] =
185           ((remailer[i].flags.mix && rtype == 0) ||             /* remailer supports type */
186           (remailer[i].flags.pgp && remailer[i].flags.ek && rtype == 1) ||           (remailer[i].flags.pgp && remailer[i].flags.ek && rtype == 1) ||
187           (remailer[i].flags.newnym && rtype == 2)) &&           (remailer[i].flags.newnym && rtype == 2)) &&
188          remailer[i].info[t].reliability >= 100 * RELFINAL &&          remailer[i].info[t].reliability >= 100 * RELFINAL && /* remailer has sufficient reliability */
189          remailer[i].info[t].latency <= MAXLAT &&          remailer[i].info[t].latency <= MAXLAT &&             /* remailer has small enough latency */
190          (type == MSG_NULL || !remailer[i].flags.middle) &&          (type == MSG_NULL || !remailer[i].flags.middle) &&   /* remailer is not middleman */
191          !remailer[i].flags.star_ex &&          !remailer[i].flags.star_ex &&                        /* remailer is not excluded from random selection */
192          (remailer[i].flags.post || type != MSG_POST))          (remailer[i].flags.post || type != MSG_POST) &&      /* remailer supports post when this is a post */
193        num++;          ((secondtolasthop == -1) || !badchains[secondtolasthop][i]);/* we only have hop or the previous one can send to this (may be random) */
194        num += select[i];
195    }    }
196    if (num == 0)    if (num == 0)
197      i = -1;      i = -1;
198    else {    else {
199      do      do
200        i = rnd_number(maxrem - 1) + 1;        i = rnd_number(maxrem - 1) + 1;
201      while (!(((remailer[i].flags.mix && rtype == 0) ||      while (!select[i]);
               (remailer[i].flags.pgp && remailer[i].flags.ek && rtype == 1) ||  
               (remailer[i].flags.newnym && rtype == 2)) &&  
              remailer[i].info[t].reliability >= 100 * RELFINAL &&  
              remailer[i].info[t].latency <= MAXLAT &&  
              (type == MSG_NULL || !remailer[i].flags.middle) &&  
              !remailer[i].flags.star_ex &&  
              (remailer[i].flags.post || type != MSG_POST)));  
202    }    }
203    return (i);    return (i);
204  }  }
205    
206  int chain_rand(REMAILER *remailer, int maxrem,  int chain_rand(REMAILER *remailer, int badchains[MAXREM][MAXREM], int maxrem,
207                 int thischain[], int chainlen, int t)                 int thischain[], int chainlen, int t)
208       /* set random chain. returns 0 if not random, 1 if random, -1 on error */       /* set random chain. returns 0 if not random, 1 if random, -1 on error */
209    /* t... 0 for mixmaster Type II
210     *      1 for cypherpunk Type I
211     */
212  {  {
213    int hop;    int hop;
214    int err = 0;    int err = 0;
# Line 157  int chain_rand(REMAILER *remailer, int m Line 222  int chain_rand(REMAILER *remailer, int m
222        int i;        int i;
223    
224        err = 1;        err = 1;
225        for (i = 1; i < maxrem; i++)        if (hop > 0)
226          select[i] = ((remailer[i].flags.mix && t == 0) ||          assert(thischain[hop-1]); /* we already should have chosen a remailer after this one */
227          for (i = 1; i < maxrem; i++) {
228            select[i] = ((remailer[i].flags.mix && t == 0) ||        /* remailer supports type */
229                       (remailer[i].flags.pgp && remailer[i].flags.ek && t == 1))                       (remailer[i].flags.pgp && remailer[i].flags.ek && t == 1))
230            && remailer[i].info[t].reliability >= 100 * MINREL &&            && remailer[i].info[t].reliability >= 100 * MINREL &&  /* remailer has sufficient reliability */
231            !remailer[i].flags.star_ex &&            !remailer[i].flags.star_ex &&                          /* remailer is not excluded from random selection */
232            remailer[i].info[t].latency <= MAXLAT,            remailer[i].info[t].latency <= MAXLAT &&               /* remailer has small enough latency */
233            randavail += select[i];            !badchains[i][0] && !badchains[i][thischain[hop-1]] && /* remailer can send to the next one */
234              (hop == chainlen-1 || !badchains[thischain[hop+1]][i]);/* we are at the first hop or the previous one can send to this (may be random) */
235            randavail += select[i];
236          }
237    
238        for (i = hop - DISTANCE; i <= hop + DISTANCE; i++)        for (i = hop - DISTANCE; i <= hop + DISTANCE; i++)
239          if (i >= 0 && i < chainlen && select[thischain[i]])          if (i >= 0 && i < chainlen && select[thischain[i]]) {
240            select[thischain[i]] = 0, randavail--;            select[thischain[i]] = 0;
241              randavail--;
242            }
243    
244    
245        if (randavail < 1) {        if (randavail < 1) {
246          err = -1;          err = -1;
# Line 219  float chain_reliability(char *chain, int Line 292  float chain_reliability(char *chain, int
292    int maxrem;    int maxrem;
293    int i;    int i;
294    REMAILER remailer[MAXREM];    REMAILER remailer[MAXREM];
295      int badchains[MAXREM][MAXREM];
296    
297    /* chaintype 0=mix 1=ek 2=newnym */    /* chaintype 0=mix 1=ek 2=newnym */
298    assert((chaintype == 0) || (chaintype == 1));    assert((chaintype == 0) || (chaintype == 1));
299    maxrem = (chaintype == 0 ? mix2_rlist(remailer) : t1_rlist(remailer));    maxrem = (chaintype == 0 ? mix2_rlist(remailer, badchains) : t1_rlist(remailer, badchains));
300    
301    /* Dissect chain */    /* Dissect chain */
302    name_start = chain;    name_start = chain;

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

  ViewVC Help
Powered by ViewVC 1.1.5