Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conan_package/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

class ProtocolSessionBase(ConanFile):
name = "ProtocolSession"
version = "0.2.1"
version = "0.3.0"
license = "(c) JoyStream Inc. 2016-2017"
url = "https://github.com/JoyStream/protocol_session-cpp.git"
repo_ssh_url = "git@github.com:JoyStream/protocol_session-cpp.git"
repo_https_url = "https://github.com/JoyStream/protocol_session-cpp.git"
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
requires = "ProtocolStateMachine/0.2.0@joystream/stable"
requires = "ProtocolStateMachine/0.3.0@joystream/stable"
build_policy = "missing"

def source(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ProtocolSessionRelease(ProtocolSessionBase):

exports_sources = "../sources*"

build_policy="always"

def source(self):
os.mkdir("repo")
shutil.move("sources", "repo/")
13 changes: 10 additions & 3 deletions sources/include/protocol_session/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ namespace protocol_session {
*/

template <class ConnectionIdType>
Session<ConnectionIdType>::Session()
Session<ConnectionIdType>::Session(Coin::Network network)
: _mode(SessionMode::not_set)
, _state(SessionState::stopped)
, _observing(nullptr)
, _selling(nullptr)
, _buying(nullptr) {
, _buying(nullptr)
, _network(network) {

time(&_started);
}
Expand Down Expand Up @@ -739,6 +740,11 @@ namespace protocol_session {
(_mode == SessionMode::buying ? _buying->status() : status::Buying<ConnectionIdType>()));
}

template<class ConnectionIdType>
Coin::Network Session<ConnectionIdType>::network() const {
return _network;
}

template<class ConnectionIdType>
void Session<ConnectionIdType>::peerAnnouncedModeAndTerms(const ConnectionIdType & id, const protocol_statemachine::AnnouncedModeAndTerms & a) {

Expand Down Expand Up @@ -924,7 +930,8 @@ namespace protocol_session {
[this, id]() { this->sellerHasInterruptedContract(id); },
[this, id](const protocol_wire::PieceData & p) { this->receivedFullPiece(id, p); },
[this, id]() { this->remoteMessageOverflow(id); },
[this, id]() { this->localMessageOverflow(id); });
[this, id]() { this->localMessageOverflow(id); },
_network);
}

template <class ConnectionIdType>
Expand Down
6 changes: 5 additions & 1 deletion sources/include/protocol_session/Session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace detail {
static int64_t minimumFundsRequiredAsBuyer(const protocol_wire::BuyerTerms & terms, int numberOfPieces);
*/

Session();
Session(Coin::Network);

~Session();

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

Coin::Network network() const;

private:

// Session mode
Expand All @@ -217,6 +219,8 @@ namespace detail {
// When session was started
time_t _started;

Coin::Network _network;

//// Substates

// Each pointer is != nullptr only when _mode corresponds
Expand Down
4 changes: 2 additions & 2 deletions sources/include/protocol_session/Status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace status {

struct CBStateMachine {

CBStateMachine()
: innerStateTypeIndex(typeid(protocol_statemachine::ChooseMode)) {}
// CBStateMachine()
// : innerStateTypeIndex(typeid(protocol_statemachine::ChooseMode)) {}

CBStateMachine(const std::type_index & innerStateTypeIndex,
const protocol_statemachine::AnnouncedModeAndTerms & announcedModeAndTermsFromPeer,
Expand Down
6 changes: 4 additions & 2 deletions sources/include/protocol_session/detail/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace detail {
const protocol_statemachine::SellerInterruptedContract & sellerInterruptedContract,
const protocol_statemachine::ReceivedFullPiece & receivedFullPiece,
const protocol_statemachine::MessageOverflow & remoteMessageOverflow,
const protocol_statemachine::MessageOverflow & localMessageOverflow)
const protocol_statemachine::MessageOverflow & localMessageOverflow,
Coin::Network network)
: _connectionId(connectionId)
, _machine(peerAnnouncedMode,
invitedToOutdatedContract,
Expand All @@ -46,7 +47,8 @@ namespace detail {
receivedFullPiece,
remoteMessageOverflow,
localMessageOverflow,
0) {
0,
network) {

// Initiating state machine
_machine.initiate();
Expand Down
6 changes: 5 additions & 1 deletion sources/include/protocol_session/detail/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <protocol_statemachine/protocol_statemachine.hpp>
#include <protocol_session/detail/PieceDeliveryPipeline.hpp>

#include <common/Network.hpp>
#include <queue>

namespace joystream {
namespace protocol_wire {
class Message;
Expand Down Expand Up @@ -42,7 +45,8 @@ namespace detail {
const protocol_statemachine::SellerInterruptedContract &,
const protocol_statemachine::ReceivedFullPiece &,
const protocol_statemachine::MessageOverflow &,
const protocol_statemachine::MessageOverflow &);
const protocol_statemachine::MessageOverflow &,
Coin::Network network);

// Processes given message
template<class M>
Expand Down
21 changes: 11 additions & 10 deletions sources/test/SessionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ namespace protocol_session {
}
}}

SessionTest::SessionTest()
: //network(Coin::Network::testnet3)
session(nullptr)
, spy(nullptr)
, defaultPieceValidationResult(true) {
SessionTest::SessionTest() :
session(nullptr),
spy(nullptr),
defaultPieceValidationResult(true) {
}

void SessionTest::init() {
void SessionTest::init(Coin::Network network) {

// Reset next key counter
nextKey = 1;

session = new Session<ID>();
session = new Session<ID>(network);

spy = new
SessionSpy<ID>(
Expand Down Expand Up @@ -116,7 +115,8 @@ paymentchannel::Payor SessionTest::getPayor(const protocol_wire::SellerTerms & s
const protocol_wire::Ready & ready,
const Coin::PrivateKey & payorContractSk,
const Coin::PublicKey & payeeContractPk,
const Coin::PubKeyHash & payeeFinalPkHash) {
const Coin::PubKeyHash & payeeFinalPkHash,
Coin::Network network) {
return paymentchannel::Payor(sellerTerms.minPrice(),
0,
ready.value(),
Expand All @@ -126,7 +126,8 @@ paymentchannel::Payor SessionTest::getPayor(const protocol_wire::SellerTerms & s
Coin::KeyPair(payorContractSk),
ready.finalPkHash(),
payeeContractPk,
payeeFinalPkHash);
payeeFinalPkHash,
network);
}

////
Expand Down Expand Up @@ -538,7 +539,7 @@ void SessionTest::takeSingleSellerToExchange(SellerPeer & peer) {

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

Expand Down
25 changes: 15 additions & 10 deletions sources/test/SessionTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ class SessionTest : public ::testing::Test {
SessionTest();

// Runs before & after each unit, creates/deletes up session and spy
void init();
void init(Coin::Network);
void cleanup();

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

// Variable shared across all units tests
//Coin::Network network;
Session<ID> * session;
SessionSpy<ID> * spy;

Expand All @@ -49,7 +48,8 @@ class SessionTest : public ::testing::Test {
const protocol_wire::Ready &,
const Coin::PrivateKey &,
const Coin::PublicKey &,
const Coin::PubKeyHash &payeeFinalPkHash);
const Coin::PubKeyHash &payeeFinalPkHash,
Coin::Network network);

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

SellerPeer(ID id, protocol_wire::SellerTerms terms, uint32_t sellerTermsIndex)
Coin::Network network;

SellerPeer(ID id, protocol_wire::SellerTerms terms, uint32_t sellerTermsIndex, Coin::Network network)
: id(id)
, terms(terms)
, sellerTermsIndex(sellerTermsIndex)
, spy(nullptr) {
, spy(nullptr)
, network(network)
, payee(network) {
}
protocol_wire::JoiningContract setJoiningContract() {
contractKeys = Coin::KeyPair::generate();
Expand All @@ -166,7 +170,7 @@ class SessionTest : public ::testing::Test {
auto slot = spy->sendReadyCallbackSlot;
EXPECT_GT((int)slot.size(), 0);
ready = std::get<0>(slot.front());
payee = getPayee();
payee = getPayee(network);
// Remove message at front
slot.pop_front();
}
Expand All @@ -187,7 +191,7 @@ class SessionTest : public ::testing::Test {
return spy->sendRequestFullPieceCallbackSlot.size() > 0;
}

paymentchannel::Payee getPayee() {
paymentchannel::Payee getPayee(Coin::Network network) {
return paymentchannel::Payee(0,
Coin::RelativeLockTime::fromTimeUnits(terms.minLock()),
terms.minPrice(),
Expand All @@ -198,13 +202,14 @@ class SessionTest : public ::testing::Test {
joiningContract.finalPkHash(),
ready.contractPk(),
ready.finalPkHash(),
Coin::Signature());
Coin::Signature(),
network);
}
};

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

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

return builder.transaction();
return builder.transaction(network);
}

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