enhance(API): Add multi-threaded call
[ric-plt/lib/rmr.git] / src / rmr / nanomsg / include / rmr_private.h
1 // : vi ts=4 sw=4 noet :
2 /*
3 ==================================================================================
4         Copyright (c) 2019 Nokia
5         Copyright (c) 2018-2019 AT&T Intellectual Property.
6
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
10
11            http://www.apache.org/licenses/LICENSE-2.0
12
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 ==================================================================================
19 */
20
21 /*
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.
26
27         Author:         E. Scott Daniels
28         Date:           27 November 2018
29
30         Mods:           28 February 2019 - moved most of the crap here to agnosic.
31 */
32
33 #ifndef _rmr_private_h
34 #define _rmr_private_h
35
36 /*
37         Manages an endpoint. Typedef for this is defined in agnostic.h
38 */
39 struct endpoint {
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
46 };
47
48 /*
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
51         visible functions.
52
53         The typedef for ctx is in the agnostic header
54 */
55 struct uta_ctx {
56         char*   my_name;                        // dns name of this host to set in sender field of a message
57         int             shutdown;                       // threads should exit if this is set
58         int max_mlen;                           // max message length payload+header
59         int     max_plen;                               // max payload length
60         int     flags;                                  // CTXFL_ constants
61         int nrtele;                                     // number of elements in the routing table
62         int     nn_sock;                                // our general listen socket
63         int     trace_data_len;                 // len of tracing data that sits just past header (0 means none)
64         int     d1_len;                                 // lengths for additional post header, pre payload data areas
65         int d2_len;
66         int last_rto;                           // last receive timeout set so that we don't bash in on every call
67         route_table_t* rtable;          // the active route table
68         route_table_t* old_rtable;      // the previously used rt, sits here to allow for draining
69         route_table_t* new_rtable;      // route table under construction
70         if_addrs_t*     ip_list;                // list manager of the IP addresses that are on our known interfaces
71         void*   mring;                          // ring where msgs are queued while waiting for a call response msg
72
73         char*   rtg_addr;                       // addr/port of the route table generation publisher
74         int             rtg_port;                       // the port that the rtg listens on
75
76         wh_mgt_t*       wormholes;              // wormhole management
77         pthread_t       rtc_th;                 // thread info for the rtc listener
78 };
79
80
81 /*
82         Prototypes of the functions which are defined in our static modules (nothing
83         from common should be here).
84 */
85
86 // ---- housekeeping and initialisation ----------
87 static void* init( char* usr_port, int max_mlen, int flags );
88 static void free_ctx( uta_ctx_t* ctx );
89
90 // --- message and context management --------
91 static rmr_mbuf_t* send_msg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int nn_sock );
92 static void* rcv_payload( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
93
94
95 // ---- route table and connection management ---------------
96
97 static int uta_link2( char* target );
98 static int rt_link2_ep( endpoint_t* ep );
99 static endpoint_t*  uta_add_ep( route_table_t* rt, rtable_ent_t* rte, char* ep_name, int group  );
100 static int uta_epsock_byname( route_table_t* rt, char* ep_name );
101 static int uta_epsock_rr( route_table_t *rt, uint64_t key, int group, int* more );
102
103 // ------ msg ------------------------------------------------
104 static rmr_mbuf_t* alloc_zcmsg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int size, int state, int tr_size );
105 static inline rmr_mbuf_t* clone_msg( rmr_mbuf_t* old_msg  );
106 static rmr_mbuf_t* rcv_msg( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
107 static void* rcv_payload( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
108 static rmr_mbuf_t* send_msg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int nn_sock );
109 static rmr_mbuf_t* send2ep( uta_ctx_t* ctx, endpoint_t* ep, rmr_mbuf_t* msg );
110
111 static int rt_link2_ep( endpoint_t* ep );
112 static rmr_mbuf_t* send2ep( uta_ctx_t* ctx, endpoint_t* ep, rmr_mbuf_t* msg );
113
114 #endif