ArnLib
4.0.x
Active Registry Network
|
Class for connecting to an Arn Server. More...
#include <ArnClient.hpp>
Classes | |
struct | HostAddrPort |
Public Types | |
typedef ArnClientConnectStat | ConnectStat |
typedef Arn::ClientSyncMode | SyncMode |
typedef QList< HostAddrPort > | HostList |
Signals | |
void | tcpError (const QString &errorText, QAbstractSocket::SocketError socketError) |
Signal emitted when a connection tcp error occur. More... | |
void | tcpConnected (const QString &arnHost, quint16 port) |
Signal emitted when the tcp connection is successfull. More... | |
void | tcpDisConnected () |
Signal emitted when the tcp connection is broken (has been successfull). More... | |
void | connectionStatusChanged (int status, int curPrio) |
Signal emitted when the connection status is changed. More... | |
void | loginRequired (int contextCode) |
Signal emitted when the remote ArnServer demands a login. More... | |
void | killRequested () |
Signal emitted when the server request this client to kill its connection. More... | |
void | chatReceived (const QString &text, int prioType) |
Signal emitted when a chat message is received from the server. More... | |
Public Member Functions | |
ArnClient (QObject *parent=arnNullptr) | |
~ArnClient () | |
void | clearArnList (int prioFilter=-1) |
Clear the Arn connection list. More... | |
HostList | arnList (int prioFilter=-1) const |
Return the Arn connection list. More... | |
void | addToArnList (const QString &arnHost, quint16 port=0, int prio=0) |
Add an Arn Server to the Arn connection list. More... | |
void | connectToArnList () |
Connect to an Arn Server in the Arn connection list. More... | |
void | connectToArn (const QString &arnHost, quint16 port=0) |
Connect to an Arn Server More... | |
void | disconnectFromArn () |
Disconnect from an Arn Server More... | |
void | loginToArn (const QString &userName, const QString &password, Arn::Allow allow=Arn::Allow::All) |
Login to an Arn Server More... | |
void | loginToArnHashed (const QString &userName, const QString &passwordHashed, Arn::Allow allow=Arn::Allow::All) |
Login to an Arn Server using hashed password. More... | |
void | close () |
Close sharing with an Arn Server More... | |
bool | setMountPoint (const QString &path) |
Set the sharing tree path. More... | |
bool | addMountPoint (const QString &localPath, const QString &remotePath=QString()) |
Add a sharing tree path. More... | |
bool | removeMountPoint (const QString &localPath) |
Remove a sharing tree path. More... | |
ConnectStat | connectStatus () const |
Return the Arn connection status. More... | |
void | setAutoConnect (bool isAuto, int retryTime=2) |
Set automatic reconnect. More... | |
void | registerClient (const QString &id) |
Register this client to be avaiable with id. More... | |
QString | id () const |
Get the id of this client. More... | |
int | receiveTimeout () const |
Get receive data timeout (base time) More... | |
void | setReceiveTimeout (int receiveTimeout) |
Set receive data timeout (base time) More... | |
bool | isDemandLogin () const |
Get clients demand for login. More... | |
void | setDemandLogin (bool isDemandLogin) |
Set clients demand for login. More... | |
SyncMode | syncMode () const |
Get ClientSyncMode. More... | |
void | setSyncMode (SyncMode syncMode) |
Set ClientSyncMode. More... | |
QStringList | freePaths () const |
Returns current list of freePaths. More... | |
void | setWhoIAm (const Arn::XStringMap &whoIAmXsm) |
Set clients human readable identification information. More... | |
Arn::XStringMap | remoteWhoIAm () const |
Returns remote side (server) readable identification information. More... | |
bool | isReContact () const |
Is last TCP connection a reContact. More... | |
bool | isReConnect () const |
Is last Arn Connection a reConnect. More... | |
void | chatSend (const QString &text, int prioType) |
Send chat message to server. More... | |
void | abortKillRequest () |
Send abort kill requst to server. More... | |
bool | getTraffic (quint64 &in, quint64 &out) const |
Get traffic metrics. More... | |
Static Public Member Functions | |
static ArnClient * | getClient (const QString &id) |
Get a client by its id. More... | |
static QString | passwordHash (const QString &password) |
Generate a hashed password from clear text password. More... | |
Class for connecting to an Arn Server.
About Sharing Arn Data Objects About Sync Rules
Connection can be made to a specific Host by connectToArn(). It's also possible to define an Arn Connection List. Each host address is added to the list with a priority. The priority is used to control the order at which the host addresses will be tried for connection. Lowest priority number is tried first. Connection trials are started with connectToArnlList(). The priority can also be used for selction in clearArnList() and arnList().
Example usage
Definition at line 104 of file ArnClient.hpp.
Definition at line 110 of file ArnClient.hpp.
typedef QList<HostAddrPort> ArnClient::HostList |
Definition at line 121 of file ArnClient.hpp.
Definition at line 111 of file ArnClient.hpp.
|
explicit |
Definition at line 253 of file ArnClient.cpp.
ArnClient::~ArnClient | ( | ) |
Definition at line 269 of file ArnClient.cpp.
void ArnClient::abortKillRequest | ( | ) |
Send abort kill requst to server.
The server can request client to kill connection. This method is used to request an abort of the kill request. This method can be called any time but it will only be considered during a kill countdown.
Definition at line 621 of file ArnClient.cpp.
bool ArnClient::addMountPoint | ( | const QString & | localPath, |
const QString & | remotePath = QString() |
||
) |
Add a sharing tree path.
Mountpoint is an association to the similarity of mounting a "remote filesystem". In Arn, the remote "file system" can be at different sub path than the local mountpoint, e.g. a client having mountpoint local="/a/b/" remote="/r/" and opening an Arn Data Object at "/a/b/c" will have the object c shared with the server at its path "/r/c". However if remotePath is not specified, it will be same as localPath. In the above example, the c object will then be shared with the server at its path "/a/b/c".
[in] | localPath | is the local sharing tree. |
[in] | remotePath | is the remote sharing tree. If empty, same as localPath. |
false | if error. |
Definition at line 385 of file ArnClient.cpp.
void ArnClient::addToArnList | ( | const QString & | arnHost, |
quint16 | port = 0 , |
||
int | prio = 0 |
||
) |
Add an Arn Server to the Arn connection list.
[in] | arnHost | is host name or ip address, e.g. "192.168.1.1". |
[in] | port | is the host port, 0 gives Arn::defaultTcpPort. |
[in] | prio | gives the sorting (connection) order and can be used for selection filter. |
Definition at line 293 of file ArnClient.cpp.
ArnClient::HostList ArnClient::arnList | ( | int | prioFilter = -1 | ) | const |
Return the Arn connection list.
[in] | prioFilter | selects hosts in the list with this pri. Default -1 selects all. |
the | selected Arn connection list. |
Definition at line 285 of file ArnClient.cpp.
|
signal |
Signal emitted when a chat message is received from the server.
[in] | text | is the message. |
[in] | prioType | is the priority of the message (1=Hi 2=Normal). |
void ArnClient::chatSend | ( | const QString & | text, |
int | prioType | ||
) |
Send chat message to server.
This is used for a chat session between client and server.
[in] | text | is the message. |
[in] | prioType | is the priority of the message (1=Hi 2=Normal). |
Definition at line 611 of file ArnClient.cpp.
void ArnClient::clearArnList | ( | int | prioFilter = -1 | ) |
Clear the Arn connection list.
Typically used to start making a new Arn connection list.
[in] | prioFilter | selects hosts in the list with this pri, to be removed. Default -1 removes all. |
Definition at line 277 of file ArnClient.cpp.
void ArnClient::close | ( | ) |
Close sharing with an Arn Server
Stop sharing Arn objects with the Arn server. Similar to disconnectFromArn(). All pending data is written before disconnect. No syncronized Arn objects are remembered. This implies that it's not possible to continue previous session. This function is aimed at later starting a new session from scratch.
Auto connection is also disabled.
Definition at line 354 of file ArnClient.cpp.
|
signal |
Signal emitted when the connection status is changed.
[in] | status | is the new connection status ArnClient::ConnectStat. |
[in] | curPrio | is the current priority of the connection in ArnList |
ArnClient::ConnectStat ArnClient::connectStatus | ( | ) | const |
Return the Arn connection status.
the | Arn connection status. |
Definition at line 364 of file ArnClient.cpp.
void ArnClient::connectToArn | ( | const QString & | arnHost, |
quint16 | port = 0 |
||
) |
Connect to an Arn Server
[in] | arnHost | is host name or ip address, e.g. "192.168.1.1". |
[in] | port | is the host port, 0 gives Arn::defaultTcpPort. |
Definition at line 314 of file ArnClient.cpp.
void ArnClient::connectToArnList | ( | ) |
Connect to an Arn Server in the Arn connection list.
Will scan the connection list once until a successful connection is made. If the end of the list is reached without connection, the tcpError() signal
Definition at line 301 of file ArnClient.cpp.
void ArnClient::disconnectFromArn | ( | ) |
Disconnect from an Arn Server
Force disconnect from the Arn server, similar behaviour to losing connection. All pending data is written before disconnect. All Arn objects that has been setup to be synronized is still kept. This implies that it's possible to continue previous session by just connecting to the Arn server again.
Auto connection is also disabled.
Definition at line 327 of file ArnClient.cpp.
QStringList ArnClient::freePaths | ( | ) | const |
Returns current list of freePaths.
A freePath can be used even if not logged in to an ArnServer that demands login. Also all children below freePath is free to use. Usage is restricted to read operations and alike from ArnServer to ArnClient. The list of freePaths is used to enable the operation requests to be transfered to ArnServer. ArnServer still decides what's allowed. The list is automatically transfered from ArnServer to ArnClient during the negotiation phase.
Definition at line 563 of file ArnClient.cpp.
|
static |
Get a client by its id.
[in] | id | if "" will always return 0. |
Definition at line 492 of file ArnClient.cpp.
bool ArnClient::getTraffic | ( | quint64 & | in, |
quint64 & | out | ||
) | const |
Get traffic metrics.
true | if ok. |
[out] | in | is the clients received number of bytes. |
[out] | out | is the clients sent number of bytes. |
Definition at line 629 of file ArnClient.cpp.
QString ArnClient::id | ( | ) | const |
Get the id of this client.
Definition at line 498 of file ArnClient.cpp.
bool ArnClient::isDemandLogin | ( | ) | const |
Get clients demand for login.
If any of server or client demand login, it must be used.
true | if client demand login. |
Definition at line 522 of file ArnClient.cpp.
bool ArnClient::isReConnect | ( | ) | const |
Is last Arn Connection a reConnect.
ReConnect occurs if an Arn connection is successful, then lost and then restored due to autoConnect. Successful Arn connection gives a state change to ConnectStat::Connected.
true | if this is a reConnect. |
Definition at line 595 of file ArnClient.cpp.
bool ArnClient::isReContact | ( | ) | const |
Is last TCP connection a reContact.
ReContact occurs if a TCP connection is successful, then lost and then restored due to autoConnect. Successful TCP connection gives a state change to ConnectStat::Negotiating.
true | if this is a reContact. |
Definition at line 587 of file ArnClient.cpp.
|
signal |
Signal emitted when the server request this client to kill its connection.
This request should normally be obeyed by the client. I.e. it should usually result in a call to close().
|
signal |
Signal emitted when the remote ArnServer demands a login.
When this signal is emitted, a call to loginToArn() must be done to complete the connection process.
[in] | contextCode | is the situation context as: 0 = First login trial 1 = Server deny, login retry 2 = Client deny, server gave bad password (fake server?) 3 = Client deny, server not support login 4 = Client deny, server bad negotiate sequence |
void ArnClient::loginToArn | ( | const QString & | userName, |
const QString & | password, | ||
Arn::Allow | allow = Arn::Allow::All |
||
) |
Login to an Arn Server
This routine must be called when the signal loginRequired() is emitted. Otherwise the client will not be fully conected to the server, ie the apropriate access privileges will not be setup at server and client. If a reconnect occurs, usually due to tcp breakage, login process is handled automatically by ArnLib using the last used login credentials. If this automatical login is failed, signal loginRequired() is emitted.
[in] | userName | |
[in] | password | |
[in] | allow | is the permissions for the server actions to this client. |
Definition at line 338 of file ArnClient.cpp.
void ArnClient::loginToArnHashed | ( | const QString & | userName, |
const QString & | passwordHashed, | ||
Arn::Allow | allow = Arn::Allow::All |
||
) |
Login to an Arn Server using hashed password.
This behaves exactly as loginToArn(), exept for password being hashed. The hashed password which can be generated by ArnClient::passwordHash() (see also ArnBrowser Settings).
[in] | userName | |
[in] | passwordHashed | |
[in] | allow | is the permissions for the server actions to this client. |
Definition at line 345 of file ArnClient.cpp.
|
static |
Generate a hashed password from clear text password.
[in] | password | is the clear text password. |
Definition at line 557 of file ArnClient.cpp.
int ArnClient::receiveTimeout | ( | ) | const |
Get receive data timeout (base time)
Definition at line 506 of file ArnClient.cpp.
void ArnClient::registerClient | ( | const QString & | id | ) |
Register this client to be avaiable with id.
When instantiating an ArnClient, it's always registered as id = "std", if that's not taken by another client.
Any previous registration of id for this client will be released when using registerClient().
[in] | id | must not be "". |
Definition at line 481 of file ArnClient.cpp.
Arn::XStringMap ArnClient::remoteWhoIAm | ( | ) | const |
Returns remote side (server) readable identification information.
This is used to identify the server side in session.
Definition at line 579 of file ArnClient.cpp.
bool ArnClient::removeMountPoint | ( | const QString & | localPath | ) |
Remove a sharing tree path.
Only the mount point will be removed, i.e any new Arn Data Objects created within the localPath tree will not be shared with the server. However already existing objects will not be affected and is still shared with the server.
[in] | localPath | is the sharing tree to be removed. Only affects newly created objects. |
false | if error. |
Definition at line 440 of file ArnClient.cpp.
void ArnClient::setAutoConnect | ( | bool | isAuto, |
int | retryTime = 2 |
||
) |
Set automatic reconnect.
If connectToArnList() is used, this auto connect funtionality starts every time after the last host in the Arn connection list has failed. The connection list is retried after retryTime. When using connectToArn(), there will be a retryTime delay between each reConnect to the host.
[in] | isAuto | true if using auto reconnect |
[in] | retryTime | is the time between attempts in seconds |
Definition at line 472 of file ArnClient.cpp.
void ArnClient::setDemandLogin | ( | bool | isDemandLogin | ) |
Set clients demand for login.
If any of server or client demand login, it must be used.
[in] | isDemandLogin | true if client demand login. |
Definition at line 530 of file ArnClient.cpp.
bool ArnClient::setMountPoint | ( | const QString & | path | ) |
Set the sharing tree path.
For campatibility, this can only set one mount point and with same local as remote path. If exactly one mount point exist, it will be removed before this new one is added.
[in] | path | is the sharing tree. |
false | if error. |
Definition at line 372 of file ArnClient.cpp.
void ArnClient::setReceiveTimeout | ( | int | receiveTimeout | ) |
Set receive data timeout (base time)
The timeout deals with no received data. This base time T is used as follows: time passed == T/2, send a dummy request to ArnServer time passed == T, signal status ConnectStat::Stopped time passed == 3*T, abort ArnClient tcp socket.
Default base time T is set to 10 seconds.
[in] | receiveTimeout | is the base time T in seconds. 0 = off (no timeout). |
Definition at line 514 of file ArnClient.cpp.
void ArnClient::setSyncMode | ( | ArnClient::SyncMode | syncMode | ) |
Set ClientSyncMode.
Default for ArnClient is StdAutoMaster.
[in] | syncMode | the ClientSyncMode to be set. |
Definition at line 546 of file ArnClient.cpp.
void ArnClient::setWhoIAm | ( | const Arn::XStringMap & | whoIAmXsm | ) |
Set clients human readable identification information.
This is used to identify the client session. Standard keys to use are: Agent, UserName, Contact, Location.
Example usage
[in] | whoIAmXsm | contains the information. |
Definition at line 571 of file ArnClient.cpp.
ArnClient::SyncMode ArnClient::syncMode | ( | ) | const |
Get ClientSyncMode.
Default for ArnClient is StdAutoMaster.
ClientSyncMode. |
Definition at line 538 of file ArnClient.cpp.
|
signal |
Signal emitted when the tcp connection is successfull.
[in] | arnHost | is host name or ip address, e.g. "192.168.1.1". |
[in] | port | is the host port, e.g. 2022. |
|
signal |
Signal emitted when the tcp connection is broken (has been successfull).
|
signal |
Signal emitted when a connection tcp error occur.
[in] | errorText | is the human readable description of the error. |
[in] | socketError | is the error from tcp socket, see Qt doc. |