Skip to content

Commit

Permalink
modify active izanami : leveldb output error, so i erase leveldb oper…
Browse files Browse the repository at this point in the history
…ate function temporary
  • Loading branch information
satellitex authored and l4l committed Mar 17, 2017
1 parent 753dc4e commit c141a09
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/infra/config/peer_service_with_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ std::vector<std::unique_ptr<peer::Node>> PeerServiceConfig::getPeerList() {
for( auto &&node : peerList )
if( node.isOK() )
nodes.push_back( std::make_unique<peer::Node>( node.getIP(), node.getPublicKey(), node.getTrustScore() ) );

sort( nodes.begin(), nodes.end(),
[]( const std::unique_ptr<peer::Node> &a, const std::unique_ptr<peer::Node> &b ) { return a->getTrustScore() > b->getTrustScore(); } );
logger::debug("getPeerList") << std::to_string( nodes.size() );
Expand Down Expand Up @@ -355,7 +355,7 @@ bool PeerServiceConfig::sendAllTransactionToNewPeer( const peer::Node& peer ) {
if( !connection::iroha::PeerService::Izanami::send( peer.getIP(), txResponse ) ) return false;
}

{ // Send transaction data separated block to new peer.
if(0){ // WIP(leveldb don't active) Send transaction data separated block to new peer.
logger::debug("peer-service") << "send all transaction infomation";
auto transactions = repository::transaction::findAll();
int block_size = 500;
Expand Down
27 changes: 26 additions & 1 deletion core/service/izanami.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ limitations under the License.
namespace izanami {
using Api::TransactionResponse;


void setAwkTimer(int const sleepMillisecs, const std::function<void(void)>& action) {
std::thread([action, sleepMillisecs]() {
std::this_thread::sleep_for(std::chrono::milliseconds(sleepMillisecs));
action();
}).join();
}


InitializeEvent::InitializeEvent() {
now_progress = 0;
}
Expand All @@ -44,6 +53,7 @@ namespace izanami {
for( auto&& tx : txResponse->transaction() ) {
hash = hash::sha3_256_hex(hash+tx.hash());
}
hashes[ txResponse->code() ].emplace_back( hash );
txResponses[ hash ] = std::move( txResponse );
}
const std::vector<std::string>& InitializeEvent::getHashes( uint64_t progress ) {
Expand All @@ -53,18 +63,21 @@ namespace izanami {
return std::move( txResponses[ hash ] );
}
void InitializeEvent::next_progress() {
logger::debug("izanami") << "next_progress : " + std::to_string( now_progress );
for( auto&& hash : hashes[now_progress] ) {
txResponses.erase( hash );
}
logger::debug("izanami") << "txResponses erase";
hashes.erase( now_progress++ );
logger::debug("izanami") << "nexted : " + std::to_string( now_progress );
}
uint64_t InitializeEvent::now() const {
return now_progress;
}

void InitializeEvent::storeTxResponse( const std::string& hash ) {
for( auto &&tx : txResponses[ hash ]->transaction() ) {
repository::transaction::add( tx.hash(), tx );
//WIP repository::transaction::add( tx.hash(), tx );
}
}
void InitializeEvent::executeTxResponse( const std::string& hash ) {
Expand Down Expand Up @@ -137,10 +150,14 @@ namespace izanami {
//invoke when receive TransactionResponse.
void receiveTransactionResponse( TransactionResponse& txResponse ) {
static InitializeEvent event;
logger::debug("izanami") << "in receiveTransactionResponse event = " + std::to_string(event.now()) ;
if( event.isFinished() ) return;
logger::debug("izanami") << "evet is not finished";
event.add_transactionResponse( std::make_unique<TransactionResponse>( txResponse ) );
if( detail::isFinishedReceive( event ) ) {
logger::debug("izanami") << "is finished receive";
if( detail::isFinishedReceiveAll( event )) {
logger::debug("izanami") << "is finished receive all";
config::PeerServiceConfig::getInstance().finishedInitializePeer();
event.finished();
logger::explore("izanami") << "Finished Receive ALl Transaction";
Expand All @@ -152,6 +169,13 @@ namespace izanami {
detail::storeTransactionResponse(event);
}
}
if( !event.isFinished() && txResponse.transaction().empty() )
setAwkTimer( 1000, [&txResponse]() {
connection::iroha::PeerService::Izanami::send(
config::PeerServiceConfig::getInstance().getMyIp(),
txResponse
);
});
}


Expand Down Expand Up @@ -189,6 +213,7 @@ namespace izanami {

connection::iroha::Izanami::Izanagi::receive([](const std::string& from, TransactionResponse& txResponse ) {
logger::info("izanami") << "receive! Transactions!!";
logger::info("izanami") << txResponse.message();
std::function<void()> &&task = std::bind( receiveTransactionResponse, txResponse );
pool.process(std::move(task));
});
Expand Down
1 change: 1 addition & 0 deletions core/service/izanami.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace izanami {
//invoke when initialize Peer that to config Participation on the way
void startIzanami();

void setAwkTimer(int const sleepMillisecs, const std::function<void(void)>& action);
}


Expand Down
12 changes: 12 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ target_link_libraries(issue_transaction
connection_with_grpc
transaction_repository
)

# make config
add_executable(send_izanami_test send_izanami.cpp)
target_link_libraries(send_izanami_test
json
config_manager
logger
event_with_grpc
create_objects_helper
connection_with_grpc
transaction_repository
)
34 changes: 34 additions & 0 deletions tools/send_izanami.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//
// Created by Takumi Yamashita on 2017/03/15.
//

#include <string>
#include <service/peer_service.hpp>
#include <infra/config/peer_service_with_json.hpp>

int main(int argc, char* argv[]) {
peer::Node peer (
config::PeerServiceConfig::getInstance().getMyIp(),
config::PeerServiceConfig::getInstance().getMyPublicKey(),
1.0,
false
);
config::PeerServiceConfig::getInstance().sendAllTransactionToNewPeer( peer );
return 0;
}

0 comments on commit c141a09

Please sign in to comment.