Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop'
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
  • Loading branch information
Warchant committed Jan 6, 2017
2 parents 23e76cb + 624f761 commit ba72815
Show file tree
Hide file tree
Showing 27 changed files with 271 additions and 164 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ build/*
*xcworkspace*
.vscode/*
*cmake-build-debug*
cmake-build-debug/*
CMakeLists.txt.user
config/sumeragi.json
cmake-build-debu/*
docker/build/iroha.tar
cmake-build-debug/*
2 changes: 1 addition & 1 deletion config/sumeragi.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"me":{
"ip":"172.17.0.6",
"name":"kabohara",
"name":"samari",
"publicKey":"Sht5opDIxbyK+oNuEnXUs5rLbrvVgb2GjSPfqIYGFdU=",
"privateKey":"aGIuSZRhnGfFyeoKNm/NbTylnAvRfMu3KumOEfyT2HPf36jSF22m2JXWrdCmKiDoshVqjFtZPX3WXaNuo9L8WA=="
},
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
10 changes: 5 additions & 5 deletions core/infra/smart_contract/smart_contract_with_java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace smart_contract {
std::map<std::string, std::unique_ptr<JavaContext>> vmSet;

void SmartContract::initializeVM(const std::string& contractName){
vmSet.insert(std::make_pair( contractName, smart_contract::initializeVM(contractName)));
vmSet.emplace(contractName, smart_contract::initializeVM(contractName));
}

void SmartContract::finishVM(const std::string& contractName){
if(vmSet.find(contractName) != vmSet.end()){
vmSet.erase(contractName);
}
if(vmSet.find(contractName) != vmSet.end()){
vmSet.erase(contractName);
}
}

void SmartContract::invokeFunction(
Expand All @@ -26,7 +26,7 @@ namespace smart_contract {
) {
if(vmSet.find(contractName) != vmSet.end()){
const auto& context = vmSet.at(contractName);
smart_contract::execFunction( context, functionName, params);
smart_contract::execFunction(context, functionName, params);
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions core/model/commands/transfer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ namespace command {
std::string receiverPublicKey;

template<typename... Args>
constexpr explicit Transfer(
explicit Transfer(
std::string&& sender,
std::string&& receiver,
Args&&... args
):
T(std::forward<Args>(args)...),
senderPublicKey(std::move(sender)),
receiverPublicKey(std::move(receiver)),
T(std::forward<Args>(args)...)
receiverPublicKey(std::move(receiver))
{}

auto getCommandName() const {
Expand Down
4 changes: 2 additions & 2 deletions core/model/commands/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ namespace command {
std::string ownerPublicKey;

template<typename... Args>
constexpr explicit Update(
explicit Update(
std::string&& ownerPublicKey,
Args&&... args
):
T(std::forward<Args>(args)...),
ownerPublicKey(std::move(ownerPublicKey))
{}

auto getCommandName() const{
auto getCommandName() const {
return "Update";
}

Expand Down
Loading

0 comments on commit ba72815

Please sign in to comment.