Skip to content

Commit

Permalink
Merge pull request #108 from hyperledger/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Warchant committed Jan 6, 2017
2 parents 9c57406 + 89d2618 commit 6103029
Show file tree
Hide file tree
Showing 34 changed files with 666 additions and 198 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ build/*
*xcworkspace*
.vscode/*
*cmake-build-debug*
cmake-build-debu/*
config/sumeragi.json
CMakeLists.txt.user
config/sumeragi.json
cmake-build-debu/*
docker/build/iroha.tar
cmake-build-debug/*
66 changes: 53 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,62 @@ Please include a developer certificate with pull requests: https://www.clahub.co
.
├── build (for cmake)
├── config
├── peer
├── core
│   ├── connection
│   ├── consensus
│   │   └── connection
│   ├── crypto
│   ├── model
│   │   └── transactions
│   ├── infra
│   │   ├── connection
│   │   ├── crypto
│   │   ├── protobuf
│   │   ├── repository
│   │   ├── server
│   │   ├── service
│   │   └── smart_contract
│   │   └── jvm
│   ├── model
│   │   ├── commands
│   │   ├── objects
│   │   ├── smart_contract
│   │   ├── state
│   │   ├── publisher
│   │   ├── repository
│   │   └── state
│   ├── publisher
│   ├── repository
│   │   ├── consensus
│   │   └── domain
│   ├── server
│   ├── smart_contract
│   ├── service
│   ├── util
│   ├── validation
│   └── vendor
├── doc
│      ├── Cappucino
│      ├── ed25519
│      ├── json
│      ├── KeccakCodePackage
│      ├── leveldb
│      └── thread_pool_cpp
├── docker
│   ├── build
│   │   └── scripts
│   ├── config-discovery
│   └── dev
│      └── scripts
├── docs
├── peer
├── smart_contract
│   └── SampleCurrency_java
└── test
├── crypto
└── smart_contract
│   └── SampleCurrency
├── test
│ ├── connection
│ ├── consensus
│ ├── crypto
│ ├── infra
│   │   ├── protobuf
│   │   └── repository
│ ├── smart_contract
│ └── vendor
├── tools
```

#### config/
Expand Down Expand Up @@ -143,8 +174,8 @@ It contains asset model, transaction logic. independent of infra knowledge.
It contains some source depend on vendor (third party) libraries.
If any source depends on vendor libraries, it should be in infra.
##### filename
basically, filename is `"function"_with_"lib name".cpp`
##### filenames
Filenames follow the convention: `"function"_with_"lib name".cpp`
```
connection
└── connection_with_aeron.cpp
Expand Down Expand Up @@ -190,7 +221,16 @@ fabric3 (python library, not hyperledger/fabric)
```
## Using docker and docker-compose for development
Refer to [this guide](./docs/using_docker.md).
To build latest container with iroha, refer to [this guide](./docker/README.md).
After this, run network of 4 nodes:
```
docker-compose up
# open another terminal
docker-compose scale iroha=4
```
To set different number of nodes, change `command: 4` in `docker-compose.yml` and `iroha=4` in previous command.
## Installation
```
Expand Down
26 changes: 13 additions & 13 deletions core/infra/connection/connection_with_aeron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ namespace connection {
bool subscription_running(true);

fragment_handler_t receiveMessage() {
return [&](AtomicBuffer& buffer, util::index_t offset, util::index_t length, Header& header) {
return [](AtomicBuffer& buffer, util::index_t offset, util::index_t length, Header& header) {
std::string raw_data = std::string((char *)buffer.buffer() + offset, (unsigned long)length);
// WIP parse json.
// logger::info("receive", raw_data);
for(auto& f : receivers) {
f( peer::getMyIp(), raw_data);
f(peer::getMyIp(), raw_data);
}
};
}
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace connection {
}

fragment_handler_t handler = receiveMessage();
subscription_thread = std::thread([subscription,handler](){
subscription_thread = std::thread([subscription, handler](){
while (subscription_running){
const int fragmentsRead = subscription->poll(handler, FRAGMENTS_LIMIT);
}
Expand All @@ -108,27 +108,27 @@ namespace connection {
return -1;
}
}

void addPublication(std::string ip) {
std::int64_t pid = aeron->addPublication( "aeron:udp?endpoint="+ip+":40123", streamId);
auto publication = aeron->findPublication(pid);
std::int64_t pid = aeron->addPublication("aeron:udp?endpoint=" + ip + ":40123", streamId);
auto publication = aeron->findPublication(pid);
while (!publication) {
std::this_thread::yield();
publication = aeron->findPublication(pid);
}
logger::info("connection", "publication ["+ ip +"]");
publications.insert(std::pair<std::string, std::shared_ptr<Publication>>{ ip, publication});
logger::info("connection", "publication [" + ip + "]");
publications.emplace(ip, publication);
}

bool send(const std::string& to,const std::string& msg) {
bool send(const std::string& to, const std::string& msg) {
logger::info("connection", "Start send");
if(publications.find(to) == publications.end()){
logger::error("connection", to + " is not registerd");
return false;
}
try{
char* message = const_cast<char*>(msg.c_str());
AERON_DECL_ALIGNED(std::uint8_t buffer[4096], 16);
auto message = const_cast<char*>(msg.c_str());
AERON_DECL_ALIGNED(std::uint8_t buffer[4096], 16);
AtomicBuffer srcBuffer(&buffer[0], 4096);
srcBuffer.putBytes(0, reinterpret_cast<std::uint8_t *>(message), strlen(message));
const std::int64_t result = publications[to]->offer(srcBuffer, 0, strlen(message));
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace connection {
logger::info("connection", "send mesage publlications "+ std::to_string(publications.size()));
for(auto& p : publications){
if(p.first != peer::getMyIp()){
send( p.first, msg);
send(p.first, msg);
}
}
return true;
Expand All @@ -171,4 +171,4 @@ namespace connection {
receivers.push_back(callback);
return true;
}
};
};
4 changes: 2 additions & 2 deletions core/infra/protobuf/convertor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace convertor{
auto name = aAccount.name();
std::vector<std::tuple<std::string,long>> assets;
for(const Event::Asset& as: aAccount.assets()){
assets.push_back(std::make_pair(as.name(),(long)as.value()));
assets.emplace_back(as.name(), static_cast<long>(as.value()));
}
return object::Account(
std::move(publicKey),
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace convertor{
auto publicKey = tx.account().publickey();
std::vector<std::tuple<std::string,long>> assets;
for(auto&& as: tx.account().assets()){
assets.push_back(std::make_pair( as.name(), as.value()));
assets.emplace_back(as.name(), as.value());
}
auto issuer = tx.senderpubkey();
auto res = ConsensusEvent<
Expand Down
24 changes: 12 additions & 12 deletions core/infra/server/http_server_with_cappuccino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace http {

json responseError(std::string message){
return json({
{"message", message},
{"message", std::move(message)},
{"status", 400}
});
}
Expand Down Expand Up @@ -82,12 +82,12 @@ namespace http {
if(!data.empty()){
try{

auto publicKey = data["publicKey"].get<std::string>();
auto alias = data["alias"].get<std::string>();
auto timestamp = data["timestamp"].get<int>();
const auto publicKey = data["publicKey"].get<std::string>();
const auto alias = data["alias"].get<std::string>();
const auto timestamp = data["timestamp"].get<int>();

uuid = hash::sha3_256_hex(publicKey);
if(repository::account::findByUuid(uuid).publicKey == "") {
if(repository::account::findByUuid(uuid).publicKey.empty()) {

auto event = ConsensusEvent < Transaction < Add < object::Account >> > (
publicKey.c_str(),
Expand Down Expand Up @@ -164,13 +164,13 @@ namespace http {
auto data = request->json();
if(!data.empty()){
try{
auto assetUuid = data["asset-uuid"].get<std::string>();
auto timestamp = data["timestamp"].get<int>();
auto signature = data["signature"].get<std::string>();
auto command = data["params"]["command"].get<std::string>();
auto value = data["params"]["value"].get<std::string>();
auto sender = data["params"]["sender"].get<std::string>();
auto receiver = data["params"]["receiver"].get<std::string>();
const auto assetUuid = data["asset-uuid"].get<std::string>();
const auto timestamp = data["timestamp"].get<int>();
const auto signature = data["signature"].get<std::string>();
const auto command = data["params"]["command"].get<std::string>();
const auto value = data["params"]["value"].get<std::string>();
const auto sender = data["params"]["sender"].get<std::string>();
const auto receiver = data["params"]["receiver"].get<std::string>();

auto event = ConsensusEvent<Transaction<Transfer<Asset>>>(
sender.c_str(),
Expand Down
12 changes: 10 additions & 2 deletions core/infra/service/peer_service_with_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../../util/logger.hpp"

#include <iostream> // for debug writing
#include <cstdlib>

#include <fstream> // ifstream, ofstream
#include <sstream> // istringstream
Expand All @@ -17,10 +18,17 @@ namespace peer {
json openConfig(){
if(configData.empty()) {
try{
if (std::string(getenv("IROHA_HOME")) == "") {
const auto IROHA_HOME = [](){
const auto p = getenv("IROHA_HOME");
return p == nullptr ? std::string() : std::string(p);
}();

if (IROHA_HOME.empty()) {
std::cerr << "IROHA_HOMEをセットして" << std::endl;
return json();
}
std::ifstream ifs(std::string(getenv("IROHA_HOME")) + "/config/sumeragi.json");

std::ifstream ifs(IROHA_HOME + "/config/sumeragi.json");
if (ifs.fail()) {
std::cerr << "Fileが見つかりません" << std::endl;
return json();
Expand Down
50 changes: 25 additions & 25 deletions core/infra/smart_contract/jvm/java_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

#include "java_virtual_machine.hpp"
#include <algorithm>
#include <array>

namespace smart_contract {

Expand All @@ -30,68 +31,67 @@ namespace smart_contract {
}

std::unique_ptr<JavaContext> initializeVM(std::string contractName) {
JNIEnv *env;
JavaVM *jvm;

if (getenv("IROHA_HOME") == nullptr) {
std::cout << "You must set IROHA_HOME!" << std::endl;
return nullptr;
}

std::cout << "-Djava.class.path=" + (std::string) getenv("IROHA_HOME") +
std::cout << "-Djava.class.path=" + std::string(getenv("IROHA_HOME")) +
"/smart_contract/" + contractName <<"/ "<< contractName.c_str() << std::endl;

JavaVMOption options[3];
//options[0].optionString = (char*)"-Djava.security.manager -Djava.security.policy=policy.txt -Djava.class.path=./contract/";
options[1].optionString = (char *) "-Djava.security.manager";
options[2].optionString = (char *) "-Djava.security.policy=policy.txt";
options[0].optionString = (char *) ("-Djava.class.path=" + (std::string) getenv("IROHA_HOME") +
"/smart_contract").c_str();


JavaVMOption options[3];
options[0].optionString = const_cast<char*>(("-Djava.class.path=" + std::string(getenv("IROHA_HOME")) + "/smart_contract").c_str());
options[1].optionString = const_cast<char*>("-Djava.security.manager");
options[2].optionString = const_cast<char*>("-Djava.security.policy=policy.txt");

JavaVMInitArgs vm_args;
vm_args.version = JNI_VERSION_1_6;
vm_args.options = options;
vm_args.version = JNI_VERSION_1_6;
vm_args.options = options;
vm_args.nOptions = 3;
//vm_args.ignoreUnrecognized = true;


JNIEnv *env;
JavaVM *jvm;

int res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
if (res) {
std::cout << "cannot run JavaVM : " << res << std::endl;
return nullptr;
}

jclass cls = env->FindClass("SampleCurrency/SampleCurrency");// (contractName+"/"+contractName).c_str());
if (cls == 0) {
if (cls == nullptr) {
std::cout << "could not found class : " << contractName << std::endl;
return nullptr;
}

jmethodID cns = env->GetMethodID(cls, "<init>", "()V");
if (cns == NULL) {
if (cns == nullptr) {
std::cout << "could not get <init> method." << std::endl;
return nullptr;
}

jobject obj = env->NewObject(cls, cns);

std::unique_ptr<JavaContext> ptr(new JavaContext(
return std::make_unique<JavaContext>(
env,
jvm,
vm_args,
std::move(contractName),
cls,
obj
));
return ptr;
);
}

void execFunction(
const std::unique_ptr<JavaContext> &context,
std::string functionName,
std::unordered_map<std::string,
std::string> params
std::unordered_map<std::string, std::string> params
) {

jmethodID mid = context->env->GetStaticMethodID(context->jClass, functionName.c_str(), "(Ljava/util/Map;)V");
if (mid == NULL) {
if (mid == nullptr) {
std::cout << "could not get method : " << functionName << std::endl;
return;
}
Expand All @@ -103,4 +103,4 @@ namespace smart_contract {
}
}

};
};
3 changes: 1 addition & 2 deletions core/infra/smart_contract/jvm/java_virtual_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ namespace smart_contract {
void execFunction(
const std::unique_ptr<JavaContext> &context,
std::string functionName,
std::unordered_map<std::string,
std::string> params
std::unordered_map<std::string, std::string> params
);

}
Expand Down

0 comments on commit 6103029

Please sign in to comment.