_lastPingTime(0),
_pingCount(0),
+ _sendPings(false),
_requestedUserModes('-')
{
_autoReconnectTimer.setSingleShot(true);
#ifdef HAVE_QCA2
-Cipher *CoreNetwork::cipher(const QString &target) const
+Cipher *CoreNetwork::cipher(const QString &target)
{
if (target.isEmpty())
return 0;
if (!Cipher::neededFeaturesAvailable())
return 0;
- QByteArray key = cipherKey(target);
- if (key.isEmpty())
- return 0;
-
CoreIrcChannel *channel = qobject_cast<CoreIrcChannel *>(ircChannel(target));
if (channel) {
- if (channel->cipher()->setKey(key))
- return channel->cipher();
+ return channel->cipher();
}
- else {
- CoreIrcUser *user = qobject_cast<CoreIrcUser *>(ircUser(target));
- if (user && user->cipher()->setKey(key))
- return user->cipher();
+ CoreIrcUser *user = qobject_cast<CoreIrcUser *>(ircUser(target));
+ if (user) {
+ return user->cipher();
+ } else if (!isChannelName(target)) {
+ return qobject_cast<CoreIrcUser*>(newIrcUser(target))->cipher();
}
return 0;
}
-QByteArray CoreNetwork::cipherKey(const QString &recipient) const
+QByteArray CoreNetwork::cipherKey(const QString &target) const
{
- return _cipherKeys.value(recipient.toLower(), QByteArray());
+ CoreIrcChannel *c = qobject_cast<CoreIrcChannel*>(ircChannel(target));
+ if (c)
+ return c->cipher()->key();
+
+ CoreIrcUser *u = qobject_cast<CoreIrcUser*>(ircUser(target));
+ if (u)
+ return u->cipher()->key();
+
+ return QByteArray();
}
-void CoreNetwork::setCipherKey(const QString &recipient, const QByteArray &key)
+void CoreNetwork::setCipherKey(const QString &target, const QByteArray &key)
{
- if (!key.isEmpty())
- _cipherKeys[recipient.toLower()] = key;
- else
- _cipherKeys.remove(recipient.toLower());
+ CoreIrcChannel *c = qobject_cast<CoreIrcChannel*>(ircChannel(target));
+ if (c) {
+ c->setEncrypted(c->cipher()->setKey(key));
+ return;
+ }
+
+ CoreIrcUser *u = qobject_cast<CoreIrcUser*>(ircUser(target));
+ if (!u && !isChannelName(target))
+ u = qobject_cast<CoreIrcUser*>(newIrcUser(target));
+
+ if (u) {
+ u->setEncrypted(u->cipher()->setKey(key));
+ return;
+ }
}
+bool CoreNetwork::cipherUsesCBC(const QString &target)
+{
+ CoreIrcChannel *c = qobject_cast<CoreIrcChannel*>(ircChannel(target));
+ if (c)
+ return c->cipher()->usesCBC();
+ CoreIrcUser *u = qobject_cast<CoreIrcUser*>(ircUser(target));
+ if (u)
+ return u->cipher()->usesCBC();
+
+ return false;
+}
#endif /* HAVE_QCA2 */
bool CoreNetwork::setAutoWhoDone(const QString &channel)
emit socketInitialized(identity, localAddress(), localPort(), peerAddress(), peerPort());
+ enablePingTimeout();
+
// TokenBucket to avoid sending too much at once
_messageDelay = 2200; // this seems to be a safe value (2.2 seconds delay)
_burstSize = 5;
sendPerform();
- enablePingTimeout();
+ _sendPings = true;
if (networkConfig()->autoWhoEnabled()) {
_autoWhoCycleTimer.start();
else {
_lastPingTime = now;
_pingCount++;
- userInputHandler()->handlePing(BufferInfo(), QString());
+ // Don't send pings until the network is initialized
+ if(_sendPings)
+ userInputHandler()->handlePing(BufferInfo(), QString());
}
}
void CoreNetwork::disablePingTimeout()
{
_pingTimer.stop();
+ _sendPings = false;
resetPingTimeout();
}