initial response from ice server to nodes

This commit is contained in:
Stephen Birarda 2014-10-02 14:50:48 -07:00
parent 6425276eb0
commit 970ba2296a
7 changed files with 44 additions and 7 deletions

View file

@ -15,6 +15,7 @@
IceServer::IceServer(int argc, char* argv[]) :
QCoreApplication(argc, argv),
_id(QUuid::createUuid()),
_serverSocket()
{
// start the ice-server socket
@ -65,11 +66,22 @@ void IceServer::processDatagrams() {
}
// check if this node also included a UUID that they would like to connect to
QUuid connectRequestUUID;
hearbeatStream >> connectRequestUUID;
QUuid connectRequestID;
hearbeatStream >> connectRequestID;
if (!connectRequestUUID.isNull()) {
qDebug() << "Peer wants to connect to peer with ID" << uuidStringWithoutCurlyBraces(connectRequestUUID);
if (!connectRequestID.isNull()) {
qDebug() << "Peer wants to connect to peer with ID" << uuidStringWithoutCurlyBraces(connectRequestID);
// check if we have that ID - if we do we can respond with their info, otherwise nothing we can do
SharedNetworkPeer matchingConectee = _activePeers.value(connectRequestID);
if (matchingConectee) {
QByteArray heartbeatResponse = byteArrayWithPopulatedHeader(PacketTypeIceServerHeartbeatResponse, _id);
QDataStream responseStream(&heartbeatResponse, QIODevice::Append);
responseStream << matchingConectee;
_serverSocket.writeDatagram(heartbeatResponse, sendingSockAddr.getAddress(), sendingSockAddr.getPort());
}
}
}
}

View file

@ -24,6 +24,7 @@ public:
private slots:
void processDatagrams();
private:
QUuid _id;
QHash<QUuid, SharedNetworkPeer> _activePeers;
QUdpSocket _serverSocket;
};

View file

@ -60,7 +60,7 @@ AccountManager::AccountManager() :
_authURL(),
_pendingCallbackMap(),
_accountInfo(),
_shouldPersistToSettingsFile(false)
_shouldPersistToSettingsFile(true)
{
qRegisterMetaType<OAuthAccessToken>("OAuthAccessToken");
qRegisterMetaTypeStreamOperators<OAuthAccessToken>("OAuthAccessToken");

View file

@ -65,6 +65,22 @@ void NetworkPeer::activateSymmetricSocket() {
_activeSocket = &_symmetricSocket;
}
QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer) {
out << peer._uuid;
out << peer._publicSocket;
out << peer._localSocket;
return out;
}
QDataStream& operator>>(QDataStream& in, NetworkPeer& peer) {
in >> peer._uuid;
in >> peer._publicSocket;
in >> peer._localSocket;
return in;
}
QDebug operator<<(QDebug debug, const NetworkPeer &peer) {
debug << uuidStringWithoutCurlyBraces(peer.getUUID())
<< "- public:" << peer.getPublicSocket()

View file

@ -41,6 +41,8 @@ public:
void activateLocalSocket();
void activateSymmetricSocket();
friend QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer);
friend QDataStream& operator>>(QDataStream& in, NetworkPeer& peer);
protected:
QUuid _uuid;

View file

@ -123,6 +123,10 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr
_domainHandler.parseDTLSRequirementPacket(packet);
break;
}
case PacketTypeIceServerHeartbeatResponse: {
break;
}
case PacketTypePing: {
// send back a reply
SharedNodePointer matchingNode = sendingNodeForPacket(packet);

View file

@ -71,7 +71,8 @@ enum PacketType {
PacketTypeParticleEditNack,
PacketTypeEntityEditNack, // 48
PacketTypeSignedTransactionPayment,
PacketTypeIceServerHeartbeat
PacketTypeIceServerHeartbeat,
PacketTypeIceServerHeartbeatResponse
};
typedef char PacketVersion;
@ -81,7 +82,8 @@ const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>()
<< PacketTypeDomainList << PacketTypeDomainListRequest << PacketTypeDomainOAuthRequest
<< PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse
<< PacketTypeNodeJsonStats << PacketTypeVoxelQuery << PacketTypeParticleQuery << PacketTypeEntityQuery
<< PacketTypeOctreeDataNack << PacketTypeVoxelEditNack << PacketTypeParticleEditNack << PacketTypeEntityEditNack;
<< PacketTypeOctreeDataNack << PacketTypeVoxelEditNack << PacketTypeParticleEditNack << PacketTypeEntityEditNack
<< PacketTypeIceServerHeartbeat << PacketTypeIceServerHeartbeatResponse;
const int NUM_BYTES_MD5_HASH = 16;
const int NUM_STATIC_HEADER_BYTES = sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;