00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2004-2006 Trolltech ASA. All rights reserved. 00004 ** 00005 ** This file is part of the example classes of the Qt Toolkit. 00006 ** 00007 ** This file may be used under the terms of the GNU General Public 00008 ** License version 2.0 as published by the Free Software Foundation 00009 ** and appearing in the file LICENSE.GPL included in the packaging of 00010 ** this file. Please review the following information to ensure GNU 00011 ** General Public Licensing requirements will be met: 00012 ** http://www.trolltech.com/products/qt/opensource.html 00013 ** 00014 ** If you are unsure which license is appropriate for your use, please 00015 ** review the following information: 00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the 00017 ** sales department at sales@trolltech.com. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00021 ** 00022 ****************************************************************************/ 00023 00024 #include "connectionmanager.h" 00025 00026 #include <QByteArray> 00027 #include <QDateTime> 00028 00029 static const int MaxConnections = 250; 00030 00031 Q_GLOBAL_STATIC(ConnectionManager, connectionManager) 00032 00033 ConnectionManager *ConnectionManager::instance() 00034 { 00035 return connectionManager(); 00036 } 00037 00038 bool ConnectionManager::canAddConnection() const 00039 { 00040 return (connections.size() < MaxConnections); 00041 } 00042 00043 void ConnectionManager::addConnection(PeerWireClient *client) 00044 { 00045 connections << client; 00046 } 00047 00048 void ConnectionManager::removeConnection(PeerWireClient *client) 00049 { 00050 connections.remove(client); 00051 } 00052 00053 int ConnectionManager::maxConnections() const 00054 { 00055 return MaxConnections; 00056 } 00057 00058 QByteArray ConnectionManager::clientId() const 00059 { 00060 if (id.isEmpty()) { 00061 // Generate peer id 00062 int startupTime = int(QDateTime::currentDateTime().toTime_t()); 00063 00064 QString s; 00065 s.sprintf("-QT%06x", QT_VERSION); 00066 id += s.toLatin1(); 00067 id += QByteArray::number(startupTime, 16); 00068 id += QByteArray(20 - id.size(), '-'); 00069 } 00070 return id; 00071 }
1.5.1