-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpeer.h
75 lines (70 loc) · 2.65 KB
/
peer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef LAFDUP_PEER_H
#define LAFDUP_PEER_H
#include <QtCore/qset.h>
#include "lafrpc.h"
#include "models.h"
class LafdupDiscovery;
class LafdupRemoteStub;
class LafdupPeer : public QObject
{
Q_OBJECT
public:
LafdupPeer(const QByteArray &uuid, quint16 port);
virtual ~LafdupPeer() override;
public:
bool start();
void stop();
void outgoing(const CopyPaste ©Paste);
void setPassword(QByteArray password);
void setExtraKnownPeers(const QSet<QPair<qtng::HostAddress, quint16>> &extraKnownPeers);
void setCacheDir(const QString &cacheDir);
void setDeleteFilesTime(int minutes);
void setSendFilesSize(float mb);
void setIgnorePassword(bool ignorePassword);
QStringList getAllBoundAddresses();
quint16 getPort();
static quint16 getDefaultPort();
signals:
void incoming(const CopyPaste ©Paste);
void stateChanged(bool ok);
void sendFeedBack(QString str);
void sendAction();
protected:
bool hasPeer(const qtng::HostAddress &remoteHost, quint16 port);
bool hasPeer(const QString &peerName);
void tryToConnectPeer(QString itsPeerName, qtng::HostAddress remoteHost, quint16 port);
void tryToConnectPeer(QSharedPointer<qtng::KcpSocket> request);
private:
void handleKcpRequestSync(QSharedPointer<qtng::KcpSocket> request, qtng::DataChannelPole pole,
const QString &itsPeerName);
QSharedPointer<lafrpc::Peer> handleRequestSync(QSharedPointer<qtng::SocketLike> request, qtng::DataChannelPole pole,
const QString &itsPeerName, const QString &itsAddress);
void _outgoing(CopyPaste copyPaste);
bool canSendContent(const CopyPaste ©Paste);
bool findItem(const QDateTime ×tamp);
bool findItem(const CopyPaste ¤tItem);
void writeInformation(const QDir destDir);
void cleanFiles();
void _cleanFiles(const QDir &dir, bool cleanAll);
bool sendContentToPeer(QSharedPointer<lafrpc::Peer> peer, const CopyPaste ©Paste, QString *errorString);
bool resultFeedBack(QSharedPointer<lafrpc::Peer> peer, QVariant result, QString errorText,
const CopyPaste ©Paste);
private:
QSharedPointer<LafdupDiscovery> discovery;
QSharedPointer<LafdupRemoteStub> stub;
QSharedPointer<qtng::Cipher> cipher;
QList<CopyPaste> items;
QSet<QString> connectingPeers;
QString cacheDir;
int deleteFilesTime;
float sendFilesSize;
bool ignorePassword;
bool cleaningFiles;
qtng::CoroutineGroup *operations;
friend LafdupRemoteStub;
friend LafdupDiscovery;
friend struct MarkCleaning;
public:
QSharedPointer<lafrpc::Rpc> rpc;
};
#endif