Browse Source

SSU added

pull/14/head
orignal 11 years ago
parent
commit
3cf3e69aef
  1. 2
      Makefile
  2. 44
      SSU.cpp
  3. 36
      SSU.h
  4. 21
      Transports.cpp
  5. 2
      Transports.h

2
Makefile

@ -3,7 +3,7 @@ CC = g++ @@ -3,7 +3,7 @@ CC = g++
CFLAGS = -g -Wall -std=c++0x
OBJECTS = i2p.o base64.o NTCPSession.o RouterInfo.o Transports.o RouterContext.o \
NetDb.o LeaseSet.o Tunnel.o TunnelEndpoint.o TunnelGateway.o TransitTunnel.o \
I2NPProtocol.o Log.o Garlic.o HTTPServer.o Streaming.o Identity.o
I2NPProtocol.o Log.o Garlic.o HTTPServer.o Streaming.o Identity.o SSU.o
INCFLAGS =
LDFLAGS = -Wl,-rpath,/usr/local/lib -lcryptopp -lboost_system -lboost_filesystem
LIBS =

44
SSU.cpp

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
#include <boost/bind.hpp>
#include "Log.h"
#include "hmac.h"
#include "SSU.h"
namespace i2p
{
namespace ssu
{
SSUServer::SSUServer (boost::asio::io_service& service, int port):
m_Socket (service, boost::asio::ip::udp::v4 (), port)
{
}
void SSUServer::Start ()
{
Receive ();
}
void SSUServer::Stop ()
{
m_Socket.close ();
}
void SSUServer::Receive ()
{
m_Socket.async_receive_from (boost::asio::buffer (m_ReceiveBuffer, SSU_MTU), m_SenderEndpoint,
boost::bind (&SSUServer::HandleReceivedFrom, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
void SSUServer::HandleReceivedFrom (const boost::system::error_code& ecode, std::size_t bytes_transferred)
{
if (!ecode)
{
LogPrint ("SSU received ", bytes_transferred, " bytes");
// Handle
Receive ();
}
else
LogPrint ("SSU receive error: ", ecode.message ());
}
}
}

36
SSU.h

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
#ifndef SSU_H__
#define SSU_H__
#include <inttypes.h>
#include <boost/asio.hpp>
namespace i2p
{
namespace ssu
{
const int SSU_MTU = 1484;
class SSUServer
{
public:
SSUServer (boost::asio::io_service& service, int port);
void Start ();
void Stop ();
private:
void Receive ();
void HandleReceivedFrom (const boost::system::error_code& ecode, std::size_t bytes_transferred);
private:
boost::asio::ip::udp::socket m_Socket;
boost::asio::ip::udp::endpoint m_SenderEndpoint;
uint8_t m_ReceiveBuffer[SSU_MTU];
};
}
}
#endif

21
Transports.cpp

@ -12,7 +12,7 @@ namespace i2p @@ -12,7 +12,7 @@ namespace i2p
Transports transports;
Transports::Transports ():
m_Thread (0), m_Work (m_Service),m_NTCPAcceptor (0)
m_Thread (nullptr), m_Work (m_Service),m_NTCPAcceptor (nullptr), m_SSUServer (nullptr)
{
}
@ -34,11 +34,22 @@ namespace i2p @@ -34,11 +34,22 @@ namespace i2p
m_NTCPAcceptor = new boost::asio::ip::tcp::acceptor (m_Service,
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address.port));
LogPrint ("Start listening port ", address.port);
LogPrint ("Start listening TCP port ", address.port);
auto conn = new i2p::ntcp::NTCPServerConnection (m_Service);
m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this,
conn, boost::asio::placeholders::error));
}
else if (address.transportStyle == RouterInfo::eTransportSSU)
{
if (!m_SSUServer)
{
m_SSUServer = new i2p::ssu::SSUServer (m_Service, address.port);
LogPrint ("Start listening UDP port ", address.port);
m_SSUServer->Start ();
}
else
LogPrint ("SSU server already exists");
}
}
}
@ -49,6 +60,12 @@ namespace i2p @@ -49,6 +60,12 @@ namespace i2p
m_NTCPSessions.clear ();
delete m_NTCPAcceptor;
if (m_SSUServer)
{
m_SSUServer->Stop ();
delete m_SSUServer;
}
m_IsRunning = false;
m_Service.stop ();
if (m_Thread)

2
Transports.h

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
#include <string>
#include <boost/asio.hpp>
#include "NTCPSession.h"
#include "SSU.h"
#include "RouterInfo.h"
#include "I2NPProtocol.h"
@ -47,6 +48,7 @@ namespace i2p @@ -47,6 +48,7 @@ namespace i2p
boost::asio::ip::tcp::acceptor * m_NTCPAcceptor;
std::map<i2p::data::IdentHash, i2p::ntcp::NTCPSession *> m_NTCPSessions;
i2p::ssu::SSUServer * m_SSUServer;
public:

Loading…
Cancel
Save