Home · Modules · All Classes · All Namespaces
Public Member Functions | Protected Member Functions | List of all members
Tp::StreamTubeClient::TcpSourceAddressGenerator Class Referenceabstract

The StreamTubeClient::TcpSourceAddressGenerator abstract interface allows using socket source address/port based access control for connecting to tubes accepted as TCP sockets. More...

#include <TelepathyQt/StreamTubeClient>

Public Member Functions

virtual QPair< QHostAddress, quint16 > nextSourceAddress (const AccountPtr &account, const IncomingStreamTubeChannelPtr &tube)=0
 

Protected Member Functions

virtual ~TcpSourceAddressGenerator ()
 

Detailed Description

The StreamTubeClient::TcpSourceAddressGenerator abstract interface allows using socket source address/port based access control for connecting to tubes accepted as TCP sockets.

By default, every application on the local computer is allowed to connect to the socket created by the protocol backend as the local endpoint of the tube. This is not always desirable, as that includes even other users.

Note that since every TCP connection must have an unique source address, only one simultaneous connection can be made through each tube for which this type of access control has been used.

Constructor & Destructor Documentation

◆ ~TcpSourceAddressGenerator()

Tp::StreamTubeClient::TcpSourceAddressGenerator::~TcpSourceAddressGenerator ( )
inlineprotectedvirtual

Class destructor. Protected, because StreamTubeClient never deletes a TcpSourceAddressGenerator passed to it.

Member Function Documentation

◆ nextSourceAddress()

QPair< QHostAddress, quint16 > Tp::StreamTubeClient::TcpSourceAddressGenerator::nextSourceAddress ( const AccountPtr &  account,
const IncomingStreamTubeChannelPtr &  tube 
)
pure virtual

Return the source address from which connections will be allowed to the given tube once it has been accepted.

Returning the pair (QHostAddress::Any, 0) (or alternatively (QHostAddress::AnyIPv4, 0) in Qt5) makes the protocol backend allow connections from any address on the local computer. This can be used on a tube-by-tube basis if for some tubes its known that multiple connections need to be made, so a single source address doesn't suffice.

The account and tube parameters can be inspected to make the decision; typically by looking at the tube's service type, parameters and/or initiator contact.

The general pattern for implementing this method is:

  1. Determine whether tube needs to allow multiple connections, and if so, skip source address access control completely
  2. Otherwise, create a socket and bind it to a free address
  3. Return this socket's address
  4. Keep the socket bound so that no other process can (accidentally or maliciously) take the address until it's used to connect to the tube when StreamTubeClient::tubeAcceptedAsTcp() is emitted for the tube
Parameters
accountThe account from which the tube originates.
tubeThe tube channel which is going to be accepted by the StreamTubeClient.
Returns
A pair containing the host address and port allowed to connect.