Skip to content

Commit

Permalink
discovery packet format changed
Browse files Browse the repository at this point in the history
  • Loading branch information
corybolar committed Dec 11, 2016
1 parent 79c5714 commit cbd06f9
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 185 deletions.
8 changes: 5 additions & 3 deletions src/PXMessenger.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = PXMessenger
VERSION = 1.2.0
VERSION = 1.2.1
QMAKE_TARGET_COMPANY = Bolar Code Solutions
QMAKE_TARGET_PRODUCT = PXMessenger
QMAKE_TARGET_DESCRIPTION = Instant Messenger
Expand Down Expand Up @@ -37,7 +37,8 @@ SOURCES += \
pxmessenger.cpp \
pxmdebugwindow.cpp \
pxmsettingsdialog.cpp \
pxmtextbrowser.cpp
pxmtextbrowser.cpp \
uuidcompression.cpp

HEADERS += \
pxmdefinitions.h \
Expand All @@ -50,7 +51,8 @@ HEADERS += \
pxmserver.h \
pxmclient.h \
pxmdebugwindow.h \
pxmtextbrowser.h
pxmtextbrowser.h \
uuidcompression.h

DISTFILES +=

Expand Down
30 changes: 5 additions & 25 deletions src/pxmclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ void PXMClient::connectToPeer(evutil_socket_t, sockaddr_in socketAddr, buffereve

void PXMClient::sendMsg(BevWrapper *bw, const char *msg, size_t msgLen, PXMConsts::MESSAGE_TYPE type, QUuid uuidSender, QUuid uuidReceiver)
{
using PXMConsts::MSG;
int bytesSent = 0;
int packetLen;
uint16_t packetLenNBO;
Expand All @@ -77,9 +76,9 @@ void PXMClient::sendMsg(BevWrapper *bw, const char *msg, size_t msgLen, PXMConst
emit resultOfTCPSend(-1, uuidReceiver, QString("Message too Long!"), print, bw);
return;
}
packetLen = PXMConsts::PACKED_UUID_BYTE_LENGTH + sizeof(uint8_t) + msgLen;
packetLen = UUIDCompression::PACKED_UUID_BYTE_LENGTH + sizeof(uint8_t) + msgLen;

if(type == MSG)
if(type == PXMConsts::MSG_TEXT)
{
print = true;
}
Expand All @@ -88,9 +87,9 @@ void PXMClient::sendMsg(BevWrapper *bw, const char *msg, size_t msgLen, PXMConst

packetLenNBO = htons(packetLen);

packUuid(full_mess, &uuidSender);
memcpy(full_mess+PXMConsts::PACKED_UUID_BYTE_LENGTH, &type, sizeof(uint8_t));
memcpy(full_mess+PXMConsts::PACKED_UUID_BYTE_LENGTH+sizeof(uint8_t), msg, msgLen);
UUIDCompression::packUUID(full_mess, &uuidSender);
memcpy(full_mess+UUIDCompression::PACKED_UUID_BYTE_LENGTH, &type, sizeof(uint8_t));
memcpy(full_mess+UUIDCompression::PACKED_UUID_BYTE_LENGTH+sizeof(uint8_t), msg, msgLen);
full_mess[packetLen] = 0;

bw->lockBev();
Expand Down Expand Up @@ -119,25 +118,6 @@ void PXMClient::sendMsgSlot(BevWrapper *bw, QByteArray msg, PXMConsts::MESSAGE_T
{
this->sendMsg(bw, msg.constData(), msg.length(), type, uuid, theiruuid);
}
size_t PXMClient::packUuid(char *buf, QUuid *uuid)
{
int index = 0;

uint32_t uuidSectionL = htonl(uuid->data1);
memcpy(&buf[index], &(uuidSectionL), sizeof(uint32_t));
index += sizeof(uint32_t);
uint16_t uuidSectionS = htons(uuid->data2);
memcpy(&buf[index], &(uuidSectionS), sizeof(uint16_t));
index += sizeof(uint16_t);
uuidSectionS = htons(uuid->data3);
memcpy(&buf[index], &(uuidSectionS), sizeof(uint16_t));
index += sizeof(uint16_t);
unsigned char *uuidSectionC = uuid->data4;
memcpy(&buf[index], uuidSectionC, 8);
index += 8;

return index;
}

void PXMClient::sendIpsSlot(BevWrapper *bw, char *msg, size_t len, PXMConsts::MESSAGE_TYPE type, QUuid uuid, QUuid theiruuid)
{
Expand Down
4 changes: 2 additions & 2 deletions src/pxmclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <event2/buffer.h>

#include "pxmdefinitions.h"
#include "uuidcompression.h"

#ifdef _WIN32
#include <winsock2.h>
Expand All @@ -36,7 +37,6 @@ class PXMClient : public QObject
public:
PXMClient(QObject *parent, in_addr multicast);
~PXMClient() {qDebug() << "Shutdown of PXMClient Successful";}
static size_t packUuid(char *buf, QUuid *uuid);
public slots:
void sendMsg(BevWrapper *bw, const char *msg, size_t msgLen, PXMConsts::MESSAGE_TYPE type, QUuid uuidSender, QUuid uuidReceiver);
/*!
Expand All @@ -61,7 +61,7 @@ public slots:
* \param msg Message to send
* \param port Port to send to in the multicast group
*/
int sendUDP(const char *msg, unsigned short port);
int sendUDP(const char* msg, unsigned short port);
/*!
* \brief connectToPeer
*
Expand Down
43 changes: 22 additions & 21 deletions src/pxmdefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Q_DECLARE_METATYPE(bufferevent*);

namespace PXMConsts {
const int BACKLOG = 200;
const char* const DEFAULT_MULTICAST_ADDRESS = "239.192.13.13";
const size_t PACKED_UUID_BYTE_LENGTH = 16;
const char * const DEFAULT_MULTICAST_ADDRESS = "239.192.13.13";
const int MESSAGE_HISTORY_LENGTH = 500;
const int MIDNIGHT_TIMER_INTERVAL_MINUTES = 1;
#ifdef QT_DEBUG
Expand All @@ -33,8 +32,9 @@ const int DEBUG_PADDING = 0;
const unsigned short DEFAULT_UDP_PORT = 53273;
const int TEXT_EDIT_MAX_LENGTH = 2000;
const int MAX_HOSTNAME_LENGTH = 24;
enum MESSAGE_TYPE : uint8_t {UUID = 1, MSG, SYNC, SYNC_REQUEST, GLOBAL};
enum MESSAGE_TYPE : const uint8_t {MSG_UUID = 1, MSG_TEXT, MSG_SYNC, MSG_SYNC_REQUEST, MSG_GLOBAL, MSG_DISCOVER = 48, MSG_INFO};
}
Q_DECLARE_METATYPE(PXMConsts::MESSAGE_TYPE);

class BevWrapper {
public:
Expand All @@ -51,46 +51,47 @@ class BevWrapper {
};

struct peerDetails{
bool isConnected;
bool isAuthenticated;
evutil_socket_t socketDescriptor;
QUuid identifier;
sockaddr_in ipAddressRaw;
QString hostname;
QLinkedList<QString*> messages;
QUuid identifier;
BevWrapper *bw;
evutil_socket_t socketDescriptor;
bool isConnected;
bool isAuthenticated;
peerDetails()
{
isConnected = false;
isAuthenticated = false;
socketDescriptor = -1;
identifier = QUuid();
memset(&ipAddressRaw, 0, sizeof(sockaddr_in));
messages = QLinkedList<QString*>();
hostname = QString();
identifier = QUuid();
messages = QLinkedList<QString*>();
bw = new BevWrapper();
socketDescriptor = -1;
isConnected = false;
isAuthenticated = false;
}
peerDetails(bool iC, bool iA, evutil_socket_t sD,
sockaddr_in iAR, QString h, QLinkedList<QString*> m,
QUuid iD, BevWrapper *bw)
{
isConnected = iC;
isAuthenticated = iA;
socketDescriptor = sD;
identifier = iD;
ipAddressRaw = iAR;
hostname = h;
messages = m;
identifier = iD;
this->bw = bw;
socketDescriptor = sD;
isConnected = iC;
isAuthenticated = iA;
}
peerDetails(const peerDetails& p) : isConnected(p.isConnected),
isAuthenticated(p.isAuthenticated),
socketDescriptor(p.socketDescriptor),
peerDetails(const peerDetails& p) :
identifier(p.identifier),
ipAddressRaw(p.ipAddressRaw),
hostname(p.hostname),
messages(p.messages),
identifier(p.identifier),
bw(p.bw) {}
bw(p.bw),
socketDescriptor(p.socketDescriptor),
isConnected(p.isConnected),
isAuthenticated(p.isAuthenticated) {}
};
struct initialSettings{
int uuidNum;
Expand Down
4 changes: 3 additions & 1 deletion src/pxmessenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int main(int argc, char **argv)
qRegisterMetaType<sockaddr_in>();
qRegisterMetaType<size_t>("size_t");
qRegisterMetaType<bufferevent*>();
qRegisterMetaType<PXMConsts::MESSAGE_TYPE>();

#ifdef QT_DEBUG
qDebug() << "Running in debug mode";
Expand All @@ -86,7 +87,7 @@ int main(int argc, char **argv)
QApplication::setApplicationName("PXMessenger");
QApplication::setOrganizationName("PXMessenger");
QApplication::setOrganizationDomain("PXMessenger");
QApplication::setApplicationVersion("1.2.0");
QApplication::setApplicationVersion("1.2.1");

MessIniReader iniReader;
initialSettings presets;
Expand Down Expand Up @@ -144,6 +145,7 @@ int main(int argc, char **argv)
presets.windowSize = iniReader.getWindowSize(QSize(700, 500));
presets.mute = iniReader.getMute();
presets.preventFocus = iniReader.getFocus();
presets.multicast = iniReader.getMulticastAddress();

PXMWindow *window = new PXMWindow(presets);
window->startThreadsAndShow();
Expand Down
5 changes: 3 additions & 2 deletions src/pxminireader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,15 @@ QString MessIniReader::getMulticastAddress()
{
return QString("");
}
return ipFull;
/*
QStringList ipList = ipFull.split(".");
for(int i = 0; i < 4; i++)
{
if(ipList[i].toUInt() > 255)
ipList[i] = "0";
}

return ipList.join("");
*/
}
int MessIniReader::setMulticastAddress(QStringList ip)
{
Expand Down
16 changes: 10 additions & 6 deletions src/pxmmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void PXMWindow::changeEvent(QEvent *event)
{
if(event->type() == QEvent::WindowStateChange)
{
if(isMinimized())
if(this->isMinimized())
{
this->hide();
event->ignore();
Expand Down Expand Up @@ -513,11 +513,11 @@ int PXMWindow::sendButtonClicked()

if( ( uuidOfSelectedItem == globalChatUuid) )
{
emit sendMsg(msg, PXMConsts::GLOBAL, ourUUID, QUuid());
emit sendMsg(msg, PXMConsts::MSG_GLOBAL, ourUUID, QUuid());
}
else
{
emit sendMsg(msg, PXMConsts::MSG, ourUUID, uuidOfSelectedItem);
emit sendMsg(msg, PXMConsts::MSG_TEXT, ourUUID, uuidOfSelectedItem);
}
messTextEdit->setText("");
}
Expand Down Expand Up @@ -551,12 +551,16 @@ int PXMWindow::focusWindow()
{
qApp->alert(this, 0);
}
else if(this->isMinimized() && !(focusCheckBox->isChecked()))
else if(this->isMinimized())
{
if(!this->focusCheckBox->isChecked())
{
this->setWindowState(Qt::WindowActive);
}
else
this->setWindowState(Qt::WindowNoState);
this->show();
qApp->alert(this, 0);
this->raise();
this->setWindowState(Qt::WindowActive);
}
return 0;
}
Expand Down
Loading

0 comments on commit cbd06f9

Please sign in to comment.