Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
292767eaa8 | ||
![]() |
4b4186dd77 | ||
![]() |
655bfe38aa | ||
![]() |
58a93fc5e3 |
6
Makefile
6
Makefile
@@ -7,9 +7,13 @@ TARGET=libi2psam.a
|
|||||||
$(TARGET): $(OBJS)
|
$(TARGET): $(OBJS)
|
||||||
$(AR) $(ARFLAGS) $(TARGET) $(OBJS)
|
$(AR) $(ARFLAGS) $(TARGET) $(OBJS)
|
||||||
|
|
||||||
LOADLIBES=-L./ -li2psam
|
LOADLIBES=-L./ -li2psam -lboost_system -lboost_thread -lpthread
|
||||||
|
|
||||||
eepget: eepget.cpp $(TARGET)
|
eepget: eepget.cpp $(TARGET)
|
||||||
|
|
||||||
|
export USE_BOOST=1
|
||||||
|
|
||||||
|
boost: boost.cpp $(TARGET)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(TARGET) $(OBJS) eepget
|
$(RM) $(TARGET) $(OBJS) eepget
|
||||||
|
62
i2psam.cpp
62
i2psam.cpp
@@ -13,10 +13,11 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
// Was 65536, seemed unnecessarily large
|
// Was 65536, seemed unnecessarily large
|
||||||
#define SAM_BUFSIZE 4096
|
#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 this, if you want more of the original standard output diagnostics
|
||||||
// #define DEBUG_ON_STDOUT
|
// #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()
|
std::string I2pSocket::read()
|
||||||
{
|
{
|
||||||
if (!isOk())
|
if (!isOk())
|
||||||
@@ -334,20 +351,23 @@ RequestResult<std::unique_ptr<I2pSocket> > StreamSession::connect(const std::str
|
|||||||
|
|
||||||
std::unique_ptr<I2pSocket> streamSocket(new I2pSocket(socket_));
|
std::unique_ptr<I2pSocket> streamSocket(new I2pSocket(socket_));
|
||||||
const Message::eStatus status = connect(*streamSocket, sessionID_, destination, silent);
|
const Message::eStatus status = connect(*streamSocket, sessionID_, destination, silent);
|
||||||
switch(status)
|
if (!silent) {
|
||||||
{
|
switch(status)
|
||||||
case Message::OK:
|
{
|
||||||
return ResultType(std::move(streamSocket));
|
case Message::OK:
|
||||||
case Message::EMPTY_ANSWER:
|
return ResultType(std::move(streamSocket));
|
||||||
case Message::CLOSED_SOCKET:
|
case Message::EMPTY_ANSWER:
|
||||||
case Message::INVALID_ID:
|
case Message::CLOSED_SOCKET:
|
||||||
case Message::I2P_ERROR:
|
case Message::INVALID_ID:
|
||||||
fallSick();
|
case Message::I2P_ERROR:
|
||||||
break;
|
fallSick();
|
||||||
default:
|
break;
|
||||||
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)
|
RequestResult<void> StreamSession::forward(const std::string& host, uint16_t port, bool silent)
|
||||||
@@ -418,15 +438,25 @@ RequestResult<const FullDestination> StreamSession::destGenerate() const
|
|||||||
|
|
||||||
FullDestination StreamSession::createStreamSession(const std::string& destination)
|
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;
|
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)
|
if (answer.status != Message::OK)
|
||||||
{
|
{
|
||||||
fallSick();
|
fallSick();
|
||||||
return FullDestination();
|
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
|
void StreamSession::fallSick() const
|
||||||
|
12
i2psam.h
12
i2psam.h
@@ -45,12 +45,15 @@
|
|||||||
#ifdef __cplusplus // __cplusplus
|
#ifdef __cplusplus // __cplusplus
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|
||||||
|
#include <boost/asio.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
using namespace boost::asio;
|
||||||
|
|
||||||
namespace SAM
|
namespace SAM
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -213,6 +216,13 @@ public:
|
|||||||
|
|
||||||
void write(const std::string& msg);
|
void write(const std::string& msg);
|
||||||
std::string read();
|
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();
|
SOCKET release();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
@@ -390,6 +400,8 @@ private:
|
|||||||
|
|
||||||
void fallSick() const;
|
void fallSick() const;
|
||||||
FullDestination createStreamSession(const std::string &destination);
|
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> rawRequest(I2pSocket& socket, const std::string& requestStr);
|
||||||
static Message::Answer<const std::string> request(I2pSocket& socket, const std::string& requestStr, const std::string& keyOnSuccess);
|
static Message::Answer<const std::string> request(I2pSocket& socket, const std::string& requestStr, const std::string& keyOnSuccess);
|
||||||
|
Reference in New Issue
Block a user