mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-14 00:55:46 -04:00
ID cleaning.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7126 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e2a53924d4
commit
fc163ff866
7 changed files with 66 additions and 41 deletions
|
@ -85,9 +85,10 @@ const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE( 0x00000001 ) ;
|
|||
|
||||
typedef uint64_t ChatLobbyId ;
|
||||
typedef uint64_t ChatLobbyMsgId ;
|
||||
typedef std::string ChatLobbyNickName ;
|
||||
typedef std::string ChatLobbyNickName ;
|
||||
|
||||
typedef RsPeerId DistantChatPeerId ;
|
||||
typedef RsPeerId DistantMsgPeerId ;
|
||||
|
||||
class MessageInfo
|
||||
{
|
||||
|
@ -286,13 +287,15 @@ virtual bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set) =
|
|||
|
||||
virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0;
|
||||
|
||||
/* private distant messages */
|
||||
/****************************************/
|
||||
/* Private distant messages */
|
||||
/****************************************/
|
||||
|
||||
virtual bool createDistantOfflineMessengingInvite(time_t validity_time_stamp, std::string& hash)=0 ;
|
||||
virtual bool createDistantOfflineMessengingInvite(time_t validity_time_stamp, DistantMsgPeerId& hash)=0 ;
|
||||
virtual bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites) = 0 ;
|
||||
virtual void enableDistantMessaging(bool b) = 0;
|
||||
virtual bool distantMessagingEnabled() = 0;
|
||||
virtual bool getDistantMessageHash(const PGPIdType& pgp_id, Sha1CheckSum& hash) = 0;
|
||||
virtual bool getDistantMessagePeerId(const PGPIdType& pgp_id, DistantMsgPeerId& peerId) = 0;
|
||||
|
||||
/****************************************/
|
||||
/* Chat */
|
||||
|
|
|
@ -100,7 +100,7 @@ bool p3Msgs::decryptMessage(const std::string& mId)
|
|||
{
|
||||
return mMsgSrv->decryptMessage(mId);
|
||||
}
|
||||
bool p3Msgs::createDistantOfflineMessengingInvite(time_t ts, std::string& hash)
|
||||
bool p3Msgs::createDistantOfflineMessengingInvite(time_t ts, DistantMsgPeerId &hash)
|
||||
{
|
||||
return mMsgSrv->createDistantOfflineMessengingInvite(ts,hash) ;
|
||||
}
|
||||
|
@ -116,9 +116,9 @@ bool p3Msgs::distantMessagingEnabled()
|
|||
{
|
||||
return mMsgSrv->distantMessagingEnabled();
|
||||
}
|
||||
bool p3Msgs::getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum& hash)
|
||||
bool p3Msgs::getDistantMessagePeerId(const PGPIdType& pgp_id,DistantMsgPeerId &pid)
|
||||
{
|
||||
return mMsgSrv->getDistantMessageHash(pgp_id,hash);
|
||||
return mMsgSrv->getDistantMessagePeerId(pgp_id,pid);
|
||||
}
|
||||
|
||||
bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
|
||||
|
|
|
@ -80,12 +80,12 @@ class p3Msgs: public RsMsgs
|
|||
|
||||
virtual bool resetMessageStandardTagTypes(MsgTagType& tags);
|
||||
|
||||
virtual bool createDistantOfflineMessengingInvite(time_t, std::string&) ;
|
||||
virtual bool createDistantOfflineMessengingInvite(time_t, DistantMsgPeerId&) ;
|
||||
virtual bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>&);
|
||||
|
||||
virtual void enableDistantMessaging(bool b) ;
|
||||
virtual bool distantMessagingEnabled() ;
|
||||
virtual bool getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum& hash) ;
|
||||
virtual bool getDistantMessagePeerId(const PGPIdType& pgp_id,DistantMsgPeerId& pid) ;
|
||||
|
||||
/*!
|
||||
* gets avatar from peer, image data in jpeg format
|
||||
|
|
|
@ -2037,9 +2037,9 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||
std::cerr << " Decrypted message was succesfully deserialized. New message:" << std::endl;
|
||||
item->print(std::cerr,0) ;
|
||||
#endif
|
||||
Sha1CheckSum own_hash ;
|
||||
RsPeerId own_id ;
|
||||
const PGPIdType& own_pgp_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
getDistantMessageHash(own_pgp_id,own_hash) ;
|
||||
getDistantMessagePeerId(own_pgp_id,own_id) ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
@ -2052,11 +2052,13 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||
msgi.msgFlags &= ~RS_MSG_FLAGS_ENCRYPTED ; // just in case.
|
||||
msgi.msgFlags |= RS_MSG_FLAGS_DECRYPTED ; // previousy encrypted msg is now decrypted
|
||||
|
||||
// NEEDS TO BE DONE
|
||||
// msgi.PeerId(senders_id) ;
|
||||
// for(std::list<RsPeerId>::iterator it(msgi.msgto.ids.begin());it!=msgi.msgto.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
// for(std::list<RsPeerId>::iterator it(msgi.msgcc.ids.begin());it!=msgi.msgcc.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
// for(std::list<RsPeerId>::iterator it(msgi.msgbcc.ids.begin());it!=msgi.msgbcc.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
DistantMsgPeerId senders_vpid ;
|
||||
getDistantMessagePeerId(senders_id,senders_vpid) ;
|
||||
msgi.PeerId(senders_vpid) ;
|
||||
|
||||
//for(std::list<RsPeerId>::iterator it(msgi.msgto.ids.begin());it!=msgi.msgto.ids.end();++it) if(*it == own_id) *it = own_pgp_id ;
|
||||
//for(std::list<RsPeerId>::iterator it(msgi.msgcc.ids.begin());it!=msgi.msgcc.ids.end();++it) if(*it == own_id) *it = own_pgp_id ;
|
||||
//for(std::list<RsPeerId>::iterator it(msgi.msgbcc.ids.begin());it!=msgi.msgbcc.ids.end();++it) if(*it == own_id) *it = own_pgp_id ;
|
||||
|
||||
if(signature_present)
|
||||
{
|
||||
|
@ -2076,16 +2078,14 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||
|
||||
RsMsgSrcId* msi = new RsMsgSrcId();
|
||||
msi->msgId = msgi.msgId;
|
||||
// NEEDS TO BE DONE
|
||||
// msi->srcId = senders_id ;
|
||||
msi->srcId = senders_vpid ;
|
||||
|
||||
mSrcIds.insert(std::pair<uint32_t, RsMsgSrcId*>(msi->msgId, msi));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Substituting source name for message id " << msgi.msgId << ": " << it->second->srcId << " -> " << senders_id << std::endl;
|
||||
// NEEDS TO BE DONE
|
||||
//it->second->srcId = senders_id ;
|
||||
it->second->srcId = senders_vpid ;
|
||||
}
|
||||
}
|
||||
delete item ;
|
||||
|
@ -2109,18 +2109,22 @@ void p3MsgService::connectToTurtleRouter(p3turtle *pt)
|
|||
pt->registerTunnelService(this) ;
|
||||
}
|
||||
|
||||
bool p3MsgService::createDistantOfflineMessengingInvite(time_t time_of_validity,TurtleFileHash& hash)
|
||||
bool p3MsgService::createDistantOfflineMessengingInvite(time_t time_of_validity,DistantMsgPeerId& peer_id)
|
||||
{
|
||||
hash = Sha1CheckSum::random().toStdString() ;
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": disabled for now" << std::endl;
|
||||
|
||||
DistantMessengingInvite invite ;
|
||||
invite.time_of_validity = time_of_validity + time(NULL);
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
_messenging_invites[Sha1CheckSum(hash)] = invite ;
|
||||
}
|
||||
IndicateConfigChanged() ;
|
||||
// peer_id = DistantMsgPeerId::random();
|
||||
// TurtleFileHash hash = rsdir::sha1sum(peer_id.toByteArray(),DistantMsgPeerId::SIZE_IN_BYTES) ;
|
||||
//
|
||||
// DistantMessengingInvite invite ;
|
||||
// invite.time_of_validity = time_of_validity + time(NULL);
|
||||
//
|
||||
//
|
||||
// {
|
||||
// RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
// _messenging_invites[hash] = invite ;
|
||||
// }
|
||||
// IndicateConfigChanged() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
@ -2129,9 +2133,9 @@ void p3MsgService::enableDistantMessaging(bool b)
|
|||
{
|
||||
// compute the hash
|
||||
|
||||
Sha1CheckSum hash ;
|
||||
Sha1CheckSum hash ;
|
||||
|
||||
if(!getDistantMessageHash(AuthGPG::getAuthGPG()->getGPGOwnId(),hash))
|
||||
if(!getDistantMessageHash(AuthGPG::getAuthGPG()->getGPGOwnId(),hash))
|
||||
return ;
|
||||
|
||||
bool cchanged = false ;
|
||||
|
@ -2208,15 +2212,32 @@ bool p3MsgService::distantMessagingEnabled()
|
|||
}
|
||||
return res ;
|
||||
}
|
||||
bool p3MsgService::getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum& hash)
|
||||
bool p3MsgService::getDistantMessagePeerId(const PGPIdType& pgp_id,DistantMsgPeerId& peer_id)
|
||||
{
|
||||
hash = RsDirUtil::sha1sum((uint8_t*)pgp_id.toByteArray(),PGPIdType::SIZE_IN_BYTES);
|
||||
if(!AuthGPG::getAuthGPG()->isKeySupported(pgp_id))
|
||||
return false ;
|
||||
|
||||
unsigned char tmp[RsPeerId::SIZE_IN_BYTES] ;
|
||||
memset(tmp,0,RsPeerId::SIZE_IN_BYTES) ;
|
||||
memcpy(tmp,pgp_id.toByteArray(),RsPgpId::SIZE_IN_BYTES) ;
|
||||
|
||||
peer_id = RsPeerId(tmp) ;
|
||||
|
||||
// Also check that we have the public key.
|
||||
|
||||
return AuthGPG::getAuthGPG()->isKeySupported(pgp_id) ;
|
||||
return true ;
|
||||
}
|
||||
bool p3MsgService::getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum& hash)
|
||||
{
|
||||
if(!AuthGPG::getAuthGPG()->isKeySupported(pgp_id))
|
||||
return false ;
|
||||
|
||||
hash = RsDirUtil::sha1sum(pgp_id.toByteArray(),RsPgpId::SIZE_IN_BYTES) ;
|
||||
|
||||
// Also check that we have the public key.
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool p3MsgService::getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites)
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
@ -2388,7 +2409,7 @@ void p3MsgService::sendTurtleData(const Sha1CheckSum& hash,RsMsgItem *msgitem)
|
|||
// If not, put on the contact's waiting list.
|
||||
|
||||
RsPeerId virtual_peer_id ;
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<Sha1CheckSum,DistantMessengingContact>::const_iterator it = _messenging_contacts.find(hash) ;
|
||||
|
||||
|
|
|
@ -127,15 +127,16 @@ int checkOutgoingMessages();
|
|||
uint32_t status ;
|
||||
bool pending_messages ;
|
||||
};
|
||||
bool createDistantOfflineMessengingInvite(time_t time_of_validity,TurtleFileHash& hash) ;
|
||||
bool createDistantOfflineMessengingInvite(time_t time_of_validity,DistantMsgPeerId &peer_id) ;
|
||||
bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites) ;
|
||||
|
||||
void enableDistantMessaging(bool b) ;
|
||||
bool distantMessagingEnabled() ;
|
||||
bool getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum &hash) ;
|
||||
bool getDistantMessagePeerId(const PGPIdType& pgp_id,DistantMsgPeerId &peer_id) ;
|
||||
|
||||
private:
|
||||
void sendPrivateMsgItem(const Sha1CheckSum& hash,RsMsgItem *) ;
|
||||
bool getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum &hash) ;
|
||||
void sendPrivateMsgItem(const Sha1CheckSum& hash,RsMsgItem *) ;
|
||||
|
||||
// This maps contains the current invitations to respond to.
|
||||
// The map is indexed by the hash
|
||||
|
|
|
@ -698,7 +698,7 @@ bool RsDirUtil::getFileHash(const std::string& filepath, std::string &hash, uint
|
|||
}
|
||||
|
||||
/* Function to hash, and get details of a file */
|
||||
Sha1CheckSum RsDirUtil::sha1sum(unsigned char *data, uint32_t size)
|
||||
Sha1CheckSum RsDirUtil::sha1sum(const unsigned char *data, uint32_t size)
|
||||
{
|
||||
SHA_CTX sha_ctx ;
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ bool cleanupDirectoryFaster(const std::string& dir, const std::set<std::stri
|
|||
bool hashFile(const std::string& filepath, std::string &name, std::string &hash, uint64_t &size);
|
||||
bool getFileHash(const std::string& filepath,std::string &hash, uint64_t &size, RsThread *thread = NULL);
|
||||
|
||||
Sha1CheckSum sha1sum(uint8_t *data,uint32_t size) ;
|
||||
Sha1CheckSum sha1sum(const uint8_t *data,uint32_t size) ;
|
||||
|
||||
// Creates a lock file with given path, and returns the lock handle
|
||||
// returns:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue