Skip to content

Commit 3f0de5c

Browse files
authored
Merge pull request #18 from JoyStream/development
v0.3.1
2 parents 589f358 + 73f9aa8 commit 3f0de5c

33 files changed

Lines changed: 737 additions & 9 deletions

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 ProtocolStateMachineBase(ConanFile):
55
name = "ProtocolStateMachine"
6-
version = "0.3.0"
6+
version = "0.3.1"
77
license = "(c) JoyStream Inc. 2016-2017"
88
url = "https://github.com/JoyStream/protocol_statemachine-cpp.git"
99
repo_ssh_url = "git@github.com:JoyStream/protocol_statemachine-cpp.git"
1010
repo_https_url = "https://github.com/JoyStream/protocol_statemachine-cpp.git"
1111
settings = "os", "compiler", "build_type", "arch"
1212
generators = "cmake"
13-
requires = "ProtocolWire/0.1.2@joystream/stable", "PaymentChannel/0.2.0@joystream/stable", "Common/0.2.0@joystream/stable"
13+
requires = "ProtocolWire/0.1.3@joystream/stable", "PaymentChannel/0.2.0@joystream/stable", "Common/0.2.0@joystream/stable"
1414
build_policy = "missing"
1515

1616
def source(self):

sources/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
22

33
project(ProtocoStateMachine CXX)
44

5-
add_definitions(-DMAJOR_PROTOCOL_VERSION=3)
5+
add_definitions(-DMAJOR_PROTOCOL_VERSION=4)
66
add_definitions(-DMINOR_PROTOCOL_VERSION=0)
77

88
option(build_tests "build tests" OFF)
@@ -24,9 +24,13 @@ set(
2424
src/event/Joined.cpp
2525
src/event/PieceLoaded.cpp
2626
src/event/InviteSeller.cpp
27+
src/event/TestSellerSpeed.cpp
28+
src/event/SendTestPayload.cpp
2729
src/exception/InvitedToJoinContractByNonBuyer.cpp
2830
src/exception/StateIncompatibleEvent.cpp
2931
src/exception/CannotInviteNonSeller.cpp
32+
src/exception/CannotSpeedTestNonSeller.cpp
33+
src/exception/SpeedTestRequestedByNonBuyer.cpp
3034
src/detail/InitializeBuying.cpp
3135
src/detail/InitializeSelling.cpp
3236
src/AnnouncedModeAndTerms.cpp
@@ -46,6 +50,8 @@ set(
4650
src/SellerHasJoined.cpp
4751
src/PreparingContract.cpp
4852
src/RequestingPieces.cpp
53+
src/TestingSellerSpeed.cpp
54+
src/ReadyToSendTestPayload.cpp
4955
)
5056

5157
# === build library ===

sources/include/protocol_statemachine/Buying.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ namespace protocol_statemachine {
2525
typedef boost::mpl::list<
2626
sc::custom_reaction<event::ObserveModeStarted>,
2727
sc::custom_reaction<event::SellModeStarted>,
28-
sc::custom_reaction<event::UpdateTerms<protocol_wire::BuyerTerms>>
28+
sc::custom_reaction<event::UpdateTerms<protocol_wire::BuyerTerms>>,
29+
sc::custom_reaction<event::Recv<protocol_wire::Observe>>,
30+
sc::custom_reaction<event::Recv<protocol_wire::Buy>>,
31+
sc::custom_reaction<event::Recv<protocol_wire::Sell>>
2932
> reactions;
3033

3134
Buying();
@@ -34,6 +37,9 @@ namespace protocol_statemachine {
3437
sc::result react(const event::ObserveModeStarted &);
3538
sc::result react(const event::SellModeStarted &);
3639
sc::result react(const event::UpdateTerms<protocol_wire::BuyerTerms> &);
40+
sc::result react(const event::Recv<protocol_wire::Observe> &);
41+
sc::result react(const event::Recv<protocol_wire::Buy> &);
42+
sc::result react(const event::Recv<protocol_wire::Sell> &);
3743

3844
private:
3945
};

sources/include/protocol_statemachine/CBStateMachine.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace protocol_wire {
3333
class BuyerTerms;
3434
class Ready;
3535
class PieceData;
36+
class SpeedTestRequest;
37+
class SpeedTestPayload;
3638
}
3739

3840
namespace protocol_statemachine {
@@ -55,6 +57,8 @@ namespace protocol_statemachine {
5557
typedef std::function<void(const protocol_wire::RequestFullPiece&)> SendRequestFullPieceMessage;
5658
typedef std::function<void(const protocol_wire::FullPiece&)> SendFullPieceMessage;
5759
typedef std::function<void(const protocol_wire::Payment&)> SendPaymentMessage;
60+
typedef std::function<void(const protocol_wire::SpeedTestRequest&)> SendSpeedTestRequestMessage;
61+
typedef std::function<void(const protocol_wire::SpeedTestPayload&)> SendSpeedTestPayloadMessage;
5862

5963
struct Send {
6064
SendObserveMessage observe;
@@ -66,6 +70,8 @@ namespace protocol_statemachine {
6670
SendRequestFullPieceMessage request_full_piece;
6771
SendFullPieceMessage full_piece;
6872
SendPaymentMessage payment;
73+
SendSpeedTestRequestMessage speedTestRequest;
74+
SendSpeedTestPayloadMessage speedTestPayload;
6975
};
7076

7177
//// Selling Notifications
@@ -94,8 +100,14 @@ namespace protocol_statemachine {
94100
// Peer sent an invalid payment signature
95101
typedef std::function<void(const Coin::Signature &)> InvalidPayment;
96102

103+
// Peer requested speed test
104+
typedef std::function<void(uint32_t)> BuyerRequestedSpeedTest;
105+
97106
//// Buying Notifications
98107

108+
// Peer sent the speedtest payload
109+
typedef std::function<void(bool)> SellerCompletedSpeedTest;
110+
99111
// Peer, in seller mode, joined the most recent invitation
100112
typedef NoPayloadNotification SellerJoined;
101113

@@ -140,6 +152,8 @@ namespace protocol_statemachine {
140152
const ReceivedFullPiece &,
141153
const MessageOverflow &,
142154
const MessageOverflow &,
155+
const SellerCompletedSpeedTest &,
156+
const BuyerRequestedSpeedTest &,
143157
int,
144158
Coin::Network network);
145159

@@ -190,10 +204,12 @@ namespace protocol_statemachine {
190204
friend class WaitingToStart;
191205
friend class StartedSelling;
192206
friend class ServicingPieceRequests;
207+
friend class ReadyToSendTestPayload;
193208

194209
// Buying states
195210
friend class Buying;
196211
friend class ReadyToInviteSeller;
212+
friend class TestingSellerSpeed;
197213
friend class WaitingForSellerToJoin;
198214
friend class PreparingContract;
199215
friend class SellerHasJoined;
@@ -211,6 +227,11 @@ namespace protocol_statemachine {
211227
void clientToSellMode(const protocol_wire::SellerTerms &, uint32_t = 0);
212228
void clientToBuyMode(const protocol_wire::BuyerTerms &);
213229

230+
// Speed testing
231+
void sentSpeedTestRequest(uint32_t);
232+
void receivedTestPayload(uint32_t);
233+
void buyerRequestedSpeedTest(uint32_t);
234+
214235
//// Callbacks
215236

216237
// All callbacks are initiated when state machine has finished all processing.
@@ -263,6 +284,8 @@ namespace protocol_statemachine {
263284
CallbackQueuer<const protocol_wire::RequestFullPiece&> _sendRequestFullPieceMessage;
264285
CallbackQueuer<const protocol_wire::FullPiece&> _sendFullPieceMessage;
265286
CallbackQueuer<const protocol_wire::Payment&> _sendPaymentMessage;
287+
CallbackQueuer<const protocol_wire::SpeedTestRequest&> _sendSpeedTestRequestMessage;
288+
CallbackQueuer<const protocol_wire::SpeedTestPayload&> _sendSpeedTestPayloadMessage;
266289

267290
CallbackQueuer<uint64_t, const Coin::typesafeOutPoint &, const Coin::PublicKey &, const Coin::PubKeyHash &> _contractIsReady;
268291
CallbackQueuer<int> _pieceRequested;
@@ -275,6 +298,8 @@ namespace protocol_statemachine {
275298
CallbackQueuer<const protocol_wire::PieceData &> _receivedFullPiece;
276299
CallbackQueuer<> _remoteMessageOverflow;
277300
CallbackQueuer<> _localMessageOverflow;
301+
CallbackQueuer<bool> _sellerCompletedSpeedTest;
302+
CallbackQueuer<uint32_t> _buyerRequestedSpeedTest;
278303

279304
void peerAnnouncedMode();
280305

@@ -300,6 +325,8 @@ namespace protocol_statemachine {
300325

301326
// Index of last piece requested
302327
int _lastRequestedPiece;
328+
329+
uint32_t _requestedTestPayloadSize;
303330
};
304331

305332
template<typename T>

sources/include/protocol_statemachine/ReadyForInvitation.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ namespace protocol_statemachine {
2020
public:
2121

2222
typedef boost::mpl::list<
23-
sc::custom_reaction<event::Recv<protocol_wire::JoinContract>>
23+
sc::custom_reaction<event::Recv<protocol_wire::JoinContract>>,
24+
sc::custom_reaction<event::Recv<protocol_wire::SpeedTestRequest>>
2425
> reactions;
2526

2627
ReadyForInvitation();
2728

2829
// Event handlers
2930
sc::result react(const event::Recv<protocol_wire::JoinContract> &);
31+
sc::result react(const event::Recv<protocol_wire::SpeedTestRequest> &);
3032

3133
};
3234
}

sources/include/protocol_statemachine/ReadyToInviteSeller.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <protocol_statemachine/Buying.hpp>
1212
#include <protocol_statemachine/event/InviteSeller.hpp>
13+
#include <protocol_statemachine/event/TestSellerSpeed.hpp>
1314

1415
namespace joystream {
1516
namespace protocol_statemachine {
@@ -19,13 +20,15 @@ namespace protocol_statemachine {
1920
public:
2021

2122
typedef boost::mpl::list<
22-
sc::custom_reaction<event::InviteSeller>
23+
sc::custom_reaction<event::InviteSeller>,
24+
sc::custom_reaction<event::TestSellerSpeed>
2325
> reactions;
2426

2527
ReadyToInviteSeller();
2628

2729
// Event handlers
2830
sc::result react(const event::InviteSeller &);
31+
sc::result react(const event::TestSellerSpeed &);
2932

3033
};
3134

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (C) JoyStream - All Rights Reserved
3+
*/
4+
5+
#ifndef JOYSTREAM_PROTOCOLSTATEMACHINE_READYTOSENDTESTPAYLOAD_HPP
6+
#define JOYSTREAM_PROTOCOLSTATEMACHINE_READYTOSENDTESTPAYLOAD_HPP
7+
8+
#include <protocol_statemachine/Buying.hpp>
9+
#include <protocol_statemachine/event/SendTestPayload.hpp>
10+
#include <protocol_statemachine/event/Recv.hpp>
11+
#include <protocol_wire/protocol_wire.hpp>
12+
13+
namespace joystream {
14+
namespace protocol_statemachine {
15+
16+
class ReadyToSendTestPayload : public sc::simple_state<ReadyToSendTestPayload, Selling> {
17+
18+
public:
19+
20+
typedef boost::mpl::list<
21+
sc::custom_reaction<event::SendTestPayload>,
22+
sc::custom_reaction<event::Recv<protocol_wire::Buy>>,
23+
sc::custom_reaction<event::UpdateTerms<protocol_wire::SellerTerms>>
24+
> reactions;
25+
26+
ReadyToSendTestPayload();
27+
28+
// Event handlers
29+
sc::result react(const event::SendTestPayload &);
30+
sc::result react(const event::Recv<protocol_wire::Buy> &);
31+
sc::result react(const event::UpdateTerms<protocol_wire::SellerTerms> &);
32+
33+
};
34+
35+
}
36+
}
37+
38+
#endif // JOYSTREAM_PROTOCOLSTATEMACHINE_READYTOSENDTESTPAYLOAD_HPP

sources/include/protocol_statemachine/Selling.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ namespace protocol_statemachine {
3131
typedef boost::mpl::list<
3232
sc::custom_reaction<event::ObserveModeStarted>,
3333
sc::custom_reaction<event::BuyModeStarted>,
34-
sc::custom_reaction<event::UpdateTerms<protocol_wire::SellerTerms>>
34+
sc::custom_reaction<event::UpdateTerms<protocol_wire::SellerTerms>>,
35+
sc::custom_reaction<event::Recv<protocol_wire::Observe>>,
36+
sc::custom_reaction<event::Recv<protocol_wire::Buy>>,
37+
sc::custom_reaction<event::Recv<protocol_wire::Sell>>
3538
> reactions;
3639

3740
Selling();
@@ -40,6 +43,9 @@ namespace protocol_statemachine {
4043
sc::result react(const event::ObserveModeStarted &);
4144
sc::result react(const event::BuyModeStarted &);
4245
sc::result react(const event::UpdateTerms<protocol_wire::SellerTerms> &);
46+
sc::result react(const event::Recv<protocol_wire::Observe> &);
47+
sc::result react(const event::Recv<protocol_wire::Buy> &);
48+
sc::result react(const event::Recv<protocol_wire::Sell> &);
4349

4450
};
4551
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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>, March 24 2016
6+
*/
7+
8+
#ifndef JOYSTREAM_PROTOCOLSTATEMACHINE_TESTINGSELLERSPEED_HPP
9+
#define JOYSTREAM_PROTOCOLSTATEMACHINE_TESTINGSELLERSPEED_HPP
10+
11+
#include <protocol_statemachine/Buying.hpp>
12+
#include <protocol_statemachine/event/Recv.hpp>
13+
#include <protocol_wire/protocol_wire.hpp>
14+
15+
namespace joystream {
16+
namespace protocol_statemachine {
17+
18+
class TestingSellerSpeed : public sc::simple_state<TestingSellerSpeed, Buying> {
19+
20+
public:
21+
22+
typedef boost::mpl::list<
23+
sc::custom_reaction<event::Recv<protocol_wire::SpeedTestPayload>>,
24+
sc::custom_reaction<event::Recv<protocol_wire::Sell>>,
25+
sc::custom_reaction<event::UpdateTerms<protocol_wire::BuyerTerms>>
26+
> reactions;
27+
28+
TestingSellerSpeed();
29+
30+
// Event handlers
31+
sc::result react(const event::Recv<protocol_wire::SpeedTestPayload> &);
32+
sc::result react(const event::Recv<protocol_wire::Sell> &);
33+
sc::result react(const event::UpdateTerms<protocol_wire::BuyerTerms> &);
34+
35+
};
36+
37+
}
38+
}
39+
40+
#endif // JOYSTREAM_PROTOCOLSTATEMACHINE_READYTOINVITESELLER_HPP
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (C) JoyStream - All Rights Reserved
3+
*/
4+
5+
#ifndef JOYSTREAM_PROTOCOLSTATEMACHINE_EVENT_SENDTESTPAYLOAD_HPP
6+
#define JOYSTREAM_PROTOCOLSTATEMACHINE_EVENT_SENDTESTPAYLOAD_HPP
7+
8+
#include <boost/statechart/event.hpp>
9+
10+
namespace sc = boost::statechart;
11+
12+
namespace joystream {
13+
namespace protocol_statemachine {
14+
namespace event {
15+
16+
class SendTestPayload : public sc::event<SendTestPayload> {
17+
18+
public:
19+
20+
SendTestPayload();
21+
22+
};
23+
24+
}
25+
}
26+
}
27+
28+
#endif // JOYSTREAM_PROTOCOLSTATEMACHINE_EVENT_SENDTESTPAYLOAD_HPP

0 commit comments

Comments
 (0)