MIRA
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
RemoteModule Class Reference

Manages connections to other remote frameworks. More...

#include <fw/RemoteModule.h>

Classes

struct  AuthSettings
 Contains the authentication settings. More...
 

Public Types

enum  AuthMode { AUTH_NONE =0, AUTH_PASSWORD =1, AUTH_KEY =2 }
 Authentication mode. More...
 
typedef boost::shared_ptr< RemoteServerRemoteServerPtr
 
typedef std::list< RemoteConnectionProxyConnectionList
 
typedef std::map< UUID, RemoteConnectionProxyConnectionMap
 
typedef std::list< KnownFrameworkKnownFrameworkList
 
typedef std::list< ServiceLevelServiceLevelList
 
typedef std::map< std::string, ServiceLevelServiceLevelMap
 
typedef std::list< TypeServiceLevelTypeServiceLevelList
 
typedef std::map< Typename, TypeServiceLevelTypeServiceLevelMap
 

Public Member Functions

 RemoteModule ()
 
template<typename Reflector >
void reflect (Reflector &r)
 
void setPort (uint16 port)
 Set the port of our TCP server. More...
 
uint16 getPort () const
 Returns the port we listen on for incoming connections. More...
 
void enablePTPSync (bool enable=true)
 Enable/Disable synchronization of clocks via PTP. More...
 
bool isPTPSyncEnabled () const
 Returns true if PTP clock synchronization is enabled. More...
 
void enablePingTimeout (bool enable=true)
 Enable/Disable the ping timeout. More...
 
bool isPingTimeoutEnabled () const
 Returns true if ping timeout is enabled. More...
 
Duration getPingInterval () const
 Return the ping interval. More...
 
Duration getPingTimeout () const
 Return the ping timeout. More...
 
void setAuthGroup (const std::string &group)
 Sets the working group for this framework. More...
 
void setNoAuth ()
 Resets passwords and keys, and sets authentication to "none". More...
 
void setAuthPassword (const std::string &password)
 Enables the weak password based authentication mode and sets the password. More...
 
void setAuthKey (const std::string &key)
 Enables the strong RSA key based authentication mode and sets the key. More...
 
void setAuthKeyFile (const std::string &keyfile)
 Enables the strong RSA key based authentication mode and sets the key file. More...
 
const AuthSettingsgetAuthSettings () const
 Returns the current authentication settings. More...
 
void setExitOnDisconnectTimeout (Duration timeout)
 Sets the timeout to exit on disconnect, closes the framework if a connection is closed or can not be established for this time (set Duration::invalid() to disable) More...
 
const UUIDgetID () const
 Returns the unique ID of the remote framework. More...
 
ServiceLevel getServiceLevel (const std::string &channelID, const Typename &channelType)
 Get the level of service for given channel. More...
 
void start ()
 Start the remote framework. More...
 
void stop ()
 Stops the remote framework. More...
 
ScopedAccess< const ConnectionMap, boost::recursive_mutex > getConnections () const
 Returns the map of connections. More...
 
void addKnownFramework (const std::string &address)
 Adds the address of a framework to the list of known remote frameworks. More...
 
void addKnownFramework (const std::string &address, bool forcePTP, bool legacyBinaryFormat, bool monitorOnly, const Duration &delayConnect=Duration::seconds(0))
 Adds the address of a framework to the list of known remote frameworks. More...
 
void disconnectFramework (const std::string &frameworkID, bool autoReconnect=false)
 Disconnects framework with given ID (if it is connected). More...
 
void disconnectFrom (const std::string &address, bool autoReconnect=false)
 Disconnects framework with given address (if it is connected). More...
 
bool isFrameworkConnected (const std::string &frameworkID) const
 Returns if a framework with given ID is connected with us. More...
 
bool isConnectedTo (const std::string &address) const
 Returns if a framework with given address is connected to us. More...
 
void migrateUnitToThisFramework (const std::string &id)
 Requests that the unit with the given id migrates to this framework. More...
 
void updateIncomingStats (std::size_t size)
 Update statistics about incoming data. More...
 
void updateOutgoingStats (std::size_t size)
 Update statistics about outgoing data. More...
 
std::size_t getIncomingBytesPerSecond () const
 
std::size_t getOutgoingBytesPerSecond () const
 
Internal functions that should not be called directly but cannot
  be protected.
void publishAuthority (const AuthorityDescription &authority)
 Publishes an authority to all connected remote frameworks. More...
 
void unpublishAuthority (const AuthorityDescription &authority)
 Unpublishes an authority to all connected remote frameworks. More...
 
void publishService (const std::string &service)
 Publishes a service to all connected remote frameworks. More...
 
void unpublishService (const std::string &service)
 Unpublishes a service to all connected remote frameworks. More...
 
void publishChannel (const std::string &channelID, const Typename &type)
 Notify all connected remote frameworks about the fact that we have a publisher for the given channel. More...
 
void unpublishChannel (const std::string &channelID)
 Notify all connected remote frameworks about the fact that we have no longer a publisher for the given channel. More...
 
void subscribeChannel (const std::string &channelID)
 Notify all connected remote frameworks about the fact that we have a subscriber for the given channel. More...
 
void unsubscribeChannel (const std::string &channelID)
 Notify all connected remote frameworks that we no longer have a subscriber on the given channel. More...
 

Static Public Member Functions

static uint32 getCurrentVersion ()
 Returns the version of the communication protocol, that is supported by THIS framework. More...
 

Protected Member Functions

RemoteConnectionProxy createIncomingConnection ()
 
RemoteConnectionProxyaddPendingIncomingConnection (RemoteConnectionProxy &&proxy, bool start=true)
 Move a connection to the list of pending incoming connections. More...
 
void removePendingIncomingConnection (RemoteConnection *connection)
 If there is a proxy for connection in the list of pending incoming connections, remove it. More...
 
RemoteConnectionProxyaddPendingOutgoingConnection (RemoteConnectionProxy &&proxy, bool start=true)
 Move a connection to the list of pending outgoing connections. More...
 
void removePendingOutgoingConnection (RemoteConnection *connection)
 If there is a proxy for connection in the list of pending outgoing connections, remove it. More...
 
void onRemoteFrameworkDiscovered (const std::string &host, uint16 port, UUID id)
 Called when a new remote framework was discovered (e.g. More...
 
void storeConnection (RemoteConnectionProxy iConnection)
 Add a connection to our internal map of connections (and update the property node). More...
 
void eraseConnection (ConnectionMap::iterator it)
 Remove a connection from our internal map of connections (and update the property node). More...
 
bool onIncomingConnected (RemoteIncomingConnection *iConnection)
 Called whenever a client connects to our server. More...
 
void onIncomingDisconnected (RemoteIncomingConnection *iConnection)
 Called whenever a client disconnects from our server. More...
 
bool onOutgoingConnected (RemoteOutgoingConnectionBase *iConnection)
 Called whenever we connect to a remote server. More...
 
void onOutgoingDisconnected (RemoteOutgoingConnectionBase *iConnection)
 Called whenever one of our client disconnects from a remote server. More...
 
void process ()
 The main process method of the remote module. More...
 
void startDisconnectTimeout ()
 
void stopDisconnectTimeout ()
 
bool checkDisconnectTimeout ()
 

Protected Attributes

PerformanceStatistics mIncomingStats
 
PerformanceStatistics mOutgoingStats
 
uint32 mIncomingData
 
uint32 mOutgoingData
 
CyclicRunnable mCyclicRunnable
 
DiscoverServicePtr mDiscoverService
 
boost::thread mThread
 
uint16 mPort
 
bool mEnablePTPSync
 
bool mEnablePingTimeout
 
Duration mPingInterval
 
Duration mPingTimeout
 
uint16 mIOThreadCount
 
UUID mID
 
RemoteServerPtr mServer
 
ConnectionList mPendingOutgoingConnections
 
ConnectionList mPendingIncomingConnections
 
ConnectionMap mConnections
 
RemoteConnectionPool mRemoteConnectionPool
 
AuthSettings mAuthSettings
 
Duration mExitOnDisconnectTimeout
 
Time mDisconnectedSince
 
KnownFrameworkList mKnownFrameworks
 
ServiceLevelList mServiceLevels
 
TypeServiceLevelList mTypeServiceLevels
 
ServiceLevelMap mChannelServiceLevels
 
TypeServiceLevelMap mChannelTypeServiceLevels
 
boost::recursive_mutex mConnectionMutex
 

Friends

class RemoteConnection
 
class RemoteIncomingConnection
 
class RemoteOutgoingConnectionBase
 
class DiscoverService
 
class RemoteServer
 

Detailed Description

Manages connections to other remote frameworks.

Exchanges channel data, authorities, RPC calls and handles time synchronization between frameworks. The handshake protocol for establishing a connection between two frameworks is as follows:

No Authentication
Client Server
| |
| CONNECT_MSG: Version, Group, ClientIDs, AuthMode 0 |
|--------------------------------------------------->|
| |
| CONNECT_ACCEPT_MSG: ServerIDs Version |
|<---------------------------------------------------|
On error (e.g. wrong version, wrong authentication, etc)
| CONNECT_DENIED_MSG: message |
|<---------------------------------------------------|
Password Authentication
Client Server
| CONNECT_MSG: Version, ClientIDs, AuthMode 1, PW |
|--------------------------------------------------->|
| |
| CONNECT_ACCEPT_MSG: ServerIDs Version |
|<---------------------------------------------------|
On error
| CONNECT_DENIED_MSG: message |
|<---------------------------------------------------|
Key Authentication
Client Server
| CONNECT_MSG: Version, ClientIDs, AuthMode 2, Msg1 |
|--------------------------------------------------->|
| |
| SERVER_AUTH_MSG: Signed Msg1, Msg2 |
|<---------------------------------------------------|
| |
| CLIENT_AUTH_MSG: Signed Msg2 |
|--------------------------------------------------->|
| |
| CONNECT_ACCEPT_MSG: ServerIDs Version |
|<---------------------------------------------------|
On error
| CONNECT_DENIED_MSG: message |
|<---------------------------------------------------|
CONNECT_DENIED_MSG is sent from server only,
clients simply close the connection on error.

Member Typedef Documentation

◆ RemoteServerPtr

typedef boost::shared_ptr<RemoteServer> RemoteServerPtr

◆ ConnectionList

◆ ConnectionMap

◆ KnownFrameworkList

typedef std::list<KnownFramework> KnownFrameworkList

◆ ServiceLevelList

typedef std::list<ServiceLevel> ServiceLevelList

◆ ServiceLevelMap

typedef std::map<std::string, ServiceLevel> ServiceLevelMap

◆ TypeServiceLevelList

◆ TypeServiceLevelMap

Member Enumeration Documentation

◆ AuthMode

enum AuthMode

Authentication mode.

Enumerator
AUTH_NONE 
AUTH_PASSWORD 
AUTH_KEY 

Constructor & Destructor Documentation

◆ RemoteModule()

Member Function Documentation

◆ reflect()

void reflect ( Reflector &  r)
inline

◆ getCurrentVersion()

static uint32 getCurrentVersion ( )
static

Returns the version of the communication protocol, that is supported by THIS framework.

◆ setPort()

void setPort ( uint16  port)
inline

Set the port of our TCP server.

If not specified it uses auto port

Parameters
[in]portThe port

◆ getPort()

uint16 getPort ( ) const

Returns the port we listen on for incoming connections.

◆ enablePTPSync()

void enablePTPSync ( bool  enable = true)
inline

Enable/Disable synchronization of clocks via PTP.

◆ isPTPSyncEnabled()

bool isPTPSyncEnabled ( ) const
inline

Returns true if PTP clock synchronization is enabled.

◆ enablePingTimeout()

void enablePingTimeout ( bool  enable = true)
inline

Enable/Disable the ping timeout.

◆ isPingTimeoutEnabled()

bool isPingTimeoutEnabled ( ) const
inline

Returns true if ping timeout is enabled.

◆ getPingInterval()

Duration getPingInterval ( ) const
inline

Return the ping interval.

◆ getPingTimeout()

Duration getPingTimeout ( ) const
inline

Return the ping timeout.

◆ setAuthGroup()

void setAuthGroup ( const std::string &  group)

Sets the working group for this framework.

The framework will be able to connect to other frameworks within the same group only. The default group is "".

◆ setNoAuth()

void setNoAuth ( )

Resets passwords and keys, and sets authentication to "none".

◆ setAuthPassword()

void setAuthPassword ( const std::string &  password)

Enables the weak password based authentication mode and sets the password.

Previously set RSA keys will be dropped.

◆ setAuthKey()

void setAuthKey ( const std::string &  key)

Enables the strong RSA key based authentication mode and sets the key.

A previously set password will be dropped.

◆ setAuthKeyFile()

void setAuthKeyFile ( const std::string &  keyfile)

Enables the strong RSA key based authentication mode and sets the key file.

A previously set password will be dropped.

◆ getAuthSettings()

const AuthSettings& getAuthSettings ( ) const

Returns the current authentication settings.

◆ setExitOnDisconnectTimeout()

void setExitOnDisconnectTimeout ( Duration  timeout)
inline

Sets the timeout to exit on disconnect, closes the framework if a connection is closed or can not be established for this time (set Duration::invalid() to disable)

◆ getID()

const UUID& getID ( ) const
inline

Returns the unique ID of the remote framework.

◆ getServiceLevel()

ServiceLevel getServiceLevel ( const std::string &  channelID,
const Typename channelType 
)

Get the level of service for given channel.

◆ start()

void start ( )

Start the remote framework.

Including the server.

◆ stop()

void stop ( )

Stops the remote framework.

◆ getConnections()

ScopedAccess<const ConnectionMap, boost::recursive_mutex> getConnections ( ) const

Returns the map of connections.

◆ addKnownFramework() [1/2]

void addKnownFramework ( const std::string &  address)

Adds the address of a framework to the list of known remote frameworks.

This module will try to connect to all known frameworks. It will also reconnect on connection loss.

Parameters
[in]addressAddress of the remote framework in the form Host:Port.

◆ addKnownFramework() [2/2]

void addKnownFramework ( const std::string &  address,
bool  forcePTP,
bool  legacyBinaryFormat,
bool  monitorOnly,
const Duration delayConnect = Duration::seconds(0) 
)

Adds the address of a framework to the list of known remote frameworks.

This module will try to connect to all known frameworks. It will also reconnect on connection loss.

Parameters
[in]addressAddress of the remote framework in the form Host:Port.
[in]forcePTPForce PTP time sync
[in]legacyBinaryFormatIf true, encode all binary data for remote connection using legacy serializer, thus it can communicate with legacy framework.
[in]monitorOnlyIf true, do not publish local channels, services and authorities to remote.
[in]delayConnectWait for this duration before trying to connect.

◆ disconnectFramework()

void disconnectFramework ( const std::string &  frameworkID,
bool  autoReconnect = false 
)

Disconnects framework with given ID (if it is connected).

If autoReconnect is false the framework is removed from the list of known remote frameworks so there will be no reconnect.

◆ disconnectFrom()

void disconnectFrom ( const std::string &  address,
bool  autoReconnect = false 
)

Disconnects framework with given address (if it is connected).

If autoReconnect is false the framework is removed from the list of known remote frameworks so there will be no reconnect.

Parameters
[in]addressAddress of the remote framework in the form Host:Port.
[in]autoReconnectIf true there will be a reconnect

◆ isFrameworkConnected()

bool isFrameworkConnected ( const std::string &  frameworkID) const

Returns if a framework with given ID is connected with us.

◆ isConnectedTo()

bool isConnectedTo ( const std::string &  address) const

Returns if a framework with given address is connected to us.

Parameters
[in]addressAddress of the remote framework in the form Host:Port.

◆ migrateUnitToThisFramework()

void migrateUnitToThisFramework ( const std::string &  id)

Requests that the unit with the given id migrates to this framework.

If the unit is already located in this framework nothing happens. Otherwise the framework will ask all connected frameworks if they run a unit with the given id and if a request is sent to move the unit into this framework. The remote framework will serialize the unit, destroy it and send it to this framework where it is created out of its serialized state.

◆ publishAuthority()

void publishAuthority ( const AuthorityDescription authority)

Publishes an authority to all connected remote frameworks.

◆ unpublishAuthority()

void unpublishAuthority ( const AuthorityDescription authority)

Unpublishes an authority to all connected remote frameworks.

◆ publishService()

void publishService ( const std::string &  service)

Publishes a service to all connected remote frameworks.

◆ unpublishService()

void unpublishService ( const std::string &  service)

Unpublishes a service to all connected remote frameworks.

◆ publishChannel()

void publishChannel ( const std::string &  channelID,
const Typename type 
)

Notify all connected remote frameworks about the fact that we have a publisher for the given channel.

All frameworks will subscribe if they have a subscriber for this channel

Parameters
[in]channelIDThe channel we have a publisher for.
[in]typeThe typename of the channels type.

◆ unpublishChannel()

void unpublishChannel ( const std::string &  channelID)

Notify all connected remote frameworks about the fact that we have no longer a publisher for the given channel.

All frameworks will unsubscribe if they were subscribed to that channel.

Parameters
[in]channelIDThe channel we have no more publishers for.

◆ subscribeChannel()

void subscribeChannel ( const std::string &  channelID)

Notify all connected remote frameworks about the fact that we have a subscriber for the given channel.

Subscribes on all remote frameworks that have a publisher for this channel. Remote frameworks will notify us on data changes.

Parameters
[in]channelIDThe channel we have a subscriber for.

◆ unsubscribeChannel()

void unsubscribeChannel ( const std::string &  channelID)

Notify all connected remote frameworks that we no longer have a subscriber on the given channel.

We will not longer receive updates on that channel.

Parameters
[in]channelIDThe channel we have no more subscribers for.

◆ updateIncomingStats()

void updateIncomingStats ( std::size_t  size)

Update statistics about incoming data.

◆ updateOutgoingStats()

void updateOutgoingStats ( std::size_t  size)

Update statistics about outgoing data.

◆ getIncomingBytesPerSecond()

std::size_t getIncomingBytesPerSecond ( ) const

◆ getOutgoingBytesPerSecond()

std::size_t getOutgoingBytesPerSecond ( ) const

◆ createIncomingConnection()

RemoteConnectionProxy createIncomingConnection ( )
protected

◆ addPendingIncomingConnection()

RemoteConnectionProxy& addPendingIncomingConnection ( RemoteConnectionProxy &&  proxy,
bool  start = true 
)
protected

Move a connection to the list of pending incoming connections.

Parameters
[in]startif true, call proxy->start()

◆ removePendingIncomingConnection()

void removePendingIncomingConnection ( RemoteConnection connection)
protected

If there is a proxy for connection in the list of pending incoming connections, remove it.

◆ addPendingOutgoingConnection()

RemoteConnectionProxy& addPendingOutgoingConnection ( RemoteConnectionProxy &&  proxy,
bool  start = true 
)
protected

Move a connection to the list of pending outgoing connections.

Parameters
[in]startif true, call proxy->start()

◆ removePendingOutgoingConnection()

void removePendingOutgoingConnection ( RemoteConnection connection)
protected

If there is a proxy for connection in the list of pending outgoing connections, remove it.

◆ onRemoteFrameworkDiscovered()

void onRemoteFrameworkDiscovered ( const std::string &  host,
uint16  port,
UUID  id 
)
protected

Called when a new remote framework was discovered (e.g.

via multi cast)

◆ storeConnection()

void storeConnection ( RemoteConnectionProxy  iConnection)
protected

Add a connection to our internal map of connections (and update the property node).

Parameters
[in]iConnectionThe connection pointer

◆ eraseConnection()

void eraseConnection ( ConnectionMap::iterator  it)
protected

Remove a connection from our internal map of connections (and update the property node).

Parameters
[in]itIterator to the entry to be removed

◆ onIncomingConnected()

bool onIncomingConnected ( RemoteIncomingConnection iConnection)
protected

Called whenever a client connects to our server.

Parameters
[in]iConnectionThe connection pointer
Returns
true if connection is accepted, false if not

◆ onIncomingDisconnected()

void onIncomingDisconnected ( RemoteIncomingConnection iConnection)
protected

Called whenever a client disconnects from our server.

Parameters
[in]iConnectionThe connection pointer

◆ onOutgoingConnected()

bool onOutgoingConnected ( RemoteOutgoingConnectionBase iConnection)
protected

Called whenever we connect to a remote server.

Parameters
[in]iConnectionThe connection pointer
Returns
true if connection is accepted, false if not

◆ onOutgoingDisconnected()

void onOutgoingDisconnected ( RemoteOutgoingConnectionBase iConnection)
protected

Called whenever one of our client disconnects from a remote server.

Parameters
[in]iConnectionThe connection pointer

◆ process()

void process ( )
protected

The main process method of the remote module.

Tries to connect to known remote frameworks and does time synchronization between frameworks.

◆ startDisconnectTimeout()

void startDisconnectTimeout ( )
protected

◆ stopDisconnectTimeout()

void stopDisconnectTimeout ( )
protected

◆ checkDisconnectTimeout()

bool checkDisconnectTimeout ( )
protected

Friends And Related Function Documentation

◆ RemoteConnection

friend class RemoteConnection
friend

◆ RemoteIncomingConnection

friend class RemoteIncomingConnection
friend

◆ RemoteOutgoingConnectionBase

friend class RemoteOutgoingConnectionBase
friend

◆ DiscoverService

friend class DiscoverService
friend

◆ RemoteServer

friend class RemoteServer
friend

Member Data Documentation

◆ mIncomingStats

PerformanceStatistics mIncomingStats
protected

◆ mOutgoingStats

PerformanceStatistics mOutgoingStats
protected

◆ mIncomingData

uint32 mIncomingData
protected

◆ mOutgoingData

uint32 mOutgoingData
protected

◆ mCyclicRunnable

CyclicRunnable mCyclicRunnable
protected

◆ mDiscoverService

DiscoverServicePtr mDiscoverService
protected

◆ mThread

boost::thread mThread
protected

◆ mPort

uint16 mPort
protected

◆ mEnablePTPSync

bool mEnablePTPSync
protected

◆ mEnablePingTimeout

bool mEnablePingTimeout
protected

◆ mPingInterval

Duration mPingInterval
protected

◆ mPingTimeout

Duration mPingTimeout
protected

◆ mIOThreadCount

uint16 mIOThreadCount
protected

◆ mID

UUID mID
protected

◆ mServer

RemoteServerPtr mServer
protected

◆ mPendingOutgoingConnections

ConnectionList mPendingOutgoingConnections
protected

◆ mPendingIncomingConnections

ConnectionList mPendingIncomingConnections
protected

◆ mConnections

ConnectionMap mConnections
protected

◆ mRemoteConnectionPool

RemoteConnectionPool mRemoteConnectionPool
protected

◆ mAuthSettings

AuthSettings mAuthSettings
protected

◆ mExitOnDisconnectTimeout

Duration mExitOnDisconnectTimeout
protected

◆ mDisconnectedSince

Time mDisconnectedSince
protected

◆ mKnownFrameworks

KnownFrameworkList mKnownFrameworks
protected

◆ mServiceLevels

ServiceLevelList mServiceLevels
protected

◆ mTypeServiceLevels

TypeServiceLevelList mTypeServiceLevels
protected

◆ mChannelServiceLevels

ServiceLevelMap mChannelServiceLevels
protected

◆ mChannelTypeServiceLevels

TypeServiceLevelMap mChannelTypeServiceLevels
protected

◆ mConnectionMutex

boost::recursive_mutex mConnectionMutex
mutableprotected

The documentation for this class was generated from the following file: