Merge branch 'atp' of https://github.com/birarda/hifi into protocol

This commit is contained in:
Atlante45 2015-07-07 16:28:21 -07:00
commit ac89571a79
22 changed files with 158 additions and 176 deletions

View file

@ -196,7 +196,7 @@ void AssignmentClientMonitor::checkSpares() {
childNode->activateLocalSocket();
auto diePacket = NLPacket::create(PacketType::StopNode, 0);
nodeList->sendPacket(diePacket, childNode);
nodeList->sendPacket(std::move(diePacket), childNode);
}
}
}
@ -231,7 +231,7 @@ void AssignmentClientMonitor::readPendingDatagrams() {
qDebug() << "asking unknown child to exit.";
auto diePacket = NL::create(PacketType::StopNode, 0);
nodeList->sendPacket(diePacket, childNode);
nodeList->sendPacket(std::move(diePacket), childNode);
}
}
}

View file

@ -530,7 +530,7 @@ void AudioMixer::sendAudioEnvironmentPacket(SharedNodePointer node) {
envPacket.write(&reverbTime, sizeof(reverb));
envPacket.write(&wetLevel, sizeof(wetLevel));
}
nodeList->sendPacket(envPacket, node);
nodeList->sendPacket(std::move(envPacket), node);
}
}
@ -794,7 +794,7 @@ void AudioMixer::run() {
if (nodeData->getAvatarAudioStream()
&& shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
auto mutePacket = NLPacket::create(PacketType::NoisyMute, 0);
nodeList->sendPacket(mutePacket, node);
nodeList->sendPacket(std::move(mutePacket), node);
}
if (node->getType() == NodeType::Agent && node->getActiveSocket()

View file

@ -190,7 +190,7 @@ void AudioMixerClientData::sendAudioStreamStatsPackets(const SharedNodePointer&
numStreamStatsRemaining -= numStreamStatsToPack;
// send the current packet
nodeList->sendPacket(statsPacket, destinationNode);
nodeList->sendPacket(std::move(statsPacket), destinationNode);
}
}

View file

@ -213,7 +213,7 @@ void AvatarMixer::broadcastAvatarData() {
}
// setup a PacketList for the avatarPackets
PacketList avatarPacketList(PacketType::AvatarData);
NLPacketList avatarPacketList(PacketType::AvatarData);
// this is an AGENT we have received head data from
// send back a packet with other active node data to this node
@ -305,11 +305,11 @@ void AvatarMixer::broadcastAvatarData() {
|| otherNodeData->getBillboardChangeTimestamp() > _lastFrameTimestamp
|| randFloat() < BILLBOARD_AND_IDENTITY_SEND_PROBABILITY)) {
auto billboardPacket { NLPacket::create(PacketType::AvatarBillboard); }
billboardPacket.write(otherNode->getUUID().toRfc4122());
billboardPacket.write(otherNodeData->getAvatar().getBillboard());
auto billboardPacket = NLPacket::create(PacketType::AvatarBillboard);
billboardPacket->write(otherNode->getUUID().toRfc4122());
billboardPacket->write(otherNodeData->getAvatar().getBillboard());
nodeList->sendPacket(billboardPacket, node);
nodeList->sendPacket(std::move(billboardPacket), node);
++_sumBillboardPackets;
}
@ -319,14 +319,14 @@ void AvatarMixer::broadcastAvatarData() {
|| otherNodeData->getIdentityChangeTimestamp() > _lastFrameTimestamp
|| randFloat() < BILLBOARD_AND_IDENTITY_SEND_PROBABILITY)) {
auto identityPacket { NLPacket::create(PacketType::AvatarIdentity); }
auto identityPacket = NLPacket::create(PacketType::AvatarIdentity);
QByteArray individualData = otherNodeData->getAvatar().identityByteArray();
individualData.replace(0, NUM_BYTES_RFC4122_UUID, otherNode->getUUID().toRfc4122());
identityPacket.write(individualData);
identityPacket->write(individualData);
nodeList->sendPacket(identityPacket, node);
nodeList->sendPacket(std::move(identityPacket), node);
++_sumIdentityPackets;
}
@ -361,8 +361,8 @@ void AvatarMixer::nodeKilled(SharedNodePointer killedNode) {
// this was an avatar we were sending to other people
// send a kill packet for it to our other nodes
auto killPacket { NLPacket::create(PacketType::KillAvatar); }
killPacket.write(killedNode->getUUID().toRfc4122());
auto killPacket = NLPacket::create(PacketType::KillAvatar, NUM_BYTES_RFC4122_UUID);
killPacket->write(killedNode->getUUID().toRfc4122());
nodeList->broadcastToNodes(killPacket, NodeSet() << NodeType::Agent);

View file

@ -235,14 +235,13 @@ void OctreeInboundPacketProcessor::trackInboundPacket(const QUuid& nodeUUID, uns
}
int OctreeInboundPacketProcessor::sendNackPackets() {
int packetsSent = 0;
if (_shuttingDown) {
qDebug() << "OctreeInboundPacketProcessor::sendNackPackets() while shutting down... ignore";
return packetsSent;
return 0;
}
auto nackPacket { NLPacket::create(_myServer->getMyEditNackType(); }
NLPacketList nackPacketList(_myServer->getMyEditNackType();
auto nodeList = DependencyManager::get<NodeList>();
NodeToSenderStatsMapIterator i = _singleSenderStats.begin();
while (i != _singleSenderStats.end()) {
@ -271,37 +270,25 @@ int OctreeInboundPacketProcessor::sendNackPackets() {
// construct nack packet(s) for this node
const QSet<unsigned short int>& missingSequenceNumbers = sequenceNumberStats.getMissingSet();
int numSequenceNumbersAvailable = missingSequenceNumbers.size();
QSet<unsigned short int>::const_iterator missingSequenceNumberIterator = missingSequenceNumbers.constBegin();
while (numSequenceNumbersAvailable > 0) {
auto nodeList = DependencyManager::get<NodeList>();
auto it = missingSequenceNumbers.constBegin();
nackPacket->reset();
// calculate and pack the number of sequence numbers to nack
int numSequenceNumbersRoomFor = (nackPacket->getCapacity() - sizeof(uint16_t)) / sizeof(unsigned short int);
uint16_t numSequenceNumbers = std::min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor);
nackPacket->write(&numSequenceNumbers, sizeof(numSequenceNumbers));
// pack sequence numbers to nack
for (uint16_t i = 0; i < numSequenceNumbers; i++) {
unsigned short int sequenceNumber = *missingSequenceNumberIterator;
nackPacket->write(&sequenceNumber, sizeof(sequenceNumber));
missingSequenceNumberIterator++;
}
numSequenceNumbersAvailable -= numSequenceNumbers;
// send it
nodeList->sendUnreliablePacket(nackPacket, destinationNode);
packetsSent++;
qDebug() << "NACK Sent back to editor/client... destinationNode=" << nodeUUID;
while (it != missingSequenceNumbers.constEnd()) {
unsigned short int sequenceNumber = *it;
nackPacketList->write(&sequenceNumber, sizeof(sequenceNumber));
++it;
}
i++;
}
int packetsSent = nackPacketList.getNumPackets();
if (packetsSent) {
qDebug() << "NACK Sent back to editor/client... destinationNode=" << nodeUUID;
}
// send the list of nack packets
nodeList->sendPacketList(nackPacketList, destinationNode);
return packetsSent;
}

View file

@ -108,9 +108,9 @@ bool OctreeQueryNode::packetIsDuplicate() const {
// since our packets now include header information, like sequence number, and createTime, we can't just do a memcmp
// of the entire packet, we need to compare only the packet content...
if (_lastOctreePacketLength == getPacketLength()) {
if (_lastOctreePacketLength == _octreePacket->getSizeUsed()) {
if (memcmp(_lastOctreePayload + OCTREE_PACKET_EXTRA_HEADERS_SIZE,
_octreePacket->getPayload() + OCTREE_PACKET_EXTRA_HEADERS_SIZE,
_octreePacket->getPayload() + OCTREE_PACKET_EXTRA_HEADERS_SIZE,
_octreePacket->getSizeUsed() - OCTREE_PACKET_EXTRA_HEADERS_SIZE) == 0) {
return true;
}
@ -379,6 +379,8 @@ void OctreeQueryNode::parseNackPacket(const QByteArray& packet) {
int numBytesPacketHeader = numBytesForPacketHeader(packet);
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader;
// TODO: This no longer has the number of sequence numbers - just read to the end of the packet in sequence number blocks
// read number of sequence numbers
uint16_t numSequenceNumbers = (*(uint16_t*)dataAt);
dataAt += sizeof(uint16_t);

View file

@ -147,7 +147,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
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 (nodeData->getPacket()->getSizeUsed() < statsPacket->bytesAvailable()) {
if (nodeData->getPacket()->getSizeWithHeader() <= statsPacket->bytesAvailable()) {
// copy octree message to back of stats message
statsPacket->write(nodeData->getPacket()->getData(), nodeData->getPacket()->getSizeWithHeader());

View file

@ -622,8 +622,8 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
QByteArray utfString = reason.toUtf8();
int payloadSize = utfString.size();
auto connectionDeniedPacket = NLPacket::make(PacketType::DomainConnectionDenied, payloadSize);
connectionDeniedPacket.write(utfString);
auto connectionDeniedPacket = NLPacket::create(PacketType::DomainConnectionDenied, payloadSize);
connectionDeniedPacket->write(utfString);
// tell client it has been refused.
limitedNodeList->sendPacket(std::move(connectionDeniedPacket, senderSockAddr);
@ -927,7 +927,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif
const NodeSet& nodeInterestSet) {
auto limitedNodeList = DependencyManager::get<LimitedNodeList>();
PacketList domainListPackets(PacketType::DomainList);
NLPacketList domainListPackets(PacketType::DomainList);
// always send the node their own UUID back
QDataStream domainListStream(&domainListPackets);
@ -1324,10 +1324,10 @@ void DomainServer::pingPunchForConnectingPeer(const SharedNetworkPeer& peer) {
// send the ping packet to the local and public sockets for this node
auto localPingPacket = nodeList->constructICEPingPacket(PingType::Local, limitedNodeList->getSessionUUID());
limitedNodeList->sendPacket(localPingPacket, peer->getLocalSocket());
limitedNodeList->sendPacket(std::move(localPingPacket), peer->getLocalSocket());
auto publicPingPacket = nodeList->constructICEPingPacket(PingType::Public, limitedNodeList->getSessionUUID());
limitedNodeList->sendPacket(publicPingPacket, peer->getPublicSocket());
limitedNodeList->sendPacket(std::move(publicPingPacket), peer->getPublicSocket());
peer->incrementConnectionAttempts();
}
@ -1448,7 +1448,7 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS
processICEPingReply(receivedPacket, senderSockAddr);
break;
}
case PacketTypeIceServerPeerInformation:
case PacketType::ICEServerPeerInformation:
processICEPeerInformation(receivedPacket);
break;
default:

View file

@ -127,7 +127,7 @@ SharedNetworkPeer IceServer::addOrUpdateHeartbeatingPeer(const QByteArray& incom
}
void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const HifiSockAddr* destinationSockAddr) {
auto peerPacket { NLPacket::create(PacketType::IceServerPeerInformation); }
auto peerPacket = Packet::create(PacketType::IceServerPeerInformation);
// get the byte array for this peer
peerPacket->write(peer.toByteArray());

View file

@ -2660,9 +2660,7 @@ int Application::sendNackPackets() {
return 0;
}
int packetsSent = 0;
auto nackPacket { NLPacket::create(PacketType::OctreeDataNack); }
NLPacketList nackPacketList(PacketType::OctreeDataNack);
// iterates thru all nodes in NodeList
auto nodeList = DependencyManager::get<NodeList>();
@ -2676,7 +2674,7 @@ int Application::sendNackPackets() {
// if there are octree packets from this node that are waiting to be processed,
// don't send a NACK since the missing packets may be among those waiting packets.
if (_octreeProcessor.hasPacketsToProcessFrom(nodeUUID)) {
return;
return 0;
}
_octreeSceneStatsLock.lockForRead();
@ -2684,7 +2682,7 @@ int Application::sendNackPackets() {
// retreive octree scene stats of this node
if (_octreeServerSceneStats.find(nodeUUID) == _octreeServerSceneStats.end()) {
_octreeSceneStatsLock.unlock();
return;
return 0;
}
// get sequence number stats of node, prune its missing set, and make a copy of the missing set
@ -2696,34 +2694,23 @@ int Application::sendNackPackets() {
// construct nack packet(s) for this node
int numSequenceNumbersAvailable = missingSequenceNumbers.size();
QSet<OCTREE_PACKET_SEQUENCE>::const_iterator missingSequenceNumbersIterator = missingSequenceNumbers.constBegin();
while (numSequenceNumbersAvailable > 0) {
// reset the position we are writing at and the size we have used
nackPacket->seek(0);
nackPacket->setSizeUsed(0);
// calculate and pack the number of sequence numbers
int numSequenceNumbersRoomFor = (nackPacket->size() - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE);
uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor);
nackPacket->write(&numSequenceNumbers, sizeof(numSequenceNumbers));
// pack sequence numbers
for (int i = 0; i < numSequenceNumbers; i++) {
OCTREE_PACKET_SEQUENCE missingNumber = *missingSequenceNumbersIterator;
nackPacket->write(&missingNumber, sizeof(OCTREE_PACKET_SEQUENCE));
missingSequenceNumbersIterator++;
}
numSequenceNumbersAvailable -= numSequenceNumbers;
// send the packet
nodeList->sendUnreliablePacket(packet, node);
packetsSent++;
auto it = missingSequenceNumbers.constBegin();
while (it != missingSequenceNumbers.constEnd()) {
OCTREE_PACKET_SEQUENCE missingNumber = *it;
nackPacketList->write(&missingNumber, sizeof(OCTREE_PACKET_SEQUENCE));
++it;
}
}
});
int packetsSent = nackPacketList.getNumPackets();
if (packetsSent) {
// send the packet list
nodeList->sendPacketList(nackPacketList, node);
}
return packetsSent;
}
@ -2817,7 +2804,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType::Value packetTyp
qCDebug(interfaceapp, "perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer);
}
auto queryPacket { NLPacket::create(packetType); }
auto queryPacket = NLPacket::create(packetType);
nodeList->eachNode([&](const SharedNodePointer& node){
// only send to the NodeTypes that are serverType
@ -2896,7 +2883,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType::Value packetTyp
// encode the query data
int packetSize = _octreeQuery.getBroadcastData(queryPacket.payload());
queryPacket.setSizeUsed(packetSize);
queryPacket->setSizeUsed(packetSize);
// make sure we still have an active socket
nodeList->sendUnreliablePacket(queryPacket, node);

View file

@ -734,7 +734,7 @@ void AudioClient::handleAudioInput() {
int inputSamplesRequired = (int)((float)AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * inputToNetworkInputRatio);
static int leadingBytes = sizeof(quint16) + sizeof(glm::vec3) + sizeof(glm::quat) + sizeof(quint8);
int16_t* networkAudioSamples = (int16_t*)(_audioPacket->payload() + leadingBytes);
int16_t* networkAudioSamples = (int16_t*)(_audioPacket->getPayload() + leadingBytes);
QByteArray inputByteArray = _inputDevice->readAll();
@ -853,11 +853,8 @@ void AudioClient::handleAudioInput() {
}
}
// seek to the beginning of the audio packet payload
_audioPacket->seek(0);
// reset the size used in this packet so it will be correct once we are done writing
_audioPacket->setSizeUsed(0);
// reset the audio packet so we can start writing
_audioPacket->reset();
// write sequence number
_audioPacket->write(&_outgoingAvatarAudioSequenceNumber, sizeof(quint16));
@ -913,21 +910,21 @@ void AudioClient::sendMuteEnvironmentPacket() {
int dataSize = sizeof(glm::vec3) + sizeof(float);
NodeList::Packet mutePacket = nodeList->makePacket(PacketType::MuteEnvironment, dataSize);
auto mutePacket = NLPacket::create(PacketType::MuteEnvironment, dataSize);
const float MUTE_RADIUS = 50;
glm::vec3 currentSourcePosition = _positionGetter();
memcpy(mutePacket.payload().data(), &currentSourcePosition, sizeof(glm::vec3));
memcpy(mutePacket.payload() + sizeof(glm::vec3), &MUTE_RADIUS, sizeof(float));
mutePacket->write(&currentSourcePosition, sizeof(currentSourcePosition));
mutePacket->write(&MUTE_RADIUS, sizeof(MUTE_RADIUS));
// grab our audio mixer from the NodeList, if it exists
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
if (audioMixer) {
// send off this mute packet
nodeList->sendPacket(mutePacket, audioMixer);
nodeList->sendPacket(std::move(mutePacket), audioMixer);
}
}

View file

@ -124,5 +124,5 @@ void AudioIOStats::sendDownstreamAudioStatsPacket() {
// send packet
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
nodeList->sendPacket(packet, audioMixer);
nodeList->sendPacket(std::move(statsPacket), audioMixer);
}

View file

@ -153,7 +153,7 @@ void AudioInjector::injectToMixer() {
// make sure we actually have samples downloaded to inject
if (_audioData.size()) {
auto audioPacket { NLPacket::create(PacketType::InjectAudio); }
auto audioPacket = NLPacket::create(PacketType::InjectAudio);
// setup the packet for injected audio
QDataStream audioPacketStream(&audioPacket);
@ -177,7 +177,6 @@ void AudioInjector::injectToMixer() {
sizeof(_options.position));
// pack our orientation for injected audio
int orientationOptionOffset = audioPacket.pos();
audioPacketStream.writeRawData(reinterpret_cast<const char*>(&_options.orientation),
sizeof(_options.orientation));
@ -216,23 +215,24 @@ void AudioInjector::injectToMixer() {
}
_loudness /= (float)(bytesToCopy / sizeof(int16_t));
audioPacket.seek(positionOptionOffset);
audioPacket.write(&_options.position, sizeof(_options.position));
audioPacket.seek(orientationOptionOffset);
audioPacket->seek(positionOptionOffset);
audioPacket->write(&_options.position, sizeof(_options.position));
audioPacket.write(&_options.orientation, sizeof(_options.orientation));
volume = MAX_INJECTOR_VOLUME * _options.volume;
audioPacket.seek(volumeOptionOffset);
audioPacket.write(&volume, sizeof(volume));
audioPacket->seek(volumeOptionOffset);
audioPacket->write(&volume, sizeof(volume));
audioPacket.seek(audioDataOffset);
audioPacket->seek(audioDataOffset);
// pack the sequence number
audioPacket.write(&outgoingInjectedAudioSequenceNumber, sizeof(quint16));
audioPacket->write(&outgoingInjectedAudioSequenceNumber, sizeof(quint16));
// copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet
audioPacket.write(_audioData.data() + _currentSendPosition, bytesToCopy);
audioPacket->write(_audioData.data() + _currentSendPosition, bytesToCopy);
// set the correct size used for this packet
audioPacket->setSizeUsed(audioPacket->pos());
// grab our audio mixer from the NodeList, if it exists
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);

View file

@ -521,11 +521,11 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t
// return n;
// }
NLPacket&& LimitedNodeList::constructPingPacket(PingType_t pingType) {
std::unique_ptr<NLPacket> LimitedNodeList::constructPingPacket(PingType_t pingType) {
int packetSize = sizeof(PingType_t) + sizeof(quint64);
auto pingPacket { NLPacket::create(PacketType::Ping, packetSize); }
auto pingPacket = NLPacket::create(PacketType::Ping, packetSize);
QDataStream packetStream(&pingPacket.payload(), QIODevice::Append);
QDataStream packetStream(&pingPacket);
packetStream << pingType;
packetStream << usecTimestampNow();
@ -533,7 +533,7 @@ NLPacket&& LimitedNodeList::constructPingPacket(PingType_t pingType) {
return pingPacket;
}
NLPacket&& LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacket) {
std::unique_ptr<NLPacket> LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacket) {
QDataStream pingPacketStream(pingPacket);
pingPacketStream.skipRawData(numBytesForPacketHeader(pingPacket));
@ -545,37 +545,37 @@ NLPacket&& LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacke
int packetSize = sizeof(PingType_t) + sizeof(quint64) + sizeof(quint64);
auto replyPacket { NLPacket::create(PacketType::Ping, packetSize); }
auto replyPacket = NLPacket::create(PacketType::Ping, packetSize);
QDataStream packetStream(&replyPacket, QIODevice::Append);
QDataStream packetStream(&replyPacket);
packetStream << typeFromOriginalPing << timeFromOriginalPing << usecTimestampNow();
return replyPacket;
}
NLPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID) {
std::unique_ptr<NLPacket> constructICEPingPacket(PingType_t pingType, const QUuid& iceID) {
int packetSize = NUM_BYTES_RFC4122_UUID + sizeof(PingType_t);
auto icePingPacket { NLPacket::create(PacketType::ICEPing, packetSize); }
auto icePingPacket = NLPacket::create(PacketType::ICEPing, packetSize);
icePingPacket.payload().replace(0, NUM_BYTES_RFC4122_UUID, iceID.toRfc4122().data());
memcpy(icePingPacket.payload() + NUM_BYTES_RFC4122_UUID, &pingType, sizeof(PingType_t));
icePingPacket->write(iceID.toRfc4122());
icePingPacket->write(&pingType, sizeof(pingType));
return icePingPacket;
}
NLPacket&& constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID) {
std::unique_ptr<NLPacket> constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID) {
// pull out the ping type so we can reply back with that
PingType_t pingType;
memcpy(&pingType, pingPacket.data() + NUM_BYTES_RFC4122_UUID, sizeof(PingType_t));
int packetSize = NUM_BYTES_RFC4122_UUID + sizeof(PingType_t);
auto icePingReplyPacket { NLPacket::create(PacketType::ICEPingReply, packetSize); }
auto icePingReplyPacket = NLPacket::create(PacketType::ICEPingReply, packetSize);
// pack the ICE ID and then the ping type
memcpy(icePingReplyPacket.payload(), iceID.toRfc4122().data(), NUM_BYTES_RFC4122_UUID);
memcpy(icePingReplyPacket.payload() + NUM_BYTES_RFC4122_UUID, &pingType, sizeof(PingType_t));
icePingReplyPacket->write(iceID.toRfc4122());
icePingReplyPacket->write(&pingType, sizeof(pingType));
return icePingReplyPacket;
}

View file

@ -145,10 +145,10 @@ public:
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
qint64 sendUnreliablePacket(NLPacket& packet, const SharedNodePointer& destinationNode) {};
qint64 sendUnreliablePacket(NLPacket& packet, const HifiSockAddr& sockAddr) {};
qint64 sendPacket(NLPacket&& packet, const SharedNodePointer& destinationNode) {};
qint64 sendPacket(NLPacket&& packet, const HifiSockAddr& sockAddr) {};
qint64 sendUnreliablePacket(std::unique_ptr<NLPacket>& packet, const SharedNodePointer& destinationNode) {};
qint64 sendUnreliablePacket(std::unique_ptr<NLPacket>& packet, const HifiSockAddr& sockAddr) {};
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const SharedNodePointer& destinationNode) {};
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr) {};
qint64 sendPacketList(NLPacketList& packetList, const SharedNodePointer& destinationNode) {};
qint64 sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) {};
@ -175,17 +175,17 @@ public:
int updateNodeWithDataFromPacket(const SharedNodePointer& matchingNode, const QByteArray& packet);
int findNodeAndUpdateWithDataFromPacket(const QByteArray& packet);
unsigned broadcastToNodes(NLPacketList& packetList, const NodeSet& destinationNodeTypes) {};
unsigned broadcastToNodes(std::unique_ptr<NLPacket> packet, const NodeSet& destinationNodeTypes) {};
SharedNodePointer soloNodeOfType(char nodeType);
void getPacketStats(float &packetsPerSecond, float &bytesPerSecond);
void resetPacketStats();
NLPacket&& constructPingPacket(PingType_t pingType = PingType::Agnostic);
NLPacket&& constructPingReplyPacket(const QByteArray& pingPacket);
std::unique_ptr<NLPacket> constructPingPacket(PingType_t pingType = PingType::Agnostic);
std::unique_ptr<NLPacket> constructPingReplyPacket(const QByteArray& pingPacket);
NLPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID);
NLPacket&& constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID);
std::unique_ptr<NLPacket> constructICEPingPacket(PingType_t pingType, const QUuid& iceID);
std::unique_ptr<NLPacket> constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID);
virtual bool processSTUNResponse(const QByteArray& packet);

View file

@ -204,7 +204,7 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr
if (matchingNode) {
matchingNode->setLastHeardMicrostamp(usecTimestampNow());
auto replyPacket = constructPingReplyPacket(packet);
sendPacket(replyPacket, matchingNode, senderSockAddr);
sendPacket(std::move(replyPacket), matchingNode, senderSockAddr);
// If we don't have a symmetric socket for this node and this socket doesn't match
// what we have for public and local then set it as the symmetric.
@ -236,7 +236,7 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr
case PacketType::ICEPing: {
// send back a reply
auto replyPacket = constructICEPingReplyPacket(packet, _domainHandler.getICEClientID());
sendPacket(replyPacket, senderSockAddr);
sendPacket(std::move(replyPacket), senderSockAddr);
break;
}
case PacketType::ICEPingReply: {
@ -369,7 +369,7 @@ void NodeList::sendDomainServerCheckIn() {
flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendDSCheckIn);
if (!isUsingDTLS) {
sendPacket(domainPacket, _domainHandler.getSockAddr());
sendPacket(std::move(domainPacket), _domainHandler.getSockAddr());
}
if (_numNoReplyDomainCheckIns >= MAX_SILENT_DOMAIN_SERVER_CHECK_INS) {
@ -422,16 +422,16 @@ void NodeList::sendDSPathQuery(const QString& newPath) {
if (numPathBytes + sizeof(numPathBytes) < pathQueryPacket.size() ) {
// append the size of the path to the query packet
pathQueryPacket.write(&numPathBytes, sizeof(numPathBytes));
pathQueryPacket->write(&numPathBytes, sizeof(numPathBytes));
// append the path itself to the query packet
pathQueryPacket.write(pathQueryUTF8);
pathQueryPacket->write(pathQueryUTF8);
qCDebug(networking) << "Sending a path query packet for path" << newPath << "to domain-server at"
<< _domainHandler.getSockAddr();
// send off the path query
sendPacket(pathQueryPacket, _domainHandler.getSockAddr());
sendPacket(std::move(pathQueryPacket), _domainHandler.getSockAddr());
} else {
qCDebug(networking) << "Path" << newPath << "would make PacketTypeDomainServerPathQuery packet > MAX_PACKET_SIZE." <<
"Will not send query.";
@ -521,10 +521,10 @@ void NodeList::pingPunchForDomainServer() {
// send the ping packet to the local and public sockets for this node
auto localPingPacket = constructICEPingPacket(PingType::Local);
sendPacket(localPingPacket, _domainHandler.getICEPeer().getLocalSocket());
sendPacket(std::move(localPingPacket), _domainHandler.getICEPeer().getLocalSocket());
auto publicPingPacket = constructICEPingPacket(PingType::Public);
sendPacket(publicPingPacket, _domainHandler.getICEPeer().getPublicSocket());
sendPacket(std::move(publicPingPacket), _domainHandler.getICEPeer().getPublicSocket());
_domainHandler.getICEPeer().incrementConnectionAttempts();
}
@ -629,10 +629,10 @@ void NodeList::pingPunchForInactiveNode(const SharedNodePointer& node) {
// send the ping packet to the local and public sockets for this node
auto localPingPacket = constructPingPacket(PingType::Local);
sendPacket(localPingPacket, node, node->getLocalSocket());
sendPacket(std::move(localPingPacket), node, node->getLocalSocket());
auto publicPingPacket = constructPingPacket(PingType::Public);
sendPacket(publicPingPacket, node, node->getPublicSocket());
sendPacket(std::move(publicPingPacket), node, node->getPublicSocket());
if (!node->getSymmetricSocket().isNull()) {
auto symmetricPingPacket = constructPingPacket(PingType::Symmetric);

View file

@ -82,17 +82,23 @@ PacketVersion versionForPacketType(PacketType::Value packetType) {
case DomainList:
case DomainListRequest:
return 5;
case DomainConnectRequest:
return 1;
case CreateAssignment:
case RequestAssignment:
return 2;
case OctreeStats:
return 1;
case OctreeDataNack:
return 1;
case StopNode:
return 1;
case EntityAdd:
case EntityEdit:
case EntityData:
return VERSION_ENTITIES_HAVE_SIMULATION_OWNER_AND_ACTIONS_OVER_WIRE;
case EntityEditNack:
return 1;
case EntityErase:
return 2;
case AudioStreamStats:

View file

@ -11,19 +11,18 @@
#include "PacketList.h"
PacketList::PacketList(PacketType::Value packetType, bool isOrdered) :
_packetType(packetType),
_isOrdered(isOrdered)
PacketList::PacketList(PacketType::Value packetType) :
_packetType(packetType)
{
}
void PacketList::createPacketWithExtendedHeader() {
// use the static create method to create a new packet
_currentPacket = T::create(_packetType);
auto packet = T::create(_packetType);
// add the extended header to the front of the packet
if (_currentPacket.write(_extendedHeader) == -1) {
if (packet->write(_extendedHeader) == -1) {
qDebug() << "Could not write extendedHeader in PacketList::createPacketWithExtendedHeader"
<< "- make sure that _extendedHeader is not larger than the payload capacity.";
}
@ -32,7 +31,7 @@ void PacketList::createPacketWithExtendedHeader() {
qint64 writeData(const char* data, qint64 maxSize) {
if (!_currentPacket) {
// we don't have a current packet, time to set one up
createPacketWithExtendedHeader();
_currentPacket = createPacketWithExtendedHeader();
}
// check if this block of data can fit into the currentPacket
@ -46,7 +45,7 @@ qint64 writeData(const char* data, qint64 maxSize) {
// it does not fit - this may need to be in the next packet
if (!_isOrdered) {
auto newPacket = T::create(_packetType);
auto newPacket = createPacketWithExtendedHeader();
if (_segmentStartIndex >= 0) {
// We in the process of writing a segment for an unordered PacketList.
@ -64,7 +63,7 @@ qint64 writeData(const char* data, qint64 maxSize) {
}
// copy from currentPacket where the segment started to the beginning of the newPacket
newPacket.write(currentPacket.constData() + _segmentStartIndex, numBytesToEnd);
newPacket.write(currentPacket->getPayload() + _segmentStartIndex, numBytesToEnd);
// the current segment now starts at the beginning of the new packet
_segmentStartIndex = 0;
@ -89,7 +88,7 @@ qint64 writeData(const char* data, qint64 maxSize) {
// into a new packet
int numBytesToEnd = _currentPacket.size() - _currentPacket.sizeUsed();
_currentPacket.write(data, numBytesToEnd);
_currentPacket->write(data, numBytesToEnd);
// move the current packet to our list of packets
_packets.insert(std::move(_currentPacket));

View file

@ -18,13 +18,15 @@
template <class T> class PacketList : public QIODevice {
public:
PacketList(PacketType::Value packetType, bool isOrdered = false);
PacketList(PacketType::Value packetType);
virtual bool isSequential() const { return true; }
void startSegment() { _segmentStartIndex = _currentPacket->payload().pos(); }
void endSegment() { _segmentStartIndex = -1; }
int getNumPackets() const { return _packets.size() + (_currentPacket ? 1 : 0); }
void closeCurrentPacket();
void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; }
@ -32,10 +34,10 @@ protected:
qint64 writeData(const char* data, qint64 maxSize);
qint64 readData(const char* data, qint64 maxSize) { return 0; };
private:
void createPacketWithExtendedHeader();
std::unique_ptr<NLPacket> createPacketWithExtendedHeader();
PacketType::Value _packetType;
bool isOrdered;
bool isOrdered = false;
std::unique_ptr<T> _currentPacket;
std::list<std::unique_ptr<T>> _packets;

View file

@ -30,7 +30,7 @@ void SentPacketHistory::packetSent(uint16_t sequenceNumber, const NLPacket& pack
<< "Expected:" << expectedSequenceNumber << "Actual:" << sequenceNumber;
}
_newestSequenceNumber = sequenceNumber;
_sentPackets.insert(new NLPacket(packet));
_sentPackets.insert(NLPacket::createCopy(packet));
}
const QByteArray* SentPacketHistory::getPacket(uint16_t sequenceNumber) const {

View file

@ -23,10 +23,10 @@ public:
SentPacketHistory(int size = MAX_REASONABLE_SEQUENCE_GAP);
void packetSent(uint16_t sequenceNumber, const NLPacket& packet);
const NLPacket* getPacket(uint16_t sequenceNumber) const;
const std::unique_ptr<NLPacket>& getPacket(uint16_t sequenceNumber) const;
private:
RingBufferHistory<NLPacket*> _sentPackets; // circular buffer
RingBufferHistory<std::unique_ptr<NLPacket>> _sentPackets; // circular buffer
uint16_t _newestSequenceNumber;
};

View file

@ -30,7 +30,7 @@ OctreeEditPacketSender::OctreeEditPacketSender() :
_maxPacketSize(MAX_PACKET_SIZE),
_destinationWalletUUID()
{
}
OctreeEditPacketSender::~OctreeEditPacketSender() {
@ -52,10 +52,10 @@ OctreeEditPacketSender::~OctreeEditPacketSender() {
bool OctreeEditPacketSender::serversExist() const {
bool hasServers = false;
bool atLeastOneJurisdictionMissing = false; // assume the best
DependencyManager::get<NodeList>()->eachNodeBreakable([&](const SharedNodePointer& node){
if (node->getType() == getMyNodeType() && node->getActiveSocket()) {
QUuid nodeUUID = node->getUUID();
// If we've got Jurisdictions set, then check to see if we know the jurisdiction for this server
if (_serverJurisdictions) {
@ -69,7 +69,7 @@ bool OctreeEditPacketSender::serversExist() const {
}
hasServers = true;
}
if (atLeastOneJurisdictionMissing) {
return false; // no point in looking further - return false from anonymous function
} else {
@ -91,27 +91,27 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, unsigned c
if (node->getType() == getMyNodeType()
&& ((node->getUUID() == nodeUUID) || (nodeUUID.isNull()))
&& node->getActiveSocket()) {
// pack sequence number
int numBytesPacketHeader = numBytesForPacketHeader(reinterpret_cast<char*>(buffer));
unsigned char* sequenceAt = buffer + numBytesPacketHeader;
quint16 sequence = _outgoingSequenceNumbers[nodeUUID]++;
memcpy(sequenceAt, &sequence, sizeof(quint16));
// send packet
QByteArray packet(reinterpret_cast<const char*>(buffer), length);
queuePacketForSending(node, packet);
if (hasDestinationWalletUUID() && satoshiCost > 0) {
// if we have a destination wallet UUID and a cost associated with this packet, signal that it
// needs to be sent
emit octreePaymentRequired(satoshiCost, nodeUUID, _destinationWalletUUID);
}
// add packet to history
_sentPacketHistories[nodeUUID].packetSent(sequence, packet);
// debugging output...
if (wantDebug) {
int numBytesPacketHeader = numBytesForPacketHeader(reinterpret_cast<const char*>(buffer));
@ -119,7 +119,7 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, unsigned c
quint64 createdAt = (*((quint64*)(buffer + numBytesPacketHeader + sizeof(sequence))));
quint64 queuedAt = usecTimestampNow();
quint64 transitTime = queuedAt - createdAt;
qCDebug(octree) << "OctreeEditPacketSender::queuePacketToNode() queued " << buffer[0] <<
" - command to node bytes=" << length <<
" satoshiCost=" << satoshiCost <<
@ -192,7 +192,7 @@ void OctreeEditPacketSender::queuePacketToNodes(unsigned char* buffer, size_t le
// But we can't really do that with a packed message, since each edit message could be destined
// for a different server... So we need to actually manage multiple queued packets... one
// for each server
DependencyManager::get<NodeList>()->eachNode([&](const SharedNodePointer& node){
// only send to the NodeTypes that are getMyNodeType()
if (node->getActiveSocket() && node->getType() == getMyNodeType()) {
@ -251,7 +251,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType::Value type, unsi
if (node->getActiveSocket() && node->getType() == getMyNodeType()) {
QUuid nodeUUID = node->getUUID();
bool isMyJurisdiction = true;
if (type == PacketTypeEntityErase) {
isMyJurisdiction = true; // send erase messages to all servers
} else if (_serverJurisdictions) {
@ -269,19 +269,19 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType::Value type, unsi
if (isMyJurisdiction) {
EditPacketBuffer& packetBuffer = _pendingEditPackets[nodeUUID];
packetBuffer._nodeUUID = nodeUUID;
// If we're switching type, then we send the last one and start over
if ((type != packetBuffer._currentType && packetBuffer._currentSize > 0) ||
(packetBuffer._currentSize + length >= (size_t)_maxPacketSize)) {
releaseQueuedPacket(packetBuffer);
initializePacket(packetBuffer, type, node->getClockSkewUsec());
}
// If the buffer is empty and not correctly initialized for our type...
if (type != packetBuffer._currentType && packetBuffer._currentSize == 0) {
initializePacket(packetBuffer, type, node->getClockSkewUsec());
}
// This is really the first time we know which server/node this particular edit message
// is going to, so we couldn't adjust for clock skew till now. But here's our chance.
// We call this virtual function that allows our specific type of EditPacketSender to
@ -289,7 +289,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType::Value type, unsi
if (node->getClockSkewUsec() != 0) {
adjustEditPacketForClockSkew(type, editPacketBuffer, length, node->getClockSkewUsec());
}
memcpy(&packetBuffer._currentBuffer[packetBuffer._currentSize], editPacketBuffer, length);
packetBuffer._currentSize += length;
packetBuffer._satoshiCost += satoshiCost;
@ -341,7 +341,7 @@ void OctreeEditPacketSender::initializePacket(EditPacketBuffer& packetBuffer, Pa
packetBuffer._currentSize += sizeof(quint64); // nudge past timestamp
packetBuffer._currentType = type;
// reset cost for packet to 0
packetBuffer._satoshiCost = 0;
}
@ -360,20 +360,22 @@ bool OctreeEditPacketSender::process() {
void OctreeEditPacketSender::processNackPacket(const QByteArray& packet) {
// parse sending node from packet, retrieve packet history for that node
QUuid sendingNodeUUID = uuidFromPacketHeader(packet);
// if packet history doesn't exist for the sender node (somehow), bail
if (!_sentPacketHistories.contains(sendingNodeUUID)) {
return;
}
const SentPacketHistory& sentPacketHistory = _sentPacketHistories.value(sendingNodeUUID);
// TODO: these NAK packets no longer send the number of sequence numbers - just read out sequence numbers in blocks
int numBytesPacketHeader = numBytesForPacketHeader(packet);
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader;
// read number of sequence numbers
uint16_t numSequenceNumbers = (*(uint16_t*)dataAt);
dataAt += sizeof(uint16_t);
// read sequence numbers and queue packets for resend
for (int i = 0; i < numSequenceNumbers; i++) {
unsigned short int sequenceNumber = (*(unsigned short int*)dataAt);