From 32f578ee90a1a8a67aea1eefd007958ca9424d6e Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Fri, 21 Jan 2022 19:39:18 +0900 Subject: [PATCH 1/3] [compat] support ssl and http transport. --- OpenRTM_aist/CORBA_RTCUtil.py | 183 +++++++++++++++++++++++++++ OpenRTM_aist/Manager.py | 23 ++-- OpenRTM_aist/NamingManager.py | 127 ++++++++++--------- OpenRTM_aist/ext/http/rtc.http.conf | 4 +- OpenRTM_aist/ext/http/rtc.https.conf | 4 +- OpenRTM_aist/ext/http/rtc.ws.conf | 4 +- OpenRTM_aist/ext/http/rtc.wss.conf | 4 +- OpenRTM_aist/ext/ssl/rtc.ssl.conf | 4 +- 8 files changed, 276 insertions(+), 77 deletions(-) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index 177d956f..f2045756 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1757,3 +1757,186 @@ def getPort(self): # @endif def isAddressOnly(self): return self._addressonly + + +## +# @if jp +# @class RTCURIObject クラス +# @brief RTCURIObject クラス +# rtcname形式、rtcloc形式のURIから通信先のアドレス、RTC名等を +# 取得する機能を提供するクラス +# rtcname形式は以下のようにrtcname.{通信プロトコル}/{アドレス}/{ネームサーバーでの登録パス} +# で指定可能である。通信プロトコルを省略するとiiopに設定する。 +# +# rtcname.ssliop://localhost:2809/test.host_cxt/ConsoleOut0 +# +# ただし、http通信を指定する場合は以下のようにアドレスの後は#で区切る必要がある。 +# +# rtcname.https://localhost:2809/call#test.host_cxt/ConsoleOut0 +# +# rtcloc形式は以下のようにrtcloc.{通信プロトコル}/{アドレス}/{カテゴリ名}/{RTC名} +# で指定可能である。通信プロトコルを省略するとiiopに設定する。 +# +# rtcloc.ssliop://localhost:2810/example/ConsoleOut0 +# +# ただし、http通信を指定する場合は以下のようにアドレスの後は#で区切る必要がある。 +# +# rtcloc.http://localhost:2810/call#example/ConsoleOut0 +# +# @since 2.0.0 +# +# @else +# @class RTCURIObject class +# @brief RTCURIObject class +# @brief +# +# @since 2.0.0 +# +# @endif +class RTCURIObject: + ## + # @if jp + # + # @brief コンストラクタ + # + # @param uri rtcname形式、もしくはrtcloc形式のURI + # @param isrtcname rtcname形式を指定する場合はtrue、それ以外はfalse + # @param isrtcloc rtcloc形式を指定する場合はtrue、それ以外はfalse + # + # @else + # + # @brief Consructor + # + # + # @param uri + # @param isrtcname + # @param isrtcloc + # + # @endif + def __init__(self, uri, isrtcname=False, isrtcloc=False): + self._is_rtcname = False + self._is_rtcloc = False + self._rtcpath = "" + self._address = "" + pos = uri.find("://") + if pos >= 0: + ptype = uri[0:pos] + addrname = uri[pos+3:] + protocol = "" + + if ptype.find("rtcname") == 0: + self._is_rtcname = True + elif ptype.find("rtcloc") == 0: + self._is_rtcloc = True + else: + return + + if isrtcname: + if not self._is_rtcname: + return + + if isrtcloc: + if not self._is_rtcloc: + return + + pos = ptype.find(".") + seprtc = "/" + if pos >= 0: + protocol = ptype[pos+1:] + if protocol == "http" or protocol == "https" or protocol == "ws" or protocol == "wss": + seprtc = "#" + + pos = addrname.find(seprtc) + hostport = "" + + if pos >= 0: + hostport = addrname[0:pos] + self._rtcpath = addrname[pos+1:] + else: + self._rtcpath = addrname + + if protocol == "http" or protocol == "https" or protocol == "ws" or protocol == "wss": + self._address = protocol + self._address += "://" + self._address += hostport + + else: + self._address = "corbaloc:" + self._address += protocol + self._address += ":" + self._address += hostport + + ## + # @if jp + # + # @brief デストラクタ + # + # + # @else + # + # @brief Destructor + # + # + # @endif + def getRTCName(self): + return self._rtcpath + + ## + # @if jp + # + # @brief RTC名を取得する + # + # rtcname形式の場合はネームサーバーに登録したRTCのパスを取得できる。 + # context1.kind1/context2.kind2/..../RTC_name + # + # rtcloc形式の場合はカテゴリ名/RTC名で取得できる。 + # + # @return RTC名 + # + # @else + # + # @brief + # + # @return + # + # @endif + def getAddress(self): + return self._address + + ## + # @if jp + # + # @brief URIがrtcname形式かを判定する + # + # @return true:rtcname形式、false:それ以外 + # + # @return RTC名 + # + # @else + # + # @brief + # + # @return + # + # @endif + def isRTCNameURI(self): + return self._is_rtcname + + ## + # @if jp + # + # @brief URIがrtcname形式かを判定する + # + # @brief URIがrtcloc形式かを判定する + # + # @return true:rtcname形式、false:それ以外 + # + # @else + # + # @brief + # + # @return + # + # @endif + def isRTCLocURI(self): + return self._is_rtcloc diff --git a/OpenRTM_aist/Manager.py b/OpenRTM_aist/Manager.py index eef7e7d4..b2966960 100644 --- a/OpenRTM_aist/Manager.py +++ b/OpenRTM_aist/Manager.py @@ -3209,9 +3209,12 @@ def initPreConnection(self): if not ("interface_type" in configs.keys()): configs["interface_type"] = "corba_cdr" - tmp = port0_str.split(".") - tmp.pop() - comp0_name = OpenRTM_aist.flatten(tmp, ".") + pos_port0 = port0_str.rfind(".") + comp0_name = "" + if pos_port0 >= 0: + comp0_name = port0_str[0:pos_port0] + else: + comp0_name = port0_str port0_name = port0_str @@ -3234,7 +3237,7 @@ def initPreConnection(self): comp0_ref, port0_name) if CORBA.is_nil(port0_var): - self._rtcout.RTC_DEBUG("port %s found: " % port0_str) + self._rtcout.RTC_DEBUG("port %s not found: " % port0_str) continue if not ports: @@ -3251,9 +3254,13 @@ def initPreConnection(self): for port_str in ports: - tmp = port_str.split(".") - tmp.pop() - comp_name = OpenRTM_aist.flatten(tmp, ".") + pos_port = port_str.rfind(".") + comp_name = "" + if pos_port >= 0: + comp_name = port_str[0:pos_port] + else: + comp_name = port_str + port_name = port_str if comp_name.find("://") == -1: @@ -3275,7 +3282,7 @@ def initPreConnection(self): comp_ref, port_name) if CORBA.is_nil(port_var): - self._rtcout.RTC_DEBUG("port %s found: " % port_str) + self._rtcout.RTC_DEBUG("port %s not found: " % port_str) continue prop = OpenRTM_aist.Properties() diff --git a/OpenRTM_aist/NamingManager.py b/OpenRTM_aist/NamingManager.py index 0d695e78..f4c7809a 100644 --- a/OpenRTM_aist/NamingManager.py +++ b/OpenRTM_aist/NamingManager.py @@ -280,6 +280,7 @@ def getCorbaNaming(self): # @endif def getComponentByName(self, context, name, rtcs): + self._rtcout.RTC_TRACE("getComponentByName(name = %s)", name) length = 500 bl, bi = context.list(length) for i in bl: @@ -318,43 +319,51 @@ def getComponentByName(self, context, name, rtcs): # virtual RTCList string_to_component(string name) = 0; def string_to_component(self, name): + self._rtcout.RTC_TRACE("string_to_component(name = %s)", name) rtc_list = [] - tmp = name.split("://") - if len(tmp) > 1: - if tmp[0] == "rtcname": - #tag = tmp[0] - url = tmp[1] - r = url.split("/") - if len(r) > 1: - host = r[0] - rtc_name = url[len(host) + 1:] + rtcuri = OpenRTM_aist.CORBA_RTCUtil.RTCURIObject(name, True, False) - try: - cns = None - if host == "*": - cns = self._cosnaming - else: - orb = OpenRTM_aist.Manager.instance().getORB() - cns = OpenRTM_aist.CorbaNaming(orb, host) - names = rtc_name.split("/") - - if len(names) == 2 and names[0] == "*": - root_cxt = cns.getRootContext() - self.getComponentByName( - root_cxt, names[1], rtc_list) - return rtc_list - else: - rtc_name += ".rtc" - obj = cns.resolveStr(rtc_name) - if CORBA.is_nil(obj): - return [] - if obj._non_existent(): - return [] - rtc_list.append(obj) - return rtc_list - except BaseException: - return [] + if not rtcuri.isRTCNameURI(): + self._rtcout.RTC_WARN("syntax error: %s", name) + return rtc_list + else: + self._rtcout.RTC_INFO("URI: %s, Address: %s, Name: %s", + (name, rtcuri.getAddress(), + rtcuri.getRTCName())) + try: + cns = None + if rtcuri.getAddress() == "*": + cns = self._cosnaming + else: + orb = OpenRTM_aist.Manager.instance().getORB() + cns = OpenRTM_aist.CorbaNaming(orb, rtcuri.getAddress()) + + rtcname = rtcuri.getRTCName() + context = "" + compname = "" + + pos = rtcname.find("/") + if pos >= 0: + context = rtcname[0:pos] + compname = rtcname[pos + 1:] + + if context == "*": + root_cxt = cns.getRootContext() + self.getComponentByName( + root_cxt, compname, rtc_list) + return rtc_list + else: + rtcname += ".rtc" + obj = cns.resolveStr(rtcname) + if CORBA.is_nil(obj): + return rtc_list + if obj._non_existent(): + return rtc_list + rtc_list.append(obj) + return rtc_list + except BaseException: + return rtc_list return rtc_list @@ -501,33 +510,32 @@ def isAlive(self): # # virtual RTCList string_to_component(); def string_to_component(self, name): + self._rtcout.RTC_TRACE("string_to_component(name = %s)", name) rtc_list = [] - tmp = name.split("://") - - if len(tmp) > 1: - if tmp[0] == "rtcloc": - #tag = tmp[0] - url = tmp[1] - r = url.split("/") - if len(r) > 1: - host = r[0] - rtc_name = url[len(host) + 1:] - - mgr = self.getManager(host) - if not CORBA.is_nil(mgr): - rtc_list = mgr.get_components_by_name(rtc_name) - - slaves = mgr.get_slave_managers() - for slave in slaves: - try: - rtc_list.extend( - slave.get_components_by_name(rtc_name)) - except BaseException: - self._rtcout.RTC_DEBUG( - OpenRTM_aist.Logger.print_exception()) - mgr.remove_slave_manager(slave) - return rtc_list + rtcuri = OpenRTM_aist.CORBA_RTCUtil.RTCURIObject(name, False, True) + + if not rtcuri.isRTCLocURI(): + self._rtcout.RTC_WARN("syntax error: %s", name) + return rtc_list + else: + self._rtcout.RTC_INFO("URI: %s, Address: %s, Name: %s", + (name, rtcuri.getAddress(), + rtcuri.getRTCName())) + + mgr = self.getManager(rtcuri.getAddress()) + if not CORBA.is_nil(mgr): + rtc_list = mgr.get_components_by_name(rtcuri.getRTCName()) + slaves = mgr.get_slave_managers() + for slave in slaves: + try: + rtc_list.extend( + slave.get_components_by_name(rtcuri.getRTCName())) + except BaseException: + self._rtcout.RTC_DEBUG( + OpenRTM_aist.Logger.print_exception()) + mgr.remove_slave_manager(slave) + return rtc_list return rtc_list ## @@ -549,6 +557,7 @@ def string_to_component(self, name): # # virtual Manager_ptr getManager(string name); def getManager(self, name): + self._rtcout.RTC_TRACE("getManager(name = %s)", name) if name == "*": mgr_sev = self._mgr.getManagerServant() mgr = None diff --git a/OpenRTM_aist/ext/http/rtc.http.conf b/OpenRTM_aist/ext/http/rtc.http.conf index 38f71370..63fdb0dc 100644 --- a/OpenRTM_aist/ext/http/rtc.http.conf +++ b/OpenRTM_aist/ext/http/rtc.http.conf @@ -6,5 +6,5 @@ manager.modules.load_path: ./ manager.preload.modules: HTTPTransport.py corba.args:-ORBserverTransportRule "* http" -ORBclientTransportRule "* http" -ORBendPoint giop:http:http:///call -corba.nameservers: http://127.0.0.1:2809/call -corba.master_manager: giop:http:http://127.0.0.1:2810/call +corba.nameservers: http://localhost:2809/call +corba.master_manager: giop:http:http://localhost:2810/call diff --git a/OpenRTM_aist/ext/http/rtc.https.conf b/OpenRTM_aist/ext/http/rtc.https.conf index fe9f59f2..471cfa9b 100644 --- a/OpenRTM_aist/ext/http/rtc.https.conf +++ b/OpenRTM_aist/ext/http/rtc.https.conf @@ -10,5 +10,5 @@ corba.http.key_file:../ssl/test/server.pem corba.http.key_file_password:password corba.args:-ORBserverTransportRule "* http" -ORBclientTransportRule "* http" -ORBendPoint giop:http:https:///call -corba.nameservers: https://127.0.0.1:2809/call -corba.master_manager: giop:http:https://127.0.0.1:2810/call +corba.nameservers: https://localhost:2809/call +corba.master_manager: giop:http:https://localhost:2810/call diff --git a/OpenRTM_aist/ext/http/rtc.ws.conf b/OpenRTM_aist/ext/http/rtc.ws.conf index 93aac207..6c191ed1 100644 --- a/OpenRTM_aist/ext/http/rtc.ws.conf +++ b/OpenRTM_aist/ext/http/rtc.ws.conf @@ -6,5 +6,5 @@ manager.modules.load_path: ./ manager.preload.modules: HTTPTransport.py corba.args:-ORBserverTransportRule "* http" -ORBclientTransportRule "* http" -ORBendPoint giop:http:ws:///ws -corba.nameservers: ws://127.0.0.1:2809/ws -corba.master_manager: giop:http:ws://127.0.0.1:2810/ws +corba.nameservers: ws://localhost:2809/ws +corba.master_manager: giop:http:ws://localhost:2810/ws diff --git a/OpenRTM_aist/ext/http/rtc.wss.conf b/OpenRTM_aist/ext/http/rtc.wss.conf index af38d952..4059f311 100644 --- a/OpenRTM_aist/ext/http/rtc.wss.conf +++ b/OpenRTM_aist/ext/http/rtc.wss.conf @@ -10,5 +10,5 @@ corba.http.key_file:../ssl/test/server.pem corba.http.key_file_password:password corba.args:-ORBserverTransportRule "* http" -ORBclientTransportRule "* http" -ORBendPoint giop:http:wss:///ws -corba.nameservers: wss://127.0.0.1:2809/ws -corba.master_manager: giop:http:wss://127.0.0.1:2810/ws +corba.nameservers: wss://localhost:2809/ws +corba.master_manager: giop:http:wss://localhost:2810/ws diff --git a/OpenRTM_aist/ext/ssl/rtc.ssl.conf b/OpenRTM_aist/ext/ssl/rtc.ssl.conf index b0ea8ac8..404ec6d1 100644 --- a/OpenRTM_aist/ext/ssl/rtc.ssl.conf +++ b/OpenRTM_aist/ext/ssl/rtc.ssl.conf @@ -9,5 +9,5 @@ corba.ssl.certificate_authority_file:test/root.crt corba.ssl.key_file:test/server.pem corba.ssl.key_file_password:password corba.args:-ORBserverTransportRule "* ssl" -ORBclientTransportRule "* ssl" -ORBendPoint giop:ssl:: -corba.nameservers: corbaloc:ssliop:127.0.0.1:2809 -corba.master_manager: giop:ssl:127.0.0.1:2810 +corba.nameservers: corbaloc:ssliop:localhost:2809 +corba.master_manager: giop:ssl:localhost:2810 From 18cf2b5a377c354b10f9aa47d72bb3b9d0189335 Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Sun, 13 Feb 2022 11:13:51 +0900 Subject: [PATCH 2/3] [compat] fixed comment. --- OpenRTM_aist/CORBA_RTCUtil.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index f2045756..9e62d1dc 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1869,13 +1869,20 @@ def __init__(self, uri, isrtcname=False, isrtcloc=False): ## # @if jp # - # @brief デストラクタ + # @brief RTC名を取得する + # + # rtcname形式の場合はネームサーバーに登録したRTCのパスを取得できる。 + # context1.kind1/context2.kind2/..../RTC_name # + # rtcloc形式の場合はカテゴリ名/RTC名で取得できる。 + # + # @return RTC名 # # @else # - # @brief Destructor + # @brief # + # @return # # @endif def getRTCName(self): @@ -1884,14 +1891,10 @@ def getRTCName(self): ## # @if jp # - # @brief RTC名を取得する + # @brief 通信先のアドレスを取得する # - # rtcname形式の場合はネームサーバーに登録したRTCのパスを取得できる。 - # context1.kind1/context2.kind2/..../RTC_name # - # rtcloc形式の場合はカテゴリ名/RTC名で取得できる。 - # - # @return RTC名 + # @return 通信先のアドレス # # @else # From 5ff9cee9ea2699bbf8b661ee698c292245bb0a6a Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Fri, 18 Feb 2022 00:53:00 +0900 Subject: [PATCH 3/3] [compat] fixed bugs. --- OpenRTM_aist/CORBA_RTCUtil.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index 9e62d1dc..03654344 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1853,18 +1853,21 @@ def __init__(self, uri, isrtcname=False, isrtcloc=False): hostport = addrname[0:pos] self._rtcpath = addrname[pos+1:] else: - self._rtcpath = addrname - - if protocol == "http" or protocol == "https" or protocol == "ws" or protocol == "wss": - self._address = protocol - self._address += "://" - self._address += hostport + hostport = addrname + if hostport != "*": + if protocol == "http" or protocol == "https" or protocol == "ws" or protocol == "wss": + self._address = protocol + self._address += "://" + self._address += hostport + + else: + self._address = "corbaloc:" + self._address += protocol + self._address += ":" + self._address += hostport else: - self._address = "corbaloc:" - self._address += protocol - self._address += ":" - self._address += hostport + self._address = hostport ## # @if jp