hook up domain request for node to authenticate

This commit is contained in:
Stephen Birarda 2014-02-18 10:54:45 -08:00
parent 4c135dd3a7
commit 7c69028dc5
4 changed files with 134 additions and 109 deletions

View file

@ -175,4 +175,5 @@ void AssignmentClient::assignmentCompleted() {
// reset our NodeList by switching back to unassigned and clearing the list
nodeList->setOwnerType(NodeType::Unassigned);
nodeList->reset();
nodeList->resetNodeInterestSet();
}

View file

@ -70,8 +70,6 @@ DomainServer::DomainServer(int argc, char* argv[]) :
_nodeAuthenticationHostname = argumentList.value(argumentIndex + 1);
}
qDebug() << "the node authentication hostname is" << _nodeAuthenticationHostname;
NodeList* nodeList = NodeList::createInstance(NodeType::DomainServer, domainServerPort);
connect(nodeList, &NodeList::nodeAdded, this, &DomainServer::nodeAdded);
@ -254,12 +252,28 @@ void DomainServer::readAvailableDatagrams() {
PacketType requestType = packetTypeForPacket(receivedPacket);
if (requestType == PacketTypeDomainListRequest) {
// this is an RFD or domain list request packet, and there is a version match
QUuid nodeUUID = uuidFromPacketHeader(receivedPacket);
if (!_nodeAuthenticationHostname.isEmpty() &&
(nodeUUID.isNull() || !nodeList->nodeWithUUID(nodeUUID))) {
// this is a node we do not recognize and we need authentication - ask them to do so
// by providing them the hostname they should authenticate with
QByteArray authenticationRequestPacket = byteArrayWithPopluatedHeader(PacketTypeDomainServerAuthRequest);
QDataStream authPacketStream(&authenticationRequestPacket, QIODevice::Append);
authPacketStream << _nodeAuthenticationHostname;
qDebug() << "Asking node at" << senderSockAddr << "to authenticate.";
// send the authentication request back to the node
nodeList->getNodeSocket().writeDatagram(authenticationRequestPacket,
senderSockAddr.getAddress(), senderSockAddr.getPort());
} else {
// this is an RFD or domain list request packet, and there is a match
QDataStream packetStream(receivedPacket);
packetStream.skipRawData(numBytesForPacketHeader(receivedPacket));
QUuid nodeUUID = uuidFromPacketHeader(receivedPacket);
packetStream >> nodeType;
packetStream >> nodePublicAddress >> nodeLocalAddress;
@ -357,6 +371,7 @@ void DomainServer::readAvailableDatagrams() {
nodeList->getNodeSocket().writeDatagram(broadcastPacket,
senderSockAddr.getAddress(), senderSockAddr.getPort());
}
}
} else if (requestType == PacketTypeRequestAssignment) {
// construct the requested assignment from the packet data

View file

@ -68,11 +68,9 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
{
_nodeSocket.bind(QHostAddress::AnyIPv4, newSocketListenPort);
qDebug() << "NodeList socket is listening on" << _nodeSocket.localPort();
}
NodeList::~NodeList() {
clear();
// clear our NodeList when the domain changes
connect(&_domainInfo, &DomainInfo::hostnameChanged, this, &NodeList::reset);
}
bool NodeList::packetVersionAndHashMatch(const QByteArray& packet) {
@ -87,7 +85,8 @@ bool NodeList::packetVersionAndHashMatch(const QByteArray& packet) {
}
const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>() << PacketTypeDomainList
<< PacketTypeDomainListRequest << PacketTypeStunResponse << PacketTypeDataServerConfirm
<< PacketTypeDomainListRequest << PacketTypeDomainServerAuthRequest
<< PacketTypeStunResponse << PacketTypeDataServerConfirm
<< PacketTypeDataServerGet << PacketTypeDataServerPut << PacketTypeDataServerSend
<< PacketTypeCreateAssignment << PacketTypeRequestAssignment;
@ -196,6 +195,18 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr
break;
}
case PacketTypeDomainServerAuthRequest: {
// the domain-server has asked us to auth via a data-server
QDataStream authPacketStream(packet);
authPacketStream.skipRawData(numBytesForPacketHeader(packet));
QString authenticationHostname;
authPacketStream >> authenticationHostname;
qDebug() << "Domain server wants us to auth with" << authenticationHostname;
break;
}
case PacketTypePing: {
// send back a reply
SharedNodePointer matchingNode = sendingNodeForPacket(packet);
@ -288,10 +299,8 @@ void NodeList::reset() {
clear();
_numNoReplyDomainCheckIns = 0;
_nodeTypesOfInterest.clear();
// refresh the owner UUID
_sessionUUID = QUuid::createUuid();
// refresh the owner UUID to the NULL UUID
_sessionUUID = QUuid();
}
void NodeList::addNodeTypeToInterestSet(NodeType_t nodeTypeToAdd) {

View file

@ -88,11 +88,10 @@ public:
int getNumNoReplyDomainCheckIns() const { return _numNoReplyDomainCheckIns; }
DomainInfo& getDomainInfo() { return _domainInfo; }
void reset();
const NodeSet& getNodeInterestSet() const { return _nodeTypesOfInterest; }
void addNodeTypeToInterestSet(NodeType_t nodeTypeToAdd);
void addSetOfNodeTypesToNodeInterestSet(const NodeSet& setOfNodeTypes);
void resetNodeInterestSet() { _nodeTypesOfInterest.clear(); }
int processDomainServerList(const QByteArray& packet);
@ -121,6 +120,8 @@ public:
void loadData(QSettings* settings);
void saveData(QSettings* settings);
public slots:
void reset();
void sendDomainServerCheckIn();
void pingInactiveNodes();
void removeSilentNodes();
@ -130,21 +131,23 @@ signals:
void uuidChanged(const QUuid& ownerUUID);
void nodeAdded(SharedNodePointer);
void nodeKilled(SharedNodePointer);
private:
static NodeList* _sharedInstance;
NodeList(char ownerType, unsigned short int socketListenPort);
~NodeList();
NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
void sendSTUNRequest();
void processSTUNResponse(const QByteArray& packet);
qint64 NodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr,
qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr,
const QUuid& connectionSecret);
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
void clear();
NodeHash _nodeHash;
QMutex _nodeHashMutex;
QUdpSocket _nodeSocket;
@ -160,9 +163,6 @@ private:
void activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode);
void timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode);
void resetDomainData(char domainField[], const char* domainData);
void domainLookup();
void clear();
};
#endif /* defined(__hifi__NodeList__) */