forked from hyphanet/lib-CppFCPLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.h
148 lines (118 loc) · 4.76 KB
/
Node.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef NODE_H__
#define NODE_H__
#include <string>
#include <memory>
#include <map>
#include "zthread/Thread.h"
#include "zthread/ThreadedExecutor.h"
#include "FCPResult.h"
#include "TQueue.h"
#include "NodeThread.h"
#include "AdditionalFields.h"
#include "Exceptions.h"
#include "sha256.h"
namespace FCPLib {
class Node {
friend class NodeThread;
std::string name;
ZThread::CountedPtr< JobTicketQueue > clientReqQueue;
NodeThread* nodeThread;
ZThread::ThreadedExecutor executor;
int globalCommandsTimeout;
static std::string _getUniqueId();
void checkProtocolError(Response &resp);
Message::Ptr nodeHelloMessage;
ZThread::Mutex access;
bool isAlive_, hasException_;
std::auto_ptr<FCPNodeFailure> failure;
void setIsAlive(bool x) {
ZThread::Guard<ZThread::Mutex> g(access);
isAlive_ = x;
}
void setFailure(std::string e) {
ZThread::Guard<ZThread::Mutex> g(access);
failure = std::auto_ptr<FCPNodeFailure>( new FCPNodeFailure( e ) );
hasException_ = true;
}
public:
Node(std::string name, std::string host, int port);
~Node();
int getGlobalCommandsTimeout() const {
return globalCommandsTimeout;
}
Node& setGlobalCommandsTimeout(int t) {
globalCommandsTimeout = t; return *this;
}
void shutdown();
bool isAlive() {
ZThread::Guard<ZThread::Mutex> g(access);
return isAlive_;
}
bool hasFailure() {
ZThread::Guard<ZThread::Mutex> g(access);
return hasException_;
}
FCPNodeFailure getFailure() {
ZThread::Guard<ZThread::Mutex> g(access);
if ( isAlive_ )
throw std::logic_error("There is no failure");
if (! hasException_ )
throw std::logic_error("Cannot retrieve the reason of a failure");
return *failure;
}
const Message::Ptr getNodeHelloMessage() const;
Message::Ptr listPeer(const std::string &);
MessagePtrContainer listPeers(const AdditionalFields& = AdditionalFields());
PeerNoteContainer listPeerNotes(const std::string&);
Message::Ptr addPeer(const std::string &, bool isURL);
Message::Ptr addPeer(const std::map<std::string, std::string> &message);
Message::Ptr modifyPeer(const std::string &, const AdditionalFields& = AdditionalFields());
PeerNote modifyPeerNote(const std::string &, const std::string &, int = 1);
Message::Ptr removePeer(const std::string &);
Message::Ptr getNode(const AdditionalFields& = AdditionalFields());
Message::Ptr getConfig(const AdditionalFields& = AdditionalFields());
Message::Ptr modifyConfig(Message::Ptr m);
TestDDAReplyResponse::Ptr testDDARequest(std::string dir, bool read, bool write);
TestDDAResponse testDDAResponse(std::string dir, std::string readContent = "");
TestDDAResponse testDDA(std::string dir, bool read, bool write);
Message::Ptr generateSSK(std::string identifier);
JobTicket::Ptr putData(const std::string , // URI
std::istream*, // Data Stream
int, // dataLength
const std::string = "", // Identifier
const AdditionalFields& = AdditionalFields()
);
JobTicket::Ptr putRedirect(const std::string , // URI
const std::string , // Target
const std::string = "", // Identifier
const AdditionalFields& = AdditionalFields()
);
JobTicket::Ptr putDisk(const std::string , // URI
const std::string , // Filename
const std::string = "", // Identifier
const AdditionalFields& = AdditionalFields()
);
GetJob::Ptr getDisk(const std::string , // URI
const std::string , // Filename
const std::string = "", // Identifier
const AdditionalFields& = AdditionalFields()
);
GetJob::Ptr fetchData(const std::string , // URI
const std::string = "", // Identifier
const AdditionalFields& = AdditionalFields()
);
GetJob::Ptr getDirect(const std::string , // URI
const std::string = "", // Identifier
std::ostream* = NULL, // Stream
const AdditionalFields& = AdditionalFields()
);
JobTicket::Ptr subscribeUSK(const std::string, const std::string, bool);
void watchGlobal( bool enabled, int verbosity );
void refreshPersistentRequest();
JobCollection listGlobalJobs();
JobCollection listPersistentJobs();
void removePersistentRequest( JobTicket::Ptr job );
void modifyPersistentRequest( JobTicket::Ptr job, const AdditionalFields& );
};
}
#endif