Commit 6997599f authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Account request resending in ms.

parent 787dd794
...@@ -513,7 +513,7 @@ send_request_resend(const unsigned char *prefix, unsigned char plen, ...@@ -513,7 +513,7 @@ send_request_resend(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash) unsigned short seqno, unsigned short router_hash)
{ {
send_request(NULL, prefix, plen, 127, seqno, router_hash); send_request(NULL, prefix, plen, 127, seqno, router_hash);
record_request(prefix, plen, seqno, router_hash, NULL, 2); record_request(prefix, plen, seqno, router_hash, NULL, 2000);
} }
static void static void
......
...@@ -82,9 +82,12 @@ record_request(const unsigned char *prefix, unsigned char plen, ...@@ -82,9 +82,12 @@ record_request(const unsigned char *prefix, unsigned char plen,
request->resend = MIN(request->resend, resend); request->resend = MIN(request->resend, resend);
else if(resend) else if(resend)
request->resend = resend; request->resend = resend;
request->time = now.tv_sec; request->time = now;
timeval_min_sec(&request_resend_time, if(request->resend) {
request->time + request->resend); struct timeval timeout;
timeval_plus_msec(&timeout, &request->time, request->resend);
timeval_min(&request_resend_time, &timeout);
}
if(request->router_hash == router_hash && if(request->router_hash == router_hash &&
seqno_compare(request->seqno, seqno) > 0) { seqno_compare(request->seqno, seqno) > 0) {
return 0; return 0;
...@@ -104,10 +107,13 @@ record_request(const unsigned char *prefix, unsigned char plen, ...@@ -104,10 +107,13 @@ record_request(const unsigned char *prefix, unsigned char plen,
request->seqno = seqno; request->seqno = seqno;
request->router_hash = router_hash; request->router_hash = router_hash;
request->network = network; request->network = network;
request->time = now.tv_sec; request->time = now;
request->resend = resend; request->resend = resend;
if(resend) if(request->resend) {
timeval_min_sec(&request_resend_time, now.tv_sec + resend); struct timeval timeout;
timeval_plus_msec(&timeout, &request->time, request->resend);
timeval_min(&request_resend_time, &timeout);
}
request->next = recorded_requests; request->next = recorded_requests;
recorded_requests = request; recorded_requests = request;
return 1; return 1;
...@@ -168,7 +174,7 @@ expire_requests() ...@@ -168,7 +174,7 @@ expire_requests()
previous = NULL; previous = NULL;
request = recorded_requests; request = recorded_requests;
while(request) { while(request) {
if(request->time < now.tv_sec - REQUEST_TIMEOUT) { if(timeval_minus_msec(&now, &request->time) >= REQUEST_TIMEOUT) {
if(previous == NULL) { if(previous == NULL) {
recorded_requests = request->next; recorded_requests = request->next;
free(request); free(request);
...@@ -195,8 +201,11 @@ recompute_request_resend_time() ...@@ -195,8 +201,11 @@ recompute_request_resend_time()
request = recorded_requests; request = recorded_requests;
while(request) { while(request) {
if(request->resend) if(request->resend) {
timeval_min_sec(&resend, request->time + request->resend); struct timeval timeout;
timeval_plus_msec(&timeout, &request->time, request->resend);
timeval_min(&request_resend_time, &timeout);
}
request = request->next; request = request->next;
} }
...@@ -210,10 +219,14 @@ resend_requests() ...@@ -210,10 +219,14 @@ resend_requests()
request = recorded_requests; request = recorded_requests;
while(request) { while(request) {
if(request->resend && now.tv_sec >= request->time + request->resend) { if(request->resend) {
send_request(NULL, request->prefix, request->plen, 127, struct timeval timeout;
request->seqno, request->router_hash); timeval_plus_msec(&timeout, &request->time, request->resend);
request->resend = 2 * request->resend; if(timeval_compare(&now, &timeout) >= 0) {
send_request(NULL, request->prefix, request->plen, 127,
request->seqno, request->router_hash);
request->resend *= 2;
}
} }
request = request->next; request = request->next;
} }
......
...@@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#define REQUEST_TIMEOUT 128 #define REQUEST_TIMEOUT 125000
struct request { struct request {
unsigned char prefix[16]; unsigned char prefix[16];
...@@ -28,7 +28,7 @@ struct request { ...@@ -28,7 +28,7 @@ struct request {
unsigned short seqno; unsigned short seqno;
unsigned short router_hash; unsigned short router_hash;
struct network *network; struct network *network;
int time; struct timeval time;
int resend; int resend;
struct request *next; struct request *next;
}; };
......
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