mirror of
https://github.com/overte-org/overte.git
synced 2025-07-15 17:16:38 +02:00
Merge pull request #6406 from birarda/peer-active-signal
add socketActivated signal to NetworkPeer for punch success
This commit is contained in:
commit
4ef04f4080
3 changed files with 52 additions and 28 deletions
|
@ -299,14 +299,17 @@ qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiS
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode) {
|
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode) {
|
||||||
Q_ASSERT(!packet->isPartOfMessage());
|
Q_ASSERT(!packet->isPartOfMessage());
|
||||||
if (!destinationNode.getActiveSocket()) {
|
auto activeSocket = destinationNode.getActiveSocket();
|
||||||
|
|
||||||
|
if (activeSocket) {
|
||||||
|
emit dataSent(destinationNode.getType(), packet->getDataSize());
|
||||||
|
destinationNode.recordBytesSent(packet->getDataSize());
|
||||||
|
|
||||||
|
return sendPacket(std::move(packet), *activeSocket, destinationNode.getConnectionSecret());
|
||||||
|
} else {
|
||||||
|
qDebug() << "LimitedNodeList::sendPacket called without active socket for node" << destinationNode << "- not sending";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataSent(destinationNode.getType(), packet->getDataSize());
|
|
||||||
destinationNode.recordBytesSent(packet->getDataSize());
|
|
||||||
|
|
||||||
return sendPacket(std::move(packet), *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr,
|
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr,
|
||||||
|
@ -327,21 +330,25 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const HifiS
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) {
|
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) {
|
||||||
auto activeSocket = destinationNode.getActiveSocket();
|
auto activeSocket = destinationNode.getActiveSocket();
|
||||||
if (!activeSocket) {
|
|
||||||
|
if (activeSocket) {
|
||||||
|
qint64 bytesSent = 0;
|
||||||
|
auto connectionSecret = destinationNode.getConnectionSecret();
|
||||||
|
|
||||||
|
// close the last packet in the list
|
||||||
|
packetList.closeCurrentPacket();
|
||||||
|
|
||||||
|
while (!packetList._packets.empty()) {
|
||||||
|
bytesSent += sendPacket(packetList.takeFront<NLPacket>(), *activeSocket, connectionSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit dataSent(destinationNode.getType(), bytesSent);
|
||||||
|
return bytesSent;
|
||||||
|
} else {
|
||||||
|
qDebug() << "LimitedNodeList::sendPacketList called without active socket for node" << destinationNode
|
||||||
|
<< " - not sending.";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
qint64 bytesSent = 0;
|
|
||||||
auto connectionSecret = destinationNode.getConnectionSecret();
|
|
||||||
|
|
||||||
// close the last packet in the list
|
|
||||||
packetList.closeCurrentPacket();
|
|
||||||
|
|
||||||
while (!packetList._packets.empty()) {
|
|
||||||
bytesSent += sendPacket(packetList.takeFront<NLPacket>(), *activeSocket, connectionSecret);
|
|
||||||
}
|
|
||||||
|
|
||||||
emit dataSent(destinationNode.getType(), bytesSent);
|
|
||||||
return bytesSent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr,
|
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr,
|
||||||
|
@ -372,23 +379,35 @@ qint64 LimitedNodeList::sendPacketList(std::unique_ptr<NLPacketList> packetList,
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacketList(std::unique_ptr<NLPacketList> packetList, const Node& destinationNode) {
|
qint64 LimitedNodeList::sendPacketList(std::unique_ptr<NLPacketList> packetList, const Node& destinationNode) {
|
||||||
// close the last packet in the list
|
auto activeSocket = destinationNode.getActiveSocket();
|
||||||
packetList->closeCurrentPacket();
|
if (activeSocket) {
|
||||||
|
// close the last packet in the list
|
||||||
for (std::unique_ptr<udt::Packet>& packet : packetList->_packets) {
|
packetList->closeCurrentPacket();
|
||||||
NLPacket* nlPacket = static_cast<NLPacket*>(packet.get());
|
|
||||||
collectPacketStats(*nlPacket);
|
for (std::unique_ptr<udt::Packet>& packet : packetList->_packets) {
|
||||||
fillPacketHeader(*nlPacket, destinationNode.getConnectionSecret());
|
NLPacket* nlPacket = static_cast<NLPacket*>(packet.get());
|
||||||
|
collectPacketStats(*nlPacket);
|
||||||
|
fillPacketHeader(*nlPacket, destinationNode.getConnectionSecret());
|
||||||
|
}
|
||||||
|
|
||||||
|
return _nodeSocket.writePacketList(std::move(packetList), *activeSocket);
|
||||||
|
} else {
|
||||||
|
qCDebug(networking) << "LimitedNodeList::sendPacketList called without active socket for node. Not sending.";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _nodeSocket.writePacketList(std::move(packetList), *destinationNode.getActiveSocket());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode,
|
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode,
|
||||||
const HifiSockAddr& overridenSockAddr) {
|
const HifiSockAddr& overridenSockAddr) {
|
||||||
|
if (overridenSockAddr.isNull() && !destinationNode.getActiveSocket()) {
|
||||||
|
qCDebug(networking) << "LimitedNodeList::sendPacket called without active socket for node. Not sending.";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// use the node's active socket as the destination socket if there is no overriden socket address
|
// use the node's active socket as the destination socket if there is no overriden socket address
|
||||||
auto& destinationSockAddr = (overridenSockAddr.isNull()) ? *destinationNode.getActiveSocket()
|
auto& destinationSockAddr = (overridenSockAddr.isNull()) ? *destinationNode.getActiveSocket()
|
||||||
: overridenSockAddr;
|
: overridenSockAddr;
|
||||||
|
|
||||||
return sendPacket(std::move(packet), destinationSockAddr, destinationNode.getConnectionSecret());
|
return sendPacket(std::move(packet), destinationSockAddr, destinationNode.getConnectionSecret());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,10 @@ void NetworkPeer::setActiveSocket(HifiSockAddr* discoveredSocket) {
|
||||||
|
|
||||||
// we're now considered connected to this peer - reset the number of connection attemps
|
// we're now considered connected to this peer - reset the number of connection attemps
|
||||||
resetConnectionAttempts();
|
resetConnectionAttempts();
|
||||||
|
|
||||||
|
if (_activeSocket) {
|
||||||
|
emit socketActivated(*_activeSocket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkPeer::activateLocalSocket() {
|
void NetworkPeer::activateLocalSocket() {
|
||||||
|
|
|
@ -83,6 +83,7 @@ public slots:
|
||||||
void stopPingTimer();
|
void stopPingTimer();
|
||||||
signals:
|
signals:
|
||||||
void pingTimerTimeout();
|
void pingTimerTimeout();
|
||||||
|
void socketActivated(const HifiSockAddr& sockAddr);
|
||||||
protected:
|
protected:
|
||||||
void setActiveSocket(HifiSockAddr* discoveredSocket);
|
void setActiveSocket(HifiSockAddr* discoveredSocket);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue