Skip to content

Commit

Permalink
Watch lottery pots to verify client has the money.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Dec 12, 2019
1 parent 86e525b commit 2ca478e
Show file tree
Hide file tree
Showing 32 changed files with 471 additions and 129 deletions.
11 changes: 8 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: all

all: cli-shared
all: all-cli-lnx
all: all-cli-mac

all: all-app-ios
all: all-app-sim
Expand All @@ -15,8 +16,12 @@ all: all-srv-mac
tst-ethereum:
$(MAKE) -C tst-ethereum test

.PHONY: cli-shared
cli-shared:
.PHONY: all-cli-lnx
all-cli-lnx:
$(MAKE) -C cli-shared target=lnx

.PHONY: all-cli-mac
all-cli-mac:
$(MAKE) -C cli-shared target=mac

.PHONY: all-srv-and
Expand Down
2 changes: 1 addition & 1 deletion p2p/source/adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Adapter :
size_t offset_ = 0;

protected:
virtual Pump *Inner() = 0;
virtual Pump<Buffer> *Inner() = 0;

void Land(const Buffer &data) override {
std::unique_lock<std::mutex> lock(mutex_);
Expand Down
2 changes: 1 addition & 1 deletion p2p/source/bond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Bonded :
Bonded *const bonded_;

protected:
virtual Pump *Inner() = 0;
virtual Pump<Buffer> *Inner() = 0;

void Land(const Buffer &data) override {
return bonded_->Land(this, data);
Expand Down
2 changes: 1 addition & 1 deletion p2p/source/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class Brick final :
};

template <size_t Size_>
inline bool operator ==(const Brick<Size_> &lhs, const Brick<Size_> &rhs) {
inline bool operator ==(const Data<Size_> &lhs, const Data<Size_> &rhs) {
return memcmp(lhs.data(), rhs.data(), Size_) == 0;
}

Expand Down
4 changes: 2 additions & 2 deletions p2p/source/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ _trace();
};

class Channel final :
public Pump,
public Pump<Buffer>,
public webrtc::DataChannelObserver
{
private:
Expand All @@ -219,7 +219,7 @@ class Channel final :
static task<Socket> Wire(Sunk<> *sunk, const S<Origin> &origin, Configuration configuration, const std::function<task<std::string> (std::string)> &respond);

Channel(BufferDrain *drain, const S<Peer> &peer, const rtc::scoped_refptr<webrtc::DataChannelInterface> &channel) :
Pump(drain),
Pump<Buffer>(drain),
peer_(peer),
channel_(channel)
{
Expand Down
14 changes: 7 additions & 7 deletions p2p/source/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ task<Json::Value> Endpoint::operator ()(const std::string &method, Argument args
root["params"] = std::move(args);

Json::FastWriter writer;
const auto result(Parse((co_await origin_->Request("POST", locator_, {{"content-type", "application/json"}}, writer.write(root))).ok()));
Log() << root << " -> " << result << "" << std::endl;
const auto data(Parse((co_await origin_->Request("POST", locator_, {{"content-type", "application/json"}}, writer.write(root))).ok()));
Log() << root << " -> " << data << "" << std::endl;

orc_assert(result["jsonrpc"] == "2.0");
orc_assert(data["jsonrpc"] == "2.0");

auto error(result["error"]);
const auto error(data["error"]);

auto id(result["id"]);
const auto id(data["id"]);
orc_assert(!id.isNull() || !error.isNull());

orc_assert_(error.isNull(), ([&]() {
Expand All @@ -116,8 +116,8 @@ task<Json::Value> Endpoint::operator ()(const std::string &method, Argument args
return text;
}()));

orc_assert(result["id"] == "");
co_return result["result"];
orc_assert(id == "");
co_return data["result"];
}

}
2 changes: 1 addition & 1 deletion p2p/source/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Selector final :
Args<false, Args_...>::Write(signature);
signature << ')';
std::cerr << signature.str() << std::endl;
return Hash(Strung(signature.str())).Clip<4>().num<uint32_t>();
return Hash(signature.str()).Clip<4>().num<uint32_t>();
}())
{
}
Expand Down
2 changes: 2 additions & 0 deletions p2p/source/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <json/json.h>

#include "error.hpp"

namespace orc {

inline Json::Value Parse(const std::string &data) {
Expand Down
32 changes: 17 additions & 15 deletions p2p/source/link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,19 @@ class Faucet :

using BufferDrain = Drain<const Buffer &>;

template <typename Type_, typename Value_ = const Type_ &>
class Pump :
public Faucet<BufferDrain>,
public Pipe<Buffer>
public Faucet<Drain<Value_>>,
public Pipe<Type_>
{
protected:
void Land(const Buffer &data) {
return Outer()->Land(data);
void Land(const Type_ &data) {
return Faucet<Drain<Value_>>::Outer()->Land(data);
}

public:
Pump(BufferDrain *drain) :
Faucet<BufferDrain>(drain)
Pump(Drain<Value_> *drain) :
Faucet<Drain<Value_>>(drain)
{
}
};
Expand All @@ -98,7 +99,7 @@ class Stopper :
public BufferDrain
{
protected:
virtual Pump *Inner() = 0;
virtual Pump<Buffer> *Inner() = 0;

void Land(const Buffer &buffer) override {
}
Expand All @@ -113,27 +114,28 @@ class Stopper :
}
};

template <typename Type_>
class Link :
public Pump,
public BufferDrain
public Pump<Type_>,
public Drain<const Type_ &>
{
protected:
void Land(const Buffer &data) override {
return Pump::Land(data);
return Pump<Type_>::Land(data);
}

void Stop(const std::string &error = std::string()) override {
return Pump::Stop(error);
return Pump<Type_>::Stop(error);
}

public:
Link(BufferDrain *drain) :
Pump(drain)
Link(Drain<const Buffer &> *drain) :
Pump<Type_>(drain)
{
}
};

template <typename Inner_ = Pump, typename Drain_ = BufferDrain>
template <typename Inner_ = Pump<Buffer>, typename Drain_ = BufferDrain>
class Sunk {
protected:
U<Inner_> inner_;
Expand All @@ -150,7 +152,7 @@ class Sunk {
}
};

template <typename Base_, typename Inner_ = Pump, typename Drain_ = BufferDrain>
template <typename Base_, typename Inner_ = Pump<Buffer>, typename Drain_ = BufferDrain>
class Sink final :
public Base_,
public Sunk<Inner_, Drain_>
Expand Down
4 changes: 4 additions & 0 deletions p2p/source/locked.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class Lock :
Lock(const Lock<Locked_> &lock) = delete;
Lock(Lock<Locked_> &&lock) noexcept = default;

Locked_ &operator *() const {
return locked_;
}

Locked_ *operator ->() const {
return &locked_;
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/source/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class Stream :
};

class Inverted final :
public Pump
public Pump<Buffer>
{
private:
U<Stream> stream_;

public:
Inverted(BufferDrain *drain, U<Stream> stream) :
Pump(drain),
Pump<Buffer>(drain),
stream_(std::move(stream))
{
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/source/remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Base {
};

class Association :
public Pump,
public Pump<Buffer>,
public Base
{
protected:
Expand Down
2 changes: 1 addition & 1 deletion p2p/source/remote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Remote :
static err_t Initialize(netif *interface);

protected:
virtual Pump *Inner() = 0;
virtual Pump<Buffer> *Inner() = 0;

void Land(const Buffer &data) override;
void Stop(const std::string &error) override;
Expand Down
41 changes: 41 additions & 0 deletions p2p/source/station.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Orchid - WebRTC P2P VPN Market (on Ethereum)
* Copyright (C) 2017-2019 The Orchid Authors
*/

/* GNU Affero General Public License, Version 3 {{{ */
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
/* }}} */


#include "station.hpp"

namespace orc {

void Station::Land(Json::Value data) {
orc_assert(data["jsonrpc"] == "2.0");
return Outer()->Land(std::move(data));
}

task<void> Station::Send(const std::string &method, const std::string &id, Argument args) {
Json::Value root;
root["jsonrpc"] = "2.0";
root["method"] = method;
root["id"] = id;
root["params"] = std::move(args);
co_await Inner()->Send(root);
}

}
55 changes: 55 additions & 0 deletions p2p/source/station.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Orchid - WebRTC P2P VPN Market (on Ethereum)
* Copyright (C) 2017-2019 The Orchid Authors
*/

/* GNU Affero General Public License, Version 3 {{{ */
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
/* }}} */


#ifndef ORCHID_STATION_HPP
#define ORCHID_STATION_HPP

#include "jsonrpc.hpp"
#include "link.hpp"

namespace orc {

class Station :
public Faucet<Drain<Json::Value>>,
public Drain<Json::Value>
{
protected:
virtual Pump<Json::Value, Json::Value> *Inner() = 0;

void Land(Json::Value data) override;

void Stop(const std::string &error) override {
return Faucet<Drain<Json::Value>>::Stop(error);
}

public:
Station(Drain<Json::Value> *drain) :
Faucet<Drain<Json::Value>>(drain)
{
}

task<void> Send(const std::string &method, const std::string &id, Argument args);
};

}

#endif//ORCHID_STATION_HPP
Loading

0 comments on commit 2ca478e

Please sign in to comment.