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