mirror of https://github.com/PurpleI2P/i2pd.git
user
4 years ago
62 changed files with 927 additions and 2270 deletions
@ -0,0 +1,29 @@ |
|||||||
|
name: Build on Windows |
||||||
|
|
||||||
|
on: [push, pull_request] |
||||||
|
|
||||||
|
defaults: |
||||||
|
run: |
||||||
|
shell: msys2 {0} |
||||||
|
|
||||||
|
jobs: |
||||||
|
build: |
||||||
|
name: Building for ${{ matrix.arch }} |
||||||
|
runs-on: windows-latest |
||||||
|
strategy: |
||||||
|
fail-fast: true |
||||||
|
matrix: |
||||||
|
include: [ |
||||||
|
{ msystem: MINGW64, arch: x86_64 }, |
||||||
|
{ msystem: MINGW32, arch: i686 } |
||||||
|
] |
||||||
|
steps: |
||||||
|
- uses: actions/checkout@v2 |
||||||
|
- name: Setup MSYS2 |
||||||
|
uses: msys2/setup-msys2@v2 |
||||||
|
with: |
||||||
|
msystem: ${{ matrix.msystem }} |
||||||
|
install: base-devel mingw-w64-${{ matrix.arch }}-gcc mingw-w64-${{ matrix.arch }}-boost mingw-w64-${{ matrix.arch }}-openssl mingw-w64-${{ matrix.arch }}-miniupnpc |
||||||
|
update: true |
||||||
|
- name: build application |
||||||
|
run: make USE_UPNP=yes DEBUG=no -j3 |
@ -0,0 +1,21 @@ |
|||||||
|
name: Build on Ubuntu with make |
||||||
|
|
||||||
|
on: [push, pull_request] |
||||||
|
|
||||||
|
jobs: |
||||||
|
build: |
||||||
|
name: Building with USE_UPNP=${{ matrix.with_upnp }} flag |
||||||
|
runs-on: ubuntu-16.04 |
||||||
|
strategy: |
||||||
|
fail-fast: true |
||||||
|
matrix: |
||||||
|
with_upnp: ['yes', 'no'] |
||||||
|
steps: |
||||||
|
- uses: actions/checkout@v2 |
||||||
|
- name: install packages |
||||||
|
run: | |
||||||
|
sudo add-apt-repository ppa:mhier/libboost-latest |
||||||
|
sudo apt-get update |
||||||
|
sudo apt-get install build-essential libboost1.74-dev libminiupnpc-dev libssl-dev zlib1g-dev |
||||||
|
- name: build application |
||||||
|
run: make USE_AVX=no USE_AESNI=no USE_UPNP=${{ matrix.with_upnp }} -j3 |
@ -1,10 +0,0 @@ |
|||||||
set -e -x |
|
||||||
|
|
||||||
base_url='http://repo.msys2.org/msys/x86_64/' |
|
||||||
packages="libzstd-1.4.4-2-x86_64.pkg.tar.xz pacman-5.2.1-6-x86_64.pkg.tar.xz zstd-1.4.4-2-x86_64.pkg.tar.xz" |
|
||||||
for p in $packages |
|
||||||
do |
|
||||||
curl "${base_url}$p" -o "$p" |
|
||||||
done |
|
||||||
pacman -U --noconfirm $packages |
|
||||||
rm -f $packages |
|
@ -1,32 +0,0 @@ |
|||||||
-----BEGIN CERTIFICATE----- |
|
||||||
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 |
|
||||||
wpBgPyAFAwouPy1whmnx |
|
||||||
-----END CERTIFICATE----- |
|
@ -0,0 +1,34 @@ |
|||||||
|
-----BEGIN CERTIFICATE----- |
||||||
|
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 |
||||||
|
LD8d2z2Lgg== |
||||||
|
-----END CERTIFICATE----- |
@ -1,242 +0,0 @@ |
|||||||
/*
|
|
||||||
* Copyright (c) 2013-2020, The PurpleI2P Project |
|
||||||
* |
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3 |
|
||||||
* |
|
||||||
* See full license text in LICENSE file at top of project tree |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef NTCP_SESSION_H__ |
|
||||||
#define NTCP_SESSION_H__ |
|
||||||
|
|
||||||
#include <inttypes.h> |
|
||||||
#include <map> |
|
||||||
#include <memory> |
|
||||||
#include <thread> |
|
||||||
#include <mutex> |
|
||||||
#include <boost/asio.hpp> |
|
||||||
#include "Crypto.h" |
|
||||||
#include "Identity.h" |
|
||||||
#include "RouterInfo.h" |
|
||||||
#include "I2NPProtocol.h" |
|
||||||
#include "TransportSession.h" |
|
||||||
#include "CryptoWorker.h" |
|
||||||
|
|
||||||
namespace i2p |
|
||||||
{ |
|
||||||
namespace transport |
|
||||||
{ |
|
||||||
struct NTCPPhase1 |
|
||||||
{ |
|
||||||
uint8_t pubKey[256]; |
|
||||||
uint8_t HXxorHI[32]; |
|
||||||
}; |
|
||||||
|
|
||||||
struct NTCPPhase2 |
|
||||||
{ |
|
||||||
uint8_t pubKey[256]; |
|
||||||
struct |
|
||||||
{ |
|
||||||
uint8_t hxy[32]; |
|
||||||
uint8_t timestamp[4]; |
|
||||||
uint8_t filler[12]; |
|
||||||
} encrypted; |
|
||||||
}; |
|
||||||
|
|
||||||
struct NTCPWork; |
|
||||||
|
|
||||||
const size_t NTCP_MAX_MESSAGE_SIZE = 16384; |
|
||||||
const size_t NTCP_BUFFER_SIZE = 1028; // fits 1 tunnel data message
|
|
||||||
const int NTCP_CONNECT_TIMEOUT = 5; // 5 seconds
|
|
||||||
const int NTCP_ESTABLISH_TIMEOUT = 10; // 10 seconds
|
|
||||||
const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes
|
|
||||||
const int NTCP_TERMINATION_CHECK_TIMEOUT = 30; // 30 seconds
|
|
||||||
const size_t NTCP_DEFAULT_PHASE3_SIZE = 2/*size*/ + i2p::data::DEFAULT_IDENTITY_SIZE/*387*/ + 4/*ts*/ + 15/*padding*/ + 40/*signature*/; // 448
|
|
||||||
const int NTCP_CLOCK_SKEW = 60; // in seconds
|
|
||||||
const int NTCP_MAX_OUTGOING_QUEUE_SIZE = 200; // how many messages we can queue up
|
|
||||||
|
|
||||||
class NTCPServer; |
|
||||||
class NTCPSession: public TransportSession, public std::enable_shared_from_this<NTCPSession> |
|
||||||
{ |
|
||||||
public: |
|
||||||
|
|
||||||
NTCPSession (NTCPServer& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr); |
|
||||||
~NTCPSession (); |
|
||||||
void Terminate (); |
|
||||||
void Done (); |
|
||||||
|
|
||||||
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; }; |
|
||||||
boost::asio::io_service & GetService(); |
|
||||||
bool IsEstablished () const { return m_IsEstablished; }; |
|
||||||
bool IsTerminated () const { return m_IsTerminated; }; |
|
||||||
|
|
||||||
void ClientLogin (); |
|
||||||
void ServerLogin (); |
|
||||||
void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs); |
|
||||||
|
|
||||||
private: |
|
||||||
|
|
||||||
void PostI2NPMessages (std::vector<std::shared_ptr<I2NPMessage> > msgs); |
|
||||||
void Connected (); |
|
||||||
void SendTimeSyncMessage (); |
|
||||||
void SetIsEstablished (bool isEstablished) { m_IsEstablished = isEstablished; } |
|
||||||
|
|
||||||
void CreateAESKey (uint8_t * pubKey); |
|
||||||
|
|
||||||
// client
|
|
||||||
void SendPhase3 (); |
|
||||||
void HandlePhase1Sent (const boost::system::error_code& ecode, std::size_t bytes_transferred); |
|
||||||
void HandlePhase2Received (const boost::system::error_code& ecode, std::size_t bytes_transferred); |
|
||||||
void HandlePhase2 (NTCPWork * work=nullptr); |
|
||||||
void HandlePhase3Sent (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsA); |
|
||||||
void HandlePhase4Received (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsA); |
|
||||||
|
|
||||||
//server
|
|
||||||
void SendPhase2 (NTCPWork * work=nullptr); |
|
||||||
void SendPhase4 (uint32_t tsA, uint32_t tsB); |
|
||||||
void HandlePhase1Received (const boost::system::error_code& ecode, std::size_t bytes_transferred); |
|
||||||
void HandlePhase2Sent (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsB); |
|
||||||
void HandlePhase3Received (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsB); |
|
||||||
void HandlePhase3ExtraReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint32_t tsB, size_t paddingLen); |
|
||||||
void HandlePhase3 (uint32_t tsB, size_t paddingLen); |
|
||||||
void HandlePhase4Sent (const boost::system::error_code& ecode, std::size_t bytes_transferred); |
|
||||||
|
|
||||||
// common
|
|
||||||
void Receive (); |
|
||||||
void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred); |
|
||||||
bool DecryptNextBlock (const uint8_t * encrypted); |
|
||||||
|
|
||||||
void Send (std::shared_ptr<i2p::I2NPMessage> msg); |
|
||||||
boost::asio::const_buffers_1 CreateMsgBuffer (std::shared_ptr<I2NPMessage> msg); |
|
||||||
void Send (const std::vector<std::shared_ptr<I2NPMessage> >& msgs); |
|
||||||
void HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, std::vector<std::shared_ptr<I2NPMessage> > msgs); |
|
||||||
|
|
||||||
private: |
|
||||||
|
|
||||||
NTCPServer& m_Server; |
|
||||||
boost::asio::ip::tcp::socket m_Socket; |
|
||||||
bool m_IsEstablished, m_IsTerminated; |
|
||||||
|
|
||||||
i2p::crypto::CBCDecryption m_Decryption; |
|
||||||
i2p::crypto::CBCEncryption m_Encryption; |
|
||||||
|
|
||||||
struct Establisher |
|
||||||
{ |
|
||||||
NTCPPhase1 phase1; |
|
||||||
NTCPPhase2 phase2; |
|
||||||
} * m_Establisher; |
|
||||||
|
|
||||||
i2p::crypto::AESAlignedBuffer<NTCP_BUFFER_SIZE + 16> m_ReceiveBuffer; |
|
||||||
i2p::crypto::AESAlignedBuffer<16> m_TimeSyncBuffer; |
|
||||||
int m_ReceiveBufferOffset; |
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> m_NextMessage; |
|
||||||
size_t m_NextMessageOffset; |
|
||||||
i2p::I2NPMessagesHandler m_Handler; |
|
||||||
|
|
||||||
bool m_IsSending; |
|
||||||
std::vector<std::shared_ptr<I2NPMessage> > m_SendQueue; |
|
||||||
}; |
|
||||||
|
|
||||||
// TODO: move to NTCP.h/.cpp
|
|
||||||
class NTCPServer |
|
||||||
{ |
|
||||||
public: |
|
||||||
|
|
||||||
typedef i2p::worker::ThreadPool<NTCPSession> Pool; |
|
||||||
|
|
||||||
enum RemoteAddressType |
|
||||||
{ |
|
||||||
eIP4Address, |
|
||||||
eIP6Address, |
|
||||||
eHostname |
|
||||||
}; |
|
||||||
|
|
||||||
enum ProxyType |
|
||||||
{ |
|
||||||
eNoProxy, |
|
||||||
eSocksProxy, |
|
||||||
eHTTPProxy |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
NTCPServer (int workers=4); |
|
||||||
~NTCPServer (); |
|
||||||
|
|
||||||
void Start (); |
|
||||||
void Stop (); |
|
||||||
|
|
||||||
bool AddNTCPSession (std::shared_ptr<NTCPSession> session); |
|
||||||
void RemoveNTCPSession (std::shared_ptr<NTCPSession> session); |
|
||||||
std::shared_ptr<NTCPSession> FindNTCPSession (const i2p::data::IdentHash& ident); |
|
||||||
void ConnectWithProxy (const std::string& addr, uint16_t port, RemoteAddressType addrtype, std::shared_ptr<NTCPSession> conn); |
|
||||||
void Connect(const boost::asio::ip::address & address, uint16_t port, std::shared_ptr<NTCPSession> conn); |
|
||||||
|
|
||||||
bool IsBoundV4() const { return m_NTCPAcceptor != nullptr; }; |
|
||||||
bool IsBoundV6() const { return m_NTCPV6Acceptor != nullptr; }; |
|
||||||
bool NetworkIsReady() const { return IsBoundV4() || IsBoundV6() || UsingProxy(); }; |
|
||||||
bool UsingProxy() const { return m_ProxyType != eNoProxy; }; |
|
||||||
|
|
||||||
void UseProxy(ProxyType proxy, const std::string & address, uint16_t port); |
|
||||||
|
|
||||||
boost::asio::io_service& GetService () { return m_Service; }; |
|
||||||
|
|
||||||
void SetSessionLimits(uint16_t softLimit, uint16_t hardLimit) { m_SoftLimit = softLimit; m_HardLimit = hardLimit; } |
|
||||||
bool ShouldLimit() const { return ShouldHardLimit() || ShouldSoftLimit(); } |
|
||||||
void Work(std::shared_ptr<NTCPSession> conn, Pool::WorkFunc work) |
|
||||||
{ |
|
||||||
m_CryptoPool->Offer({conn, work}); |
|
||||||
} |
|
||||||
private: |
|
||||||
|
|
||||||
/** @brief return true for hard limit */ |
|
||||||
bool ShouldHardLimit() const { return m_HardLimit && m_NTCPSessions.size() >= m_HardLimit; } |
|
||||||
|
|
||||||
/** @brief return true for probabalistic soft backoff */ |
|
||||||
bool ShouldSoftLimit() const |
|
||||||
{ |
|
||||||
auto sessions = m_NTCPSessions.size(); |
|
||||||
return sessions && m_SoftLimit && m_SoftLimit < sessions && ( rand() % sessions ) <= m_SoftLimit; |
|
||||||
} |
|
||||||
void Run (); |
|
||||||
void HandleAccept (std::shared_ptr<NTCPSession> conn, const boost::system::error_code& error); |
|
||||||
void HandleAcceptV6 (std::shared_ptr<NTCPSession> conn, const boost::system::error_code& error); |
|
||||||
|
|
||||||
void HandleConnect (const boost::system::error_code& ecode, std::shared_ptr<NTCPSession> conn, std::shared_ptr<boost::asio::deadline_timer> timer); |
|
||||||
|
|
||||||
void HandleProxyConnect(const boost::system::error_code& ecode, std::shared_ptr<NTCPSession> conn, std::shared_ptr<boost::asio::deadline_timer> timer, const std::string & host, uint16_t port, RemoteAddressType adddrtype); |
|
||||||
void AfterSocksHandshake(std::shared_ptr<NTCPSession> conn, std::shared_ptr<boost::asio::deadline_timer> timer, const std::string & host, uint16_t port, RemoteAddressType adddrtype); |
|
||||||
|
|
||||||
// timer
|
|
||||||
void ScheduleTermination (); |
|
||||||
void HandleTerminationTimer (const boost::system::error_code& ecode); |
|
||||||
|
|
||||||
private: |
|
||||||
|
|
||||||
bool m_IsRunning; |
|
||||||
std::thread * m_Thread; |
|
||||||
boost::asio::io_service m_Service; |
|
||||||
boost::asio::io_service::work m_Work; |
|
||||||
boost::asio::deadline_timer m_TerminationTimer; |
|
||||||
boost::asio::ip::tcp::acceptor * m_NTCPAcceptor, * m_NTCPV6Acceptor; |
|
||||||
std::map<i2p::data::IdentHash, std::shared_ptr<NTCPSession> > m_NTCPSessions; // access from m_Thread only
|
|
||||||
std::list<std::shared_ptr<NTCPSession> > m_PendingIncomingSessions; |
|
||||||
|
|
||||||
ProxyType m_ProxyType; |
|
||||||
std::string m_ProxyAddress; |
|
||||||
uint16_t m_ProxyPort; |
|
||||||
boost::asio::ip::tcp::resolver m_Resolver; |
|
||||||
boost::asio::ip::tcp::endpoint * m_ProxyEndpoint; |
|
||||||
|
|
||||||
std::shared_ptr<Pool> m_CryptoPool; |
|
||||||
|
|
||||||
uint16_t m_SoftLimit, m_HardLimit; |
|
||||||
public: |
|
||||||
|
|
||||||
// for HTTP/I2PControl
|
|
||||||
const decltype(m_NTCPSessions)& GetNTCPSessions () const { return m_NTCPSessions; }; |
|
||||||
}; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#endif |
|
Loading…
Reference in new issue