4 Commits

3 changed files with 63 additions and 17 deletions

View File

@@ -7,9 +7,13 @@ TARGET=libi2psam.a
$(TARGET): $(OBJS)
$(AR) $(ARFLAGS) $(TARGET) $(OBJS)
LOADLIBES=-L./ -li2psam
LOADLIBES=-L./ -li2psam -lboost_system -lboost_thread -lpthread
eepget: eepget.cpp $(TARGET)
export USE_BOOST=1
boost: boost.cpp $(TARGET)
clean:
$(RM) $(TARGET) $(OBJS) eepget

View File

@@ -13,10 +13,11 @@
#include <stdlib.h>
#include <time.h>
#include <stdarg.h>
#include <boost/asio.hpp>
// Was 65536, seemed unnecessarily large
#define SAM_BUFSIZE 4096
#define I2P_DESTINATION_SIZE 516
#define I2P_MIN_DESTINATION_SIZE 516
// Define this, if you want more of the original standard output diagnostics
// #define DEBUG_ON_STDOUT
@@ -169,6 +170,22 @@ void I2pSocket::write(const std::string& msg)
}
}
std::size_t I2pSocket::write_some(boost::asio::const_buffers_1 buffer, boost::system::error_code ec) {
// get a string from the buffer
std::string str(boost::asio::buffers_begin(buffer), boost::asio::buffers_end(buffer));
// get the buffer size
std::size_t size = boost::asio::buffer_size(buffer);
write(str);
return size;
}
std::size_t I2pSocket::read_some(boost::asio::mutable_buffers_1 buffer, boost::system::error_code ec) {
// get a string from the buffer
//std::string str(boost::asio::buffers_begin(buffer), boost::asio::buffers_end(buffer));
std::string str = read();
return str.size();
}
std::string I2pSocket::read()
{
if (!isOk())
@@ -334,20 +351,23 @@ RequestResult<std::unique_ptr<I2pSocket> > StreamSession::connect(const std::str
std::unique_ptr<I2pSocket> streamSocket(new I2pSocket(socket_));
const Message::eStatus status = connect(*streamSocket, sessionID_, destination, silent);
switch(status)
{
case Message::OK:
return ResultType(std::move(streamSocket));
case Message::EMPTY_ANSWER:
case Message::CLOSED_SOCKET:
case Message::INVALID_ID:
case Message::I2P_ERROR:
fallSick();
break;
default:
break;
if (!silent) {
switch(status)
{
case Message::OK:
return ResultType(std::move(streamSocket));
case Message::EMPTY_ANSWER:
case Message::CLOSED_SOCKET:
case Message::INVALID_ID:
case Message::I2P_ERROR:
fallSick();
break;
default:
break;
}
return ResultType();
}
return ResultType();
return ResultType(std::move(streamSocket));
}
RequestResult<void> StreamSession::forward(const std::string& host, uint16_t port, bool silent)
@@ -417,16 +437,26 @@ RequestResult<const FullDestination> StreamSession::destGenerate() const
}
FullDestination StreamSession::createStreamSession(const std::string& destination)
{
return createStreamSession(destination, SAM_SIGNATURE_TYPE);
}
FullDestination StreamSession::createStreamSession(const std::string& destination, const std::string& sigType)
{
return createStreamSession(destination, sigType, i2pOptions_);
}
FullDestination StreamSession::createStreamSession(const std::string& destination, const std::string& sigType, const std::string& i2pOptions)
{
typedef Message::Answer<const std::string> AnswerType;
const AnswerType answer = createStreamSession(socket_, sessionID_, nickname_, destination, i2pOptions_, SAM_SIGNATURE_TYPE);
const AnswerType answer = createStreamSession(socket_, sessionID_, nickname_, destination, i2pOptions, sigType);
if (answer.status != Message::OK)
{
fallSick();
return FullDestination();
}
return FullDestination(answer.value.substr(0, I2P_DESTINATION_SIZE), answer.value, (destination == SAM_GENERATE_MY_DESTINATION));
return FullDestination(answer.value.c_str(), answer.value, (destination == SAM_GENERATE_MY_DESTINATION));
}
void StreamSession::fallSick() const

View File

@@ -45,12 +45,15 @@
#ifdef __cplusplus // __cplusplus
#include "compat.h"
#include <boost/asio.hpp>
#include <string>
#include <list>
#include <stdint.h>
#include <memory>
#include <utility>
using namespace boost::asio;
namespace SAM
{
@@ -213,6 +216,13 @@ public:
void write(const std::string& msg);
std::string read();
// only include these if we're compiling with boost
//#ifdef USE_BOOST
std::size_t write_some(boost::asio::const_buffers_1 buffer, boost::system::error_code error);
std::size_t read_some(boost::asio::mutable_buffers_1 buffer, boost::system::error_code error);
//#endif
SOCKET release();
void close();
@@ -390,6 +400,8 @@ private:
void fallSick() const;
FullDestination createStreamSession(const std::string &destination);
FullDestination createStreamSession(const std::string &destination, const std::string &sigType);
FullDestination createStreamSession(const std::string &destination, const std::string &sigType, const std::string &i2pOptions);
static Message::Answer<const std::string> rawRequest(I2pSocket& socket, const std::string& requestStr);
static Message::Answer<const std::string> request(I2pSocket& socket, const std::string& requestStr, const std::string& keyOnSuccess);