convert RSDHT_PEERTYPE_ to enum class

This commit is contained in:
sehraf 2020-02-19 19:29:37 +01:00
parent 7599b7ad9c
commit 1b1b09217a
No known key found for this signature in database
GPG Key ID: DF09F6EAE356B2C6
4 changed files with 50 additions and 47 deletions

View File

@ -45,7 +45,7 @@ class DhtPeerDetails
DhtPeerDetails(); DhtPeerDetails();
uint32_t mPeerType; RsDhtPeerType mPeerType;
bdId mDhtId; bdId mDhtId;
RsPeerId mRsId; RsPeerId mRsId;
@ -348,9 +348,9 @@ public:
private: private:
DhtPeerDetails *addInternalPeer_locked(const RsPeerId& pid, uint32_t type); DhtPeerDetails *addInternalPeer_locked(const RsPeerId& pid, RsDhtPeerType type);
int removeInternalPeer_locked(const RsPeerId& pid); int removeInternalPeer_locked(const RsPeerId& pid);
DhtPeerDetails *findInternalDhtPeer_locked(const bdNodeId *id, uint32_t type); DhtPeerDetails *findInternalDhtPeer_locked(const bdNodeId *id, RsDhtPeerType type);
DhtPeerDetails *findInternalRsPeer_locked(const RsPeerId &pid); DhtPeerDetails *findInternalRsPeer_locked(const RsPeerId &pid);
bool havePeerTranslation_locked(const RsPeerId &pid); bool havePeerTranslation_locked(const RsPeerId &pid);

View File

@ -83,7 +83,7 @@ int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
@ -204,7 +204,7 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
@ -717,7 +717,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
proxyPort = dpd->mConnectLogic.shouldUseProxyPort( proxyPort = dpd->mConnectLogic.shouldUseProxyPort(
@ -811,7 +811,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mExclusiveProxyLock = true; dpd->mExclusiveProxyLock = true;
@ -939,7 +939,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mPeerCbMsg = "ERROR : "; dpd->mPeerCbMsg = "ERROR : ";
@ -980,7 +980,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
if (errcode) if (errcode)
@ -1232,7 +1232,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
connectOk = true; connectOk = true;
@ -1387,7 +1387,7 @@ int p3BitDht::doActions()
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mPeerReqStatusMsg = "Connect Request"; dpd->mPeerReqStatusMsg = "Connect Request";
@ -1428,7 +1428,7 @@ int p3BitDht::doActions()
//} //}
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mConnectLogic.updateCb(failReason); dpd->mConnectLogic.updateCb(failReason);
@ -1496,7 +1496,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mSrcId.id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mSrcId.id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
if (action.mAnswer) if (action.mAnswer)
@ -1604,7 +1604,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
peerRsId = dpd->mRsId; peerRsId = dpd->mRsId;
@ -1730,7 +1730,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
rstime_t now = time(NULL); rstime_t now = time(NULL);
/* check if they are in our friend list */ /* check if they are in our friend list */
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId->id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId->id), RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
@ -1752,7 +1752,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
it->second.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; it->second.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE;
it->second.mDhtUpdateTS = now; it->second.mDhtUpdateTS = now;
it->second.mPeerType = RSDHT_PEERTYPE_OTHER; it->second.mPeerType = RsDhtPeerType::OTHER;
it->second.mPeerCbMsg = "Denied Non-Friend"; it->second.mPeerCbMsg = "Denied Non-Friend";
it->second.mPeerReqStatusMsg = "Denied Non-Friend"; it->second.mPeerReqStatusMsg = "Denied Non-Friend";
@ -1979,7 +1979,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerConnectId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerConnectId.id), RsDhtPeerType::FRIEND);
/* grab a socket */ /* grab a socket */
if (!dpd) if (!dpd)
{ {
@ -2092,22 +2092,22 @@ int p3BitDht::installRelayConnection(const bdId *srcId, const bdId *destId, uint
#endif #endif
/* grab a socket */ /* grab a socket */
DhtPeerDetails *dpd_src = findInternalDhtPeer_locked(&(srcId->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd_src = findInternalDhtPeer_locked(&(srcId->id), RsDhtPeerType::ANY);
DhtPeerDetails *dpd_dest = findInternalDhtPeer_locked(&(destId->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd_dest = findInternalDhtPeer_locked(&(destId->id), RsDhtPeerType::ANY);
if ((dpd_src) && (dpd_src->mPeerType == RSDHT_PEERTYPE_FRIEND)) if ((dpd_src) && (dpd_src->mPeerType == RsDhtPeerType::FRIEND))
{ {
relayClass = UDP_RELAY_CLASS_FRIENDS; relayClass = UDP_RELAY_CLASS_FRIENDS;
} }
else if ((dpd_dest) && (dpd_dest->mPeerType == RSDHT_PEERTYPE_FRIEND)) else if ((dpd_dest) && (dpd_dest->mPeerType == RsDhtPeerType::FRIEND))
{ {
relayClass = UDP_RELAY_CLASS_FRIENDS; relayClass = UDP_RELAY_CLASS_FRIENDS;
} }
else if ((dpd_src) && (dpd_src->mPeerType == RSDHT_PEERTYPE_FOF)) else if ((dpd_src) && (dpd_src->mPeerType == RsDhtPeerType::FOF))
{ {
relayClass = UDP_RELAY_CLASS_FOF; relayClass = UDP_RELAY_CLASS_FOF;
} }
else if ((dpd_dest) && (dpd_dest->mPeerType == RSDHT_PEERTYPE_FOF)) else if ((dpd_dest) && (dpd_dest->mPeerType == RsDhtPeerType::FOF))
{ {
relayClass = UDP_RELAY_CLASS_FOF; relayClass = UDP_RELAY_CLASS_FOF;
} }
@ -2178,7 +2178,7 @@ void p3BitDht::monitorConnections()
for(it = mPeers.begin(); it != mPeers.end(); ++it) for(it = mPeers.begin(); it != mPeers.end(); ++it)
{ {
/* ignore ones which aren't friends */ /* ignore ones which aren't friends */
if (it->second.mPeerType != RSDHT_PEERTYPE_FRIEND) if (it->second.mPeerType != RsDhtPeerType::FRIEND)
{ {
continue; continue;
} }

View File

@ -64,7 +64,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid); DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
if (!dpd) if (!dpd)
{ {
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND); dpd = addInternalPeer_locked(pid, RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
/* ERROR */ /* ERROR */
@ -150,7 +150,7 @@ bool p3BitDht::dropPeer(const RsPeerId& pid)
#endif #endif
//addFriend(pid); //addFriend(pid);
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FOF); dpd = addInternalPeer_locked(pid, RsDhtPeerType::FOF);
return false; return false;
} }
@ -242,7 +242,7 @@ int p3BitDht::addKnownPeer( const RsPeerId &pid,
addrv4.sin_addr = ap->sin_addr; addrv4.sin_addr = ap->sin_addr;
addrv4.sin_port = ap->sin_port; addrv4.sin_port = ap->sin_port;
int p3type = 0; RsDhtPeerType p3type = static_cast<RsDhtPeerType>(0);
int bdflags = 0; int bdflags = 0;
bdId id; bdId id;
bool isOwnId = false; bool isOwnId = false;
@ -253,27 +253,27 @@ int p3BitDht::addKnownPeer( const RsPeerId &pid,
return 0; return 0;
break; break;
case NETASSIST_KNOWN_PEER_WHITELIST: case NETASSIST_KNOWN_PEER_WHITELIST:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST; bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST;
break; break;
case NETASSIST_KNOWN_PEER_FOF: case NETASSIST_KNOWN_PEER_FOF:
p3type = RSDHT_PEERTYPE_FOF; p3type = RsDhtPeerType::FOF;
bdflags = BITDHT_PEER_STATUS_DHT_FOF; bdflags = BITDHT_PEER_STATUS_DHT_FOF;
break; break;
case NETASSIST_KNOWN_PEER_FRIEND: case NETASSIST_KNOWN_PEER_FRIEND:
p3type = RSDHT_PEERTYPE_FRIEND; p3type = RsDhtPeerType::FRIEND;
bdflags = BITDHT_PEER_STATUS_DHT_FRIEND; bdflags = BITDHT_PEER_STATUS_DHT_FRIEND;
break; break;
case NETASSIST_KNOWN_PEER_RELAY: case NETASSIST_KNOWN_PEER_RELAY:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER; bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER;
break; break;
case NETASSIST_KNOWN_PEER_SELF: case NETASSIST_KNOWN_PEER_SELF:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_SELF; bdflags = BITDHT_PEER_STATUS_DHT_SELF;
isOwnId = true; isOwnId = true;
@ -364,7 +364,7 @@ int p3BitDht::addFriend(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::FRIEND));
} }
@ -372,7 +372,7 @@ int p3BitDht::addFriendOfFriend(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_FOF)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::FOF));
} }
@ -380,7 +380,7 @@ int p3BitDht::addOther(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_OTHER)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::OTHER));
} }
#endif #endif
@ -397,7 +397,7 @@ int p3BitDht::removePeer(const RsPeerId& pid)
********************************* Basic Peer Details ************************************* ********************************* Basic Peer Details *************************************
******************************************************************************************/ ******************************************************************************************/
DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t type) DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, RsDhtPeerType type)
{ {
/* create the data structure */ /* create the data structure */
if (!havePeerTranslation_locked(pid)) if (!havePeerTranslation_locked(pid))
@ -411,7 +411,7 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t t
return 0; return 0;
} }
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id, RsDhtPeerType::ANY);
if (!dpd) if (!dpd)
{ {
DhtPeerDetails newdpd; DhtPeerDetails newdpd;
@ -419,10 +419,10 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t t
newdpd.mDhtId.id = id; newdpd.mDhtId.id = id;
newdpd.mRsId = pid; newdpd.mRsId = pid;
newdpd.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; newdpd.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE;
newdpd.mPeerType = RSDHT_PEERTYPE_ANY; newdpd.mPeerType = RsDhtPeerType::ANY;
mPeers[id] = newdpd; mPeers[id] = newdpd;
dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY); dpd = findInternalDhtPeer_locked(&id, RsDhtPeerType::ANY);
if(dpd == NULL) if(dpd == NULL)
{ {
@ -462,14 +462,14 @@ int p3BitDht::removeInternalPeer_locked(const RsPeerId& pid)
/* indexed by bdNodeId, as this is the more used call interface */ /* indexed by bdNodeId, as this is the more used call interface */
DhtPeerDetails *p3BitDht::findInternalDhtPeer_locked(const bdNodeId *id, uint32_t type) DhtPeerDetails *p3BitDht::findInternalDhtPeer_locked(const bdNodeId *id, RsDhtPeerType type)
{ {
std::map<bdNodeId, DhtPeerDetails>::iterator it = mPeers.find(*id); std::map<bdNodeId, DhtPeerDetails>::iterator it = mPeers.find(*id);
if (it == mPeers.end()) if (it == mPeers.end())
{ {
return NULL; return NULL;
} }
if (type) if (type != static_cast<RsDhtPeerType>(0))
{ {
if (it->second.mPeerType != type) if (it->second.mPeerType != type)
{ {
@ -495,7 +495,7 @@ DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const RsPeerId &pid)
return NULL; return NULL;
} }
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id,RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id,RsDhtPeerType::ANY);
return dpd; return dpd;
} }

View File

@ -36,10 +36,13 @@ extern RsDht *rsDht;
//std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail); //std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail);
//std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail); //std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
#define RSDHT_PEERTYPE_ANY 0x0000 enum class RsDhtPeerType : uint8_t
#define RSDHT_PEERTYPE_OTHER 0x0001 {
#define RSDHT_PEERTYPE_FOF 0x0002 ANY = 0,
#define RSDHT_PEERTYPE_FRIEND 0x0003 OTHER = 1,
FOF = 2,
FRIEND = 3
};
#define RSDHT_PEERDHT_NOT_ACTIVE 0x0000 #define RSDHT_PEERDHT_NOT_ACTIVE 0x0000
#define RSDHT_PEERDHT_SEARCHING 0x0001 #define RSDHT_PEERDHT_SEARCHING 0x0001
@ -102,7 +105,7 @@ class RsDhtNetPeer
std::string mDhtId; std::string mDhtId;
RsPeerId mRsId; RsPeerId mRsId;
uint32_t mPeerType; RsDhtPeerType mPeerType;
uint32_t mDhtState; uint32_t mDhtState;
std::string mConnectState; // connectLogic. std::string mConnectState; // connectLogic.