added display of friend status in FS

This commit is contained in:
csoler 2022-10-19 17:24:58 +02:00
parent efa00b2802
commit 5847b08766
4 changed files with 155 additions and 4 deletions

View File

@ -103,18 +103,29 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it
sr_item.friend_invites = computeListOfFriendInvites(pi->first,item->n_requested_friends,item->already_received_peers,friends);
sr_item.PeerId(item->PeerId());
RsDbg() << " Got " << sr_item.friend_invites.size() << " closest peers not in the list." ;
RsDbg() << " Updating local information for destination peer." ;
// Update friendship levels of the peer that will receive the new list
for(auto fr:friends)
{
auto& p(pi->second.friendship_levels[fr]);
RsDbg() << " Already a friend: " << fr << ", with local status " << static_cast<int>(p) ;
if(static_cast<int>(p) < static_cast<int>(RsFriendServer::PeerFriendshipLevel::HAS_KEY))
{
p = RsFriendServer::PeerFriendshipLevel::HAS_KEY;
RsDbg() << " --> updating status to HAS_KEY" ;
}
}
// Now encrypt the item with the public PGP key of the destination. This prevents the wrong person to request for
// someone else's data.
RsDbg() << " Encrypting item..." ;
RsFriendServerEncryptedServerResponseItem *encrypted_response_item = new RsFriendServerEncryptedServerResponseItem;
uint32_t serialized_clear_size = FsSerializer().size(&sr_item);
RsTemporaryMemory serialized_clear_mem(serialized_clear_size);
@ -137,8 +148,9 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it
memcpy(encrypted_response_item->bin_data,encrypted_mem,encrypted_mem_size);
// Send the item.
mni->SendItem(encrypted_response_item);
RsDbg() << " Sending item..." ;
mni->SendItem(encrypted_response_item);
}
catch(std::exception& e)
{
@ -191,8 +203,11 @@ std::map<std::string,RsFriendServer::PeerFriendshipLevel> FriendServer::computeL
auto pinfo(pinfo_it->second);
for(const auto& pit:pinfo.closest_peers)
{
if(already_known_peers.find(pit.second) == already_known_peers.end())
{
RsDbg() << " peer " << pit.second << ": not in supplied list => adding it.";
const auto p = mCurrentClientPeers.find(pit.second);
if(p == mCurrentClientPeers.end()) // should not happen, but just an extra security.
@ -208,6 +223,12 @@ std::map<std::string,RsFriendServer::PeerFriendshipLevel> FriendServer::computeL
if(res.size() + already_known_peers.size() >= nb_reqs_invites)
break;
}
else
{
auto p = already_known_peers.find(pit.second);
RsDbg() << " peer " << pit.second << ": already in supplied list, with status " << static_cast<int>(p->second) << ". Not adding it.";
}
}
return res;
}

View File

@ -37,6 +37,11 @@
#define ICON_STATUS_UNKNOWN ":/images/ledoff1.png"
#define ICON_STATUS_OK ":/images/ledon1.png"
#define NAME_COLUMN 0
#define NODE_COLUMN 1
#define ADDR_COLUMN 2
#define STAT_COLUMN 3
/** Constructor */
FriendServerControl::FriendServerControl(QWidget *parent)
: MainPage(parent)
@ -71,6 +76,8 @@ FriendServerControl::FriendServerControl(QWidget *parent)
mConnectionCheckTimer = new QTimer;
whileBlocking(autoAccept_CB)->setChecked(rsFriendServer->autoAddFriends());
// init values
torServerFriendsToRequest_SB->setValue(rsFriendServer->friendsToRequest());
@ -83,18 +90,51 @@ FriendServerControl::FriendServerControl(QWidget *parent)
QObject::connect(torServerFriendsToRequest_SB,SIGNAL(valueChanged(int)),this,SLOT(onFriendsToRequestChanged(int)));
QObject::connect(torServerAddress_LE,SIGNAL(textEdited(const QString&)),this,SLOT(onOnionAddressEdit(const QString&)));
QObject::connect(torServerPort_SB,SIGNAL(valueChanged(int)),this,SLOT(onOnionPortEdit(int)));
QObject::connect(autoAccept_CB,SIGNAL(toggled(bool)),this,SLOT(onAutoAddFriends(bool)));
QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress()));
mCheckingServerMovie = new QMovie(":/images/loader/circleball-16.gif");
updateFriendServerStatusIcon(false);
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
{
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
}, mEventHandlerId, RsEventType::FRIEND_SERVER );
}
void FriendServerControl::onAutoAddFriends(bool b)
{
rsFriendServer->setAutoAddFriends(b);
}
void FriendServerControl::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
if(event->mType != RsEventType::FRIEND_SERVER) return;
const RsFriendServerEvent *fe = dynamic_cast<const RsFriendServerEvent*>(event.get());
if(!fe)
return;
switch(fe->mFriendServerEventType)
{
case RsFriendServerEventCode::PEER_INFO_CHANGED: updateContactsStatus();
break;
default:
case RsFriendServerEventCode::UNKNOWN: break;
}
}
FriendServerControl::~FriendServerControl()
{
delete mCheckingServerMovie;
delete mConnectionCheckTimer;
rsEvents->unregisterEventsHandler(mEventHandlerId);
}
void FriendServerControl::onOnOffClick(bool b)
@ -193,6 +233,7 @@ void FriendServerControl::updateFriendServerStatusIcon(bool ok)
serverStatusCheckResult_LB->setToolTip(tr("Friend server is currently reachable.")) ;
serverStatusCheckResult_LB->setPixmap(QPixmap(ICON_STATUS_OK));
friendServerOnOff_CB->setEnabled(true);
status_TW->setEnabled(true);
}
else
{
@ -201,8 +242,56 @@ void FriendServerControl::updateFriendServerStatusIcon(bool ok)
serverStatusCheckResult_LB->setPixmap(QPixmap(ICON_STATUS_UNKNOWN));
friendServerOnOff_CB->setChecked(false);
friendServerOnOff_CB->setEnabled(false);
status_TW->setEnabled(false);
}
}
void FriendServerControl::updateContactsStatus()
{
std::map<RsPeerId,RsFriendServer::RsFsPeerInfo> pinfo = rsFriendServer->getPeersInfo();
status_TW->clear();
int row = 0;
status_TW->setRowCount(pinfo.size());
status_TW->setColumnCount(4);
status_TW->setHorizontalHeaderItem(NAME_COLUMN,new QTableWidgetItem(QObject::tr("Name")));
status_TW->setHorizontalHeaderItem(NODE_COLUMN,new QTableWidgetItem(QObject::tr("Node")));
status_TW->setHorizontalHeaderItem(ADDR_COLUMN,new QTableWidgetItem(QObject::tr("Address")));
status_TW->setHorizontalHeaderItem(STAT_COLUMN,new QTableWidgetItem(QObject::tr("Status")));
for(auto it:pinfo)
{
uint32_t err_code=0;
RsPeerDetails details;
rsPeers->parseShortInvite(it.second.mInvite,details,err_code);
status_TW->setItem(row,NAME_COLUMN,new QTableWidgetItem(QString::fromStdString(details.name)));
status_TW->setItem(row,NODE_COLUMN,new QTableWidgetItem(QString::fromStdString(details.id.toStdString())));
status_TW->setItem(row,ADDR_COLUMN,new QTableWidgetItem(QString::fromStdString(details.hiddenNodeAddress)+":"+QString::number(details.hiddenNodePort)));
QString status_string;
if(details.accept_connection)
status_string += QString("Friend");
else
status_string += QString("Not friend");
status_string += QString(" / ");
switch(it.second.mPeerLevel)
{
case RsFriendServer::PeerFriendshipLevel::NO_KEY: status_string += "Doesn't have my key" ; break;
case RsFriendServer::PeerFriendshipLevel::HAS_KEY: status_string += "Has my key" ; break;
case RsFriendServer::PeerFriendshipLevel::HAS_ACCEPTED_KEY: status_string += "Has friended me" ; break;
default:
case RsFriendServer::PeerFriendshipLevel::UNKNOWN: status_string += "Unkn" ; break;
}
status_TW->setItem(row,STAT_COLUMN,new QTableWidgetItem(status_string));
row++;
}
}

View File

@ -22,6 +22,8 @@
#include <QGraphicsScene>
#include "retroshare/rsevents.h"
#include "retroshare-gui/mainpage.h"
#include "ui_FriendServerControl.h"
@ -39,11 +41,16 @@ protected slots:
void onOnionPortEdit(int);
void onNbFriendsToRequestsChanged(int n);
void checkServerAddress();
void onAutoAddFriends(bool b);
private:
void updateContactsStatus();
void updateFriendServerStatusIcon(bool ok);
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
QTimer *mConnectionCheckTimer;
QMovie *mCheckingServerMovie;
bool mCurrentlyCheckingServerAddress;
RsEventsHandlerId_t mEventHandlerId;
};

View File

@ -81,7 +81,7 @@
<enum>Qt::NoFocus</enum>
</property>
<property name="icon">
<iconset resource="images.qrc">
<iconset resource="icons.qrc">
<normaloff>:/icons/help_64.png</normaloff>:/icons/help_64.png</iconset>
</property>
<property name="checkable">
@ -179,9 +179,43 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoAccept_CB">
<property name="toolTip">
<string>Auto accept received certificates as friends</string>
</property>
<property name="text">
<string>Auto-accept</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTableWidget" name="status_TW">
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Node ID</string>
</property>
</column>
<column>
<property name="text">
<string>Address</string>
</property>
</column>
<column>
<property name="text">
<string>Status</string>
</property>
</column>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
@ -198,7 +232,7 @@
</layout>
</widget>
<resources>
<include location="images.qrc"/>
<include location="icons.qrc"/>
</resources>
<connections/>
</ui>