Remove SAM version range from API

The library should handle version negotiation, and fail gracefully if the user
asks the library to do something that the negotiated version doesn't allow.
github/master
str4d 2017-04-02 10:07:36 +12:00
parent a50d85ca9d
commit 0adc0121b7
2 changed files with 12 additions and 46 deletions

View File

@ -52,8 +52,8 @@ void I2pSocket::freeWSA()
}
#endif
I2pSocket::I2pSocket(const std::string& SAMHost, uint16_t SAMPort, const std::string& minVer, const std::string &maxVer)
: socket_(INVALID_SOCKET), SAMHost_(SAMHost), SAMPort_(SAMPort), minVer_(minVer), maxVer_(maxVer)
I2pSocket::I2pSocket(const std::string& SAMHost, uint16_t SAMPort)
: socket_(INVALID_SOCKET), SAMHost_(SAMHost), SAMPort_(SAMPort)
{
#ifdef WIN32
if (instances_++ == 0)
@ -68,8 +68,8 @@ I2pSocket::I2pSocket(const std::string& SAMHost, uint16_t SAMPort, const std::st
bootstrapI2P();
}
I2pSocket::I2pSocket(const sockaddr_in& addr, const std::string &minVer, const std::string& maxVer)
: socket_(INVALID_SOCKET), servAddr_(addr), minVer_(minVer), maxVer_(maxVer)
I2pSocket::I2pSocket(const sockaddr_in& addr)
: socket_(INVALID_SOCKET), servAddr_(addr)
{
#ifdef WIN32
if (instances_++ == 0)
@ -79,7 +79,7 @@ I2pSocket::I2pSocket(const sockaddr_in& addr, const std::string &minVer, const s
}
I2pSocket::I2pSocket(const I2pSocket& rhs)
: socket_(INVALID_SOCKET), servAddr_(rhs.servAddr_), minVer_(rhs.minVer_), maxVer_(rhs.maxVer_)
: socket_(INVALID_SOCKET), servAddr_(rhs.servAddr_)
{
#ifdef WIN32
if (instances_++ == 0)
@ -228,16 +228,6 @@ const std::string& I2pSocket::getVersion() const
return version_;
}
const std::string& I2pSocket::getMinVer() const
{
return minVer_;
}
const std::string& I2pSocket::getMaxVer() const
{
return maxVer_;
}
const sockaddr_in& I2pSocket::getAddress() const
{
return servAddr_;
@ -251,10 +241,8 @@ StreamSession::StreamSession(
const std::string& SAMHost /*= SAM_DEFAULT_ADDRESS*/,
uint16_t SAMPort /*= SAM_DEFAULT_PORT*/,
const std::string& destination /*= SAM_GENERATE_MY_DESTINATION*/,
const std::string& i2pOptions /*= SAM_DEFAULT_I2P_OPTIONS*/,
const std::string& minVer /*= SAM_DEFAULT_MIN_VER*/,
const std::string& maxVer /*= SAM_DEFAULT_MAX_VER*/)
: socket_(SAMHost, SAMPort, minVer, maxVer)
const std::string& i2pOptions /*= SAM_DEFAULT_I2P_OPTIONS*/)
: socket_(SAMHost, SAMPort)
, nickname_(nickname)
, sessionID_(generateSessionID())
, i2pOptions_(i2pOptions)
@ -607,22 +595,6 @@ uint16_t StreamSession::getSAMPort() const
return socket_.getPort();
}
const std::string& StreamSession::getSAMMinVer() const
{
#ifdef DEBUG_ON_STDOUT
std::cout << "getSAMMinVer: " << socket_.getMinVer() << std::endl;
#endif // DEBUG_ON_STDOUT
return socket_.getMinVer();
}
const std::string& StreamSession::getSAMMaxVer() const
{
#ifdef DEBUG_ON_STDOUT
std::cout << "getSAMMaxVer: " << socket_.getMaxVer() << std::endl;
#endif // DEBUG_ON_STDOUT
return socket_.getMaxVer();
}
const std::string& StreamSession::getSAMVersion() const
{
#ifdef DEBUG_ON_STDOUT

View File

@ -18,8 +18,6 @@
#define SAM_DEFAULT_ADDRESS "127.0.0.1"
#define SAM_DEFAULT_PORT 7656
#define SAM_DEFAULT_MIN_VER "3.0"
#define SAM_DEFAULT_MAX_VER "3.0"
#define SAM_GENERATE_MY_DESTINATION "TRANSIENT"
#define SAM_MY_NAME "ME"
#define SAM_DEFAULT_I2P_OPTIONS ""
@ -201,8 +199,8 @@ private:
class I2pSocket
{
public:
I2pSocket(const std::string& SAMHost, uint16_t SAMPort, const std::string &minVer, const std::string& maxVer);
I2pSocket(const sockaddr_in& addr, const std::string& minVer, const std::string& maxVer);
I2pSocket(const std::string& SAMHost, uint16_t SAMPort);
I2pSocket(const sockaddr_in& addr);
// explicit because we don't want to create any socket implicity
explicit I2pSocket(const I2pSocket& rhs); // creates a new socket with the same parameters
~I2pSocket();
@ -219,8 +217,6 @@ public:
const std::string& getVersion() const;
const std::string& getHost() const;
uint16_t getPort() const;
const std::string& getMinVer() const;
const std::string& getMaxVer() const;
const sockaddr_in& getAddress() const;
@ -229,8 +225,8 @@ private:
sockaddr_in servAddr_;
std::string SAMHost_;
uint16_t SAMPort_;
const std::string minVer_;
const std::string maxVer_;
const std::string minVer_ = "3.0";
const std::string maxVer_ = "3.0";
std::string version_;
#ifdef WIN32
@ -332,9 +328,7 @@ public:
const std::string& SAMHost = SAM_DEFAULT_ADDRESS,
uint16_t SAMPort = SAM_DEFAULT_PORT,
const std::string& destination = SAM_GENERATE_MY_DESTINATION,
const std::string& i2pOptions = SAM_DEFAULT_I2P_OPTIONS,
const std::string& minVer = SAM_DEFAULT_MIN_VER,
const std::string& maxVer = SAM_DEFAULT_MAX_VER);
const std::string& i2pOptions = SAM_DEFAULT_I2P_OPTIONS);
explicit StreamSession(StreamSession& rhs);
~StreamSession();