Improve async distant chat, fix chat msg receiving

DistantChatService::initiateDistantChatConnexion(...) made notification
  message optional (enabled by default)
p3ChatService removed duplicion avoidance as it is not necessary
p3ChatService::sendStatusString(...) send status only if peer is online
protect p3ChatService::mDistantGxsMap with mutex as operation on it may
  be done by different threads
p3ChatService::receiveGxsMai(...) set chat message item peer id with
  distant tunnel id, so it is recognized as a distant message later
made p3GxsTunnelService::makeGxsTunnelId(...) static as it need no
  access to this, now it can be used easier by other components
rename RsGxsMailItem::recipientsHint to recipientHint as for now only
  one recipient is possible (TODO: update documentation too)
GxsMailsClient::receiveGxsMail(...) changed paramethers for better
  abstracion, now destination id is passed too because it is usually a
  very useful information
ChatWidget some adaptation to async chat, a couple of method have been
  deprecated too
PopupDistantChatDialog::updateDisplay(...) adapt message shown to the
  user to the new async chat paradigm (TODO: need review)
This commit is contained in:
Gioacchino Mazzurco 2017-03-01 23:07:53 +01:00
parent 0f1106fd8f
commit 953b70fbe4
14 changed files with 212 additions and 212 deletions

View file

@ -262,7 +262,7 @@ void p3GxsMails::service_tick()
<< msg->meta.mMsgId
<< " with cryptoType: "
<< static_cast<uint32_t>(msg->cryptoType)
<< " recipientHint: " << msg->recipientsHint
<< " recipientHint: " << msg->recipientHint
<< " mailId: "<< msg->mailId
<< " payload.size(): " << msg->payload.size()
<< std::endl;
@ -423,8 +423,10 @@ bool p3GxsMails::handleEcryptedMail(const RsGxsMailItem* mail)
getRawUInt16(&mail->payload[0], mail->payload.size(), &off, &csri);
std::cerr << "service: " << csri << " got CLEAR_TEXT mail!"
<< std::endl;
return dispatchDecryptedMail( mail, &mail->payload[0],
mail->payload.size() );
/* As we cannot verify recipient without encryption, just pass the hint
* as recipient */
return dispatchDecryptedMail( mail->meta.mAuthorId, mail->recipientHint,
&mail->payload[0], mail->payload.size() );
}
case RsGxsMailEncryptionMode::RSA:
{
@ -432,14 +434,16 @@ bool p3GxsMails::handleEcryptedMail(const RsGxsMailItem* mail)
for( std::set<RsGxsId>::const_iterator it = decryptIds.begin();
it != decryptIds.end(); ++it )
{
const RsGxsId& decryptId(*it);
uint8_t* decrypted_data = NULL;
uint32_t decrypted_data_size = 0;
uint32_t decryption_error;
if( idService.decryptData( &mail->payload[0],
mail->payload.size(), decrypted_data,
decrypted_data_size, *it,
decrypted_data_size, decryptId,
decryption_error ) )
ok = ok && dispatchDecryptedMail( mail, decrypted_data,
ok = ok && dispatchDecryptedMail( mail->meta.mAuthorId,
decryptId, decrypted_data,
decrypted_data_size );
free(decrypted_data);
}
@ -452,7 +456,8 @@ bool p3GxsMails::handleEcryptedMail(const RsGxsMailItem* mail)
}
}
bool p3GxsMails::dispatchDecryptedMail( const RsGxsMailItem* received_msg,
bool p3GxsMails::dispatchDecryptedMail( const RsGxsId& authorId,
const RsGxsId& decryptId,
const uint8_t* decrypted_data,
uint32_t decrypted_data_size )
{
@ -486,16 +491,16 @@ bool p3GxsMails::dispatchDecryptedMail( const RsGxsMailItem* received_msg,
std::vector<RsNxsMsg*> rcct; rcct.push_back(receipt);
RsGenExchange::notifyNewMessages(rcct);
GxsMailsClient* reecipientService = NULL;
GxsMailsClient* recipientService = NULL;
{
RS_STACK_MUTEX(servClientsMutex);
reecipientService = servClients[rsrvc];
recipientService = servClients[rsrvc];
}
if(reecipientService)
return reecipientService->receiveGxsMail( *received_msg,
&decrypted_data[offset],
decrypted_data_size-offset );
if(recipientService)
return recipientService->receiveGxsMail( authorId, decryptId,
&decrypted_data[offset],
decrypted_data_size-offset );
else
{
std::cerr << "p3GxsMails::dispatchReceivedMail(...) "
@ -625,7 +630,7 @@ void p3GxsMails::processOutgoingRecord(OutgoingRecord& pr)
<< pr.recipient
<< " with cryptoType: "
<< static_cast<uint>(pr.mailItem.cryptoType)
<< " recipientHint: " << pr.mailItem.recipientsHint
<< " recipientHint: " << pr.mailItem.recipientHint
<< " receiptId: " << pr.mailItem.mailId
<< " payload size: " << pr.mailItem.payload.size()
<< std::endl;