mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 06:44:10 +02:00
Merge branch 'protocol' of https://github.com/highfidelity/hifi into protocol
This commit is contained in:
commit
422bef4e18
5 changed files with 27 additions and 30 deletions
|
@ -18,38 +18,38 @@
|
||||||
|
|
||||||
#include "NetworkPacket.h"
|
#include "NetworkPacket.h"
|
||||||
|
|
||||||
void NetworkPacket::copyContents(const SharedNodePointer& node, const QByteArray& packet) {
|
NetworkPacket::NetworkPacket(const NetworkPacket& other) :
|
||||||
if (packet.size() && packet.size() <= MAX_PACKET_SIZE) {
|
_node(other._node),
|
||||||
|
_nlPacket(other._nlPacket) {
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkPacket::NetworkPacket(const SharedNodePointer& node, const NLPacket& packet) {
|
||||||
|
if (packet.getSizeWitHeader() && packet.getSizeWithHeader() <= MAX_nlPacket_SIZE) {
|
||||||
_node = node;
|
_node = node;
|
||||||
_byteArray = packet;
|
_nlPacket = packet;
|
||||||
} else {
|
} else {
|
||||||
qCDebug(networking, ">>> NetworkPacket::copyContents() unexpected length = %d", packet.size());
|
qCDebug(networking, ">>> NetworkPacket::copyContents() unexpected length = %d", packet.size());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
NetworkPacket::NetworkPacket(const NetworkPacket& packet) {
|
|
||||||
copyContents(packet.getNode(), packet.getByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkPacket::NetworkPacket(const SharedNodePointer& node, const QByteArray& packet) {
|
|
||||||
copyContents(node, packet);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// copy assignment
|
// copy assignment
|
||||||
NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) {
|
NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) {
|
||||||
copyContents(other.getNode(), other.getByteArray());
|
_node = other._node;
|
||||||
|
_nlPacket = other._nlPacket;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAS_MOVE_SEMANTICS
|
#ifdef HAS_MOVE_SEMANTICS
|
||||||
// move, same as copy, but other packet won't be used further
|
// move, same as copy, but other packet won't be used further
|
||||||
NetworkPacket::NetworkPacket(NetworkPacket && packet) {
|
NetworkPacket::NetworkPacket(NetworkPacket&& other) :
|
||||||
copyContents(packet.getNode(), packet.getByteArray());
|
_node(std::move(other._node)),
|
||||||
|
_nlPacket(std::move(other._nlPacket)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// move assignment
|
// move assignment
|
||||||
NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) {
|
NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) {
|
||||||
copyContents(other.getNode(), other.getByteArray());
|
_node = std::move(other._node);
|
||||||
|
_nlPacket = std::move(other._nlPacket);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,20 +24,19 @@ public:
|
||||||
NetworkPacket& operator= (const NetworkPacket& other); // copy assignment
|
NetworkPacket& operator= (const NetworkPacket& other); // copy assignment
|
||||||
|
|
||||||
#ifdef HAS_MOVE_SEMANTICS
|
#ifdef HAS_MOVE_SEMANTICS
|
||||||
NetworkPacket(NetworkPacket&& packet); // move?? // same as copy, but other packet won't be used further
|
NetworkPacket(NetworkPacket&& other); // move?? // same as copy, but other packet won't be used further
|
||||||
NetworkPacket& operator= (NetworkPacket&& other); // move assignment
|
NetworkPacket& operator= (NetworkPacket&& other); // move assignment
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NetworkPacket(const SharedNodePointer& node, const QByteArray& byteArray);
|
NetworkPacket(const SharedNodePointer& node, const NLPacket& nlPacket);
|
||||||
|
|
||||||
const SharedNodePointer& getNode() const { return _node; }
|
const SharedNodePointer& getNode() const { return _node; }
|
||||||
const QByteArray& getByteArray() const { return _byteArray; }
|
const NLPacket& getPacket() const { return _nlPacket; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void copyContents(const SharedNodePointer& node, const QByteArray& byteArray);
|
|
||||||
|
|
||||||
SharedNodePointer _node;
|
SharedNodePointer _node;
|
||||||
QByteArray _byteArray;
|
NLPacket _nlPacket;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_NetworkPacket_h
|
#endif // hifi_NetworkPacket_h
|
||||||
|
|
|
@ -48,13 +48,13 @@ PacketSender::~PacketSender() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNode, const QByteArray& packet) {
|
void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNode, const NLPacket& packet) {
|
||||||
NetworkPacket networkPacket(destinationNode, packet);
|
NetworkPacket networkPacket(destinationNode, packet);
|
||||||
lock();
|
lock();
|
||||||
_packets.push_back(networkPacket);
|
_packets.push_back(networkPacket);
|
||||||
unlock();
|
unlock();
|
||||||
_totalPacketsQueued++;
|
_totalPacketsQueued++;
|
||||||
_totalBytesQueued += packet.size();
|
_totalBytesQueued += packet.getSizeWithHeader();
|
||||||
|
|
||||||
// Make sure to wake our actual processing thread because we now have packets for it to process.
|
// Make sure to wake our actual processing thread because we now have packets for it to process.
|
||||||
_hasPackets.wakeAll();
|
_hasPackets.wakeAll();
|
||||||
|
@ -271,13 +271,13 @@ bool PacketSender::nonThreadedProcess() {
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
// send the packet through the NodeList...
|
// send the packet through the NodeList...
|
||||||
DependencyManager::get<NodeList>()->writeDatagram(temporary.getByteArray(), temporary.getNode());
|
DependencyManager::get<NodeList>()->sendUnreliablePacket(temporary.getPacket(), temporary.getNode());
|
||||||
packetsSentThisCall++;
|
packetsSentThisCall++;
|
||||||
_packetsOverCheckInterval++;
|
_packetsOverCheckInterval++;
|
||||||
_totalPacketsSent++;
|
_totalPacketsSent++;
|
||||||
_totalBytesSent += temporary.getByteArray().size();
|
_totalBytesSent += temporary.getPacket().getSizeWithHeader();
|
||||||
|
|
||||||
emit packetSent(temporary.getByteArray().size());
|
emit packetSent(temporary.getPacket().getSizeWithHeader());
|
||||||
|
|
||||||
_lastSendTime = now;
|
_lastSendTime = now;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
~PacketSender();
|
~PacketSender();
|
||||||
|
|
||||||
/// Add packet to outbound queue.
|
/// Add packet to outbound queue.
|
||||||
void queuePacketForSending(const SharedNodePointer& destinationNode, const QByteArray& packet);
|
void queuePacketForSending(const SharedNodePointer& destinationNode, const NLPacket& packet);
|
||||||
|
|
||||||
void setPacketsPerSecond(int packetsPerSecond);
|
void setPacketsPerSecond(int packetsPerSecond);
|
||||||
int getPacketsPerSecond() const { return _packetsPerSecond; }
|
int getPacketsPerSecond() const { return _packetsPerSecond; }
|
||||||
|
|
|
@ -33,17 +33,15 @@ void JurisdictionListener::nodeKilled(SharedNodePointer node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JurisdictionListener::queueJurisdictionRequest() {
|
bool JurisdictionListener::queueJurisdictionRequest() {
|
||||||
static unsigned char buffer[MAX_PACKET_SIZE];
|
auto packet = NLPacket::create(PacketType::JurisdictionRequest, 0);
|
||||||
unsigned char* bufferOut = &buffer[0];
|
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
|
||||||
int sizeOut = nodeList->populatePacketHeader(reinterpret_cast<char*>(bufferOut), PacketTypeJurisdictionRequest);
|
|
||||||
int nodeCount = 0;
|
int nodeCount = 0;
|
||||||
|
|
||||||
nodeList->eachNode([&](const SharedNodePointer& node) {
|
nodeList->eachNode([&](const SharedNodePointer& node) {
|
||||||
if (node->getType() == getNodeType() && node->getActiveSocket()) {
|
if (node->getType() == getNodeType() && node->getActiveSocket()) {
|
||||||
_packetSender.queuePacketForSending(node, QByteArray(reinterpret_cast<char*>(bufferOut), sizeOut));
|
_packetSender.queuePacketForSending(node, packet);
|
||||||
nodeCount++;
|
nodeCount++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue