annotate libfdcore/p_out.c @ 1327:82b386714795

Set callback data also when only setting expire callback (and not answer callback as well). It is used when calling the expire callback, so not setting it makes no sense.
author Thomas Klausner <tk@giga.or.at>
date Mon, 27 Nov 2017 15:21:20 +0100
parents 84a3c9c4b834
children 566bb46cc73f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
e6fcdf12b9a0 Added a lot of TODOs :)
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> *
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
1305
84a3c9c4b834 Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1299
diff changeset
5 * Copyright (c) 2015, WIDE Project and NICT *
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
e6fcdf12b9a0 Added a lot of TODOs :)
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 *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
e6fcdf12b9a0 Added a lot of TODOs :)
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 *
e6fcdf12b9a0 Added a lot of TODOs :)
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 *
e6fcdf12b9a0 Added a lot of TODOs :)
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 *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
e6fcdf12b9a0 Added a lot of TODOs :)
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 *
e6fcdf12b9a0 Added a lot of TODOs :)
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 *
e6fcdf12b9a0 Added a lot of TODOs :)
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 *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
e6fcdf12b9a0 Added a lot of TODOs :)
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: 455
diff changeset
36 #include "fdcore-internal.h"
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 /* Alloc a new hbh for requests, bufferize the message and send on the connection, save in sentreq if provided */
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
39 static int do_send(struct msg ** msg, struct cnxctx * cnx, uint32_t * hbh, struct fd_peer * peer)
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 {
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
41 struct msg_hdr * hdr;
229
965f5971dc23 Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
42 int msg_is_a_req;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
43 uint8_t * buf;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
44 size_t sz;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
45 int ret;
165
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 136
diff changeset
46 uint32_t bkp_hbh = 0;
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
47 struct msg *cpy_for_logs_only;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
48
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
49 TRACE_ENTRY("%p %p %p %p", msg, cnx, hbh, peer);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
50
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
51 /* Retrieve the message header */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
52 CHECK_FCT( fd_msg_hdr(*msg, &hdr) );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
53
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
54 msg_is_a_req = (hdr->msg_flags & CMD_FLAG_REQUEST);
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
55 if (msg_is_a_req) {
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
56 CHECK_PARAMS(hbh && peer);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
57 /* Alloc the hop-by-hop id and increment the value for next message */
165
4679ff581d6a Fix invalid restore of the hop-by-hop id on forwarded answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 136
diff changeset
58 bkp_hbh = hdr->msg_hbhid;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
59 hdr->msg_hbhid = *hbh;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
60 *hbh = hdr->msg_hbhid + 1;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
61 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
62
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
63 /* Create the message buffer */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
64 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz ));
72
57ffd98dbe96 Fix race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 61
diff changeset
65 pthread_cleanup_push( free, buf );
57ffd98dbe96 Fix race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 61
diff changeset
66
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
67 cpy_for_logs_only = *msg;
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
68
72
57ffd98dbe96 Fix race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 61
diff changeset
69 /* Save a request before sending so that there is no race condition with the answer */
57ffd98dbe96 Fix race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 61
diff changeset
70 if (msg_is_a_req) {
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
71 CHECK_FCT_DO( ret = fd_p_sr_store(&peer->p_sr, msg, &hdr->msg_hbhid, bkp_hbh), goto out );
72
57ffd98dbe96 Fix race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 61
diff changeset
72 }
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73
895
fbf77629cb7b Added received and sent timestamps in the messages; added logs on emission and reception
Sebastien Decugis <sdecugis@freediameter.net>
parents: 740
diff changeset
74 /* Log the message */
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
75 fd_hook_call(HOOK_MESSAGE_SENT, cpy_for_logs_only, peer, NULL, fd_msg_pmdl_get(cpy_for_logs_only));
895
fbf77629cb7b Added received and sent timestamps in the messages; added logs on emission and reception
Sebastien Decugis <sdecugis@freediameter.net>
parents: 740
diff changeset
76
1207
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
77 pthread_cleanup_push((void *)fd_msg_free, *msg /* might be NULL, no problem */);
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
78
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
79 /* Send the message */
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
80 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz), );
1207
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
81
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
82 pthread_cleanup_pop(0);
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
83
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
84 out:
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
85 ;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
86 pthread_cleanup_pop(1);
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87
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
88 if (ret)
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
89 return ret;
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
90
72
57ffd98dbe96 Fix race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 61
diff changeset
91 /* Free remaining messages (i.e. answers) */
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
92 if (*msg) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
93 CHECK_FCT( fd_msg_free(*msg) );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
94 *msg = NULL;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
95 }
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
97 return 0;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
98 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
99
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100 /* The code of the "out" thread */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 static void * out_thr(void * arg)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 {
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
103 struct fd_peer * peer = arg;
1207
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
104 int stop = 0;
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
105 struct msg * msg;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
106 ASSERT( CHECK_PEER(peer) );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
107
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
108 /* Set the thread name */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
109 {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
110 char buf[48];
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
111 snprintf(buf, sizeof(buf), "OUT/%s", peer->p_hdr.info.pi_diamid);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
112 fd_log_threadname ( buf );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
113 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
114
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
115 /* Loop until cancelation */
1207
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
116 while (!stop) {
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
117 int ret;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
118
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
119 /* Retrieve next message to send */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
120 CHECK_FCT_DO( fd_fifo_get(peer->p_tosend, &msg), goto error );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
121
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
122 /* Send the message, log any error */
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
123 CHECK_FCT_DO( ret = do_send(&msg, peer->p_cnxctx, &peer->p_hbh, peer),
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
124 {
455
7250e91f0662 Some additional flush enforcement to attempt to avoid some possible problems
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 454
diff changeset
125 if (msg) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
126 char buf[256];
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
127 snprintf(buf, sizeof(buf), "Error while sending this message: %s", strerror(ret));
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
128 fd_hook_call(HOOK_MESSAGE_DROPPED, msg, NULL, buf, fd_msg_pmdl_get(msg));
455
7250e91f0662 Some additional flush enforcement to attempt to avoid some possible problems
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 454
diff changeset
129 fd_msg_free(msg);
7250e91f0662 Some additional flush enforcement to attempt to avoid some possible problems
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 454
diff changeset
130 }
1207
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
131 stop = 1;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
132 } );
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
133
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
134 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
135
1207
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
136 /* If we're here it means there was an error on the socket. We need to continue to purge the fifo & until we are canceled */
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
137 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL), /* What do we do if it fails? */ );
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
138
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
139 /* Requeue all routable messages in the global "out" queue, until we are canceled once the PSM deals with the CNX_ERROR sent above */
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
140 while ( fd_fifo_get(peer->p_tosend, &msg) == 0 ) {
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
141 if (fd_msg_is_routable(msg)) {
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
142 CHECK_FCT_DO(fd_fifo_post_noblock(peer->p_tofailover, (void *)&msg),
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
143 {
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
144 /* fallback: destroy the message */
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
145 fd_hook_call(HOOK_MESSAGE_DROPPED, msg, NULL, "Internal error: unable to requeue this message during failover process", fd_msg_pmdl_get(msg));
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
146 CHECK_FCT_DO(fd_msg_free(msg), /* What can we do more? */)
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
147 } );
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
148 } else {
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
149 /* Just free it */
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
150 /* fd_hook_call(HOOK_MESSAGE_DROPPED, m, NULL, "Non-routable message freed during handover", fd_msg_pmdl_get(m)); */
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
151 CHECK_FCT_DO(fd_msg_free(msg), /* What can we do more? */)
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
152 }
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
153 }
043b894b0511 Cleanups in failover situation to avoid deadlocks and corrupt messages ids. Tested OK now.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
154
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 error:
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
156 /* It is not really a connection error, but the effect is the same, we are not able to send anymore message */
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 33
diff changeset
157 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL), /* What do we do if it fails? */ );
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158 return NULL;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160
229
965f5971dc23 Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 208
diff changeset
161 /* Wrapper to sending a message either by out thread (peer in OPEN state) or directly; cnx or peer must be provided. Flags are valid only for direct sending, not through thread (unused) */
1238
8f9684264fe0 Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1207
diff changeset
162 int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer, int update_reqin_cnt)
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 {
1010
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
164 struct msg_hdr * hdr;
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
165
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
166 TRACE_ENTRY("%p %p %p", msg, cnx, peer);
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx)));
1299
035f489b845b Added a new hook HOOK_MESSAGE_SENDING
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1238
diff changeset
168
035f489b845b Added a new hook HOOK_MESSAGE_SENDING
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1238
diff changeset
169 fd_hook_call(HOOK_MESSAGE_SENDING, *msg, peer, NULL, fd_msg_pmdl_get(*msg));
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170
1238
8f9684264fe0 Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1207
diff changeset
171 if (update_reqin_cnt && peer) {
1010
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
172 CHECK_FCT( fd_msg_hdr(*msg, &hdr) );
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
173 if (!(hdr->msg_flags & CMD_FLAG_REQUEST)) {
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
174 /* Update the count of pending answers to send */
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
175 CHECK_POSIX( pthread_mutex_lock(&peer->p_state_mtx) );
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
176 peer->p_reqin_count--;
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
177 CHECK_POSIX( pthread_mutex_unlock(&peer->p_state_mtx) );
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
178 }
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
179 }
357c2f892d24 Implement a new counter on pending answers to send back to a peer.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 975
diff changeset
180
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
181 if (fd_peer_getstate(peer) == STATE_OPEN) {
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 /* Normal case: just queue for the out thread to pick it up */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 CHECK_FCT( fd_fifo_post(peer->p_tosend, msg) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 } else {
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
186 int ret;
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 uint32_t *hbh = NULL;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 /* In other cases, the thread is not running, so we handle the sending directly */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190 if (peer)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191 hbh = &peer->p_hbh;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 if (!cnx)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 cnx = peer->p_cnxctx;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 /* Do send the message */
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
197 CHECK_FCT_DO( ret = do_send(msg, cnx, hbh, peer),
35
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
198 {
455
7250e91f0662 Some additional flush enforcement to attempt to avoid some possible problems
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 454
diff changeset
199 if (msg) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
200 char buf[256];
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
201 snprintf(buf, sizeof(buf), "Error while sending this message: %s", strerror(ret));
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
202 fd_hook_call(HOOK_MESSAGE_DROPPED, *msg, NULL, buf, fd_msg_pmdl_get(*msg));
455
7250e91f0662 Some additional flush enforcement to attempt to avoid some possible problems
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 454
diff changeset
203 fd_msg_free(*msg);
7250e91f0662 Some additional flush enforcement to attempt to avoid some possible problems
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 454
diff changeset
204 *msg = NULL;
7250e91f0662 Some additional flush enforcement to attempt to avoid some possible problems
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 454
diff changeset
205 }
35
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
206 } );
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 return 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
211
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 /* Start the "out" thread that picks messages in p_tosend and send them on p_cnxctx */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 int fd_out_start(struct fd_peer * peer)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 TRACE_ENTRY("%p", peer);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216 CHECK_PARAMS( CHECK_PEER(peer) && (peer->p_outthr == (pthread_t)NULL) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
218 CHECK_POSIX( pthread_create(&peer->p_outthr, NULL, out_thr, peer) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
220 CHECK_FCT( fd_cnx_unordered_delivery(peer->p_cnxctx, 1) );
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
221
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 return 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 /* Stop that thread */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226 int fd_out_stop(struct fd_peer * peer)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 TRACE_ENTRY("%p", peer);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229 CHECK_PARAMS( CHECK_PEER(peer) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
231 CHECK_FCT( fd_cnx_unordered_delivery(peer->p_cnxctx, 0) );
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
232
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233 CHECK_FCT( fd_thr_term(&peer->p_outthr) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
234
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235 return 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
236 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
237
"Welcome to our mercurial repository"