mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Merge branch 'protocol' of github.com:Atlante45/hifi into protocol
This commit is contained in:
commit
10c69fefe1
6 changed files with 43 additions and 31 deletions
|
@ -203,7 +203,7 @@ void AssignmentClientMonitor::checkSpares() {
|
|||
}
|
||||
|
||||
void AssignmentClientMonitor::handleChildStatusPacket(QSharedPointer<NLPacket> packet) {
|
||||
QUuid senderID = QUuid::fromRfc4122(QByteArray::fromRawData(packet->getData(), NUM_BYTES_RFC4122_UUID));
|
||||
QUuid senderID = QUuid::fromRfc4122(QByteArray::fromRawData(packet->getPayload(), NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
|
||||
int AvatarMixerClientData::parseData(NLPacket& packet) {
|
||||
// compute the offset to the data payload
|
||||
return _avatar.parseDataFromBuffer(QByteArray::fromRawData(packet.getPayload(), packet.getPayloadSize()));
|
||||
QByteArray byteArray = QByteArray::fromRawData(packet.getPayload() + packet.pos(),
|
||||
packet.bytesLeftToRead());
|
||||
return _avatar.parseDataFromBuffer(byteArray);
|
||||
}
|
||||
|
||||
bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() {
|
||||
|
|
|
@ -61,6 +61,8 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer<NLPacket> packet, Sha
|
|||
while (packet->bytesLeftToRead()) {
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
QByteArray byteArray = QByteArray::fromRawData(packet->getPayload() + packet->pos(),
|
||||
packet->bytesLeftToRead());
|
||||
if (sessionUUID != _lastOwnerSessionUUID) {
|
||||
AvatarSharedPointer avatar = _avatarHash.value(sessionUUID);
|
||||
if (!avatar) {
|
||||
|
@ -68,12 +70,12 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer<NLPacket> packet, Sha
|
|||
}
|
||||
|
||||
// have the matching (or new) avatar parse the data from the packet
|
||||
int bytesRead = avatar->parseDataFromBuffer(QByteArray::fromRawData(packet->getPayload(), packet->getPayloadSize()));
|
||||
int bytesRead = avatar->parseDataFromBuffer(byteArray);
|
||||
packet->seek(packet->pos() + bytesRead);
|
||||
} else {
|
||||
// create a dummy AvatarData class to throw this data on the ground
|
||||
AvatarData dummyData;
|
||||
int bytesRead = dummyData.parseDataFromBuffer(QByteArray::fromRawData(packet->getPayload(), packet->getPayloadSize()));
|
||||
int bytesRead = dummyData.parseDataFromBuffer(byteArray);
|
||||
packet->seek(packet->pos() + bytesRead);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,6 +216,20 @@ bool LimitedNodeList::packetSourceAndHashMatch(const NLPacket& packet, SharedNod
|
|||
return false;
|
||||
}
|
||||
|
||||
qint64 LimitedNodeList::writePacket(const NLPacket& packet, const Node& destinationNode) {
|
||||
if (!destinationNode.getActiveSocket()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO Move to transport layer when ready
|
||||
if (SEQUENCE_NUMBERED_PACKETS.contains(packet.getType())) {
|
||||
PacketSequenceNumber sequenceNumber = getNextSequenceNumberForPacket(destinationNode.getUUID(), packet.getType());
|
||||
const_cast<NLPacket&>(packet).writeSequenceNumber(sequenceNumber);
|
||||
}
|
||||
|
||||
return writePacket(packet, *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret());
|
||||
}
|
||||
|
||||
qint64 LimitedNodeList::writePacket(const NLPacket& packet, const HifiSockAddr& destinationSockAddr,
|
||||
const QUuid& connectionSecret) {
|
||||
if (!NON_SOURCED_PACKETS.contains(packet.getType())) {
|
||||
|
@ -248,14 +262,7 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSock
|
|||
}
|
||||
|
||||
qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode) {
|
||||
const HifiSockAddr* activeSocket = destinationNode.getActiveSocket();
|
||||
if (!activeSocket) {
|
||||
// we don't have a socket to send to, return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
// use the node's active socket as the destination socket
|
||||
return sendUnreliablePacket(packet, *activeSocket, destinationNode.getConnectionSecret());
|
||||
return writePacket(packet, destinationNode);
|
||||
}
|
||||
|
||||
qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr,
|
||||
|
@ -264,30 +271,29 @@ qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiS
|
|||
}
|
||||
|
||||
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode) {
|
||||
const HifiSockAddr* activeSocket = destinationNode.getActiveSocket();
|
||||
if (!activeSocket) {
|
||||
// we don't have a socket to send to, return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
// use the node's active socket as the destination socket
|
||||
return sendPacket(std::move(packet), *activeSocket, destinationNode.getConnectionSecret());
|
||||
// Keep unique_ptr alive during write
|
||||
auto result = writePacket(*packet, destinationNode);
|
||||
return result;
|
||||
}
|
||||
|
||||
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr,
|
||||
const QUuid& connectionSecret) {
|
||||
return writePacket(*packet, sockAddr, connectionSecret);
|
||||
// Keep unique_ptr alive during write
|
||||
auto result = writePacket(*packet, sockAddr, connectionSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) {
|
||||
const HifiSockAddr* activeSocket = destinationNode.getActiveSocket();
|
||||
if (!activeSocket) {
|
||||
// we don't have a socket to send to, return 0
|
||||
return 0;
|
||||
qint64 bytesSent = 0;
|
||||
|
||||
// close the last packet in the list
|
||||
packetList.closeCurrentPacket();
|
||||
|
||||
while (!packetList._packets.empty()) {
|
||||
bytesSent += sendPacket(std::move(packetList.takeFront<NLPacket>()), destinationNode);
|
||||
}
|
||||
|
||||
// use the node's active socket as the destination socket
|
||||
return sendPacketList(packetList, *activeSocket, destinationNode.getConnectionSecret());
|
||||
return bytesSent;
|
||||
}
|
||||
|
||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr,
|
||||
|
@ -395,6 +401,7 @@ void LimitedNodeList::processKillNode(NLPacket& packet) {
|
|||
|
||||
void LimitedNodeList::handleNodeKill(const SharedNodePointer& node) {
|
||||
qCDebug(networking) << "Killed" << *node;
|
||||
node->stopPingTimer();
|
||||
emit nodeKilled(node);
|
||||
}
|
||||
|
||||
|
@ -490,8 +497,8 @@ unsigned int LimitedNodeList::broadcastToNodes(std::unique_ptr<NLPacket> packet,
|
|||
unsigned int n = 0;
|
||||
|
||||
eachNode([&](const SharedNodePointer& node){
|
||||
if (node->getActiveSocket() && destinationNodeTypes.contains(node->getType())) {
|
||||
writePacket(*packet, *node->getActiveSocket(), node->getConnectionSecret());
|
||||
if (node && destinationNodeTypes.contains(node->getType())) {
|
||||
writePacket(*packet, *node);
|
||||
++n;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -248,6 +248,7 @@ protected:
|
|||
LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||
void operator=(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||
|
||||
qint64 writePacket(const NLPacket& packet, const Node& destinationNode);
|
||||
qint64 writePacket(const NLPacket& packet, const HifiSockAddr& destinationSockAddr,
|
||||
const QUuid& connectionSecret = QUuid());
|
||||
qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr);
|
||||
|
|
|
@ -68,7 +68,8 @@ public:
|
|||
|
||||
HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; }
|
||||
const HifiSockAddr& getSenderSockAddr() const { return _senderSockAddr; }
|
||||
|
||||
|
||||
void writeSequenceNumber(SequenceNumber seqNum);
|
||||
SequenceNumber readSequenceNumber() const;
|
||||
bool readIsControlPacket() const;
|
||||
|
||||
|
@ -100,7 +101,6 @@ protected:
|
|||
|
||||
// Header writers
|
||||
void writePacketTypeAndVersion(PacketType::Value type);
|
||||
void writeSequenceNumber(SequenceNumber seqNum);
|
||||
|
||||
PacketType::Value _type; // Packet type
|
||||
PacketVersion _version; // Packet version
|
||||
|
|
Loading…
Reference in a new issue