From 58a93fc5e32d1836b5b3d916ef18fe5be1338036 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 30 Mar 2022 01:32:20 -0400 Subject: [PATCH 1/3] fix destination parsing issue with wrong lengths, looks like we can just use c_str(), closes #9 --- i2psam.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/i2psam.cpp b/i2psam.cpp index a1dca52..6f016ed 100644 --- a/i2psam.cpp +++ b/i2psam.cpp @@ -16,7 +16,7 @@ // 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 @@ -426,7 +426,7 @@ FullDestination StreamSession::createStreamSession(const std::string& destinatio 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 From 655bfe38aa39c2688d765075b5f77c8604922de2 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 30 Mar 2022 01:38:21 -0400 Subject: [PATCH 2/3] fix destination parsing issue with wrong lengths, looks like we can just use c_str(), closes #7 --- i2psam.cpp | 12 +++++++++++- i2psam.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/i2psam.cpp b/i2psam.cpp index 6f016ed..bd61289 100644 --- a/i2psam.cpp +++ b/i2psam.cpp @@ -418,9 +418,19 @@ RequestResult 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 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(); diff --git a/i2psam.h b/i2psam.h index 6fb8e39..7d0ad50 100644 --- a/i2psam.h +++ b/i2psam.h @@ -390,6 +390,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 rawRequest(I2pSocket& socket, const std::string& requestStr); static Message::Answer request(I2pSocket& socket, const std::string& requestStr, const std::string& keyOnSuccess); From 4b4186dd7745561ba5ee8b601695bd5122ac268c Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 30 Mar 2022 01:41:52 -0400 Subject: [PATCH 3/3] ignore result type and just move the stream socket if silent is true. Closes #8 --- i2psam.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/i2psam.cpp b/i2psam.cpp index bd61289..fd91dcd 100644 --- a/i2psam.cpp +++ b/i2psam.cpp @@ -334,20 +334,23 @@ RequestResult > StreamSession::connect(const std::str std::unique_ptr 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 StreamSession::forward(const std::string& host, uint16_t port, bool silent)