mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-07 00:25:16 -04:00
added challenge protocol to securely improve lobby connectivity
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4735 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
816a477806
commit
d4abb42788
4 changed files with 259 additions and 45 deletions
|
@ -57,6 +57,15 @@ std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent)
|
|||
printRsItemEnd(out, "RsChatMsgItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& RsChatLobbyConnectChallengeItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsChatLobbyConnectChallengeItem", indent);
|
||||
printIndent(out, indent);
|
||||
out << "Challenge Code: " << std::hex << challenge_code << std::endl;
|
||||
printRsItemEnd(out, "RsChatLobbyConnectChallengeItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsChatLobbyMsgItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
RsChatMsgItem::print(out,indent) ;
|
||||
|
@ -190,6 +199,13 @@ uint32_t RsChatMsgItem::serial_size()
|
|||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsChatLobbyConnectChallengeItem::serial_size()
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 8; // challenge code
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsChatLobbyMsgItem::serial_size()
|
||||
{
|
||||
uint32_t s = RsChatMsgItem::serial_size() ; // parent
|
||||
|
@ -339,6 +355,33 @@ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize)
|
|||
return ok ;
|
||||
}
|
||||
|
||||
bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header!
|
||||
uint32_t offset = 8 ;
|
||||
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, challenge_code);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
|
||||
#endif
|
||||
pktsize = tlvsize ;
|
||||
return ok ;
|
||||
}
|
||||
|
||||
bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
|
@ -540,6 +583,23 @@ RsChatLobbyMsgItem::RsChatLobbyMsgItem(void *data,uint32_t /*size*/)
|
|||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||
}
|
||||
|
||||
RsChatLobbyConnectChallengeItem::RsChatLobbyConnectChallengeItem(void *data,uint32_t /*size*/)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE)
|
||||
{
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
std::cerr << "RsChatLobbyConnectChallengeItem: rsitem size is " << rssize << std::endl;
|
||||
uint32_t offset = 8 ;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= getRawUInt64(data, rssize, &offset, &challenge_code);
|
||||
|
||||
if (offset != rssize)
|
||||
std::cerr << "Size error while deserializing." << std::endl ;
|
||||
if (!ok)
|
||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||
}
|
||||
RsChatLobbyInviteItem::RsChatLobbyInviteItem(void *data,uint32_t /*size*/)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue