mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Merge branch 'atp' of https://github.com/birarda/hifi into protocol
This commit is contained in:
commit
60831d55c6
10 changed files with 31 additions and 29 deletions
|
@ -356,7 +356,7 @@ void OctreeQueryNode::dumpOutOfView() {
|
|||
}
|
||||
}
|
||||
|
||||
void OctreeQueryNode::packetSent(const std::unique_ptr<NLPacket>& packet) {
|
||||
void OctreeQueryNode::packetSent(const NLPacket& packet) {
|
||||
_sentPacketHistory.packetSent(_sequenceNumber, packet);
|
||||
_sequenceNumber++;
|
||||
}
|
||||
|
|
|
@ -104,8 +104,8 @@ public:
|
|||
void forceNodeShutdown();
|
||||
bool isShuttingDown() const { return _isShuttingDown; }
|
||||
|
||||
void octreePacketSent() { packetSent(_octreePacket); }
|
||||
void packetSent(const std::unique_ptr<NLPacket>& packet);
|
||||
void octreePacketSent() { packetSent(*_octreePacket.get()); }
|
||||
void packetSent(const NLPacket& packet);
|
||||
|
||||
OCTREE_PACKET_SEQUENCE getSequenceNumber() const { return _sequenceNumber; }
|
||||
|
||||
|
|
|
@ -56,12 +56,12 @@ void IceServer::processDatagrams() {
|
|||
|
||||
PacketType::Value packetType = packetTypeForPacket(incomingPacket);
|
||||
|
||||
if (packetType == PacketType::IceServerHeartbeat) {
|
||||
if (packetType == PacketType::ICEServerHeartbeat) {
|
||||
SharedNetworkPeer peer = addOrUpdateHeartbeatingPeer(incomingPacket);
|
||||
|
||||
// so that we can send packets to the heartbeating peer when we need, we need to activate a socket now
|
||||
peer->activateMatchingOrNewSymmetricSocket(sendingSockAddr);
|
||||
} else if (packetType == PacketType::IceServerQuery) {
|
||||
} else if (packetType == PacketType::ICEServerQuery) {
|
||||
QDataStream heartbeatStream(incomingPacket);
|
||||
|
||||
// this is a node hoping to connect to a heartbeating peer - do we have the heartbeating peer?
|
||||
|
@ -128,13 +128,13 @@ SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(const QByteArray& incom
|
|||
}
|
||||
|
||||
void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr) {
|
||||
auto peerPacket = Packet::create(PacketType::IceServerPeerInformation);
|
||||
auto peerPacket = Packet::create(PacketType::ICEServerPeerInformation);
|
||||
|
||||
// get the byte array for this peer
|
||||
peerPacket->write(peer.toByteArray());
|
||||
|
||||
// write the current packet
|
||||
_serverSocket.writeDatagram(peerPacket.constData(), peerPacket.sizeUsed(),
|
||||
_serverSocket.writeDatagram(peerPacket->getData(), peerPacket->getSizeWithHeader(),
|
||||
destinationSockAddr->getAddress(), destinationSockAddr->getPort());
|
||||
}
|
||||
|
||||
|
|
|
@ -33,19 +33,18 @@ std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, int64_t size)
|
|||
if (size > maxPayloadSize(type)) {
|
||||
return std::unique_ptr<NLPacket>();
|
||||
}
|
||||
|
||||
|
||||
return std::unique_ptr<NLPacket>(new NLPacket(type, size));
|
||||
}
|
||||
|
||||
std::unique_ptr<NLPacket> NLPacket::createCopy(const std::unique_ptr<NLPacket>& other) {
|
||||
Q_ASSERT(other);
|
||||
return std::unique_ptr<NLPacket>(new NLPacket(*other));
|
||||
std::unique_ptr<NLPacket> NLPacket::createCopy(const NLPacket& other) {
|
||||
return std::unique_ptr<NLPacket>(new NLPacket(other));
|
||||
}
|
||||
|
||||
NLPacket::NLPacket(PacketType::Value type, int64_t size) : Packet(type, localHeaderSize(type) + size) {
|
||||
}
|
||||
|
||||
NLPacket::NLPacket(NLPacket& other) : Packet(other) {
|
||||
NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
|
||||
}
|
||||
|
||||
void NLPacket::setSourceUuid(QUuid sourceUuid) {
|
||||
|
@ -59,4 +58,4 @@ void NLPacket::setConnectionUuid(QUuid connectionUuid) {
|
|||
auto offset = Packet::totalHeadersSize() +
|
||||
((NON_SOURCED_PACKETS.contains(_type)) ? 0 : NUM_BYTES_RFC4122_UUID);
|
||||
memcpy(_packet.get() + offset, connectionUuid.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class NLPacket : public Packet {
|
|||
public:
|
||||
static std::unique_ptr<NLPacket> create(PacketType::Value type, int64_t size = -1);
|
||||
// Provided for convenience, try to limit use
|
||||
static std::unique_ptr<NLPacket> createCopy(const std::unique_ptr<NLPacket>& other);
|
||||
static std::unique_ptr<NLPacket> createCopy(const NLPacket& other);
|
||||
|
||||
static int64_t localHeaderSize(PacketType::Value type);
|
||||
static int64_t maxPayloadSize(PacketType::Value type);
|
||||
|
@ -29,7 +29,7 @@ public:
|
|||
|
||||
protected:
|
||||
NLPacket(PacketType::Value type, int64_t size);
|
||||
NLPacket(NLPacket& other);
|
||||
NLPacket(const NLPacket& other);
|
||||
|
||||
void setSourceUuid(QUuid sourceUuid);
|
||||
void setConnectionUuid(QUuid connectionUuid);
|
||||
|
|
|
@ -38,9 +38,8 @@ std::unique_ptr<Packet> Packet::create(PacketType::Value type, qint64 size) {
|
|||
return std::unique_ptr<Packet>(new Packet(type, size));
|
||||
}
|
||||
|
||||
std::unique_ptr<Packet> Packet::createCopy(const std::unique_ptr<Packet>& other) {
|
||||
Q_ASSERT(other);
|
||||
return std::unique_ptr<Packet>(new Packet(*other));
|
||||
std::unique_ptr<Packet> Packet::createCopy(const Packet& other) {
|
||||
return std::unique_ptr<Packet>(new Packet(other));
|
||||
}
|
||||
|
||||
qint64 Packet::totalHeadersSize() const {
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
static std::unique_ptr<Packet> create(PacketType::Value type, int64_t size = -1);
|
||||
// Provided for convenience, try to limit use
|
||||
static std::unique_ptr<Packet> createCopy(const std::unique_ptr<Packet>& other);
|
||||
static std::unique_ptr<Packet> createCopy(const Packet& other);
|
||||
|
||||
static qint64 localHeaderSize(PacketType::Value type);
|
||||
static qint64 maxPayloadSize(PacketType::Value type);
|
||||
|
|
|
@ -24,7 +24,7 @@ SentPacketHistory::SentPacketHistory(int size)
|
|||
|
||||
}
|
||||
|
||||
void SentPacketHistory::packetSent(uint16_t sequenceNumber, const std::unique_ptr<NLPacket>& packet) {
|
||||
void SentPacketHistory::packetSent(uint16_t sequenceNumber, const NLPacket& packet) {
|
||||
|
||||
// check if given seq number has the expected value. if not, something's wrong with
|
||||
// the code calling this function
|
||||
|
@ -38,7 +38,7 @@ void SentPacketHistory::packetSent(uint16_t sequenceNumber, const std::unique_pt
|
|||
_sentPackets.insert(NLPacket::createCopy(packet));
|
||||
}
|
||||
|
||||
const std::unique_ptr<NLPacket>& SentPacketHistory::getPacket(uint16_t sequenceNumber) const {
|
||||
const NLPacket* SentPacketHistory::getPacket(uint16_t sequenceNumber) const {
|
||||
|
||||
const int UINT16_RANGE = std::numeric_limits<uint16_t>::max() + 1;
|
||||
|
||||
|
@ -48,6 +48,10 @@ const std::unique_ptr<NLPacket>& SentPacketHistory::getPacket(uint16_t sequenceN
|
|||
if (seqDiff < 0) {
|
||||
seqDiff += UINT16_RANGE;
|
||||
}
|
||||
|
||||
return *_sentPackets.get(seqDiff);
|
||||
auto packet = _sentPackets.get(seqDiff);
|
||||
if (packet) {
|
||||
return packet->get();
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ class SentPacketHistory {
|
|||
public:
|
||||
SentPacketHistory(int size = MAX_REASONABLE_SEQUENCE_GAP);
|
||||
|
||||
void packetSent(uint16_t sequenceNumber, const std::unique_ptr<NLPacket>& packet);
|
||||
const std::unique_ptr<NLPacket>& getPacket(uint16_t sequenceNumber) const;
|
||||
void packetSent(uint16_t sequenceNumber, const NLPacket& packet);
|
||||
const NLPacket* getPacket(uint16_t sequenceNumber) const;
|
||||
|
||||
private:
|
||||
RingBufferHistory<std::unique_ptr<NLPacket>> _sentPackets; // circular buffer
|
||||
|
|
|
@ -108,7 +108,7 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu
|
|||
}
|
||||
|
||||
// add packet to history
|
||||
_sentPacketHistories[nodeUUID].packetSent(sequence, packet);
|
||||
_sentPacketHistories[nodeUUID].packetSent(sequence, *packet.get());
|
||||
|
||||
queuePacketForSending(node, std::move(packet));
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ void OctreeEditPacketSender::queuePacketToNodes(std::unique_ptr<NLPacket> packet
|
|||
|
||||
if (isMyJurisdiction) {
|
||||
// make a copy of this packet for this node and queue
|
||||
auto packetCopy = NLPacket::createCopy(packet);
|
||||
auto packetCopy = NLPacket::createCopy(*packet.get());
|
||||
queuePacketToNode(nodeUUID, std::move(packetCopy));
|
||||
}
|
||||
}
|
||||
|
@ -362,10 +362,10 @@ void OctreeEditPacketSender::processNackPacket(const QByteArray& packet) {
|
|||
dataAt += sizeof(unsigned short int);
|
||||
|
||||
// retrieve packet from history
|
||||
const std::unique_ptr<NLPacket>& packet = sentPacketHistory.getPacket(sequenceNumber);
|
||||
const NLPacket* packet = sentPacketHistory.getPacket(sequenceNumber);
|
||||
if (packet) {
|
||||
const SharedNodePointer& node = DependencyManager::get<NodeList>()->nodeWithUUID(sendingNodeUUID);
|
||||
queuePacketForSending(node, NLPacket::createCopy(packet));
|
||||
queuePacketForSending(node, NLPacket::createCopy(*packet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue