TCPChannelResourceSecure.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _FASTDDS_TCP_CHANNEL_RESOURCE_SECURE_
  15. #define _FASTDDS_TCP_CHANNEL_RESOURCE_SECURE_
  16. #include <asio.hpp>
  17. #include <asio/ssl.hpp>
  18. #include <asio/strand.hpp>
  19. #include <fastdds/rtps/transport/TCPChannelResource.h>
  20. namespace eprosima{
  21. namespace fastdds{
  22. namespace rtps{
  23. class TCPChannelResourceSecure : public TCPChannelResource
  24. {
  25. public:
  26. // Constructor called when trying to connect to a remote server (secure version)
  27. TCPChannelResourceSecure(
  28. TCPTransportInterface* parent,
  29. asio::io_service& service,
  30. asio::ssl::context& ssl_context,
  31. const fastrtps::rtps::Locator_t& locator,
  32. uint32_t maxMsgSize);
  33. // Constructor called when local server accepted connection (secure version)
  34. TCPChannelResourceSecure(
  35. TCPTransportInterface* parent,
  36. asio::io_service& service,
  37. asio::ssl::context& ssl_context,
  38. std::shared_ptr<asio::ssl::stream<asio::ip::tcp::socket>> socket,
  39. uint32_t maxMsgSize);
  40. virtual ~TCPChannelResourceSecure();
  41. void connect(
  42. const std::shared_ptr<TCPChannelResource>& myself) override;
  43. void disconnect() override;
  44. uint32_t read(
  45. fastrtps::rtps::octet* buffer,
  46. std::size_t size,
  47. asio::error_code& ec) override;
  48. size_t send(
  49. const fastrtps::rtps::octet* header,
  50. size_t header_size,
  51. const fastrtps::rtps::octet* data,
  52. size_t size,
  53. asio::error_code& ec) override;
  54. asio::ip::tcp::endpoint remote_endpoint() const override;
  55. asio::ip::tcp::endpoint local_endpoint() const override;
  56. void set_options(const TCPTransportDescriptor* options) override;
  57. void set_tls_verify_mode(const TCPTransportDescriptor* options);
  58. void cancel() override;
  59. void close() override;
  60. void shutdown(asio::socket_base::shutdown_type what) override;
  61. inline std::shared_ptr<asio::ssl::stream<asio::ip::tcp::socket>> secure_socket()
  62. {
  63. return secure_socket_;
  64. }
  65. private:
  66. TCPChannelResourceSecure(const TCPChannelResource&) = delete;
  67. TCPChannelResourceSecure& operator=(const TCPChannelResource&) = delete;
  68. asio::io_service& service_;
  69. asio::ssl::context& ssl_context_;
  70. asio::io_service::strand strand_read_;
  71. asio::io_service::strand strand_write_;
  72. std::shared_ptr<asio::ssl::stream<asio::ip::tcp::socket>> secure_socket_;
  73. };
  74. } // namespace rtps
  75. } // namespace fastdds
  76. } // namespace eprosima
  77. #endif // _FASTDDS_TCP_CHANNEL_RESOURCE_SECURE_