Merge pull request #2495 from csoler/v0.6-FriendServer

V0.6 friend server
This commit is contained in:
csoler 2022-01-10 20:14:58 +01:00 committed by GitHub
commit b847caa11b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 3009 additions and 688 deletions

View file

@ -0,0 +1,171 @@
/*******************************************************************************
* gui/FriendServer.cpp *
* *
* Copyright (c) 2021 Retroshare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include <QTimer>
#include <QMovie>
#include <QTcpSocket>
#include "retroshare/rsfriendserver.h"
#include "retroshare/rstor.h"
#include "util/qtthreadsutils.h"
#include "gui/common/FilesDefs.h"
#include "FriendServerControl.h"
#include <iostream>
#define ICON_STATUS_UNKNOWN ":/images/ledoff1.png"
#define ICON_STATUS_OK ":/images/ledon1.png"
/** Constructor */
FriendServerControl::FriendServerControl(QWidget *parent)
: QWidget(parent)
{
/* Invoke the Qt Designer generated object setup routine */
setupUi(this);
if(!rsFriendServer)
{
setEnabled(false);
return;
}
mConnectionCheckTimer = new QTimer;
// init values
torServerFriendsToRequest_SB->setValue(rsFriendServer->friendsToRequest());
torServerAddress_LE->setText(QString::fromStdString(rsFriendServer->friendsServerAddress().c_str()));
torServerPort_SB->setValue(rsFriendServer->friendsServerPort());
// connect slignals/slots
QObject::connect(friendServerOnOff_CB,SIGNAL(toggled(bool)),this,SLOT(onOnOffClick(bool)));
QObject::connect(torServerFriendsToRequest_SB,SIGNAL(valueChanged(int)),this,SLOT(onFriendsToRequestChanged(int)));
QObject::connect(torServerAddress_LE,SIGNAL(textChanged(const QString&)),this,SLOT(onOnionAddressEdit(const QString&)));
QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress()));
mCheckingServerMovie = new QMovie(":/images/loader/circleball-16.gif");
serverStatusCheckResult_LB->setMovie(mCheckingServerMovie);
updateFriendServerStatusIcon(false);
updateTorProxyInfo();
}
void FriendServerControl::updateTorProxyInfo()
{
std::string friend_proxy_address;
uint16_t friend_proxy_port;
RsTor::getProxyServerInfo(friend_proxy_address,friend_proxy_port);
torProxyPort_SB->setValue(friend_proxy_port);
torProxyAddress_LE->setText(QString::fromStdString(friend_proxy_address));
}
FriendServerControl::~FriendServerControl()
{
delete mCheckingServerMovie;
delete mConnectionCheckTimer;
}
void FriendServerControl::onOnOffClick(bool b)
{
if(b)
rsFriendServer->startServer();
else
rsFriendServer->stopServer();
}
void FriendServerControl::onOnionPortEdit(int)
{
#warning TODO
// // Setup timer to auto-check the friend server address
//
// mConnectionCheckTimer->setSingleShot(true);
// mConnectionCheckTimer->setInterval(5000); // check in 5 secs unless something is changed in the mean time.
//
// mConnectionCheckTimer->start();
//
// if(mCheckingServerMovie->fileName() != QString(":/images/loader/circleball-16.gif" ))
// {
// mCheckingServerMovie->setFileName(":/images/loader/circleball-16.gif");
// mCheckingServerMovie->start();
// }
rsFriendServer->setServerAddress(torServerAddress_LE->text().toStdString(),torServerPort_SB->value());
rsFriendServer->setProxyAddress(torProxyAddress_LE->text().toStdString(),torProxyPort_SB->value());
}
void FriendServerControl::onOnionAddressEdit(const QString&)
{
// Setup timer to auto-check the friend server address
// mConnectionCheckTimer->setSingleShot(true);
// mConnectionCheckTimer->setInterval(5000); // check in 5 secs unless something is changed in the mean time.
//
// mConnectionCheckTimer->start();
//
// if(mCheckingServerMovie->fileName() != QString(":/images/loader/circleball-16.gif" ))
// {
// mCheckingServerMovie->setFileName(":/images/loader/circleball-16.gif");
// mCheckingServerMovie->start();
// }
rsFriendServer->setServerAddress(torServerAddress_LE->text().toStdString(),torServerPort_SB->value());
rsFriendServer->setProxyAddress(torProxyAddress_LE->text().toStdString(),torProxyPort_SB->value());
}
void FriendServerControl::checkServerAddress()
{
rsFriendServer->checkServerAddress_async(torServerAddress_LE->text().toStdString(),torServerPort_SB->value(),
[this](const std::string& address,bool test_result)
{
if(test_result)
rsFriendServer->setServerAddress(address,1729);
RsQThreadUtils::postToObject( [=]() { updateFriendServerStatusIcon(test_result); },this);
}
);
}
void FriendServerControl::onNbFriendsToRequestsChanged(int n)
{
rsFriendServer->setFriendsToRequest(n);
}
void FriendServerControl::updateFriendServerStatusIcon(bool ok)
{
mCheckingServerMovie->stop();
if(ok)
{
torServerStatus_LB->setToolTip(tr("Friend server is currently reachable.")) ;
mCheckingServerMovie->setFileName(ICON_STATUS_OK);
}
else
{
torServerStatus_LB->setToolTip(tr("The proxy is not enabled or broken.\nAre all services up and running fine??\nAlso check your ports!")) ;
mCheckingServerMovie->setFileName(ICON_STATUS_UNKNOWN);
}
mCheckingServerMovie->start();
}

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* gui/NetworkView.h *
* *
* Copyright (c) 2008 Robert Fernie <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#pragma once
#include <QGraphicsScene>
#include "ui_FriendServerControl.h"
class FriendServerControl : public QWidget, public Ui::FriendServerControl
{
Q_OBJECT
public:
FriendServerControl(QWidget *parent = 0);
virtual ~FriendServerControl();
protected slots:
void onOnOffClick(bool b);
void onOnionAddressEdit(const QString&);
void onOnionPortEdit(int);
void onNbFriendsToRequestsChanged(int n);
void updateTorProxyInfo();
private:
void checkServerAddress();
void updateFriendServerStatusIcon(bool ok);
QTimer *mConnectionCheckTimer;
QMovie *mCheckingServerMovie;
};

View file

@ -0,0 +1,183 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FriendServerControl</class>
<widget class="QWidget" name="FriendServerControl">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>620</width>
<height>499</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="friendServerOnOff_CB">
<property name="text">
<string>On/Off</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Friends to request: </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="torServerFriendsToRequest_SB">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>15</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Server onion address:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="torServerAddress_LE">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>.onion</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="torServerPort_SB">
<property name="minimum">
<number>1025</number>
</property>
<property name="maximum">
<number>65536</number>
</property>
<property name="value">
<number>2017</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="serverStatusCheckResult_LB">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="torServerStatus_LB">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Tor proxy address:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="torProxyAddress_LE">
<property name="text">
<string>127.0.0.1</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="torProxyPort_SB">
<property name="minimum">
<number>1025</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>9050</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>380</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -44,6 +44,9 @@
#include "NetworkView.h"
#include "NetworkDialog.h"
#include "gui/common/NewFriendList.h"
#ifdef RS_EMBEDED_FRIEND_SERVER
#include "gui/FriendServerControl.h"
#endif
#include "gui/Identity/IdDialog.h"
/* Images for Newsfeed icons */
//#define IMAGE_NEWSFEED ""
@ -88,6 +91,9 @@ FriendsDialog::FriendsDialog(QWidget *parent) : MainPage(parent)
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
ui.tabWidget->setTabPosition(QTabWidget::North);
#ifdef RS_EMBEDED_FRIEND_SERVER
ui.tabWidget->addTab(friendServerControl = new FriendServerControl(),QIcon(IMAGE_PEERS), tr("Friend Server"));
#endif
ui.tabWidget->addTab(networkView = new NetworkView(),QIcon(IMAGE_NETWORK2), tr("Network graph"));
ui.tabWidget->addTab(networkDialog = new NetworkDialog(),QIcon(IMAGE_PEERS), tr("Keyring"));

View file

@ -30,6 +30,7 @@ class NetworkDialog;
class NetworkView;
class IdDialog;
class CirclesDialog;
class FriendServerControl;
class FriendsDialog : public MainPage
{
@ -64,7 +65,8 @@ public:
NetworkDialog *networkDialog ;
NetworkView *networkView ;
FriendServerControl *friendServerControl ;
IdDialog *idDialog;
private slots:

View file

@ -1085,6 +1085,13 @@ DEFINES *= CHANNELS_FRAME_CATCHER
}
# Embedded Friend Server
rs_efs {
SOURCES += gui/FriendServerControl.cpp
HEADERS += gui/FriendServerControl.h
FORMS += gui/FriendServerControl.ui
}
# BELOW IS GXS Unfinished Services.