33 #ifndef _IDENTT_HRPC_REMOTE_ENDPOINT_SERVICE_HPP_ 34 #define _IDENTT_HRPC_REMOTE_ENDPOINT_SERVICE_HPP_ 46 template <
class HttpServerT>
72 identt::utils::SharedTable::pointer stptr,
73 typename std::shared_ptr<HttpServerT> server,
74 ::identt::hrpc::RemoteKeeper::pointer rkeeper,
77 identt::query::
ServiceBase<HttpServerT>(IDENTT_SERVICE_SCOPE_HTTP | IDENTT_SERVICE_SCOPE_HTTPS)
79 if (!(this->myscope & scope))
return;
83 server->resource[
"/_identt/identity/remote/v1/endpoint$"][
"POST"]
84 =[
this,stptr,rkeeper](
typename HttpServerT::RespPtr response,
typename HttpServerT::ReqPtr request) {
85 IDENTT_PARALLEL_ONE([
this,stptr,rkeeper,response,request] {
101 case ::identt::hrpc::R_REGISTER : {
102 identt::hrpc::StateT data;
103 if (!data.ParseFromString( b64_decode(request->content.string()) ))
107 if (stptr->is_master.Get()) {
108 rkeeper->AddHost( data.thisurl(), data.logcounter(), data.ts() );
109 rkeeper->HostUpdate();
113 rkeeper->GetHosts(&data);
114 data.SerializeToString(&output);
115 DLOG(INFO) << request->path <<
" " << sname;
118 case ::identt::hrpc::R_READONE : {
119 identt::store::TransactionT data;
120 if (!data.ParseFromString( b64_decode(request->content.string()) ))
126 data.SerializeToString(&output);
127 DLOG(INFO) << request->path <<
" " << sname;
130 case ::identt::hrpc::R_TRANSLOG : {
131 identt::store::TransListT data;
132 if (!data.ParseFromString( b64_decode(request->content.string()) ))
136 auto logc = stptr->logcounter.Get();
137 if (data.lastid()>logc)
138 throw ::identt::BadDataException(
"Remote Log Counter ahead");
140 if (data.lastid()==logc) {
141 data.set_ts( IDENTT_CURRTIME_MS );
142 data.set_currid( logc );
146 if (stptr->lastslave.Get().empty())
147 stptr->lastslave.Set(data.endpoint());
155 data.SerializeToString(&output);
156 DLOG(INFO) << request->path <<
" " << sname;
159 case ::identt::hrpc::R_SETINFO : {
160 identt::hrpc::StateT data;
161 if (!data.ParseFromString( b64_decode(request->content.string()) ))
165 rkeeper->SetHosts(&data);
168 rkeeper->GetHosts(&data);
169 data.SerializeToString(&output);
170 DLOG(INFO) << request->path <<
" " << sname;
173 case ::identt::hrpc::R_ADDHOST : {
174 identt::hrpc::RemoteT data;
175 if (!data.ParseFromString( b64_decode(request->content.string()) ))
179 if (stptr->is_master.Get())
181 rkeeper->AddHost(&data);
184 data.SerializeToString(&output);
185 DLOG(INFO) << request->path <<
" " << sname;
188 case ::identt::hrpc::R_BUFFTRANS : {
189 identt::store::TransactionT data;
190 if (!data.ParseFromString( b64_decode(request->content.string()) ))
193 if (stptr->is_master.Get())
196 data.SerializeToString(&output);
197 stptr->transactions.AddOne(data.id(),output);
199 DLOG(INFO) << request->path <<
" " << sname;
203 DLOG(INFO) << request->path <<
" " << sname;
214 output=
"Unknown Error";
232 #endif // _IDENTT_HRPC_REMOTE_ENDPOINT_SERVICE_HPP_
ServiceBase(const unsigned int myscope_)
Constructor : to be used by inherited classes.
Definition: ServiceBase.hpp:65
void ServiceOKAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, std::string &payload)
ServiceOKAction : OK Action template for service.
Definition: ProtoServiceBase.hpp:114
int ServiceName(typename HttpServerT::ReqPtr request)
ServiceName : Check protobuf request service name.
Definition: ProtoServiceBase.hpp:93
HrpcRemoteEndpointService(identt::utils::SharedTable::pointer stptr, typename std::shared_ptr< HttpServerT > server, ::identt::hrpc::RemoteKeeper::pointer rkeeper, unsigned int scope)
HrpcRemoteEndpointService : constructor.
Definition: HrpcRemoteEndpointService.hpp:71
void ReadOne(::identt::utils::SharedTable::pointer stptr, TransactionT *trans)
ReadOne : read a single transaction.
Definition: StoreTrans.cc:144
Definition: ServiceBase.hpp:55
Definition: CryptoBase.hpp:49
Definition: BaseUtils.hpp:89
void ReadLog(::identt::utils::SharedTable::pointer stptr, TransListT *tlist)
ReadLog : read from log in sequence.
bool SharedSecretOK(typename HttpServerT::ReqPtr request, std::string sharedkey)
SharedSecretOK : Check if shared key header is present and ok.
Definition: ProtoServiceBase.hpp:77
void ServiceErrAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, int ecode, std::string &emsg)
ServiceErrAction : Error Action template for service.
Definition: ProtoServiceBase.hpp:173
Definition: ProtoServiceBase.hpp:43
Definition: StoreTrans.hpp:41
bool ProtoRequest(typename HttpServerT::ReqPtr request)
ProtoRequest : Check if request is protobuf from Content-Type and Accept fields.
Definition: ProtoServiceBase.hpp:55
Definition: HrpcRemoteEndpointService.hpp:47