diff options
author | Thorvald Natvig <slicer@users.sourceforge.net> | 2009-05-15 19:24:27 +0400 |
---|---|---|
committer | Thorvald Natvig <slicer@users.sourceforge.net> | 2009-05-15 19:24:27 +0400 |
commit | a98d45a39312f28e9ec5ec5397f025f58a8d12c1 (patch) | |
tree | ebd63a339b9e796147b6a13b5d4dcdcb191da09e /src | |
parent | 9f7ef74e4a3ba022e0cb634d081f4cb460f64ead (diff) |
Faster quint64 based netaddress handling
Diffstat (limited to 'src')
-rw-r--r-- | src/Connection.cpp | 68 | ||||
-rw-r--r-- | src/Connection.h | 23 | ||||
-rw-r--r-- | src/CryptState.cpp | 12 | ||||
-rw-r--r-- | src/Net.cpp | 130 | ||||
-rw-r--r-- | src/Net.h | 89 | ||||
-rw-r--r-- | src/mumble/BanEditor.cpp | 8 | ||||
-rw-r--r-- | src/mumble/BanEditor.h | 13 | ||||
-rw-r--r-- | src/mumble/mumble.pro | 4 | ||||
-rw-r--r-- | src/murmur/DBus.cpp | 9 | ||||
-rw-r--r-- | src/murmur/Messages.cpp | 14 | ||||
-rw-r--r-- | src/murmur/MurmurIce.cpp | 8 | ||||
-rw-r--r-- | src/murmur/Server.cpp | 34 | ||||
-rw-r--r-- | src/murmur/Server.h | 14 | ||||
-rw-r--r-- | src/murmur/ServerDB.cpp | 15 | ||||
-rw-r--r-- | src/murmur/murmur.pro | 4 |
15 files changed, 250 insertions, 195 deletions
diff --git a/src/Connection.cpp b/src/Connection.cpp index 2567010d8..89a8b5ee6 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -42,74 +42,6 @@ HANDLE Connection::hQoS = NULL; #endif -HostAddress::HostAddress() { - addr[0] = addr[1] = 0ULL; -} - -HostAddress::HostAddress(const Q_IPV6ADDR &address) { - for(int i=0;i<16;++i) - qip6[i] = address[i]; -} - -HostAddress::HostAddress(const std::string &address) { - if (address.length() != 16) - addr[0] = addr[1] = 0ULL; - else - for(int i=0;i<16;++i) - qip6[i] = address[i]; -} - -HostAddress::HostAddress(const QHostAddress &address) { - if (address.protocol() == QAbstractSocket::IPv6Protocol) - *this = HostAddress(address.toIPv6Address()); - else { - quint32 a = htonl(address.toIPv4Address()); - const unsigned char *ptr = reinterpret_cast<const unsigned char *>(&a); - - for (int i=0;i<10;++i) - qip6[i] = 0; - qip6[10] = 0xff; - qip6[11] = 0xff; - qip6[12] = ptr[0]; - qip6[13] = ptr[1]; - qip6[14] = ptr[2]; - qip6[15] = ptr[3]; - } -} - -bool HostAddress::operator < (const HostAddress &other) const { - return memcmp(qip6.c, other.qip6.c, 16) < 0; -} - -bool HostAddress::operator == (const HostAddress &other) const { - return ((addr[0] == other.addr[0]) && (addr[1] == other.addr[1])); -} - -std::string HostAddress::toStdString() const { - return std::string(reinterpret_cast<const char *>(qip6.c), 16); -} - -bool HostAddress::isV6() const { - bool isv4 = true; - for(int i=0;i<10;++i) - isv4 = isv4 && (qip6[i] == 0); - isv4 = isv4 && (qip6[10] == 0xff) && (qip6[11] == 0xff); - return !isv4; -} - -QHostAddress HostAddress::toAddress() const { - if (isV6()) - return QHostAddress(qip6); - else { - quint32 a = (qip6[12] << 24) | (qip6[13] << 16) | (qip6[14] << 8) | qip6[15] ; - return QHostAddress(a); - } -} - -quint32 qHash(const HostAddress &ha) { - return (ha.hash[0] ^ ha.hash[1] ^ ha.hash[2] ^ ha.hash[3]); -} - Connection::Connection(QObject *p, QSslSocket *qtsSock) : QObject(p) { qtsSocket = qtsSock; qtsSocket->setParent(this); diff --git a/src/Connection.h b/src/Connection.h index 39a5c2dfc..9727cd5f8 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -35,29 +35,6 @@ #include "CryptState.h" #include "Mumble.pb.h" -struct HostAddress { - union { - Q_IPV6ADDR qip6; - quint32 hash[4]; - quint64 addr[2]; - }; - - HostAddress(); - HostAddress(const Q_IPV6ADDR &); - HostAddress(const std::string &); - HostAddress(const QHostAddress &); - - bool isV6() const; - - bool operator < (const HostAddress &) const; - bool operator == (const HostAddress &) const; - - std::string toStdString() const; - QHostAddress toAddress() const; -}; - -quint32 qHash(const HostAddress &); - class Connection : public QObject { private: Q_OBJECT diff --git a/src/CryptState.cpp b/src/CryptState.cpp index cf88a7d34..476d849c5 100644 --- a/src/CryptState.cpp +++ b/src/CryptState.cpp @@ -38,6 +38,7 @@ */ #include "CryptState.h" +#include "Net.h" CryptState::CryptState() { for (int i=0;i<0x100;i++) @@ -187,15 +188,8 @@ bool CryptState::decrypt(const unsigned char *source, unsigned char *dst, unsign #define SHIFTBITS 63 typedef quint64 subblock; -#if __BYTE_ORDER == __BIG_ENDIAN -#define SWAPPED(x) (x) -#else -#ifdef __x86_64__ -#define SWAPPED(x) ({register quint64 __out, __in = (x); __asm__("bswap %q0" : "=r"(__out) : "0"(__in)); __out;}) -#else -#define SWAPPED(x) qbswap<quint64>(x) -#endif -#endif +#define SWAPPED(x) SWAP64(x) + #else #define BLOCKSIZE 4 #define SHIFTBITS 31 diff --git a/src/Net.cpp b/src/Net.cpp new file mode 100644 index 000000000..ac27eb6ba --- /dev/null +++ b/src/Net.cpp @@ -0,0 +1,130 @@ +/* Copyright (C) 2005-2009, Thorvald Natvig <thorvald@natvig.com> + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + - Neither the name of the Mumble Developers nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "Net.h" + +HostAddress::HostAddress() { + addr[0] = addr[1] = 0ULL; +} + +HostAddress::HostAddress(const Q_IPV6ADDR &address) { + memcpy(qip6.c, address.c, 16); +} + +HostAddress::HostAddress(const std::string &address) { + if (address.length() != 16) + addr[0] = addr[1] = 0ULL; + else + for(int i=0;i<16;++i) + qip6[i] = address[i]; +} + +HostAddress::HostAddress(const QByteArray &address) { + if (address.length() != 16) + addr[0] = addr[1] = 0ULL; + else + for(int i=0;i<16;++i) + qip6[i] = address[i]; +} + +HostAddress::HostAddress(const QHostAddress &address) { + if (address.protocol() == QAbstractSocket::IPv6Protocol) { + const Q_IPV6ADDR &a = address.toIPv6Address(); + memcpy(qip6.c, a.c, 16); + } else { + addr[0] = 0ULL; + shorts[4] = 0; + shorts[5] = 0xffff; + hash[3] = htonl(address.toIPv4Address()); + } +} + +bool HostAddress::operator < (const HostAddress &other) const { + return memcmp(qip6.c, other.qip6.c, 16) < 0; +} + +bool HostAddress::operator == (const HostAddress &other) const { + return ((addr[0] == other.addr[0]) && (addr[1] == other.addr[1])); +} + +bool HostAddress::match(const HostAddress &netmask, int bits) const { + quint64 mask[2]; + + if (bits == 128) { + mask[0] = mask[1] = 0xffffffffffffffffULL; + } else if (bits > 64) { + mask[0] = 0xffffffffffffffffULL; + mask[1] = SWAP64(~((1ULL << (128-bits)) - 1)); + } else { + mask[0] = SWAP64(~((1ULL << (64-bits)) - 1)); + mask[1] = 0ULL; + } + return ((addr[0] & mask[0]) == (netmask.addr[0] & mask[0])) && ((addr[1] & mask[1]) == (netmask.addr[1] & mask[1])); +} + +std::string HostAddress::toStdString() const { + return std::string(reinterpret_cast<const char *>(qip6.c), 16); +} + +bool HostAddress::isV6() const { + return (addr[0] != 0ULL) || (shorts[4] != 0) || (shorts[5] != 0xffff); +} + +bool HostAddress::isValid() const { + return (addr[0] != 0ULL) || (addr[1] != 0ULL); +} + +QHostAddress HostAddress::toAddress() const { + if (isV6()) + return QHostAddress(qip6); + else { + return QHostAddress(ntohl(hash[3])); + } +} + +QByteArray HostAddress::toByteArray() const { + return QByteArray(reinterpret_cast<const char *>(qip6.c), 16); +} + +quint32 qHash(const HostAddress &ha) { + return (ha.hash[0] ^ ha.hash[1] ^ ha.hash[2] ^ ha.hash[3]); +} + +bool Ban::operator <(const Ban &other) const { + return haAddress < other.haAddress; +} + +bool Ban::operator ==(const Ban &other) const { + return (haAddress == other.haAddress) && (qsUsername == other.qsUsername) && (qsHash == other.qsHash) && (qsReason == other.qsReason) && (qdtStart == other.qdtStart) && (iDuration == other.iDuration); +} + +bool Ban::isValid() const { + return haAddress.isValid() && (iMask >= 8) && (iMask <= 128); +} diff --git a/src/Net.h b/src/Net.h new file mode 100644 index 000000000..c878f0c68 --- /dev/null +++ b/src/Net.h @@ -0,0 +1,89 @@ +/* Copyright (C) 2005-2009, Thorvald Natvig <thorvald@natvig.com> + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + - Neither the name of the Mumble Developers nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _NET_H +#define _NET_H + +#include "murmur_pch.h" + +struct HostAddress { + union { + Q_IPV6ADDR qip6; + quint16 shorts[8]; + quint32 hash[4]; + quint64 addr[2]; + }; + + HostAddress(); + HostAddress(const Q_IPV6ADDR &); + HostAddress(const std::string &); + HostAddress(const QHostAddress &); + HostAddress(const QByteArray &); + + bool isV6() const; + bool isValid() const; + + bool operator < (const HostAddress &) const; + bool operator == (const HostAddress &) const; + + bool match(const HostAddress &, int) const; + + std::string toStdString() const; + QHostAddress toAddress() const; + QByteArray toByteArray() const; +}; + +quint32 qHash(const HostAddress &); + +struct Ban { + HostAddress haAddress; + int iMask; + QString qsUsername; + QString qsHash; + QString qsReason; + QDateTime qdtStart; + unsigned int iDuration; + bool isExpired() const; + bool isValid() const; + bool operator < (const Ban &) const; + bool operator == (const Ban &) const; +}; + +#if __BYTE_ORDER == __BIG_ENDIAN +#define SWAP64(x) (x) +#else +#ifdef __x86_64__ +#define SWAP64(x) ({register quint64 __out, __in = (x); __asm__("bswap %q0" : "=r"(__out) : "0"(__in)); __out;}) +#else +#define SWAP64(x) qbswap<quint64>(x) +#endif +#endif + +#endif diff --git a/src/mumble/BanEditor.cpp b/src/mumble/BanEditor.cpp index b656aeddb..7bc083c3c 100644 --- a/src/mumble/BanEditor.cpp +++ b/src/mumble/BanEditor.cpp @@ -33,14 +33,6 @@ #include "Channel.h" #include "Global.h" -bool Ban::operator <(const Ban &other) const { - return haAddress < other.haAddress; -} - -bool Ban::operator ==(const Ban &other) const { - return (haAddress == other.haAddress) && (qsUsername == other.qsUsername) && (qsHash == other.qsHash) && (qsReason == other.qsReason) && (qdtStart == other.qdtStart) && (iDuration == other.iDuration); -} - BanEditor::BanEditor(const MumbleProto::BanList &msg, QWidget *p) : QDialog(p) { setupUi(this); diff --git a/src/mumble/BanEditor.h b/src/mumble/BanEditor.h index 4a13a5069..c30f05cf3 100644 --- a/src/mumble/BanEditor.h +++ b/src/mumble/BanEditor.h @@ -34,18 +34,7 @@ #include "mumble_pch.hpp" #include "ui_BanEditor.h" #include "Message.h" - -struct Ban { - HostAddress haAddress; - int iMask; - QString qsUsername; - QString qsHash; - QString qsReason; - QDateTime qdtStart; - unsigned int iDuration; - bool operator < (const Ban &) const; - bool operator == (const Ban &) const; -}; +#include "Net.h" class BanEditor : public QDialog, public Ui::BanEditor { private: diff --git a/src/mumble/mumble.pro b/src/mumble/mumble.pro index 7a78ce649..b9c705513 100644 --- a/src/mumble/mumble.pro +++ b/src/mumble/mumble.pro @@ -5,8 +5,8 @@ QT *= network sql opengl xml TARGET = mumble HEADERS *= BanEditor.h ACLEditor.h Log.h AudioConfigDialog.h AudioStats.h AudioInput.h AudioOutput.h MainWindow.h ServerHandler.h About.h ConnectDialog.h GlobalShortcut.h TextToSpeech.h Settings.h Database.h VersionCheck.h Global.h UserModel.h Audio.h ConfigDialog.h Plugins.h LookConfig.h Overlay.h AudioWizard.h ViewCert.h TextMessage.h NetworkConfig.h LCD.h Usage.h Cert.h ClientUser.h SOURCES *= BanEditor.cpp ACLEditor.cpp Log.cpp AudioConfigDialog.cpp AudioStats.cpp AudioInput.cpp AudioOutput.cpp main.cpp MainWindow.cpp ServerHandler.cpp About.cpp ConnectDialog.cpp Settings.cpp Database.cpp VersionCheck.cpp Global.cpp UserModel.cpp Audio.cpp ConfigDialog.cpp Plugins.cpp LookConfig.cpp Overlay.cpp AudioWizard.cpp ViewCert.cpp Messages.cpp TextMessage.cpp GlobalShortcut.cpp NetworkConfig.cpp LCD.cpp Usage.cpp Cert.cpp ClientUser.cpp -HEADERS *= ../ACL.h ../Group.h ../Channel.h ../Connection.h ../User.h -SOURCES *= ../ACL.cpp ../Group.cpp ../Channel.cpp ../Connection.cpp ../User.cpp ../Timer.cpp ../CryptState.cpp ../OSInfo.cpp +HEADERS *= ../ACL.h ../Group.h ../Channel.h ../Connection.h ../User.h ../Net.h +SOURCES *= ../ACL.cpp ../Group.cpp ../Channel.cpp ../Connection.cpp ../User.cpp ../Timer.cpp ../CryptState.cpp ../OSInfo.cpp ../Net.cpp SOURCES *= smallft.cpp DIST *= ../../icons/mumble.ico licenses.h smallft.h ../../icons/mumble.xpm murmur_pch.h mumble.plist RESOURCES *= mumble.qrc mumble_flags.qrc diff --git a/src/murmur/DBus.cpp b/src/murmur/DBus.cpp index 0e5ca56b9..2f741b57f 100644 --- a/src/murmur/DBus.cpp +++ b/src/murmur/DBus.cpp @@ -539,12 +539,7 @@ void MurmurDBus::setACL(int id, const QList<ACLInfo> &acls, const QList<GroupInf void MurmurDBus::getBans(QList<BanInfo> &bi) { bi.clear(); foreach(const Ban &b, server->qlBans) { - bool ok = true; - for (int i=0;i<10;++i) - ok = ok && (b.qip6Address[i] == 0); - for (int i=10;i<12;++i) - ok = ok && (b.qip6Address[i] == 0xFF); - if (ok) + if (! b.haAddress.isV6()) bi << BanInfo(b); } } @@ -745,7 +740,7 @@ GroupInfo::GroupInfo(const Group *g) { } BanInfo::BanInfo(const Ban &b) { - address = (b.qip6Address[12] << 24) | (b.qip6Address[13] << 16) | (b.qip6Address[14] << 8) | b.qip6Address[15]; + address = ntohl(b.haAddress.hash[3]); bits = b.iMask; } diff --git a/src/murmur/Messages.cpp b/src/murmur/Messages.cpp index 0e2db8990..47eac067a 100644 --- a/src/murmur/Messages.cpp +++ b/src/murmur/Messages.cpp @@ -296,7 +296,7 @@ void Server::msgBanList(ServerUser *uSource, MumbleProto::BanList &msg) { msg.clear_bans(); foreach(const Ban &b, qlBans) { MumbleProto::BanList_BanEntry *be = msg.add_bans(); - be->set_address(std::string(reinterpret_cast<const char *>(b.qip6Address.c), 16)); + be->set_address(b.haAddress.toStdString()); be->set_mask(b.iMask); be->set_name(u8(b.qsUsername)); be->set_hash(u8(b.qsHash)); @@ -309,11 +309,9 @@ void Server::msgBanList(ServerUser *uSource, MumbleProto::BanList &msg) { qlBans.clear(); for (int i=0;i < msg.bans_size(); ++i) { const MumbleProto::BanList_BanEntry &be = msg.bans(i); - std::string s = be.address(); - if (s.length() == 16) { + Ban b; - for (int j=0;j<16;++j) - b.qip6Address[j] = s[j]; + b.haAddress = be.address(); b.iMask = be.mask(); b.qsUsername = u8(be.name()); b.qsHash = u8(be.hash()); @@ -323,8 +321,8 @@ void Server::msgBanList(ServerUser *uSource, MumbleProto::BanList &msg) { else b.qdtStart = QDateTime::currentDateTime().toUTC(); b.iDuration = be.duration(); - qlBans << b; - } + if (b.isValid()) + qlBans << b; } saveBans(); log(uSource, "Updated banlist"); @@ -509,7 +507,7 @@ void Server::msgUserRemove(ServerUser *uSource, MumbleProto::UserRemove &msg) { if (ban) { Ban b; - b.qip6Address = pDstServerUser->qip6Address; + b.haAddress = pDstServerUser->haAddress; b.iMask = 128; b.qsReason = u8(msg.reason()); b.qsUsername = pDstServerUser->qsName; diff --git a/src/murmur/MurmurIce.cpp b/src/murmur/MurmurIce.cpp index 63c865cda..20fd7ec17 100644 --- a/src/murmur/MurmurIce.cpp +++ b/src/murmur/MurmurIce.cpp @@ -98,7 +98,7 @@ static void userToUser(const ::User *p, Murmur::User &mp) { mp.tcponly = (u->saiUdpAddress.sin_port == 0); ::Murmur::NetAddress addr(16, 0); - const Q_IPV6ADDR &a = u->qip6Address; + const Q_IPV6ADDR &a = u->haAddress.qip6; for (int i=0;i<16;++i) addr[i] = a[i]; @@ -137,7 +137,7 @@ static void groupToGroup(const ::Group *g, Murmur::Group &mg) { static void banToBan(const ::Ban &b, Murmur::Ban &mb) { ::Murmur::NetAddress addr(16, 0); - const Q_IPV6ADDR &a = b.qip6Address; + const Q_IPV6ADDR &a = b.haAddress.qip6; for (int i=0;i<16;++i) addr[i] = a[i]; @@ -153,10 +153,10 @@ static void banToBan(const ::Ban &b, Murmur::Ban &mb) { static void banToBan(const ::Murmur::Ban &mb, ::Ban &b) { if (mb.address.size() != 16) for (int i=0;i<16;++i) - b.qip6Address[i] = 0; + b.haAddress.qip6[i] = 0; else for (int i=0;i<16;++i) - b.qip6Address[i] = mb.address[i]; + b.haAddress.qip6[i] = mb.address[i]; b.iMask = mb.bits; b.qsUsername = u8(mb.name); b.qsHash = u8(mb.hash); diff --git a/src/murmur/Server.cpp b/src/murmur/Server.cpp index 903cb2410..9038f18c4 100644 --- a/src/murmur/Server.cpp +++ b/src/murmur/Server.cpp @@ -577,37 +577,11 @@ void Server::newClient() { sock->deleteLater(); return; } - - Q_IPV6ADDR base; - Q_IPV6ADDR mask; - if (adr.protocol() == QAbstractSocket::IPv6Protocol) { - base = adr.toIPv6Address(); - } else { - quint32 a = htonl(adr.toIPv4Address()); - const unsigned char *ptr = reinterpret_cast<const unsigned char *>(&a); - - for (int i=0;i<10;++i) - base[i] = 0; - base[10] = 0xff; - base[11] = 0xff; - base[12] = ptr[0]; - base[13] = ptr[1]; - base[14] = ptr[2]; - base[15] = ptr[3]; - } - + + HostAddress ha(adr); foreach(const Ban &ban, qlBans) { - for (int i=0;i<16;++i) - mask[i] = 0x00; - for (int i=0;i<ban.iMask;++i) - mask[i/8] |= static_cast<unsigned char>(0x80 >>(i%8)); - - bool match = true; - for (int i=0;i<16;++i) - match = match & ((base[i] & mask[i]) == (ban.qip6Address[i] & mask[i])); - - if (match) { + if (ban.haAddress.match(ha, ban.iMask)) { log(QString("Ignoring connection: %1:%2 (Server ban)").arg(addressToString(sock->peerAddress())).arg(sock->peerPort())); sock->disconnectFromHost(); sock->deleteLater(); @@ -629,7 +603,7 @@ void Server::newClient() { ServerUser *u = new ServerUser(this, sock); u->uiSession = qqIds.dequeue(); - u->qip6Address = base; + u->haAddress = ha; { QWriteLocker wl(&qrwlUsers); diff --git a/src/murmur/Server.h b/src/murmur/Server.h index 4ae92635e..7b5b151e1 100644 --- a/src/murmur/Server.h +++ b/src/murmur/Server.h @@ -36,6 +36,7 @@ #include "Timer.h" #include "User.h" #include "Connection.h" +#include "Net.h" #include "ACL.h" #include "DBus.h" @@ -111,9 +112,8 @@ class ServerUser : public Connection, public User { bool bVerified; QStringList qslEmail; - - Q_IPV6ADDR qip6Address; + HostAddress haAddress; bool bUdp; BandwidthRecord bwr; @@ -121,16 +121,6 @@ class ServerUser : public Connection, public User { ServerUser(Server *parent, QSslSocket *socket); }; -struct Ban { - Q_IPV6ADDR qip6Address; - int iMask; - QString qsUsername; - QString qsHash; - QString qsReason; - QDateTime qdtStart; - unsigned int iDuration; -}; - class Server : public QThread { private: Q_OBJECT; diff --git a/src/murmur/ServerDB.cpp b/src/murmur/ServerDB.cpp index 790533814..47dcd177d 100644 --- a/src/murmur/ServerDB.cpp +++ b/src/murmur/ServerDB.cpp @@ -1324,11 +1324,9 @@ void Server::getBans() { query.addBindValue(iServerNum); SQLEXEC(); while (query.next()) { - QByteArray qba = query.value(0).toByteArray(); - if (qba.length() == 16) { + Ban ban; - for (int i=0;i<16;++i) - ban.qip6Address[i] = qba.at(i); + ban.haAddress = query.value(0).toByteArray(); ban.iMask = query.value(1).toInt(); ban.qsUsername = query.value(2).toString(); @@ -1337,8 +1335,8 @@ void Server::getBans() { ban.qdtStart = query.value(5).toDateTime(); ban.iDuration = query.value(6).toInt(); - qlBans << ban; - } + if (ban.isValid()) + qlBans << ban; } } @@ -1352,11 +1350,8 @@ void Server::saveBans() { SQLPREP("INSERT INTO `%1bans` (`server_id`, `base`,`mask`,`name`,`hash`,`reason`,`start`,`duration`) VALUES (?,?,?,?,?,?,?,?)"); foreach(const Ban &ban, qlBans) { - QByteArray qba(16, 0); - for (int i=0;i<16;++i) - qba[i] = ban.qip6Address[i]; query.addBindValue(iServerNum); - query.addBindValue(qba); + query.addBindValue(ban.haAddress.toByteArray()); query.addBindValue(ban.iMask); query.addBindValue(ban.qsUsername); query.addBindValue(ban.qsHash); diff --git a/src/murmur/murmur.pro b/src/murmur/murmur.pro index 5649826de..98846304d 100644 --- a/src/murmur/murmur.pro +++ b/src/murmur/murmur.pro @@ -14,8 +14,8 @@ LANGUAGE = C++ FORMS = HEADERS *= Server.h Meta.h SOURCES *= main.cpp Server.cpp ServerDB.cpp Register.cpp Cert.cpp Messages.cpp Meta.cpp RPC.cpp -HEADERS *= ../ACL.h ../Group.h ../Channel.h ../Connection.h ../User.h -SOURCES *= ../ACL.cpp ../Group.cpp ../Channel.cpp ../Connection.cpp ../User.cpp ../Timer.cpp ../CryptState.cpp ../OSInfo.cpp +HEADERS *= ../ACL.h ../Group.h ../Channel.h ../Connection.h ../User.h ../Net.h +SOURCES *= ../ACL.cpp ../Group.cpp ../Channel.cpp ../Connection.cpp ../User.cpp ../Timer.cpp ../CryptState.cpp ../OSInfo.cpp ../Net.cpp DIST = DBus.h ServerDB.h ../../icons/murmur.ico Murmur.ice MurmurI.h MurmurIceWrapper.cpp PRECOMPILED_HEADER = murmur_pch.h |