Skip to content

Commit 0a2d54a

Browse files
authored
Merge pull request #32 from JoyStream/development
dev to master - v0.3.0
2 parents 70668e4 + 7f235f9 commit 0a2d54a

10 files changed

Lines changed: 77 additions & 52 deletions

File tree

conan_package/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
class ProtocolSessionBase(ConanFile):
55
name = "ProtocolSession"
6-
version = "0.2.1"
6+
version = "0.3.0"
77
license = "(c) JoyStream Inc. 2016-2017"
88
url = "https://github.com/JoyStream/protocol_session-cpp.git"
99
repo_ssh_url = "git@github.com:JoyStream/protocol_session-cpp.git"
1010
repo_https_url = "https://github.com/JoyStream/protocol_session-cpp.git"
1111
settings = "os", "compiler", "build_type", "arch"
1212
generators = "cmake"
13-
requires = "ProtocolStateMachine/0.2.0@joystream/stable"
13+
requires = "ProtocolStateMachine/0.3.0@joystream/stable"
1414
build_policy = "missing"
1515

1616
def source(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class ProtocolSessionRelease(ProtocolSessionBase):
1111

1212
exports_sources = "../sources*"
1313

14+
build_policy="always"
15+
1416
def source(self):
1517
os.mkdir("repo")
1618
shutil.move("sources", "repo/")

sources/include/protocol_session/Session.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ namespace protocol_session {
4141
*/
4242

4343
template <class ConnectionIdType>
44-
Session<ConnectionIdType>::Session()
44+
Session<ConnectionIdType>::Session(Coin::Network network)
4545
: _mode(SessionMode::not_set)
4646
, _state(SessionState::stopped)
4747
, _observing(nullptr)
4848
, _selling(nullptr)
49-
, _buying(nullptr) {
49+
, _buying(nullptr)
50+
, _network(network) {
5051

5152
time(&_started);
5253
}
@@ -739,6 +740,11 @@ namespace protocol_session {
739740
(_mode == SessionMode::buying ? _buying->status() : status::Buying<ConnectionIdType>()));
740741
}
741742

743+
template<class ConnectionIdType>
744+
Coin::Network Session<ConnectionIdType>::network() const {
745+
return _network;
746+
}
747+
742748
template<class ConnectionIdType>
743749
void Session<ConnectionIdType>::peerAnnouncedModeAndTerms(const ConnectionIdType & id, const protocol_statemachine::AnnouncedModeAndTerms & a) {
744750

@@ -924,7 +930,8 @@ namespace protocol_session {
924930
[this, id]() { this->sellerHasInterruptedContract(id); },
925931
[this, id](const protocol_wire::PieceData & p) { this->receivedFullPiece(id, p); },
926932
[this, id]() { this->remoteMessageOverflow(id); },
927-
[this, id]() { this->localMessageOverflow(id); });
933+
[this, id]() { this->localMessageOverflow(id); },
934+
_network);
928935
}
929936

930937
template <class ConnectionIdType>

sources/include/protocol_session/Session.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace detail {
5757
static int64_t minimumFundsRequiredAsBuyer(const protocol_wire::BuyerTerms & terms, int numberOfPieces);
5858
*/
5959

60-
Session();
60+
Session(Coin::Network);
6161

6262
~Session();
6363

@@ -203,6 +203,8 @@ namespace detail {
203203
// Status of session
204204
status::Session<ConnectionIdType> status() const noexcept;
205205

206+
Coin::Network network() const;
207+
206208
private:
207209

208210
// Session mode
@@ -217,6 +219,8 @@ namespace detail {
217219
// When session was started
218220
time_t _started;
219221

222+
Coin::Network _network;
223+
220224
//// Substates
221225

222226
// Each pointer is != nullptr only when _mode corresponds

sources/include/protocol_session/Status.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace status {
2424

2525
struct CBStateMachine {
2626

27-
CBStateMachine()
28-
: innerStateTypeIndex(typeid(protocol_statemachine::ChooseMode)) {}
27+
// CBStateMachine()
28+
// : innerStateTypeIndex(typeid(protocol_statemachine::ChooseMode)) {}
2929

3030
CBStateMachine(const std::type_index & innerStateTypeIndex,
3131
const protocol_statemachine::AnnouncedModeAndTerms & announcedModeAndTermsFromPeer,

sources/include/protocol_session/detail/Connection.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace detail {
2929
const protocol_statemachine::SellerInterruptedContract & sellerInterruptedContract,
3030
const protocol_statemachine::ReceivedFullPiece & receivedFullPiece,
3131
const protocol_statemachine::MessageOverflow & remoteMessageOverflow,
32-
const protocol_statemachine::MessageOverflow & localMessageOverflow)
32+
const protocol_statemachine::MessageOverflow & localMessageOverflow,
33+
Coin::Network network)
3334
: _connectionId(connectionId)
3435
, _machine(peerAnnouncedMode,
3536
invitedToOutdatedContract,
@@ -46,7 +47,8 @@ namespace detail {
4647
receivedFullPiece,
4748
remoteMessageOverflow,
4849
localMessageOverflow,
49-
0) {
50+
0,
51+
network) {
5052

5153
// Initiating state machine
5254
_machine.initiate();

sources/include/protocol_session/detail/Connection.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <protocol_statemachine/protocol_statemachine.hpp>
1212
#include <protocol_session/detail/PieceDeliveryPipeline.hpp>
1313

14+
#include <common/Network.hpp>
15+
#include <queue>
16+
1417
namespace joystream {
1518
namespace protocol_wire {
1619
class Message;
@@ -42,7 +45,8 @@ namespace detail {
4245
const protocol_statemachine::SellerInterruptedContract &,
4346
const protocol_statemachine::ReceivedFullPiece &,
4447
const protocol_statemachine::MessageOverflow &,
45-
const protocol_statemachine::MessageOverflow &);
48+
const protocol_statemachine::MessageOverflow &,
49+
Coin::Network network);
4650

4751
// Processes given message
4852
template<class M>

sources/test/SessionTest.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@ namespace protocol_session {
1919
}
2020
}}
2121

22-
SessionTest::SessionTest()
23-
: //network(Coin::Network::testnet3)
24-
session(nullptr)
25-
, spy(nullptr)
26-
, defaultPieceValidationResult(true) {
22+
SessionTest::SessionTest() :
23+
session(nullptr),
24+
spy(nullptr),
25+
defaultPieceValidationResult(true) {
2726
}
2827

29-
void SessionTest::init() {
28+
void SessionTest::init(Coin::Network network) {
3029

3130
// Reset next key counter
3231
nextKey = 1;
3332

34-
session = new Session<ID>();
33+
session = new Session<ID>(network);
3534

3635
spy = new
3736
SessionSpy<ID>(
@@ -116,7 +115,8 @@ paymentchannel::Payor SessionTest::getPayor(const protocol_wire::SellerTerms & s
116115
const protocol_wire::Ready & ready,
117116
const Coin::PrivateKey & payorContractSk,
118117
const Coin::PublicKey & payeeContractPk,
119-
const Coin::PubKeyHash & payeeFinalPkHash) {
118+
const Coin::PubKeyHash & payeeFinalPkHash,
119+
Coin::Network network) {
120120
return paymentchannel::Payor(sellerTerms.minPrice(),
121121
0,
122122
ready.value(),
@@ -126,7 +126,8 @@ paymentchannel::Payor SessionTest::getPayor(const protocol_wire::SellerTerms & s
126126
Coin::KeyPair(payorContractSk),
127127
ready.finalPkHash(),
128128
payeeContractPk,
129-
payeeFinalPkHash);
129+
payeeFinalPkHash,
130+
network);
130131
}
131132

132133
////
@@ -538,7 +539,7 @@ void SessionTest::takeSingleSellerToExchange(SellerPeer & peer) {
538539

539540
// Setup
540541
auto v = { BuyerSellerRelationship(StartDownloadConnectionInformation(peer.terms, 0, 9999999, Coin::KeyPair(nextPrivateKey()), nextPrivateKey().toPublicKey().toPubKeyHash()), peer)};
541-
Coin::Transaction contractTx = simpleContract(v);
542+
Coin::Transaction contractTx = simpleContract(v, session->network());
542543
peer.assertContractValidity(contractTx);
543544
PeerToStartDownloadInformationMap<ID> map = downloadInformationMap(v);
544545

sources/test/SessionTest.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ class SessionTest : public ::testing::Test {
2525
SessionTest();
2626

2727
// Runs before & after each unit, creates/deletes up session and spy
28-
void init();
28+
void init(Coin::Network);
2929
void cleanup();
3030

3131
//private:
3232
//// NB: None of these routines can return values, as they use QTest macroes which dont return this value.
3333

3434
// Variable shared across all units tests
35-
//Coin::Network network;
3635
Session<ID> * session;
3736
SessionSpy<ID> * spy;
3837

@@ -49,7 +48,8 @@ class SessionTest : public ::testing::Test {
4948
const protocol_wire::Ready &,
5049
const Coin::PrivateKey &,
5150
const Coin::PublicKey &,
52-
const Coin::PubKeyHash &payeeFinalPkHash);
51+
const Coin::PubKeyHash &payeeFinalPkHash,
52+
Coin::Network network);
5353

5454
//// Routines for doing spesific set of tests which can be used across number of cases
5555
//// Spy is always reset, if affected, by each call
@@ -147,11 +147,15 @@ class SessionTest : public ::testing::Test {
147147
protocol_wire::Ready ready;
148148
paymentchannel::Payee payee;
149149

150-
SellerPeer(ID id, protocol_wire::SellerTerms terms, uint32_t sellerTermsIndex)
150+
Coin::Network network;
151+
152+
SellerPeer(ID id, protocol_wire::SellerTerms terms, uint32_t sellerTermsIndex, Coin::Network network)
151153
: id(id)
152154
, terms(terms)
153155
, sellerTermsIndex(sellerTermsIndex)
154-
, spy(nullptr) {
156+
, spy(nullptr)
157+
, network(network)
158+
, payee(network) {
155159
}
156160
protocol_wire::JoiningContract setJoiningContract() {
157161
contractKeys = Coin::KeyPair::generate();
@@ -166,7 +170,7 @@ class SessionTest : public ::testing::Test {
166170
auto slot = spy->sendReadyCallbackSlot;
167171
EXPECT_GT((int)slot.size(), 0);
168172
ready = std::get<0>(slot.front());
169-
payee = getPayee();
173+
payee = getPayee(network);
170174
// Remove message at front
171175
slot.pop_front();
172176
}
@@ -187,7 +191,7 @@ class SessionTest : public ::testing::Test {
187191
return spy->sendRequestFullPieceCallbackSlot.size() > 0;
188192
}
189193

190-
paymentchannel::Payee getPayee() {
194+
paymentchannel::Payee getPayee(Coin::Network network) {
191195
return paymentchannel::Payee(0,
192196
Coin::RelativeLockTime::fromTimeUnits(terms.minLock()),
193197
terms.minPrice(),
@@ -198,13 +202,14 @@ class SessionTest : public ::testing::Test {
198202
joiningContract.finalPkHash(),
199203
ready.contractPk(),
200204
ready.finalPkHash(),
201-
Coin::Signature());
205+
Coin::Signature(),
206+
network);
202207
}
203208
};
204209

205210
typedef std::pair<StartDownloadConnectionInformation, SellerPeer> BuyerSellerRelationship;
206211

207-
static Coin::Transaction simpleContract(const std::vector<BuyerSellerRelationship> & v) {
212+
static Coin::Transaction simpleContract(const std::vector<BuyerSellerRelationship> & v, Coin::Network network) {
208213
paymentchannel::ContractTransactionBuilder::Commitments commitments;
209214
for(auto s : v) {
210215
StartDownloadConnectionInformation inf = s.first;
@@ -216,7 +221,7 @@ class SessionTest : public ::testing::Test {
216221
paymentchannel::ContractTransactionBuilder builder;
217222
builder.setCommitments(commitments);
218223

219-
return builder.transaction();
224+
return builder.transaction(network);
220225
}
221226

222227
static PeerToStartDownloadInformationMap<ID> downloadInformationMap(const std::vector<BuyerSellerRelationship> & v) noexcept {

0 commit comments

Comments
 (0)