forked from hyphanet/lib-CppFCPLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerMessage.h
153 lines (117 loc) · 4.59 KB
/
ServerMessage.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
149
150
151
152
153
#ifndef SERVERMESSAGE_H__
#define SERVERMESSAGE_H__
#include <string>
#include <boost/shared_ptr.hpp>
#include "Message.h"
#include "Server.h"
#include "Exceptions.h"
namespace FCPLib {
class JobTicket;
typedef boost::shared_ptr<JobTicket> JobTicketPtr;
class ServerMessage {
virtual void read(boost::shared_ptr<Server> s);
protected:
Message::Ptr message;
public:
typedef boost::shared_ptr<ServerMessage> Ptr;
static Ptr factory(boost::shared_ptr<Server> s);
std::string getIdOfJob() const {
std::string id = message->getField("Identifier");
return id.size() ? id : "";
}
virtual bool isLast(const JobTicketPtr job) const = 0;
virtual bool isError() const = 0;
virtual ~ServerMessage() {}
const std::string& toString() const;
const Message::Ptr getMessage() const { return message; }
};
typedef std::vector<ServerMessage::Ptr> Response;
template<bool isLast>
struct IsLastT {
Message::Ptr message;
IsLastT( Message::Ptr m ) : message(m) {}
bool operator()(const JobTicketPtr job) const {
return isLast;
}
};
typedef IsLastT<true> IsLastTrue;
typedef IsLastT<false> IsLastFalse;
struct IsLastPeer {
Message::Ptr message;
IsLastPeer( Message::Ptr m ) : message(m) {}
bool operator()(const JobTicketPtr job) const;
};
struct IsLastPeerNote {
Message::Ptr message;
IsLastPeerNote( Message::Ptr m ) : message(m) {}
bool operator()(const JobTicketPtr job) const;
};
struct IsLastPutFailed {
Message::Ptr message;
IsLastPutFailed( Message::Ptr m ) : message(m) {}
bool operator()(const JobTicketPtr job) const;
};
struct IsLastGetFailed {
Message::Ptr message;
IsLastGetFailed( Message::Ptr m ) : message(m) {}
bool operator()(const JobTicketPtr job) const;
};
struct IsLastDataFound {
Message::Ptr message;
IsLastDataFound( Message::Ptr m ) : message(m) {}
bool operator()(const JobTicketPtr job) const;
};
template<typename isLastT = IsLastTrue, bool isErrorT = false>
class ServerMessageT : public ServerMessage {
friend class ServerMessage;
ServerMessageT() {}
public:
bool isLast(const JobTicketPtr job) const {
return isLastT( message )( job );
}
bool isError() const {
return isErrorT;
}
};
class AllDataMessage : public ServerMessage {
friend class ServerMessage;
boost::shared_ptr<Server> server;
std::size_t bytesToRead;
void read(boost::shared_ptr<Server> s);
AllDataMessage() {}
public:
bool isLast(const JobTicketPtr job) const;
bool isError() const { return false; }
};
typedef class ServerMessageT<IsLastTrue, false> NodeHelloMessage;
typedef class ServerMessageT<IsLastTrue, true> CloseConnectionDuplicateNameMessage;
typedef class ServerMessageT<IsLastPeer, false> PeerMessage;
typedef class ServerMessageT<IsLastPeerNote, false> PeerNoteMessage;
typedef class ServerMessageT<IsLastTrue, false> PeerRemovedMessage;
typedef class ServerMessageT<IsLastTrue, false> EndMessage;
typedef class ServerMessageT<IsLastTrue, false> NodeDataMessage;
typedef class ServerMessageT<IsLastTrue, false> ConfigDataMessage;
typedef class ServerMessageT<IsLastTrue, false> TestDDAReplyMessage;
typedef class ServerMessageT<IsLastTrue, false> TestDDACompleteMessage;
typedef class ServerMessageT<IsLastTrue, false> SSKKeypairMessage;
typedef class ServerMessageT<IsLastFalse, false> PersistentGetMessage;
typedef class ServerMessageT<IsLastFalse, false> PersistentPutMessage;
typedef class ServerMessageT<IsLastFalse, false> PersistentPutDirMessage;
typedef class ServerMessageT<IsLastFalse, false> URIGeneratedMessage;
typedef class ServerMessageT<IsLastTrue, false> PutSuccessfulMessage;
typedef class ServerMessageT<IsLastFalse, false> PutFetchableMessage;
typedef class ServerMessageT<IsLastDataFound, false> DataFoundMessage;
typedef class ServerMessageT<IsLastFalse, false> StartedCompressionMessage;
typedef class ServerMessageT<IsLastFalse, false> FinishedCompressionMessage;
typedef class ServerMessageT<IsLastFalse, false> SimpleProgressMessage;
typedef class ServerMessageT<IsLastTrue, false> PersistentRequestRemovedMessage;
typedef class ServerMessageT<IsLastFalse, false> PersistentRequestModifiedMessage;
typedef class ServerMessageT<IsLastPutFailed, true> PutFailedMessage;
typedef class ServerMessageT<IsLastGetFailed, true> GetFailedMessage;
typedef class ServerMessageT<IsLastTrue, true> ProtocolErrorMessage;
typedef class ServerMessageT<IsLastTrue, true> IdentifierCollisionMessage;
typedef class ServerMessageT<IsLastTrue, true> UnknownNodeIdentifierMessage;
typedef class ServerMessageT<IsLastTrue, true> UnknownPeerNoteTypeMessage;
typedef class ServerMessageT<IsLastFalse, false> SubscribedUSKUpdate;
}
#endif // SERVERMESSAGE_H__