mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
whitespace cleanup
This commit is contained in:
parent
f2e6fad104
commit
cd59ca8376
3 changed files with 68 additions and 69 deletions
|
@ -12,69 +12,68 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace worker
|
namespace worker
|
||||||
{
|
{
|
||||||
template<typename Caller>
|
template<typename Caller>
|
||||||
struct ThreadPool
|
struct ThreadPool
|
||||||
{
|
{
|
||||||
typedef std::function<void(void)> ResultFunc;
|
typedef std::function<void(void)> ResultFunc;
|
||||||
typedef std::function<ResultFunc(void)> WorkFunc;
|
typedef std::function<ResultFunc(void)> WorkFunc;
|
||||||
typedef std::pair<std::shared_ptr<Caller>, WorkFunc> Job;
|
typedef std::pair<std::shared_ptr<Caller>, WorkFunc> Job;
|
||||||
typedef std::mutex mtx_t;
|
typedef std::mutex mtx_t;
|
||||||
typedef std::unique_lock<mtx_t> lock_t;
|
typedef std::unique_lock<mtx_t> lock_t;
|
||||||
typedef std::condition_variable cond_t;
|
typedef std::condition_variable cond_t;
|
||||||
ThreadPool(int workers)
|
ThreadPool(int workers)
|
||||||
{
|
{
|
||||||
stop = false;
|
stop = false;
|
||||||
if(workers > 0)
|
if(workers > 0)
|
||||||
{
|
{
|
||||||
while(workers--)
|
while(workers--)
|
||||||
{
|
{
|
||||||
threads.emplace_back([this] {
|
threads.emplace_back([this] {
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
Job job;
|
Job job;
|
||||||
{
|
{
|
||||||
lock_t lock(this->queue_mutex);
|
lock_t lock(this->queue_mutex);
|
||||||
this->condition.wait(
|
this->condition.wait(
|
||||||
lock, [this] { return this->stop || !this->jobs.empty(); });
|
lock, [this] { return this->stop || !this->jobs.empty(); });
|
||||||
if (this->stop && this->jobs.empty()) return;
|
if (this->stop && this->jobs.empty()) return;
|
||||||
job = std::move(this->jobs.front());
|
job = std::move(this->jobs.front());
|
||||||
this->jobs.pop_front();
|
this->jobs.pop_front();
|
||||||
}
|
}
|
||||||
ResultFunc result = job.second();
|
ResultFunc result = job.second();
|
||||||
job.first->GetService().post(result);
|
job.first->GetService().post(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void Offer(const Job & job)
|
void Offer(const Job & job)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
lock_t lock(queue_mutex);
|
lock_t lock(queue_mutex);
|
||||||
if (stop) return;
|
if (stop) return;
|
||||||
jobs.emplace_back(job);
|
jobs.emplace_back(job);
|
||||||
}
|
}
|
||||||
condition.notify_one();
|
condition.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
~ThreadPool()
|
~ThreadPool()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
lock_t lock(queue_mutex);
|
lock_t lock(queue_mutex);
|
||||||
stop = true;
|
stop = true;
|
||||||
}
|
}
|
||||||
condition.notify_all();
|
condition.notify_all();
|
||||||
for(auto &t: threads) t.join();
|
for(auto &t: threads) t.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
std::deque<Job> jobs;
|
std::deque<Job> jobs;
|
||||||
mtx_t queue_mutex;
|
mtx_t queue_mutex;
|
||||||
cond_t condition;
|
cond_t condition;
|
||||||
bool stop;
|
bool stop;
|
||||||
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,8 @@ namespace transport
|
||||||
m_Encryption.SetIV (y + 240);
|
m_Encryption.SetIV (y + 240);
|
||||||
m_Decryption.SetIV (m_Establisher->phase1.HXxorHI + 16);
|
m_Decryption.SetIV (m_Establisher->phase1.HXxorHI + 16);
|
||||||
m_Encryption.Encrypt ((uint8_t *)&m_Establisher->phase2.encrypted, sizeof(m_Establisher->phase2.encrypted), (uint8_t *)&m_Establisher->phase2.encrypted);
|
m_Encryption.Encrypt ((uint8_t *)&m_Establisher->phase2.encrypted, sizeof(m_Establisher->phase2.encrypted), (uint8_t *)&m_Establisher->phase2.encrypted);
|
||||||
boost::asio::async_write(m_Socket, boost::asio::buffer (&m_Establisher->phase2, sizeof (NTCPPhase2)), boost::asio::transfer_all(), std::bind(&NTCPSession::HandlePhase2Sent, shared_from_this(), std::placeholders::_1, std::placeholders::_2, tsB));
|
boost::asio::async_write(m_Socket, boost::asio::buffer (&m_Establisher->phase2, sizeof (NTCPPhase2)), boost::asio::transfer_all(),
|
||||||
|
std::bind(&NTCPSession::HandlePhase2Sent, shared_from_this(), std::placeholders::_1, std::placeholders::_2, tsB));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTCPSession::HandlePhase2Sent (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsB)
|
void NTCPSession::HandlePhase2Sent (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsB)
|
||||||
|
@ -299,7 +300,7 @@ namespace transport
|
||||||
s.Sign (keys, buf);
|
s.Sign (keys, buf);
|
||||||
m_Encryption.Encrypt(m_ReceiveBuffer, len, m_ReceiveBuffer);
|
m_Encryption.Encrypt(m_ReceiveBuffer, len, m_ReceiveBuffer);
|
||||||
boost::asio::async_write (m_Socket, boost::asio::buffer (m_ReceiveBuffer, len), boost::asio::transfer_all (),
|
boost::asio::async_write (m_Socket, boost::asio::buffer (m_ReceiveBuffer, len), boost::asio::transfer_all (),
|
||||||
std::bind(&NTCPSession::HandlePhase3Sent, shared_from_this (), std::placeholders::_1, std::placeholders::_2, tsA));
|
std::bind(&NTCPSession::HandlePhase3Sent, shared_from_this (), std::placeholders::_1, std::placeholders::_2, tsA));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTCPSession::HandlePhase3Sent (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsA)
|
void NTCPSession::HandlePhase3Sent (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsA)
|
||||||
|
|
|
@ -133,7 +133,7 @@ namespace transport
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef i2p::worker::ThreadPool<NTCPSession> Pool;
|
typedef i2p::worker::ThreadPool<NTCPSession> Pool;
|
||||||
|
|
||||||
enum RemoteAddressType
|
enum RemoteAddressType
|
||||||
{
|
{
|
||||||
|
@ -177,7 +177,6 @@ namespace transport
|
||||||
{
|
{
|
||||||
m_CryptoPool->Offer({conn, work});
|
m_CryptoPool->Offer({conn, work});
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** @brief return true for hard limit */
|
/** @brief return true for hard limit */
|
||||||
|
@ -219,7 +218,7 @@ namespace transport
|
||||||
boost::asio::ip::tcp::resolver m_Resolver;
|
boost::asio::ip::tcp::resolver m_Resolver;
|
||||||
boost::asio::ip::tcp::endpoint * m_ProxyEndpoint;
|
boost::asio::ip::tcp::endpoint * m_ProxyEndpoint;
|
||||||
|
|
||||||
std::shared_ptr<Pool> m_CryptoPool;
|
std::shared_ptr<Pool> m_CryptoPool;
|
||||||
|
|
||||||
uint16_t m_SoftLimit, m_HardLimit;
|
uint16_t m_SoftLimit, m_HardLimit;
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue