Mercurial > hg > freeDiameter
annotate libfdcore/p_psm.c @ 658:f198d16fa7f4
Initial commit for 1.1.0:
* Restructuring:
* libfreeDiameter:
- renamed folder & binary into libfdproto
- renamed libfD.h into fdproto-internal.h
- removed signals management (replaced by triggers in libfdcore)
* freeDiameter split into:
- libfdcore (most contents)
- renamed fD.h into fdcore-internal.h
- added core.c for framework init/shutdown.
- new triggers mechanism in events.c.
- freeDiameterd (main, command line parsing, signals management)
* tests:
- now in top-level directory tests.
* other changes:
- fd_dict_new now returns 0 on duplicate identical entries.
- fixes in dict_legacy_xml
- fixes in some dictionaries
- moved FD_DEFAULT_CONF_FILENAME definition to freeDiameter-host.h
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Fri, 14 Jan 2011 15:15:23 +0900 |
parents | freeDiameter/p_psm.c@f1484823cb4a |
children | 2e94ef0515d7 |
rev | line source |
---|---|
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
258
5df55136361b
Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
229
diff
changeset
|
5 * Copyright (c) 2010, WIDE Project and NICT * |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
ef9ef3bf4752
Progress on peer state machine
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 * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
ef9ef3bf4752
Progress on peer state machine
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 * |
ef9ef3bf4752
Progress on peer state machine
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 * |
ef9ef3bf4752
Progress on peer state machine
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 * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
ef9ef3bf4752
Progress on peer state machine
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 * |
ef9ef3bf4752
Progress on peer state machine
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 * |
ef9ef3bf4752
Progress on peer state machine
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 * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
ef9ef3bf4752
Progress on peer state machine
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:
454
diff
changeset
|
36 #include "fdcore-internal.h" |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
38 /* The actual declaration of peer_state_str */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
39 DECLARE_STATE_STR(); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
40 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
41 /* Helper for next macro */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
42 #define case_str( _val ) \ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
43 case _val : return #_val |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
44 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
45 DECLARE_PEV_STR(); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
46 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
47 /************************************************************************/ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
48 /* Delayed startup */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
49 /************************************************************************/ |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
50 static int started = 0; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 static pthread_mutex_t started_mtx = PTHREAD_MUTEX_INITIALIZER; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
52 static pthread_cond_t started_cnd = PTHREAD_COND_INITIALIZER; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
53 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
54 /* Wait for start signal */ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
55 static int fd_psm_waitstart() |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
56 { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
57 TRACE_ENTRY(""); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
58 CHECK_POSIX( pthread_mutex_lock(&started_mtx) ); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
59 awake: |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
60 if (! started) { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
61 pthread_cleanup_push( fd_cleanup_mutex, &started_mtx ); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
62 CHECK_POSIX( pthread_cond_wait(&started_cnd, &started_mtx) ); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
63 pthread_cleanup_pop( 0 ); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
64 goto awake; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
65 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
66 CHECK_POSIX( pthread_mutex_unlock(&started_mtx) ); |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
67 return 0; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
69 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
70 /* Allow the state machines to start */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
71 int fd_psm_start() |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
72 { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
73 TRACE_ENTRY(""); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
74 CHECK_POSIX( pthread_mutex_lock(&started_mtx) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
75 started = 1; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
76 CHECK_POSIX( pthread_cond_broadcast(&started_cnd) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
77 CHECK_POSIX( pthread_mutex_unlock(&started_mtx) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
78 return 0; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
79 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
80 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
81 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
82 /************************************************************************/ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
83 /* Manage the list of active peers */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
84 /************************************************************************/ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
85 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
86 /* Enter/leave OPEN state */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
87 static int enter_open_state(struct fd_peer * peer) |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
88 { |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
89 struct fd_list * li; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
90 CHECK_PARAMS( FD_IS_LIST_EMPTY(&peer->p_actives) ); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
91 |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
92 /* Callback registered by the credential validator (fd_peer_validate_register) */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
93 if (peer->p_cb2) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
94 CHECK_FCT_DO( (*peer->p_cb2)(&peer->p_hdr.info), |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
95 { |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
96 TRACE_DEBUG(FULL, "Validation failed, terminating the connection"); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
97 fd_psm_terminate(peer, "DO_NOT_WANT_TO_TALK_TO_YOU" ); |
34
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 peer->p_cb2 = NULL; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
100 return 0; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
101 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
102 /* Insert in the active peers list */ |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
103 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_activ_peers_rw) ); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
104 for (li = fd_g_activ_peers.next; li != &fd_g_activ_peers; li = li->next) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
105 struct fd_peer * next_p = (struct fd_peer *)li->o; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
106 int cmp = strcmp(peer->p_hdr.info.pi_diamid, next_p->p_hdr.info.pi_diamid); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
107 if (cmp < 0) |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
108 break; |
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 fd_list_insert_before(li, &peer->p_actives); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
111 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_activ_peers_rw) ); |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
112 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
113 /* Callback registered when the peer was added, by fd_peer_add */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
114 if (peer->p_cb) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
115 TRACE_DEBUG(FULL, "Calling add callback for peer %s", peer->p_hdr.info.pi_diamid); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
116 (*peer->p_cb)(&peer->p_hdr.info, peer->p_cb_data); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
117 peer->p_cb = NULL; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
118 peer->p_cb_data = NULL; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
119 } |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
120 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
121 /* Start the thread to handle outgoing messages */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
122 CHECK_FCT( fd_out_start(peer) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
123 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
124 /* Update the expiry timer now */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
125 CHECK_FCT( fd_p_expi_update(peer) ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
126 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
127 return 0; |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
128 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
129 static int leave_open_state(struct fd_peer * peer) |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
130 { |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
131 /* Remove from active peers list */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
132 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_activ_peers_rw) ); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
133 fd_list_unlink( &peer->p_actives ); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
134 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_activ_peers_rw) ); |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
135 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
136 /* Stop the "out" thread */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
137 CHECK_FCT( fd_out_stop(peer) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
138 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
139 /* Failover the messages */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
140 fd_peer_failover_msg(peer); |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
141 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
142 return 0; |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
143 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
144 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
145 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
146 /************************************************************************/ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
147 /* Helpers for state changes */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
148 /************************************************************************/ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
149 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
150 /* Cleanup pending events in the peer */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
151 void fd_psm_events_free(struct fd_peer * peer) |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
152 { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
153 struct fd_event * ev; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
154 /* Purge all events, and free the associated data if any */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
155 while (fd_fifo_tryget( peer->p_events, &ev ) == 0) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
156 switch (ev->code) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
157 case FDEVP_CNX_ESTABLISHED: { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
158 fd_cnx_destroy(ev->data); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
159 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
160 break; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
161 |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
162 case FDEVP_TERMINATE: |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
163 /* Do not free the string since it is a constant */ |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
164 break; |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
165 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
166 case FDEVP_CNX_INCOMING: { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
167 struct cnx_incoming * evd = ev->data; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
168 CHECK_FCT_DO( fd_msg_free(evd->cer), /* continue */); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
169 fd_cnx_destroy(evd->cnx); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
170 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
171 default: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
172 free(ev->data); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
173 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
174 free(ev); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
175 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
176 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
177 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
178 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
179 /* Change state */ |
36 | 180 int fd_psm_change_state(struct fd_peer * peer, int new_state) |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
181 { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
182 int old; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
183 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
184 TRACE_ENTRY("%p %d(%s)", peer, new_state, STATE_STR(new_state)); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
185 CHECK_PARAMS( CHECK_PEER(peer) ); |
454
f1484823cb4a
Small hack which might spear some concurrency problems and is quite harmless
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
186 fd_cpu_flush_cache(); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
187 old = peer->p_hdr.info.runtime.pir_state; |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
188 if (old == new_state) |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
189 return 0; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
190 |
228 | 191 TRACE_DEBUG(((old == STATE_OPEN) || (new_state == STATE_OPEN)) ? INFO : FULL, "'%s'\t-> '%s'\t'%s'", |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
192 STATE_STR(old), |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
193 STATE_STR(new_state), |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
194 peer->p_hdr.info.pi_diamid); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
195 |
224
3caac3cd359d
Change state first, otherwise failover might re-select the same peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
204
diff
changeset
|
196 peer->p_hdr.info.runtime.pir_state = new_state; |
454
f1484823cb4a
Small hack which might spear some concurrency problems and is quite harmless
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
197 fd_cpu_flush_cache(); |
224
3caac3cd359d
Change state first, otherwise failover might re-select the same peer
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
204
diff
changeset
|
198 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
199 if (old == STATE_OPEN) { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
200 CHECK_FCT( leave_open_state(peer) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
201 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
202 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
203 if (new_state == STATE_OPEN) { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
204 CHECK_FCT( enter_open_state(peer) ); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
205 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
206 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
207 if (new_state == STATE_CLOSED) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
208 /* Purge event list */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
209 fd_psm_events_free(peer); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
210 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
211 /* If the peer is not persistant, we destroy it */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
212 if (peer->p_hdr.info.config.pic_flags.persist == PI_PRST_NONE) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
213 CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, 0, NULL) ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
214 } |
36 | 215 } |
216 | |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
217 return 0; |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
218 } |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
219 |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
220 /* Set timeout timer of next event */ |
36 | 221 void fd_psm_next_timeout(struct fd_peer * peer, int add_random, int delay) |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
222 { |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
223 TRACE_DEBUG(FULL, "Peer timeout reset to %d seconds%s", delay, add_random ? " (+/- 2)" : "" ); |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
224 |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
225 /* Initialize the timer */ |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
226 CHECK_POSIX_DO( clock_gettime( CLOCK_REALTIME, &peer->p_psm_timer ), ASSERT(0) ); |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
227 |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
228 if (add_random) { |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
229 if (delay > 2) |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
230 delay -= 2; |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
231 else |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
232 delay = 0; |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
233 |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
234 /* Add a random value between 0 and 4sec */ |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
235 peer->p_psm_timer.tv_sec += random() % 4; |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
236 peer->p_psm_timer.tv_nsec+= random() % 1000000000L; |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
237 if (peer->p_psm_timer.tv_nsec > 1000000000L) { |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
238 peer->p_psm_timer.tv_nsec -= 1000000000L; |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
239 peer->p_psm_timer.tv_sec ++; |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
240 } |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
241 } |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
242 |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
243 peer->p_psm_timer.tv_sec += delay; |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
244 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
245 #ifdef SLOW_PSM |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
246 /* temporary for debug */ |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
247 peer->p_psm_timer.tv_sec += 10; |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
248 #endif |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
249 } |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
250 |
36 | 251 /* Cleanup the peer */ |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
252 void fd_psm_cleanup(struct fd_peer * peer, int terminate) |
36 | 253 { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
254 /* Move to CLOSED state: failover messages, stop OUT thread, unlink peer from active list */ |
454
f1484823cb4a
Small hack which might spear some concurrency problems and is quite harmless
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
255 fd_cpu_flush_cache(); |
74 | 256 if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) { |
257 CHECK_FCT_DO( fd_psm_change_state(peer, STATE_CLOSED), /* continue */ ); | |
258 } | |
36 | 259 |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
260 fd_p_cnx_abort(peer, terminate); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
261 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
42
diff
changeset
|
262 fd_p_ce_clear_cnx(peer, NULL); |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
263 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
264 if (peer->p_receiver) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
265 fd_cnx_destroy(peer->p_receiver); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
266 peer->p_receiver = NULL; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
267 } |
36 | 268 |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
269 if (terminate) { |
204
2465698b9f31
Purge events on cleanup
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
198
diff
changeset
|
270 fd_psm_events_free(peer); |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
271 CHECK_FCT_DO( fd_fifo_del(&peer->p_events), /* continue */ ); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
272 } |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
273 |
36 | 274 } |
275 | |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
276 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
277 /************************************************************************/ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
278 /* The PSM thread */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
279 /************************************************************************/ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
280 /* Cancelation cleanup : set ZOMBIE state in the peer */ |
36 | 281 void cleanup_setstate(void * arg) |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
282 { |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
283 struct fd_peer * peer = (struct fd_peer *)arg; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
284 CHECK_PARAMS_DO( CHECK_PEER(peer), return ); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
285 peer->p_hdr.info.runtime.pir_state = STATE_ZOMBIE; |
454
f1484823cb4a
Small hack which might spear some concurrency problems and is quite harmless
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
286 fd_cpu_flush_cache(); |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
287 return; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
288 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
289 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
290 /* The state machine thread (controler) */ |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
291 static void * p_psm_th( void * arg ) |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
292 { |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
293 struct fd_peer * peer = (struct fd_peer *)arg; |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
294 int created_started = started ? 1 : 0; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
295 int event; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
296 size_t ev_sz; |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
297 void * ev_data; |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
298 |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
299 CHECK_PARAMS_DO( CHECK_PEER(peer), ASSERT(0) ); |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
300 |
36 | 301 pthread_cleanup_push( cleanup_setstate, arg ); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
302 |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
303 /* Set the thread name */ |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
304 { |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
305 char buf[48]; |
136
abd3c441780b
Fix 64 bits warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
131
diff
changeset
|
306 sprintf(buf, "PSM/%.*s", (int)sizeof(buf) - 5, peer->p_hdr.info.pi_diamid); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
307 fd_log_threadname ( buf ); |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
308 } |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
309 |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
310 /* The state machine starts in CLOSED state */ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
311 peer->p_hdr.info.runtime.pir_state = STATE_CLOSED; |
454
f1484823cb4a
Small hack which might spear some concurrency problems and is quite harmless
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
312 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
313 /* Wait that the PSM are authorized to start in the daemon */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
314 CHECK_FCT_DO( fd_psm_waitstart(), goto psm_end ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
315 |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
316 /* Initialize the timer */ |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
317 if (peer->p_flags.pf_responder) { |
36 | 318 fd_psm_next_timeout(peer, 0, INCNX_TIMEOUT); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
319 } else { |
36 | 320 fd_psm_next_timeout(peer, created_started, 0); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
321 } |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
322 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
323 psm_loop: |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
324 /* Get next event */ |
67
f0215a3edca9
Added small debug message
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
66
diff
changeset
|
325 TRACE_DEBUG(FULL, "'%s' in state '%s' waiting for next event.", |
f0215a3edca9
Added small debug message
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
66
diff
changeset
|
326 peer->p_hdr.info.pi_diamid, STATE_STR(peer->p_hdr.info.runtime.pir_state)); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
327 CHECK_FCT_DO( fd_event_timedget(peer->p_events, &peer->p_psm_timer, FDEVP_PSM_TIMEOUT, &event, &ev_sz, &ev_data), goto psm_end ); |
27
b3a1773e9f46
again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
26
diff
changeset
|
328 TRACE_DEBUG(FULL, "'%s'\t<-- '%s'\t(%p,%zd)\t'%s'", |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
329 STATE_STR(peer->p_hdr.info.runtime.pir_state), |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
330 fd_pev_str(event), ev_data, ev_sz, |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
331 peer->p_hdr.info.pi_diamid); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
332 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
333 /* Now, the action depends on the current state and the incoming event */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
334 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
335 /* The following states are impossible */ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
336 ASSERT( peer->p_hdr.info.runtime.pir_state != STATE_NEW ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
337 ASSERT( peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE ); |
42 | 338 ASSERT( peer->p_hdr.info.runtime.pir_state != STATE_OPEN_HANDSHAKE ); /* because it should exist only between two loops */ |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
339 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
340 /* Purge invalid events */ |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
341 if (!CHECK_PEVENT(event)) { |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
342 TRACE_DEBUG(INFO, "Invalid event received in PSM '%s' : %d", peer->p_hdr.info.pi_diamid, event); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
343 goto psm_loop; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
344 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
345 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
346 /* Handle the (easy) debug event now */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
347 if (event == FDEVP_DUMP_ALL) { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
348 fd_peer_dump(peer, ANNOYING); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
349 goto psm_loop; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
350 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
351 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
352 /* Requests to terminate the peer object */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
353 if (event == FDEVP_TERMINATE) { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
354 switch (peer->p_hdr.info.runtime.pir_state) { |
36 | 355 case STATE_OPEN: |
356 case STATE_REOPEN: | |
357 /* We cannot just close the conenction, we have to send a DPR first */ | |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
358 CHECK_FCT_DO( fd_p_dp_initiate(peer, ev_data), goto psm_end ); |
36 | 359 goto psm_loop; |
360 | |
361 /* | |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
362 case STATE_CLOSING: |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
363 case STATE_WAITCNXACK: |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
364 case STATE_WAITCNXACK_ELEC: |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
365 case STATE_WAITCEA: |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
366 case STATE_SUSPECT: |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
367 case STATE_CLOSED: |
36 | 368 */ |
369 default: | |
370 /* In these cases, we just cleanup the peer object (if needed) and terminate */ | |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
371 goto psm_end; |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
372 } |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
373 } |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
374 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
375 /* A message was received */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
376 if (event == FDEVP_CNX_MSG_RECV) { |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
377 struct msg * msg = NULL; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
378 struct msg_hdr * hdr; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
379 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
380 /* If the current state does not allow receiving messages, just drop it */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
381 if (peer->p_hdr.info.runtime.pir_state == STATE_CLOSED) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
382 TRACE_DEBUG(FULL, "Purging message in queue while in CLOSED state (%zdb)", ev_sz); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
383 free(ev_data); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
384 goto psm_loop; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
385 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
386 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
387 /* Parse the received buffer */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
388 CHECK_FCT_DO( fd_msg_parse_buffer( (void *)&ev_data, ev_sz, &msg), |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
389 { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
390 fd_log_debug("Received invalid data from peer '%s', closing the connection\n", peer->p_hdr.info.pi_diamid); |
42 | 391 free(ev_data); |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
392 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL), goto psm_reset ); |
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
393 goto psm_loop; |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
394 } ); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
395 |
36 | 396 TRACE_DEBUG(FULL, "Received a message (%zdb) from '%s'", ev_sz, peer->p_hdr.info.pi_diamid); |
266
f404b5f84d7b
Dump complete received messages at FULL+1 level
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
265
diff
changeset
|
397 if (TRACE_BOOL(FULL+1)) { |
f404b5f84d7b
Dump complete received messages at FULL+1 level
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
265
diff
changeset
|
398 CHECK_FCT_DO( fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ), ); |
f404b5f84d7b
Dump complete received messages at FULL+1 level
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
265
diff
changeset
|
399 fd_msg_dump_walk(FULL, msg); |
f404b5f84d7b
Dump complete received messages at FULL+1 level
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
265
diff
changeset
|
400 } else { |
f404b5f84d7b
Dump complete received messages at FULL+1 level
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
265
diff
changeset
|
401 fd_msg_dump_one(FULL, msg); |
f404b5f84d7b
Dump complete received messages at FULL+1 level
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
265
diff
changeset
|
402 } |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
403 |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
404 /* Extract the header */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
405 CHECK_FCT_DO( fd_msg_hdr(msg, &hdr), goto psm_end ); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
406 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
407 /* If it is an answer, associate with the request or drop */ |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
408 if (!(hdr->msg_flags & CMD_FLAG_REQUEST)) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
409 struct msg * req; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
410 /* Search matching request (same hbhid) */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
411 CHECK_FCT_DO( fd_p_sr_fetch(&peer->p_sr, hdr->msg_hbhid, &req), goto psm_end ); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
412 if (req == NULL) { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
413 fd_log_debug("Received a Diameter answer message with no corresponding sent request, discarding.\n"); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
414 fd_msg_dump_walk(NONE, msg); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
415 fd_msg_free(msg); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
416 goto psm_loop; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
417 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
418 |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
419 /* Associate */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
420 CHECK_FCT_DO( fd_msg_answ_associate( msg, req ), goto psm_end ); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
421 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
422 |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
423 /* Now handle non-link-local messages */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
424 if (fd_msg_is_routable(msg)) { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
425 switch (peer->p_hdr.info.runtime.pir_state) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
426 /* To maximize compatibility -- should not be a security issue here */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
427 case STATE_REOPEN: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
428 case STATE_SUSPECT: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
429 case STATE_CLOSING: |
66
dcbd5b5ee55c
Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
65
diff
changeset
|
430 TRACE_DEBUG(FULL, "Accepted a message while not in OPEN state... "); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
431 /* The standard situation : */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
432 case STATE_OPEN: |
42 | 433 /* We received a valid routable message, update the expiry timer */ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
434 CHECK_FCT_DO( fd_p_expi_update(peer), goto psm_end ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
435 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
436 /* Set the message source and add the Route-Record */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
437 CHECK_FCT_DO( fd_msg_source_set( msg, peer->p_hdr.info.pi_diamid, 1, fd_g_config->cnf_dict ), goto psm_end); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
438 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
439 /* Requeue to the global incoming queue */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
440 CHECK_FCT_DO(fd_fifo_post(fd_g_incoming, &msg), goto psm_end ); |
36 | 441 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
442 /* Update the peer timer (only in OPEN state) */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
443 if ((peer->p_hdr.info.runtime.pir_state == STATE_OPEN) && (!peer->p_flags.pf_dw_pending)) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
444 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_twtimer ?: fd_g_config->cnf_timer_tw); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
445 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
446 break; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
447 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
448 /* In other states, we discard the message, it is either old or invalid to send it for the remote peer */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
449 case STATE_WAITCNXACK: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
450 case STATE_WAITCNXACK_ELEC: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
451 case STATE_WAITCEA: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
452 case STATE_CLOSED: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
453 default: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
454 /* In such case, just discard the message */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
455 fd_log_debug("Received a routable message while not in OPEN state from peer '%s', discarded.\n", peer->p_hdr.info.pi_diamid); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
456 fd_msg_dump_walk(NONE, msg); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
457 fd_msg_free(msg); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
458 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
459 goto psm_loop; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
460 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
461 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
462 /* Link-local message: They must be understood by our dictionary, otherwise we return an error */ |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
463 { |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
464 int ret = fd_msg_parse_or_error( &msg ); |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
465 if (ret != EBADMSG) { |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
466 CHECK_FCT_DO( ret, goto psm_end ); |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
467 } else { |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
468 if (msg) { |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
469 /* Send the error back to the peer */ |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
470 CHECK_FCT_DO( fd_out_send(&msg, NULL, peer, FD_CNX_ORDERED), /* In case of error the message has already been dumped */ ); |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
471 if (msg) { |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
472 CHECK_FCT_DO( fd_msg_free(msg), goto psm_end); |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
473 } |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
474 } else { |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
475 /* We received an invalid answer, let's disconnect */ |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
476 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL), goto psm_reset ); |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
477 } |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
478 goto psm_loop; |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
479 } |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
480 } |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
481 |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
482 /* Handle the LL message and update the expiry timer appropriately */ |
36 | 483 switch (hdr->msg_code) { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
484 case CC_CAPABILITIES_EXCHANGE: |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
485 CHECK_FCT_DO( fd_p_ce_msgrcv(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_reset ); |
36 | 486 break; |
487 | |
488 case CC_DISCONNECT_PEER: | |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
489 CHECK_FCT_DO( fd_p_dp_handle(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_reset ); |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
490 if (peer->p_hdr.info.runtime.pir_state == STATE_CLOSING) |
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
491 goto psm_end; |
36 | 492 break; |
493 | |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
494 case CC_DEVICE_WATCHDOG: |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
495 CHECK_FCT_DO( fd_p_dw_handle(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_reset ); |
36 | 496 break; |
497 | |
498 default: | |
499 /* Unknown / unexpected / invalid message */ | |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
500 fd_log_debug("Received an unknown local message from peer '%s', discarded.\n", peer->p_hdr.info.pi_diamid); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
501 fd_msg_dump_walk(NONE, msg); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
502 if (hdr->msg_flags & CMD_FLAG_REQUEST) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
503 do { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
504 /* Reply with an error code */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
505 CHECK_FCT_DO( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msg, MSGFL_ANSW_ERROR ), break ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
506 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
507 /* Set the error code */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
508 CHECK_FCT_DO( fd_msg_rescode_set(msg, "DIAMETER_INVALID_HDR_BITS", NULL, NULL, 1 ), break ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
509 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
510 /* Send the answer */ |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
511 CHECK_FCT_DO( fd_out_send(&msg, peer->p_cnxctx, peer, FD_CNX_ORDERED), break ); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
512 } while (0); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
513 } else { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
514 /* We did ASK for it ??? */ |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
515 fd_log_debug("Invalid PXY flag in answer header ?\n"); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
516 } |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
517 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
518 /* Cleanup the message if not done */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
519 if (msg) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
520 CHECK_FCT_DO( fd_msg_free(msg), /* continue */); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
521 msg = NULL; |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
522 } |
36 | 523 }; |
524 | |
525 /* At this point the message must have been fully handled already */ | |
526 if (msg) { | |
527 fd_log_debug("Internal error: unhandled message (discarded)!\n"); | |
528 fd_msg_dump_walk(NONE, msg); | |
529 fd_msg_free(msg); | |
530 } | |
531 | |
532 goto psm_loop; | |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
533 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
534 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
535 /* The connection object is broken */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
536 if (event == FDEVP_CNX_ERROR) { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
537 switch (peer->p_hdr.info.runtime.pir_state) { |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
538 case STATE_WAITCNXACK_ELEC: |
74 | 539 /* Abort the initiating side */ |
540 fd_p_cnx_abort(peer, 0); | |
541 /* Process the receiver side */ | |
542 CHECK_FCT_DO( fd_p_ce_process_receiver(peer), goto psm_end ); | |
543 break; | |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
544 |
131
50d1dc19b221
Hopefully removed infinite loop
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
129
diff
changeset
|
545 case STATE_WAITCEA: |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
546 case STATE_OPEN: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
547 case STATE_REOPEN: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
548 case STATE_WAITCNXACK: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
549 case STATE_SUSPECT: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
550 default: |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
551 /* Mark the connection problem */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
552 peer->p_flags.pf_cnx_pb = 1; |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
553 |
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
554 /* Destroy the connection, restart the timer to a new connection attempt */ |
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
555 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
556 |
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
557 case STATE_CLOSED: |
159 | 558 goto psm_reset; |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
559 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
560 case STATE_CLOSING: |
79
d273a2ce19c8
Fix problem in DPR handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
561 /* We sent a DPR so we are terminating, do not wait for DPA */ |
d273a2ce19c8
Fix problem in DPR handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
78
diff
changeset
|
562 goto psm_end; |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
563 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
564 } |
74 | 565 goto psm_loop; |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
566 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
567 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
568 /* The connection notified a change in endpoints */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
569 if (event == FDEVP_CNX_EP_CHANGE) { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
570 /* We actually don't care if we are in OPEN state here... */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
571 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
572 /* Cleanup the remote LL and primary addresses */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
573 CHECK_FCT_DO( fd_ep_filter( &peer->p_hdr.info.pi_endpoints, EP_FL_CONF | EP_FL_DISC | EP_FL_ADV ), /* ignore the error */); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
574 CHECK_FCT_DO( fd_ep_clearflags( &peer->p_hdr.info.pi_endpoints, EP_FL_PRIMARY ), /* ignore the error */); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
575 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
576 /* Get the new ones */ |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
373
diff
changeset
|
577 CHECK_FCT_DO( fd_cnx_getremoteeps(peer->p_cnxctx, &peer->p_hdr.info.pi_endpoints), /* ignore the error */); |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
578 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
373
diff
changeset
|
579 /* We do not support local endpoints change currently, but it could be added here if needed (refresh fd_g_config->cnf_endpoints)*/ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
580 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
581 if (TRACE_BOOL(ANNOYING)) { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
582 TRACE_DEBUG(ANNOYING, "New remote endpoint(s):" ); |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
583 fd_ep_dump(6, &peer->p_hdr.info.pi_endpoints); |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
584 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
585 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
586 /* Done */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
587 goto psm_loop; |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
588 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
589 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
590 /* A new connection was established and CER containing this peer id was received */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
591 if (event == FDEVP_CNX_INCOMING) { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
592 struct cnx_incoming * params = ev_data; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
593 ASSERT(params); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
594 |
36 | 595 /* Handle the message */ |
596 CHECK_FCT_DO( fd_p_ce_handle_newCER(¶ms->cer, peer, ¶ms->cnx, params->validate), goto psm_end ); | |
597 | |
598 /* Cleanup if needed */ | |
599 if (params->cnx) { | |
600 fd_cnx_destroy(params->cnx); | |
601 params->cnx = NULL; | |
602 } | |
603 if (params->cer) { | |
604 CHECK_FCT_DO( fd_msg_free(params->cer), ); | |
605 params->cer = NULL; | |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
606 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
607 |
36 | 608 /* Loop */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
609 free(ev_data); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
610 goto psm_loop; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
611 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
612 |
40
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
613 /* A new connection has been established with the remote peer */ |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
614 if (event == FDEVP_CNX_ESTABLISHED) { |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
615 struct cnxctx * cnx = ev_data; |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
616 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
42
diff
changeset
|
617 /* Release the resources of the connecting thread */ |
40
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
618 CHECK_POSIX_DO( pthread_join( peer->p_ini_thr, NULL), /* ignore, it is not a big deal */); |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
619 peer->p_ini_thr = (pthread_t)NULL; |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
620 |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
621 switch (peer->p_hdr.info.runtime.pir_state) { |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
622 case STATE_WAITCNXACK_ELEC: |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
623 case STATE_WAITCNXACK: |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
624 fd_p_ce_handle_newcnx(peer, cnx); |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
625 break; |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
626 |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
627 default: |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
628 /* Just abort the attempt and continue */ |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
629 TRACE_DEBUG(FULL, "Connection attempt successful but current state is %s, closing...", STATE_STR(peer->p_hdr.info.runtime.pir_state)); |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
630 fd_cnx_destroy(cnx); |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
631 } |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
632 |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
633 goto psm_loop; |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
634 } |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
635 |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
636 /* A new connection has not been established with the remote peer */ |
70
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
637 if (event == FDEVP_CNX_FAILED) { |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
638 |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
639 /* Release the resources of the connecting thread */ |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
640 CHECK_POSIX_DO( pthread_join( peer->p_ini_thr, NULL), /* ignore, it is not a big deal */); |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
641 peer->p_ini_thr = (pthread_t)NULL; |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
642 |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
643 switch (peer->p_hdr.info.runtime.pir_state) { |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
644 case STATE_WAITCNXACK_ELEC: |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
645 /* Abort the initiating side */ |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
646 fd_p_cnx_abort(peer, 0); |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
647 /* Process the receiver side */ |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
648 CHECK_FCT_DO( fd_p_ce_process_receiver(peer), goto psm_end ); |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
649 break; |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
650 |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
651 case STATE_WAITCNXACK: |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
652 /* Go back to CLOSE */ |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
653 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
654 goto psm_reset; |
70
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
655 |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
656 default: |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
657 /* Just ignore */ |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
658 TRACE_DEBUG(FULL, "Connection attempt failed but current state is %s, ignoring...", STATE_STR(peer->p_hdr.info.runtime.pir_state)); |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
659 } |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
660 |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
661 goto psm_loop; |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
662 } |
65b32c93f21e
Do not wait for timeout when all connections attempts have failed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
67
diff
changeset
|
663 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
664 /* The timeout for the current state has been reached */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
665 if (event == FDEVP_PSM_TIMEOUT) { |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
666 switch (peer->p_hdr.info.runtime.pir_state) { |
36 | 667 case STATE_OPEN: |
668 case STATE_REOPEN: | |
669 CHECK_FCT_DO( fd_p_dw_timeout(peer), goto psm_end ); | |
49 | 670 goto psm_loop; |
36 | 671 |
672 case STATE_CLOSED: | |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
673 CHECK_FCT_DO( fd_psm_change_state(peer, STATE_WAITCNXACK), goto psm_end ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
674 fd_psm_next_timeout(peer, 0, CNX_TIMEOUT); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
675 CHECK_FCT_DO( fd_p_cnx_init(peer), goto psm_end ); |
49 | 676 goto psm_loop; |
36 | 677 |
198
5ea550c3f033
Fix handling of long network failures
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
184
diff
changeset
|
678 case STATE_SUSPECT: |
5ea550c3f033
Fix handling of long network failures
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
184
diff
changeset
|
679 /* Mark the connection problem */ |
5ea550c3f033
Fix handling of long network failures
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
184
diff
changeset
|
680 peer->p_flags.pf_cnx_pb = 1; |
5ea550c3f033
Fix handling of long network failures
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
184
diff
changeset
|
681 |
36 | 682 case STATE_CLOSING: |
683 case STATE_WAITCNXACK: | |
684 case STATE_WAITCEA: | |
685 /* Destroy the connection, restart the timer to a new connection attempt */ | |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
686 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
687 goto psm_reset; |
36 | 688 |
689 case STATE_WAITCNXACK_ELEC: | |
40
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
690 /* Abort the initiating side */ |
7e1deaa89540
Some progress on the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
691 fd_p_cnx_abort(peer, 0); |
66
dcbd5b5ee55c
Added handling for DWR/DWA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
65
diff
changeset
|
692 /* Process the receiver side */ |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
42
diff
changeset
|
693 CHECK_FCT_DO( fd_p_ce_process_receiver(peer), goto psm_end ); |
49 | 694 goto psm_loop; |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
378
diff
changeset
|
695 |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
378
diff
changeset
|
696 default: |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
378
diff
changeset
|
697 ASSERT(0); /* implementation problem, we did not foresee this case? */ |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
698 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
699 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
700 |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
701 /* Default action : the handling has not yet been implemented. [for debug only] */ |
81
66a00b701f02
Removed last TODO in PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
79
diff
changeset
|
702 TRACE_DEBUG(INFO, "Missing handler in PSM for '%s'\t<-- '%s'", STATE_STR(peer->p_hdr.info.runtime.pir_state), fd_pev_str(event)); |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
703 psm_reset: |
154
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
704 if (peer->p_flags.pf_delete) |
4356de61174d
Small tweaks in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
705 goto psm_end; |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
706 fd_psm_cleanup(peer, 0); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
707 goto psm_loop; |
129
b20b2aeeb160
Small changes in the PSM
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
81
diff
changeset
|
708 |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
709 psm_end: |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
710 fd_psm_cleanup(peer, 1); |
373 | 711 TRACE_DEBUG(INFO, "'%s'\t-> STATE_ZOMBIE (terminated)\t'%s'", |
371
ba39f4afd45d
Added trace when going ZOMBIE
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
266
diff
changeset
|
712 STATE_STR(peer->p_hdr.info.runtime.pir_state), |
ba39f4afd45d
Added trace when going ZOMBIE
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
266
diff
changeset
|
713 peer->p_hdr.info.pi_diamid); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
714 pthread_cleanup_pop(1); /* set STATE_ZOMBIE */ |
454
f1484823cb4a
Small hack which might spear some concurrency problems and is quite harmless
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
715 fd_cpu_flush_cache(); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
716 peer->p_psm = (pthread_t)NULL; |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
28
diff
changeset
|
717 pthread_detach(pthread_self()); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
718 return NULL; |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
719 } |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
720 |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
721 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
722 /************************************************************************/ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
723 /* Functions to control the PSM */ |
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
724 /************************************************************************/ |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
725 /* Create the PSM thread of one peer structure */ |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
726 int fd_psm_begin(struct fd_peer * peer ) |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
727 { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
728 TRACE_ENTRY("%p", peer); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
729 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
730 /* Check the peer and state are OK */ |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
731 CHECK_PARAMS( CHECK_PEER(peer) && (peer->p_hdr.info.runtime.pir_state == STATE_NEW) ); |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
732 |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
733 /* Create the FIFO for events */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
734 CHECK_FCT( fd_fifo_new(&peer->p_events) ); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
735 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
736 /* Create the PSM controler thread */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
737 CHECK_POSIX( pthread_create( &peer->p_psm, NULL, p_psm_th, peer ) ); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
738 |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
739 /* We're done */ |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
740 return 0; |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
741 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
742 |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
743 /* End the PSM (clean ending) */ |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
744 int fd_psm_terminate(struct fd_peer * peer, char * reason ) |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
745 { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
746 TRACE_ENTRY("%p", peer); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
747 CHECK_PARAMS( CHECK_PEER(peer) ); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
748 |
454
f1484823cb4a
Small hack which might spear some concurrency problems and is quite harmless
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
749 fd_cpu_flush_cache(); |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
750 if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) { |
78
a58f0757c06a
Added code for DPR/DPA
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
76
diff
changeset
|
751 CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, 0, reason) ); |
16
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
752 } else { |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
753 TRACE_DEBUG(FULL, "Peer '%s' was already terminated", peer->p_hdr.info.pi_diamid); |
013ce9851131
Started including TLS code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
754 } |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
13
diff
changeset
|
755 return 0; |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
756 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
757 |
33
e6fcdf12b9a0
Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
758 /* End the PSM & cleanup the peer structure */ |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
759 void fd_psm_abord(struct fd_peer * peer ) |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
760 { |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
761 TRACE_ENTRY("%p", peer); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
762 |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
763 /* Cancel PSM thread */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
764 CHECK_FCT_DO( fd_thr_term(&peer->p_psm), /* continue */ ); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
765 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
766 /* Cleanup the data */ |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
767 fd_psm_cleanup(peer, 1); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
768 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
769 /* Destroy the event list */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
770 CHECK_FCT_DO( fd_fifo_del(&peer->p_events), /* continue */ ); |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
33
diff
changeset
|
771 |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
36
diff
changeset
|
772 /* Remaining cleanups are performed in fd_peer_free */ |
13
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
773 return; |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
774 } |
ef9ef3bf4752
Progress on peer state machine
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
775 |