From b6925edbe8d52fba1899ba25795d8470f75a3a34 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 13 May 2013 17:34:34 -0700 Subject: [PATCH 1/2] add a PairingHandler to send pair requests to the pairing server --- interface/src/Application.cpp | 8 ++++-- interface/src/Application.h | 4 +-- interface/src/PairingHandler.cpp | 48 ++++++++++++++++++++++++++++++++ interface/src/PairingHandler.h | 19 +++++++++++++ 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 interface/src/PairingHandler.cpp create mode 100644 interface/src/PairingHandler.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ff6c80d456..1def8e4b2e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "Application.h" @@ -14,9 +15,10 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) { // simple menu bar (will only appear on OS X, for now) QMenuBar* menuBar = new QMenuBar(); QMenu* fileMenu = menuBar->addMenu("File"); - fileMenu->addAction("Test", this, SLOT(testSlot())); + + fileMenu->addAction("Pair", this, SLOT(pair())); } -void Application::testSlot() { - qDebug() << "Hello world."; +void Application::pair() { + PairingHandler::sendPairRequest(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index c47dc3e33a..0aab27329e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -15,12 +15,10 @@ class Application : public QApplication { Q_OBJECT public: - Application(int& argc, char** argv); public slots: - - void testSlot(); + void pair(); }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/PairingHandler.cpp b/interface/src/PairingHandler.cpp new file mode 100644 index 0000000000..8a3b049807 --- /dev/null +++ b/interface/src/PairingHandler.cpp @@ -0,0 +1,48 @@ +// +// PairingHandler.cpp +// hifi +// +// Created by Stephen Birarda on 5/13/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#include + +#include + +#include "PairingHandler.h" + +const char PAIRING_SERVER_HOSTNAME[] = "pairing.highfidelity.io"; +const int PAIRING_SERVER_PORT = 7247; + +void PairingHandler::sendPairRequest() { + // grab the agent socket from the AgentList singleton + UDPSocket *agentSocket = &AgentList::getInstance()->getAgentSocket(); + + // prepare the pairing request packet + + // use the getLocalAddress helper to get this client's listening address + int localAddress = getLocalAddress(); + + char pairPacket[24] = {}; + sprintf(pairPacket, "Find %d.%d.%d.%d:%d", + localAddress & 0xFF, + (localAddress >> 8) & 0xFF, + (localAddress >> 16) & 0xFF, + (localAddress >> 24) & 0xFF, + AGENT_SOCKET_LISTEN_PORT); + + sockaddr_in pairingServerSocket; + + pairingServerSocket.sin_family = AF_INET; + + // lookup the pairing server IP by the hostname + struct hostent* hostInfo = gethostbyname(PAIRING_SERVER_HOSTNAME); + memcpy(&pairingServerSocket.sin_addr, hostInfo->h_addr_list[0], hostInfo->h_length); + pairingServerSocket.sin_port = htons(PAIRING_SERVER_PORT); + + printf("Sending a pair request to %s on port %d\n", inet_ntoa(pairingServerSocket.sin_addr), ntohs(pairingServerSocket.sin_port)); + + // send the pair request to the pairing server + agentSocket->send((sockaddr*) &pairingServerSocket, pairPacket, strlen(pairPacket)); +} diff --git a/interface/src/PairingHandler.h b/interface/src/PairingHandler.h new file mode 100644 index 0000000000..d201465898 --- /dev/null +++ b/interface/src/PairingHandler.h @@ -0,0 +1,19 @@ +// +// PairingHandler.h +// hifi +// +// Created by Stephen Birarda on 5/13/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __hifi__PairingHandler__ +#define __hifi__PairingHandler__ + +#include + +class PairingHandler { +public: + static void sendPairRequest(); +}; + +#endif /* defined(__hifi__PairingHandler__) */ From a01b35f04170e9e93b62288599780280cde640b2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 13 May 2013 18:16:59 -0700 Subject: [PATCH 2/2] remove extra debugging --- interface/src/PairingHandler.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/PairingHandler.cpp b/interface/src/PairingHandler.cpp index 8a3b049807..63f208c308 100644 --- a/interface/src/PairingHandler.cpp +++ b/interface/src/PairingHandler.cpp @@ -41,8 +41,6 @@ void PairingHandler::sendPairRequest() { memcpy(&pairingServerSocket.sin_addr, hostInfo->h_addr_list[0], hostInfo->h_length); pairingServerSocket.sin_port = htons(PAIRING_SERVER_PORT); - printf("Sending a pair request to %s on port %d\n", inet_ntoa(pairingServerSocket.sin_addr), ntohs(pairingServerSocket.sin_port)); - // send the pair request to the pairing server agentSocket->send((sockaddr*) &pairingServerSocket, pairPacket, strlen(pairPacket)); }