annotate libfdcore/p_sr.c @ 1113:eb4ce68b6e5c

Added calls to remaining hooks
author Sebastien Decugis <sdecugis@freediameter.net>
date Mon, 13 May 2013 19:17:13 +0800
parents a731051d2e83
children 79dd22145f52
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
837
1d2721778c7a Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 824
diff changeset
5 * Copyright (c) 2012, WIDE Project and NICT *
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 650
diff changeset
36 #include "fdcore-internal.h"
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 /* Structure to store a sent request */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 struct sentreq {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 struct fd_list chain; /* the "o" field points directly to the hop-by-hop of the request (uint32_t *) */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 struct msg *req; /* A request that was sent and not yet answered. */
165
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
42 uint32_t prevhbh;/* The value to set in the hbh header when the message is retrieved */
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
43 struct fd_list expire; /* the list of expiring requests */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
44 struct timespec added_on; /* the time the request was added */
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 };
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
47 /* Find an element in the hbh list, or the following one */
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 static struct fd_list * find_or_next(struct fd_list * srlist, uint32_t hbh, int * match)
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49 {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 struct fd_list * li;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 *match = 0;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 for (li = srlist->next; li != srlist; li = li->next) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 uint32_t * nexthbh = li->o;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 if (*nexthbh < hbh)
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 continue;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 if (*nexthbh == hbh)
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 *match = 1;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 break;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 return li;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62
71
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
63 static void srl_dump(const char * text, struct fd_list * srlist)
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
64 {
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
65 struct fd_list * li;
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
66 struct timespec now;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
67
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
68 if (!TRACE_BOOL(ANNOYING))
73
02db4d794ccf Lower trace level
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 71
diff changeset
69 return;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
70
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 938
diff changeset
71 fd_log_debug("%sSentReq list @%p:", text, srlist);
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
72
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
73 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), );
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
74
71
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
75 for (li = srlist->next; li != srlist; li = li->next) {
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
76 struct sentreq * sr = (struct sentreq *)li;
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
77 uint32_t * nexthbh = li->o;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
78
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 938
diff changeset
79 fd_log_debug(" - Next req (hbh:%x): [since %ld.%06ld sec]", *nexthbh,
1052
b3d623f04b6d Fix a number of remaining compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
80 (long)((now.tv_nsec >= sr->added_on.tv_nsec) ? (now.tv_sec - sr->added_on.tv_sec) : (now.tv_sec - sr->added_on.tv_sec - 1)),
b3d623f04b6d Fix a number of remaining compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
81 (long)((now.tv_nsec >= sr->added_on.tv_nsec) ? ((now.tv_nsec - sr->added_on.tv_nsec) / 1000) : ((now.tv_nsec - sr->added_on.tv_nsec + 1000000000) / 1000)));
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
82
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
83 fd_msg_dump_one(ANNOYING + 1, sr->req);
71
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
84 }
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
85 }
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
86
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
87 struct expire_data {
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
88 struct msg * request;
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
89 struct fd_peer * sentto;
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
90 };
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
91
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
92 /* (detached) thread that calls the anscb on expired messages.
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
93 We do it in a separate thread to avoid blocking the reception of new messages during this time */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
94 static void * call_expirecb(void * arg) {
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
95 struct expire_data * ed = arg;
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
96
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
97 void (*expirecb)(void *, DiamId_t, size_t, struct msg **);
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
98 void * data;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
99
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
100 TRACE_ENTRY("%p", arg);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
101 CHECK_PARAMS_DO( arg, return NULL );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
102
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
103 /* Set the thread name */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
104 fd_log_threadname ( "Expired req cb." );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
105
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
106 /* Log */
1105
6b4a417d2845 Fix typo.
Thomas Klausner <tk@giga.or.at>
parents: 1099
diff changeset
107 TRACE_DEBUG(INFO, "The expiration timer for a request has been reached, aborting this attempt now & calling cb...");
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
108
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
109 /* Retrieve callback in the message */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
110 CHECK_FCT_DO( fd_msg_anscb_get( ed->request, NULL, &expirecb, &data ), return NULL);
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
111 ASSERT(expirecb);
824
89c5849b0832 Allow retransmission of messages on timeout
Sebastien Decugis <sdecugis@freediameter.net>
parents: 740
diff changeset
112
89c5849b0832 Allow retransmission of messages on timeout
Sebastien Decugis <sdecugis@freediameter.net>
parents: 740
diff changeset
113 /* Clean up this data from the message */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
114 CHECK_FCT_DO( fd_msg_anscb_associate( ed->request, NULL, NULL, NULL, NULL ), return NULL);
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
115
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
116 /* Call it */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
117 (*expirecb)(data, ed->sentto->p_hdr.info.pi_diamid, ed->sentto->p_hdr.info.pi_diamidlen, &ed->request);
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
118
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
119 /* If the callback did not dispose of the message, do it now */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
120 if (ed->request) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1110
diff changeset
121 fd_hook_call(HOOK_MESSAGE_DROPPED, ed->request, NULL, "Expiration period completed without an answer, and the expiry callback did not dispose of the message.", fd_msg_pmdl_get(ed->request));
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
122 CHECK_FCT_DO( fd_msg_free(ed->request), /* ignore */ );
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
123 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
124
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
125 free(ed);
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
126
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
127 /* Finish */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
128 return NULL;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
129 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
130
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
131 /* thread that handles messages expiring. The thread is started only when needed */
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
132 static void * sr_expiry_th(void * arg) {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
133 struct sr_list * srlist = arg;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
134 pthread_attr_t detached;
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
135 struct expire_data * ed;
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
136
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
137 TRACE_ENTRY("%p", arg);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
138 CHECK_PARAMS_DO( arg, return NULL );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
139
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
140 /* Set the thread name */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
141 {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
142 char buf[48];
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
143 snprintf(buf, sizeof(buf), "ReqExp/%s", ((struct fd_peer *)(srlist->exp.o))->p_hdr.info.pi_diamid);
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
144 fd_log_threadname ( buf );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
145 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
146
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
147 CHECK_POSIX_DO( pthread_attr_init(&detached), return NULL );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
148 CHECK_POSIX_DO( pthread_attr_setdetachstate(&detached, PTHREAD_CREATE_DETACHED), return NULL );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
149
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
150 CHECK_POSIX_DO( pthread_mutex_lock(&srlist->mtx), return NULL );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
151 pthread_cleanup_push( fd_cleanup_mutex, &srlist->mtx );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
152
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
153 do {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
154 struct timespec now, *t;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
155 struct sentreq * first;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
156 pthread_t th;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
157
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
158 /* Check if there are expiring requests available */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
159 if (FD_IS_LIST_EMPTY(&srlist->exp)) {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
160 /* Just wait for a change or cancelation */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
161 CHECK_POSIX_DO( pthread_cond_wait( &srlist->cnd, &srlist->mtx ), goto error );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
162 /* Restart the loop on wakeup */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
163 continue;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
164 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
165
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
166 /* Get the pointer to the request that expires first */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
167 first = (struct sentreq *)(srlist->exp.next->o);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
168 t = fd_msg_anscb_gettimeout( first->req );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
169 ASSERT(t);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
170
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
171 /* Get the current time */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
172 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), goto error );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
173
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
174 /* If first request is not expired, we just wait until it happens */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
175 if ( TS_IS_INFERIOR( &now, t ) ) {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
176
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
177 CHECK_POSIX_DO2( pthread_cond_timedwait( &srlist->cnd, &srlist->mtx, t ),
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
178 ETIMEDOUT, /* ETIMEDOUT is a normal return value, continue */,
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
179 /* on other error, */ goto error );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
180
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
181 /* on wakeup, loop */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
182 continue;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
183 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
184
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
185 /* Now, the first request in the list is expired; remove it and call the anscb for it in a new thread */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
186 CHECK_MALLOC_DO( ed = malloc(sizeof(struct expire_data)), goto error );
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
187 ed->sentto = first->chain.head->o;
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
188 ed->request = first->req;
1110
a731051d2e83 Fix handling of the hop-by-hop value for expired messages
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1105
diff changeset
189 *((uint32_t *)first->chain.o) = first->prevhbh; /* Restore the hbhid */
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
190 fd_list_unlink(&first->chain);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
191 fd_list_unlink(&first->expire);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
192 free(first);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
193
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
194 CHECK_POSIX_DO( pthread_create( &th, &detached, call_expirecb, ed ), goto error );
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
195
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
196 /* loop */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
197 } while (1);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
198 error:
1099
6ce5c99a40af Fix some typos.
Thomas Klausner <tk@giga.or.at>
parents: 1078
diff changeset
199 ; /* pthread_cleanup_pop sometimes expands as "} ..." and the label before this cause some compilers to complain... */
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
200 pthread_cleanup_pop( 1 );
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 688
diff changeset
201 ASSERT(0); /* we have encountered a problem, maybe time to signal the framework to terminate? */
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
202 return NULL;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
203 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
204
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
205
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
206 /* Store a new sent request */
165
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
207 int fd_p_sr_store(struct sr_list * srlist, struct msg **req, uint32_t *hbhloc, uint32_t hbh_restore)
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208 {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 struct sentreq * sr;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 struct fd_list * next;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
211 int match;
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
212 struct timespec * ts;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213
165
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
214 TRACE_ENTRY("%p %p %p %x", srlist, req, hbhloc, hbh_restore);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 CHECK_PARAMS(srlist && req && *req && hbhloc);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217 CHECK_MALLOC( sr = malloc(sizeof(struct sentreq)) );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
218 memset(sr, 0, sizeof(struct sentreq));
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219 fd_list_init(&sr->chain, hbhloc);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
220 sr->req = *req;
165
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
221 sr->prevhbh = hbh_restore;
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
222 fd_list_init(&sr->expire, sr);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
223 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &sr->added_on) );
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 /* Search the place in the list */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226 CHECK_POSIX( pthread_mutex_lock(&srlist->mtx) );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227 next = find_or_next(&srlist->srs, *hbhloc, &match);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 if (match) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229 TRACE_DEBUG(INFO, "A request with the same hop-by-hop Id was already sent: error");
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230 free(sr);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
231 CHECK_POSIX_DO( pthread_mutex_unlock(&srlist->mtx), /* ignore */ );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232 return EINVAL;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
234
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235 /* Save in the list */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
236 *req = NULL;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
237 fd_list_insert_before(next, &sr->chain);
938
4158151cc694 Add counter for number of requests pending answers
Sebastien Decugis <sdecugis@freediameter.net>
parents: 837
diff changeset
238 srlist->cnt++;
71
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
239 srl_dump("Saved new request, ", &srlist->srs);
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
240
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
241 /* In case of request with a timeout, also store in the timeout list */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
242 ts = fd_msg_anscb_gettimeout( sr->req );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
243 if (ts) {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
244 struct fd_list * li;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
245 struct timespec * t;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
246
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
247 /* browse srlist->exp from the end */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
248 for (li = srlist->exp.prev; li != &srlist->exp; li = li->prev) {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
249 struct sentreq * s = (struct sentreq *)(li->o);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
250 t = fd_msg_anscb_gettimeout( s->req );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
251 ASSERT( t ); /* sanity */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
252 if (TS_IS_INFERIOR(t, ts))
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
253 break;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
254 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
255
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
256 fd_list_insert_after(li, &sr->expire);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
257
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
258 /* if the thread does not exist yet, create it */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
259 if (srlist->thr == (pthread_t)NULL) {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
260 CHECK_POSIX_DO( pthread_create(&srlist->thr, NULL, sr_expiry_th, srlist), /* continue anyway */);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
261 } else {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
262 /* or, if added in first position, signal the condvar to update the sleep time of the thread */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
263 if (li == &srlist->exp) {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
264 CHECK_POSIX_DO( pthread_cond_signal(&srlist->cnd), /* continue anyway */);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
265 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
266 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
267 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
268
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
269 CHECK_POSIX( pthread_mutex_unlock(&srlist->mtx) );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
270 return 0;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
271 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
272
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
273 /* Fetch a request by hbh */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
274 int fd_p_sr_fetch(struct sr_list * srlist, uint32_t hbh, struct msg **req)
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
275 {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
276 struct sentreq * sr;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
277 int match;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
278
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
279 TRACE_ENTRY("%p %x %p", srlist, hbh, req);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
280 CHECK_PARAMS(srlist && req);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
281
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
282 /* Search the request in the list */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
283 CHECK_POSIX( pthread_mutex_lock(&srlist->mtx) );
71
cba30013d8f5 Added debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
284 srl_dump("Fetching a request, ", &srlist->srs);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
285 sr = (struct sentreq *)find_or_next(&srlist->srs, hbh, &match);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
286 if (!match) {
165
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
287 TRACE_DEBUG(INFO, "There is no saved request with this hop-by-hop id (%x)", hbh);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
288 *req = NULL;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
289 } else {
165
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
290 /* Restore hop-by-hop id */
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
291 *((uint32_t *)sr->chain.o) = sr->prevhbh;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
292 /* Unlink */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
293 fd_list_unlink(&sr->chain);
938
4158151cc694 Add counter for number of requests pending answers
Sebastien Decugis <sdecugis@freediameter.net>
parents: 837
diff changeset
294 srlist->cnt--;
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
295 fd_list_unlink(&sr->expire);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
296 *req = sr->req;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
297 free(sr);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
298 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
299 CHECK_POSIX( pthread_mutex_unlock(&srlist->mtx) );
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
300
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
301 /* do not stop the expire thread here, it might cause creating/destroying it very often otherwise */
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
302
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
303 /* Done */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
304 return 0;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
305 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
306
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
307 /* Failover requests (free or requeue routables) */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
308 void fd_p_sr_failover(struct sr_list * srlist)
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
309 {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
310 CHECK_POSIX_DO( pthread_mutex_lock(&srlist->mtx), /* continue anyway */ );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
311 while (!FD_IS_LIST_EMPTY(&srlist->srs)) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
312 struct sentreq * sr = (struct sentreq *)(srlist->srs.next);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
313 fd_list_unlink(&sr->chain);
938
4158151cc694 Add counter for number of requests pending answers
Sebastien Decugis <sdecugis@freediameter.net>
parents: 837
diff changeset
314 srlist->cnt--;
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
315 fd_list_unlink(&sr->expire);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
316 if (fd_msg_is_routable(sr->req)) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
317 struct msg_hdr * hdr = NULL;
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
318 int ret;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
319
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
320 /* Set the 'T' flag */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
321 CHECK_FCT_DO(fd_msg_hdr(sr->req, &hdr), /* continue */);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
322 if (hdr)
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
323 hdr->msg_flags |= CMD_FLAG_RETRANSMIT;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
324
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1110
diff changeset
325 fd_hook_call(HOOK_MESSAGE_FAILOVER, sr->req, (struct fd_peer *)srlist->srs.o, NULL, fd_msg_pmdl_get(sr->req));
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1110
diff changeset
326
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
327 /* Requeue for sending to another peer */
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
328 CHECK_FCT_DO( ret = fd_fifo_post(fd_g_outgoing, &sr->req),
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
329 {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1110
diff changeset
330 char buf[256];
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1110
diff changeset
331 snprintf(buf, sizeof(buf), "Internal error: error while requeuing during failover: %s", strerror(ret));
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1110
diff changeset
332 fd_hook_call(HOOK_MESSAGE_DROPPED, sr->req, NULL, buf, fd_msg_pmdl_get(sr->req));
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
333 CHECK_FCT_DO(fd_msg_free(sr->req), /* What can we do more? */)
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
334 });
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
335 } else {
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
336 /* Just free the request. */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1110
diff changeset
337 /* fd_hook_call(HOOK_MESSAGE_DROPPED, sr->req, NULL, "Sent & unanswered local message discarded during failover.", fd_msg_pmdl_get(sr->req)); */
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
338 CHECK_FCT_DO(fd_msg_free(sr->req), /* Ignore */);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
339 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
340 free(sr);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
341 }
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
342 /* The list of expiring requests must be empty now */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
343 ASSERT( FD_IS_LIST_EMPTY(&srlist->exp) );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
344
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
345 CHECK_POSIX_DO( pthread_mutex_unlock(&srlist->mtx), /* continue anyway */ );
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
346
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
347 /* Terminate the expiry thread (must be done when the lock can be taken) */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
348 CHECK_FCT_DO( fd_thr_term(&srlist->thr), /* ignore error */ );
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
349 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
350
"Welcome to our mercurial repository"