-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuna.cpp
31 lines (28 loc) · 1.01 KB
/
tuna.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// Created by yc chow on 2021/2/22.
//
#include "tuna.h"
tuna::tuna(boost::asio::io_context &io_context, const string &seed, vector<shared_ptr<node_info>> nis, bool *stop) :
context_(io_context), socket_(io_context), nis_(nis), stop_(stop) {
auto acc = Wallet::Account::NewAccount(seed); // new Random account
wallet_ = Wallet::NewWallet(acc, Wallet::WalletCfg::MergeWalletConfig(nullptr));
cerr << "wallet addr:" << wallet_->Address() << endl;
}
void tuna::async_choose_local(std::function<void(std::shared_ptr<nkn_Local>)> f) {
auto i = rand() % conn_num;
auto local = locals_[i].lock();
if ((!local) || local->is_destroyed()) {
auto ni = nis_[nis_index_/3 % nis_.size()];
nis_index_++;
local = std::make_shared<nkn_Local>(context_, wallet_, ni, stop_);
// if (!local) {
// f(nullptr);
// }
local->run();
local->send_payment();
locals_[i] = local;
f(local);
return;
}
f(local);
}