fixed up display of GXS net tunnel info

This commit is contained in:
csoler 2018-07-15 19:09:12 +02:00
parent cca986ad75
commit 1de31493a9
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
5 changed files with 156 additions and 39 deletions

View File

@ -1147,10 +1147,11 @@ void RsGxsNetTunnelService::receiveSearchResult(TurtleSearchRequestId request_id
GXS_NET_TUNNEL_ERROR() << ": deserialized item is of unknown type. Dropping!" << std::endl; GXS_NET_TUNNEL_ERROR() << ": deserialized item is of unknown type. Dropping!" << std::endl;
} }
void RsGxsNetTunnelService::getStatistics( std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo>& groups,std::map<RsGxsNetTunnelVirtualPeerId, RsGxsNetTunnelVirtualPeerInfo>& virtual_peers,Bias20Bytes& bias ) const void RsGxsNetTunnelService::getStatistics(std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo>& groups, std::map<RsGxsNetTunnelVirtualPeerId, RsGxsNetTunnelVirtualPeerInfo>& virtual_peers, std::map<TurtleVirtualPeerId, RsGxsNetTunnelVirtualPeerId> &turtle_vpid_to_net_tunnel_vpid, Bias20Bytes& bias ) const
{ {
groups = mGroups ; groups = mGroups ;
virtual_peers = mVirtualPeers ; virtual_peers = mVirtualPeers ;
turtle_vpid_to_net_tunnel_vpid = mTurtle2GxsPeer;
bias = mRandomBias ; bias = mRandomBias ;
} }

View File

@ -213,6 +213,7 @@ public:
void getStatistics(std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo>& groups, // groups on the client and server side void getStatistics(std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo>& groups, // groups on the client and server side
std::map<RsGxsNetTunnelVirtualPeerId, RsGxsNetTunnelVirtualPeerInfo>& virtual_peers, // current virtual peers, which group they provide, and how to talk to them through turtle std::map<RsGxsNetTunnelVirtualPeerId, RsGxsNetTunnelVirtualPeerInfo>& virtual_peers, // current virtual peers, which group they provide, and how to talk to them through turtle
std::map<TurtleVirtualPeerId,RsGxsNetTunnelVirtualPeerId>& turtle_vpid_to_net_tunnel_vpid,
Bias20Bytes& bias) const; Bias20Bytes& bias) const;
protected: protected:

View File

@ -0,0 +1,92 @@
/*
* RetroShare C++ Interface.
*
* Copyright 2018 by Cyril Soler
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#pragma once
#include "retroshare/rsfiles.h"
#include "retroshare/rsturtle.h"
typedef RsPeerId RsGxsNetTunnelVirtualPeerId ;
struct RsGxsNetTunnelVirtualPeerInfo
{
enum { RS_GXS_NET_TUNNEL_VP_STATUS_UNKNOWN = 0x00, // unknown status.
RS_GXS_NET_TUNNEL_VP_STATUS_TUNNEL_OK = 0x01, // tunnel has been established and we're waiting for virtual peer id
RS_GXS_NET_TUNNEL_VP_STATUS_ACTIVE = 0x02 // virtual peer id is known. Data can transfer.
};
RsGxsNetTunnelVirtualPeerInfo() : vpid_status(RS_GXS_NET_TUNNEL_VP_STATUS_UNKNOWN), last_contact(0),side(0) { memset(encryption_master_key,0,32) ; }
virtual ~RsGxsNetTunnelVirtualPeerInfo(){}
uint8_t vpid_status ; // status of the peer
time_t last_contact ; // last time some data was sent/recvd
uint8_t side ; // client/server
uint8_t encryption_master_key[32];
TurtleVirtualPeerId turtle_virtual_peer_id ; // turtle peer to use when sending data to this vpid.
RsGxsGroupId group_id ; // group that virtual peer is providing
uint16_t service_id ; // this is used for checkng consistency of the incoming data
};
struct RsGxsNetTunnelGroupInfo
{
enum GroupStatus {
RS_GXS_NET_TUNNEL_GRP_STATUS_UNKNOWN = 0x00, // unknown status
RS_GXS_NET_TUNNEL_GRP_STATUS_IDLE = 0x01, // no virtual peers requested, just waiting
RS_GXS_NET_TUNNEL_GRP_STATUS_VPIDS_AVAILABLE = 0x02 // some virtual peers are available. Data can be read/written
};
enum GroupPolicy {
RS_GXS_NET_TUNNEL_GRP_POLICY_UNKNOWN = 0x00, // nothing has been set
RS_GXS_NET_TUNNEL_GRP_POLICY_PASSIVE = 0x01, // group is available for server side tunnels, but does not explicitely request tunnels
RS_GXS_NET_TUNNEL_GRP_POLICY_ACTIVE = 0x02, // group will only explicitely request tunnels if none available
RS_GXS_NET_TUNNEL_GRP_POLICY_REQUESTING = 0x03, // group explicitely requests tunnels
};
RsGxsNetTunnelGroupInfo() : group_policy(RS_GXS_NET_TUNNEL_GRP_POLICY_PASSIVE),group_status(RS_GXS_NET_TUNNEL_GRP_STATUS_IDLE),last_contact(0) {}
GroupPolicy group_policy ;
GroupStatus group_status ;
time_t last_contact ;
RsFileHash hash ;
uint16_t service_id ;
std::set<TurtleVirtualPeerId> virtual_peers ; // list of which virtual peers provide this group. Can me more than 1.
};
// This class is here to provide statistics about GXS dist sync internals. It
//
class RsGxsDistSync
{
public:
virtual void getStatistics(
std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo>& groups, // groups on the client and server side
std::map<RsGxsNetTunnelVirtualPeerId, RsGxsNetTunnelVirtualPeerInfo>& virtual_peers, // current virtual peers, which group they provide, and how to talk to them through turtle
std::map<TurtleVirtualPeerId,RsGxsNetTunnelVirtualPeerId>& turtle_vpid_to_net_tunnel_vpid,
Bias20Bytes& bias
) const =0;
};
extern RsGxsDistSync *rsGxsDistSync ;

View File

@ -44,6 +44,7 @@ class RsTurtle;
extern RsTurtle *rsTurtle ; extern RsTurtle *rsTurtle ;
typedef uint32_t TurtleRequestId ; typedef uint32_t TurtleRequestId ;
typedef RsPeerId TurtleVirtualPeerId;
// This is the structure used to send back results of the turtle search // This is the structure used to send back results of the turtle search
// to the notifyBase class, or send info to the GUI. // to the notifyBase class, or send info to the GUI.

View File

@ -1,4 +1,5 @@
#include <QObject> #include <QObject>
#include <util/rsprint.h>
#include <retroshare/rsturtle.h> #include <retroshare/rsturtle.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsgxstunnel.h> #include <retroshare/rsgxstunnel.h>
@ -481,9 +482,14 @@ static QString getVirtualPeerStatusString(uint8_t status)
return QString(); return QString();
} }
static QString getSideString(uint8_t side)
{
return side?QObject::tr("Client"):QObject::tr("Server") ;
}
static QString getMasterKeyString(uint8_t *key) static QString getMasterKeyString(uint8_t *key)
{ {
return QString(); return QString::fromStdString(RsUtil::BinToHex(key,10));
} }
void GxsNetTunnelsDialog::updateDisplay() void GxsNetTunnelsDialog::updateDisplay()
@ -491,10 +497,11 @@ void GxsNetTunnelsDialog::updateDisplay()
// Request info about ongoing tunnels // Request info about ongoing tunnels
std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo> groups; // groups on the client and server side std::map<RsGxsGroupId,RsGxsNetTunnelGroupInfo> groups; // groups on the client and server side
std::map<TurtleVirtualPeerId,RsGxsNetTunnelVirtualPeerId> turtle2gxsnettunnel; // convertion table from turtle to net tunnel virtual peer id
std::map<RsGxsNetTunnelVirtualPeerId, RsGxsNetTunnelVirtualPeerInfo> virtual_peers; // current virtual peers, which group they provide, and how to talk to them through turtle std::map<RsGxsNetTunnelVirtualPeerId, RsGxsNetTunnelVirtualPeerInfo> virtual_peers; // current virtual peers, which group they provide, and how to talk to them through turtle
Bias20Bytes bias; Bias20Bytes bias;
rsGxsDistSync->getStatistics(groups,virtual_peers,bias) ; rsGxsDistSync->getStatistics(groups,virtual_peers,turtle2gxsnettunnel,bias) ;
// RsGxsNetTunnelGroupInfo: // RsGxsNetTunnelGroupInfo:
// //
@ -518,6 +525,29 @@ void GxsNetTunnelsDialog::updateDisplay()
// RsFileHash hash ; // RsFileHash hash ;
// uint16_t service_id ; // uint16_t service_id ;
// std::set<RsPeerId> virtual_peers ; // std::set<RsPeerId> virtual_peers ;
//
// struct RsGxsNetTunnelVirtualPeerInfo:
//
// enum { RS_GXS_NET_TUNNEL_VP_STATUS_UNKNOWN = 0x00, // unknown status.
// RS_GXS_NET_TUNNEL_VP_STATUS_TUNNEL_OK = 0x01, // tunnel has been established and we're waiting for virtual peer id
// RS_GXS_NET_TUNNEL_VP_STATUS_ACTIVE = 0x02 // virtual peer id is known. Data can transfer.
// };
//
// RsGxsNetTunnelVirtualPeerInfo() : vpid_status(RS_GXS_NET_TUNNEL_VP_STATUS_UNKNOWN), last_contact(0),side(0) { memset(encryption_master_key,0,32) ; }
// virtual ~RsGxsNetTunnelVirtualPeerInfo(){}
//
// uint8_t vpid_status ; // status of the peer
// time_t last_contact ; // last time some data was sent/recvd
// uint8_t side ; // client/server
// uint8_t encryption_master_key[32];
//
// RsPeerId turtle_virtual_peer_id ; // turtle peer to use when sending data to this vpid.
//
// RsGxsGroupId group_id ; // group that virtual peer is providing
// uint16_t service_id ; // this is used for checkng consistency of the incoming data
// update the pixmap
//
// now draw the shit // now draw the shit
QPixmap tmppixmap(maxWidth, maxHeight); QPixmap tmppixmap(maxWidth, maxHeight);
@ -540,52 +570,44 @@ void GxsNetTunnelsDialog::updateDisplay()
painter.drawText(ox+2*cellx,oy+celly,tr("GXS Groups:")) ; oy += celly ; painter.drawText(ox+2*cellx,oy+celly,tr("GXS Groups:")) ; oy += celly ;
for(auto it(groups.begin());it!=groups.end();++it) for(auto it(groups.begin());it!=groups.end();++it)
painter.drawText(ox+4*cellx,oy+celly,tr("Service: %1 (%2) - Group ID: %3,\t policy: %4, \tstatus: %5, \tlast contact: %6, \t%7 virtual peers.") {
painter.drawText(ox+4*cellx,oy+celly,tr("Service: %1 (%2) - Group ID: %3,\t policy: %4, \tstatus: %5, \tlast contact: %6")
.arg(QString::number(it->second.service_id)) .arg(QString::number(it->second.service_id))
.arg(getServiceNameString(it->second.service_id)) .arg(getServiceNameString(it->second.service_id))
.arg(QString::fromStdString(it->first.toStdString())) .arg(QString::fromStdString(it->first.toStdString()))
.arg(getGroupPolicyString(it->second.group_policy)) .arg(getGroupPolicyString(it->second.group_policy))
.arg(getGroupStatusString(it->second.group_status)) .arg(getGroupStatusString(it->second.group_status))
.arg(getLastContactString(it->second.last_contact)) .arg(getLastContactString(it->second.last_contact))
.arg(QString::number(it->second.virtual_peers.size()))
),oy+=celly ; ),oy+=celly ;
for(auto it2(it->second.virtual_peers.begin());it2!=it->second.virtual_peers.end();++it2)
{
auto it4 = turtle2gxsnettunnel.find(*it2) ;
if(it4 != turtle2gxsnettunnel.end())
{
auto it3 = virtual_peers.find(it4->second) ;
if(virtual_peers.end() != it3)
painter.drawText(ox+6*cellx,oy+celly,tr("Peer: %1:\tstatus: %2/%3, \tlast contact: %4, \tMaster key: %5.")
.arg(QString::fromStdString((*it2).toStdString()))
.arg(getVirtualPeerStatusString(it3->second.vpid_status))
.arg(getSideString(it3->second.side))
.arg(getLastContactString(it3->second.last_contact))
.arg(getMasterKeyString(it3->second.encryption_master_key))
),oy+=celly ;
}
else
painter.drawText(ox+6*cellx,oy+celly,tr("Peer: %1: no information available")
.arg(QString::fromStdString((*it2).toStdString()))
),oy+=celly;
}
}
oy += celly ; oy += celly ;
// struct RsGxsNetTunnelVirtualPeerInfo:
//
// enum { RS_GXS_NET_TUNNEL_VP_STATUS_UNKNOWN = 0x00, // unknown status.
// RS_GXS_NET_TUNNEL_VP_STATUS_TUNNEL_OK = 0x01, // tunnel has been established and we're waiting for virtual peer id
// RS_GXS_NET_TUNNEL_VP_STATUS_ACTIVE = 0x02 // virtual peer id is known. Data can transfer.
// };
//
// RsGxsNetTunnelVirtualPeerInfo() : vpid_status(RS_GXS_NET_TUNNEL_VP_STATUS_UNKNOWN), last_contact(0),side(0) { memset(encryption_master_key,0,32) ; }
// virtual ~RsGxsNetTunnelVirtualPeerInfo(){}
//
// uint8_t vpid_status ; // status of the peer
// time_t last_contact ; // last time some data was sent/recvd
// uint8_t side ; // client/server
// uint8_t encryption_master_key[32];
//
// RsPeerId turtle_virtual_peer_id ; // turtle peer to use when sending data to this vpid.
//
// RsGxsGroupId group_id ; // group that virtual peer is providing
// uint16_t service_id ; // this is used for checkng consistency of the incoming data
painter.drawText(ox+2*cellx,oy+celly,tr("Virtual peers:")) ; oy += celly ;
for(auto it(virtual_peers.begin());it!=virtual_peers.end();++it)
painter.drawText(ox+4*cellx,oy+celly,tr("Peer: %1 - Group ID: %2 (service %3),\t status: %4, \tlast contact: %5, \tside %6 \tMaster key: %7.")
.arg(QString::fromStdString(it->first.toStdString()))
.arg(QString::fromStdString(it->second.group_id.toStdString()))
.arg(getServiceNameString(it->second.service_id))
.arg(getVirtualPeerStatusString(it->second.vpid_status))
.arg(getLastContactString(it->second.last_contact))
.arg(getMasterKeyString(it->second.encryption_master_key))
),oy+=celly ;
// update the pixmap
//
pixmap = tmppixmap; pixmap = tmppixmap;
maxHeight = std::max(oy,10*celly); maxHeight = std::max(oy,10*celly);
} }