eris 1.4.0
A WorldForge client library.
MetaQuery.cpp
1#include "MetaQuery.h"
2
3#ifdef HAVE_CONFIG_H
4#include "config.h"
5#endif
6
7#include "Metaserver.h"
8#include "Connection.h"
9
10#include <Atlas/Objects/Operation.h>
11#include <Atlas/Objects/Encoder.h>
12
13#include <sigc++/slot.h>
14
15#include <cassert>
16
17using namespace Atlas::Objects::Operation;
18using WFMath::TimeStamp;
19
20namespace Eris {
21
22MetaQuery::MetaQuery(boost::asio::io_service& io_service,
23 Atlas::Bridge& bridge,
24 Meta& meta,
25 const std::string& host,
26 size_t sindex) :
27 BaseConnection(io_service, "eris-metaquery", host),
28 _meta(meta),
29 _queryNo(0),
30 m_serverIndex(sindex),
31 m_complete(false),
32 m_completeTimer(io_service) {
33 _bridge = &bridge;
34 connectRemote(host, 6767);
35}
36
37// clean up is all done by the Base Connection
38MetaQuery::~MetaQuery() = default;
39
40void MetaQuery::onConnect() {
41 // servers must responed to a fully anonymous GET operation
42 // with pertinent info
43 Get gt;
44 gt->setSerialno(getNewSerialno());
45
46 // send code from Connection
47 _socket->getEncoder().streamObjectsMessage(gt);
48 _socket->write();
49
50 _stamp = TimeStamp::now();
51
52 // save our serial-no (so we can identify replies)
53 _queryNo = gt->getSerialno();
54
55 m_completeTimer.expires_from_now(std::chrono::seconds(10));
56 m_completeTimer.async_wait([&](boost::system::error_code ec) {
57 if (!ec) {
58 this->onQueryTimeout();
59 }
60 });
61
62}
63
64void MetaQuery::dispatch() {
65 _meta.dispatch();
66}
67
68long MetaQuery::getElapsed() {
69 return (TimeStamp::now() - _stamp).milliseconds();
70}
71
72void MetaQuery::handleFailure(const std::string& msg) {
73 _meta.queryFailure(this, msg);
74}
75
76void MetaQuery::handleTimeout(const std::string&) {
77 _meta.queryTimeout(this);
78}
79
80void MetaQuery::onQueryTimeout() {
81 _meta.queryTimeout(this);
82}
83
84void MetaQuery::setComplete() {
85 assert(!m_complete);
86 m_complete = true;
87 m_completeTimer.cancel();
88}
89
90} // of namsespace
Definition: Account.cpp:33
std::int64_t getNewSerialno()
operation serial number sequencing
Definition: Connection.cpp:390