Skip to content

Commit

Permalink
fix hangup
Browse files Browse the repository at this point in the history
  • Loading branch information
yingyingcui.scholarzhang committed Apr 9, 2010
1 parent 226da20 commit c3d4a6d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 53 deletions.
22 changes: 13 additions & 9 deletions keywords/dstmaintain.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inline void type1_lift(struct idle_t *const hsub, int p) {

if (p > 1) {
int n = p >> 1;
if ( (hsub + p)->time - (hsub + n)->time > 0 )
if ( (hsub + p)->time - (hsub + n)->time >= 0 )
return;
memcpy(&orig, hsub + p, sizeof(struct idle_t));
do {
Expand Down Expand Up @@ -100,7 +100,7 @@ inline void type2_lift(struct idle_t *const hsub, int p) {

if (p > 1) {
int n = p >> 1;
if ( (hsub - p)->time - (hsub - n)->time > 0 )
if ( (hsub - p)->time - (hsub - n)->time >= 0 )
return;
memcpy(&orig, hsub - p, sizeof(struct idle_t));
do {
Expand Down Expand Up @@ -318,7 +318,7 @@ inline void fill_dstlist_without_maintain_heap(struct dstlist *const list,
newdst->used = 0;
newdst->dport = j;
newdst->type = (HK_TYPE1 | HK_TYPE2);

idle = list->idle_type1 + list->count_type1;
idle->dst = newdst;
idle->time = inittime;
Expand All @@ -327,10 +327,10 @@ inline void fill_dstlist_without_maintain_heap(struct dstlist *const list,
idle->dst = newdst;
idle->time = inittime;
++list->count_type2;

newdst->pos_type1 = list->count_type1;
newdst->pos_type2 = list->count_type2;

if (--nn == 0)
goto out;
}
Expand Down Expand Up @@ -405,8 +405,10 @@ inline struct dstinfo *get_type1(struct dstlist *const list) {
usleep(1000 * (time % 1000));
}
type1_delmin( idle, &list->count_type1 );
(list->idle_type2 - (idle->dst->pos_type2 - 1))->time += DAY_NS;
type2_sink( list->idle_type2 + 1, idle->dst->pos_type2, list->count_type2 );
if (idle->dst->type & HK_TYPE2) {
(list->idle_type2 - (idle->dst->pos_type2 - 1))->time += DAY_NS;
type2_sink( list->idle_type2 + 1, idle->dst->pos_type2, list->count_type2 );
}

return idle->dst;
}
Expand All @@ -422,8 +424,10 @@ inline struct dstinfo *get_type2(struct dstlist *const list) {
usleep(1000 * (time % 1000));
}
type2_delmin( idle, &list->count_type2 );
(list->idle_type1 + (idle->dst->pos_type1 - 1))->time += DAY_NS;
type1_sink( list->idle_type1 - 1, idle->dst->pos_type1, list->count_type1 );
if (idle->dst->type & HK_TYPE1) {
(list->idle_type1 + (idle->dst->pos_type1 - 1))->time += DAY_NS;
type1_sink( list->idle_type1 - 1, idle->dst->pos_type1, list->count_type1 );
}

return idle->dst;
}
2 changes: 1 addition & 1 deletion keywords/gfwkeyword_us.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
i eth0 seg 1300 kps 250 dstlist 203.208.37.0-203.208.37.255:1024-65535 e 500
i eth0 seg 1300 kps 250 dstlist 203.208.37.0-203.208.37.255:1024-65535 e 500 w 100
80 changes: 42 additions & 38 deletions keywords/return_dst.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,32 @@ static inline void return_type1(struct dstlist *const list, struct dstinfo *cons
type1_insert(list->idle_type1, available, dst, &list->count_type1);
}

if ((status & STATUS_TYPE2) == 0) {
if (status & STATUS_CHECK) {
// should remove dst from GFW type2 dstlist
type2_delete(list->idle_type2, dst->pos_type2 - 1,
&list->count_type2);
dst->type &= HK_TYPE1;
++list->removed_type2;
supply_type2(list);
if (dst->type & HK_TYPE2) {
if ((status & STATUS_TYPE2) == 0) {
if (status & STATUS_CHECK) {
// should remove dst from GFW type2 dstlist
type2_delete(list->idle_type2, dst->pos_type2 - 1,
&list->count_type2);
dst->type &= HK_TYPE1;
++list->removed_type2;
supply_type2(list);
}
else {
/* it's either not hit or not usable, so that
we recover its available time */
(list->idle_type2 - (dst->pos_type2 - 1))->time -= DAY_NS;
type2_lift(list->idle_type2 + 1, dst->pos_type2);
}
}
else {
/* it's either not hit or not usable, so that
we recover its available time */
(list->idle_type2 - (dst->pos_type2 - 1))->time -= DAY_NS;
// GFW type2 is hit
long available = gettime() + GFW_TIMEOUT - expire_timeout;
(list->idle_type2 - (dst->pos_type2 - 1))->time = available;
type2_lift(list->idle_type2 + 1, dst->pos_type2);
/* since after get_type1, the available time of type2
is add by one day, so here it is _lift not _sink */
}
}
else {
// GFW type2 is hit
long available = gettime() + GFW_TIMEOUT - expire_timeout;
(list->idle_type2 - (dst->pos_type2 - 1))->time = available;
type2_lift(list->idle_type2 + 1, dst->pos_type2);
/* since after get_type1, the available time of type2
is add by one day, so here it is _lift not _sink */
}

if (dst->type == 0)
dstlist_delete(list, dst);
Expand All @@ -56,30 +58,32 @@ static inline void return_type2(struct dstlist *const list, struct dstinfo *cons
type2_insert(list->idle_type2, available, dst, &list->count_type2);
}

if ((status & STATUS_TYPE1) == 0) {
if (status & STATUS_CHECK) {
// should remove dst from GFW type1 dstlist
type1_delete(list->idle_type1, dst->pos_type1 - 1,
&list->count_type1);
dst->type &= HK_TYPE2;
++list->removed_type1;
supply_type1(list);
if (dst->type & HK_TYPE1) {
if ((status & STATUS_TYPE1) == 0) {
if (status & STATUS_CHECK) {
// should remove dst from GFW type1 dstlist
type1_delete(list->idle_type1, dst->pos_type1 - 1,
&list->count_type1);
dst->type &= HK_TYPE2;
++list->removed_type1;
supply_type1(list);
}
else {
/* it's either not hit or not usable, so that
we recover its available time */
(list->idle_type1 + (dst->pos_type1 - 1))->time -= DAY_NS;
type1_lift(list->idle_type1 - 1, dst->pos_type1);
}
}
else {
/* it's either not hit or not usable, so that
we recover its available time */
(list->idle_type1 + (dst->pos_type1 - 1))->time -= DAY_NS;
// GFW type1 is hit
long available = gettime() + GFW_TIMEOUT - expire_timeout;
(list->idle_type1 + (dst->pos_type1 - 1))->time = available;
type1_lift(list->idle_type1 - 1, dst->pos_type1);
/* since after get_type2, the available time of type1
is add by one day, so here it is _lift not _sink */
}
}
else {
// GFW type1 is hit
long available = gettime() + GFW_TIMEOUT - expire_timeout;
(list->idle_type1 + (dst->pos_type1 - 1))->time = available;
type1_lift(list->idle_type1 - 1, dst->pos_type1);
/* since after get_type2, the available time of type1
is add by one day, so here it is _lift not _sink */
}

if (dst->type == 0)
dstlist_delete(list, dst);
Expand Down
8 changes: 3 additions & 5 deletions keywords/url_keywords.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,14 @@ int main(int argc, char *argv[]) {
gk_cm_config(control_wait, times, time_interval, expire_timeout, tcp_mss, kps, pps);
}
else {
if (line[0] == 'q')
break;
offset = 2;
offset = 1;
if (line[0] == 'm')
if (line[1] == 's') {
offset = 3;
offset = 2;
local_mode = 2;
}
else
local_mode = 3;
local_mode = 2;
else if (line[0] == 's')
local_mode = 1;
else {
Expand Down

0 comments on commit c3d4a6d

Please sign in to comment.