/
GetChannelSize.d
106 lines (71 loc) · 3.38 KB
/
GetChannelSize.d
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
/*******************************************************************************
Protocol base for DHT `GetChannelSize` request
Copyright:
Copyright (c) 2015-2017 dunnhumby Germany GmbH. All rights reserved.
License:
Boost Software License Version 1.0. See LICENSE.txt for details.
*******************************************************************************/
module dhtproto.node.request.GetChannelSize;
/*******************************************************************************
Imports
*******************************************************************************/
import ocean.transition;
import dhtproto.node.request.model.SingleChannel;
/*******************************************************************************
RemoveChannel request protocol
*******************************************************************************/
public abstract scope class GetChannelSize : SingleChannel
{
import dhtproto.node.request.model.DhtCommand;
import dhtproto.client.legacy.DhtConst;
/***************************************************************************
Constructor
Params:
reader = FiberSelectReader instance to use for read requests
writer = FiberSelectWriter instance to use for write requests
resources = object providing resource getters
***************************************************************************/
public this ( FiberSelectReader reader, FiberSelectWriter writer,
DhtCommand.Resources resources )
{
super(DhtConst.Command.E.GetChannelSize, reader, writer, resources);
}
/***************************************************************************
Payload struct that will hold requesed data
***************************************************************************/
protected struct ChannelSizeData
{
mstring address;
ushort port;
ulong records;
ulong bytes;
}
/***************************************************************************
Replies with ChannelSizeData content as appropriate
Params:
channel_name = name of channel to be queried
***************************************************************************/
final override protected void handleChannelRequest ( cstring channel_name )
{
this.writer.write(DhtConst.Status.E.Ok);
this.getChannelData(channel_name,
( ChannelSizeData data )
{
// TODO: is there a need to send the addr/port?
// surely the client knows this anyway?
this.writer.writeArray(data.address);
this.writer.write(data.port);
this.writer.write(data.records);
this.writer.write(data.bytes);
});
}
/***************************************************************************
Gets the size metadata for specified channel. Overriden in
actual implementors of dhtnode protocol.
Params:
channel_name = name of channel to be queried
value_getter_dg = The delegate that is called with the channel data.
***************************************************************************/
abstract protected void getChannelData ( cstring channel_name,
scope void delegate ( ChannelSizeData ) value_getter_dg );
}