void ExtPlaneConnection::socketError(QAbstractSocket::SocketError err) { INFO << "Socket error:" << errorString(); server_ok = false; emit connectionMessage(errorString() + " : " + peerName() + ":" + QString::number(peerPort())); reconnectTimer.setInterval(5000); reconnectTimer.start(); }
void IONapsterConnection::handleHostFound() { __io->clear(); __io->setMessageType( IONapsterCodes::SocketHostFound ); __io->insert( "host", peerName() ); __io->insert( "port", QString::number( peerPort() ) ); recvIOEvent( __io ); }
void IONapsterConnection::handleConnected() { __io->clear(); __io->setMessageType( IONapsterCodes::SocketConnected ); __io->insert( "host", peerName() ); __io->insert( "port", QString::number( peerPort() ) ); recvIOEvent( __io ); if ( ! __redirect ) sendRegisteredRequest(); }
void Q3Socket::tryConnection() { if ( d->socket->connect( d->addr, d->port ) ) { d->state = Connected; #if defined(Q3SOCKET_DEBUG) qDebug( "Q3Socket (%s): sn_write: Got connection to %s", name(), peerName().ascii() ); #endif if ( d->rsn ) d->rsn->setEnabled( true ); emit connected(); } else { d->state = Idle; QTimer::singleShot( 0, this, SLOT(emitErrorConnectionRefused()) ); return; } }
void IONapsterConnection::handleConnectionClosed() { __io->clear(); __io->setMessageType( IONapsterCodes::SocketConnectionClosed ); __io->insert( "host", peerName() ); __io->insert( "port", QString::number( peerPort() ) ); __io->insert( "rio", totalReadMessagesString() ); __io->insert( "sio", totalSentMessagesString() ); __io->insert( "rbytes", totalReadBytesString() ); __io->insert( "sbytes", totalSentBytesString() ); recvIOEvent( __io ); __num_rio = 0; __num_sio = 0; __num_rbytes = 0; __num_sbytes = 0; }
void pServer::onConnection() { auto socket = _server.nextPendingConnection(); auto addr = socket->peerAddress(); auto it = _limits.find(addr); if (it == _limits.end()) { it = _limits.insert(addr, 0); } else { if (it.value() > pServer::LIMIT) { socket->disconnectFromHost(); socket->deleteLater(); return; } } // qDebug() << "Connected: " << socket->peerAddress().toString() << " with used limit " << it.value() << " bytes"; new pSocket(socket, pThreadPool::getNextThread(), it.value()); Logger::log(socket->peerAddress().toString() + socket->peerName(), it.value()); }
//### query management qint64 Session::sendQuery(OutboundPkt &outboundPkt, QueryMethods *methods, const QVariant &extra, const QString &name) { Q_ASSERT (m_sessionId); Q_ASSERT (m_dc->authKeyId()); qint32 *data = outboundPkt.buffer(); qint32 ints = outboundPkt.length(); qCDebug(TG_CORE_SESSION) << "Sending query of size" << 4 * ints << "to DC" << m_dc->id() << "at" << peerName() << ":" << peerPort() << "by session" << QString::number(m_sessionId, 16); Query *q = new Query(this); q->setData(data, ints); q->setMsgId(encryptSendMessage(data, ints, 1)); q->setSeqNo(m_seqNo - 1); qCDebug(TG_CORE_SESSION) << "msgId is" << QString::number(q->msgId(), 16); q->setMethods(methods); q->setAcked(false); q->setExtra(extra); q->setName(name); if (mSettings->resendQueries()) { connect(q, SIGNAL(timeout(Query*)), this, SLOT(resendQuery(Query*)), Qt::UniqueConnection); q->startTimer(QUERY_TIMEOUT); }
bool IONapsterConnection::handleReadOnce() { if ( ( __size == 0 ) && ( __type == 0 ) ) { if ( bytesAvailable() < 4 ) return false ; __stream >> __size ; __stream >> __type ; } if ( bytesAvailable() < __size ) return false ; __data.resize( __size ) ; __stream.readRawBytes( __data.data(), __size ) ; __num_rbytes += 4; __num_rbytes += __size; // parse the message __io->clear(); __io->setMessageType( __type ); // the reason splitting the list is not done first is that // some messages (ie channel text) will often have an invalid // number of quotes. So in some cases it is better to read // from a stream than dequote directly. QString data = __data; data.truncate( __size ); QStringList list; QString temp; QTextStream stream( &data, IO_ReadOnly ); // save the original message __io->insert( "rawdata", data ); switch ( __type ) { // // login and system stuff we mostly ignore // case IONapsterCodes::LoginReply: list = IOSupport::quoteSplit( data ); __io->insert( "email", list[0] ); break; case IONapsterCodes::RegisteredReply: break; case IONapsterCodes::RegisteredError: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); break; case IONapsterCodes::RegisteredInvalid: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); break; case IONapsterCodes::SystemMessageReply: temp = stream.read(); __io->insert( "message", IOSupport::replaceCarets( temp ) ); __io->insert( "message.orig", temp ); break; case IONapsterCodes::ServerStats: stream >> temp; __io->insert( "users", temp ); stream >> temp; __io->insert( "files", temp ); stream >> temp; __io->insert( "size", temp ); break; case IONapsterCodes::GeneralError: temp = stream.read(); __io->insert( "message", IOSupport::replaceCarets( temp ) ); __io->insert( "message.orig", temp ); break; // // search codes // case IONapsterCodes::SearchRequest: break; case IONapsterCodes::SearchReply: list = IOSupport::quoteSplit( data ); __io->insert( "path", list[0] ); __io->insert( "directory", IOSupport::stripFile( list[0] ) ); __io->insert( "name", IOSupport::stripDir( list[0] ) ); __io->insert( "md5sum", list[1] ); __io->insert( "size", IOSupport::sizeText( list[2] ) ); __io->insert( "bitrate", list[3] ); __io->insert( "freq", list[4] ); __io->insert( "time", IOSupport::timeText( list[5] ) ); __io->insert( "nick", list[6] ); __io->insert( "host", IOSupport::networkToAscii( list[7] ) ); __io->insert( "speed", IOSupport::speedText( list[8] ) ); __io->insert( "weight", list[9] ); // original values __io->insert( "size.orig", list[2] ); __io->insert( "time.orig", list[5] ); __io->insert( "speed.orig", list[8] ); break; case IONapsterCodes::SearchDone: break; // // Download / queued codes // case IONapsterCodes::DownloadReply: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); __io->insert( "host", IOSupport::networkToAscii( list[1] ) ); __io->insert( "port", list[2] ); __io->insert( "path", list[3] ); __io->insert( "directory", IOSupport::stripFile( list[3] ) ); __io->insert( "name", IOSupport::stripDir( list[3] ) ); __io->insert( "speed", IOSupport::speedText( list[5] ) ); // original values __io->insert( "host.orig", list[1] ); __io->insert( "speed.orig", list[5] ); break; case IONapsterCodes::DownloadError: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); __io->insert( "path", list[1] ); __io->insert( "directory", IOSupport::stripFile( list[1] ) ); __io->insert( "name", IOSupport::stripDir( list[1] ) ); break; case IONapsterCodes::QueueLimitReply: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); __io->insert( "path", list[1] ); __io->insert( "directory", IOSupport::stripFile( list[1] ) ); __io->insert( "name", IOSupport::stripDir( list[1] ) ); __io->insert( "size", IOSupport::sizeText( list[5] ) ); __io->insert( "limit", list[3] ); // original values __io->insert( "size.orig", list[5] ); break; // // hotlist codes // case IONapsterCodes::HotlistAddReply: __io->insert( "nick", data ); break; case IONapsterCodes::HotlistAddError: __io->insert( "nick", data ); break; case IONapsterCodes::HotlistLogon: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); __io->insert( "speed", IOSupport::speedText( list[2] ) ); __io->insert( "speed.orig", list[2] ); break; case IONapsterCodes::HotlistLogoff: __io->insert( "nick", data ); break; // // channel codes // case IONapsterCodes::ChanPartRequest: __io->insert( "channel", data ); break; case IONapsterCodes::ChanJoinReply: __io->insert( "channel", data ); break; case IONapsterCodes::ChanList: list = IOSupport::quoteSplit( data ); __io->insert( "channel", list[0] ); __io->insert( "nick", list[1] ); __io->insert( "size", list[2] ); __io->insert( "speed", IOSupport::speedText( list[3] ) ); __io->insert( "speed.orig", list[3] ); break; case IONapsterCodes::ChanListDone: __io->insert( "channel", data ); break; case IONapsterCodes::ChanJoin: list = IOSupport::quoteSplit( data ); __io->insert( "channel", list[0] ); __io->insert( "nick", list[1] ); __io->insert( "size", list[2] ); __io->insert( "speed", IOSupport::speedText( list[3] ) ); __io->insert( "speed.orig", list[3] ); break; case IONapsterCodes::ChanPart: list = IOSupport::quoteSplit( data ); __io->insert( "channel", list[0] ); __io->insert( "nick", list[1] ); __io->insert( "size", list[2] ); __io->insert( "speed", IOSupport::speedText( list[3] ) ); __io->insert( "speed.orig", list[3] ); break; case IONapsterCodes::ChanMessage: stream >> temp; __io->insert( "channel", temp ); stream >> temp; __io->insert( "nick", temp ); temp = stream.read(); __io->insert( "message", IOSupport::replaceCarets( temp ) ); __io->insert( "message.orig", temp ); break; case IONapsterCodes::ChanEmote: stream >> temp; __io->insert( "channel", temp ); stream >> temp; __io->insert( "nick", temp ); temp = stream.read(); __io->insert( "message", IOSupport::replaceCarets( temp ) ); __io->insert( "message.orig", temp ); break; case IONapsterCodes::ChanTopic: stream >> temp; __io->insert( "channel", temp ); temp = stream.read(); __io->insert( "message", IOSupport::replaceCarets( temp ) ); __io->insert( "message.orig", temp ); break; case IONapsterCodes::ChanMotd: list = IOSupport::quoteSplit( data ); __io->insert( "channel", list[0] ); __io->insert( "message", IOSupport::replaceCarets( list[1] ) ); __io->insert( "message.orig", list[1] ); break; // // private messages // case IONapsterCodes::UserMessageReply: stream >> temp; __io->insert( "nick", temp ); __io->insert( "message", stream.read() ); break; case IONapsterCodes::OpMessageReply: stream >> temp; __io->insert( "nick", temp ); __io->insert( "message", stream.read() ); break; case IONapsterCodes::GlobalMessageReply: stream >> temp; __io->insert( "nick", temp ); __io->insert( "message", stream.read() ); break; // // browse codes // case IONapsterCodes::BrowseReply: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); __io->insert( "path", list[1] ); __io->insert( "directory", IOSupport::stripFile( list[1] ) ); __io->insert( "name", IOSupport::stripDir( list[1] ) ); __io->insert( "md5sum", list[2] ); __io->insert( "size", IOSupport::sizeText( list[3] ) ); __io->insert( "bitrate", list[4] ); __io->insert( "freq", list[5] ); __io->insert( "time", IOSupport::timeText( list[6] ) ); __io->insert( "size.orig", list[3] ); __io->insert( "time.orig", list[6] ); break; case IONapsterCodes::BrowseDone: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); __io->insert( "host", IOSupport::networkToAscii( list[1] ) ); __io->insert( "host.orig", list[1] ); break; // // list of active channels // case IONapsterCodes::ListChansReply: stream >> temp; __io->insert( "channel", temp ); stream >> temp; __io->insert( "size", temp ); __io->insert( "message", stream.read() ); break; case IONapsterCodes::ListChansDone: break; case IONapsterCodes::ListAllChansReply: list = IOSupport::quoteSplit( data ); __io->insert( "channel", list[0] ); __io->insert( "size", list[1] ); __io->insert( "extra", list[2] ); __io->insert( "level", list[3] ); __io->insert( "limit", list[4] ); __io->insert( "message", list[5] ); break; case IONapsterCodes::ListAllChansDone: break; // // whois codes // case IONapsterCodes::WhoisReply: list = IOSupport::quoteSplit( data ); __io->insert( "nick", list[0] ); __io->insert( "level", list[1] ); __io->insert( "time", IOSupport::timeText( list[2] ) ); __io->insert( "channels", list[3] ); __io->insert( "status", list[4] ); __io->insert( "shared", list[5] ); __io->insert( "downloads", list[6] ); __io->insert( "uploads", list[7] ); __io->insert( "speed", IOSupport::speedText( list[8] ) ); __io->insert( "client", list[9] ); __io->insert( "time.orig", list[2] ); __io->insert( "speed.orig", list[8] ); break; default: qDebug( "parse(): " "unknown code %d: %s", __type, data.latin1() ); break; } // always add the host and port __io->insert( "napster.host", peerName() ); __io->insert( "napster.port", QString::number( peerPort() ) ); // // handle the message // recvIOEvent( __io ); // reset the message __size = 0; __type = 0; __data.fill( 0 ); // try to read again return true; }
//### query management qint64 Session::sendQuery(OutboundPkt &outboundPkt, QueryMethods *methods, const QVariant &extra, const QString &name) { Q_ASSERT (m_sessionId); Q_ASSERT (m_dc->authKeyId()); qint32 *data = outboundPkt.buffer(); qint32 ints = outboundPkt.length(); // prepend init connection header to outboundPkt if initConnectionNeeded // Note: 'wrap' needs to be declare outside of if to persist until encriptSendMessage is completed OutboundPkt wrap(mSettings); if (m_initConnectionNeeded) { wrap.initConnection(); wrap.appendOutboundPkt(outboundPkt); data = wrap.buffer(); ints = wrap.length(); m_initConnectionNeeded = false; } qCDebug(TG_CORE_SESSION) << "Sending query of size" << 4 * ints << "to DC" << m_dc->id() << "at" << peerName() << ":" << peerPort() << "by session" << QString::number(m_sessionId, 16); Query *q = new Query(this); q->setData(data, ints); q->setMsgId(encryptSendMessage(data, ints, 1)); q->setMainMsgId(q->msgId()); q->setSeqNo(m_seqNo - 1); qCDebug(TG_CORE_SESSION) << "msgId is" << QString::number(q->msgId(), 16); q->setMethods(methods); q->setAcked(false); q->setExtra(extra); q->setName(name); if (mSettings->resendQueries()) { connect(q, &Query::timeout, this, &Session::resendQuery, Qt::UniqueConnection); q->startTimer(QUERY_TIMEOUT); } m_pendingQueries.insert(q->msgId(), q); return q->msgId(); }
void DeviceAgent::onEncrypted() { DEBUG_INFO << "Client onEncrypted:" << peerName(); }