use local sockets for android

This commit is contained in:
orignal 2016-06-22 15:48:36 -04:00
parent 7ea5af448e
commit 49d2878938
2 changed files with 43 additions and 5 deletions

View File

@ -114,7 +114,12 @@ namespace client
}
}
I2CPSession::I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket):
I2CPSession::I2CPSession (I2CPServer& owner,
#ifdef ANDROID
std::shared_ptr<boost::asio::local::stream_protocol::socket> socket):
#else
std::shared_ptr<boost::asio::ip::tcp::socket> socket):
#endif
m_Owner (owner), m_Socket (socket), m_Payload (nullptr),
m_SessionID (0xFFFF), m_MessageID (0), m_IsSendAccepted (true)
{
@ -583,7 +588,12 @@ namespace client
I2CPServer::I2CPServer (const std::string& interface, int port):
m_IsRunning (false), m_Thread (nullptr),
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(interface), port))
m_Acceptor (m_Service,
#ifdef ANDROID
boost::asio::local::stream_protocol::endpoint(std::string (1, '\0') + interface)) // leading 0 for abstract address
#else
boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(interface), port))
#endif
{
memset (m_MessagesHandlers, 0, sizeof (m_MessagesHandlers));
m_MessagesHandlers[I2CP_GET_DATE_MESSAGE] = &I2CPSession::GetDateMessageHandler;
@ -644,12 +654,21 @@ namespace client
void I2CPServer::Accept ()
{
#ifdef ANDROID
auto newSocket = std::make_shared<boost::asio::local::stream_protocol::socket> (m_Service);
#else
auto newSocket = std::make_shared<boost::asio::ip::tcp::socket> (m_Service);
#endif
m_Acceptor.async_accept (*newSocket, std::bind (&I2CPServer::HandleAccept, this,
std::placeholders::_1, newSocket));
}
void I2CPServer::HandleAccept(const boost::system::error_code& ecode, std::shared_ptr<boost::asio::ip::tcp::socket> socket)
void I2CPServer::HandleAccept(const boost::system::error_code& ecode,
#ifdef ANDROID
std::shared_ptr<boost::asio::local::stream_protocol::socket> socket)
#else
std::shared_ptr<boost::asio::ip::tcp::socket> socket)
#endif
{
if (!ecode && socket)
{

23
I2CP.h
View File

@ -99,7 +99,12 @@ namespace client
{
public:
I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
I2CPSession (I2CPServer& owner,
#ifdef ANDROID
std::shared_ptr<boost::asio::local::stream_protocol::socket> socket);
#else
std::shared_ptr<boost::asio::ip::tcp::socket> socket);
#endif
~I2CPSession ();
void Start ();
@ -144,7 +149,11 @@ namespace client
private:
I2CPServer& m_Owner;
#ifdef ANDROID
std::shared_ptr<boost::asio::local::stream_protocol::socket> m_Socket;
#else
std::shared_ptr<boost::asio::ip::tcp::socket> m_Socket;
#endif
uint8_t m_Header[I2CP_HEADER_SIZE], * m_Payload;
size_t m_PayloadLen;
@ -173,7 +182,13 @@ namespace client
void Run ();
void Accept ();
void HandleAccept(const boost::system::error_code& ecode, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
void HandleAccept(const boost::system::error_code& ecode,
#ifdef ANDROID
std::shared_ptr<boost::asio::local::stream_protocol::socket> socket);
#else
std::shared_ptr<boost::asio::ip::tcp::socket> socket);
#endif
private:
@ -183,7 +198,11 @@ namespace client
bool m_IsRunning;
std::thread * m_Thread;
boost::asio::io_service m_Service;
#ifdef ANDROID
boost::asio::local::stream_protocol::acceptor m_Acceptor;
#else
boost::asio::ip::tcp::acceptor m_Acceptor;
#endif
public: