summaryrefslogtreecommitdiffstats
path: root/NetworkDiscovery/networkdiscovery.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NetworkDiscovery/networkdiscovery.cpp')
-rw-r--r--NetworkDiscovery/networkdiscovery.cpp158
1 files changed, 145 insertions, 13 deletions
diff --git a/NetworkDiscovery/networkdiscovery.cpp b/NetworkDiscovery/networkdiscovery.cpp
index e9710fd..da2cb1d 100644
--- a/NetworkDiscovery/networkdiscovery.cpp
+++ b/NetworkDiscovery/networkdiscovery.cpp
@@ -2,6 +2,10 @@
#include "../common/fbgui.h"
+
+/**
+ * constructor
+ */
NetworkDiscovery::NetworkDiscovery(QObject *parent) {
_tag = "[nd:NetworkDiscovery]";
_server = new QLocalServer(this);
@@ -9,12 +13,39 @@ NetworkDiscovery::NetworkDiscovery(QObject *parent) {
+/**
+ * destructor
+ */
NetworkDiscovery::~NetworkDiscovery() {
}
+/**
+ * initialize all important class members and start the main work.
+ *
+ * @param serverIp
+ * the ip of the server with which we are testing the connectivity.
+ *
+ * @param userChoice
+ * true if the user wishes to have a user choice. true: the chooseInterfaceDialog will be showed.
+ *
+ * @param autoUp
+ * true if we want to "auto Up" all down interfaces.
+ *
+ * @param pathToLogFile
+ * the path to the log file.
+ *
+ * @param serverPath
+ * the path to the server socket (default value: DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default")
+ *
+ * @param pathToExe
+ * the path to the customdhcpcd exe. (default value: #define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default")
+ *
+ * @param args
+ * additional arguments for the customdhcpcd client. (default value: NULL)
+ */
void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp, QString pathToLogFile, QString serverPath, QString pathToExe,
QStringList* args) {
@@ -82,6 +113,12 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
+/**
+ * emits the addInterface signal for each interface name in _ifUpList
+ * and calls the runDHCPCD method.
+ * if the _ifUpList is empty, this method emits an abortBoot signal.
+ * connected to the readyForRun signal.
+ */
void NetworkDiscovery::slotReadyForRun() {
if (_ifUpList.size() > 0) {
foreach(QString i, _ifUpList) {
@@ -99,6 +136,11 @@ void NetworkDiscovery::slotReadyForRun() {
+/**
+ * only called if autoUp == true.
+ * check the IsRunning flag of each interface in the _ifDownList.
+ * connected to the timeout signal of the timer.
+ */
void NetworkDiscovery::checkForIsRunning() {
bool isRunning = false;
QList<QString> copyOfIfDownList(_ifDownList);
@@ -120,18 +162,35 @@ void NetworkDiscovery::checkForIsRunning() {
-int NetworkDiscovery::replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss) {
- return _networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET);
-}
-
-
-
+/**
+ * replace the default route. sets af automatically to AF_INET
+ *
+ * @param ifName
+ * interface name
+ *
+ * @param gateway
+ * gateway address
+ *
+ * @param mss
+ * mss value (i think this is the metric. in most cases this value is 0)
+ */
int NetworkDiscovery::ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss) {
return _networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET);
}
+/**
+ * replace the dhcp configuration with the manual config, entered by the user.
+ * if we can not establish a connection with the entered values, reset to the old
+ * dhcp values.
+ *
+ * @param result
+ * a json object formated string.
+ *
+ * @return
+ * 0 if everything ok
+ */
int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) {
QList<QString> dns;
dns.append(result["dns"].toString());
@@ -172,6 +231,15 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) {
+/**
+ * returns the gateway address, written into the dhcp config file.
+ *
+ * @param ifName
+ * name of the interface.
+ *
+ * @return
+ * gateway address as string.
+ */
QString NetworkDiscovery::getGatewayForInterface(QString ifName) {
interfaceconfiguration * ifConf = _ifcMap.value(ifName);
return ifConf->getGateway();
@@ -179,19 +247,24 @@ QString NetworkDiscovery::getGatewayForInterface(QString ifName) {
+/**
+ * reads the log file.
+ *
+ * @return the log file as one string.
+ */
QString NetworkDiscovery::readLogFile() {
// path to log file is in _pathToLogFile. initialized in initAndRun().
QString retval("the log file");
QFile logFile(_pathToLogFile);
if (logFile.exists()) {
if (logFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ while (!logFile.atEnd()) {
+ retval.append(logFile.readLine());
+ }
return retval;
}
}
- while (!logFile.atEnd()) {
- retval.append(logFile.readLine());
- }
- return retval;
+
}
@@ -202,6 +275,14 @@ QString NetworkDiscovery::readLogFile() {
* ================================================================================
**/
+
+
+/**
+ * searches for usable interfaces and puts them into a list.
+ * if the interface is down, put it in the _ifDownList, try to bring it up.
+ * else put it in the _ifUpList.
+ * usable interfaces are: can Broadcast, no loopback, no point to point, name is not in the BlackList,
+ */
void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
@@ -230,6 +311,10 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
+/**
+ * searches for usable interfaces which are up and running and put them into a list.
+ * usable interfaces are: can Broadcast, no loopback, no point to point, name is not in the BlackList,
+ */
void NetworkDiscovery::getListOfNetworkInterfaces() {
QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
@@ -253,6 +338,14 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
+/**
+ * not used so far. checks the carrier state using the sysfs library.
+ * if carrier = 1 ==> the interface is running.
+ * interfaces have to be up in order to get right results.
+ *
+ * @param interface
+ * name of the interface
+ */
bool NetworkDiscovery::checkCarrierState(QString interface) {
qDebug() << _tag << "check carrier state for interface " << interface;
@@ -295,6 +388,12 @@ bool NetworkDiscovery::checkCarrierState(QString interface) {
+/**
+ * call for every interface in the list the runDHCPCD method.
+ *
+ * @param interfaces
+ * list of interface names.
+ */
void NetworkDiscovery::runDHCPCD(QList<QString> &interfaces) {
foreach(QString nI, interfaces)
{
@@ -304,6 +403,12 @@ void NetworkDiscovery::runDHCPCD(QList<QString> &interfaces) {
+/**
+ * start a cdhcpcd process with the interface name as last argument.
+ *
+ * @param interface
+ * name of an interface.
+ */
void NetworkDiscovery::runDHCPCD(QString interface) {
emit updateStatusLabel(interface, "start DHCP");
_dhcpcdArguments.append(interface);
@@ -321,6 +426,20 @@ void NetworkDiscovery::runDHCPCD(QString interface) {
+/**
+ * checks the connectivity. tries to open a TCP connection to the
+ * server (see _serverIp). For this it adjusts the routing table.
+ * (sets the gateway of the interface as default gateway)
+ * Gateway is written into the dhcpcd config file of this interface.
+ * (see DEFAULT_INTERFACE_CONF_LOCATION "/var/tmp/conf_")
+ *
+ * @param ifName
+ * name of a interface.
+ *
+ * @return
+ * true: connection is possible
+ * false: connection not possible
+ */
bool NetworkDiscovery::checkConnectivity(QString ifName) {
int mss = 0;
@@ -359,6 +478,16 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) {
+/**
+ * try to open a tcp connection to the server
+ *
+ * @param server
+ * a ip address.
+ *
+ * @return
+ * true: connection is possible
+ * false: connection not possible
+ */
bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
// check connectivity via tcp connection
QTcpSocket *tcpSocket = new QTcpSocket(this);
@@ -374,7 +503,8 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
/**
- *
+ * connected to the new client arrived signal.
+ * connects the client readyRead signal with the handleNewInput slot.
*/
void NetworkDiscovery::handleNewConnection() {
qDebug() << _tag << "New Connection arrived";
@@ -390,7 +520,7 @@ void NetworkDiscovery::handleNewConnection() {
/**
- *
+ * called when a client disconnects.
*/
void NetworkDiscovery::handleClientDisconnect() {
QLocalSocket* socket = qobject_cast<QLocalSocket *> (QObject::sender());
@@ -405,7 +535,10 @@ void NetworkDiscovery::handleClientDisconnect() {
/**
+ * same function as handleNewInput() but with a client as parameter.
*
+ * @param cleint
+ * a client
*/
void NetworkDiscovery::handleNewInput(QLocalSocket * client) {
qDebug() << _tag << "last read before exit";
@@ -425,7 +558,6 @@ void NetworkDiscovery::handleNewInput(QLocalSocket * client) {
/**
- *
* This method is connected to the readyRead Signal of the QLocalSocket
* client.
* send an ACK to the client with every received message.