mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 06:35:08 -04:00
added default encryption policy variable and GUI to change it
This commit is contained in:
parent
8486346368
commit
babc126be3
10 changed files with 183 additions and 35 deletions
|
@ -94,7 +94,7 @@ ftFileControl::ftFileControl(std::string fname,
|
|||
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
|
||||
mSize(size), mFlags(flags), mCreateTime(0), mQueuePriority(0), mQueuePosition(0)
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t ftServiceId)
|
||||
|
@ -113,7 +113,8 @@ ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t f
|
|||
{
|
||||
_max_active_downloads = 5 ; // default queue size
|
||||
_min_prioritized_transfers = 3 ;
|
||||
/* TODO */
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE;
|
||||
/* TODO */
|
||||
cnt = 0 ;
|
||||
}
|
||||
|
||||
|
@ -580,7 +581,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
|||
_queue[pos]->mState = ftFileControl::DOWNLOADING ;
|
||||
|
||||
if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->monitorTunnels(_queue[pos]->mHash,mFtServer,true) ;
|
||||
mFtServer->activateTunnels(_queue[pos]->mHash,_queue[pos]->mFlags,true);
|
||||
}
|
||||
|
||||
if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED && _queue[pos]->mState != ftFileControl::PAUSED)
|
||||
|
@ -589,8 +590,8 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
|||
_queue[pos]->mCreator->closeFile() ;
|
||||
|
||||
if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->stopMonitoringTunnels(_queue[pos]->mHash) ;
|
||||
}
|
||||
mFtServer->activateTunnels(_queue[pos]->mHash,_queue[pos]->mFlags,false);
|
||||
}
|
||||
}
|
||||
|
||||
bool ftController::FlagFileComplete(const RsFileHash& hash)
|
||||
|
@ -835,7 +836,7 @@ bool ftController::completeFile(const RsFileHash& hash)
|
|||
mDownloads.erase(it);
|
||||
|
||||
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->stopMonitoringTunnels(hash_to_suppress) ;
|
||||
mFtServer->activateTunnels(hash_to_suppress,flags,false);
|
||||
|
||||
} /******* UNLOCKED ********/
|
||||
|
||||
|
@ -978,6 +979,17 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash
|
|||
if(alreadyHaveFile(hash, info))
|
||||
return false ;
|
||||
|
||||
if(mDefaultEncryptionPolicy == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT)
|
||||
{
|
||||
flags |= RS_FILE_REQ_ENCRYPTED ;
|
||||
flags &= ~RS_FILE_REQ_UNENCRYPTED ;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags |= RS_FILE_REQ_ENCRYPTED ;
|
||||
flags |= RS_FILE_REQ_UNENCRYPTED ;
|
||||
}
|
||||
|
||||
if(size == 0) // we treat this special case because
|
||||
{
|
||||
/* if no destpath - send to download directory */
|
||||
|
@ -1174,7 +1186,7 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash
|
|||
// We check that flags are consistent.
|
||||
|
||||
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->monitorTunnels(hash,mFtServer,true) ;
|
||||
mFtServer->activateTunnels(hash,flags,true);
|
||||
|
||||
bool assume_availability = false;
|
||||
|
||||
|
@ -1275,7 +1287,7 @@ bool ftController::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::Chunk
|
|||
|
||||
bool ftController::FileCancel(const RsFileHash& hash)
|
||||
{
|
||||
rsTurtle->stopMonitoringTunnels(hash) ;
|
||||
mFtServer->activateTunnels(hash,TransferRequestFlags(0),false);
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::FileCancel" << std::endl;
|
||||
|
@ -1813,6 +1825,7 @@ const std::string download_dir_ss("DOWN_DIR");
|
|||
const std::string partial_dir_ss("PART_DIR");
|
||||
const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY");
|
||||
const std::string free_space_limit_ss("FREE_SPACE_LIMIT");
|
||||
const std::string default_encryption_policy("DEFAULT_ENCRYPTION_POLICY");
|
||||
|
||||
|
||||
/* p3Config Interface */
|
||||
|
@ -2102,7 +2115,26 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
|
|||
setPartialsDirectory(mit->second);
|
||||
}
|
||||
|
||||
if (configMap.end() != (mit = configMap.find(default_chunk_strategy_ss)))
|
||||
if (configMap.end() != (mit = configMap.find(default_encryption_policy)))
|
||||
{
|
||||
if(mit->second == "STRICT")
|
||||
{
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT ;
|
||||
std::cerr << "Note: loading default value for encryption policy: STRICT" << std::endl;
|
||||
}
|
||||
else if(mit->second == "PERMISSIVE")
|
||||
{
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE ;
|
||||
std::cerr << "Note: loading default value for encryption policy: PERMISSIVE" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "(EE) encryption policy not recognized: \"" << mit->second << "\"" << std::endl;
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE ;
|
||||
}
|
||||
}
|
||||
|
||||
if (configMap.end() != (mit = configMap.find(default_chunk_strategy_ss)))
|
||||
{
|
||||
if(mit->second == "STREAMING")
|
||||
{
|
||||
|
|
|
@ -237,6 +237,7 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
|
|||
ftServer *mFtServer ;
|
||||
p3ServiceControl *mServiceCtrl;
|
||||
uint32_t mFtServiceId;
|
||||
uint32_t mDefaultEncryptionPolicy ;
|
||||
|
||||
uint32_t cnt ;
|
||||
RsMutex ctrlMutex;
|
||||
|
|
|
@ -250,6 +250,26 @@ bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uin
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags,bool onoff)
|
||||
{
|
||||
RsFileHash hash_of_hash ;
|
||||
|
||||
encryptHash(hash,hash_of_hash) ;
|
||||
mEncryptedHashes.insert(std::make_pair(hash_of_hash,hash)) ;
|
||||
|
||||
if(onoff)
|
||||
{
|
||||
if(flags & RS_FILE_REQ_ENCRYPTED) mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ;
|
||||
if(flags & RS_FILE_REQ_UNENCRYPTED) mTurtleRouter->monitorTunnels(hash,this,true) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
mTurtleRouter->stopMonitoringTunnels(hash_of_hash);
|
||||
mTurtleRouter->stopMonitoringTunnels(hash);
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::setDestinationName(const RsFileHash& hash,const std::string& name)
|
||||
{
|
||||
return mFtController->setDestinationName(hash,name);
|
||||
|
@ -462,7 +482,12 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i
|
|||
FileInfo info ;
|
||||
bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info);
|
||||
|
||||
#warning need code here => turn H(H) into real hash
|
||||
if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED)
|
||||
{
|
||||
std::cerr << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl;
|
||||
mEncryptedHashes[info.hash] = hash ;
|
||||
}
|
||||
#warning needs to tweak for swarming with encrypted FT
|
||||
if( (!res) && FileDetails(hash,RS_FILE_HINTS_DOWNLOAD,info))
|
||||
{
|
||||
// This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to
|
||||
|
@ -1191,6 +1216,12 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash)
|
||||
{
|
||||
hash_of_hash = RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES);
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::findRealHash(const RsFileHash& hash, RsFileHash& real_hash)
|
||||
{
|
||||
std::map<RsFileHash,RsFileHash>::const_iterator it = mEncryptedHashes.find(hash) ;
|
||||
|
|
|
@ -217,6 +217,8 @@ public:
|
|||
/*************** Data Transfer Interface ***********************/
|
||||
/***************************************************************/
|
||||
public:
|
||||
virtual bool activateTunnels(const RsFileHash& hash,TransferRequestFlags flags,bool onoff);
|
||||
|
||||
virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ;
|
||||
|
@ -255,6 +257,7 @@ protected:
|
|||
|
||||
// fnds out what is the real hash of encrypted hash hash
|
||||
bool findRealHash(const RsFileHash& hash, RsFileHash& real_hash);
|
||||
bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash);
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue