|
9 | 9 | #include <protocol_wire/RequestFullPiece.hpp> |
10 | 10 | #include <protocol_wire/FullPiece.hpp> |
11 | 11 | #include <protocol_wire/Payment.hpp> |
| 12 | +#include <protocol_wire/SpeedTestRequest.hpp> |
| 13 | +#include <protocol_wire/SpeedTestPayload.hpp> |
12 | 14 |
|
13 | 15 | namespace joystream { |
14 | 16 | namespace protocol_wire { |
@@ -117,6 +119,34 @@ Payment InputWireStream::readPayment() { |
117 | 119 | return payment; |
118 | 120 | } |
119 | 121 |
|
| 122 | +SpeedTestRequest InputWireStream::readSpeedTestRequest() { |
| 123 | + SpeedTestRequest request; |
| 124 | + |
| 125 | + auto value = readInt<decltype(request.payloadSize())>(); |
| 126 | + |
| 127 | + request.setPayloadSize(value); |
| 128 | + |
| 129 | + return request; |
| 130 | +} |
| 131 | + |
| 132 | +SpeedTestPayload InputWireStream::readSpeedTestPayload() { |
| 133 | + SpeedTestPayload payload; |
| 134 | + |
| 135 | + auto size = readInt<uint32_t>(); |
| 136 | + |
| 137 | + // check max size limit? |
| 138 | + if(size > _buffer->in_avail()) { |
| 139 | + throw std::runtime_error("unable to read speedtest payload, not enough data in stream buffer"); |
| 140 | + } |
| 141 | + |
| 142 | + // skip over the data, we don't actually care what the payload is, just that it was sent |
| 143 | + _buffer->pubseekoff(size, std::ios_base::cur, std::ios_base::in); |
| 144 | + |
| 145 | + payload.setPayloadSize(size); |
| 146 | + |
| 147 | + return payload; |
| 148 | +} |
| 149 | + |
120 | 150 | Coin::PubKeyHash InputWireStream::readPubKeyHash() { |
121 | 151 | Coin::PubKeyHash hash; |
122 | 152 | readBytes(hash.data(), hash.rawLength()); |
|
0 commit comments