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

View File

@ -64,7 +64,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
if (!dpd)
{
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND);
dpd = addInternalPeer_locked(pid, RsDhtPeerType::FRIEND);
if (!dpd)
{
/* ERROR */
@ -150,7 +150,7 @@ bool p3BitDht::dropPeer(const RsPeerId& pid)
#endif
//addFriend(pid);
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FOF);
dpd = addInternalPeer_locked(pid, RsDhtPeerType::FOF);
return false;
}
@ -242,7 +242,7 @@ int p3BitDht::addKnownPeer( const RsPeerId &pid,
addrv4.sin_addr = ap->sin_addr;
addrv4.sin_port = ap->sin_port;
int p3type = 0;
RsDhtPeerType p3type = static_cast<RsDhtPeerType>(0);
int bdflags = 0;
bdId id;
bool isOwnId = false;
@ -253,27 +253,27 @@ int p3BitDht::addKnownPeer( const RsPeerId &pid,
return 0;
break;
case NETASSIST_KNOWN_PEER_WHITELIST:
p3type = RSDHT_PEERTYPE_OTHER;
p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST;
break;
case NETASSIST_KNOWN_PEER_FOF:
p3type = RSDHT_PEERTYPE_FOF;
p3type = RsDhtPeerType::FOF;
bdflags = BITDHT_PEER_STATUS_DHT_FOF;
break;
case NETASSIST_KNOWN_PEER_FRIEND:
p3type = RSDHT_PEERTYPE_FRIEND;
p3type = RsDhtPeerType::FRIEND;
bdflags = BITDHT_PEER_STATUS_DHT_FRIEND;
break;
case NETASSIST_KNOWN_PEER_RELAY:
p3type = RSDHT_PEERTYPE_OTHER;
p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER;
break;
case NETASSIST_KNOWN_PEER_SELF:
p3type = RSDHT_PEERTYPE_OTHER;
p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_SELF;
isOwnId = true;
@ -364,7 +364,7 @@ int p3BitDht::addFriend(const std::string pid)
{
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 *********/
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 *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_OTHER));
return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::OTHER));
}
#endif
@ -397,7 +397,7 @@ int p3BitDht::removePeer(const RsPeerId& pid)
********************************* 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 */
if (!havePeerTranslation_locked(pid))
@ -411,7 +411,7 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t t
return 0;
}
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY);
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id, RsDhtPeerType::ANY);
if (!dpd)
{
DhtPeerDetails newdpd;
@ -419,10 +419,10 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t t
newdpd.mDhtId.id = id;
newdpd.mRsId = pid;
newdpd.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE;
newdpd.mPeerType = RSDHT_PEERTYPE_ANY;
newdpd.mPeerType = RsDhtPeerType::ANY;
mPeers[id] = newdpd;
dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY);
dpd = findInternalDhtPeer_locked(&id, RsDhtPeerType::ANY);
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 */
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);
if (it == mPeers.end())
{
return NULL;
}
if (type)
if (type != static_cast<RsDhtPeerType>(0))
{
if (it->second.mPeerType != type)
{
@ -495,7 +495,7 @@ DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const RsPeerId &pid)
return NULL;
}
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id,RSDHT_PEERTYPE_ANY);
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id,RsDhtPeerType::ANY);
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 RsPhotoDetails &detail);
#define RSDHT_PEERTYPE_ANY 0x0000
#define RSDHT_PEERTYPE_OTHER 0x0001
#define RSDHT_PEERTYPE_FOF 0x0002
#define RSDHT_PEERTYPE_FRIEND 0x0003
enum class RsDhtPeerType : uint8_t
{
ANY = 0,
OTHER = 1,
FOF = 2,
FRIEND = 3
};
#define RSDHT_PEERDHT_NOT_ACTIVE 0x0000
#define RSDHT_PEERDHT_SEARCHING 0x0001
@ -102,7 +105,7 @@ class RsDhtNetPeer
std::string mDhtId;
RsPeerId mRsId;
uint32_t mPeerType;
RsDhtPeerType mPeerType;
uint32_t mDhtState;
std::string mConnectState; // connectLogic.