Merge pull request #2560 from csoler/v0.6-FriendServer2

V0.6 friend server2
This commit is contained in:
csoler 2022-01-17 23:39:38 +01:00 committed by GitHub
commit f03862b984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 195 additions and 90 deletions

@ -1 +1 @@
Subproject commit a7a430008b76e53727598c4d13106e7ce95221d7 Subproject commit 47548627adddc444a5d36368bd7a5f5baeed17ba

View File

@ -4,6 +4,8 @@
#include "util/rsbase64.h" #include "util/rsbase64.h"
#include "util/radix64.h" #include "util/radix64.h"
#include "crypto/hashstream.h"
#include "pgp/pgpkeyutil.h" #include "pgp/pgpkeyutil.h"
#include "pgp/rscertificate.h" #include "pgp/rscertificate.h"
#include "pgp/openpgpsdkhandler.h" #include "pgp/openpgpsdkhandler.h"
@ -60,7 +62,7 @@ void FriendServer::threadTick()
if(last_debugprint_TS + DELAY_BETWEEN_TWO_DEBUG_PRINT < now) if(last_debugprint_TS + DELAY_BETWEEN_TWO_DEBUG_PRINT < now)
{ {
last_debugprint_TS = now; last_debugprint_TS = now;
debugPrint(); debugPrint(false);
} }
} }
@ -82,12 +84,12 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it
RsDbg() << "Sending response item to " << item->PeerId() ; RsDbg() << "Sending response item to " << item->PeerId() ;
RsFriendServerServerResponseItem *sr_item = new RsFriendServerServerResponseItem; RsFriendServerServerResponseItem sr_item;
std::map<RsPeerId,RsPgpFingerprint> friends; std::map<RsPeerId,RsPgpFingerprint> friends;
sr_item->nonce = pi->second.last_nonce; sr_item.nonce = pi->second.last_nonce;
sr_item->friend_invites = computeListOfFriendInvites(item->n_requested_friends,pi->first,friends); sr_item.friend_invites = computeListOfFriendInvites(item->n_requested_friends,pi->first,friends);
sr_item->PeerId(item->PeerId()); sr_item.PeerId(item->PeerId());
// Update the have_added_as_friend for the list of each peer. We do that before sending because sending destroys // Update the have_added_as_friend for the list of each peer. We do that before sending because sending destroys
// the item. // the item.
@ -100,10 +102,29 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it
// Now encrypt the item with the public PGP key of the destination. This prevents the wrong person to request for // Now encrypt the item with the public PGP key of the destination. This prevents the wrong person to request for
// someone else's data. // someone else's data.
#warning TODO RsFriendServerEncryptedServerResponseItem *encrypted_response_item = new RsFriendServerEncryptedServerResponseItem;
uint32_t serialized_clear_size = FsSerializer().size(&sr_item);
RsTemporaryMemory serialized_clear_mem(serialized_clear_size);
FsSerializer().serialise(&sr_item,serialized_clear_mem,&serialized_clear_size);
uint32_t encrypted_mem_size = serialized_clear_size+1000; // leave some extra space
RsTemporaryMemory encrypted_mem(encrypted_mem_size);
if(!mPgpHandler->encryptDataBin(PGPHandler::pgpIdFromFingerprint(pi->second.pgp_fingerprint),
serialized_clear_mem,serialized_clear_size,
encrypted_mem,&encrypted_mem_size))
{
RsErr() << "Cannot encrypt item for PGP Id/FPR " << pi->second.pgp_fingerprint << ". Something went wrong." ;
return;
}
encrypted_response_item->PeerId(item->PeerId());
encrypted_response_item->bin_len = encrypted_mem_size;
encrypted_response_item->bin_data = malloc(encrypted_mem_size);
memcpy(encrypted_response_item->bin_data,encrypted_mem,encrypted_mem_size);
// Send the item. // Send the item.
mni->SendItem(sr_item); mni->SendItem(encrypted_response_item);
// Update the list of closest peers for all peers currently in the database. // Update the list of closest peers for all peers currently in the database.
@ -302,7 +323,7 @@ void FriendServer::removePeer(const RsPeerId& peer_id)
auto tmp(fit); auto tmp(fit);
++tmp; ++tmp;
it.second.closest_peers.erase(fit); it.second.have_added_this_peer.erase(fit);
fit=tmp; fit=tmp;
} }
else else
@ -349,8 +370,6 @@ void FriendServer::run()
void FriendServer::autoWash() void FriendServer::autoWash()
{ {
rstime_t now = time(nullptr); rstime_t now = time(nullptr);
RsDbg() << "autoWash..." ;
std::list<RsPeerId> to_remove; std::list<RsPeerId> to_remove;
for(std::map<RsPeerId,PeerInfo>::iterator it(mCurrentClientPeers.begin());it!=mCurrentClientPeers.end();++it) for(std::map<RsPeerId,PeerInfo>::iterator it(mCurrentClientPeers.begin());it!=mCurrentClientPeers.end();++it)
@ -362,8 +381,6 @@ void FriendServer::autoWash()
for(auto peer_id:to_remove) for(auto peer_id:to_remove)
removePeer(peer_id); removePeer(peer_id);
RsDbg() << "done." ;
} }
void FriendServer::updateClosestPeers(const RsPeerId& pid,const RsPgpFingerprint& fpr) void FriendServer::updateClosestPeers(const RsPeerId& pid,const RsPgpFingerprint& fpr)
@ -380,11 +397,44 @@ void FriendServer::updateClosestPeers(const RsPeerId& pid,const RsPgpFingerprint
} }
} }
void FriendServer::debugPrint() Sha1CheckSum FriendServer::computeDataHash()
{
librs::crypto::HashStream s(librs::crypto::HashStream::SHA1);
for(auto p(mCurrentClientPeers.begin());p!=mCurrentClientPeers.end();++p)
{
s << p->first;
const auto& inf(p->second);
s << inf.pgp_fingerprint;
s << inf.short_certificate;
s << (uint64_t)inf.last_connection_TS;
s << inf.last_nonce;
for(auto d(inf.closest_peers.begin());d!=inf.closest_peers.end();++d)
{
s << d->first ;
s << d->second;
}
for(auto d(inf.have_added_this_peer.begin());d!=inf.have_added_this_peer.end();++d)
{
s << d->first ;
s << d->second;
}
}
return s.hash();
}
void FriendServer::debugPrint(bool force)
{
auto h = computeDataHash();
if((h != mCurrentDataHash) || force)
{ {
RsDbg() << "========== FriendServer statistics ============"; RsDbg() << "========== FriendServer statistics ============";
RsDbg() << " Base directory: "<< mBaseDirectory; RsDbg() << " Base directory: "<< mBaseDirectory;
RsDbg() << " Random peer bias: "<< mRandomPeerBias; RsDbg() << " Random peer bias: "<< mRandomPeerBias;
RsDbg() << " Current hash: "<< h;
RsDbg() << " Network interface: "; RsDbg() << " Network interface: ";
RsDbg() << " Max peers in n-closest list: " << MAXIMUM_PEERS_TO_REQUEST; RsDbg() << " Max peers in n-closest list: " << MAXIMUM_PEERS_TO_REQUEST;
RsDbg() << " Current active peers: " << mCurrentClientPeers.size() ; RsDbg() << " Current active peers: " << mCurrentClientPeers.size() ;
@ -407,6 +457,9 @@ void FriendServer::debugPrint()
RsDbg() << "==============================================="; RsDbg() << "===============================================";
mCurrentDataHash = h;
}
} }

View File

@ -75,7 +75,8 @@ private:
PeerInfo::PeerDistance computePeerDistance(const RsPgpFingerprint &p1, const RsPgpFingerprint &p2); PeerInfo::PeerDistance computePeerDistance(const RsPgpFingerprint &p1, const RsPgpFingerprint &p2);
void autoWash(); void autoWash();
void debugPrint(); void debugPrint(bool force);
Sha1CheckSum computeDataHash();
// Local members // Local members
@ -88,4 +89,6 @@ private:
std::map<RsPeerId, PeerInfo> mCurrentClientPeers; std::map<RsPeerId, PeerInfo> mCurrentClientPeers;
std::string mListeningAddress; std::string mListeningAddress;
uint16_t mListeningPort; uint16_t mListeningPort;
Sha1CheckSum mCurrentDataHash;
}; };

View File

@ -21,9 +21,9 @@
#ifndef _SEARCHDIALOG_H #ifndef _SEARCHDIALOG_H
#define _SEARCHDIALOG_H #define _SEARCHDIALOG_H
#include <retroshare/rstypes.h> #include "retroshare/rstypes.h"
#include "ui_SearchDialog.h" #include "ui_SearchDialog.h"
#include <retroshare-gui/mainpage.h> #include "retroshare-gui/mainpage.h"
class AdvancedSearchDialog; class AdvancedSearchDialog;
class RSTreeWidgetItemCompareRole; class RSTreeWidgetItemCompareRole;

View File

@ -20,12 +20,14 @@
#include <QTimer> #include <QTimer>
#include <QMovie> #include <QMovie>
#include <QMessageBox>
#include <QTcpSocket> #include <QTcpSocket>
#include "retroshare/rsfriendserver.h" #include "retroshare/rsfriendserver.h"
#include "retroshare/rstor.h" #include "retroshare/rstor.h"
#include "util/qtthreadsutils.h" #include "util/qtthreadsutils.h"
#include "util/misc.h"
#include "gui/common/FilesDefs.h" #include "gui/common/FilesDefs.h"
#include "FriendServerControl.h" #include "FriendServerControl.h"
@ -37,7 +39,7 @@
/** Constructor */ /** Constructor */
FriendServerControl::FriendServerControl(QWidget *parent) FriendServerControl::FriendServerControl(QWidget *parent)
: QWidget(parent) : MainPage(parent)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
setupUi(this); setupUi(this);
@ -48,6 +50,22 @@ FriendServerControl::FriendServerControl(QWidget *parent)
return; return;
} }
int H = QFontMetricsF(torServerAddress_LE->font()).height();
QString help_str = tr("\
<h1><img width=\"%1\" src=\":/icons/help_64.png\">&nbsp;&nbsp;Friend Server</h1> \
<p>This configuration panel allows you to specify the onion address of a \
friend server. Retroshare will talk to that server anonymously through Tor \
and use it to acquire a fixed number of friends.</p> \
<p>The friend server will continue supplying new friends until that number is reached \
in particular if you add your own friends manually, the friend server may become useless \
and you will save bandwidth disabling it. When disabling it, you will keep existing friends.</p> \
<p>The friend server only knows your peer ID and profile public key. It doesn't know your IP address.</p> \
"
).arg(QString::number(2*H), QString::number(2*H)) ;
registerHelpButton(helpButton,help_str,"Friend Server") ;
mConnectionCheckTimer = new QTimer; mConnectionCheckTimer = new QTimer;
// init values // init values
@ -69,18 +87,6 @@ FriendServerControl::FriendServerControl(QWidget *parent)
serverStatusCheckResult_LB->setMovie(mCheckingServerMovie); serverStatusCheckResult_LB->setMovie(mCheckingServerMovie);
updateFriendServerStatusIcon(false); 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() FriendServerControl::~FriendServerControl()
@ -92,7 +98,16 @@ FriendServerControl::~FriendServerControl()
void FriendServerControl::onOnOffClick(bool b) void FriendServerControl::onOnOffClick(bool b)
{ {
if(b) if(b)
{
if(passphrase_LE->text().isNull())
{
QMessageBox::critical(nullptr,tr("Missing profile passphrase."),tr("Your profile passphrase is missing. Please enter is in the field below before enabling the friend server."));
whileBlocking(friendServerOnOff_CB)->setCheckState(Qt::Unchecked);
return;
}
rsFriendServer->setProfilePassphrase(passphrase_LE->text().toStdString());
rsFriendServer->startServer(); rsFriendServer->startServer();
}
else else
rsFriendServer->stopServer(); rsFriendServer->stopServer();
} }

View File

@ -22,9 +22,10 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include "retroshare-gui/mainpage.h"
#include "ui_FriendServerControl.h" #include "ui_FriendServerControl.h"
class FriendServerControl : public QWidget, public Ui::FriendServerControl class FriendServerControl : public MainPage, public Ui::FriendServerControl
{ {
Q_OBJECT Q_OBJECT
@ -37,7 +38,6 @@ protected slots:
void onOnionAddressEdit(const QString&); void onOnionAddressEdit(const QString&);
void onOnionPortEdit(int); void onOnionPortEdit(int);
void onNbFriendsToRequestsChanged(int n); void onNbFriendsToRequestsChanged(int n);
void updateTorProxyInfo();
void checkServerAddress(); void checkServerAddress();
private: private:

View File

@ -11,6 +11,8 @@
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
<widget class="QCheckBox" name="friendServerOnOff_CB"> <widget class="QCheckBox" name="friendServerOnOff_CB">
<property name="text"> <property name="text">
@ -18,6 +20,41 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_5">
<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>
<widget class="QToolButton" name="helpButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/icons/help_64.png</normaloff>:/icons/help_64.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
@ -72,13 +109,22 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter here the onion address of the Friend Server that was given to you. The address will be automatically checked after you enter it and a green bullet will appear if the server is online.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text"> <property name="text">
<string>.onion</string> <string>.onion</string>
</property> </property>
<property name="placeholderText">
<string>Onion address of the friend server</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="torServerPort_SB"> <widget class="QSpinBox" name="torServerPort_SB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Communication port of the server. You usually get a server address as somestring.onion:port. The port is the number right after &amp;quot;:&amp;quot;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum"> <property name="minimum">
<number>1025</number> <number>1025</number>
</property> </property>
@ -107,49 +153,35 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>Tor proxy address:</string> <string>Retroshare passphrase:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="torProxyAddress_LE"> <widget class="QLineEdit" name="passphrase_LE">
<property name="text"> <property name="sizePolicy">
<string>127.0.0.1</string> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Your Retroshare login passphrase is needed to ensure the security of data exchange with the friend server.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>Your retroshare passphrase</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="torProxyPort_SB"> <spacer name="horizontalSpacer_4">
<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"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -178,6 +210,8 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources>
<include location="images.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>726</width> <width>738</width>
<height>579</height> <height>579</height>
</rect> </rect>
</property> </property>