more cleanups + sanitize p3Peers::getPeerDetails avoid to look for port on null sockaddr_storage

This commit is contained in:
Gio 2015-12-31 19:32:46 +01:00
parent ed7f958f95
commit 1303d855e6
3 changed files with 246 additions and 238 deletions

View File

@ -42,6 +42,10 @@
class RsPeers;
extern RsPeers *rsPeers;
/* TODO: 2015/12/31 As for type safetyness all those constant must be declared as enum!
* C++ now supports typed enum so there is no ambiguity in serialization size
*/
/* Trust Levels. Should be the same values than what is declared in PGPHandler.h */
const uint32_t RS_TRUST_LVL_UNDEFINED = 0;
@ -216,7 +220,7 @@ class RsPeerDetails
RsPgpId issuer;
PGPFingerprintType fpr; /* pgp fingerprint */
std::string authcode; // (cyril) what is this used for ?????
std::string authcode; // TODO: 2015/12/31 (cyril) what is this used for ?????
std::list<RsPgpId> gpgSigners;
uint32_t trustLvl;
@ -234,6 +238,8 @@ class RsPeerDetails
uint32_t state;
bool actAsServer;
// TODO: 2015/12/31 to take advantage of multiple connection this must be
// replaced by a set of addresses
std::string connectAddr ; // current address if connected.
uint16_t connectPort ;
@ -274,7 +280,6 @@ class RsPeerDetails
// This class is used to get info about crytographic algorithms used with a
// particular peer.
//
class RsPeerCryptoParams
{
public:
@ -299,13 +304,17 @@ public:
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);
/* TODO: 2015/12/31 this class seems foundamental for RetroShare code
* understanding must document it as soon as possible
*/
class RsPeers
{
public:
RsPeers() { return; }
virtual ~RsPeers() { return; }
RsPeers() {}
virtual ~RsPeers() {}
// TODO: 2015/12/31 is this dead code?
/* Updates ... */
// not implemented
//virtual bool FriendsChanged() = 0;
@ -322,7 +331,7 @@ class RsPeers
virtual bool isOnline(const RsPeerId &ssl_id) = 0;
virtual bool isFriend(const RsPeerId &ssl_id) = 0;
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend) = 0; //
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend) = 0;
virtual std::string getPeerName(const RsPeerId &ssl_id) = 0;
virtual std::string getGPGName(const RsPgpId& gpg_id) = 0;
virtual bool getPeerDetails(const RsPeerId& ssl_id, RsPeerDetails &d) = 0;
@ -410,7 +419,9 @@ class RsPeers
// ... computes the sharing file permission hint flags set for this peer, that is a combination of
// RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE.
//
virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags file_sharing_flags,const std::list<std::string>& file_parent_groups) = 0;
virtual FileSearchFlags computePeerPermissionFlags(
const RsPeerId& peer_id, FileStorageFlags file_sharing_flags,
const std::list<std::string>& file_parent_groups) = 0;
/* Service permission flags */

View File

@ -256,8 +256,6 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
std::cerr << "p3Peers::getPeerDetails() called for id : " << id << std::endl;
#endif
// NOW Only for SSL Details.
RsPeerId sOwnId = AuthSSL::getAuthSSL()->OwnId();
peerState ps;
@ -274,24 +272,8 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
return false;
}
// bool res = getGPGDetails(id, d);
//
// d.isOnlyGPGdetail = true;
//
// if(id.length() == 16)
// d.service_perm_flags = mPeerMgr->servicePermissionFlags(id) ;
// else if(id.length() == 32)
// d.service_perm_flags = mPeerMgr->servicePermissionFlags(id) ;
// else
// {
// std::cerr << "p3Peers::getPeerDetails() ERROR not an correct Id: " << id << std::endl;
// d.service_perm_flags = RS_SERVICE_PERM_NONE ;
// }
//
// return res ;
/* get from gpg (first), to fill in the sign and trust details */
/* don't retrun now, we've got fill in the ssl and connection info */
/* don't return now, we've got fill in the ssl and connection info */
getGPGDetails(ps.gpg_id, d);
d.isOnlyGPGdetail = false;
@ -327,10 +309,28 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
d.hiddenNodePort = 0;
d.hiddenType = RS_HIDDEN_TYPE_NONE;
if (sockaddr_storage_isnull(ps.localaddr))
{
d.localAddr = "INVALID_IP";
d.localPort = 0;
}
else
{
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
d.localPort = sockaddr_storage_port(ps.localaddr);
}
if (sockaddr_storage_isnull(ps.serveraddr))
{
d.extAddr = "INVALID_IP";
d.extPort = 0;
}
else
{
d.extAddr = sockaddr_storage_iptostring(ps.serveraddr);
d.extPort = sockaddr_storage_port(ps.serveraddr);
}
d.dyndns = ps.dyndns;
std::list<pqiIpAddress>::iterator it;

View File

@ -38,7 +38,7 @@ class p3Peers: public RsPeers
public:
p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm);
virtual ~p3Peers() { return; }
virtual ~p3Peers() {}
/* Updates ... */
virtual bool FriendsChanged();
@ -49,15 +49,13 @@ virtual const RsPeerId& getOwnId();
virtual bool haveSecretKey(const RsPgpId& gpg_id) ;
virtual bool getOnlineList(std::list<RsPeerId> &ids);
virtual bool getFriendList(std::list<RsPeerId> &ids);
//virtual bool getOthersList(std::list<std::string> &ids);
virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl);
virtual bool isOnline(const RsPeerId &id);
virtual bool isFriend(const RsPeerId &id);
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend); //
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend);
virtual std::string getGPGName(const RsPgpId &gpg_id);
virtual std::string getPeerName(const RsPeerId& ssl_or_gpg_id);
virtual bool getPeerDetails(const RsPeerId& ssl_or_gpg_id, RsPeerDetails &d);
@ -96,7 +94,7 @@ virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht);
virtual bool getProxyServer(const uint32_t type, std::string &addr, uint16_t &port,uint32_t& status);
virtual bool setProxyServer(const uint32_t type, const std::string &addr, const uint16_t port);
virtual bool isProxyAddress(const uint32_t type,const sockaddr_storage&);
virtual bool isProxyAddress(const uint32_t type, const sockaddr_storage &addr);
virtual void getIPServersList(std::list<std::string>& ip_servers);
virtual void allowServerIPDetermination(bool);
@ -146,7 +144,6 @@ virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileS
p3LinkMgr *mLinkMgr;
p3PeerMgr *mPeerMgr;
p3NetMgr *mNetMgr;
};
#endif