forked from tjjh89017/ezio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.cpp
56 lines (46 loc) · 1.45 KB
/
service.cpp
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
#include "service.hpp"
EZIOServiceImpl::EZIOServiceImpl(lt::session &tmp) : ses(tmp) {}
Status EZIOServiceImpl::GetTorrentStatus(ServerContext* context, const UpdateRequest* request, UpdateStatus* status)
{
// get status from session
// we ignore request hashes first, always return all
auto hash = request->hashes();
for(auto h : hash){
//std::cout << h << std::endl;
// do some filter for below
}
auto &t_stats = *status->mutable_torrents();
std::stringstream ss;
std::vector<lt::torrent_handle> torrents = ses.get_torrents();
for(lt::torrent_handle const &h : torrents) {
auto hash = status->add_hashes();
ss << h.info_hash();
ss >> *hash;
//std::cout << *hash << std::endl;
// disable those info we don't need
lt::torrent_status t_stat = h.status(0);
//std::cout << t_stat.download_payload_rate << std::endl;
//std::cout << t_stat.upload_payload_rate << std::endl;
//std::cout << t_stat.progress << std::endl;
Torrent t;;
t.set_hash(*hash);
t.set_progress(t_stat.progress);
t.set_download(t_stat.download_payload_rate);
t.set_upload(t_stat.upload_payload_rate);
t_stats[*hash] = t;
}
return Status::OK;
}
gRPCService::gRPCService(lt::session &tmp) :
server_address("0.0.0.0:50051"),
service(tmp)
{
ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
server = builder.BuildAndStart();
}
void gRPCService::stop()
{
server->Shutdown();
}