Better code
This commit is contained in:
parent
4643aa7a42
commit
5bfc545f23
1 changed files with 11 additions and 4 deletions
|
@ -25,6 +25,7 @@ struct pkt_reconstruct {
|
|||
enum pkt_reconstruct_res r;
|
||||
int diff_0;
|
||||
int diff_1;
|
||||
struct buffer_packet single[2][MAX_PKTS_TO_CHECK_FOR_DROP];
|
||||
};
|
||||
|
||||
struct pkt_stats {
|
||||
|
@ -60,6 +61,12 @@ void update_stats(struct buffer_packet *bp, GHashTable* stat_elem) {
|
|||
ps->cumulated_size += bp->ip.ap.fmt.headers.size;
|
||||
}
|
||||
|
||||
void unroll_packets(struct cap_file cf[], struct buffer_packet bpread[], GHashTable* stats[], struct pkt_reconstruct *pr, int m, int i) {
|
||||
cap_next_bp (&cf[i], &bpread[i]);
|
||||
update_stats(&bpread[i], stats[i]);
|
||||
memcpy(&pr->single[i][m], &bpread[i], sizeof(struct buffer_packet));
|
||||
}
|
||||
|
||||
void reconstruct_action(struct cap_file cf[], struct pkt_reconstruct* pr, GHashTable *stats[]) {
|
||||
struct buffer_packet bpread[2];
|
||||
pr->r = PREC_FAIL;
|
||||
|
@ -71,8 +78,8 @@ void reconstruct_action(struct cap_file cf[], struct pkt_reconstruct* pr, GHashT
|
|||
pr->r = m1 == 0 && m2 == 0 ? PREC_SAME : PREC_DROP;
|
||||
pr->diff_0 = m1;
|
||||
pr->diff_1 = m2;
|
||||
while (m1-- >= 0) { cap_next_bp (&cf[0], &bpread[0]); update_stats(&bpread[0], stats[0]); }
|
||||
while (m2-- >= 0) { cap_next_bp (&cf[1], &bpread[1]); update_stats(&bpread[1], stats[1]); }
|
||||
for (int m = m1; m >= 0; m--) unroll_packets (cf, bpread, stats, pr, m, 0);
|
||||
for (int m = m2; m >= 0; m--) unroll_packets (cf, bpread, stats, pr, m, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -82,8 +89,8 @@ void reconstruct_action(struct cap_file cf[], struct pkt_reconstruct* pr, GHashT
|
|||
pr->r = PREC_DROP;
|
||||
pr->diff_0 = m2;
|
||||
pr->diff_1 = m1;
|
||||
while (m2-- >= 0) { cap_next_bp (&cf[0], &bpread[0]); update_stats(&bpread[0], stats[0]); }
|
||||
while (m1-- >= 0) { cap_next_bp (&cf[1], &bpread[1]); update_stats(&bpread[1], stats[1]); }
|
||||
for (int m = m2; m >= 0; m--) unroll_packets (cf, bpread, stats, pr, m, 0);
|
||||
for (int m = m1; m >= 0; m--) unroll_packets (cf, bpread, stats, pr, m, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue