1 // : vi ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2019 Nokia
5 Copyright (c) 2018-2019 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
22 Mnemonic: rmr_private.h
23 Abstract: Private header information for the uta library functions.
24 This should contain only things which are specific to nanomsg;
25 anything else is defined in the common/rmr_agnostic.h header.
27 Author: E. Scott Daniels
28 Date: 27 November 2018
30 Mods: 28 February 2019 - moved most of the crap here to agnosic.
33 #ifndef _rmr_private_h
34 #define _rmr_private_h
37 Manages an endpoint. Typedef for this is defined in agnostic.h
40 char* name; // end point name (symtab reference)
41 char* proto; // connection proto (should only be TCP, but future might bring others)
42 char* addr; // address used for connection
43 int nn_sock; // the nano-msg socket to write to for this entry
44 int open; // true if we've established the connection
48 Context describing our world. Should be returned to user programme on
49 call to initialise, and passed as first parm on all calls to other
52 The typedef for ctx is in the agnostic header
55 char* my_name; // dns name of this host to set in sender field of a message
56 int shutdown; // threads should exit if this is set
57 int max_mlen; // max message length payload+header
58 int max_plen; // max payload length
59 int flags; // CTXFL_ constants
60 int nrtele; // number of elements in the routing table
61 int nn_sock; // our general listen socket
62 route_table_t* rtable; // the active route table
63 route_table_t* old_rtable; // the previously used rt, sits here to allow for draining
64 route_table_t* new_rtable; // route table under construction
65 if_addrs_t* ip_list; // list manager of the IP addresses that are on our known interfaces
66 void* mring; // ring where msgs are queued while waiting for a call response msg
68 char* rtg_addr; // addr/port of the route table generation publisher
69 int rtg_port; // the port that the rtg listens on
71 wh_mgt_t* wormholes; // wormhole management
72 pthread_t rtc_th; // thread info for the rtc listener
77 Prototypes of the functions which are defined in our static modules (nothing
78 from common should be here).
81 // ---- housekeeping and initialisation ----------
82 static void* init( char* usr_port, int max_mlen, int flags );
83 static void free_ctx( uta_ctx_t* ctx );
85 // --- message and context management --------
86 static rmr_mbuf_t* send_msg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int nn_sock );
87 static void* rcv_payload( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
90 // ---- route table and connection management ---------------
92 static int uta_link2( char* target );
93 static int rt_link2_ep( endpoint_t* ep );
94 static endpoint_t* uta_add_ep( route_table_t* rt, rtable_ent_t* rte, char* ep_name, int group );
95 static int uta_epsock_byname( route_table_t* rt, char* ep_name );
96 static int uta_epsock_rr( route_table_t *rt, int mtype, int group, int* more );
98 // ------ msg ------------------------------------------------
99 static rmr_mbuf_t* alloc_zcmsg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int size, int state );
100 static inline rmr_mbuf_t* clone_msg( rmr_mbuf_t* old_msg );
101 static rmr_mbuf_t* rcv_msg( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
102 static void* rcv_payload( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
103 static rmr_mbuf_t* send_msg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int nn_sock );
104 static rmr_mbuf_t* send2ep( uta_ctx_t* ctx, endpoint_t* ep, rmr_mbuf_t* msg );
109 // --- message ring --------------------------
110 static void* uta_mk_ring( int size );
111 static void uta_ring_free( void* vr );
112 static inline void* uta_ring_extract( void* vr );
113 static inline int uta_ring_insert( void* vr, void* new_data );
115 // --- message and context management --------
116 static int ie_test( void* r, int i_factor, long inserts );
117 static void free_ctx( uta_ctx_t* ctx );
118 static rmr_mbuf_t* alloc_zcmsg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int size, int state );
119 static inline rmr_mbuf_t* clone_msg( rmr_mbuf_t* old_msg );
120 static rmr_mbuf_t* rcv_msg( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
122 // ----- route table static things ---------
123 static void collect_things( void* st, void* entry, char const* name, void* thing, void* vthing_list );
124 static void del_rte( void* st, void* entry, char const* name, void* thing, void* data );
125 static char* uta_fib( char* fname );
126 static route_table_t* uta_rt_init( );
127 static route_table_t* uta_rt_clone( route_table_t* srt );
128 static void uta_rt_drop( route_table_t* rt );
129 static endpoint_t* uta_add_ep( route_table_t* rt, rtable_ent_t* rte, char* ep_name, int group );
130 static rtable_ent_t* uta_add_rte( route_table_t* rt, int mtype, int nrrgroups );
131 static endpoint_t* uta_get_ep( route_table_t* rt, char const* ep_name );
132 static int uta_epsock_byname( route_table_t* rt, char* ep_name );
133 static int uta_epsock_rr( route_table_t *rt, int mtype, int group, int* more );
134 static void read_static_rt( uta_ctx_t* ctx, int vlevel );
135 static void parse_rt_rec( uta_ctx_t* ctx, char* buf, int vlevel );
136 static void* rtc( void* vctx );
137 static endpoint_t* rt_ensure_ep( route_table_t* rt, char const* ep_name );
140 // --- tools_static protos ------------------
141 static int uta_tokenise( char* buf, char** tokens, int max, char sep );
142 static char* uta_h2ip( char const* hname );
143 static int uta_link2( char* target );
144 static int uta_lookup_rtg( uta_ctx_t* ctx );
145 static int uta_has_str( char const* buf, char const* str, char sep, int max );
148 static int rt_link2_ep( endpoint_t* ep );
149 static rmr_mbuf_t* send2ep( uta_ctx_t* ctx, endpoint_t* ep, rmr_mbuf_t* msg );