Skip to content

Commit 67a5c2e

Browse files
authored
Merge pull request #11 from JoyStream/development
v0.1.3
2 parents ac71908 + a65cf41 commit 67a5c2e

12 files changed

Lines changed: 243 additions & 1 deletion

conan_package/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class ProtocolWireBase(ConanFile):
55
name = "ProtocolWire"
6-
version = "0.1.2"
6+
version = "0.1.3"
77
license = "(c) JoyStream Inc. 2016-2017"
88
url = "https://github.com/JoyStream/protocol_wire-cpp.git"
99
repo_ssh_url = "git@github.com:JoyStream/protocol_wire-cpp.git"

sources/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ set(
3232
src/char_array_buffer.cpp
3333
src/BinaryStreamWriter.cpp
3434
src/BinaryStreamReader.cpp
35+
src/SpeedTestRequest.cpp
36+
src/SpeedTestPayload.cpp
3537
)
3638

3739
# === build library ===

sources/include/protocol_wire/InputWireStream.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class Ready;
2323
class RequestFullPiece;
2424
class FullPiece;
2525
class Payment;
26+
class SpeedTestRequest;
27+
class SpeedTestPayload;
2628

2729
class PieceData;
2830
class BuyerTerms;
@@ -43,6 +45,8 @@ class InputWireStream : public BinaryStreamReader {
4345
RequestFullPiece readRequestFullPiece();
4446
FullPiece readFullPiece();
4547
Payment readPayment();
48+
SpeedTestRequest readSpeedTestRequest();
49+
SpeedTestPayload readSpeedTestPayload();
4650

4751
private:
4852

sources/include/protocol_wire/OutputWireStream.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Ready;
2424
class RequestFullPiece;
2525
class FullPiece;
2626
class Payment;
27+
class SpeedTestRequest;
28+
class SpeedTestPayload;
2729

2830
class PieceData;
2931
class BuyerTerms;
@@ -44,6 +46,8 @@ class OutputWireStream : public BinaryStreamWriter {
4446
std::streamsize write(const RequestFullPiece&);
4547
std::streamsize write(const FullPiece&);
4648
std::streamsize write(const Payment&);
49+
std::streamsize write(const SpeedTestRequest&);
50+
std::streamsize write(const SpeedTestPayload&);
4751

4852
template<class T>
4953
static std::streamsize sizeOf(const T& msg) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (C) JoyStream - All Rights Reserved
3+
*/
4+
5+
#ifndef JOYSTREAM_PROTOCOL_WIRE_SPEED_TEST_PAYLOAD_HPP
6+
#define JOYSTREAM_PROTOCOL_WIRE_SPEED_TEST_PAYLOAD_HPP
7+
8+
#include <stdint.h>
9+
#include <iostream>
10+
11+
namespace joystream {
12+
namespace protocol_wire {
13+
14+
class SpeedTestPayload {
15+
16+
public:
17+
18+
// Default constructor
19+
SpeedTestPayload();
20+
21+
SpeedTestPayload(const uint32_t payloadSize);
22+
23+
bool operator==(const SpeedTestPayload &) const;
24+
25+
// Getters and setters
26+
uint32_t payloadSize() const;
27+
void setPayloadSize(const uint32_t);
28+
29+
// Overload the << operator for easiness in debugging with GTest
30+
friend std::ostream& operator<<(std::ostream &os, const SpeedTestPayload &obj);
31+
32+
private:
33+
34+
// Size of the speedtest payload to send
35+
uint32_t _payloadSize;
36+
};
37+
38+
}
39+
}
40+
41+
#endif // JOYSTREAM_PROTOCOL_WIRE_BUY_HPP
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (C) JoyStream - All Rights Reserved
3+
*/
4+
5+
#ifndef JOYSTREAM_PROTOCOL_WIRE_SPEED_TEST_REQUEST_HPP
6+
#define JOYSTREAM_PROTOCOL_WIRE_SPEED_TEST_REQUEST_HPP
7+
8+
#include <stdint.h>
9+
#include <iostream>
10+
11+
namespace joystream {
12+
namespace protocol_wire {
13+
14+
class SpeedTestRequest {
15+
16+
public:
17+
18+
// Default constructor
19+
SpeedTestRequest();
20+
21+
SpeedTestRequest(const uint32_t payloadSize);
22+
23+
bool operator==(const SpeedTestRequest &) const;
24+
25+
// Getters and setters
26+
uint32_t payloadSize() const;
27+
void setPayloadSize(const uint32_t);
28+
29+
// Overload the << operator for easiness in debugging with GTest
30+
friend std::ostream& operator<<(std::ostream &os, const SpeedTestRequest &obj);
31+
32+
private:
33+
34+
// Size of the speedtest payload to send
35+
uint32_t _payloadSize;
36+
};
37+
38+
}
39+
}
40+
41+
#endif // JOYSTREAM_PROTOCOL_WIRE_BUY_HPP

sources/include/protocol_wire/protocol_wire.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@
2323
#include <protocol_wire/NetworkInt.hpp>
2424
#include <protocol_wire/InputWireStream.hpp>
2525
#include <protocol_wire/OutputWireStream.hpp>
26+
#include <protocol_wire/SpeedTestRequest.hpp>
27+
#include <protocol_wire/SpeedTestPayload.hpp>
2628

2729
#endif // JOYSTREAM_PROTOCOLWIRE_HPP

sources/src/InputWireStream.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <protocol_wire/RequestFullPiece.hpp>
1010
#include <protocol_wire/FullPiece.hpp>
1111
#include <protocol_wire/Payment.hpp>
12+
#include <protocol_wire/SpeedTestRequest.hpp>
13+
#include <protocol_wire/SpeedTestPayload.hpp>
1214

1315
namespace joystream {
1416
namespace protocol_wire {
@@ -117,6 +119,34 @@ Payment InputWireStream::readPayment() {
117119
return payment;
118120
}
119121

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+
120150
Coin::PubKeyHash InputWireStream::readPubKeyHash() {
121151
Coin::PubKeyHash hash;
122152
readBytes(hash.data(), hash.rawLength());

sources/src/OutputWireStream.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <protocol_wire/RequestFullPiece.hpp>
1010
#include <protocol_wire/FullPiece.hpp>
1111
#include <protocol_wire/Payment.hpp>
12+
#include <protocol_wire/SpeedTestRequest.hpp>
13+
#include <protocol_wire/SpeedTestPayload.hpp>
1214

1315
namespace joystream {
1416
namespace protocol_wire {
@@ -83,6 +85,22 @@ std::streamsize OutputWireStream::write(const Payment &payment) {
8385
return writeSignature(payment.sig());
8486
}
8587

88+
std::streamsize OutputWireStream::write(const SpeedTestRequest &speedTestRequest) {
89+
return writeInt<uint32_t>(speedTestRequest.payloadSize());
90+
}
91+
92+
std::streamsize OutputWireStream::write(const SpeedTestPayload &speedTestPayload) {
93+
std::streamsize written = 0;
94+
95+
// Initialize payload to 0xff (we don't want to send a dump of our memory to the other side)
96+
std::vector<unsigned char> payload(speedTestPayload.payloadSize(), 0xff);
97+
98+
written += writeInt<uint32_t>(speedTestPayload.payloadSize());
99+
written += writeBytes(payload);
100+
101+
return written;
102+
}
103+
86104
std::streamsize OutputWireStream::writePubKeyHash(const Coin::PubKeyHash& hash) {
87105
return writeBytes(hash.data(), hash.rawLength());
88106
}

sources/src/SpeedTestPayload.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (C) JoyStream - All Rights Reserved
3+
* Unauthorized copying of this file, via any medium is strictly prohibited
4+
* Proprietary and confidential
5+
* Written by Bedeho Mender <bedeho.mender@gmail.com>, June 26 2015
6+
*/
7+
8+
#include <protocol_wire/SpeedTestPayload.hpp>
9+
10+
namespace joystream {
11+
namespace protocol_wire {
12+
13+
SpeedTestPayload::SpeedTestPayload() :
14+
_payloadSize(0) {
15+
16+
}
17+
18+
SpeedTestPayload::SpeedTestPayload(const uint32_t payloadSize)
19+
: _payloadSize(payloadSize) {
20+
}
21+
22+
bool SpeedTestPayload::operator==(const SpeedTestPayload & o) const {
23+
return _payloadSize == o.payloadSize();
24+
}
25+
26+
uint32_t SpeedTestPayload::payloadSize() const {
27+
return _payloadSize;
28+
}
29+
30+
void SpeedTestPayload::setPayloadSize(const uint32_t payloadSize) {
31+
_payloadSize = payloadSize;
32+
}
33+
34+
std::ostream& operator<<(std::ostream &os, const SpeedTestPayload &obj)
35+
{
36+
return os << "SpeedTestPayload payloadSize = " << obj.payloadSize();
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)