8 #if defined(HAVE_CONFIG_H)
16 #include <boost/thread/shared_mutex.hpp>
23 explicit SessionHolder(std::auto_ptr<SAM::StreamSession> session);
31 mutable std::auto_ptr<SAM::StreamSession>
session_;
41 boost::upgrade_lock<mutex_type> lock(mtx_);
42 if (session_->isSick())
44 boost::upgrade_to_unique_lock<mutex_type> ulock(lock);
52 boost::upgrade_lock<mutex_type> lock(mtx_);
53 if (session_->isSick())
55 boost::upgrade_to_unique_lock<mutex_type> ulock(lock);
68 if (!session_->isSick())
71 if (!newSession->isSick() && session_->isSick())
72 session_ = newSession;
78 const std::string& nickname,
79 const std::string& SAMHost ,
81 const std::string& myDestination ,
82 const std::string& i2pOptions ,
83 const std::string& minVer ,
84 const std::string& maxVer )
88 new
SAM::
StreamSession(nickname, SAMHost, SAMPort, myDestination, i2pOptions, minVer, maxVer))))
110 return sessionHolder_->getSession().forward(host, port, silent).isOk;
116 return result.
isOk ? result.
value : std::string();
192 static std::string sOptions;
208 void static FormatBoolI2POptionsString( std::string& I2pOptions,
const std::string& I2pSamName,
const std::string& confParamName ) {
209 bool fConfigValue =
GetArg( confParamName,
true );
211 if (!I2pOptions.empty()) I2pOptions +=
" ";
212 I2pOptions += I2pSamName +
"=" + (fConfigValue ?
"true" :
"false");
215 void static FormatIntI2POptionsString( std::string& I2pOptions,
const std::string& I2pSamName,
const std::string& confParamName ) {
216 int64_t i64ConfigValue =
GetArg( confParamName, 0 );
218 if (!I2pOptions.empty()) I2pOptions +=
" ";
219 std::ostringstream oss;
220 oss << i64ConfigValue;
221 I2pOptions += I2pSamName +
"=" + oss.str();
224 void static BuildI2pOptionsString(
void ) {
241 std::string ExtrasStr =
GetArg(
"-i2p.options.extra",
"");
242 if( ExtrasStr.size() ) {
243 if (!OptStr.empty()) OptStr +=
" ";
258 SoftSetArg(
"-i2p.options.inbound.quantity",
"3" );
259 SoftSetArg(
"-i2p.options.inbound.length",
"3" );
260 SoftSetArg(
"-i2p.options.inbound.lengthvariance",
"0" );
261 SoftSetArg(
"-i2p.options.inbound.backupquantity",
"1" );
263 SoftSetArg(
"-i2p.options.inbound.iprestriction",
"2" );
264 SoftSetArg(
"-i2p.options.outbound.quantity",
"3" );
265 SoftSetArg(
"-i2p.options.outbound.length",
"3" );
266 SoftSetArg(
"-i2p.options.outbound.lengthvariance",
"0" );
267 SoftSetArg(
"-i2p.options.outbound.backupquantity",
"1" );
269 SoftSetArg(
"-i2p.options.outbound.iprestriction",
"2" );
270 SoftSetArg(
"-i2p.options.outbound.priority",
"0" );
278 if(
GetBoolArg(
"-i2p.options.static",
false ) )
285 BuildI2pOptionsString();
300 return fPublic && fPrivate;
304 return (B32Address.size() ==
NATIVE_I2P_B32ADDR_SIZE) && (B32Address.substr(B32Address.size() - 8, 8) ==
".b32.i2p");
309 std::string canonicalDest = destination;
310 for (
size_t pos = canonicalDest.find_first_of(
'-'); pos != std::string::npos; pos = canonicalDest.find_first_of(
'-', pos))
311 canonicalDest[pos] =
'+';
312 for (
size_t pos = canonicalDest.find_first_of(
'~'); pos != std::string::npos; pos = canonicalDest.find_first_of(
'~', pos))
313 canonicalDest[pos] =
'/';
316 SHA256((
const unsigned char*)rawHash.c_str(), rawHash.size(), (
unsigned char*)&hash);
318 for (
size_t pos = result.find_first_of(
'='); pos != std::string::npos; pos = result.find_first_of(
'=', pos-1))
319 result.erase(pos, 1);
std::string namingLookup(const std::string &name) const
#define SAM_DEFAULT_ADDRESS
#define SAM_NAME_OUTBOUND_BACKUPQUANTITY
void stopForwarding(const std::string &host, uint16_t port)
const std::string & getNickname() const
const SAM::FullDestination & getMyDestination() const
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool isValidI2pAddress(const std::string &I2pAddr)
#define SAM_INVALID_SOCKET
const std::string & getOptions() const
#define SAM_NAME_INBOUND_BACKUPQUANTITY
std::string B32AddressFromDestination(const std::string &destination)
const std::string & getSAMHost() const
SAM::SOCKET accept(bool silent)
#define SAM_NAME_OUTBOUND_ALLOWZEROHOP
#define SAM_NAME_OUTBOUND_QUANTITY
const std::string & getSAMMinVer() const
#define SAM_NAME_INBOUND_QUANTITY
bool isValidI2pDestination(const SAM::FullDestination &DestKeys)
#define SAM_NAME_OUTBOUND_PRIORITY
void InitializeI2pSettings(void)
uint16_t getSAMPort() const
#define SAM_DEFAULT_OUTBOUND_ALLOWZEROHOP
#define I2P_SESSION_NAME_DEFAULT
const std::string & getSAMVersion() const
SAM::SOCKET connect(const std::string &destination, bool silent)
const std::string & getSessionID() const
#define NATIVE_I2P_B32ADDR_SIZE
std::auto_ptr< SessionHolder > sessionHolder_
bool isValidI2pB32(const std::string &B32Address)
#define SAM_NAME_INBOUND_IPRESTRICTION
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
#define SAM_NAME_INBOUND_ALLOWZEROHOP
#define SAM_NAME_INBOUND_LENGTH
#define NATIVE_I2P_DESTINATION_SIZE
#define SAM_NAME_INBOUND_LENGTHVARIANCE
StreamSessionAdapter(const std::string &nickname, const std::string &SAMHost=SAM_DEFAULT_ADDRESS, uint16_t SAMPort=SAM_DEFAULT_PORT, const std::string &myDestination=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)
string EncodeBase32(const unsigned char *pch, size_t len)
#define SAM_DEFAULT_INBOUND_ALLOWZEROHOP
#define SAM_GENERATE_MY_DESTINATION
boost::shared_mutex mutex_type
const sockaddr_in & getSAMAddress() const
SessionHolder(std::auto_ptr< SAM::StreamSession > session)
std::auto_ptr< SAM::StreamSession > session_
#define SAM_NAME_OUTBOUND_IPRESTRICTION
static std::string GenerateB32AddressFromDestination(const std::string &destination)
SAM::FullDestination destGenerate() const
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
bool forward(const std::string &host, uint16_t port, bool silent)
#define SAM_NAME_OUTBOUND_LENGTHVARIANCE
const SAM::StreamSession & getSession() const
#define SAM_NAME_OUTBOUND_LENGTH
const std::string & getSAMMaxVer() const