first commit, change some members name from localaddr to currentlocaladdr, and add ip lists in the classes. Not used yet to connect or exchange

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1804 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2009-11-11 16:43:51 +00:00
parent a444484734
commit 00361c22a5
12 changed files with 156 additions and 115 deletions

View File

@ -102,8 +102,8 @@ peerConnectState::peerConnectState()
source(0),
inConnAttempt(0)
{
sockaddr_clear(&localaddr);
sockaddr_clear(&serveraddr);
sockaddr_clear(&currentlocaladdr);
sockaddr_clear(&currentserveraddr);
return;
}
@ -114,10 +114,10 @@ std::string textPeerConnectState(peerConnectState &state)
out << "Id: " << state.id << std::endl;
out << "NetMode: " << state.netMode << std::endl;
out << "VisState: " << state.visState << std::endl;
out << "laddr: " << inet_ntoa(state.localaddr.sin_addr)
<< ":" << ntohs(state.localaddr.sin_port) << std::endl;
out << "eaddr: " << inet_ntoa(state.serveraddr.sin_addr)
<< ":" << ntohs(state.serveraddr.sin_port) << std::endl;
out << "laddr: " << inet_ntoa(state.currentlocaladdr.sin_addr)
<< ":" << ntohs(state.currentlocaladdr.sin_port) << std::endl;
out << "eaddr: " << inet_ntoa(state.currentserveraddr.sin_addr)
<< ":" << ntohs(state.currentserveraddr.sin_port) << std::endl;
std::string output = out.str();
return output;
@ -586,7 +586,7 @@ void p3ConnectMgr::netUdpInit()
#endif
connMtx.lock(); /* LOCK MUTEX */
struct sockaddr_in iaddr = ownState.localaddr;
struct sockaddr_in iaddr = ownState.currentlocaladdr;
connMtx.unlock(); /* UNLOCK MUTEX */
@ -622,8 +622,8 @@ void p3ConnectMgr::netUpnpInit()
/* get the ports from the configuration */
mNetStatus = RS_NET_UPNP_SETUP;
iport = ntohs(ownState.localaddr.sin_port);
eport = ntohs(ownState.serveraddr.sin_port);
iport = ntohs(ownState.currentlocaladdr.sin_port);
eport = ntohs(ownState.currentserveraddr.sin_port);
if ((eport < 1000) || (eport > 30000))
{
eport = iport;
@ -746,19 +746,19 @@ void p3ConnectMgr::networkConsistencyCheck()
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::networkConsistencyCheck() using STUN for ownState.serveraddr." << std::endl;
#endif
ownState.serveraddr = extAddr;
ownState.currentserveraddr = extAddr;
} else {
//call the extrafinder address
if (getExtFinderExtAddress(extAddr)) {
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::networkConsistencyCheck() using External address finder for ownState.serveraddr." << std::endl;
#endif
ownState.serveraddr = extAddr;
ownState.currentserveraddr = extAddr;
} else if (getUpnpExtAddress(extAddr)) {
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::networkConsistencyCheck() using UPNP for ownState.serveraddr." << std::endl;
#endif
ownState.serveraddr = extAddr;
ownState.currentserveraddr = extAddr;
} else {
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::networkConsistencyCheck() no external ip address." << std::endl;
@ -1515,15 +1515,16 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
it->second.lastattempt = time(NULL); /* time of last connect attempt */
it->second.inConnAttempt = true;
it->second.currentConnAddr = it->second.connAddrs.front();
it->second.currentConnAddrAttempt = it->second.connAddrs.front();
it->second.connAddrs.pop_front();
addr = it->second.currentConnAddr.addr;
delay = it->second.currentConnAddr.delay;
period = it->second.currentConnAddr.period;
type = it->second.currentConnAddr.type;
#ifdef CONN_DEBUG
addr = it->second.currentConnAddrAttempt.addr;
delay = it->second.currentConnAddrAttempt.delay;
period = it->second.currentConnAddrAttempt.period;
type = it->second.currentConnAddrAttempt.type;
std::cerr << "p3ConnectMgr::connectAttempt() Success: ";
std::cerr << " id: " << id;
std::cerr << std::endl;
@ -1772,8 +1773,8 @@ void p3ConnectMgr::peerStatus(std::string id,
it->second.source = RS_CB_PERSON;
it->second.peer = details;
it->second.localaddr = laddr;
it->second.serveraddr = raddr;
it->second.currentlocaladdr = laddr;
it->second.currentserveraddr = raddr;
it->second.state |= RS_PEER_S_ONLINE;
it->second.lastavailable = now;
@ -1924,7 +1925,7 @@ void p3ConnectMgr::peerStatus(std::string id,
/* if address is same -> try local */
if ((isValidNet(&(details.laddr.sin_addr))) &&
(sameNet(&(ownState.localaddr.sin_addr), &(details.laddr.sin_addr))))
(sameNet(&(ownState.currentlocaladdr.sin_addr), &(details.laddr.sin_addr))))
{
/* add the local address */
@ -1970,8 +1971,8 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << " id: " << id;
std::cerr << " laddr: " << inet_ntoa(details.laddr.sin_addr);
std::cerr << ": " << ntohs(details.laddr.sin_port);
std::cerr << " own.laddr: " << inet_ntoa(ownState.localaddr.sin_addr);
std::cerr << ": " << ntohs(ownState.localaddr.sin_port);
std::cerr << " own.laddr: " << inet_ntoa(ownState.currentlocaladdr.sin_addr);
std::cerr << ": " << ntohs(ownState.currentlocaladdr.sin_port);
std::cerr << std::endl;
#endif
}
@ -2546,21 +2547,21 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
#ifndef P3CONNMGR_NO_TCP_CONNECTIONS
/* if address is same -> try local */
if ((isValidNet(&(it->second.localaddr.sin_addr))) &&
(sameNet(&(ownState.localaddr.sin_addr),
&(it->second.localaddr.sin_addr))))
if ((isValidNet(&(it->second.currentlocaladdr.sin_addr))) &&
(sameNet(&(ownState.currentlocaladdr.sin_addr),
&(it->second.currentlocaladdr.sin_addr))))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Local Address Valid: ";
std::cerr << inet_ntoa(it->second.localaddr.sin_addr);
std::cerr << ":" << ntohs(it->second.localaddr.sin_port);
std::cerr << inet_ntoa(it->second.currentlocaladdr.sin_addr);
std::cerr << ":" << ntohs(it->second.currentlocaladdr.sin_port);
std::cerr << std::endl;
#endif
bool localExists = false;
if ((it->second.inConnAttempt) &&
(it->second.currentConnAddr.type == RS_NET_CONN_TCP_LOCAL))
(it->second.currentConnAddrAttempt.type == RS_NET_CONN_TCP_LOCAL))
{
localExists = true;
}
@ -2587,7 +2588,7 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
peerConnectAddress pca;
pca.ts = now;
pca.type = RS_NET_CONN_TCP_LOCAL;
pca.addr = it->second.localaddr;
pca.addr = it->second.currentlocaladdr;
{
/* Log */
@ -2619,19 +2620,19 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
// (it->second.netMode = RS_NET_MODE_EXT))
/* always try external */
if (isValidNet(&(it->second.serveraddr.sin_addr)))
if (isValidNet(&(it->second.currentserveraddr.sin_addr)))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Ext Address Valid: ";
std::cerr << inet_ntoa(it->second.serveraddr.sin_addr);
std::cerr << ":" << ntohs(it->second.serveraddr.sin_port);
std::cerr << inet_ntoa(it->second.currentserveraddr.sin_addr);
std::cerr << ":" << ntohs(it->second.currentserveraddr.sin_port);
std::cerr << std::endl;
#endif
bool remoteExists = false;
if ((it->second.inConnAttempt) &&
(it->second.currentConnAddr.type == RS_NET_CONN_TCP_EXTERNAL))
(it->second.currentConnAddrAttempt.type == RS_NET_CONN_TCP_EXTERNAL))
{
remoteExists = true;
}
@ -2658,7 +2659,7 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
peerConnectAddress pca;
pca.ts = now;
pca.type = RS_NET_CONN_TCP_EXTERNAL;
pca.addr = it->second.serveraddr;
pca.addr = it->second.currentserveraddr;
{
/* Log */
@ -2796,7 +2797,7 @@ bool p3ConnectMgr::setLocalAddress(std::string id, struct sockaddr_in addr)
if (id == mAuthMgr->OwnId())
{
ownState.localaddr = addr;
ownState.currentlocaladdr = addr;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
@ -2817,7 +2818,7 @@ bool p3ConnectMgr::setLocalAddress(std::string id, struct sockaddr_in addr)
}
/* "it" points to peer */
it->second.localaddr = addr;
it->second.currentlocaladdr = addr;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
@ -2830,7 +2831,7 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
if (id == mAuthMgr->OwnId())
{
ownState.serveraddr = addr;
ownState.currentserveraddr = addr;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
@ -2851,7 +2852,7 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
}
/* "it" points to peer */
it->second.serveraddr = addr;
it->second.currentserveraddr = addr;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
@ -2941,17 +2942,17 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
bool p3ConnectMgr::checkNetAddress()
{
in_addr_t old_in_addr = ownState.localaddr.sin_addr.s_addr;
int old_in_port = ownState.localaddr.sin_port;
in_addr_t old_in_addr = ownState.currentlocaladdr.sin_addr.s_addr;
int old_in_port = ownState.currentlocaladdr.sin_port;
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
// GetPreferredInterface now chooses the best local ilterface for you. So it's the default function to use now.
//
ownState.localaddr.sin_addr = getPreferredInterface() ;
ownState.currentlocaladdr.sin_addr = getPreferredInterface() ;
if(ownState.localaddr.sin_addr.s_addr != 0)
if(ownState.currentlocaladdr.sin_addr.s_addr != 0)
{
if (netFlagLocalOk != true)
{
@ -2964,34 +2965,34 @@ bool p3ConnectMgr::checkNetAddress()
}
}
if(isLoopbackNet(&(ownState.localaddr.sin_addr)))
if(isLoopbackNet(&(ownState.currentlocaladdr.sin_addr)))
mNetStatus = RS_NET_LOOPBACK;
int port = ntohs(ownState.localaddr.sin_port);
int port = ntohs(ownState.currentlocaladdr.sin_port);
if ((port < PQI_MIN_PORT) || (port > PQI_MAX_PORT))
ownState.localaddr.sin_port = htons(PQI_DEFAULT_PORT);
ownState.currentlocaladdr.sin_port = htons(PQI_DEFAULT_PORT);
/* if localaddr = serveraddr, then ensure that the ports
* are the same (modify server)... this mismatch can
* occur when the local port is changed....
*/
if (ownState.localaddr.sin_addr.s_addr == ownState.serveraddr.sin_addr.s_addr)
ownState.serveraddr.sin_port = ownState.localaddr.sin_port;
if (ownState.currentlocaladdr.sin_addr.s_addr == ownState.currentserveraddr.sin_addr.s_addr)
ownState.currentserveraddr.sin_port = ownState.currentlocaladdr.sin_port;
// ensure that address family is set, otherwise windows Barfs.
ownState.localaddr.sin_family = AF_INET;
ownState.serveraddr.sin_family = AF_INET;
ownState.currentlocaladdr.sin_family = AF_INET;
ownState.currentserveraddr.sin_family = AF_INET;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::checkNetAddress() Final Local Address: ";
std::cerr << inet_ntoa(ownState.localaddr.sin_addr);
std::cerr << ":" << ntohs(ownState.localaddr.sin_port);
std::cerr << inet_ntoa(ownState.currentlocaladdr.sin_addr);
std::cerr << ":" << ntohs(ownState.currentlocaladdr.sin_port);
std::cerr << std::endl;
#endif
}
if ((old_in_addr != ownState.localaddr.sin_addr.s_addr) || (old_in_port != ownState.localaddr.sin_port))
if ((old_in_addr != ownState.currentlocaladdr.sin_addr.s_addr) || (old_in_port != ownState.currentlocaladdr.sin_port))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::checkNetAddress() local address changed, resetting network." << std::endl;
@ -3143,8 +3144,20 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
item->visState = ownState.visState;
item->lastContact = ownState.lastcontact;
item->localaddr = ownState.localaddr;
item->remoteaddr = ownState.serveraddr;
std::list <IpAddressTimed> tempLocaladdrList;
struct IpAddressTimed locaIp;
locaIp.ipAddr = ownState.currentlocaladdr;
locaIp.seenTime = time(NULL);
tempLocaladdrList.push_back(locaIp);
item->localaddrList = tempLocaladdrList;
std::list <IpAddressTimed> tempRemoteaddrList;
struct IpAddressTimed remoteIp;
remoteIp.ipAddr = ownState.currentserveraddr;
remoteIp.seenTime = time(NULL);
tempRemoteaddrList.push_back(remoteIp);
item->remoteaddrList = tempRemoteaddrList;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::saveList() Own Config Item:";
@ -3166,8 +3179,10 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
item->netMode = (it->second).netMode;
item->visState = (it->second).visState;
item->lastContact = (it->second).lastcontact;
item->localaddr = (it->second).localaddr;
item->remoteaddr = (it->second).serveraddr;
item->currentlocaladdr = (it->second).currentlocaladdr;
item->currentremoteaddr = (it->second).currentserveraddr;
item->localaddrList = (it->second).localaddrList;
item->remoteaddrList = (it->second).remoteaddrList;
saveData.push_back(item);
#ifdef CONN_DEBUG
@ -3239,8 +3254,8 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
#endif
/* add ownConfig */
setOwnNetConfig(pitem->netMode, pitem->visState);
setLocalAddress(pitem->pid, pitem->localaddr);
setExtAddress(pitem->pid, pitem->remoteaddr);
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
setExtAddress(pitem->pid, pitem->currentremoteaddr);
}
else
{
@ -3252,8 +3267,8 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
#endif
/* ************* */
addFriend(pitem->pid, pitem->netMode, pitem->visState, pitem->lastContact);
setLocalAddress(pitem->pid, pitem->localaddr);
setExtAddress(pitem->pid, pitem->remoteaddr);
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
setExtAddress(pitem->pid, pitem->currentremoteaddr);
}
}
else if (sitem)

View File

@ -28,6 +28,7 @@
#include "pqi/pqimonitor.h"
#include "pqi/p3authmgr.h"
#include "serialiser/rsconfigitems.h"
//#include "pqi/p3dhtmgr.h"
//#include "pqi/p3upnpmgr.h"
@ -135,7 +136,13 @@ class peerConnectState
uint32_t netMode; /* EXT / UPNP / UDP / INVALID */
uint32_t visState; /* STD, GRAY, DARK */
struct sockaddr_in localaddr, serveraddr;
//used to store friends ip lists
std::list<IpAddressTimed> localaddrList;
std::list<IpAddressTimed> remoteaddrList;
//used to store current ip (for config and connection management)
struct sockaddr_in currentlocaladdr; /* Mandatory */
struct sockaddr_in currentserveraddr; /* Mandatory */
time_t lastcontact;
@ -157,7 +164,7 @@ class peerConnectState
/* a list of connect attempts to make (in order) */
bool inConnAttempt;
peerConnectAddress currentConnAddr;
peerConnectAddress currentConnAddrAttempt;
std::list<peerConnectAddress> connAddrs;
};

View File

@ -179,7 +179,7 @@ int pqipersongrp::init_listener()
mConnMgr->getOwnNetStatus(state);
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
pqil = createListener(state.localaddr);
pqil = createListener(state.currentlocaladdr);
}
return 1;
}
@ -207,7 +207,7 @@ int pqipersongrp::restart_listener()
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
pqil -> resetlisten();
pqil -> setListenAddr(state.localaddr);
pqil -> setListenAddr(state.currentlocaladdr);
pqil -> setuplisten();
std::cerr << "pqipersongrp::restart_listener() done!" << std::endl;

View File

@ -1264,7 +1264,7 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
peerConnectState details;
mConnMgr->getOwnNetStatus(details);
sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(details.localaddr.sin_addr));
sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(details.currentlocaladdr.sin_addr));
{
std::ostringstream out;
@ -1272,7 +1272,7 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
out << std::endl;
out << "\t\tchecking for same LAN";
out << std::endl;
out << "\t localaddr: " << inet_ntoa(details.localaddr.sin_addr);
out << "\t localaddr: " << inet_ntoa(details.currentlocaladdr.sin_addr);
out << std::endl;
out << "\t remoteaddr: " << inet_ntoa(remote_addr.sin_addr);
out << std::endl;

View File

@ -37,11 +37,13 @@ typedef std::string RsChanId;
typedef std::string RsMsgId;
typedef std::string RsAuthId;
const uint32_t FT_STATE_FAILED = 0x0000;
const uint32_t FT_STATE_OKAY = 0x0001;
const uint32_t FT_STATE_WAITING = 0x0002;
const uint32_t FT_STATE_DOWNLOADING = 0x0003;
const uint32_t FT_STATE_COMPLETE = 0x0004;
#ifndef FT_STATE_FAILED
const uint32_t FT_STATE_FAILED = 0x0000;
const uint32_t FT_STATE_OKAY = 0x0001;
const uint32_t FT_STATE_WAITING = 0x0002;
const uint32_t FT_STATE_DOWNLOADING = 0x0003;
const uint32_t FT_STATE_COMPLETE = 0x0004;
#endif
class TransferInfo
{

View File

@ -108,14 +108,14 @@ int RsServer::UpdateAllConfig()
mConnMgr->getOwnNetStatus(pstate);
/* ports */
config.localAddr = inet_ntoa(pstate.localaddr.sin_addr);
config.localPort = ntohs(pstate.localaddr.sin_port);
config.localAddr = inet_ntoa(pstate.currentlocaladdr.sin_addr);
config.localPort = ntohs(pstate.currentlocaladdr.sin_port);
config.firewalled = true;
config.forwardPort = true;
config.extAddr = inet_ntoa(pstate.serveraddr.sin_addr);
config.extPort = ntohs(pstate.serveraddr.sin_port);
config.extAddr = inet_ntoa(pstate.currentserveraddr.sin_addr);
config.extPort = ntohs(pstate.currentserveraddr.sin_port);
/* data rates */
config.maxDownloadDataRate = (int) pqih -> getMaxRate(true); /* kb */

View File

@ -354,9 +354,10 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
}
}
//TODO : check use of this details
// From all addresses, show the most recent one if no address is currently in use.
struct sockaddr_in best_local_addr = (!strcmp(inet_ntoa(pcs.localaddr.sin_addr),"0.0.0.0"))?getPreferredAddress(pcs.dht.laddr,pcs.dht.ts,pcs.disc.laddr,pcs.disc.ts,pcs.peer.laddr,pcs.peer.ts):pcs.localaddr ;
struct sockaddr_in best_servr_addr = (!strcmp(inet_ntoa(pcs.serveraddr.sin_addr),"0.0.0.0"))?getPreferredAddress(pcs.dht.raddr,pcs.dht.ts,pcs.disc.raddr,pcs.disc.ts,pcs.peer.raddr,pcs.peer.ts):pcs.serveraddr ;
struct sockaddr_in best_local_addr = (!strcmp(inet_ntoa(pcs.currentlocaladdr.sin_addr),"0.0.0.0"))?getPreferredAddress(pcs.dht.laddr,pcs.dht.ts,pcs.disc.laddr,pcs.disc.ts,pcs.peer.laddr,pcs.peer.ts):pcs.currentlocaladdr ;
struct sockaddr_in best_servr_addr = (!strcmp(inet_ntoa(pcs.currentserveraddr.sin_addr),"0.0.0.0"))?getPreferredAddress(pcs.dht.raddr,pcs.dht.ts,pcs.disc.raddr,pcs.disc.ts,pcs.peer.raddr,pcs.peer.ts):pcs.currentserveraddr ;
/* fill from pcs */
@ -430,7 +431,7 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
/*
*/
autostr << "Trying ";
switch(pcs.currentConnAddr.type)
switch(pcs.currentConnAddrAttempt.type)
{
case RS_NET_CONN_TCP_LOCAL:
autostr << "TCP (Local)";
@ -440,7 +441,7 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
break;
case RS_NET_CONN_UDP_DHT_SYNC:
autostr << "UDP (ETA: ";
autostr << 420 - (time(NULL) - pcs.currentConnAddr.ts);
autostr << 420 - (time(NULL) - pcs.currentConnAddrAttempt.ts);
autostr << ")";
break;
default:

View File

@ -718,8 +718,8 @@ void RsPeerNetItem::clear()
visState = 0;
lastContact = 0;
sockaddr_clear(&localaddr);
sockaddr_clear(&remoteaddr);
sockaddr_clear(&currentlocaladdr);
sockaddr_clear(&currentremoteaddr);
}
std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent)
@ -740,12 +740,12 @@ std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent)
out << "lastContact: " << lastContact << std::endl;
printIndent(out, int_Indent);
out << "localaddr: " << inet_ntoa(localaddr.sin_addr);
out << ":" << htons(localaddr.sin_port) << std::endl;
out << "currentlocaladdr: " << inet_ntoa(currentlocaladdr.sin_addr);
out << ":" << htons(currentlocaladdr.sin_port) << std::endl;
printIndent(out, int_Indent);
out << "remoteaddr: " << inet_ntoa(remoteaddr.sin_addr);
out << ":" << htons(remoteaddr.sin_port) << std::endl;
out << "currentremoteaddr: " << inet_ntoa(currentremoteaddr.sin_addr);
out << ":" << htons(currentremoteaddr.sin_port) << std::endl;
printRsItemEnd(out, "RsPeerNetItem", indent);
return out;
@ -796,8 +796,8 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3
ok &= setRawUInt32(data, tlvsize, &offset, item->netMode); /* Mandatory */
ok &= setRawUInt32(data, tlvsize, &offset, item->visState); /* Mandatory */
ok &= setRawUInt32(data, tlvsize, &offset, item->lastContact); /* Mandatory */
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_LOCAL, &(item->localaddr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(item->remoteaddr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_LOCAL, &(item->currentlocaladdr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(item->currentremoteaddr));
if(offset != tlvsize)
{
@ -847,8 +847,8 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size
ok &= getRawUInt32(data, rssize, &offset, &(item->netMode)); /* Mandatory */
ok &= getRawUInt32(data, rssize, &offset, &(item->visState)); /* Mandatory */
ok &= getRawUInt32(data, rssize, &offset, &(item->lastContact)); /* Mandatory */
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_LOCAL, &(item->localaddr));
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_REMOTE, &(item->remoteaddr));
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_LOCAL, &(item->currentlocaladdr));
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_REMOTE, &(item->currentremoteaddr));
if (offset != rssize)
{

View File

@ -50,6 +50,11 @@ const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x02;
/**************************************************************************/
struct IpAddressTimed {
struct sockaddr_in ipAddr;
time_t seenTime;
};
class RsPeerNetItem: public RsItem
{
public:
@ -68,8 +73,11 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
uint32_t visState; /* Mandatory */
uint32_t lastContact; /* Mandatory */
struct sockaddr_in localaddr; /* Mandatory */
struct sockaddr_in remoteaddr; /* Mandatory */
struct sockaddr_in currentlocaladdr; /* Mandatory */
struct sockaddr_in currentremoteaddr; /* Mandatory */
std::list<IpAddressTimed> localaddrList;
std::list<IpAddressTimed> remoteaddrList;
};
class RsPeerStunItem: public RsItem
@ -161,11 +169,13 @@ virtual RsItem * deserialise(void *data, uint32_t *size);
/**************************************************************************/
#define FT_STATE_FAILED 0
#define FT_STATE_OKAY 1
#define FT_STATE_WAITING 2
#define FT_STATE_DOWNLOADING 3
#define FT_STATE_COMPLETE 4
#ifndef FT_STATE_FAILED
#define FT_STATE_FAILED 0
#define FT_STATE_OKAY 1
#define FT_STATE_WAITING 2
#define FT_STATE_DOWNLOADING 3
#define FT_STATE_COMPLETE 4
#endif
class RsFileTransfer: public RsItem
{

View File

@ -306,8 +306,8 @@ RsDiscReply::~RsDiscReply()
void RsDiscReply::clear()
{
memset(&laddr, 0, sizeof(laddr));
memset(&saddr, 0, sizeof(laddr));
memset(&currentladdr, 0, sizeof(currentladdr));
memset(&currentsaddr, 0, sizeof(currentladdr));
contact_tf = 0;
discFlags = 0;
aboutId.clear();
@ -320,12 +320,12 @@ std::ostream &RsDiscReply::print(std::ostream &out, uint16_t indent)
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Local Address: " << inet_ntoa(laddr.sin_addr);
out << " Port: " << ntohs(laddr.sin_port) << std::endl;
out << "Local Address: " << inet_ntoa(currentladdr.sin_addr);
out << " Port: " << ntohs(currentladdr.sin_port) << std::endl;
printIndent(out, int_Indent);
out << "Server Address: " << inet_ntoa(saddr.sin_addr);
out << " Port: " << ntohs(saddr.sin_port) << std::endl;
out << "Server Address: " << inet_ntoa(currentsaddr.sin_addr);
out << " Port: " << ntohs(currentsaddr.sin_port) << std::endl;
printIndent(out, int_Indent);
out << "Contact TimeFrame: " << contact_tf;
@ -380,8 +380,8 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
offset += 8;
/* add mandatory parts first */
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_LOCAL, &(item->laddr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(item->saddr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_LOCAL, &(item->currentladdr));
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(item->currentsaddr));
ok &= setRawUInt16(data, tlvsize, &offset, item->contact_tf);
ok &= setRawUInt32(data, tlvsize, &offset, item->discFlags);
@ -441,9 +441,9 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
/* get mandatory parts first */
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
TLV_TYPE_IPV4_LOCAL, &(item->laddr));
TLV_TYPE_IPV4_LOCAL, &(item->currentladdr));
ok &= GetTlvIpAddrPortV4(data, rssize, &offset,
TLV_TYPE_IPV4_REMOTE, &(item->saddr));
TLV_TYPE_IPV4_REMOTE, &(item->currentsaddr));
ok &= getRawUInt16(data, rssize, &offset, &(item->contact_tf));
ok &= getRawUInt32(data, rssize, &offset, &(item->discFlags));

View File

@ -32,6 +32,7 @@
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rsserviceids.h"
#include "serialiser/rsconfigitems.h"
const uint8_t RS_PKT_SUBTYPE_DISC_OWN = 0x01;
const uint8_t RS_PKT_SUBTYPE_DISC_REPLY = 0x02;
@ -80,8 +81,13 @@ virtual ~RsDiscReply();
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
struct sockaddr_in laddr;
struct sockaddr_in saddr;
//use for transmitting peer adress list
std::list<IpAddressTimed> localaddrList;
std::list<IpAddressTimed> remoteaddrList;
//use for transmitting my own adress list
struct sockaddr_in currentladdr;
struct sockaddr_in currentsaddr;
// time frame of recent connections.
uint16_t contact_tf;

View File

@ -358,8 +358,8 @@ void p3disc::sendOwnDetails(std::string to)
// Fill the message
di -> PeerId(to);
di -> laddr = detail.localaddr;
di -> saddr = detail.serveraddr;
di -> laddr = detail.currentlocaladdr;
di -> saddr = detail.currentserveraddr;
di -> contact_tf = 0;
/* construct disc flags */
@ -431,8 +431,8 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
di -> aboutId = about;
// set the server address.
di -> laddr = detail.localaddr;
di -> saddr = detail.serveraddr;
di -> localaddrList = detail.localaddrList;
di -> remoteaddrList = detail.remoteaddrList;
if (detail.state & RS_PEER_S_CONNECTED)
{
@ -702,13 +702,13 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
/* only valid certs, and not ourselves */
if ((loaded) && (peerId != mConnMgr->getOwnId()))
{
mConnMgr->peerStatus(peerId, item->laddr, item->saddr, type, flags, RS_CB_DISC);
mConnMgr->peerStatus(peerId, item->currentladdr, item->currentsaddr, type, flags, RS_CB_DISC);
std::string hashid1 = RsUtil::HashId(peerId, false);
mConnMgr->stunStatus(hashid1, item->saddr, type, RS_STUN_FRIEND_OF_FRIEND);
mConnMgr->stunStatus(hashid1, item->currentsaddr, type, RS_STUN_FRIEND_OF_FRIEND);
}
addDiscoveryData(item->PeerId(), peerId, item->laddr, item->saddr, item->discFlags, time(NULL));
addDiscoveryData(item->PeerId(), peerId, item->currentladdr, item->currentsaddr, item->discFlags, time(NULL));
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);