mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
final code, working on local machine
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1811 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
020bb73665
commit
d2f9f1c4f1
@ -126,7 +126,7 @@ void addPeer(std::string id)
|
||||
}
|
||||
|
||||
virtual void peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr, std::list<IpAddressTimed> ipAddressList,
|
||||
uint32_t type, uint32_t mode, uint32_t source)
|
||||
{
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ void addPeer(std::string id)
|
||||
}
|
||||
|
||||
virtual void peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr, std::list<IpAddressTimed> ipAddressList,
|
||||
uint32_t type, uint32_t mode, uint32_t source)
|
||||
{
|
||||
|
||||
|
@ -1528,12 +1528,12 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
|
||||
it->second.connAddrs.pop_front();
|
||||
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
addr = it->second.currentConnAddrAttempt.addr;
|
||||
delay = it->second.currentConnAddrAttempt.delay;
|
||||
period = it->second.currentConnAddrAttempt.period;
|
||||
type = it->second.currentConnAddrAttempt.type;
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectAttempt() Success: ";
|
||||
std::cerr << " id: " << id;
|
||||
std::cerr << std::endl;
|
||||
@ -1668,7 +1668,7 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
||||
|
||||
|
||||
void p3ConnectMgr::peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr, std::list<IpAddressTimed> ipDiscAddressList,
|
||||
uint32_t type, uint32_t flags, uint32_t source)
|
||||
{
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
@ -1698,6 +1698,7 @@ void p3ConnectMgr::peerStatus(std::string id,
|
||||
std::cerr << " flags: " << flags;
|
||||
std::cerr << " source: " << source;
|
||||
std::cerr << std::endl;
|
||||
peerConnectState::printIpAddressList(ipDiscAddressList);
|
||||
#endif
|
||||
{
|
||||
/* Log */
|
||||
@ -1772,6 +1773,10 @@ void p3ConnectMgr::peerStatus(std::string id,
|
||||
it->second.source = RS_CB_DISC;
|
||||
it->second.disc = details;
|
||||
|
||||
it->second.currentlocaladdr = laddr;
|
||||
it->second.currentserveraddr = raddr;
|
||||
it->second.updateIpAddressList(ipDiscAddressList);
|
||||
|
||||
if (flags & RS_NET_FLAGS_ONLINE)
|
||||
{
|
||||
it->second.actions |= RS_PEER_ONLINE;
|
||||
@ -1796,6 +1801,7 @@ void p3ConnectMgr::peerStatus(std::string id,
|
||||
|
||||
it->second.currentlocaladdr = laddr;
|
||||
it->second.currentserveraddr = raddr;
|
||||
it->second.updateIpAddressList(ipDiscAddressList);
|
||||
|
||||
it->second.state |= RS_PEER_S_ONLINE;
|
||||
it->second.lastavailable = now;
|
||||
@ -3771,6 +3777,11 @@ void peerConnectState::updateIpAddressList(std::list<IpAddressTimed> ipTimedList
|
||||
}
|
||||
|
||||
void peerConnectState::updateIpAddressList(IpAddressTimed ipTimed) { //purge old addresses to keep a small list
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "peerConnectState::updateIpAdressList() ip " << inet_ntoa(ipTimed.ipAddr.sin_addr);
|
||||
std::cerr << ":" << ntohs(ipTimed.ipAddr.sin_port);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if (ipTimed.ipAddr.sin_addr.s_addr == 0) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "peerConnectState::updateIpAdressList() ip parameter is 0.0.0.0, do nothing." << std::endl;
|
||||
@ -3781,24 +3792,25 @@ void peerConnectState::updateIpAddressList(IpAddressTimed ipTimed) { //purge old
|
||||
//check if the ip list contains the current remote address of the connected peer
|
||||
bool found = false;
|
||||
std::list<IpAddressTimed>::iterator ipListIt;
|
||||
for (ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()); ipListIt++) {
|
||||
if (ipListIt->ipAddr.sin_addr.s_addr == ipTimed.ipAddr.sin_addr.s_addr && ipListIt->ipAddr.sin_port == ipTimed.ipAddr.sin_port) {
|
||||
for (ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()) && !found; ipListIt++) {
|
||||
if (is_same_address(*ipListIt, ipTimed)) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "peerConnectState::updateIpAdressList() ip found in the list. Update seen time for : ";
|
||||
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr);
|
||||
std::cerr << ":" << ntohs(ipListIt->ipAddr.sin_port);
|
||||
std::cerr << "peerConnectState::updateIpAdressList() ip found in the list.";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
found = true;
|
||||
//update the seen time
|
||||
if (ipListIt->seenTime < ipTimed.seenTime) {
|
||||
ipListIt->seenTime = ipTimed.seenTime;
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "peerConnectState::updateIpAdressList() Update seen time to : " << ipTimed.seenTime << std::endl;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found && (ipTimed.ipAddr.sin_addr.s_addr != 0)) {
|
||||
if (!found) {
|
||||
//add the current addresses to the ip list
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "peerConnectState::updateIpAdressList() adding to the ip list the current remote addr : " << id << " address : ";
|
||||
@ -3811,7 +3823,7 @@ void peerConnectState::updateIpAddressList(IpAddressTimed ipTimed) { //purge old
|
||||
|
||||
}
|
||||
|
||||
void peerConnectState::printIpAddressList() { //purge old addresses to keep a small list
|
||||
void peerConnectState::printIpAddressList() {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "peerConnectState::printIpAdressList() current ip list for the peer : " << id;
|
||||
std::cerr << ", size : " << ipAddressList.size();
|
||||
@ -3826,3 +3838,17 @@ void peerConnectState::printIpAddressList() { //purge old addresses to keep a sm
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void peerConnectState::printIpAddressList(std::list<IpAddressTimed> ipTimedList) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "peerConnectState::printIpAdressList()" << std::endl;
|
||||
#endif
|
||||
for (std::list<IpAddressTimed>::iterator ipListIt = ipTimedList.begin(); ipListIt!=(ipTimedList.end()); ipListIt++) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr);
|
||||
std::cerr << ":" << ntohs(ipListIt->ipAddr.sin_port);
|
||||
std::cerr << " seenTime : " << ipListIt->seenTime << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -149,6 +149,7 @@ class peerConnectState
|
||||
static bool compare_seen_time (IpAddressTimed first, IpAddressTimed second);
|
||||
static bool is_same_address (IpAddressTimed first, IpAddressTimed second);
|
||||
void printIpAddressList();
|
||||
static void printIpAddressList(std::list<IpAddressTimed> ipTimedList);
|
||||
|
||||
//used to store current ip (for config and connection management)
|
||||
struct sockaddr_in currentlocaladdr; /* Mandatory */
|
||||
@ -255,7 +256,7 @@ void removeMonitor(pqiMonitor *mon);
|
||||
|
||||
/******* overloaded from pqiConnectCb *************/
|
||||
virtual void peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr, std::list<IpAddressTimed> ipAddressList,
|
||||
uint32_t type, uint32_t flags, uint32_t source);
|
||||
virtual void peerConnectRequest(std::string id,
|
||||
struct sockaddr_in raddr, uint32_t source);
|
||||
|
@ -1756,7 +1756,8 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash,
|
||||
|
||||
if (doCb)
|
||||
{
|
||||
mConnCb->peerStatus(ent.id, ent.laddr, ent.raddr,
|
||||
std::list<IpAddressTimed> ipAddressList;
|
||||
mConnCb->peerStatus(ent.id, ent.laddr, ent.raddr, ipAddressList,
|
||||
ent.type, 0, RS_CB_DHT);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ pqiConnectCbDummy::~pqiConnectCbDummy()
|
||||
}
|
||||
|
||||
void pqiConnectCbDummy::peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr, std::list<IpAddressTimed> ipAddressList,
|
||||
uint32_t type, uint32_t mode, uint32_t source)
|
||||
{
|
||||
std::cerr << "pqiConnectCbDummy::peerStatus()";
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
|
||||
/************** Define Type/Mode/Source ***************/
|
||||
|
||||
@ -108,7 +109,7 @@ class pqiConnectCb
|
||||
public:
|
||||
virtual ~pqiConnectCb() { return; }
|
||||
virtual void peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr, std::list<IpAddressTimed> ipAddressList,
|
||||
uint32_t type, uint32_t flags, uint32_t source) = 0;
|
||||
|
||||
virtual void peerConnectRequest(std::string id,
|
||||
@ -125,7 +126,7 @@ class pqiConnectCbDummy: public pqiConnectCb
|
||||
pqiConnectCbDummy();
|
||||
virtual ~pqiConnectCbDummy();
|
||||
virtual void peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr, std::list<IpAddressTimed> ipAddressList,
|
||||
uint32_t type, uint32_t mode, uint32_t source);
|
||||
|
||||
virtual void peerConnectRequest(std::string id,
|
||||
|
@ -181,6 +181,11 @@ uint32_t RsDiscSerialiser::sizeItem(RsDiscOwnItem *item)
|
||||
s += 2; /* contact_tf */
|
||||
s += 4; /* discFlags */
|
||||
|
||||
//add the size of the ip list
|
||||
int ipListSize = item->ipAddressList.size();
|
||||
s += ipListSize * GetTlvIpAddrPortV4Size();
|
||||
s += ipListSize * 8; //size of an uint64
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -215,6 +220,13 @@ bool RsDiscSerialiser::serialiseItem(RsDiscOwnItem *item, void *data, uint32
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, item->contact_tf);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->discFlags);
|
||||
|
||||
//store the ip list
|
||||
std::list<IpAddressTimed>::iterator ipListIt;
|
||||
for (ipListIt = item->ipAddressList.begin(); ipListIt!=(item->ipAddressList.end()); ipListIt++) {
|
||||
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(ipListIt->ipAddr));
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, ipListIt->seenTime);
|
||||
}
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
@ -273,6 +285,18 @@ RsDiscOwnItem *RsDiscSerialiser::deserialiseOwnItem(void *data, uint32_t *pktsiz
|
||||
ok &= getRawUInt16(data, rssize, &offset, &(item->contact_tf));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->discFlags));
|
||||
|
||||
//get the ip adress list
|
||||
std::list<IpAddressTimed> ipTimedList;
|
||||
while (offset < rssize) {
|
||||
IpAddressTimed ipTimed;
|
||||
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_REMOTE, &ipTimed.ipAddr);
|
||||
uint64_t time;
|
||||
ok &= getRawUInt64(data, rssize, &offset, &time);
|
||||
ipTimed.seenTime = time;
|
||||
ipTimedList.push_back(ipTimed);
|
||||
}
|
||||
item->ipAddressList = ipTimedList;
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
@ -353,6 +377,11 @@ uint32_t RsDiscSerialiser::sizeReply(RsDiscReply *item)
|
||||
s += GetTlvStringSize(item->aboutId);
|
||||
s += item->certDER.TlvSize();
|
||||
|
||||
//add the size of the ip list
|
||||
int ipListSize = item->ipAddressList.size();
|
||||
s += ipListSize * GetTlvIpAddrPortV4Size();
|
||||
s += ipListSize * 8; //size of an uint64
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -389,6 +418,14 @@ bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_
|
||||
|
||||
ok &= item->certDER.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
|
||||
//store the ip list
|
||||
std::list<IpAddressTimed>::iterator ipListIt;
|
||||
for (ipListIt = item->ipAddressList.begin(); ipListIt!=(item->ipAddressList.end()); ipListIt++) {
|
||||
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(ipListIt->ipAddr));
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, ipListIt->seenTime);
|
||||
}
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
@ -451,6 +488,17 @@ RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize)
|
||||
TLV_TYPE_STR_PEERID, item->aboutId);
|
||||
ok &= item->certDER.GetTlv(data, rssize, &offset);
|
||||
|
||||
//get the ip adress list
|
||||
std::list<IpAddressTimed> ipTimedList;
|
||||
while (offset < rssize) {
|
||||
IpAddressTimed ipTimed;
|
||||
ok &= GetTlvIpAddrPortV4(data, rssize, &offset, TLV_TYPE_IPV4_REMOTE, &ipTimed.ipAddr);
|
||||
uint64_t time;
|
||||
ok &= getRawUInt64(data, rssize, &offset, &time);
|
||||
ipTimed.seenTime = time;
|
||||
ipTimedList.push_back(ipTimed);
|
||||
}
|
||||
item->ipAddressList = ipTimedList;
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
@ -58,6 +58,10 @@ class RsDiscOwnItem: public RsDiscItem
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
//use for transmitting ip address list
|
||||
std::list<IpAddressTimed> ipAddressList;
|
||||
|
||||
//use for transmitting my own adress list
|
||||
struct sockaddr_in laddr;
|
||||
struct sockaddr_in saddr;
|
||||
|
||||
@ -81,7 +85,7 @@ virtual ~RsDiscReply();
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
//use for transmitting peer adress list
|
||||
//use for transmitting ip address list
|
||||
std::list<IpAddressTimed> ipAddressList;
|
||||
|
||||
//use for transmitting my own adress list
|
||||
|
@ -360,6 +360,7 @@ void p3disc::sendOwnDetails(std::string to)
|
||||
di -> PeerId(to);
|
||||
di -> laddr = detail.currentlocaladdr;
|
||||
di -> saddr = detail.currentserveraddr;
|
||||
di -> ipAddressList = detail.getIpAddressList();
|
||||
di -> contact_tf = 0;
|
||||
|
||||
/* construct disc flags */
|
||||
@ -630,7 +631,7 @@ void p3disc::recvPeerOwnMsg(RsDiscOwnItem *item)
|
||||
flags |= RS_NET_FLAGS_STABLE_UDP;
|
||||
}
|
||||
|
||||
mConnMgr->peerStatus(item->PeerId(), item->laddr, item->saddr,
|
||||
mConnMgr->peerStatus(item->PeerId(), item->laddr, item->saddr, item->ipAddressList,
|
||||
type, flags, RS_CB_PERSON);
|
||||
|
||||
/* also add as potential stun buddy */
|
||||
@ -703,7 +704,7 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
|
||||
/* only valid certs, and not ourselves */
|
||||
if ((loaded) && (peerId != mConnMgr->getOwnId()))
|
||||
{
|
||||
mConnMgr->peerStatus(peerId, item->currentladdr, item->currentsaddr, type, flags, RS_CB_DISC);
|
||||
mConnMgr->peerStatus(peerId, item->currentladdr, item->currentsaddr, item->ipAddressList, type, flags, RS_CB_DISC);
|
||||
|
||||
std::string hashid1 = RsUtil::HashId(peerId, false);
|
||||
mConnMgr->stunStatus(hashid1, item->currentsaddr, type, RS_STUN_FRIEND_OF_FRIEND);
|
||||
|
Loading…
Reference in New Issue
Block a user