X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fnng%2Fsrc%2Frtable_nng_static.c;h=81e79ca0572a6287c0f52dcc1009f019b18bc883;hb=refs%2Fchanges%2F59%2F1959%2F1;hp=7cd3e201bc6d7b75fd46e4f7259372a41628559f;hpb=c06c626ddf4f45a28a3db3f1afbb7ac87160045f;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/nng/src/rtable_nng_static.c b/src/rmr/nng/src/rtable_nng_static.c index 7cd3e20..81e79ca 100644 --- a/src/rmr/nng/src/rtable_nng_static.c +++ b/src/rmr/nng/src/rtable_nng_static.c @@ -388,6 +388,20 @@ static inline rtable_ent_t* uta_get_rte( route_table_t *rt, int sid, int mtype, return rte; } +/* + Given a route table and meid string, find the owner (if known). Returns a pointer to + the endpoint struct or nil. +*/ +static inline endpoint_t* get_meid_owner( route_table_t *rt, char* meid ) { + endpoint_t* ep; // the ep we found in the hash + + if( rt == NULL || rt->hash == NULL || meid == NULL || *meid == 0 ) { + return NULL; + } + + return (endpoint_t *) rmr_sym_get( rt->hash, meid, RT_ME_SPACE ); +} + /* Return a string of count information. E.g.: : @@ -419,4 +433,56 @@ static inline char* get_ep_counts( endpoint_t* ep, char* ubuf, int ubuf_len ) { return rs; } +/* + Given a message, use the meid field to find the owner endpoint for the meid. + The owner ep is then used to extract the socket through which the message + is sent. This returns TRUE if we found a socket and it was written to the + nn_sock pointer; false if we didn't. + + We've been told that the meid is a string, thus we count on it being a nil + terminated set of bytes. +*/ +static int epsock_meid( route_table_t *rtable, rmr_mbuf_t* msg, nng_socket* nn_sock, endpoint_t** uepp ) { + endpoint_t* ep; // seected end point + int state = FALSE; // processing state + char* meid; + + + errno = 0; + if( ! nn_sock || msg == NULL || rtable == NULL ) { // missing stuff; bail fast + errno = EINVAL; + return FALSE; + } + + meid = ((uta_mhdr_t *) msg->header)->meid; + + if( (ep = get_meid_owner( rtable, meid )) == NULL ) { + if( uepp != NULL ) { // caller needs refernce to endpoint too + *uepp = NULL; + } + + if( DEBUG ) fprintf( stderr, "[DBUG] epsock_meid: no ep in hash for (%s)\n", meid ); + return FALSE; + } + + state = TRUE; + if( ! ep->open ) { // not connected + if( ep->addr == NULL ) { // name didn't resolve before, try again + ep->addr = strdup( ep->name ); // use the name directly; if not IP then transport will do dns lookup + } + + if( uta_link2( ep ) ) { // find entry in table and create link + ep->open = TRUE; + *nn_sock = ep->nn_sock; // pass socket back to caller + } else { + state = FALSE; + } + if( DEBUG ) fprintf( stderr, "[DBUG] epsock_meid: connection attempted with %s: %s\n", ep->name, state ? "[OK]" : "[FAIL]" ); + } else { + *nn_sock = ep->nn_sock; + } + + return state; +} + #endif