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
45 pthread_mutex_t gate; // must be able to serialise some transport level functions on the ep
49 Context describing our world. Should be returned to user programme on
50 call to initialise, and passed as first parm on all calls to other
53 The typedef for ctx is in the agnostic header
56 char* my_name; // dns name of this host to set in sender field of a message
57 char* my_ip; // default IP address
58 int shutdown; // threads should exit if this is set
59 int max_mlen; // max message length payload+header
60 int max_plen; // max payload length
61 int flags; // CTXFL_ constants
62 int nrtele; // number of elements in the routing table
63 int nn_sock; // our general listen socket
64 int trace_data_len; // len of tracing data that sits just past header (0 means none)
65 int d1_len; // lengths for additional post header, pre payload data areas
67 int last_rto; // last receive timeout set so that we don't bash in on every call
68 route_table_t* rtable; // the active route table
69 route_table_t* old_rtable; // the previously used rt, sits here to allow for draining
70 route_table_t* new_rtable; // route table under construction
71 if_addrs_t* ip_list; // list manager of the IP addresses that are on our known interfaces
72 void* mring; // ring where msgs are queued while waiting for a call response msg
74 char* rtg_addr; // addr/port of the route table generation publisher
75 int rtg_port; // the port that the rtg listens on
77 wh_mgt_t* wormholes; // wormhole management
78 pthread_t rtc_th; // thread info for the rtc listener
83 Prototypes of the functions which are defined in our static modules (nothing
84 from common should be here).
87 // ---- housekeeping and initialisation ----------
88 static void* init( char* usr_port, int max_mlen, int flags );
89 static void free_ctx( uta_ctx_t* ctx );
91 // --- message and context management --------
92 static rmr_mbuf_t* send_msg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int nn_sock );
93 static void* rcv_payload( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
96 // ---- route table and connection management ---------------
98 static int uta_link2( char* target );
99 static int rt_link2_ep( endpoint_t* ep );
100 static endpoint_t* uta_add_ep( route_table_t* rt, rtable_ent_t* rte, char* ep_name, int group );
101 static int uta_epsock_byname( route_table_t* rt, char* ep_name );
102 static int uta_epsock_rr( route_table_t *rt, uint64_t key, int group, int* more );
104 // ------ msg ------------------------------------------------
105 static rmr_mbuf_t* alloc_zcmsg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int size, int state, int tr_size );
106 static inline rmr_mbuf_t* clone_msg( rmr_mbuf_t* old_msg );
107 static rmr_mbuf_t* rcv_msg( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
108 static void* rcv_payload( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
109 static rmr_mbuf_t* send_msg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int nn_sock );
110 static rmr_mbuf_t* send2ep( uta_ctx_t* ctx, endpoint_t* ep, rmr_mbuf_t* msg );
112 static int rt_link2_ep( endpoint_t* ep );
113 static rmr_mbuf_t* send2ep( uta_ctx_t* ctx, endpoint_t* ep, rmr_mbuf_t* msg );