mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #2287 from csoler/v0.6-BugFixing_8
Added early check of ExtAddrFinder and notify about its results
This commit is contained in:
commit
d9721746c3
@ -373,12 +373,32 @@ void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContac
|
||||
}
|
||||
|
||||
// Peer Own Info replaces the existing info, because the
|
||||
// peer is the primary source of his own IPs.
|
||||
// peer is the primary source of his own IPs, except for hidden nodes
|
||||
// that normally send nothing. We still ignore it as a double security.
|
||||
|
||||
mPeerMgr->setNetworkMode(fromId, item->netMode);
|
||||
mPeerMgr->setLocation(fromId, item->location);
|
||||
mPeerMgr->setVisState(fromId, item->vs_disc, item->vs_dht);
|
||||
|
||||
if(!mPeerMgr->isHiddenNode(fromId))
|
||||
{
|
||||
if(!det.localAddr.empty())
|
||||
{
|
||||
if(sockaddr_storage_isValidNet(item->localAddrV4.addr))
|
||||
mPeerMgr->setLocalAddress(fromId,item->localAddrV4.addr);
|
||||
else if(sockaddr_storage_isValidNet(item->localAddrV6.addr))
|
||||
mPeerMgr->setLocalAddress(fromId,item->localAddrV6.addr);
|
||||
}
|
||||
|
||||
if(!det.extAddr.empty())
|
||||
{
|
||||
if(sockaddr_storage_isValidNet(item->extAddrV4.addr))
|
||||
mPeerMgr->setExtAddress(fromId,item->extAddrV4.addr);
|
||||
else if(sockaddr_storage_isValidNet(item->extAddrV6.addr))
|
||||
mPeerMgr->setExtAddress(fromId,item->extAddrV6.addr);
|
||||
}
|
||||
}
|
||||
|
||||
setPeerVersion(fromId, item->version);
|
||||
|
||||
// Hidden nodes do not need IP information. So that information is dropped.
|
||||
@ -388,6 +408,15 @@ void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContac
|
||||
if(!mPeerMgr->isHiddenNode(rsPeers->getOwnId()))
|
||||
updatePeerAddresses(item);
|
||||
|
||||
if(rsEvents)
|
||||
{
|
||||
auto ev = std::make_shared<RsGossipDiscoveryEvent>();
|
||||
ev->mGossipDiscoveryEventType = RsGossipDiscoveryEventType::FRIEND_PEER_INFO_RECEIVED;
|
||||
ev->mFromId = fromId;
|
||||
ev->mAboutId = item->sslId;
|
||||
rsEvents->postEvent(ev);
|
||||
}
|
||||
|
||||
// if the peer is not validated, we stop the exchange here
|
||||
|
||||
if(det.skip_pgp_signature_validation)
|
||||
@ -977,7 +1006,18 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
|
||||
|
||||
if(should_notify_discovery)
|
||||
{
|
||||
RsServer::notify()->notifyDiscInfoChanged();
|
||||
|
||||
if(rsEvents)
|
||||
{
|
||||
auto ev = std::make_shared<RsGossipDiscoveryEvent>();
|
||||
ev->mGossipDiscoveryEventType = RsGossipDiscoveryEventType::FRIEND_PEER_INFO_RECEIVED;
|
||||
ev->mFromId = fromId;
|
||||
ev->mAboutId = item->sslId;
|
||||
rsEvents->postEvent(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* we explictly request certificates, instead of getting them all the time
|
||||
|
@ -5368,14 +5368,13 @@ void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req,const unsig
|
||||
#endif
|
||||
uint32_t used_size = clear_group_data_len;
|
||||
RsItem *item = RsNxsSerialiser(mServType).deserialise(clear_group_data,&used_size) ;
|
||||
RsNxsGrp *nxs_identity_grp=nullptr;
|
||||
|
||||
if(used_size < clear_group_data_len)
|
||||
{
|
||||
uint32_t remaining_size = clear_group_data_len-used_size ;
|
||||
RsItem *item2 = RsNxsSerialiser(RS_SERVICE_GXS_TYPE_GXSID).deserialise(clear_group_data+used_size,&remaining_size) ;
|
||||
|
||||
nxs_identity_grp = dynamic_cast<RsNxsGrp*>(item2);
|
||||
auto nxs_identity_grp = dynamic_cast<RsNxsGrp*>(item2);
|
||||
|
||||
if(!nxs_identity_grp)
|
||||
std::cerr << "(EE) decrypted item contains more data that cannot be deserialized as a GxsId. Unexpected!" << std::endl;
|
||||
@ -5383,6 +5382,9 @@ void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req,const unsig
|
||||
// We should probably check that the identity that is sent corresponds to the group author and don't add
|
||||
// it otherwise. But in any case, this won't harm to add a new public identity. If that identity is banned,
|
||||
// the group will be discarded in RsGenExchange anyway.
|
||||
|
||||
if(nxs_identity_grp)
|
||||
mGixs->receiveNewIdentity(nxs_identity_grp);
|
||||
}
|
||||
|
||||
free(clear_group_data);
|
||||
@ -5413,9 +5415,6 @@ void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req,const unsig
|
||||
#endif
|
||||
mObserver->receiveNewGroups(new_grps);
|
||||
mObserver->receiveDistantSearchResults(req, grpId);
|
||||
|
||||
if(nxs_identity_grp)
|
||||
mGixs->receiveNewIdentity(nxs_identity_grp);
|
||||
}
|
||||
|
||||
bool RsGxsNetService::search( const std::string& substring,
|
||||
|
@ -472,6 +472,17 @@ void p3LinkMgrIMPL::tickMonitors()
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
// if(peer.actions & RS_PEER_CONNECTED)
|
||||
// {
|
||||
// pqiIpAddress ip;
|
||||
// ip.mAddr = it->second.currentConnAddrAttempt.addr;
|
||||
// ip.mSeenTime = time(NULL);
|
||||
// ip.mSrc = time(NULL);
|
||||
//
|
||||
// mPeerMgr->updateCurrentAddress(it->second.id,)
|
||||
// std::cerr << "Peer " << it->second.id << " connected with IP " << sockaddr_storage_tostring(it->second.currentConnAddrAttempt.addr) << std::endl;
|
||||
// }
|
||||
|
||||
/* notify GUI */
|
||||
if (rsEvents && (peer.actions & RS_PEER_CONNECTED))
|
||||
{
|
||||
@ -788,6 +799,8 @@ bool p3LinkMgrIMPL::connectResult(const RsPeerId &id, bool success, bool isIncom
|
||||
bool updatePeerAddr = false;
|
||||
bool updateLastContact = false;
|
||||
|
||||
std::cerr << "Connection result with peer " << id << ": " << success << ". Is incoming: " << isIncomingConnection << ", remote addr: " << sockaddr_storage_tostring(remote_peer_address) << std::endl;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
|
@ -379,8 +379,10 @@ void p3NetMgrIMPL::netStartup()
|
||||
break;
|
||||
|
||||
case RS_NET_MODE_TRY_LOOPBACK:
|
||||
#ifdef NETMGR_DEBUG_RESET
|
||||
std::cerr << "p3NetMgrIMPL::netStartup() TRY_LOOPBACK mode";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
mNetMode |= RS_NET_MODE_HIDDEN;
|
||||
mNetStatus = RS_NET_LOOPBACK;
|
||||
break;
|
||||
@ -466,6 +468,28 @@ void p3NetMgrIMPL::netStatusTick()
|
||||
|
||||
}
|
||||
|
||||
if(netStatus <= RS_NET_UPNP_SETUP && mUseExtAddrFinder)
|
||||
{
|
||||
sockaddr_storage tmpip = mLocalAddr; // copies local port and correctly inits the IP family
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "Asking ExtAddrFinder for IP. Initializing port with " << sockaddr_storage_port(tmpip) << std::endl;
|
||||
#endif
|
||||
|
||||
if(mExtAddrFinder->hasValidIP(tmpip) && sockaddr_storage_ipv6_to_ipv4(tmpip) && !sockaddr_storage_same(tmpip,mExtAddr))
|
||||
{
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
|
||||
#endif
|
||||
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() ";
|
||||
std::cerr << "ExtAddr: " << sockaddr_storage_tostring(tmpip);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
setExtAddress(tmpip);
|
||||
}
|
||||
}
|
||||
|
||||
switch(netStatus)
|
||||
{
|
||||
case RS_NET_NEEDS_RESET:
|
||||
@ -518,6 +542,10 @@ void p3NetMgrIMPL::netStatusTick()
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netTick() STATUS: EXT_SETUP" << std::endl;
|
||||
#endif
|
||||
// This could take a lot of time on some systems to get there:
|
||||
// (e.g. 10 mins to get passed upnp on windows), so it would be better to call it right away, so other external address finding
|
||||
// systems still have a chance to run early.
|
||||
|
||||
netExtCheck();
|
||||
break;
|
||||
|
||||
@ -719,7 +747,10 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() checking ExtAddrFinder" << std::endl;
|
||||
#endif
|
||||
sockaddr_storage tmpip = mLocalAddr; // copies local port and correctly inits the IP family
|
||||
|
||||
bool extFinderOk = mExtAddrFinder->hasValidIP(tmpip);
|
||||
|
||||
if (extFinderOk && sockaddr_storage_ipv6_to_ipv4(tmpip))
|
||||
{
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
@ -759,11 +790,10 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
uint8_t isstable; // unused
|
||||
sockaddr_storage tmpaddr;
|
||||
|
||||
if ( mPeerMgr->getExtAddressReportedByFriends(tmpaddr, isstable) &&
|
||||
sockaddr_storage_ipv6_to_ipv4(tmpaddr) )
|
||||
if ( mPeerMgr->getExtAddressReportedByFriends(tmpaddr, isstable) && sockaddr_storage_ipv6_to_ipv4(tmpaddr) )
|
||||
{
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied by friends" << std::endl;
|
||||
#endif
|
||||
sockaddr_storage_setport(tmpaddr, guessNewExtPort());
|
||||
|
||||
@ -1067,21 +1097,23 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||
* that needs special permissions or root access.
|
||||
* This do not impede the user to set a reserved port manually,
|
||||
* which make sense in some cases. */
|
||||
|
||||
std::cerr << __PRETTY_FUNCTION__ << " local port is 0. Ext port is " << port ;
|
||||
|
||||
while (port < 1025)
|
||||
port = static_cast<uint16_t>(RsRandom::random_u32());
|
||||
|
||||
sockaddr_storage_setport(mLocalAddr, htons(port));
|
||||
addrChanged = true;
|
||||
std::cerr << " new ext port is " << port << ": using these for local/ext ports" << std::endl;
|
||||
|
||||
RsWarn() << __PRETTY_FUNCTION__ << " local port was 0, corrected "
|
||||
<<"to: " << port << std::endl;
|
||||
sockaddr_storage_setport(mLocalAddr, port);
|
||||
sockaddr_storage_setport(mExtAddr, port); // this accounts for when the port was updated
|
||||
addrChanged = true;
|
||||
}
|
||||
} // RS_STACK_MUTEX(mNetMtx);
|
||||
|
||||
if (addrChanged)
|
||||
{
|
||||
RsInfo() << __PRETTY_FUNCTION__ << " local address changed, resetting"
|
||||
<<" network." << std::endl;
|
||||
RsInfo() << __PRETTY_FUNCTION__ << " local address changed, resetting network." << std::endl;
|
||||
|
||||
if(rsEvents)
|
||||
{
|
||||
@ -1124,6 +1156,7 @@ bool p3NetMgrIMPL::setLocalAddress(const struct sockaddr_storage &addr)
|
||||
}
|
||||
|
||||
mLocalAddr = addr;
|
||||
mPeerMgr->UpdateOwnAddress(mLocalAddr, mExtAddr);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
@ -1160,6 +1193,7 @@ bool p3NetMgrIMPL::setExtAddress(const struct sockaddr_storage &addr)
|
||||
}
|
||||
|
||||
mExtAddr = addr;
|
||||
mPeerMgr->UpdateOwnAddress(mLocalAddr, mExtAddr);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
@ -1745,17 +1779,17 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
|
||||
{
|
||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
uint32_t netstate = mNetStateBox.getNetStateMode();
|
||||
uint32_t netMode = mNetStateBox.getNetworkMode();
|
||||
uint32_t natType = mNetStateBox.getNatTypeMode();
|
||||
uint32_t natHole = mNetStateBox.getNatHoleMode();
|
||||
uint32_t connect = mNetStateBox.getConnectModes();
|
||||
|
||||
std::string netstatestr = NetStateNetStateString(netstate);
|
||||
std::string connectstr = NetStateConnectModesString(connect);
|
||||
std::string natholestr = NetStateNatHoleString(natHole);
|
||||
std::string nattypestr = NetStateNatTypeString(natType);
|
||||
std::string netmodestr = NetStateNetworkModeString(netMode);
|
||||
auto netstate = mNetStateBox.getNetStateMode();
|
||||
auto netMode = mNetStateBox.getNetworkMode();
|
||||
auto natType = mNetStateBox.getNatTypeMode();
|
||||
auto natHole = mNetStateBox.getNatHoleMode();
|
||||
auto connect = mNetStateBox.getConnectModes();
|
||||
#ifdef SUSPENDED
|
||||
auto netstatestr = NetStateNetStateString(netstate);
|
||||
auto connectstr = NetStateConnectModesString(connect);
|
||||
auto natholestr = NetStateNatHoleString(natHole);
|
||||
auto nattypestr = NetStateNatTypeString(natType);
|
||||
auto netmodestr = NetStateNetworkModeString(netMode);
|
||||
|
||||
std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() NetStateBox Thinking";
|
||||
std::cerr << std::endl;
|
||||
@ -1769,6 +1803,7 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tNatType: " << nattypestr;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
@ -1800,8 +1835,8 @@ void p3NetMgrIMPL::updateNatSetting()
|
||||
|
||||
#ifdef NETMGR_DEBUG_STATEBOX
|
||||
std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() NatType Change!";
|
||||
std::cerr << "\tNatType: " << NetStateNatTypeString(natType);
|
||||
std::cerr << "\tNatHole: " << NetStateNatHoleString(natHole);
|
||||
// std::cerr << "\tNatType: " << NetStateNatTypeString(natType);
|
||||
// std::cerr << "\tNatHole: "k << NetStateNatHoleString(natHole);
|
||||
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -1938,7 +1973,9 @@ void p3NetMgrIMPL::updateNetStateBox_startup()
|
||||
/* ExtAddrFinder */
|
||||
if (mUseExtAddrFinder)
|
||||
{
|
||||
tmpip = mLocalAddr;
|
||||
bool extFinderOk = mExtAddrFinder->hasValidIP(tmpip);
|
||||
|
||||
if (extFinderOk)
|
||||
{
|
||||
sockaddr_storage_setport(tmpip, guessNewExtPort());
|
||||
|
@ -1597,9 +1597,7 @@ bool p3PeerMgrIMPL::setLocalAddress( const RsPeerId &id,
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres " << "info : peer id not found in friend list id: " << id << std::endl;
|
||||
#endif
|
||||
std::cerr << "(EE) p3PeerMgrIMPL::setLocalAddress() cannot add addres " << "info : peer id not found in friend list id: " << id << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1658,9 +1656,7 @@ bool p3PeerMgrIMPL::setExtAddress( const RsPeerId &id,
|
||||
std::map<RsPeerId, peerState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
std::cerr << "p3PeerMgrIMPL::setExtAddress() cannot add addres " << "info : peer id not found in friend list id: " << id << std::endl;
|
||||
#endif
|
||||
std::cerr << "(EE) p3PeerMgrIMPL::setExtAddress() cannot add addres " << "info : peer id not found in friend list id: " << id << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ extern std::shared_ptr<RsGossipDiscovery> rsGossipDiscovery;
|
||||
|
||||
enum class RsGossipDiscoveryEventType: uint32_t {
|
||||
UNKNOWN = 0x00,
|
||||
PEER_INVITE_RECEIVED = 0x01
|
||||
FRIEND_PEER_INFO_RECEIVED = 0x01,
|
||||
};
|
||||
|
||||
struct RsGossipDiscoveryEvent : RsEvent
|
||||
@ -57,7 +57,8 @@ struct RsGossipDiscoveryEvent : RsEvent
|
||||
virtual ~RsGossipDiscoveryEvent() override {}
|
||||
|
||||
RsGossipDiscoveryEventType mGossipDiscoveryEventType;
|
||||
std::string mInvite;
|
||||
RsPeerId mFromId;
|
||||
RsPeerId mAboutId;
|
||||
|
||||
/// @see RsSerializable
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
@ -65,7 +66,8 @@ struct RsGossipDiscoveryEvent : RsEvent
|
||||
{
|
||||
RsEvent::serial_process(j,ctx);
|
||||
RS_SERIAL_PROCESS(mGossipDiscoveryEventType);
|
||||
RS_SERIAL_PROCESS(mInvite);
|
||||
RS_SERIAL_PROCESS(mFromId);
|
||||
RS_SERIAL_PROCESS(mAboutId);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1165,7 +1165,8 @@ enum class RsShortInviteFieldType : uint8_t
|
||||
* trasport layer will be implemented */
|
||||
HIDDEN_LOCATOR = 0x90,
|
||||
DNS_LOCATOR = 0x91,
|
||||
EXT4_LOCATOR = 0x92
|
||||
EXT4_LOCATOR = 0x92, // external IPv4 address
|
||||
LOC4_LOCATOR = 0x93 // local IPv4 address
|
||||
};
|
||||
|
||||
static void addPacketHeader(RsShortInviteFieldType ptag, size_t size, unsigned char *& buf, uint32_t& offset, uint32_t& buf_size)
|
||||
@ -1213,7 +1214,7 @@ bool p3Peers::getShortInvite(std::string& invite, const RsPeerId& _sslId, Retros
|
||||
offset += tDetails.name.size();
|
||||
|
||||
/* If it is a hidden node, always use hidden address and port as locator */
|
||||
sockaddr_storage tExt;
|
||||
|
||||
if(tDetails.isHiddenNode)
|
||||
{
|
||||
addPacketHeader(RsShortInviteFieldType::HIDDEN_LOCATOR,4 + 2 + tDetails.hiddenNodeAddress.size(),buf,offset,buf_size);
|
||||
@ -1243,8 +1244,62 @@ bool p3Peers::getShortInvite(std::string& invite, const RsPeerId& _sslId, Retros
|
||||
offset += 2 + tDetails.dyndns.size();
|
||||
}
|
||||
|
||||
if( !!(invite_flags & RetroshareInviteFlags::CURRENT_IP) && sockaddr_storage_inet_pton(tExt, tDetails.extAddr)
|
||||
&& sockaddr_storage_isValidNet(tExt) && sockaddr_storage_ipv6_to_ipv4(tExt) && tDetails.extPort )
|
||||
if( !!(invite_flags & RetroshareInviteFlags::FULL_IP_HISTORY) && (!tDetails.ipAddressList.empty()))
|
||||
for(auto& s: tDetails.ipAddressList)
|
||||
{
|
||||
const std::string& tLc = s;
|
||||
std::string tLocator = tLc.substr(0, tLc.find_first_of(" ")-1);
|
||||
|
||||
addPacketHeader(RsShortInviteFieldType::LOCATOR, tLocator.size(),buf,offset,buf_size);
|
||||
memcpy(&buf[offset],tLocator.c_str(),tLocator.size());
|
||||
|
||||
offset += tLocator.size();
|
||||
}
|
||||
else if( !!(invite_flags & RetroshareInviteFlags::CURRENT_IP) ) // only add at least the local and external IPs
|
||||
{
|
||||
#ifdef USE_NEW_LOCATOR_SYSTEM
|
||||
// This new locator system as some advantages, but here it also has major drawbacks: (1) it cannot differentiate local and external addresses,
|
||||
// and (2) it's quite larger than the old system, which tends to make certificates more than 1 line long.
|
||||
|
||||
sockaddr_storage tLocal;
|
||||
|
||||
if(sockaddr_storage_inet_pton(tLocal, tDetails.localAddr) && sockaddr_storage_isValidNet(tLocal) && tDetails.localPort )
|
||||
{
|
||||
addPacketHeader(RsShortInviteFieldType::LOCATOR, tDetails.localAddr.size(),buf,offset,buf_size);
|
||||
memcpy(&buf[offset],tDetails.localAddr.c_str(),tDetails.localAddr.size());
|
||||
|
||||
offset += tDetails.localAddr.size();
|
||||
}
|
||||
sockaddr_storage tExt;
|
||||
|
||||
if(sockaddr_storage_inet_pton(tExt, tDetails.extAddr) && sockaddr_storage_isValidNet(tExt) && tDetails.extPort )
|
||||
{
|
||||
addPacketHeader(RsShortInviteFieldType::LOCATOR, tDetails.extAddr.size(),buf,offset,buf_size);
|
||||
memcpy(&buf[offset],tDetails.extAddr.c_str(),tDetails.extAddr.size());
|
||||
|
||||
offset += tDetails.extAddr.size();
|
||||
}
|
||||
#else
|
||||
sockaddr_storage tLocal;
|
||||
if(sockaddr_storage_inet_pton(tLocal, tDetails.localAddr) && sockaddr_storage_isValidNet(tLocal) && sockaddr_storage_ipv6_to_ipv4(tLocal) && tDetails.localPort )
|
||||
{
|
||||
uint32_t t4Addr = reinterpret_cast<sockaddr_in&>(tLocal).sin_addr.s_addr;
|
||||
|
||||
addPacketHeader(RsShortInviteFieldType::LOC4_LOCATOR, 4 + 2,buf,offset,buf_size);
|
||||
|
||||
buf[offset+0] = (uint8_t)((t4Addr >> 24) & 0xff);
|
||||
buf[offset+1] = (uint8_t)((t4Addr >> 16) & 0xff);
|
||||
buf[offset+2] = (uint8_t)((t4Addr >> 8) & 0xff);
|
||||
buf[offset+3] = (uint8_t)((t4Addr ) & 0xff);
|
||||
|
||||
buf[offset+4] = (uint8_t)((tDetails.localPort >> 8) & 0xff);
|
||||
buf[offset+5] = (uint8_t)((tDetails.localPort ) & 0xff);
|
||||
|
||||
offset += 4+2;
|
||||
}
|
||||
|
||||
sockaddr_storage tExt;
|
||||
if(sockaddr_storage_inet_pton(tExt, tDetails.extAddr) && sockaddr_storage_isValidNet(tExt) && sockaddr_storage_ipv6_to_ipv4(tExt) && tDetails.extPort )
|
||||
{
|
||||
uint32_t t4Addr = reinterpret_cast<sockaddr_in&>(tExt).sin_addr.s_addr;
|
||||
|
||||
@ -1260,17 +1315,8 @@ bool p3Peers::getShortInvite(std::string& invite, const RsPeerId& _sslId, Retros
|
||||
|
||||
offset += 4+2;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( !!(invite_flags & RetroshareInviteFlags::FULL_IP_HISTORY) && (!tDetails.ipAddressList.empty()))
|
||||
for(auto& s: tDetails.ipAddressList)
|
||||
{
|
||||
const std::string& tLc = s;
|
||||
std::string tLocator = tLc.substr(0, tLc.find_first_of(" ")-1);
|
||||
|
||||
addPacketHeader(RsShortInviteFieldType::LOCATOR, tLocator.size(),buf,offset,buf_size);
|
||||
memcpy(&buf[offset],tLocator.c_str(),tLocator.size());
|
||||
|
||||
offset += tLocator.size();
|
||||
}
|
||||
|
||||
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(buf,offset) ;
|
||||
@ -1372,6 +1418,17 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
|
||||
case RsShortInviteFieldType::DNS_LOCATOR:
|
||||
details.extPort = (((int)buf[0]) << 8) + buf[1];
|
||||
details.dyndns = std::string((char*)&buf[2],s-2);
|
||||
break;
|
||||
|
||||
case RsShortInviteFieldType::LOC4_LOCATOR:
|
||||
{
|
||||
uint32_t t4Addr = (((uint32_t)buf[0]) << 24)+(((uint32_t)buf[1])<<16)+(((uint32_t)buf[2])<<8) + (uint32_t)buf[3];
|
||||
sockaddr_in tLocalAddr;
|
||||
tLocalAddr.sin_addr.s_addr = t4Addr;
|
||||
|
||||
details.localAddr = rs_inet_ntoa(tLocalAddr.sin_addr);
|
||||
details.localPort = (((uint32_t)buf[4])<<8) + (uint32_t)buf[5];
|
||||
}
|
||||
break;
|
||||
|
||||
case RsShortInviteFieldType::EXT4_LOCATOR:
|
||||
|
@ -2654,90 +2654,9 @@ void p3GxsChannels::receiveDistantSearchResults( TurtleRequestId id, const RsGxs
|
||||
// So we put some data in there and will send an event with all of them at once every 1 sec at most.
|
||||
|
||||
mSearchResultsToNotify[id].insert(grpId);
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
std::cerr << __PRETTY_FUNCTION__ << "(" << id << ", " << grpId << ")" << std::endl;
|
||||
|
||||
{
|
||||
RsGenExchange::receiveDistantSearchResults(id, grpId);
|
||||
RsGxsGroupSearchResults gs;
|
||||
netService()->retrieveDistantGroupSummary(grpId, gs);
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mSearchCallbacksMapMutex);
|
||||
auto cbpt = mSearchCallbacksMap.find(id);
|
||||
if(cbpt != mSearchCallbacksMap.end())
|
||||
{
|
||||
cbpt->second.first(gs);
|
||||
return;
|
||||
}
|
||||
} // end RS_STACK_MUTEX(mSearchCallbacksMapMutex);
|
||||
}
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex);
|
||||
auto cbpt = mDistantChannelsCallbacksMap.find(id);
|
||||
if(cbpt != mDistantChannelsCallbacksMap.end())
|
||||
{
|
||||
std::function<void (const RsGxsChannelGroup&)> callback =
|
||||
cbpt->second.first;
|
||||
RsThread::async([this, callback, grpId]()
|
||||
{
|
||||
std::list<RsGxsGroupId> chanIds({grpId});
|
||||
std::vector<RsGxsChannelGroup> channelsInfo;
|
||||
if(!getChannelsInfo(chanIds, channelsInfo))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error! Received "
|
||||
<< "distant channel result grpId: " << grpId
|
||||
<< " but failed getting channel info"
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
for(const RsGxsChannelGroup& chan : channelsInfo)
|
||||
callback(chan);
|
||||
} );
|
||||
|
||||
return;
|
||||
}
|
||||
} // RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
void p3GxsChannels::cleanTimedOutCallbacks()
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mSearchCallbacksMapMutex);
|
||||
for( auto cbpt = mSearchCallbacksMap.begin();
|
||||
cbpt != mSearchCallbacksMap.end(); )
|
||||
if(cbpt->second.second <= now)
|
||||
{
|
||||
clearDistantSearchResults(cbpt->first);
|
||||
cbpt = mSearchCallbacksMap.erase(cbpt);
|
||||
}
|
||||
else ++cbpt;
|
||||
} // RS_STACK_MUTEX(mSearchCallbacksMapMutex);
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex);
|
||||
for( auto cbpt = mDistantChannelsCallbacksMap.begin();
|
||||
cbpt != mDistantChannelsCallbacksMap.end(); )
|
||||
if(cbpt->second.second <= now)
|
||||
{
|
||||
clearDistantSearchResults(cbpt->first);
|
||||
cbpt = mDistantChannelsCallbacksMap.erase(cbpt);
|
||||
}
|
||||
else ++cbpt;
|
||||
} // RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex)
|
||||
}
|
||||
#endif
|
||||
|
||||
bool p3GxsChannels::exportChannelLink(
|
||||
std::string& link, const RsGxsGroupId& chanId, bool includeGxsData,
|
||||
const std::string& baseUrl, std::string& errMsg )
|
||||
bool p3GxsChannels::exportChannelLink( std::string& link, const RsGxsGroupId& chanId, bool includeGxsData, const std::string& baseUrl, std::string& errMsg )
|
||||
{
|
||||
constexpr auto fname = __PRETTY_FUNCTION__;
|
||||
const auto failure = [&](const std::string& err)
|
||||
@ -2773,8 +2692,7 @@ bool p3GxsChannels::exportChannelLink(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsChannels::importChannelLink(
|
||||
const std::string& link, RsGxsGroupId& chanId, std::string& errMsg )
|
||||
bool p3GxsChannels::importChannelLink( const std::string& link, RsGxsGroupId& chanId, std::string& errMsg )
|
||||
{
|
||||
constexpr auto fname = __PRETTY_FUNCTION__;
|
||||
const auto failure = [&](const std::string& err)
|
||||
@ -2801,18 +2719,12 @@ bool p3GxsChannels::importChannelLink(
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ const std::string RsGxsChannels::DEFAULT_CHANNEL_BASE_URL =
|
||||
"retroshare:///channels";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_NAME_FIELD =
|
||||
"chanName";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_ID_FIELD =
|
||||
"chanId";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_DATA_FIELD =
|
||||
"chanData";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_MSG_TITLE_FIELD =
|
||||
"chanMsgTitle";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_MSG_ID_FIELD =
|
||||
"chanMsgId";
|
||||
/*static*/ const std::string RsGxsChannels::DEFAULT_CHANNEL_BASE_URL = "retroshare:///channels";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_NAME_FIELD = "chanName";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_ID_FIELD = "chanId";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_DATA_FIELD = "chanData";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_MSG_TITLE_FIELD = "chanMsgTitle";
|
||||
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_MSG_ID_FIELD = "chanMsgId";
|
||||
|
||||
RsGxsChannelGroup::~RsGxsChannelGroup() = default;
|
||||
RsGxsChannelPost::~RsGxsChannelPost() = default;
|
||||
|
@ -250,7 +250,7 @@ bool ExtAddrFinder::hasValidIP(struct sockaddr_storage &addr)
|
||||
#ifdef EXTADDRSEARCH_DEBUG
|
||||
std::cerr << "ExtAddrFinder: Has stored ip: responding with this ip." << std::endl ;
|
||||
#endif
|
||||
addr = mAddr;
|
||||
sockaddr_storage_copyip(addr,mAddr); // just copy the IP so we dont erase the port.
|
||||
}
|
||||
}
|
||||
rstime_t delta;
|
||||
|
@ -177,10 +177,11 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par
|
||||
ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
|
||||
ui->filterLineEdit->showFilterIcon();
|
||||
|
||||
mEventHandlerId=0; // forces initialization
|
||||
rsEvents->registerEventsHandler(
|
||||
[this](std::shared_ptr<const RsEvent> e) { handleEvent(e); },
|
||||
mEventHandlerId, RsEventType::PEER_CONNECTION );
|
||||
mEventHandlerId_peer=0; // forces initialization
|
||||
mEventHandlerId_gssp=0; // forces initialization
|
||||
|
||||
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::PEER_CONNECTION );
|
||||
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_gssp, RsEventType::GOSSIP_DISCOVERY );
|
||||
|
||||
mModel = new RsFriendListModel();
|
||||
mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this);
|
||||
@ -269,7 +270,9 @@ void NewFriendList::handleEvent(std::shared_ptr<const RsEvent> /*e*/)
|
||||
|
||||
NewFriendList::~NewFriendList()
|
||||
{
|
||||
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
||||
rsEvents->unregisterEventsHandler(mEventHandlerId_peer);
|
||||
rsEvents->unregisterEventsHandler(mEventHandlerId_gssp);
|
||||
|
||||
delete mModel;
|
||||
delete mProxyModel;
|
||||
delete ui;
|
||||
|
@ -121,7 +121,8 @@ private:
|
||||
|
||||
// Settings for peer list display
|
||||
bool mShowState;
|
||||
RsEventsHandlerId_t mEventHandlerId;
|
||||
RsEventsHandlerId_t mEventHandlerId_peer;
|
||||
RsEventsHandlerId_t mEventHandlerId_gssp;
|
||||
|
||||
std::set<RsNodeGroupId> openGroups;
|
||||
std::set<RsPgpId> openPeers;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>658</width>
|
||||
<height>400</height>
|
||||
<height>419</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -441,17 +441,17 @@
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>RSTextBrowser</class>
|
||||
<extends>QTextBrowser</extends>
|
||||
<header>gui/common/RSTextBrowser.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>HeaderFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/common/HeaderFrame.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>RSTextBrowser</class>
|
||||
<extends>QTextBrowser</extends>
|
||||
<header>gui/common/RSTextBrowser.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AvatarWidget</class>
|
||||
<extends>QLabel</extends>
|
||||
|
@ -551,24 +551,25 @@ void ConnectFriendWizard::initializePage(int id)
|
||||
|
||||
ui->nodeEdit->setText(loc);
|
||||
|
||||
std::string s;
|
||||
QString s;
|
||||
|
||||
if(peerDetails.isHiddenNode)
|
||||
s += peerDetails.hiddenNodeAddress;
|
||||
s += QString::fromStdString(peerDetails.hiddenNodeAddress);
|
||||
else
|
||||
{
|
||||
if(peerDetails.localAddr!="0.0.0.0")// This is not so nice, but because we deal we string there's no way
|
||||
s += peerDetails.localAddr; // to ask about if the ip is null. We really need a proper IP class.
|
||||
s += QString::fromStdString(peerDetails.localAddr)+":"+QString::number(peerDetails.localPort); // to ask about if the ip is null. We really need a proper IP class.
|
||||
|
||||
if(peerDetails.extAddr!="0.0.0.0")
|
||||
{
|
||||
if(!s.empty()) s += " / " ;
|
||||
s += peerDetails.extAddr;
|
||||
if(!s.isNull()) s += " / " ;
|
||||
s += QString::fromStdString(peerDetails.extAddr) + ":"+QString::number(peerDetails.extPort);
|
||||
}
|
||||
|
||||
if(!peerDetails.dyndns.empty())
|
||||
s += "(" + peerDetails.dyndns + ")" ;
|
||||
s += " (" + QString::fromStdString(peerDetails.dyndns) + ")" ;
|
||||
}
|
||||
ui->ipEdit->setText(QString::fromStdString(s));
|
||||
ui->ipEdit->setText(s);
|
||||
ui->signersEdit->setPlainText(ts);
|
||||
|
||||
fillGroups(this, ui->groupComboBox, groupId);
|
||||
|
@ -1295,13 +1295,13 @@ void GxsChannelPostsWidgetWithModel::setSubscribeButtonText(const RsGxsGroupId&
|
||||
ui->subscribeToolButton->setEnabled(true);
|
||||
break;
|
||||
case DistantSearchGroupStatus::CAN_BE_REQUESTED: // means no search ongoing. This is not a distant search
|
||||
ui->subscribeToolButton->setText(tr("Subscribe"));
|
||||
ui->subscribeToolButton->setToolTip(tr("Hit this button to retrieve the data you need to subscribe to this channel") );
|
||||
ui->subscribeToolButton->setText(tr("Channel info missing"));
|
||||
ui->subscribeToolButton->setToolTip(tr("To subscribe, first request the channel information by right-clicking Request Data in the search results.") );
|
||||
ui->subscribeToolButton->setSubscribed(false);
|
||||
ui->subscribeToolButton->setEnabled(false);
|
||||
break;
|
||||
case DistantSearchGroupStatus::ONGOING_REQUEST:
|
||||
ui->subscribeToolButton->setText(tr("Subscribe"));
|
||||
ui->subscribeToolButton->setText(tr("Channel info requested..."));
|
||||
ui->subscribeToolButton->setToolTip("");
|
||||
ui->subscribeToolButton->setSubscribed(true);
|
||||
ui->subscribeToolButton->setEnabled(false);
|
||||
|
Loading…
Reference in New Issue
Block a user