25#include <boost/shared_array.hpp>
29namespace RobotRaconteur
47class TcpTransportConnection;
51class TcpWebSocketConnector;
52class TcpWSSWebSocketConnector;
53class TcpSocketAcceptor;
131class ROBOTRACONTEUR_CORE_API
TcpTransport :
public Transport,
public RR_ENABLE_SHARED_FROM_THIS<TcpTransport>
133 friend class TcpTransportConnection;
134 friend class detail::TcpConnector;
135 friend class detail::TcpWebSocketConnector;
136 friend class detail::TcpWSSWebSocketConnector;
142 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<ITransportConnection> > TransportConnections;
143 boost::mutex TransportConnections_lock;
145 std::list<RR_WEAK_PTR<ITransportConnection> > closing_TransportConnections;
146 std::list<RR_WEAK_PTR<ITransportConnection> > incoming_TransportConnections;
165 RR_OVIRTUAL
bool IsServer() const RR_OVERRIDE;
166 RR_OVIRTUAL
bool IsClient() const RR_OVERRIDE;
214 RR_OVIRTUAL std::
string GetUrlSchemeString() const RR_OVERRIDE;
216 virtual int32_t GetListenPort();
218 RR_OVIRTUAL
void SendMessage(const RR_INTRUSIVE_PTR<Message>& m) RR_OVERRIDE;
220 RR_OVIRTUAL
void AsyncSendMessage(
221 const RR_INTRUSIVE_PTR<Message>& m,
224 RR_OVIRTUAL
void AsyncCreateTransportConnection(
225 boost::string_ref url, const RR_SHARED_PTR<Endpoint>& e,
226 boost::function<
void(const RR_SHARED_PTR<ITransportConnection>&,
229 RR_OVIRTUAL RR_SHARED_PTR<ITransportConnection> CreateTransportConnection(
230 boost::string_ref url, const RR_SHARED_PTR<Endpoint>& e) RR_OVERRIDE;
232 RR_OVIRTUAL
void CloseTransportConnection(const RR_SHARED_PTR<Endpoint>& e) RR_OVERRIDE;
235 virtual
void CloseTransportConnection_timed(const boost::system::error_code& err, const RR_SHARED_PTR<Endpoint>& e,
236 const RR_SHARED_PTR<
void>& timer);
249 virtual
void StartServer(int32_t porte,
bool localhost_only = false,
250 boost::function<
bool(const boost::asio::ip::tcp::endpoint&)> accept_filter = 0);
278 virtual
void StartServer(const std::vector<boost::asio::ip::tcp::endpoint>& listen_endpoints,
279 boost::function<
bool(const boost::asio::ip::tcp::endpoint&)> accept_filter = 0);
302 RR_OVIRTUAL
bool CanConnectService(boost::string_ref url) RR_OVERRIDE;
304 RR_OVIRTUAL
void Close() RR_OVERRIDE;
306 RR_OVIRTUAL
void CheckConnection(uint32_t endpoint) RR_OVERRIDE;
356 void SendDiscoveryRequest();
358 RR_OVIRTUAL
void PeriodicCleanupTask() RR_OVERRIDE;
360 RR_OVIRTUAL uint32_t TransportCapability(boost::string_ref name) RR_OVERRIDE;
362 static
void GetLocalAdapterIPAddresses(std::vector<boost::asio::ip::address>& addresses);
364 RR_OVIRTUAL
void MessageReceived(const RR_INTRUSIVE_PTR<Message>& m) RR_OVERRIDE;
667 template <typename T, typename F>
668 boost::signals2::connection AddCloseListener(const RR_SHARED_PTR<T>& t, const F& f)
670 boost::mutex::scoped_lock lock(closed_lock);
675 return boost::signals2::connection();
678 return close_signal.connect(boost::signals2::signal<
void()>::slot_type(boost::bind(f, t.get())).track(t));
682 RR_OVIRTUAL
void LocalNodeServicesChanged() RR_OVERRIDE;
684 boost::mutex node_discovery_lock;
685 RR_SHARED_PTR<
void> node_discovery;
687 std::vector<RR_SHARED_PTR<detail::TcpSocketAcceptor> > acceptors;
688 boost::mutex acceptor_lock;
690 static
void handle_accept(const RR_SHARED_PTR<
TcpTransport>& parent,
691 const RR_SHARED_PTR<detail::TcpSocketAcceptor>& acceptor,
692 const RR_SHARED_PTR<boost::asio::ip::tcp::socket>& socket,
693 const boost::system::error_code& error);
695 virtual
void register_transport(const RR_SHARED_PTR<ITransportConnection>& connection);
696 virtual
void erase_transport(const RR_SHARED_PTR<ITransportConnection>& connection);
697 virtual
void incoming_transport(const RR_SHARED_PTR<ITransportConnection>& connection);
699 boost::mutex parameter_lock;
700 int32_t heartbeat_period;
701 int32_t default_connect_timeout;
702 int32_t default_receive_timeout;
703 int32_t max_message_size;
704 int32_t max_connection_count;
705 bool disable_message4;
706 bool disable_string_table;
707 bool disable_async_message_io;
709 boost::shared_ptr<
void> GetTlsContext();
711 boost::shared_ptr<
void> tls_context;
712 boost::mutex tls_context_lock;
715 RR_SHARED_PTR<
void> port_sharer_client;
716 boost::mutex port_sharer_client_lock;
718 bool accept_websockets;
720 std::vector<std::
string> allowed_websocket_origins;
723 boost::signals2::signal<
void()> close_signal;
724 boost::mutex closed_lock;
727#ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
boost::shared_ptr< TcpTransport > TcpTransportPtr
Convenience alias for TcpTransport shared_ptr.
Definition TcpTransport.h:729
IPNodeDiscoveryFlags
Configuration flags for IP network node discovery.
Definition TcpTransport.h:36
@ IPNodeDiscoveryFlags_IPV4_BROADCAST
Use IPv4 255.255.255.255 broadcast addresses.
Definition TcpTransport.h:44
@ IPNodeDiscoveryFlags_LINK_LOCAL
Use IPv6 FF02:: link local multicast addresses.
Definition TcpTransport.h:40
@ IPNodeDiscoveryFlags_NODE_LOCAL
Use IPv6 FF01:: node local multicast addresses.
Definition TcpTransport.h:38
@ IPNodeDiscoveryFlags_SITE_LOCAL
Use IPv6 FF05:: site local multicast addresses.
Definition TcpTransport.h:42
Base class for all Robot Raconteur objects.
Definition DataTypes.h:228
Base class for Robot Raconteur exceptions.
Definition Error.h:53
static boost::shared_ptr< RobotRaconteurNode > sp()
Singleton shared_ptr accessor.
Transport for Transport Control Protocol Internet Protocol (TCP/IP) networks.
Definition TcpTransport.h:132
virtual void StartServer(int32_t porte, bool localhost_only=false, boost::function< bool(const boost::asio::ip::tcp::endpoint &)> accept_filter=0)
Start the server on the specified TCP port.
virtual bool GetRequireTls()
Get if all connections require TLS.
virtual void SetMaxMessageSize(int32_t size)
Set the maximum serialized message size.
virtual std::vector< boost::asio::ip::tcp::endpoint > GetResolvedListenEndpoints()
Get the TCP endpoints the server is listening with "all" addresses resolved to specific addresses.
virtual std::vector< boost::asio::ip::tcp::endpoint > GetListenEndpoints()
Get the TCP endpoints the server is listening on.
virtual bool IsPortSharerRunning()
Check if the port sharer is running.
RR_OVIRTUAL std::vector< std::string > GetServerListenUrls() RR_OVERRIDE
Get the TCP endpoints the server is listening on as Robot Raconteur candidate URLs.
virtual bool IsTransportConnectionSecure(uint32_t endpoint)
Check if specified endpoint is using TLS for its transport.
virtual void SetDisableStringTable(bool d)
Set disable string table.
virtual void SetDefaultReceiveTimeout(int32_t milliseconds)
Set the default receive timeout.
virtual void LoadTlsNodeCertificate()
Load the TLS certificate from the system.
TcpTransport(const boost::shared_ptr< RobotRaconteurNode > &node=RobotRaconteurNode::sp())
Construct a new TcpTransport.
void DisableNodeAnnounce()
Disable node discovery announce.
virtual int32_t GetMaxMessageSize()
Get the maximum serialized message size.
virtual bool GetDisableStringTable()
Get disable string table.
virtual bool GetAcceptWebSockets()
Get if the transport will accept incoming HTTP WebSocket connections.
virtual std::string GetSecurePeerIdentity(uint32_t endpoint)
Get the identity of the peer if secured using TLS.
virtual void SetDefaultConnectTimeout(int32_t milliseconds)
Set the default connect timeout.
virtual void SetMaxConnectionCount(int32_t count)
Set the maximum number of concurrent connections.
virtual int32_t GetDefaultReceiveTimeout()
Get the default receive timeout.
int32_t GetNodeAnnouncePeriod()
Get the period between node announce.
virtual void SetDefaultHeartbeatPeriod(int32_t milliseconds)
Set the default heartbeat period.
void EnableNodeAnnounce(uint32_t flags=(IPNodeDiscoveryFlags_LINK_LOCAL))
Enable node discovery announce.
virtual void AddWebSocketAllowedOrigin(boost::string_ref origin)
Add a WebSocket allowed origin.
virtual void StartServerUsingPortSharer()
Start the server using the TCP port sharer.
void DisableNodeDiscoveryListening()
Disable node discovery listening.
virtual int32_t GetDefaultHeartbeatPeriod()
Get the default heartbeat period.
virtual void SetRequireTls(bool require_tls)
Set if all connections require TLS.
void SetNodeAnnouncePeriod(int32_t millis)
Set the period between node announce.
virtual int32_t GetMaxConnectionCount()
Get the maximum number of concurrent connections.
void EnableNodeDiscoveryListening(uint32_t flags=(IPNodeDiscoveryFlags_LINK_LOCAL))
Enable node discovery listening.
virtual bool IsSecurePeerIdentityVerified(uint32_t endpoint)
Check if specified endpoint peer is using TLS and has been verified using a certificate.
virtual void SetAcceptWebSockets(bool value)
Set if the transport will accept incoming HTTP websocket connections.
virtual bool GetDisableMessage4()
Get disable Message Format Version 4.
virtual int32_t GetDefaultConnectTimeout()
Get the default connect timeout.
virtual void SetDisableAsyncMessageIO(bool d)
Set if async message io is disabled.
virtual std::vector< std::string > GetWebSocketAllowedOrigins()
Get the currently configured WebSocket origins.
virtual void RemoveWebSocketAllowedOrigin(boost::string_ref origin)
Remove a previously added WebSocket origin.
virtual bool GetDisableAsyncMessageIO()
Get if async message io is disabled.
virtual bool IsTlsNodeCertificateLoaded()
Check if TLS certificate is loaded.
virtual void SetDisableMessage4(bool d)
Set disable Message Format Version 4.