1 /* 2 * Copyright 2013 Vitaly Valtman 3 * Copyright 2014 Canonical Ltd. 4 * Authors: 5 * Roberto Mier 6 * Tiago Herrmann 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; version 3. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 #ifndef NETWORKMGR_H 23 #define NETWORKMGR_H 24 25 #include <QObject> 26 #include "outboundpkt.h" 27 #include "inboundpkt.h" 28 #include "connection.h" 29 #include "settings.h" 30 #include "util/cryptoutils.h" 31 32 class DC : public Endpoint 33 { 34 public: 35 enum DcState { 36 error = -1, 37 init, 38 reqPQSent, 39 reqDHSent, 40 clientDHSent, 41 authKeyCreated, 42 userSignedIn 43 }; 44 DC(qint32 dcNum)45 explicit DC(qint32 dcNum) : 46 m_id(dcNum), 47 m_state(init), 48 m_authKeyId(0), 49 m_expires(0), 50 m_serverSalt(0), 51 mTimeDifference(0) {} 52 id()53 inline qint32 id() { return m_id; } setState(DcState dcState)54 inline void setState(DcState dcState) { m_state = dcState; } state()55 inline DcState state() { return m_state; } serverSalt()56 inline qint64 serverSalt() { return m_serverSalt; } setServerSalt(qint64 serverSalt)57 inline void setServerSalt(qint64 serverSalt) { this->m_serverSalt = serverSalt; } authKeyId()58 inline qint64 authKeyId() { return m_authKeyId; } setAuthKeyId(qint64 authkeyId)59 inline void setAuthKeyId(qint64 authkeyId) { this->m_authKeyId = authkeyId; } authKey()60 inline char *authKey() { return m_authKey; } timeDifference()61 inline double timeDifference() { return mTimeDifference; } setTimeDifference(qint32 timeDifference)62 inline void setTimeDifference(qint32 timeDifference) { mTimeDifference = timeDifference; } expires()63 inline qint32 expires() { return m_expires; } setExpires(qint32 expires)64 inline void setExpires(qint32 expires) { m_expires = expires; } 65 66 private: 67 68 // dc metadata 69 qint32 m_id; 70 DcState m_state; 71 // auth members 72 qint64 m_authKeyId; 73 char m_authKey[SHARED_KEY_LENGTH]; 74 qint32 m_expires; // date the authorization expires 75 // to be used during session 76 qint64 m_serverSalt; 77 qint32 mTimeDifference; // difference between client and server time 78 79 }; 80 81 #endif // NETWORKMGR_H 82