Commit 25573e36 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implemented resending of requests.

parent c519a4b9
......@@ -415,6 +415,8 @@ main(int argc, char **argv)
tv = check_neighbours_time;
timeval_min_sec(&tv, expiry_time);
if(request_resend_time)
timeval_min_sec(&tv, request_resend_time);
for(i = 0; i < numnets; i++) {
timeval_min(&tv, &nets[i].flush_time);
timeval_min_sec(&tv,
......@@ -517,6 +519,9 @@ main(int argc, char **argv)
}
}
if(now.tv_sec >= request_resend_time)
resend_requests();
if(update_flush_time.tv_sec != 0) {
if(now.tv_sec >= update_flush_time.tv_sec)
flushupdates();
......
......@@ -250,7 +250,7 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
send_unicast_request(route->nexthop, prefix, plen,
hop_count - 1, seqno, router_hash);
record_request(prefix, plen, seqno, router_hash,
neigh->network);
neigh->network, 0);
}
} else {
send_update(neigh->network, 1, prefix, plen);
......@@ -456,6 +456,14 @@ send_request(struct network *net,
send_message(net, 2, 0xFF, 0, 0, 0, ones);
}
void
send_request_resend(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash)
{
send_request(NULL, prefix, plen, 127, seqno, router_hash);
record_request(prefix, plen, seqno, router_hash, NULL, 2);
}
static void
send_unicast_packet(struct neighbour *neigh, unsigned char *buf, int buflen)
{
......
......@@ -45,6 +45,8 @@ void send_request(struct network *net,
const unsigned char *prefix, unsigned char plen,
unsigned char hop_count, unsigned short seqno,
unsigned short router_hash);
void send_request_resend(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash);
void send_unicast_request(struct neighbour *neigh,
const unsigned char *prefix, unsigned char plen,
unsigned char hop_count, unsigned short seqno,
......
......@@ -29,7 +29,9 @@ THE SOFTWARE.
#include "util.h"
#include "neighbour.h"
#include "request.h"
#include "message.h"
int request_resend_time = 0;
struct request *recorded_requests = NULL;
static int
......@@ -63,19 +65,25 @@ find_request(const unsigned char *prefix, unsigned char plen,
int
record_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash,
struct network *network)
struct network *network, int resend)
{
struct request *request;
request = find_request(prefix, plen, NULL);
if(request) {
if(request->resend && resend)
request->resend = MIN(request->resend, resend);
else if(resend)
request->resend = resend;
request->time = now.tv_sec;
request_resend_time = MIN(request_resend_time,
request->time + request->resend);
if(request->router_hash == router_hash &&
seqno_compare(request->seqno, seqno) > 0) {
return 0;
} else {
request->router_hash = router_hash;
request->seqno = seqno;
request->time = now.tv_sec;
if(request->network != network)
request->network = NULL;
return 1;
......@@ -88,8 +96,11 @@ record_request(const unsigned char *prefix, unsigned char plen,
request->plen = plen;
request->seqno = seqno;
request->router_hash = router_hash;
request->time = now.tv_sec;
request->network = network;
request->time = now.tv_sec;
request->resend = resend;
if(resend)
request_resend_time = MIN(request_resend_time, now.tv_sec + resend);
request->next = recorded_requests;
recorded_requests = request;
return 1;
......@@ -117,6 +128,7 @@ satisfy_request(const unsigned char *prefix, unsigned char plen,
else
previous->next = request->next;
free(request);
recompute_request_resend_time();
return 1;
}
......@@ -127,11 +139,12 @@ void
expire_requests()
{
struct request *request, *previous;
int recompute = 0;
previous = NULL;
request = recorded_requests;
while(request) {
if(request->time < now.tv_sec - 60) {
if(request->time < now.tv_sec - REQUEST_TIMEOUT) {
if(previous == NULL) {
recorded_requests = request->next;
free(request);
......@@ -146,5 +159,43 @@ expire_requests()
request = request->next;
}
}
if(recompute)
recompute_request_resend_time();
}
int
recompute_request_resend_time()
{
struct request *request;
int resend = 0;
request = recorded_requests;
while(request) {
if(request->resend) {
if(resend)
resend = MIN(resend, request->time + request->resend);
else
resend = request->time + request->resend;
}
request = request->next;
}
request_resend_time = resend;
return resend;
}
void
resend_requests()
{
struct request *request;
request = recorded_requests;
while(request) {
if(request->resend && now.tv_sec >= request->time + request->resend) {
send_request(NULL, request->prefix, request->plen, 127,
request->seqno, request->router_hash);
request->resend = 2 * request->resend;
}
request = request->next;
}
}
......@@ -20,6 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#define REQUEST_TIMEOUT 128
struct request {
unsigned char prefix[16];
unsigned char plen;
......@@ -27,18 +29,20 @@ struct request {
unsigned short router_hash;
struct network *network;
int time;
int resend;
struct request *next;
};
extern int request_resend_time;
struct request *find_request(const unsigned char *prefix, unsigned char plen,
struct request **previous_return);
int record_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash,
struct network *net);
struct network *net, int resend);
int satisfy_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash,
struct network *net);
void expire_requests(void);
int recompute_request_resend_time(void);
......@@ -462,10 +462,10 @@ send_triggered_update(struct route *route, struct source *oldsrc, int oldmetric)
if(oldmetric < INFINITY) {
if(newmetric >= INFINITY)
send_request(NULL, route->src->prefix, route->src->plen,
127,
send_request_resend(route->src->prefix, route->src->plen,
route->src->metric >= INFINITY ?
route->src->seqno : seqno_plus(route->src->seqno, 1),
route->src->seqno :
seqno_plus(route->src->seqno, 1),
hash_id(route->src->address));
else if(newmetric >= oldmetric + 384)
send_request(NULL, route->src->prefix, route->src->plen,
......@@ -512,7 +512,7 @@ route_lost(struct source *src, int oldmetric)
/* Complain loudly. */
send_update(NULL, 1, src->prefix, src->plen);
if(oldmetric < INFINITY)
send_request(NULL, src->prefix, src->plen, 127,
send_request_resend(src->prefix, src->plen,
src->metric >= INFINITY ?
src->seqno : seqno_plus(src->seqno, 1),
hash_id(src->address));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment