mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:40:11 +02:00
Merge branch 'atp' of https://github.com/birarda/hifi into protocol
This commit is contained in:
commit
a7fa0a733b
12 changed files with 39 additions and 31 deletions
|
@ -218,7 +218,7 @@ void OctreeQueryNode::writeToPacket(const unsigned char* buffer, unsigned int by
|
||||||
OCTREE_PACKET_INTERNAL_SECTION_SIZE sectionSize = bytes;
|
OCTREE_PACKET_INTERNAL_SECTION_SIZE sectionSize = bytes;
|
||||||
_octreePacket->writePrimitive(sectionSize);
|
_octreePacket->writePrimitive(sectionSize);
|
||||||
}
|
}
|
||||||
if (bytes <= _octreePacket->bytesAvailable()) {
|
if (bytes <= _octreePacket->bytesAvailableForWrite()) {
|
||||||
_octreePacket->write(reinterpret_cast<const char*>(buffer), bytes);
|
_octreePacket->write(reinterpret_cast<const char*>(buffer), bytes);
|
||||||
_octreePacketWaiting = true;
|
_octreePacketWaiting = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
bool packetIsDuplicate() const;
|
bool packetIsDuplicate() const;
|
||||||
bool shouldSuppressDuplicatePacket();
|
bool shouldSuppressDuplicatePacket();
|
||||||
|
|
||||||
unsigned int getAvailable() const { return _octreePacket->bytesAvailable(); }
|
unsigned int getAvailable() const { return _octreePacket->bytesAvailableForWrite(); }
|
||||||
int getMaxSearchLevel() const { return _maxSearchLevel; }
|
int getMaxSearchLevel() const { return _maxSearchLevel; }
|
||||||
void resetMaxSearchLevel() { _maxSearchLevel = 1; }
|
void resetMaxSearchLevel() { _maxSearchLevel = 1; }
|
||||||
void incrementMaxSearchLevel() { _maxSearchLevel++; }
|
void incrementMaxSearchLevel() { _maxSearchLevel++; }
|
||||||
|
|
|
@ -147,7 +147,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
|
||||||
NLPacket& statsPacket = nodeData->stats.getStatsMessage();
|
NLPacket& statsPacket = nodeData->stats.getStatsMessage();
|
||||||
|
|
||||||
// If the size of the stats message and the octree message will fit in a packet, then piggyback them
|
// If the size of the stats message and the octree message will fit in a packet, then piggyback them
|
||||||
if (nodeData->getPacket().getSizeWithHeader() <= statsPacket.bytesAvailable()) {
|
if (nodeData->getPacket().getSizeWithHeader() <= statsPacket.bytesAvailableForWrite()) {
|
||||||
|
|
||||||
// copy octree message to back of stats message
|
// copy octree message to back of stats message
|
||||||
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getSizeWithHeader());
|
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getSizeWithHeader());
|
||||||
|
|
|
@ -971,10 +971,10 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif
|
||||||
// setup the extended header for the domain list packets
|
// setup the extended header for the domain list packets
|
||||||
// this data is at the beginning of each of the domain list packets
|
// this data is at the beginning of each of the domain list packets
|
||||||
QByteArray extendedHeader(NUM_DOMAIN_LIST_EXTENDED_HEADER_BYTES, 0);
|
QByteArray extendedHeader(NUM_DOMAIN_LIST_EXTENDED_HEADER_BYTES, 0);
|
||||||
QDataStream extendedHeaderStream(&extendedHeader, QIODevice::Append);
|
QDataStream extendedHeaderStream(&extendedHeader, QIODevice::WriteOnly);
|
||||||
|
|
||||||
extendedHeaderStream << limitedNodeList->getSessionUUID().toRfc4122();
|
extendedHeaderStream << limitedNodeList->getSessionUUID();
|
||||||
extendedHeaderStream << node->getUUID().toRfc4122();
|
extendedHeaderStream << node->getUUID();
|
||||||
extendedHeaderStream << (quint8) node->getCanAdjustLocks();
|
extendedHeaderStream << (quint8) node->getCanAdjustLocks();
|
||||||
extendedHeaderStream << (quint8) node->getCanRez();
|
extendedHeaderStream << (quint8) node->getCanRez();
|
||||||
|
|
||||||
|
@ -1007,6 +1007,9 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send an empty list to the node, in case there were no other nodes
|
||||||
|
domainListPackets.closeCurrentPacket(true);
|
||||||
|
|
||||||
// write the PacketList to this node
|
// write the PacketList to this node
|
||||||
limitedNodeList->sendPacketList(domainListPackets, *node);
|
limitedNodeList->sendPacketList(domainListPackets, *node);
|
||||||
|
|
|
@ -796,7 +796,7 @@ std::unique_ptr<NLPacket> EntityTree::encodeEntitiesDeletedSince(OCTREE_PACKET_S
|
||||||
++numberOfIDs;
|
++numberOfIDs;
|
||||||
|
|
||||||
// check to make sure we have room for one more ID
|
// check to make sure we have room for one more ID
|
||||||
if (NUM_BYTES_RFC4122_UUID > deletesPacket->bytesAvailable()) {
|
if (NUM_BYTES_RFC4122_UUID > deletesPacket->bytesAvailableForWrite()) {
|
||||||
hasFilledPacket = true;
|
hasFilledPacket = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,15 +263,20 @@ 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) {
|
||||||
if (!destinationNode.getActiveSocket()) {
|
const HifiSockAddr* activeSocket = destinationNode.getActiveSocket();
|
||||||
|
if (!activeSocket) {
|
||||||
// we don't have a socket to send to, return 0
|
// we don't have a socket to send to, return 0
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return sendPacketList(packetList, *destinationNode.getActiveSocket());
|
return sendPacketList(packetList, *activeSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) {
|
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) {
|
||||||
qint64 bytesSent{ 0 };
|
qint64 bytesSent { 0 };
|
||||||
|
|
||||||
|
// close the last packet in the list
|
||||||
|
packetList.closeCurrentPacket();
|
||||||
|
|
||||||
while (!packetList._packets.empty()) {
|
while (!packetList._packets.empty()) {
|
||||||
bytesSent += sendPacket(std::move(packetList.takeFront<NLPacket>()), sockAddr);
|
bytesSent += sendPacket(std::move(packetList.takeFront<NLPacket>()), sockAddr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,7 +284,7 @@ void NodeList::sendDomainServerCheckIn() {
|
||||||
|
|
||||||
flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendDSCheckIn);
|
flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendDSCheckIn);
|
||||||
|
|
||||||
if (!isUsingDTLS) {
|
if (!isUsingDTLS) {
|
||||||
sendPacket(std::move(domainPacket), _domainHandler.getSockAddr());
|
sendPacket(std::move(domainPacket), _domainHandler.getSockAddr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ void NodeList::sendDSPathQuery(const QString& newPath) {
|
||||||
// get the size of the UTF8 representation of the desired path
|
// get the size of the UTF8 representation of the desired path
|
||||||
qint64 numPathBytes = pathQueryUTF8.size();
|
qint64 numPathBytes = pathQueryUTF8.size();
|
||||||
|
|
||||||
if (numPathBytes + ((qint64) sizeof(numPathBytes)) < pathQueryPacket->bytesAvailable()) {
|
if (numPathBytes + ((qint64) sizeof(numPathBytes)) < pathQueryPacket->bytesAvailableForWrite()) {
|
||||||
// append the size of the path to the query packet
|
// append the size of the path to the query packet
|
||||||
pathQueryPacket->writePrimitive(numPathBytes);
|
pathQueryPacket->writePrimitive(numPathBytes);
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ void NodeList::processDomainServerList(QSharedPointer<NLPacket> packet) {
|
||||||
quint8 thisNodeCanRez;
|
quint8 thisNodeCanRez;
|
||||||
packetStream >> thisNodeCanRez;
|
packetStream >> thisNodeCanRez;
|
||||||
setThisNodeCanRez((bool) thisNodeCanRez);
|
setThisNodeCanRez((bool) thisNodeCanRez);
|
||||||
|
|
||||||
// pull each node in the packet
|
// pull each node in the packet
|
||||||
while (packetStream.device()->pos() < packet->getSizeUsed()) {
|
while (packetStream.device()->pos() < packet->getSizeUsed()) {
|
||||||
parseNodeFromPacketStream(packetStream);
|
parseNodeFromPacketStream(packetStream);
|
||||||
|
|
|
@ -243,13 +243,11 @@ void PacketReceiver::processDatagrams() {
|
||||||
static const QByteArray SHARED_NODE_NORMALIZED = QMetaObject::normalizedType("SharedNodePointer");
|
static const QByteArray SHARED_NODE_NORMALIZED = QMetaObject::normalizedType("SharedNodePointer");
|
||||||
|
|
||||||
if (metaMethod.parameterTypes().contains(SHARED_NODE_NORMALIZED)) {
|
if (metaMethod.parameterTypes().contains(SHARED_NODE_NORMALIZED)) {
|
||||||
qDebug() << "invoking with matchingNode" << matchingNode;
|
|
||||||
success = metaMethod.invoke(listener.first,
|
success = metaMethod.invoke(listener.first,
|
||||||
Q_ARG(QSharedPointer<NLPacket>, QSharedPointer<NLPacket>(packet.release())),
|
Q_ARG(QSharedPointer<NLPacket>, QSharedPointer<NLPacket>(packet.release())),
|
||||||
Q_ARG(SharedNodePointer, matchingNode));
|
Q_ARG(SharedNodePointer, matchingNode));
|
||||||
|
|
||||||
} else if (metaMethod.parameterTypes().contains(QSHAREDPOINTER_NODE_NORMALIZED)) {
|
} else if (metaMethod.parameterTypes().contains(QSHAREDPOINTER_NODE_NORMALIZED)) {
|
||||||
qDebug() << "invoking with matchingNode" << matchingNode;
|
|
||||||
success = metaMethod.invoke(listener.first,
|
success = metaMethod.invoke(listener.first,
|
||||||
Q_ARG(QSharedPointer<NLPacket>, QSharedPointer<NLPacket>(packet.release())),
|
Q_ARG(QSharedPointer<NLPacket>, QSharedPointer<NLPacket>(packet.release())),
|
||||||
Q_ARG(QSharedPointer<Node>, matchingNode));
|
Q_ARG(QSharedPointer<Node>, matchingNode));
|
||||||
|
|
|
@ -70,7 +70,7 @@ Packet::Packet(PacketType::Value type, qint64 size) :
|
||||||
}
|
}
|
||||||
|
|
||||||
_packetSize = localHeaderSize(type) + size;
|
_packetSize = localHeaderSize(type) + size;
|
||||||
_packet.reset(new char(_packetSize));
|
_packet.reset(new char[_packetSize]);
|
||||||
_capacity = size;
|
_capacity = size;
|
||||||
_payloadStart = _packet.get() + (_packetSize - _capacity);
|
_payloadStart = _packet.get() + (_packetSize - _capacity);
|
||||||
|
|
||||||
|
@ -196,15 +196,14 @@ qint64 Packet::writeData(const char* data, qint64 maxSize) {
|
||||||
// make sure we have the space required to write this block
|
// make sure we have the space required to write this block
|
||||||
if (maxSize <= bytesAvailableForWrite()) {
|
if (maxSize <= bytesAvailableForWrite()) {
|
||||||
qint64 currentPos = pos();
|
qint64 currentPos = pos();
|
||||||
|
|
||||||
|
Q_ASSERT(currentPos < _capacity);
|
||||||
|
|
||||||
// good to go - write the data
|
// good to go - write the data
|
||||||
memcpy(_payloadStart + currentPos, data, maxSize);
|
memcpy(_payloadStart + currentPos, data, maxSize);
|
||||||
|
|
||||||
// seek to the new position based on where our write just finished
|
|
||||||
seek(currentPos + maxSize);
|
|
||||||
|
|
||||||
// keep track of _sizeUsed so we can just write the actual data when packet is about to be sent
|
// keep track of _sizeUsed so we can just write the actual data when packet is about to be sent
|
||||||
_sizeUsed = std::max(pos(), _sizeUsed);
|
_sizeUsed = std::max(currentPos + maxSize, _sizeUsed);
|
||||||
|
|
||||||
// return the number of bytes written
|
// return the number of bytes written
|
||||||
return maxSize;
|
return maxSize;
|
||||||
|
@ -223,9 +222,6 @@ qint64 Packet::readData(char* dest, qint64 maxSize) {
|
||||||
|
|
||||||
// read out the data
|
// read out the data
|
||||||
memcpy(dest, _payloadStart + currentPosition, numBytesToRead);
|
memcpy(dest, _payloadStart + currentPosition, numBytesToRead);
|
||||||
|
|
||||||
// seek to the end of the read
|
|
||||||
seek(currentPosition + numBytesToRead);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return numBytesToRead;
|
return numBytesToRead;
|
||||||
|
|
|
@ -56,7 +56,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this block of data can fit into the currentPacket
|
// check if this block of data can fit into the currentPacket
|
||||||
if (maxSize <= _currentPacket->bytesAvailable()) {
|
if (maxSize <= _currentPacket->bytesAvailableForWrite()) {
|
||||||
// it fits, just write it to the current packet
|
// it fits, just write it to the current packet
|
||||||
_currentPacket->write(data, maxSize);
|
_currentPacket->write(data, maxSize);
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
|
||||||
// We need to try and pull the first part of the segment out to our new packet
|
// We need to try and pull the first part of the segment out to our new packet
|
||||||
|
|
||||||
// check now to see if this is an unsupported write
|
// check now to see if this is an unsupported write
|
||||||
int numBytesToEnd = _currentPacket->bytesAvailable();
|
int numBytesToEnd = _currentPacket->bytesAvailableForWrite();
|
||||||
|
|
||||||
if ((newPacket->size() - numBytesToEnd) < maxSize) {
|
if ((newPacket->size() - numBytesToEnd) < maxSize) {
|
||||||
// this is an unsupported case - the segment is bigger than the size of an individual packet
|
// this is an unsupported case - the segment is bigger than the size of an individual packet
|
||||||
|
@ -108,7 +108,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
|
||||||
// we're an ordered PacketList - let's fit what we can into the current packet and then put the leftover
|
// we're an ordered PacketList - let's fit what we can into the current packet and then put the leftover
|
||||||
// into a new packet
|
// into a new packet
|
||||||
|
|
||||||
int numBytesToEnd = _currentPacket->bytesAvailable();
|
int numBytesToEnd = _currentPacket->bytesAvailableForWrite();
|
||||||
_currentPacket->write(data, numBytesToEnd);
|
_currentPacket->write(data, numBytesToEnd);
|
||||||
|
|
||||||
// move the current packet to our list of packets
|
// move the current packet to our list of packets
|
||||||
|
@ -120,7 +120,13 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::closeCurrentPacket() {
|
void PacketList::closeCurrentPacket(bool shouldSendEmpty) {
|
||||||
// move the current packet to our list of packets
|
if (shouldSendEmpty && !_currentPacket) {
|
||||||
_packets.push_back(std::move(_currentPacket));
|
_currentPacket = createPacketWithExtendedHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_currentPacket) {
|
||||||
|
// move the current packet to our list of packets
|
||||||
|
_packets.push_back(std::move(_currentPacket));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
PacketType::Value getType() const { return _packetType; }
|
PacketType::Value getType() const { return _packetType; }
|
||||||
int getNumPackets() const { return _packets.size() + (_currentPacket ? 1 : 0); }
|
int getNumPackets() const { return _packets.size() + (_currentPacket ? 1 : 0); }
|
||||||
|
|
||||||
void closeCurrentPacket();
|
void closeCurrentPacket(bool shouldSendEmpty = false);
|
||||||
|
|
||||||
void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; }
|
void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; }
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType::Value type, QByt
|
||||||
} else {
|
} else {
|
||||||
// If we're switching type, then we send the last one and start over
|
// If we're switching type, then we send the last one and start over
|
||||||
if ((type != bufferedPacket->getType() && bufferedPacket->getSizeUsed() > 0) ||
|
if ((type != bufferedPacket->getType() && bufferedPacket->getSizeUsed() > 0) ||
|
||||||
(editMessage.size() >= bufferedPacket->bytesAvailable())) {
|
(editMessage.size() >= bufferedPacket->bytesAvailableForWrite())) {
|
||||||
|
|
||||||
// create the new packet and swap it with the packet in _pendingEditPackets
|
// create the new packet and swap it with the packet in _pendingEditPackets
|
||||||
auto packetToRelease = initializePacket(type, node->getClockSkewUsec());
|
auto packetToRelease = initializePacket(type, node->getClockSkewUsec());
|
||||||
|
|
Loading…
Reference in a new issue