mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Merge branch 'master' into gxs_mail_experiments
This commit is contained in:
commit
c0c5cc52db
94 changed files with 3054 additions and 783 deletions
|
@ -428,14 +428,14 @@ bool DistributedChatService::handleRecvItem(RsChatItem *item)
|
|||
{
|
||||
switch(item->PacketSubType())
|
||||
{
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: handleRecvChatLobbyEventItem (dynamic_cast<RsChatLobbyEventItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: handleRecvLobbyInvite (dynamic_cast<RsChatLobbyInviteItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: handleConnectionChallenge (dynamic_cast<RsChatLobbyConnectChallengeItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: handleFriendUnsubscribeLobby (dynamic_cast<RsChatLobbyUnsubscribeItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: handleRecvChatLobbyListRequest (dynamic_cast<RsChatLobbyListRequestItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: handleRecvChatLobbyList (dynamic_cast<RsChatLobbyListItem *>(item)) ; break ;
|
||||
default:
|
||||
return false ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: handleRecvChatLobbyEventItem (dynamic_cast<RsChatLobbyEventItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED: handleRecvLobbyInvite_Deprecated (dynamic_cast<RsChatLobbyInviteItem_Deprecated*>(item)) ; break ; // to be removed (deprecated since May 2017)
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: handleRecvLobbyInvite (dynamic_cast<RsChatLobbyInviteItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: handleConnectionChallenge (dynamic_cast<RsChatLobbyConnectChallengeItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: handleFriendUnsubscribeLobby (dynamic_cast<RsChatLobbyUnsubscribeItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: handleRecvChatLobbyListRequest (dynamic_cast<RsChatLobbyListRequestItem *>(item)) ; break ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: handleRecvChatLobbyList (dynamic_cast<RsChatLobbyListItem *>(item)) ; break ;
|
||||
default: return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
@ -1233,14 +1233,45 @@ void DistributedChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, cons
|
|||
|
||||
RsChatLobbyInviteItem *item = new RsChatLobbyInviteItem ;
|
||||
|
||||
item->lobby_id = lobby_id ;
|
||||
item->lobby_name = it->second.lobby_name ;
|
||||
item->lobby_topic = it->second.lobby_topic ;
|
||||
item->lobby_flags = connexion_challenge?RS_CHAT_LOBBY_FLAGS_CHALLENGE:(it->second.lobby_flags) ;
|
||||
item->lobby_id = lobby_id ;
|
||||
item->lobby_name = it->second.lobby_name ;
|
||||
item->lobby_topic = it->second.lobby_topic ;
|
||||
item->lobby_flags = connexion_challenge?RS_CHAT_LOBBY_FLAGS_CHALLENGE:(it->second.lobby_flags) ;
|
||||
item->PeerId(peer_id) ;
|
||||
|
||||
sendChatItem(item) ;
|
||||
|
||||
//FOR BACKWARD COMPATIBILITY
|
||||
{// to be removed (deprecated since May 2017)
|
||||
RsChatLobbyInviteItem_Deprecated *item = new RsChatLobbyInviteItem_Deprecated ;
|
||||
|
||||
item->lobby_id = lobby_id ;
|
||||
item->lobby_name = it->second.lobby_name ;
|
||||
item->lobby_topic = it->second.lobby_topic ;
|
||||
item->lobby_flags = connexion_challenge?RS_CHAT_LOBBY_FLAGS_CHALLENGE:(it->second.lobby_flags) ;
|
||||
item->PeerId(peer_id) ;
|
||||
|
||||
sendChatItem(item) ;
|
||||
}
|
||||
}
|
||||
|
||||
// to be removed (deprecated since May 2017)
|
||||
void DistributedChatService::handleRecvLobbyInvite_Deprecated(RsChatLobbyInviteItem_Deprecated *item)
|
||||
{
|
||||
#ifdef DEBUG_CHAT_LOBBIES
|
||||
std::cerr << "Received deprecated invite to lobby from " << item->PeerId() << " to lobby " << std::hex << item->lobby_id << std::dec << ", named " << item->lobby_name << item->lobby_topic << std::endl;
|
||||
#endif
|
||||
RsChatLobbyInviteItem* newItem = new RsChatLobbyInviteItem();
|
||||
|
||||
newItem->lobby_id = item->lobby_id ;
|
||||
newItem->lobby_name = item->lobby_name ;
|
||||
newItem->lobby_topic = item->lobby_topic ;
|
||||
newItem->lobby_flags = item->lobby_flags ;
|
||||
newItem->PeerId( item->PeerId() );
|
||||
|
||||
handleRecvLobbyInvite(newItem);
|
||||
}
|
||||
|
||||
void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
|
||||
{
|
||||
#ifdef DEBUG_CHAT_LOBBIES
|
||||
|
@ -1259,10 +1290,10 @@ void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
|
|||
{
|
||||
#ifdef DEBUG_CHAT_LOBBIES
|
||||
std::cerr << " Lobby already exists. " << std::endl;
|
||||
std::cerr << " privacy levels: " << item->lobby_flags << " vs. " << it->second.lobby_flags ;
|
||||
std::cerr << " privacy levels: " << item->lobby_flags << " vs. " << it->second.lobby_flags ;
|
||||
#endif
|
||||
|
||||
if((!IS_CONNEXION_CHALLENGE(item->lobby_flags)) && EXTRACT_PRIVACY_FLAGS(item->lobby_flags) != EXTRACT_PRIVACY_FLAGS(it->second.lobby_flags))
|
||||
if ((!IS_CONNEXION_CHALLENGE(item->lobby_flags)) && EXTRACT_PRIVACY_FLAGS(item->lobby_flags) != EXTRACT_PRIVACY_FLAGS(it->second.lobby_flags))
|
||||
{
|
||||
std::cerr << " : Don't match. Cancelling." << std::endl;
|
||||
return ;
|
||||
|
@ -1274,10 +1305,22 @@ void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
|
|||
std::cerr << " Adding new friend " << item->PeerId() << " to lobby." << std::endl;
|
||||
#endif
|
||||
|
||||
// to be removed (deprecated since May 2017)
|
||||
{ //Update Topics if have received deprecated before (withou topic)
|
||||
if(it->second.lobby_topic.empty() && !item->lobby_topic.empty())
|
||||
it->second.lobby_topic = item->lobby_topic;
|
||||
}
|
||||
|
||||
it->second.participating_friends.insert(item->PeerId()) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
// to be removed (deprecated since May 2017)
|
||||
{//check if invitation is already received by deprecated version
|
||||
std::map<ChatLobbyId,ChatLobbyInvite>::const_iterator it(_lobby_invites_queue.find( item->lobby_id)) ;
|
||||
if(it != _lobby_invites_queue.end())
|
||||
return ;
|
||||
}
|
||||
// Don't record the invitation if it's a challenge response item or a lobby we don't have.
|
||||
//
|
||||
if(IS_CONNEXION_CHALLENGE(item->lobby_flags))
|
||||
|
@ -1290,7 +1333,7 @@ void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
|
|||
invite.peer_id = item->PeerId() ;
|
||||
invite.lobby_name = item->lobby_name ;
|
||||
invite.lobby_topic = item->lobby_topic ;
|
||||
invite.lobby_flags = item->lobby_flags ;
|
||||
invite.lobby_flags = item->lobby_flags ;
|
||||
|
||||
_lobby_invites_queue[item->lobby_id] = invite ;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ class RsChatLobbyListRequestItem ;
|
|||
class RsChatLobbyListItem ;
|
||||
class RsChatLobbyEventItem ;
|
||||
class RsChatLobbyBouncingObject ;
|
||||
class RsChatLobbyInviteItem_Deprecated ; // to be removed (deprecated since May 2017)
|
||||
class RsChatLobbyInviteItem ;
|
||||
class RsChatLobbyMsgItem ;
|
||||
class RsChatLobbyConnectChallengeItem ;
|
||||
|
@ -111,6 +112,7 @@ class DistributedChatService
|
|||
|
||||
/// receive and handle chat lobby item
|
||||
bool recvLobbyChat(RsChatLobbyMsgItem*,const RsPeerId& src_peer_id) ;
|
||||
void handleRecvLobbyInvite_Deprecated(RsChatLobbyInviteItem_Deprecated*) ; // to be removed (deprecated since May 2017)
|
||||
void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ;
|
||||
void checkAndRedirectMsgToLobby(RsChatMsgItem*) ;
|
||||
void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ;
|
||||
|
|
|
@ -39,23 +39,24 @@ static const uint32_t RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE = 0x0001;
|
|||
|
||||
RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_TYPE_CHAT)
|
||||
return NULL ;
|
||||
if (service_id != RS_SERVICE_TYPE_CHAT)
|
||||
return NULL;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ;
|
||||
case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT:return new RsChatLobbyEventItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST:return new RsChatLobbyListRequestItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem() ;
|
||||
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ;
|
||||
case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED: return new RsChatLobbyInviteItem_Deprecated() ; // to be removed (deprecated since May 2017)
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: return new RsChatLobbyEventItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: return new RsChatLobbyListRequestItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem() ;
|
||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem() ;
|
||||
default:
|
||||
std::cerr << "Unknown packet type in chat!" << std::endl ;
|
||||
return NULL ;
|
||||
|
@ -97,12 +98,12 @@ void RsChatLobbyMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
|
|||
RsChatLobbyBouncingObject::serial_process(j,ctx) ;
|
||||
}
|
||||
|
||||
void RsChatLobbyListRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
void RsChatLobbyListRequestItem::serial_process(RsGenericSerializer::SerializeJob /*j*/,RsGenericSerializer::SerializeContext& /*ctx*/)
|
||||
{
|
||||
// nothing to do. This is an empty item.
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name)
|
||||
template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& /*name*/)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,info.id,"info.id") ;
|
||||
|
||||
|
@ -135,10 +136,19 @@ void RsChatLobbyConnectChallengeItem::serial_process(RsGenericSerializer::Serial
|
|||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,challenge_code,"challenge_code") ;
|
||||
}
|
||||
|
||||
// to be removed (deprecated since May 2017)
|
||||
void RsChatLobbyInviteItem_Deprecated::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx, lobby_id, "lobby_id") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ;
|
||||
RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ;
|
||||
}
|
||||
|
||||
void RsChatLobbyInviteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx, lobby_id, "lobby_id") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_topic,"lobby_topic") ;
|
||||
RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,8 +77,10 @@ const uint8_t RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY = 0x16 ;
|
|||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG = 0x17 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT = 0x18 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_LIST = 0x19 ;
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x1A ;
|
||||
const uint8_t RS_PKT_SUBTYPE_OUTGOING_MAP = 0x1B ;
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED = 0x1A ; // to be removed (deprecated since May 2017)
|
||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x1B ;
|
||||
const uint8_t RS_PKT_SUBTYPE_OUTGOING_MAP = 0x1C ;
|
||||
|
||||
typedef uint64_t ChatLobbyId ;
|
||||
typedef uint64_t ChatLobbyMsgId ;
|
||||
|
@ -94,7 +96,7 @@ class RsChatItem: public RsItem
|
|||
}
|
||||
|
||||
virtual ~RsChatItem() {}
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) { return out; } // derived from RsItem, but should be removed
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t /*indent*/ = 0) { return out; } // derived from RsItem, but should be removed
|
||||
|
||||
virtual void clear() {}
|
||||
};
|
||||
|
@ -239,6 +241,21 @@ class RsChatLobbyConnectChallengeItem: public RsChatItem
|
|||
uint64_t challenge_code ;
|
||||
};
|
||||
|
||||
// to be removed (deprecated since May 2017)
|
||||
class RsChatLobbyInviteItem_Deprecated: public RsChatItem
|
||||
{
|
||||
public:
|
||||
RsChatLobbyInviteItem_Deprecated() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED) {}
|
||||
virtual ~RsChatLobbyInviteItem_Deprecated() {}
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
ChatLobbyId lobby_id ;
|
||||
std::string lobby_name ;
|
||||
std::string lobby_topic ;
|
||||
ChatLobbyFlags lobby_flags ;
|
||||
};
|
||||
|
||||
class RsChatLobbyInviteItem: public RsChatItem
|
||||
{
|
||||
public:
|
||||
|
@ -250,7 +267,7 @@ class RsChatLobbyInviteItem: public RsChatItem
|
|||
ChatLobbyId lobby_id ;
|
||||
std::string lobby_name ;
|
||||
std::string lobby_topic ;
|
||||
ChatLobbyFlags lobby_flags ;
|
||||
ChatLobbyFlags lobby_flags ;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
|
|
@ -44,6 +44,12 @@
|
|||
|
||||
//#define DEBUG_CHACHA20
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x010100000L
|
||||
#define AEAD_chacha20_poly1305_openssl AEAD_chacha20_poly1305
|
||||
#else
|
||||
#define AEAD_chacha20_poly1305_rs AEAD_chacha20_poly1305
|
||||
#endif
|
||||
|
||||
namespace librs {
|
||||
namespace crypto {
|
||||
|
||||
|
@ -273,6 +279,7 @@ static void quotient(const uint256_32& n,const uint256_32& p,uint256_32& q,uint2
|
|||
q += m ;
|
||||
}
|
||||
}
|
||||
|
||||
static void remainder(const uint256_32& n,const uint256_32& p,uint256_32& r)
|
||||
{
|
||||
// simple algorithm: add up multiples of u while keeping below *this. Once done, substract.
|
||||
|
@ -356,7 +363,7 @@ static void print(const chacha20_state& s)
|
|||
}
|
||||
#endif
|
||||
|
||||
void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size)
|
||||
void chacha20_encrypt_rs(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size)
|
||||
{
|
||||
for(uint32_t i=0;i<size/64 + 1;++i)
|
||||
{
|
||||
|
@ -379,6 +386,50 @@ void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12]
|
|||
}
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x010100000L
|
||||
void chacha20_encrypt_openssl(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size)
|
||||
{
|
||||
EVP_CIPHER_CTX *ctx;
|
||||
|
||||
int len;
|
||||
int tmp_len;
|
||||
uint8_t tmp[size];
|
||||
uint8_t iv[16];
|
||||
|
||||
// create iv with nonce and block counter
|
||||
memcpy(iv, &block_counter, 4);
|
||||
memcpy(iv + 4, nonce, 12);
|
||||
|
||||
/* Create and initialise the context */
|
||||
if(!(ctx = EVP_CIPHER_CTX_new())) return;
|
||||
|
||||
/* Initialise the encryption operation. IMPORTANT - ensure you use a key
|
||||
* and IV size appropriate for your cipher
|
||||
* In this example we are using 256 bit AES (i.e. a 256 bit key). The
|
||||
* IV size for *most* modes is the same as the block size. For AES this
|
||||
* is 128 bits */
|
||||
if(1 != EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, key, iv)) goto out;
|
||||
|
||||
/* Provide the message to be encrypted, and obtain the encrypted output.
|
||||
* EVP_EncryptUpdate can be called multiple times if necessary
|
||||
*/
|
||||
if(1 != EVP_EncryptUpdate(ctx, tmp, &len, data, size)) goto out;
|
||||
tmp_len = len;
|
||||
|
||||
/* Finalise the encryption. Further ciphertext bytes may be written at
|
||||
* this stage.
|
||||
*/
|
||||
if(1 != EVP_EncryptFinal_ex(ctx, tmp + len, &len)) goto out;
|
||||
tmp_len += len;
|
||||
|
||||
memcpy(data, tmp, tmp_len);
|
||||
|
||||
out:
|
||||
/* Clean up */
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct poly1305_state
|
||||
{
|
||||
uint256_32 r ;
|
||||
|
@ -475,7 +526,7 @@ bool constant_time_memory_compare(const uint8_t *m1,const uint8_t *m2,uint32_t s
|
|||
return !CRYPTO_memcmp(m1,m2,size) ;
|
||||
}
|
||||
|
||||
bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt)
|
||||
bool AEAD_chacha20_poly1305_rs(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt)
|
||||
{
|
||||
// encrypt + tag. See RFC7539-2.8
|
||||
|
||||
|
@ -492,7 +543,7 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin
|
|||
|
||||
if(encrypt)
|
||||
{
|
||||
chacha20_encrypt(key,1,nonce,data,data_size);
|
||||
chacha20_encrypt_rs(key,1,nonce,data,data_size);
|
||||
|
||||
poly1305_state pls ;
|
||||
|
||||
|
@ -520,19 +571,107 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin
|
|||
|
||||
// decrypt
|
||||
|
||||
chacha20_encrypt(key,1,nonce,data,data_size);
|
||||
chacha20_encrypt_rs(key,1,nonce,data,data_size);
|
||||
|
||||
return constant_time_memory_compare(tag,computed_tag,16) ;
|
||||
}
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x010100000L
|
||||
#define errorOut {ret = false; goto out;}
|
||||
|
||||
bool AEAD_chacha20_poly1305_openssl(uint8_t key[32], uint8_t nonce[12], uint8_t *data, uint32_t data_size, uint8_t *aad, uint32_t aad_size, uint8_t tag[16], bool encrypt_or_decrypt)
|
||||
{
|
||||
EVP_CIPHER_CTX *ctx;
|
||||
|
||||
bool ret = true;
|
||||
int len;
|
||||
const uint8_t tag_len = 16;
|
||||
int tmp_len;
|
||||
uint8_t tmp[data_size];
|
||||
|
||||
/* Create and initialise the context */
|
||||
if(!(ctx = EVP_CIPHER_CTX_new())) return false;
|
||||
|
||||
if (encrypt_or_decrypt) {
|
||||
/* Initialise the encryption operation. */
|
||||
if(1 != EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL, NULL)) errorOut
|
||||
|
||||
/* Initialise key and IV */
|
||||
if(1 != EVP_EncryptInit_ex(ctx, NULL, NULL, key, nonce)) errorOut
|
||||
|
||||
/* Provide any AAD data. This can be called zero or more times as
|
||||
* required
|
||||
*/
|
||||
if(1 != EVP_EncryptUpdate(ctx, NULL, &len, aad, aad_size)) errorOut
|
||||
|
||||
/* Provide the message to be encrypted, and obtain the encrypted output.
|
||||
* EVP_EncryptUpdate can be called multiple times if necessary
|
||||
*/
|
||||
if(1 != EVP_EncryptUpdate(ctx, tmp, &len, data, data_size)) errorOut
|
||||
tmp_len = len;
|
||||
|
||||
/* Finalise the encryption. Normally ciphertext bytes may be written at
|
||||
* this stage, but this does not occur in GCM mode
|
||||
*/
|
||||
if(1 != EVP_EncryptFinal_ex(ctx, data + len, &len)) errorOut
|
||||
tmp_len += len;
|
||||
|
||||
/* Get the tag */
|
||||
if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, tag_len, tag)) errorOut
|
||||
} else {
|
||||
/* Initialise the decryption operation. */
|
||||
if(!EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, key, nonce)) errorOut
|
||||
|
||||
/* Provide any AAD data. This can be called zero or more times as
|
||||
* required
|
||||
*/
|
||||
if(!EVP_DecryptUpdate(ctx, NULL, &len, aad, aad_size)) errorOut
|
||||
|
||||
/* Provide the message to be decrypted, and obtain the plaintext output.
|
||||
* EVP_DecryptUpdate can be called multiple times if necessary
|
||||
*/
|
||||
if(!EVP_DecryptUpdate(ctx, tmp, &len, data, data_size)) errorOut
|
||||
tmp_len = len;
|
||||
|
||||
/* Set expected tag value. Works in OpenSSL 1.0.1d and later */
|
||||
if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, tag_len, tag)) errorOut
|
||||
|
||||
/* Finalise the decryption. A positive return value indicates success,
|
||||
* anything else is a failure - the plaintext is not trustworthy.
|
||||
*/
|
||||
if(EVP_DecryptFinal_ex(ctx, tmp + len, &len) > 0) {
|
||||
/* Success */
|
||||
tmp_len += len;
|
||||
ret = true;
|
||||
} else {
|
||||
/* Verify failed */
|
||||
errorOut
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(data, tmp, tmp_len);
|
||||
|
||||
out:
|
||||
/* Clean up */
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return !!ret;
|
||||
}
|
||||
|
||||
#undef errorOut
|
||||
#endif
|
||||
|
||||
bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt)
|
||||
{
|
||||
// encrypt + tag. See RFC7539-2.8
|
||||
|
||||
if(encrypt)
|
||||
{
|
||||
chacha20_encrypt(key,1,nonce,data,data_size);
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
chacha20_encrypt_rs(key,1,nonce,data,data_size);
|
||||
#else
|
||||
chacha20_encrypt_openssl(key, 1, nonce, data, data_size);
|
||||
#endif
|
||||
|
||||
uint8_t computed_tag[EVP_MAX_MD_SIZE];
|
||||
unsigned int md_size ;
|
||||
|
@ -594,7 +733,11 @@ bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint3
|
|||
|
||||
// decrypt
|
||||
|
||||
chacha20_encrypt(key,1,nonce,data,data_size);
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
chacha20_encrypt_rs(key,1,nonce,data,data_size);
|
||||
#else
|
||||
chacha20_encrypt_openssl(key, 1, nonce, data, data_size);
|
||||
#endif
|
||||
|
||||
return constant_time_memory_compare(tag,computed_tag,16) ;
|
||||
}
|
||||
|
@ -674,7 +817,7 @@ bool perform_tests()
|
|||
0x74, 0x2e
|
||||
};
|
||||
|
||||
chacha20_encrypt(key,1,nounce2,plaintext,7*16+2) ;
|
||||
chacha20_encrypt_rs(key,1,nounce2,plaintext,7*16+2) ;
|
||||
|
||||
#ifdef DEBUG_CHACHA20
|
||||
fprintf(stdout,"CipherText: \n") ;
|
||||
|
@ -1154,12 +1297,12 @@ bool perform_tests()
|
|||
uint8_t tag[16] ;
|
||||
uint8_t test_tag[16] = { 0x1a,0xe1,0x0b,0x59,0x4f,0x09,0xe2,0x6a,0x7e,0x90,0x2e,0xcb,0xd0,0x60,0x06,0x91 };
|
||||
|
||||
AEAD_chacha20_poly1305(key,nonce,msg,7*16+2,aad,12,tag,true) ;
|
||||
AEAD_chacha20_poly1305_rs(key,nonce,msg,7*16+2,aad,12,tag,true) ;
|
||||
|
||||
if(!constant_time_memory_compare(msg,test_msg,7*16+2)) return false ;
|
||||
if(!constant_time_memory_compare(tag,test_tag,16)) return false ;
|
||||
|
||||
bool res = AEAD_chacha20_poly1305(key,nonce,msg,7*16+2,aad,12,tag,false) ;
|
||||
bool res = AEAD_chacha20_poly1305_rs(key,nonce,msg,7*16+2,aad,12,tag,false) ;
|
||||
|
||||
if(!res) return false ;
|
||||
}
|
||||
|
@ -1197,7 +1340,7 @@ bool perform_tests()
|
|||
|
||||
uint8_t received_tag[16] = { 0xee,0xad,0x9d,0x67,0x89,0x0c,0xbb,0x22,0x39,0x23,0x36,0xfe,0xa1,0x85,0x1f,0x38 };
|
||||
|
||||
if(!AEAD_chacha20_poly1305(key,nonce,ciphertext,16*16+9,aad,12,received_tag,false))
|
||||
if(!AEAD_chacha20_poly1305_rs(key,nonce,ciphertext,16*16+9,aad,12,received_tag,false))
|
||||
return false ;
|
||||
|
||||
uint8_t cleartext[16*16+9] = {
|
||||
|
@ -1243,21 +1386,29 @@ bool perform_tests()
|
|||
|
||||
{
|
||||
RsScopeTimer s("AEAD1") ;
|
||||
chacha20_encrypt(key, 1, nonce, ten_megabyte_data,SIZE) ;
|
||||
chacha20_encrypt_rs(key, 1, nonce, ten_megabyte_data,SIZE) ;
|
||||
|
||||
std::cerr << " Chacha20 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
std::cerr << " Chacha20 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
}
|
||||
{
|
||||
RsScopeTimer s("AEAD2") ;
|
||||
AEAD_chacha20_poly1305(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
|
||||
AEAD_chacha20_poly1305_rs(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
|
||||
|
||||
std::cerr << " AEAD/poly1305 encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
std::cerr << " AEAD/poly1305 own encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
}
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x010100000L
|
||||
{
|
||||
RsScopeTimer s("AEAD3") ;
|
||||
AEAD_chacha20_poly1305_openssl(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
|
||||
|
||||
std::cerr << " AEAD/poly1305 openssl encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
RsScopeTimer s("AEAD4") ;
|
||||
AEAD_chacha20_sha256(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
|
||||
|
||||
std::cerr << " AEAD/sha256 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
std::cerr << " AEAD/sha256 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
}
|
||||
|
||||
free(ten_megabyte_data) ;
|
||||
|
|
|
@ -75,6 +75,7 @@ static const int32_t INACTIVE_CHUNKS_CHECK_DELAY = 240 ; // time after which an
|
|||
static const int32_t MAX_TIME_INACTIVE_REQUEUED = 120 ; // time after which an inactive ftFileControl is bt-queued
|
||||
|
||||
static const int32_t FT_FILECONTROL_QUEUE_ADD_END = 0 ;
|
||||
static const int32_t FT_FILECONTROL_MAX_UPLOAD_SLOTS_DEFAULT= 0 ;
|
||||
|
||||
const uint32_t FT_CNTRL_STANDARD_RATE = 10 * 1024 * 1024;
|
||||
const uint32_t FT_CNTRL_SLOW_RATE = 100 * 1024;
|
||||
|
@ -113,6 +114,7 @@ ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t f
|
|||
{
|
||||
_max_active_downloads = 5 ; // default queue size
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE;
|
||||
_max_uploads_per_friend = FT_FILECONTROL_MAX_UPLOAD_SLOTS_DEFAULT ;
|
||||
/* TODO */
|
||||
cnt = 0 ;
|
||||
}
|
||||
|
@ -239,8 +241,8 @@ void ftController::data_tick()
|
|||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
it->second->mCreator->removeInactiveChunks() ;
|
||||
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
it->second->mCreator->removeInactiveChunks() ;
|
||||
|
||||
last_clean_time = now ;
|
||||
}
|
||||
|
@ -1723,6 +1725,7 @@ void ftController::statusChange(const std::list<pqiServicePeer> &plist)
|
|||
const std::string active_downloads_size_ss("MAX_ACTIVE_DOWNLOADS");
|
||||
const std::string download_dir_ss("DOWN_DIR");
|
||||
const std::string partial_dir_ss("PART_DIR");
|
||||
const std::string max_uploads_per_friend_ss("MAX_UPLOADS_PER_FRIEND");
|
||||
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_ss("DEFAULT_ENCRYPTION_POLICY");
|
||||
|
@ -1771,6 +1774,9 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||
break ;
|
||||
}
|
||||
|
||||
rs_sprintf(s,"%lu",_max_uploads_per_friend) ;
|
||||
configMap[max_uploads_per_friend_ss] = s ;
|
||||
|
||||
configMap[default_encryption_policy_ss] = (mDefaultEncryptionPolicy==RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE)?"PERMISSIVE":"STRICT" ;
|
||||
|
||||
rs_sprintf(s, "%lu", RsDiscSpace::freeSpaceLimit());
|
||||
|
@ -2057,9 +2063,29 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
|
|||
RsDiscSpace::setFreeSpaceLimit(size) ;
|
||||
}
|
||||
}
|
||||
if(configMap.end() != (mit = configMap.find(max_uploads_per_friend_ss)))
|
||||
{
|
||||
uint32_t n ;
|
||||
if (sscanf(mit->second.c_str(), "%u", &n) == 1) {
|
||||
std::cerr << "have read a max upload slots limit of " << n << std::endl ;
|
||||
|
||||
_max_uploads_per_friend = n ;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ftController::setMaxUploadsPerFriend(uint32_t m)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
_max_uploads_per_friend = m ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
uint32_t ftController::getMaxUploadsPerFriend()
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
return _max_uploads_per_friend ;
|
||||
}
|
||||
void ftController::setDefaultEncryptionPolicy(uint32_t p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
|
|
@ -146,6 +146,9 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
|
|||
void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
uint32_t defaultEncryptionPolicy();
|
||||
|
||||
void setMaxUploadsPerFriend(uint32_t m) ;
|
||||
uint32_t getMaxUploadsPerFriend() ;
|
||||
|
||||
bool FileCancel(const RsFileHash& hash);
|
||||
bool FileControl(const RsFileHash& hash, uint32_t flags);
|
||||
bool FileClearCompleted();
|
||||
|
@ -261,7 +264,8 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
|
|||
|
||||
FileChunksInfo::ChunkStrategy mDefaultChunkStrategy ;
|
||||
|
||||
uint32_t _max_active_downloads ; // maximum number of simultaneous downloads
|
||||
uint32_t _max_active_downloads ; // maximum number of simultaneous downloads
|
||||
uint32_t _max_uploads_per_friend ; // maximum number of uploads per friend. 0 means unlimited.
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -53,11 +53,6 @@ void ftExtraList::data_tick()
|
|||
bool todo = false;
|
||||
time_t now = time(NULL);
|
||||
|
||||
#ifdef DEBUG_ELIST
|
||||
//std::cerr << "ftExtraList::run() Iteration";
|
||||
//std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
{
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
|
@ -131,6 +126,7 @@ void ftExtraList::hashAFile()
|
|||
|
||||
/* stick it in the available queue */
|
||||
mFiles[details.info.hash] = details;
|
||||
mHashOfHash[makeEncryptedHash(details.info.hash)] = details.info.hash ;
|
||||
|
||||
/* add to the path->hash map */
|
||||
mHashedList[details.info.path] = details.info.hash;
|
||||
|
@ -169,6 +165,7 @@ bool ftExtraList::addExtraFile(std::string path, const RsFileHash& hash,
|
|||
|
||||
/* stick it in the available queue */
|
||||
mFiles[details.info.hash] = details;
|
||||
mHashOfHash[makeEncryptedHash(details.info.hash)] = details.info.hash ;
|
||||
|
||||
IndicateConfigChanged();
|
||||
|
||||
|
@ -190,6 +187,8 @@ bool ftExtraList::removeExtraFile(const RsFileHash& hash, TransferRequestFlags f
|
|||
|
||||
RsStackMutex stack(extMutex);
|
||||
|
||||
mHashOfHash.erase(makeEncryptedHash(hash)) ;
|
||||
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
it = mFiles.find(hash);
|
||||
if (it == mFiles.end())
|
||||
|
@ -242,29 +241,26 @@ bool ftExtraList::cleanupOldFiles()
|
|||
time_t now = time(NULL);
|
||||
|
||||
std::list<RsFileHash> toRemove;
|
||||
std::list<RsFileHash>::iterator rit;
|
||||
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
for(it = mFiles.begin(); it != mFiles.end(); ++it)
|
||||
{
|
||||
/* check timestamps */
|
||||
for( std::map<RsFileHash, FileDetails>::iterator it = mFiles.begin(); it != mFiles.end(); ++it) /* check timestamps */
|
||||
if ((time_t)it->second.info.age < now)
|
||||
{
|
||||
toRemove.push_back(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove.size() > 0)
|
||||
{
|
||||
std::map<RsFileHash, FileDetails>::iterator it;
|
||||
|
||||
/* remove items */
|
||||
for(rit = toRemove.begin(); rit != toRemove.end(); ++rit)
|
||||
{
|
||||
for(std::list<RsFileHash>::iterator rit = toRemove.begin(); rit != toRemove.end(); ++rit)
|
||||
{
|
||||
if (mFiles.end() != (it = mFiles.find(*rit)))
|
||||
{
|
||||
cleanupEntry(it->second.info.path, it->second.info.transfer_info_flags);
|
||||
mFiles.erase(it);
|
||||
}
|
||||
}
|
||||
mHashOfHash.erase(makeEncryptedHash(*rit)) ;
|
||||
}
|
||||
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
return true;
|
||||
|
@ -333,31 +329,71 @@ bool ftExtraList::hashExtraFileDone(std::string path, FileInfo &info)
|
|||
**/
|
||||
bool ftExtraList::search(const RsFileHash &hash, FileSearchFlags /*hintflags*/, FileInfo &info) const
|
||||
{
|
||||
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << "ftExtraList::search()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "ftExtraList::search() hash=" << hash ;
|
||||
#endif
|
||||
|
||||
/* find hash */
|
||||
std::map<RsFileHash, FileDetails>::const_iterator fit;
|
||||
if (mFiles.end() == (fit = mFiles.find(hash)))
|
||||
{
|
||||
return false;
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << " not found in mFiles. Trying encrypted... " ;
|
||||
#endif
|
||||
// File not found. We try to look for encrypted hash.
|
||||
|
||||
std::map<RsFileHash,RsFileHash>::const_iterator hit = mHashOfHash.find(hash) ;
|
||||
|
||||
if(hit == mHashOfHash.end())
|
||||
{
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << " not found." << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << " found! Reaching data..." ;
|
||||
#endif
|
||||
|
||||
fit = mFiles.find(hit->second) ;
|
||||
|
||||
if(fit == mFiles.end()) // not found. This is an error.
|
||||
{
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << " no data. Returning false." << std::endl;
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << " ok! Accepting encrypted transfer." << std::endl;
|
||||
#endif
|
||||
info = fit->second.info;
|
||||
info.storage_permission_flags = FileStorageFlags(DIR_FLAGS_ANONYMOUS_DOWNLOAD) ;
|
||||
info.transfer_info_flags |= RS_FILE_REQ_ENCRYPTED ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << " found! Accepting direct transfer" << std::endl;
|
||||
#endif
|
||||
info = fit->second.info;
|
||||
|
||||
info = fit->second.info;
|
||||
|
||||
// Now setup the file storage flags so that the client can know how to handle permissions
|
||||
//
|
||||
#warning mr-alice: make sure this is right
|
||||
info.storage_permission_flags = FileStorageFlags(0) ;//DIR_FLAGS_BROWSABLE_OTHERS ;
|
||||
// Unencrypted file transfer: We only allow direct transfers. This is not exactly secure since another friend can
|
||||
// swarm the file. But the hash being kept secret, there's no risk here.
|
||||
//
|
||||
info.storage_permission_flags = FileStorageFlags(DIR_FLAGS_BROWSABLE) ;
|
||||
}
|
||||
|
||||
if(info.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) info.storage_permission_flags |= DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsFileHash ftExtraList::makeEncryptedHash(const RsFileHash& hash)
|
||||
{
|
||||
return RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES);
|
||||
}
|
||||
|
||||
/***
|
||||
* Configuration - store extra files.
|
||||
|
@ -472,6 +508,8 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
|
|||
|
||||
/* stick it in the available queue */
|
||||
mFiles[details.info.hash] = details;
|
||||
mHashOfHash[makeEncryptedHash(details.info.hash)] = details.info.hash ;
|
||||
|
||||
delete (*it);
|
||||
|
||||
/* short sleep */
|
||||
|
|
|
@ -109,66 +109,69 @@ const uint32_t CLEANUP_PERIOD = 600; /* 10 minutes */
|
|||
class ftExtraList: public RsTickingThread, public p3Config, public ftSearch
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
ftExtraList();
|
||||
ftExtraList();
|
||||
|
||||
/***
|
||||
/***
|
||||
* If the File is alreay Hashed, then just add it in.
|
||||
**/
|
||||
|
||||
bool addExtraFile(std::string path, const RsFileHash &hash,
|
||||
uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
bool addExtraFile(std::string path, const RsFileHash &hash,
|
||||
uint64_t size, uint32_t period, TransferRequestFlags flags);
|
||||
|
||||
bool removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags);
|
||||
bool moveExtraFile(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
std::string destpath);
|
||||
bool removeExtraFile(const RsFileHash& hash, TransferRequestFlags flags);
|
||||
bool moveExtraFile(std::string fname, const RsFileHash& hash, uint64_t size,
|
||||
std::string destpath);
|
||||
|
||||
|
||||
/***
|
||||
* Hash file, and add to the files,
|
||||
/***
|
||||
* Hash file, and add to the files,
|
||||
* file is removed after period.
|
||||
**/
|
||||
|
||||
bool hashExtraFile(std::string path, uint32_t period, TransferRequestFlags flags);
|
||||
bool hashExtraFileDone(std::string path, FileInfo &info);
|
||||
bool hashExtraFile(std::string path, uint32_t period, TransferRequestFlags flags);
|
||||
bool hashExtraFileDone(std::string path, FileInfo &info);
|
||||
|
||||
/***
|
||||
* Search Function - used by File Transfer
|
||||
/***
|
||||
* Search Function - used by File Transfer
|
||||
* implementation of ftSearch.
|
||||
*
|
||||
**/
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||
|
||||
/***
|
||||
* Thread Main Loop
|
||||
/***
|
||||
* Thread Main Loop
|
||||
**/
|
||||
virtual void data_tick();
|
||||
virtual void data_tick();
|
||||
|
||||
/***
|
||||
/***
|
||||
* Configuration - store extra files.
|
||||
*
|
||||
**/
|
||||
protected:
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem*>&);
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
protected:
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem*>&);
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
|
||||
private:
|
||||
static RsFileHash makeEncryptedHash(const RsFileHash& hash);
|
||||
|
||||
/* Worker Functions */
|
||||
void hashAFile();
|
||||
bool cleanupOldFiles();
|
||||
bool cleanupEntry(std::string path, TransferRequestFlags flags);
|
||||
private:
|
||||
|
||||
mutable RsMutex extMutex;
|
||||
/* Worker Functions */
|
||||
void hashAFile();
|
||||
bool cleanupOldFiles();
|
||||
bool cleanupEntry(std::string path, TransferRequestFlags flags);
|
||||
|
||||
std::list<FileDetails> mToHash;
|
||||
mutable RsMutex extMutex;
|
||||
|
||||
std::map<std::string, RsFileHash> mHashedList; /* path -> hash ( not saved ) */
|
||||
std::map<RsFileHash, FileDetails> mFiles;
|
||||
std::list<FileDetails> mToHash;
|
||||
|
||||
time_t cleanup ;
|
||||
std::map<std::string, RsFileHash> mHashedList; /* path -> hash ( not saved ) */
|
||||
std::map<RsFileHash, FileDetails> mFiles;
|
||||
std::map<RsFileHash, RsFileHash> mHashOfHash; /* sha1(hash) map so as to answer requests to encrypted transfers */
|
||||
|
||||
time_t cleanup ;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -60,7 +60,8 @@ const int ftserverzone = 29539;
|
|||
#define FTSERVER_DEBUG() std::cerr << time(NULL) << " : FILE_SERVER : " << __FUNCTION__ << " : "
|
||||
#define FTSERVER_ERROR() std::cerr << "(EE) FILE_SERVER ERROR : "
|
||||
|
||||
static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds
|
||||
static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds
|
||||
static const time_t FILE_TRANSFER_MAX_DELAY_BEFORE_DROP_USAGE_RECORD = 10 ; // keep usage records for 10 secs at most.
|
||||
|
||||
/* Setup */
|
||||
ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc)
|
||||
|
@ -318,6 +319,16 @@ uint32_t ftServer::defaultEncryptionPolicy()
|
|||
{
|
||||
return mFtController->defaultEncryptionPolicy() ;
|
||||
}
|
||||
|
||||
void ftServer::setMaxUploadSlotsPerFriend(uint32_t n)
|
||||
{
|
||||
mFtController->setMaxUploadsPerFriend(n) ;
|
||||
}
|
||||
uint32_t ftServer::getMaxUploadSlotsPerFriend()
|
||||
{
|
||||
return mFtController->getMaxUploadsPerFriend() ;
|
||||
}
|
||||
|
||||
void ftServer::setDefaultEncryptionPolicy(uint32_t s)
|
||||
{
|
||||
mFtController->setDefaultEncryptionPolicy(s) ;
|
||||
|
@ -1518,6 +1529,83 @@ int ftServer::tick()
|
|||
return moreToTick;
|
||||
}
|
||||
|
||||
bool ftServer::checkUploadLimit(const RsPeerId& pid,const RsFileHash& hash)
|
||||
{
|
||||
// No need for this extra cost if the value means "unlimited"
|
||||
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "Checking upload limit for friend " << pid << " and hash " << hash << ": " ;
|
||||
#endif
|
||||
|
||||
uint32_t max_ups = mFtController->getMaxUploadsPerFriend() ;
|
||||
|
||||
RS_STACK_MUTEX(srvMutex) ;
|
||||
|
||||
if(max_ups == 0)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << " no limit! returning true." << std::endl;
|
||||
#endif
|
||||
return true ;
|
||||
}
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << " max=" << max_ups ;
|
||||
#endif
|
||||
|
||||
// Find the latest records for this pid.
|
||||
|
||||
std::map<RsFileHash,time_t>& tmap(mUploadLimitMap[pid]) ;
|
||||
std::map<RsFileHash,time_t>::iterator it ;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
// If the limit has been decresed, we arbitrarily drop some ongoing slots.
|
||||
|
||||
while(tmap.size() > max_ups)
|
||||
tmap.erase(tmap.begin()) ;
|
||||
|
||||
// Look in the upload record map. If it's not full, directly allocate a slot. If full, re-use an existing slot if a file is already cited.
|
||||
|
||||
if(tmap.size() < max_ups || (tmap.size()==max_ups && tmap.end() != (it = tmap.find(hash))))
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << " allocated slot for this hash => true" << std::endl;
|
||||
#endif
|
||||
|
||||
tmap[hash] = now ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
// There's no room in the used slots, but maybe some of them are not used anymore, in which case we remove them, which freeze a slot.
|
||||
uint32_t cleaned = 0 ;
|
||||
|
||||
for(it = tmap.begin();it!=tmap.end() && cleaned<2;)
|
||||
if(it->second + FILE_TRANSFER_MAX_DELAY_BEFORE_DROP_USAGE_RECORD < now)
|
||||
{
|
||||
std::map<RsFileHash,time_t>::iterator tmp(it) ;
|
||||
++tmp;
|
||||
tmap.erase(it) ;
|
||||
it = tmp;
|
||||
++cleaned ;
|
||||
}
|
||||
else
|
||||
++it ;
|
||||
|
||||
if(cleaned > 0)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << " cleaned up " << cleaned << " old hashes => true" << std::endl;
|
||||
#endif
|
||||
tmap[hash] = now ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << " no slot for this hash => false" << std::endl;
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
|
||||
int ftServer::handleIncoming()
|
||||
{
|
||||
// now File Input.
|
||||
|
@ -1534,7 +1622,8 @@ int ftServer::handleIncoming()
|
|||
case RS_PKT_SUBTYPE_FT_DATA_REQUEST:
|
||||
{
|
||||
RsFileTransferDataRequestItem *f = dynamic_cast<RsFileTransferDataRequestItem*>(item) ;
|
||||
if (f)
|
||||
|
||||
if (f && checkUploadLimit(f->PeerId(),f->file.hash))
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
FTSERVER_DEBUG() << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl;
|
||||
|
|
|
@ -138,6 +138,8 @@ public:
|
|||
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
virtual void setDefaultEncryptionPolicy(uint32_t policy) ; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
|
||||
virtual uint32_t defaultEncryptionPolicy() ;
|
||||
virtual void setMaxUploadSlotsPerFriend(uint32_t n) ;
|
||||
virtual uint32_t getMaxUploadSlotsPerFriend() ;
|
||||
|
||||
/***
|
||||
* Control of Downloads Priority.
|
||||
|
@ -266,6 +268,7 @@ protected:
|
|||
bool findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash);
|
||||
bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash);
|
||||
|
||||
bool checkUploadLimit(const RsPeerId& pid,const RsFileHash& hash);
|
||||
private:
|
||||
|
||||
/**** INTERNAL FUNCTIONS ***/
|
||||
|
@ -293,6 +296,7 @@ private:
|
|||
|
||||
std::map<RsFileHash,RsFileHash> mEncryptedHashes ; // This map is such that sha1(it->second) = it->first
|
||||
std::map<RsPeerId,RsFileHash> mEncryptedPeerIds ; // This map holds the hash to be used with each peer id
|
||||
std::map<RsPeerId,std::map<RsFileHash,time_t> > mUploadLimitMap ;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1363,6 +1363,18 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem
|
|||
gItem->meta.mPop = 0;
|
||||
gItem->meta.mVisibleMsgCount = 0;
|
||||
}
|
||||
|
||||
// Also check the group privacy flags. A while ago, it as possible to publish a group without privacy flags. Now it is not possible anymore.
|
||||
// As a consequence, it's important to supply a correct value in this flag before the data can be edited/updated.
|
||||
|
||||
if((gItem->meta.mGroupFlags & GXS_SERV::FLAG_PRIVACY_MASK) == 0)
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "(WW) getGroupData(): mGroupFlags for group " << gItem->meta.mGroupId << " has incorrect value " << std::hex << gItem->meta.mGroupFlags << std::dec << ". Setting value to GXS_SERV::FLAG_PRIVACY_PUBLIC." << std::endl;
|
||||
#endif
|
||||
gItem->meta.mGroupFlags |= GXS_SERV::FLAG_PRIVACY_PUBLIC;
|
||||
}
|
||||
|
||||
grpItem.push_back(gItem);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -82,14 +82,23 @@ bool RsGxsMessageCleanUp::clean()
|
|||
for(; mit != result.end(); ++mit)
|
||||
{
|
||||
std::vector<RsGxsMsgMetaData*>& metaV = mit->second;
|
||||
std::vector<RsGxsMsgMetaData*>::iterator vit = metaV.begin();
|
||||
|
||||
for(; vit != metaV.end(); )
|
||||
// First, make a map of which message have a child message. This allows to only delete messages that dont have child messages.
|
||||
// A more accurate way to go would be to compute the time of the oldest message and possibly delete all the branch, but in the
|
||||
// end the message tree will be deleted slice after slice, which should still be reasonnably fast.
|
||||
//
|
||||
std::set<RsGxsMessageId> messages_with_kids ;
|
||||
|
||||
for( uint32_t i=0;i<metaV.size();++i)
|
||||
if(!metaV[i]->mParentId.isNull())
|
||||
messages_with_kids.insert(metaV[i]->mParentId) ;
|
||||
|
||||
for( uint32_t i=0;i<metaV.size();++i)
|
||||
{
|
||||
RsGxsMsgMetaData* meta = *vit;
|
||||
RsGxsMsgMetaData* meta = metaV[i];
|
||||
|
||||
// check if expired
|
||||
bool remove = store_period > 0 && (meta->mPublishTs + store_period) < now;
|
||||
bool remove = store_period > 0 && ((meta->mPublishTs + store_period) < now) && (messages_with_kids.find(meta->mMsgId)==messages_with_kids.end());
|
||||
|
||||
// check client does not want the message kept regardless of age
|
||||
remove &= !(meta->mMsgStatus & GXS_SERV::GXS_MSG_STATUS_KEEP);
|
||||
|
@ -106,7 +115,6 @@ bool RsGxsMessageCleanUp::clean()
|
|||
}
|
||||
|
||||
delete meta;
|
||||
vit = metaV.erase(vit);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -532,7 +532,8 @@ HEADERS += util/folderiterator.h \
|
|||
util/rsrecogn.h \
|
||||
util/rsscopetimer.h \
|
||||
util/stacktrace.h \
|
||||
util/rsdeprecate.h
|
||||
util/rsdeprecate.h \
|
||||
util/cxx11retrocompat.h
|
||||
|
||||
SOURCES += ft/ftchunkmap.cc \
|
||||
ft/ftcontroller.cc \
|
||||
|
|
|
@ -503,12 +503,15 @@ bool RsPluginManager::loadList(std::list<RsItem*>& list)
|
|||
delete (*it);
|
||||
}
|
||||
|
||||
// Rejected hashes are always kept, so that RS wont ask again if the executable hash has changed.
|
||||
//
|
||||
_rejected_hashes = rejected_hash_candidates ;
|
||||
|
||||
if(reference_executable_hash == _current_executable_hash)
|
||||
{
|
||||
std::cerr << "(II) Executable hash matches. Updating the list of accepted/rejected plugins." << std::endl;
|
||||
|
||||
_accepted_hashes = accepted_hash_candidates ;
|
||||
_rejected_hashes = rejected_hash_candidates ;
|
||||
}
|
||||
else
|
||||
std::cerr << "(WW) Executable hashes do not match. Executable hash has changed. Discarding the list of accepted/rejected plugins." << std::endl;
|
||||
|
|
|
@ -815,7 +815,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long /*days*/)
|
|||
const EVP_MD *type = EVP_sha1();
|
||||
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_create();
|
||||
unsigned char *p,*buf_in=NULL;
|
||||
unsigned char *buf_in=NULL;
|
||||
unsigned char *buf_hashout=NULL,*buf_sigout=NULL;
|
||||
int inl=0,hashoutl=0;
|
||||
int sigoutl=0;
|
||||
|
@ -854,6 +854,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long /*days*/)
|
|||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
inl=i2d(data,NULL);
|
||||
buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl);
|
||||
unsigned char *p=NULL;
|
||||
#else
|
||||
inl=i2d_re_X509_tbs(x509,&buf_in) ; // this does the i2d over x509->cert_info
|
||||
#endif
|
||||
|
@ -977,9 +978,9 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,uint32_t& diagnostic)
|
|||
/* verify GPG signature */
|
||||
|
||||
/*** NOW The Manual signing bit (HACKED FROM asn1/a_sign.c) ***/
|
||||
int (*i2d)(X509_CINF*, unsigned char**) = i2d_X509_CINF;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
int (*i2d)(X509_CINF*, unsigned char**) = i2d_X509_CINF;
|
||||
ASN1_BIT_STRING *signature = x509->signature;
|
||||
X509_CINF *data = x509->cert_info;
|
||||
#else
|
||||
|
@ -993,7 +994,7 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,uint32_t& diagnostic)
|
|||
const EVP_MD *type = EVP_sha1();
|
||||
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_create();
|
||||
unsigned char *p,*buf_in=NULL;
|
||||
unsigned char *buf_in=NULL;
|
||||
unsigned char *buf_hashout=NULL,*buf_sigout=NULL;
|
||||
int inl=0,hashoutl=0;
|
||||
int sigoutl=0;
|
||||
|
@ -1002,6 +1003,7 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,uint32_t& diagnostic)
|
|||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
inl=i2d(data,NULL);
|
||||
buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl);
|
||||
unsigned char *p=NULL;
|
||||
#else
|
||||
inl=i2d_re_X509_tbs(x509,&buf_in) ; // this does the i2d over x509->cert_info
|
||||
#endif
|
||||
|
@ -1026,13 +1028,13 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,uint32_t& diagnostic)
|
|||
diagnostic = RS_SSL_HANDSHAKE_DIAGNOSTIC_MALLOC_ERROR ;
|
||||
goto err;
|
||||
}
|
||||
p=buf_in;
|
||||
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << "Buffers Allocated" << std::endl;
|
||||
#endif
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
p=buf_in;
|
||||
i2d(data,&p);
|
||||
#endif
|
||||
/* data in buf_in, ready to be hashed */
|
||||
|
|
|
@ -167,6 +167,8 @@ class RsFiles
|
|||
virtual bool FileClearCompleted() = 0;
|
||||
virtual void setDefaultEncryptionPolicy(uint32_t policy)=0 ; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
|
||||
virtual uint32_t defaultEncryptionPolicy()=0 ;
|
||||
virtual void setMaxUploadSlotsPerFriend(uint32_t n)=0 ;
|
||||
virtual uint32_t getMaxUploadSlotsPerFriend()=0 ;
|
||||
|
||||
/***
|
||||
* Control of Downloads Priority.
|
||||
|
|
|
@ -192,7 +192,7 @@ void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneri
|
|||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,stunList,"stunList") ;
|
||||
}
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const PeerBandwidthLimits& s)
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const PeerBandwidthLimits& /*s*/)
|
||||
{
|
||||
return 4+4 ;
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz
|
|||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const PeerBandwidthLimits& s)
|
||||
template<> void RsTypeSerializer::print_data(const std::string& /*n*/, const PeerBandwidthLimits& s)
|
||||
{
|
||||
std::cerr << " [Peer BW limit] " << s.max_up_rate_kbs << " / " << s.max_dl_rate_kbs << std::endl;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "serialiser/rsserializer.h"
|
||||
#include "util/stacktrace.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
class RsItem: public RsMemoryManagement::SmallObject
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -162,6 +162,19 @@ void RsNxsGrp::clear()
|
|||
meta.TlvClear();
|
||||
}
|
||||
|
||||
RsNxsGrp* RsNxsGrp::clone() const {
|
||||
RsNxsGrp* grp = new RsNxsGrp(this->grp.tlvtype);
|
||||
*grp = *this;
|
||||
|
||||
if(this->metaData)
|
||||
{
|
||||
grp->metaData = new RsGxsGrpMetaData();
|
||||
*(grp->metaData) = *(this->metaData);
|
||||
}
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
||||
void RsNxsSyncGrpReqItem::clear()
|
||||
{
|
||||
flag = 0;
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
|
@ -385,7 +387,7 @@ RsItem * RsSerialiser::deserialise(void *data, uint32_t *size)
|
|||
//std::cerr << "RsSerialiser::deserialise() RsItem Type: " << std::hex << getRsItemId(data) << " Size: " << pkt_size;
|
||||
//std::cerr << std::endl;
|
||||
|
||||
if (pkt_size != *size)
|
||||
if (pkt_size > *size)
|
||||
{
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsSerialiser::deserialise() ERROR Size mismatch(2)";
|
||||
|
|
|
@ -60,12 +60,14 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size)
|
|||
|
||||
item->serial_process(RsGenericSerializer::DESERIALIZE, ctx) ;
|
||||
|
||||
if(ctx.mSize != ctx.mOffset)
|
||||
if(ctx.mSize < ctx.mOffset)
|
||||
{
|
||||
std::cerr << "RsSerializer::deserialise(): ERROR. offset does not match expected size!" << std::endl;
|
||||
delete item ;
|
||||
return NULL ;
|
||||
}
|
||||
*size = ctx.mOffset ;
|
||||
|
||||
if(ctx.mOk)
|
||||
return item ;
|
||||
|
||||
|
@ -96,12 +98,14 @@ RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size)
|
|||
|
||||
item->serial_process(DESERIALIZE, ctx) ;
|
||||
|
||||
if(ctx.mSize != ctx.mOffset)
|
||||
if(ctx.mSize < ctx.mOffset)
|
||||
{
|
||||
std::cerr << "RsSerializer::deserialise(): ERROR. offset does not match expected size!" << std::endl;
|
||||
delete item ;
|
||||
return NULL ;
|
||||
}
|
||||
*size = ctx.mOffset ;
|
||||
|
||||
if(ctx.mOk)
|
||||
return item ;
|
||||
|
||||
|
@ -139,6 +143,8 @@ bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size)
|
|||
std::cerr << "RsSerializer::serialise(): ERROR. offset does not match expected size!" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
*size = ctx.mOffset ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#include "util/rsprint.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <typeinfo>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
static const uint32_t MAX_SERIALIZED_ARRAY_SIZE = 500 ;
|
||||
static const uint32_t MAX_SERIALIZED_CHUNK_SIZE = 10*1024*1024 ; // 10 MB.
|
||||
|
@ -192,7 +195,7 @@ template<> void RsTypeSerializer::print_data(const std::string& n, uint16_t type
|
|||
// TlvInt with subtype //
|
||||
//=================================================================================================//
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(uint16_t /* type_subtype */,const uint32_t& s)
|
||||
template<> uint32_t RsTypeSerializer::serial_size(uint16_t /* type_subtype */,const uint32_t& /*s*/)
|
||||
{
|
||||
return GetTlvUInt32Size() ;
|
||||
}
|
||||
|
|
|
@ -452,7 +452,6 @@ protected:
|
|||
template<typename T> static void print_data(
|
||||
const std::string& name,uint16_t type_id,const T& member );
|
||||
|
||||
|
||||
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
|
||||
static bool serialize(
|
||||
uint8_t data[], uint32_t size, uint32_t &offset,
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "rsitems/rsposteditems.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
/****
|
||||
* #define POSTED_DEBUG 1
|
||||
|
|
|
@ -52,12 +52,14 @@ RsSerialType* init_item(RsChatLobbyListItem& cmi)
|
|||
|
||||
cmi.lobby_ids.resize(n) ;
|
||||
cmi.lobby_names.resize(n) ;
|
||||
cmi.lobby_topics.resize(n) ;
|
||||
cmi.lobby_counts.resize(n) ;
|
||||
|
||||
for(int i=0;i<n;++i)
|
||||
{
|
||||
cmi.lobby_ids[i] = RSRandom::random_u64() ;
|
||||
randString(5+(rand()%10), cmi.lobby_names[i]);
|
||||
randString(5+(rand()%10), cmi.lobby_topics[i]);
|
||||
cmi.lobby_counts[i] = RSRandom::random_u32() ;
|
||||
}
|
||||
|
||||
|
@ -87,6 +89,7 @@ RsSerialType* init_item(RsChatLobbyInviteItem& cmi)
|
|||
{
|
||||
cmi.lobby_id = RSRandom::random_u64() ;
|
||||
cmi.lobby_name = "Name of the lobby" ;
|
||||
cmi.lobby_topic = "Topic of the lobby" ;
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
|
@ -185,12 +188,14 @@ bool operator ==(const RsChatLobbyListItem& cmiLeft,const RsChatLobbyListItem&
|
|||
{
|
||||
if(cmiLeft.lobby_ids.size() != cmiRight.lobby_ids.size()) return false;
|
||||
if(cmiLeft.lobby_names.size() != cmiRight.lobby_names.size()) return false;
|
||||
if(cmiLeft.lobby_topics.size() != cmiRight.lobby_topics.size()) return false;
|
||||
if(cmiLeft.lobby_counts.size() != cmiRight.lobby_counts.size()) return false;
|
||||
|
||||
for(uint32_t i=0;i<cmiLeft.lobby_ids.size();++i)
|
||||
{
|
||||
if(cmiLeft.lobby_ids[i] != cmiRight.lobby_ids[i]) return false ;
|
||||
if(cmiLeft.lobby_names[i] != cmiRight.lobby_names[i]) return false ;
|
||||
if(cmiLeft.lobby_topics[i] != cmiRight.lobby_topics[i]) return false ;
|
||||
if(cmiLeft.lobby_counts[i] != cmiRight.lobby_counts[i]) return false ;
|
||||
}
|
||||
return true ;
|
||||
|
@ -254,6 +259,7 @@ bool operator ==(const RsChatLobbyInviteItem& csiLeft, const RsChatLobbyInviteIt
|
|||
{
|
||||
if(csiLeft.lobby_id != csiRight.lobby_id) return false ;
|
||||
if(csiLeft.lobby_name != csiRight.lobby_name) return false ;
|
||||
if(csiLeft.lobby_topic != csiRight.lobby_topic) return false ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
25
libretroshare/src/util/cxx11retrocompat.h
Normal file
25
libretroshare/src/util/cxx11retrocompat.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
/*
|
||||
* RetroShare
|
||||
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
# if __GNUC__*100 + __GNUC_MINOR__ < 40700
|
||||
# define override
|
||||
# define final
|
||||
# endif //GCC version
|
||||
#endif //defined GNUC
|
|
@ -552,8 +552,8 @@ RsGxsRecognTagItem *RsRecogn::extractTag(const std::string &encoded)
|
|||
std::vector<uint8_t> buffer = Radix64::decode(encoded);
|
||||
pktsize = buffer.size();
|
||||
|
||||
if(buffer.empty())
|
||||
return NULL ;
|
||||
if( buffer.empty() )
|
||||
return NULL;
|
||||
|
||||
RsGxsRecognSerialiser serialiser;
|
||||
RsItem *item = serialiser.deserialise(buffer.data(), &pktsize);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue