This commit is contained in:
Quentin 2019-05-15 09:38:02 +02:00
parent ff1b94e3ef
commit 2b989f15d8

View file

@ -200,10 +200,11 @@ co_error:
}
int algo_rr_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
struct rr_ctx* rr = app_ctx->misc;
struct evt_core_fdinfo *to_fdinfo = NULL;
char url[255];
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
struct rr_ctx* rr = app_ctx->misc;
struct evt_core_fdinfo *to_fdinfo = NULL;
uint16_t min_pkt;
char url[255];
// 1. Prepare RR state and packet values
struct timespec curr;
@ -225,9 +226,18 @@ int algo_rr_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo
// 3. Prepare fresh packet
assert(bp->ip.ap.fmt.headers.cmd == CMD_CLEAR);
bp->ip.ap.fmt.content.clear.id = rr->sent_content_id;
min_pkt = rr->sent_content_id;
rr->sent_content_id++;
// 4. Create health packet
// 4. Append redundancy if needed
if (app_ctx->ap.redundant_data == 1) {
min_pkt = rr->prev_packet.ap.fmt.content.clear.id;
append_buffer(&bp->ip.ap, bp->ap_count, &rr->prev_packet.ap); // We append previous packet
append_buffer(&rr->prev_packet.ap, 0, &bp->ip.ap); // We store current packet for next time
bp->ap_count++;
}
// 5. Append health packet
struct buffer_packet hp;
hp.ip.ap.fmt.headers.cmd = CMD_HEALTH;
hp.ip.ap.fmt.headers.size = sizeof(bp->ip.ap.fmt.headers) + sizeof(bp->ip.ap.fmt.content.health);
@ -235,24 +245,12 @@ int algo_rr_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo
hp.ip.ap.fmt.content.health.deltat = mili_sec;
hp.ip.ap.fmt.content.health.prevlink = rr->current_link;
hp.ip.ap.fmt.content.health.bitfield = rr->remote_links;
hp.ip.ap.fmt.content.health.min_blocked_pkt = min_pkt;
rr->sent_health_id++;
// 5. Append redundancy if needed
if (app_ctx->ap.redundant_data == 1) {
assert(ring_gt(bp->ip.ap.fmt.content.health.min_blocked_pkt, rr->prev_packet.ap.fmt.content.clear.id));
bp->ip.ap.fmt.content.health.min_blocked_pkt = rr->prev_packet.ap.fmt.content.clear.id;
append_buffer(&bp->ip.ap, bp->ap_count, &rr->prev_packet.ap); // We append previous packet
append_buffer(&rr->prev_packet.ap, 0, &bp->ip.ap); // We store current packet for next time
bp->ap_count++;
}
// 6. Add health to buffer
append_buffer(&bp->ip.ap, bp->ap_count, &hp.ip.ap);
bp->ap_count++;
//printf("Will send packet id=%d\n", bp->ip.ap.str.id);
// 7. Try to find someone to send it
// 6. Try to find someone to send it
int max = 16;
uint8_t sel_link = rr->current_link;
while(max-- >= 0) {