remove i2psam (library) support

This commit is contained in:
sehraf 2020-11-04 17:47:29 +01:00
parent 10189ba4d0
commit eb0aa340e3
No known key found for this signature in database
GPG Key ID: DF09F6EAE356B2C6
5 changed files with 7 additions and 225 deletions

View File

@ -1,11 +1,6 @@
#include "pqissli2psam3.h"
#ifdef RS_USE_I2P_SAM3_I2PSAM
#include "util/i2psam.h"
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
#include <libsam3.h>
#endif
RS_SET_CONTEXT_DEBUG_LEVEL(2)
@ -51,12 +46,7 @@ int pqissli2psam3::Initiate_Connection()
{
if(mConn) {
// how did we end up here?
#ifdef RS_USE_I2P_SAM3_I2PSAM
unix_close(mConn);
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
sam3CloseConnection(mConn);
#endif
RS_ERR("state is NONE but a connection is existing?!");
}
mConn = 0;
// get SAM session
@ -65,12 +55,7 @@ int pqissli2psam3::Initiate_Connection()
ss.session = nullptr;
rsAutoProxyMonitor::taskSync(autoProxyType::I2PSAM3, autoProxyTask::getSettings, static_cast<void*>(&ss));
#ifdef RS_USE_I2P_SAM3_I2PSAM
if (!!ss.session && !ss.session->isSick()) {
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
if (!!ss.session) {
#endif
RS_DBG3("NONE->DO_LOOKUP");
mState = pqisslSam3State::DO_LOOKUP;
} else {
@ -102,12 +87,8 @@ int pqissli2psam3::Initiate_Connection()
auto wrapper = new samEstablishConnectionWrapper();
wrapper->address.clear();
wrapper->address.publicKey = mI2pAddrLong;
#ifdef RS_USE_I2P_SAM3_I2PSAM
wrapper->socket = 0;
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
wrapper->connection = nullptr;
#endif
rsAutoProxyMonitor::taskAsync(autoProxyType::I2PSAM3, autoProxyTask::establishConnection, this, static_cast<void*>(wrapper));
}
mState = pqisslSam3State::WAIT_CONNECT;
@ -135,29 +116,14 @@ int pqissli2psam3::net_internal_close(int fd)
RS_DBG4();
// sanity check
#ifdef RS_USE_I2P_SAM3_I2PSAM
if (mConn && fd != mConn) {
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
if (mConn && fd != mConn->fd) {
#endif
// this should never happen!
//#ifdef RS_USE_I2P_SAM3_I2PSAM
// unix_close(mConn);
//#endif
//#ifdef RS_USE_I2P_SAM3_LIBSAM3
RS_ERR("fd != mConn");
// sam3CloseConnection(mConn);
//#endif
}
// now to the actuall closing
int ret = pqissl::net_internal_close(fd);
// int ret = 0;
//#ifdef RS_USE_I2P_SAM3_LIBSAM3
// if (mConn)
// ret = sam3CloseConnection(mConn);
//#endif
rsAutoProxyMonitor::taskAsync(autoProxyType::I2PSAM3, autoProxyTask::closeConnection, this, mConn),
// finally cleanup
@ -195,12 +161,7 @@ void pqissli2psam3::taskFinished(taskTicket *&ticket)
RS_STACK_MUTEX(mSslMtx);
if (ticket->result == autoProxyStatus::ok) {
#ifdef RS_USE_I2P_SAM3_I2PSAM
mConn = wrapper->socket;
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
mConn = wrapper->connection;
#endif
mState = pqisslSam3State::DONE;
} else {
waiting = WAITING_FAIL_INTERFACE;
@ -229,12 +190,7 @@ bool pqissli2psam3::setupSocket()
* This function contains the generis part from pqissl::Initiate_Connection()
*/
int err;
#ifdef RS_USE_I2P_SAM3_I2PSAM
int osock = mConn;
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
int osock = mConn->fd;
#endif
err = unix_fcntl_nonblock(osock);
if (err < 0)

View File

@ -41,13 +41,7 @@ private:
std::string mI2pAddrB32;
std::string mI2pAddrLong;
// samSession *mSs;
#ifdef RS_USE_I2P_SAM3_I2PSAM
int mConn;
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
Sam3Connection *mConn;
#endif
};
#endif // PQISSLI2PSAM3_H

View File

@ -1,11 +1,6 @@
#include "p3i2psam3.h"
#ifdef RS_USE_I2P_SAM3_LIBSAM3
#include <libsam3.h>
#endif
#ifdef RS_USE_I2P_SAM3_I2PSAM
#include "util/i2psam.h"
#endif
#include "pqi/p3peermgr.h"
#include "rsitems/rsconfigitems.h"
@ -36,9 +31,6 @@ static constexpr bool kDefaultSAM3Enable = false;
RS_SET_CONTEXT_DEBUG_LEVEL(4)
// copy from i2psam.cpp
//#define I2P_DESTINATION_SIZE 516
static void inline doSleep(std::chrono::duration<long, std::ratio<1,1000>> timeToSleepMS) {
std::this_thread::sleep_for(timeToSleepMS);
}
@ -176,12 +168,8 @@ void p3I2pSam3::processTaskSync(taskTicket *ticket)
rsAutoProxyMonitor::taskDone(ticket, autoProxyStatus::ok);
break;
case autoProxyTask::getErrorInfo:
#ifdef RS_USE_I2P_SAM3_LIBSAM3
*static_cast<std::string *>(ticket->data) = mSetting.session->error;
rsAutoProxyMonitor::taskDone(ticket, autoProxyStatus::ok);
#else
rsAutoProxyMonitor::taskError(ticket);
#endif
break;
case autoProxyTask::reloadConfig:
{
@ -298,23 +286,14 @@ void p3I2pSam3::threadTick()
case autoProxyTask::lookupKey:
lookupKey(tt);
#ifdef RS_USE_I2P_SAM3_I2PSAM
// artificially delay following operations as i2psam uses time(null) as rng seed
doSleep(std::chrono::seconds(1));
#endif
break;
case autoProxyTask::proxyStatusCheck:
{
// TODO better detection of status
bool ok;
#ifdef RS_USE_I2P_SAM3_I2PSAM
ok = !mSetting.session->isSick();
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
ok = !!mSetting.session->fd;
ok &= !!mSetting.session->fwd_fd;
#endif // RS_USE_I2P_SAM3_LIBSAM3
*static_cast<bool*>(tt->data) = ok;
rsAutoProxyMonitor::taskDone(tt, ok ? autoProxyStatus::ok : autoProxyStatus::error);
}
@ -497,70 +476,6 @@ bool p3I2pSam3::startSession()
paramsStr.append(p + " ");
// keep trailing space for easier extending when necessary
#ifdef RS_USE_I2P_SAM3_I2PSAM
if(mSetting.session) {
RS_STACK_MUTEX(mLock);
delete mSetting.session; // stopForwardingAll(); is called in destructor
mSetting.session = nullptr;
}
SAM::StreamSession *session;
if(!mSetting.address.privateKey.empty()) {
Dbg3() << __PRETTY_FUNCTION__ << " with destination" << std::endl;
session = new SAM::StreamSession(nick, SAM_DEFAULT_ADDRESS, SAM_DEFAULT_PORT, mSetting.address.privateKey, paramsStr);
} else {
Dbg3() << __PRETTY_FUNCTION__ << " without destination" << std::endl;
session = new SAM::StreamSession(nick, SAM_DEFAULT_ADDRESS, SAM_DEFAULT_PORT, SAM_GENERATE_MY_DESTINATION, paramsStr, "DSA_SHA1");
}
if (!session || session->isSick()) {
return false;
}
/*
* i2psam is sometimes unable to reliable read the public key, which is crucial to base32 address generation
* (due to the fact that is assumes it's length wrongly)
*
* The following are attempts to reliable receive our public key
*/
const auto dest = session->getMyDestination();
// auto copy = dest;
std::string pubKey1 = dest.pub;
std::string pubKey2(dest.pub);
i2p::validatePubkeyFromPrivKey(pubKey2, dest.priv);
/*
* pubkeys:
* 1: from initial call (== dest.pub)
* 2: from parsing (was == dest.pub
*/
Dbg3() << __PRETTY_FUNCTION__ << " figuring out our pubKey: p1 " << pubKey1 << std::endl;
Dbg3() << __PRETTY_FUNCTION__ << " figuring out our pubKey: p2 " << pubKey2 << std::endl;
if (pubKey1 == pubKey2) {
// unchanged
Dbg3() << __PRETTY_FUNCTION__ << " figuring out our pubKey: p1 == p2" << std::endl;
} else {
// parsed pub key is different, prefer parsed one
pubKey1 = pubKey2;
Dbg3() << __PRETTY_FUNCTION__ << " figuring out our pubKey: p1 != p2" << std::endl;
}
SAM::FullDestination dest2(pubKey1, dest.priv, true);
// populate settings
RS_STACK_MUTEX(mLock);
mSetting.session = session;
if (!mSetting.address.publicKey.empty() && mSetting.address.publicKey != dest2.pub)
// This should be ok for non hidden locations. This should be a problem for hidden i2p locations...
RsDbg() << __PRETTY_FUNCTION__ << " public key changed! Yet unsure if this is ok or a problem" << std::endl;
mSetting.address.publicKey = dest2.pub;
mSetting.address.base32 = i2p::keyToBase32Addr(dest2.pub);
// do not overwrite the private key, if any!!
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
int ret;
if (mSetting.session) {
@ -604,7 +519,6 @@ bool p3I2pSam3::startSession()
mSetting.address.publicKey = session->pubkey;
mSetting.address.base32 = i2p::keyToBase32Addr(session->pubkey);
// do not overwrite the private key, if any!!
#endif
RS_DBG1("nick:", nick, "address:", mSetting.address.base32);
RS_DBG2(" myDestination.pub ", mSetting.address.publicKey);
@ -631,16 +545,6 @@ bool p3I2pSam3::startForwarding()
peerState ps;
mPeerMgr->getOwnNetStatus(ps);
#ifdef RS_USE_I2P_SAM3_I2PSAM
auto ret = mSetting.session->forward(sockaddr_storage_iptostring(ps.localaddr).c_str(), sockaddr_storage_port(ps.localaddr), true);
if (!ret.isOk)
RsDbg() << __PRETTY_FUNCTION__ << " forward failed" << std::endl;
else
Dbg2() << __PRETTY_FUNCTION__ << " forward successfull" << std::endl;
return ret.isOk;
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
RS_STACK_MUTEX(mLockSam3Access);
int ret = sam3StreamForward(mSetting.session, sockaddr_storage_iptostring(ps.localaddr).c_str(), sockaddr_storage_port(ps.localaddr));
@ -649,7 +553,7 @@ bool p3I2pSam3::startForwarding()
RS_DBG("forward failed, due to", mSetting.session->error);
return false;
}
#endif
return true;
}
@ -661,11 +565,7 @@ void p3I2pSam3::stopSession()
RS_STACK_MUTEX(mLock);
if (!mSetting.session)
return;
#ifdef RS_USE_I2P_SAM3_I2PSAM
// TODO cleanup sockets
delete mSetting.session; // will stop forwarding, too
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
// swap connections
mInvalidConnections = mValidConnections;
mValidConnections.clear();
@ -673,7 +573,6 @@ void p3I2pSam3::stopSession()
RS_STACK_MUTEX(mLockSam3Access);
sam3CloseSession(mSetting.session);
delete mSetting.session;
#endif
mSetting.session = nullptr;
mState = samStatus::samState::offline;
@ -697,18 +596,6 @@ bool p3I2pSam3::generateKey(std::string &pub, std::string &priv)
pub.clear();
priv.clear();
#ifdef RS_USE_I2P_SAM3_I2PSAM
auto ss = new SAM::StreamSession("RS-destgen");
auto ret = ss->destGenerate();
if (!ret.isOk)
return false;
auto dest = ret.value;
pub = std::string(dest.pub);
priv = std::string(dest.priv);
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
// The session is only usef for transporting the data
Sam3Session ss;
@ -718,7 +605,6 @@ bool p3I2pSam3::generateKey(std::string &pub, std::string &priv)
}
pub = std::string(ss.pubkey);
priv = std::string(ss.privkey);
#endif
RS_DBG2("publuc key / address", pub);
RS_DBG2("private key", priv);
@ -736,30 +622,11 @@ void p3I2pSam3::lookupKey(taskTicket *ticket)
rsAutoProxyMonitor::taskError(ticket);
return;
}
#ifdef RS_USE_I2P_SAM3_I2PSAM
auto sam = mSetting.session;
RsThread::async([ticket, sam]()
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
RsThread::async([ticket]()
#endif
{
auto addr = static_cast<i2p::address*>(ticket->data);
#ifdef RS_USE_I2P_SAM3_I2PSAM
auto r = sam->namingLookup(addr->base32);
if (!r.isOk) {
// get error
RsDbg() << __PRETTY_FUNCTION__ << " key: " << addr->base32 << std::endl;
RsDbg() << __PRETTY_FUNCTION__ << " got error!" << std::endl;
rsAutoProxyMonitor::taskError(ticket);
} else {
addr->publicKey = r.value;
rsAutoProxyMonitor::taskDone(ticket, autoProxyStatus::ok);
Dbg1() << __PRETTY_FUNCTION__ << " success " << std::endl;
}
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
// The session is only usef for transporting the data
Sam3Session ss;
int ret = sam3NameLookup(&ss, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, addr->base32.c_str());
@ -773,7 +640,6 @@ void p3I2pSam3::lookupKey(taskTicket *ticket)
rsAutoProxyMonitor::taskDone(ticket, autoProxyStatus::ok);
RS_DBG1("success");
}
#endif
});
}
@ -794,20 +660,7 @@ void p3I2pSam3::establishConnection(taskTicket *ticket)
RsThread::async([ticket, this]() {
auto wrapper = static_cast<samEstablishConnectionWrapper*>(ticket->data);
#ifdef RS_USE_I2P_SAM3_I2PSAM
auto r = this->mSetting.session->connect(wrapper->address.publicKey.c_str(), false); // silent=true is broken!
if (!r.isOk) {
// get error
RsDbg() << __PRETTY_FUNCTION__ << " got error!" << std::endl;
rsAutoProxyMonitor::taskError(ticket);
} else {
// extract socket
wrapper->socket = r.value.get()->release();
Dbg1() << __PRETTY_FUNCTION__ << " success " << std::endl;
rsAutoProxyMonitor::taskDone(ticket, autoProxyStatus::ok);
}
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
struct Sam3Connection *connection;
{
auto l = this->mLockSam3Access;
@ -829,7 +682,6 @@ void p3I2pSam3::establishConnection(taskTicket *ticket)
RS_DBG1("success");
rsAutoProxyMonitor::taskDone(ticket, autoProxyStatus::ok);
}
#endif
});
}

View File

@ -30,21 +30,10 @@
class p3PeerMgr;
// typedef samSession is used to unify access to the session independent of the underlying library
#ifdef RS_USE_I2P_SAM3_I2PSAM
namespace SAM {
class StreamSession;
class I2pSocket;
}
typedef SAM::StreamSession samSession;
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
class Sam3Session;
class Sam3Connection;
typedef Sam3Session samSession;
#endif
struct samSettings : i2p::settings {
samSession *session;
@ -52,12 +41,7 @@ struct samSettings : i2p::settings {
struct samEstablishConnectionWrapper {
i2p::address address;
#ifdef RS_USE_I2P_SAM3_I2PSAM
int socket;
#endif
#ifdef RS_USE_I2P_SAM3_LIBSAM3
Sam3Connection *connection;
#endif
};
struct samStatus {
@ -120,9 +104,7 @@ private:
// mutex
RsMutex mLock;
#ifdef RS_USE_I2P_SAM3_LIBSAM3
RsMutex mLockSam3Access; // libsam3 is not thread safe! (except for key lookup)
#endif
};
#endif // P3I2PSAM3_H

View File

@ -206,7 +206,6 @@ retroshare_plugins:win32:CONFIG *= libretroshare_shared
CONFIG+=rs_sam3
CONFIG+=rs_sam3_libsam3
#CONFIG+=rs_sam3_i2psam
# Specify host precompiled jsonapi-generator path, appending the following
# assignation to qmake command line
@ -577,7 +576,6 @@ rs_sam3: {
DEFINES *= RS_I2P_SAM3_BOB_COMPAT
}
rs_sam3_libsam3: DEFINES *= RS_USE_I2P_SAM3_LIBSAM3
rs_sam3_i2psam: DEFINES *= RS_USE_I2P_SAM3_I2PSAM
debug {
rs_mutex_debug:DEFINES *= RS_MUTEX_DEBUG