Added a seperation between 'desired' net mode and 'actual' net mode

this is needed for accurate stunlist creation. Also added stunStatus
calls from discovery.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@355 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-02-26 16:14:13 +00:00
parent 685182ff0b
commit 06cb9e0121
9 changed files with 144 additions and 27 deletions

View File

@ -102,9 +102,43 @@ p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am)
void p3ConnectMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
{
ownState.netMode = netMode;
/* only change TRY flags */
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::setOwnNetConfig()" << std::endl;
std::cerr << "Existing netMode: " << ownState.netMode << " vis: " << ownState.visState;
std::cerr << std::endl;
std::cerr << "Input netMode: " << netMode << " vis: " << visState;
std::cerr << std::endl;
#endif
ownState.netMode &= ~(RS_NET_MODE_TRYMODE);
#ifdef CONN_DEBUG
std::cerr << "After Clear netMode: " << ownState.netMode << " vis: " << ownState.visState;
std::cerr << std::endl;
#endif
switch(netMode & RS_NET_MODE_ACTUAL)
{
case RS_NET_MODE_EXT:
ownState.netMode |= RS_NET_MODE_TRY_EXT;
break;
case RS_NET_MODE_UPNP:
ownState.netMode |= RS_NET_MODE_TRY_UPNP;
break;
default:
case RS_NET_MODE_UDP:
ownState.netMode |= RS_NET_MODE_TRY_UDP;
break;
}
ownState.visState = visState;
#ifdef CONN_DEBUG
std::cerr << "Final netMode: " << ownState.netMode << " vis: " << ownState.visState;
std::cerr << std::endl;
#endif
/* if we've started up - then tweak Dht On/Off */
if (mNetStatus != RS_NET_UNKNOWN)
{
@ -190,15 +224,23 @@ void p3ConnectMgr::netStartup()
mNetInitTS = time(NULL);
switch(ownState.netMode)
ownState.netMode &= ~(RS_NET_MODE_ACTUAL);
switch(ownState.netMode & RS_NET_MODE_TRYMODE)
{
case RS_NET_MODE_UPNP:
case RS_NET_MODE_TRY_UPNP:
mNetStatus = RS_NET_UPNP_INIT;
ownState.netMode |= RS_NET_MODE_UDP;
break;
case RS_NET_MODE_EXT: /* v similar to UDP */
case RS_NET_MODE_UDP:
case RS_NET_MODE_TRY_EXT: /* v similar to UDP */
ownState.netMode |= RS_NET_MODE_EXT;
mNetStatus = RS_NET_UDP_SETUP;
break;
case RS_NET_MODE_TRY_UDP:
default:
ownState.netMode |= RS_NET_MODE_UDP;
mNetStatus = RS_NET_UDP_SETUP;
break;
@ -341,9 +383,9 @@ void p3ConnectMgr::netUpnpCheck()
/* fallback to UDP startup */
connMtx.lock(); /* LOCK MUTEX */
/* UPnP Failed us! */
mUpnpAddrValid = false;
mNetStatus = RS_NET_UDP_SETUP;
//ownState.netMode = RS_NET_MODE_UDP; /* UPnP Failed us! */
connMtx.unlock(); /* UNLOCK MUTEX */
}
@ -356,6 +398,8 @@ void p3ConnectMgr::netUpnpCheck()
mUpnpAddrValid = true;
mUpnpExtAddr = extAddr;
mNetStatus = RS_NET_UDP_SETUP;
/* Fix netMode & Clear others! */
ownState.netMode = RS_NET_MODE_TRY_UPNP | RS_NET_MODE_UPNP;
connMtx.unlock(); /* UNLOCK MUTEX */
}
@ -411,7 +455,8 @@ void p3ConnectMgr::netUdpCheck()
}
else
{
mDhtMgr->setExternalInterface(iaddr, extAddr, RS_NET_MODE_ERROR);
/* mode = 0 for error */
mDhtMgr->setExternalInterface(iaddr, extAddr, mode);
}
}
}
@ -1127,6 +1172,7 @@ void p3ConnectMgr::peerStatus(std::string id,
* but no need for action as should be connected already
*/
it->second.netMode &= (~RS_NET_MODE_ACTUAL); /* clear actual flags */
if (flags & RS_NET_FLAGS_EXTERNAL_ADDR)
{
it->second.netMode = RS_NET_MODE_EXT;
@ -2017,7 +2063,19 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
item->clear();
item->pid = getOwnId();
item->netMode = ownState.netMode;
if (ownState.netMode & RS_NET_MODE_TRY_EXT)
{
item->netMode = RS_NET_MODE_EXT;
}
else if (ownState.netMode & RS_NET_MODE_TRY_UPNP)
{
item->netMode = RS_NET_MODE_UPNP;
}
else
{
item->netMode = RS_NET_MODE_UDP;
}
item->visState = ownState.visState;
item->lastContact = ownState.lastcontact;
item->localaddr = ownState.localaddr;
@ -2062,6 +2120,14 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
{
sitem->stunList.ids.push_back(*sit);
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::saveList() Peer Stun Item:";
std::cerr << std::endl;
sitem->print(std::cerr, 10);
std::cerr << std::endl;
#endif
saveData.push_back(sitem);
return saveData;

View File

@ -54,11 +54,22 @@ const uint32_t RS_VIS_STATE_BROWN = RS_VIS_STATE_NODISC;
/* Startup Modes (confirmed later) */
const uint32_t RS_NET_MODE_TRYMODE = 0x00f0;
const uint32_t RS_NET_MODE_TRY_EXT = 0x0010;
const uint32_t RS_NET_MODE_TRY_UPNP = 0x0020;
const uint32_t RS_NET_MODE_TRY_UDP = 0x0040;
/* Actual State */
const uint32_t RS_NET_MODE_ACTUAL = 0x000f;
const uint32_t RS_NET_MODE_UNKNOWN = 0x0000;
const uint32_t RS_NET_MODE_EXT = 0x0001;
const uint32_t RS_NET_MODE_UPNP = 0x0002;
const uint32_t RS_NET_MODE_UDP = 0x0003;
const uint32_t RS_NET_MODE_ERROR = 0x0004;
const uint32_t RS_NET_MODE_UDP = 0x0004;
const uint32_t RS_NET_MODE_ERROR = 0x0008;
/* order of attempts ... */

View File

@ -60,6 +60,7 @@ const uint32_t RS_PEER_CONNECT_REQ = 0x0020;
//const uint32_t RS_STUN_SRC_PEER = 0x0002;
const uint32_t RS_STUN_ONLINE = 0x0010;
const uint32_t RS_STUN_FRIEND = 0x0020;
const uint32_t RS_STUN_FRIEND_OF_FRIEND = 0x0040;

View File

@ -94,6 +94,7 @@ class RsPeerDetails
uint16_t extPort;
uint32_t netMode;
uint32_t tryNetMode; /* only for ownState */
uint32_t visState;
/* basic stats */

View File

@ -273,20 +273,33 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
if (pcs.state & RS_PEER_S_CONNECTED)
d.state |= RS_PEER_STATE_CONNECTED;
switch(pcs.netMode)
switch(pcs.netMode & RS_NET_MODE_ACTUAL)
{
case RS_NET_MODE_EXT:
d.netMode = RS_NETMODE_EXT;
break;
case RS_NET_MODE_UDP:
d.netMode = RS_NETMODE_UDP;
break;
case RS_NET_MODE_UNKNOWN:
case RS_NET_MODE_ERROR:
case RS_NET_MODE_UPNP:
default:
d.netMode = RS_NETMODE_UPNP;
break;
case RS_NET_MODE_UDP:
case RS_NET_MODE_UNKNOWN:
case RS_NET_MODE_ERROR:
default:
d.netMode = RS_NETMODE_UDP;
break;
}
if (pcs.netMode & RS_NET_MODE_TRY_EXT)
{
d.tryNetMode = RS_NETMODE_EXT;
}
else if (pcs.netMode & RS_NET_MODE_TRY_UPNP)
{
d.tryNetMode = RS_NETMODE_UPNP;
}
else
{
d.tryNetMode = RS_NETMODE_UDP;
}
d.visState = 0;
@ -411,16 +424,17 @@ bool p3Peers::setNetworkMode(std::string id, uint32_t extNetMode)
uint32_t netMode = 0;
switch(extNetMode)
{
case RS_NETMODE_UDP:
netMode = RS_NET_MODE_UDP;
break;
case RS_NETMODE_EXT:
netMode = RS_NET_MODE_EXT;
break;
default:
case RS_NETMODE_UPNP:
netMode = RS_NET_MODE_UPNP;
break;
case RS_NETMODE_UDP:
netMode = RS_NET_MODE_UDP;
break;
default:
break;
}
return mConnMgr->setNetworkMode(id, netMode);

View File

@ -334,7 +334,7 @@ void p3disc::sendOwnDetails(std::string to)
di->discFlags |= P3DISC_FLAGS_USE_DHT;
}
if ((detail.netMode == RS_NET_MODE_EXT) ||
if ((detail.netMode & RS_NET_MODE_EXT) ||
(detail.netMode & RS_NET_MODE_UPNP))
{
di->discFlags |= P3DISC_FLAGS_EXTERNAL_ADDR;
@ -408,7 +408,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
di->discFlags |= P3DISC_FLAGS_USE_DHT;
}
if (detail.netMode == RS_NET_MODE_EXT)
if (detail.netMode & RS_NET_MODE_EXT)
{
di->discFlags |= P3DISC_FLAGS_EXTERNAL_ADDR;
}
@ -483,6 +483,10 @@ void p3disc::recvPeerOwnMsg(RsDiscItem *item)
mConnMgr->peerStatus(item->PeerId(), item->laddr, item->saddr,
type, flags, RS_CB_PERSON);
/* also add as potential stun buddy */
mConnMgr->stunStatus(item->PeerId(), item->saddr, type,
RS_STUN_ONLINE | RS_STUN_FRIEND);
/* now reply with all details */
respondToPeer(item->PeerId());
@ -540,6 +544,10 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
{
mConnMgr->peerStatus(peerId, item->laddr,
item->saddr, type, flags, RS_CB_DISC);
mConnMgr->stunStatus(peerId, item->saddr, type,
RS_STUN_FRIEND_OF_FRIEND);
}
addDiscoveryData(item->PeerId(), peerId, item->laddr, item->saddr, item->discFlags, time(NULL));

View File

@ -181,7 +181,7 @@ void ChatDialog::insertChat()
QString timestamp = "[" + QDateTime::currentDateTime().toString("hh:mm:ss") + "]";
QString name = QString::fromStdString(it->name);
QString line = "<span style=\"color:#C00000\"><strong>" + timestamp + "</strong></span>" +
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span> \<br>";
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span> <br>";
extraTxt += line;

View File

@ -79,7 +79,7 @@ void ServerDialog::load()
/* set net mode */
int netIndex = 0;
switch(detail.netMode)
switch(detail.tryNetMode)
{
case RS_NETMODE_EXT:
netIndex = 2;
@ -120,7 +120,22 @@ void ServerDialog::load()
/* set status */
std::ostringstream out;
out << "Network Mode: ";
out << "Attempted Network Mode: ";
switch(detail.tryNetMode)
{
case RS_NETMODE_EXT:
out << "External Forwarded Port (UltraPEER Mode)";
break;
case RS_NETMODE_UDP:
out << "Firewalled";
break;
default:
case RS_NETMODE_UPNP:
out << "Automatic: UPnP Forwarded Port";
break;
}
out << std::endl;
out << "Actual Network Mode: ";
switch(detail.netMode)
{
case RS_NETMODE_EXT:
@ -239,7 +254,7 @@ void ServerDialog::saveAddresses()
break;
}
if (detail.netMode != netMode)
if (detail.tryNetMode != netMode)
{
rsPeers->setNetworkMode(ownId, netMode);
}

View File

@ -94,6 +94,7 @@ class RsPeerDetails
uint16_t extPort;
uint32_t netMode;
uint32_t tryNetMode; /* only for ownState */
uint32_t visState;
/* basic stats */