Commmit the code from Thunder

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2754 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2010-04-22 18:49:08 +00:00
parent c79d55a7a7
commit 948e4fb61d
15 changed files with 204 additions and 5 deletions

View File

@ -791,7 +791,13 @@ void p3ConnectMgr::networkConsistencyCheck()
if (!doNetReset) {//set an external address. if ip adresses are different, let's use the stun address, then the extaddrfinder and then the upnp address.
struct sockaddr_in extAddr;
if (getExtFinderExtAddress(extAddr)) {
if (!ownState.dyndns.empty () && getIPAddressFromString (ownState.dyndns.c_str (), &extAddr.sin_addr)) {
#ifdef CONN_DEBUG_TICK
std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getIPAddressFromString for ownState.serveraddr." << std::endl;
#endif
extAddr.sin_port = ownState.currentserveraddr.sin_port;
ownState.currentserveraddr = extAddr;
} if (getExtFinderExtAddress(extAddr)) {
netExtFinderAddressCheck(); //so we put the extra address flag ok.
#ifdef CONN_DEBUG_TICK
std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getExtFinderExtAddress for ownState.serveraddr." << std::endl;
@ -2359,7 +2365,7 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
peerConnectAddress pca;
pca.addr = ipListIt->ipAddr;
pca.type = RS_NET_CONN_TCP_UNKNOW_TOPOLOGY;
//fir the delay, we add a random time and some more time when the friend list is big
//for the delay, we add a random time and some more time when the friend list is big
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY + rand() % 3 + (mFriendList.size() / 5);
pca.ts = time(NULL);
pca.period = 0;
@ -2367,6 +2373,43 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
}
}
if (!it->second.dyndns.empty()) {
struct in_addr addr;
u_short port = it->second.currentserveraddr.sin_port ? it->second.currentserveraddr.sin_port : it->second.currentlocaladdr.sin_port;
if (port) {
if (getIPAddressFromString (it->second.dyndns.c_str (), &addr)) {
bool found = false;
for (std::list<peerConnectAddress>::iterator cit = it->second.connAddrs.begin(); cit != it->second.connAddrs.end(); cit++) {
if (cit->addr.sin_addr.s_addr == addr.s_addr &&
cit->addr.sin_port == port &&
cit->type == RS_NET_CONN_TCP_UNKNOW_TOPOLOGY) {
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() tcp attempt already in list." << std::endl;
#endif
found = true;
break;
}
}
if (!found) {
#ifdef CONN_DEBUG
std::cerr << "Adding tcp connection attempt list." << std::endl;
#endif
peerConnectAddress pca;
pca.addr.sin_family = AF_INET;
pca.addr.sin_addr.s_addr = addr.s_addr;
pca.addr.sin_port = port;
pca.type = RS_NET_CONN_TCP_UNKNOW_TOPOLOGY;
//for the delay, we add a random time and some more time when the friend list is big
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY + rand() % 3 + (mFriendList.size() / 5);
pca.ts = time(NULL);
pca.period = 0;
it->second.connAddrs.push_back(pca);
}
}
}
}
//add the supposed external address UDP
IpAddressTimed extractedAddress;
if (peerConnectState::extractExtAddress(it->second.getIpAddressList(), extractedAddress)) {
@ -2632,6 +2675,36 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
return true;
}
bool p3ConnectMgr::setDynDNS(std::string id, std::string dyndns)
{
if (id == AuthSSL::getAuthSSL()->OwnId())
{
ownState.dyndns = dyndns;
return true;
}
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
{
if (mOthersList.end() == (it = mOthersList.find(id)))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::setLocalAddress() cannot add addres info : peer id not found in friend list id: " << id << std::endl;
#endif
return false;
}
}
/* "it" points to peer */
it->second.dyndns = dyndns;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
bool p3ConnectMgr::setAddressList(std::string id, std::list<IpAddressTimed> IpAddressTimedList)
{
#ifdef CONN_DEBUG
@ -2912,6 +2985,7 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
item->currentlocaladdr = ownState.currentlocaladdr;
item->currentremoteaddr = ownState.currentserveraddr;
item->dyndns = ownState.dyndns;
item->ipAddressList = ownState.getIpAddressList();
#ifdef CONN_DEBUG
@ -2937,7 +3011,8 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
item->lastContact = (it->second).lastcontact;
item->currentlocaladdr = (it->second).currentlocaladdr;
item->currentremoteaddr = (it->second).currentserveraddr;
item->ipAddressList = (it->second).getIpAddressList();
item->dyndns = (it->second).dyndns;
item->ipAddressList = (it->second).getIpAddressList();
saveData.push_back(item);
#ifdef CONN_DEBUG
@ -3043,6 +3118,7 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
}
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
setExtAddress(pitem->pid, pitem->currentremoteaddr);
setDynDNS (pitem->pid, pitem->dyndns);
setAddressList(pitem->pid, pitem->ipAddressList);
}
else if (sitem)

View File

@ -158,6 +158,7 @@ class peerConnectState
//used to store current ip (for config and connection management)
struct sockaddr_in currentlocaladdr; /* Mandatory */
struct sockaddr_in currentserveraddr; /* Mandatory */
std::string dyndns;
time_t lastcontact;
@ -228,6 +229,7 @@ bool getNetStatusExtraAddressCheckOk();
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
bool setLocalAddress(std::string id, struct sockaddr_in addr);
bool setExtAddress(std::string id, struct sockaddr_in addr);
bool setDynDNS(std::string id, std::string dyndns);
bool setAddressList(std::string id, std::list<IpAddressTimed> IpAddressTimedList);
bool setNetworkMode(std::string id, uint32_t netMode);

View File

@ -106,6 +106,7 @@ class RsPeerDetails
uint16_t localPort;
std::string extAddr;
uint16_t extPort;
std::string dyndns;
std::list<std::string> ipAddressList;
uint32_t netMode;
@ -166,6 +167,7 @@ virtual bool connectAttempt(std::string ssl_id) = 0;
virtual bool setLocation(std::string ssl_id, std::string location) = 0;//location is shown in the gui to differentiate ssl certs
virtual bool setLocalAddress(std::string ssl_id, std::string addr, uint16_t port) = 0;
virtual bool setExtAddress( std::string ssl_id, std::string addr, uint16_t port) = 0;
virtual bool setDynDNS(std::string id, std::string addr) = 0;
virtual bool setNetworkMode(std::string ssl_id, uint32_t netMode) = 0;
virtual bool setVisState(std::string ssl_id, uint32_t vis) = 0;

View File

@ -42,6 +42,7 @@ const std::string CERT_SSL_ID = "--SSLID--";
const std::string CERT_LOCATION = "--LOCATION--";
const std::string CERT_LOCAL_IP = "--LOCAL--";
const std::string CERT_EXT_IP = "--EXT--";
const std::string CERT_DYNDNS = "--DYNDNS--";
@ -308,6 +309,7 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
d.localPort = ntohs(best_local_addr.sin_port);
d.extAddr = inet_ntoa(best_servr_addr.sin_addr);
d.extPort = ntohs(best_servr_addr.sin_port);
d.dyndns = pcs.dyndns;
d.lastConnect = pcs.lastcontact;
d.connectPeriod = 0;
std::list<std::string> ipAddressList;
@ -729,6 +731,10 @@ bool p3Peers::setExtAddress(std::string id, std::string addr_str, uint16_t port
return false;
}
bool p3Peers::setDynDNS(std::string id, std::string dyndns)
{
return mConnMgr->setDynDNS(id, dyndns);
}
bool p3Peers::setNetworkMode(std::string id, uint32_t extNetMode)
{
@ -800,6 +806,9 @@ p3Peers::GetRetroshareInvite()
std::ostringstream out2;
out2 << ownDetail.extPort;
invite += out2.str() + ";";
if (!ownDetail.dyndns.empty()) {
invite += "\n" + CERT_DYNDNS + ownDetail.dyndns + ";";
}
}
#ifdef P3PEERS_DEBUG
@ -976,6 +985,19 @@ bool p3Peers::loadDetailsFromStringCert(std::string certstr, RsPeerDetails &pd)
}
}
//let's parse DynDNS
parsePosition = certstr.find(CERT_DYNDNS);
std::cerr << "location DynDNS : " << parsePosition << std::endl;
if (parsePosition != std::string::npos) {
parsePosition += CERT_DYNDNS.length();
std::string subCert = certstr.substr(parsePosition);
parsePosition = subCert.find(";");
if (parsePosition != std::string::npos) {
std::string DynDNS = subCert.substr(0, parsePosition);
std::cerr << "DynDNS : " << DynDNS << std::endl;
pd.dyndns = DynDNS;
}
}
} catch (...) {
std::cerr << "ConnectFriendWizard : Parse ip address error." << std::endl;

View File

@ -75,6 +75,7 @@ virtual bool connectAttempt(std::string id);
virtual bool setLocation(std::string ssl_id, std::string location);//location is shown in the gui to differentiate ssl certs
virtual bool setLocalAddress(std::string id, std::string addr, uint16_t port);
virtual bool setExtAddress(std::string id, std::string addr, uint16_t port);
virtual bool setDynDNS(std::string id, std::string dyndns);
virtual bool setNetworkMode(std::string id, uint32_t netMode);
virtual bool setVisState(std::string id, uint32_t mode);

View File

@ -740,6 +740,7 @@ void RsPeerNetItem::clear()
sockaddr_clear(&currentlocaladdr);
sockaddr_clear(&currentremoteaddr);
dyndns.clear();
}
std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent)
@ -773,6 +774,9 @@ std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent)
out << "currentremoteaddr: " << inet_ntoa(currentremoteaddr.sin_addr);
out << ":" << htons(currentremoteaddr.sin_port) << std::endl;
printIndent(out, int_Indent);
out << "DynDNS: " << dyndns << std::endl;
printIndent(out, int_Indent);
out << "ipAdressList: size : " << ipAddressList.size() << ", adresses : " << std::endl;
for (std::list<IpAddressTimed>::iterator ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()); ipListIt++) {
@ -797,6 +801,7 @@ uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i)
s += 4; /* lastContact */
s += GetTlvIpAddrPortV4Size(); /* localaddr */
s += GetTlvIpAddrPortV4Size(); /* remoteaddr */
s += GetTlvStringSize(i->dyndns);
//add the size of the ip list
int ipListSize = i->ipAddressList.size();
@ -840,6 +845,7 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3
ok &= setRawUInt32(data, tlvsize, &offset, item->lastContact); /* Mandatory */
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_LOCAL, &(item->currentlocaladdr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(item->currentremoteaddr));
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns);
//store the ip list
std::list<IpAddressTimed>::iterator ipListIt;
@ -900,6 +906,7 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size
ok &= getRawUInt32(data, rssize, &offset, &(item->lastContact)); /* Mandatory */
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_LOCAL, &(item->currentlocaladdr));
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_REMOTE, &(item->currentremoteaddr));
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns);
//get the ip adress list
std::list<IpAddressTimed> ipTimedList;

View File

@ -79,6 +79,7 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
struct sockaddr_in currentlocaladdr; /* Mandatory */
struct sockaddr_in currentremoteaddr; /* Mandatory */
std::string dyndns;
std::list<IpAddressTimed> ipAddressList;
};

View File

@ -155,6 +155,7 @@ const uint16_t TLV_TYPE_STR_HASH_ED2K = 0x0071;
const uint16_t TLV_TYPE_IPV4_LOCAL = 0x0080;
const uint16_t TLV_TYPE_IPV4_REMOTE = 0x0081;
const uint16_t TLV_TYPE_IPV4_LAST = 0x0082;
const uint16_t TLV_TYPE_STR_DYNDNS = 0x0083;
/*** MORE STRING IDS ****/
const uint16_t TLV_TYPE_STR_GROUPID = 0x00a0;

View File

@ -349,6 +349,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
rsPeerNetItem->lastContact = detail.lastcontact;
rsPeerNetItem->currentlocaladdr = detail.currentlocaladdr;
rsPeerNetItem->currentremoteaddr = detail.currentserveraddr;
rsPeerNetItem->dyndns = detail.dyndns;
rsPeerNetItem->ipAddressList = detail.getIpAddressList();
di->rsPeerList.push_back(*rsPeerNetItem);
@ -369,6 +370,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
rsPeerNetItem->lastContact = time(NULL);
rsPeerNetItem->currentlocaladdr = detail.currentlocaladdr;
rsPeerNetItem->currentremoteaddr = detail.currentserveraddr;
rsPeerNetItem->dyndns = detail.dyndns;
rsPeerNetItem->ipAddressList = detail.getIpAddressList();
di->rsPeerList.push_back(*rsPeerNetItem);
@ -550,6 +552,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
//their info is fresher than ours (there is a 10000 seconds margin), update ours
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
mConnMgr->setDynDNS(pitem->pid, pitem->dyndns);
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
if (item->PeerId() == pitem->pid) {
mConnMgr->setVisState(pitem->pid, pitem->visState); //update vistate only if it's from the peer itself

View File

@ -123,5 +123,15 @@ bool isExternalNet(struct in_addr *addr)
return true;
}
bool getIPAddressFromString (const char *addr_str, struct in_addr *addr)
{
if (addr_str && addr) {
hostent *pHost = gethostbyname (addr_str);
if (pHost) {
addr->s_addr = *(unsigned long*) (pHost->h_addr);
return true;
}
}
return false;
}

View File

@ -68,5 +68,7 @@ bool isLoopbackNet(struct in_addr *addr);
bool isPrivateNet(struct in_addr *addr);
bool isExternalNet(struct in_addr *addr);
/* convert addresses */
bool getIPAddressFromString (const char *addr_str, struct in_addr *addr);
#endif /* RS_UNIVERSAL_NETWORK_HEADER */

View File

@ -450,6 +450,16 @@ p, li { white-space: pre-wrap; }
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Dynamic DNS:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="DynDNS"/>
</item>
</layout>
</item>
<item row="1" column="0">
@ -636,6 +646,15 @@ p, li { white-space: pre-wrap; }
<attribute name="verticalHeaderDefaultSectionSize">
<number>22</number>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>22</number>
</attribute>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Directory</string>

View File

@ -141,6 +141,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Dynamic DNS</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -151,6 +158,9 @@
<item>
<widget class="QLineEdit" name="extAddress"/>
</item>
<item>
<widget class="QLineEdit" name="dynDNS"/>
</item>
</layout>
</item>
<item>
@ -169,6 +179,22 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>27</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
@ -199,6 +225,19 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>

View File

@ -160,6 +160,8 @@ void ServerPage::load()
/* set the server address */
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
ui.extPort -> setValue(detail.extPort);
/* set DynDNS */
ui.dynDNS -> setText(QString::fromStdString(detail.dyndns));
}
/** Loads the settings for this page */
@ -262,7 +264,9 @@ void ServerPage::saveAddresses()
rsPeers->setExtAddress(rsPeers->getOwnId(), ui.extAddress->text().toStdString(), ui.extPort->value());
}
rsicontrol->ConfigSetDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() );
rsPeers->setDynDNS(rsPeers->getOwnId(), ui.dynDNS->text().toStdString());
rsicontrol->ConfigSetDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() );
load();
}

View File

@ -691,6 +691,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Dynamic DNS</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -744,6 +751,9 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="dynDNS"/>
</item>
</layout>
</item>
</layout>