finished implementing GXS search items

This commit is contained in:
csoler 2018-05-31 15:41:54 +02:00
parent e7182013bf
commit 90d7f55c40
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
9 changed files with 322 additions and 160 deletions

View File

@ -231,6 +231,7 @@ void p3Notify::notifyChatLobbyTimeShift (int time_shift)
void p3Notify::notifyCustomState (const std::string& peer_id , const std::string& status_string ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyCustomState (peer_id,status_string) ; } void p3Notify::notifyCustomState (const std::string& peer_id , const std::string& status_string ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyCustomState (peer_id,status_string) ; }
void p3Notify::notifyHashingInfo (uint32_t type , const std::string& fileinfo ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHashingInfo (type,fileinfo) ; } void p3Notify::notifyHashingInfo (uint32_t type , const std::string& fileinfo ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHashingInfo (type,fileinfo) ; }
void p3Notify::notifyTurtleSearchResult (uint32_t search_id , const std::list<TurtleFileInfo>& files ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(search_id,files) ; } void p3Notify::notifyTurtleSearchResult (uint32_t search_id , const std::list<TurtleFileInfo>& files ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(search_id,files) ; }
void p3Notify::notifyTurtleSearchResult (uint32_t search_id , const std::list<TurtleGxsInfo>& groups ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(search_id,groups) ; }
void p3Notify::notifyPeerHasNewAvatar (std::string peer_id ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerHasNewAvatar(peer_id) ; } void p3Notify::notifyPeerHasNewAvatar (std::string peer_id ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerHasNewAvatar(peer_id) ; }
void p3Notify::notifyOwnAvatarChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnAvatarChanged() ; } void p3Notify::notifyOwnAvatarChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnAvatarChanged() ; }
void p3Notify::notifyOwnStatusMessageChanged() { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnStatusMessageChanged() ; } void p3Notify::notifyOwnStatusMessageChanged() { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnStatusMessageChanged() ; }

View File

@ -106,6 +106,7 @@ class p3Notify: public RsNotify
void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) ; void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) ;
void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) ; void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) ;
void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleFileInfo>& /* files */) ; void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleFileInfo>& /* files */) ;
void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleGxsInfo >& /* groups */) ;
void notifyPeerHasNewAvatar (std::string /* peer_id */) ; void notifyPeerHasNewAvatar (std::string /* peer_id */) ;
void notifyOwnAvatarChanged () ; void notifyOwnAvatarChanged () ;
void notifyOwnStatusMessageChanged () ; void notifyOwnStatusMessageChanged () ;

View File

@ -228,6 +228,7 @@ class NotifyClient
virtual void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) {} virtual void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) {}
virtual void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) {} virtual void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) {}
virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleFileInfo>& /* files */) {} virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleFileInfo>& /* files */) {}
virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list<TurtleGxsInfo >& /* groups */) {}
virtual void notifyPeerHasNewAvatar (std::string /* peer_id */) {} virtual void notifyPeerHasNewAvatar (std::string /* peer_id */) {}
virtual void notifyOwnAvatarChanged () {} virtual void notifyOwnAvatarChanged () {}
virtual void notifyOwnStatusMessageChanged () {} virtual void notifyOwnStatusMessageChanged () {}

View File

@ -57,8 +57,9 @@ struct TurtleFileInfo
struct TurtleGxsInfo struct TurtleGxsInfo
{ {
RsGxsGroupId group_id ; RsGxsGroupId group_id ;
uint16_t service_id ;
std::string name ; std::string name ;
RsTlvBinaryData meta ; //RsTlvBinaryData meta ;// is that actually needed? Not sure. Better if it's not.
}; };
struct TurtleTunnelRequestDisplayInfo struct TurtleTunnelRequestDisplayInfo
{ {

View File

@ -155,13 +155,15 @@ void p3turtle::getItemNames(std::map<uint8_t,std::string>& names) const
{ {
names.clear(); names.clear();
names[RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST ] = "Search request"; names[RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST ] = "Filename substring search request";
names[RS_TURTLE_SUBTYPE_SEARCH_RESULT ] = "Search result"; names[RS_TURTLE_SUBTYPE_GXS_SEARCH_REQUEST ] = "GXS search request";
names[RS_TURTLE_SUBTYPE_FT_SEARCH_RESULT ] = "File search result";
names[RS_TURTLE_SUBTYPE_GXS_SEARCH_RESULT ] = "GXS search result";
names[RS_TURTLE_SUBTYPE_OPEN_TUNNEL ] = "Tunnel request"; names[RS_TURTLE_SUBTYPE_OPEN_TUNNEL ] = "Tunnel request";
names[RS_TURTLE_SUBTYPE_TUNNEL_OK ] = "Tunnel response"; names[RS_TURTLE_SUBTYPE_TUNNEL_OK ] = "Tunnel response";
names[RS_TURTLE_SUBTYPE_FILE_REQUEST ] = "Data request"; names[RS_TURTLE_SUBTYPE_FILE_REQUEST ] = "Data request";
names[RS_TURTLE_SUBTYPE_FILE_DATA ] = "Data chunk"; names[RS_TURTLE_SUBTYPE_FILE_DATA ] = "Data chunk";
names[RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST ] = "RegExp search"; names[RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST ] = "Filename RegExp search request";
names[RS_TURTLE_SUBTYPE_GENERIC_DATA ] = "Generic data"; names[RS_TURTLE_SUBTYPE_GENERIC_DATA ] = "Generic data";
names[RS_TURTLE_SUBTYPE_FILE_MAP ] = "Chunk map"; names[RS_TURTLE_SUBTYPE_FILE_MAP ] = "Chunk map";
names[RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST ] = "Chunk map request"; names[RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST ] = "Chunk map request";
@ -840,7 +842,8 @@ int p3turtle::handleIncoming()
case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST: handleSearchRequest(dynamic_cast<RsTurtleSearchRequestItem *>(item)) ; case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST: handleSearchRequest(dynamic_cast<RsTurtleSearchRequestItem *>(item)) ;
break ; break ;
case RS_TURTLE_SUBTYPE_SEARCH_RESULT : handleSearchResult(dynamic_cast<RsTurtleSearchResultItem *>(item)) ; case RS_TURTLE_SUBTYPE_GXS_SEARCH_RESULT :
case RS_TURTLE_SUBTYPE_FT_SEARCH_RESULT : handleSearchResult(dynamic_cast<RsTurtleSearchResultItem *>(item)) ;
break ; break ;
case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : handleTunnelRequest(dynamic_cast<RsTurtleOpenTunnelItem *>(item)) ; case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : handleTunnelRequest(dynamic_cast<RsTurtleOpenTunnelItem *>(item)) ;
@ -924,49 +927,12 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
std::cerr << " Request not from us. Performing local search" << std::endl ; std::cerr << " Request not from us. Performing local search" << std::endl ;
#endif #endif
std::list<RsTurtleSearchResultItem*> search_results ;
std::list<TurtleFileInfo> result ; item->performLocalSearch(req,search_results) ;
item->performLocalSearch(result) ; for(auto it(search_results.begin());it!=search_results.end();++it)
sendItem(*it) ;
RsTurtleSearchResultItem *res_item = NULL ;
uint32_t item_size = 0 ;
#ifdef P3TURTLE_DEBUG
if(!result.empty())
std::cerr << " " << result.size() << " matches found. Sending back to origin (" << item->PeerId() << ")." << std::endl ;
#endif
while(!result.empty() && req.result_count < TURTLE_SEARCH_RESULT_MAX_HITS)
{
// Let's chop search results items into several chunks of finite size to avoid exceeding streamer's capacity.
//
static const uint32_t RSTURTLE_MAX_SEARCH_RESPONSE_SIZE = 10000 ;
if(res_item == NULL)
{
res_item = new RsTurtleSearchResultItem ;
item_size = 0 ;
res_item->depth = 0 ;
res_item->request_id = item->request_id ;
res_item->PeerId(item->PeerId()) ; // send back to the same guy
}
res_item->result.push_back(result.front()) ;
++req.result_count ; // increase hit number for this particular search request.
item_size += 8 /* size */ + result.front().hash.serial_size() + result.front().name.size() ;
result.pop_front() ;
if(item_size > RSTURTLE_MAX_SEARCH_RESPONSE_SIZE || result.empty() || req.result_count >= TURTLE_SEARCH_RESULT_MAX_HITS)
{
#ifdef P3TURTLE_DEBUG
std::cerr << " Sending back chunk of size " << item_size << ", for " << res_item->result.size() << " elements." << std::endl ;
#endif
sendItem(res_item) ;
res_item = NULL ;
}
}
} }
// if enough has been sent back already, do not sarch further // if enough has been sent back already, do not sarch further
@ -1055,7 +1021,7 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
if(it->second.origin == _own_id) if(it->second.origin == _own_id)
{ {
it->second.result_count += item->result.size() ; it->second.result_count += item->count() ;
returnSearchResult(item) ; // Yes, so send upward. returnSearchResult(item) ; // Yes, so send upward.
} }
else else
@ -1065,7 +1031,7 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
#endif #endif
// We update the total count forwarded back, and chop it to TURTLE_SEARCH_RESULT_MAX_HITS. // We update the total count forwarded back, and chop it to TURTLE_SEARCH_RESULT_MAX_HITS.
uint32_t n = item->result.size(); // not so good! uint32_t n = item->count(); // not so good!
if(it->second.result_count >= TURTLE_SEARCH_RESULT_MAX_HITS) if(it->second.result_count >= TURTLE_SEARCH_RESULT_MAX_HITS)
{ {
@ -1076,14 +1042,14 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
if(it->second.result_count + n > TURTLE_SEARCH_RESULT_MAX_HITS) if(it->second.result_count + n > TURTLE_SEARCH_RESULT_MAX_HITS)
{ {
for(uint32_t i=it->second.result_count + n; i>TURTLE_SEARCH_RESULT_MAX_HITS;--i) for(uint32_t i=it->second.result_count + n; i>TURTLE_SEARCH_RESULT_MAX_HITS;--i)
item->result.pop_back() ; item->pop() ;
it->second.result_count = TURTLE_SEARCH_RESULT_MAX_HITS ; it->second.result_count = TURTLE_SEARCH_RESULT_MAX_HITS ;
} }
else else
it->second.result_count += n ; it->second.result_count += n ;
RsTurtleSearchResultItem *fwd_item = new RsTurtleSearchResultItem(*item) ; // copy the item RsTurtleSearchResultItem *fwd_item = item->duplicate();
// Normally here, we should setup the forward adress, so that the owner's // Normally here, we should setup the forward adress, so that the owner's
// of the files found can be further reached by a tunnel. // of the files found can be further reached by a tunnel.
@ -1777,7 +1743,61 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
// ------------------------------ IO with libretroshare ----------------------------// // ------------------------------ IO with libretroshare ----------------------------//
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
// //
void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInfo>& result) const void RsTurtleFileSearchRequestItem::performLocalSearch(TurtleSearchRequestInfo &req, std::list<RsTurtleSearchResultItem*>& result) const
{
#ifdef P3TURTLE_DEBUG
std::cerr << "Performing rsFiles->search()" << std::endl ;
#endif
// now, search!
std::list<TurtleFileInfo> initialResults ;
search(initialResults) ;
#ifdef P3TURTLE_DEBUG
std::cerr << initialResults.size() << " matches found." << std::endl ;
#endif
result.clear() ;
RsTurtleFTSearchResultItem *res_item = NULL ;
uint32_t item_size = 0 ;
static const uint32_t RSTURTLE_MAX_SEARCH_RESPONSE_SIZE = 10000 ;
for(auto it(initialResults.begin());it!=initialResults.end();++it)
{
if(res_item == NULL)
{
res_item = new RsTurtleFTSearchResultItem ;
item_size = 0 ;
res_item->depth = 0 ;
res_item->request_id = request_id ;
res_item->PeerId(PeerId()) ; // send back to the same guy
result.push_back(res_item) ;
}
res_item->result.push_back(*it);
// Let's chop search results items into several chunks of finite size to avoid exceeding streamer's capacity.
//
++req.result_count ; // increase hit number for this particular search request.
item_size += 8 /* size */ + it->hash.serial_size() + it->name.size() ;
if(item_size > RSTURTLE_MAX_SEARCH_RESPONSE_SIZE || req.result_count >= TURTLE_SEARCH_RESULT_MAX_HITS)
{
#ifdef P3TURTLE_DEBUG
std::cerr << " Sending back chunk of size " << item_size << ", for " << res_item->result.size() << " elements." << std::endl ;
#endif
res_item = NULL ; // forces creation of a new item.
}
}
}
void RsTurtleGxsSearchRequestItem::performLocalSearch(TurtleSearchRequestInfo &req, std::list<RsTurtleSearchResultItem*>& result) const
{
std::cerr << "(EE) Missing code to perform actual GXS search" << std::endl;
}
void RsTurtleStringSearchRequestItem::search(std::list<TurtleFileInfo>& result) const
{ {
/* call to core */ /* call to core */
std::list<DirDetails> initialResults; std::list<DirDetails> initialResults;
@ -1816,7 +1836,7 @@ void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
result.push_back(i) ; result.push_back(i) ;
} }
} }
void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInfo>& result) const void RsTurtleRegExpSearchRequestItem::search(std::list<TurtleFileInfo>& result) const
{ {
/* call to core */ /* call to core */
std::list<DirDetails> initialResults; std::list<DirDetails> initialResults;
@ -1953,13 +1973,25 @@ void p3turtle::monitorTunnels(const RsFileHash& hash,RsTurtleClientService *clie
void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item) void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item)
{ {
// just cout for now, but it should be notified to the gui
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
std::cerr << " Returning result for search request " << HEX_PRINT(item->request_id) << " upwards." << std::endl ; std::cerr << " Returning result for search request " << HEX_PRINT(item->request_id) << " upwards." << std::endl ;
#endif #endif
RsServer::notify()->notifyTurtleSearchResult(item->request_id,item->result) ; RsTurtleFTSearchResultItem *ft_sr = dynamic_cast<RsTurtleFTSearchResultItem*>(item) ;
if(ft_sr != NULL)
{
RsServer::notify()->notifyTurtleSearchResult(ft_sr->request_id,ft_sr->result) ;
return ;
}
RsTurtleGxsSearchResultItem *gxs_sr = dynamic_cast<RsTurtleGxsSearchResultItem*>(item) ;
if(gxs_sr != NULL)
{
RsServer::notify()->notifyTurtleSearchResult(gxs_sr->request_id,gxs_sr->result) ;
return ;
}
} }
/// Warning: this function should never be called while the turtle mutex is locked. /// Warning: this function should never be called while the turtle mutex is locked.
@ -2103,7 +2135,7 @@ bool p3turtle::encryptData(const unsigned char *clear_data,uint32_t clear_data_s
TURTLE_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_TURTLE_INITIALIZATION_VECTOR_SIZE) << std::endl; TURTLE_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_TURTLE_INITIALIZATION_VECTOR_SIZE) << std::endl;
#endif #endif
uint32_t item_serialized_size = clear_data_size;//RsGenericSerializer().size(clear_item) ; uint32_t item_serialized_size = clear_data_size;//RsGenericSerializer().size(clear_item) ;
uint32_t total_data_size = ENCRYPTED_TURTLE_HEADER_SIZE + ENCRYPTED_TURTLE_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_TURTLE_EDATA_SIZE + item_serialized_size + ENCRYPTED_TURTLE_AUTHENTICATION_TAG_SIZE ; uint32_t total_data_size = ENCRYPTED_TURTLE_HEADER_SIZE + ENCRYPTED_TURTLE_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_TURTLE_EDATA_SIZE + item_serialized_size + ENCRYPTED_TURTLE_AUTHENTICATION_TAG_SIZE ;
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
@ -2124,7 +2156,7 @@ bool p3turtle::encryptData(const unsigned char *clear_data,uint32_t clear_data_s
edata[0] = 0xae ; edata[0] = 0xae ;
edata[1] = 0xad ; edata[1] = 0xad ;
edata[2] = ENCRYPTED_TURTLE_FORMAT_AEAD_CHACHA20_SHA256 ; // means AEAD_chacha20_sha256 edata[2] = ENCRYPTED_TURTLE_FORMAT_AEAD_CHACHA20_SHA256 ; // means AEAD_chacha20_sha256
edata[3] = 0x01 ; edata[3] = 0x01 ;
offset += ENCRYPTED_TURTLE_HEADER_SIZE; offset += ENCRYPTED_TURTLE_HEADER_SIZE;
@ -2141,7 +2173,7 @@ bool p3turtle::encryptData(const unsigned char *clear_data,uint32_t clear_data_s
offset += ENCRYPTED_TURTLE_EDATA_SIZE ; offset += ENCRYPTED_TURTLE_EDATA_SIZE ;
memcpy(&edata[offset],clear_data,clear_data_size); memcpy(&edata[offset],clear_data,clear_data_size);
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
TURTLE_DEBUG() << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl; TURTLE_DEBUG() << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl;

View File

@ -28,7 +28,9 @@ RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype) c
{ {
case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST : return new RsTurtleStringSearchRequestItem(); case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST : return new RsTurtleStringSearchRequestItem();
case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST : return new RsTurtleRegExpSearchRequestItem(); case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST : return new RsTurtleRegExpSearchRequestItem();
case RS_TURTLE_SUBTYPE_SEARCH_RESULT : return new RsTurtleSearchResultItem(); case RS_TURTLE_SUBTYPE_GXS_SEARCH_REQUEST : return new RsTurtleGxsSearchRequestItem();
case RS_TURTLE_SUBTYPE_FT_SEARCH_RESULT : return new RsTurtleFTSearchResultItem();
case RS_TURTLE_SUBTYPE_GXS_SEARCH_RESULT : return new RsTurtleGxsSearchResultItem();
case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : return new RsTurtleOpenTunnelItem(); case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : return new RsTurtleOpenTunnelItem();
case RS_TURTLE_SUBTYPE_TUNNEL_OK : return new RsTurtleTunnelOkItem(); case RS_TURTLE_SUBTYPE_TUNNEL_OK : return new RsTurtleTunnelOkItem();
case RS_TURTLE_SUBTYPE_GENERIC_DATA : return new RsTurtleGenericDataItem(); case RS_TURTLE_SUBTYPE_GENERIC_DATA : return new RsTurtleGenericDataItem();
@ -61,7 +63,13 @@ void RsTurtleRegExpSearchRequestItem::serial_process(RsGenericSerializer::Serial
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth,"depth") ; RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth,"depth") ;
RsTypeSerializer::serial_process(j,ctx,expr,"expr") ; RsTypeSerializer::serial_process(j,ctx,expr,"expr") ;
} }
void RsTurtleGxsSearchRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth,"depth") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,service_id,"service_id") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_VALUE,match_string,"match_string") ;
}
template<> uint32_t RsTypeSerializer::serial_size(const RsRegularExpression::LinearizedExpression& r) template<> uint32_t RsTypeSerializer::serial_size(const RsRegularExpression::LinearizedExpression& r)
{ {
uint32_t s = 0 ; uint32_t s = 0 ;
@ -140,13 +148,18 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsRegul
std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl; std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl;
} }
void RsTurtleSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) void RsTurtleFTSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
RsTypeSerializer::serial_process (j,ctx,result ,"result") ;
}
void RsTurtleGxsSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ; RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
RsTypeSerializer::serial_process (j,ctx,result ,"result") ; RsTypeSerializer::serial_process (j,ctx,result ,"result") ;
} }
template<> uint32_t RsTypeSerializer::serial_size(const TurtleFileInfo& i) template<> uint32_t RsTypeSerializer::serial_size(const TurtleFileInfo& i)
{ {
uint32_t s = 0 ; uint32_t s = 0 ;
@ -193,6 +206,52 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleF
std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl; std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl;
} }
template<> uint32_t RsTypeSerializer::serial_size(const TurtleGxsInfo& i)
{
uint32_t s = 0 ;
s += 2 ; // service_id
s += i.group_id.SIZE_IN_BYTES ;
s += GetTlvStringSize(i.name) ;
return s;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size,uint32_t& offset,TurtleGxsInfo& i)
{
uint32_t saved_offset = offset ;
bool ok = true ;
ok &= getRawUInt16(data, size, &offset, &i.service_id); // service_id
ok &= i.group_id.deserialise(data, size, offset); // group_id
ok &= GetTlvString(data, size, &offset, TLV_TYPE_STR_NAME, i.name); // group name
if(!ok)
offset = saved_offset ;
return ok;
}
template<> bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_t& offset,const TurtleGxsInfo& i)
{
uint32_t saved_offset = offset ;
bool ok = true ;
ok &= setRawUInt16(data, size, &offset, i.service_id); // service_id
ok &= i.group_id.serialise(data, size, offset); // group_id
ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_NAME, i.name); // group name
if(!ok)
offset = saved_offset ;
return ok;
}
template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleGxsInfo& i)
{
std::cerr << " [GXS Info ] " << n << " group_id=" << i.group_id << " service=" << std::hex << i.service_id << std::dec << ", name=" << i.name << std::endl;
}
void RsTurtleOpenTunnelItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) void RsTurtleOpenTunnelItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ; RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ;

View File

@ -23,6 +23,7 @@ const uint8_t RS_TURTLE_SUBTYPE_FILE_REQUEST = 0x07 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_DATA = 0x08 ; const uint8_t RS_TURTLE_SUBTYPE_FILE_DATA = 0x08 ;
const uint8_t RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST = 0x09 ; const uint8_t RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST = 0x09 ;
const uint8_t RS_TURTLE_SUBTYPE_GENERIC_DATA = 0x0a ; const uint8_t RS_TURTLE_SUBTYPE_GENERIC_DATA = 0x0a ;
const uint8_t RS_TURTLE_SUBTYPE_GXS_SEARCH_REQUEST = 0x0b ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP = 0x10 ; const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP = 0x10 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST = 0x11 ; const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST = 0x11 ;
const uint8_t RS_TURTLE_SUBTYPE_CHUNK_CRC = 0x14 ; const uint8_t RS_TURTLE_SUBTYPE_CHUNK_CRC = 0x14 ;
@ -32,6 +33,8 @@ const uint8_t RS_TURTLE_SUBTYPE_GXS_SEARCH_RESULT = 0x16 ;
// const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC = 0x12 ; // unused // const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC = 0x12 ; // unused
// const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST = 0x13 ; // const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST = 0x13 ;
class TurtleSearchRequestInfo ;
/***********************************************************************************/ /***********************************************************************************/
/* Basic Turtle Item Class */ /* Basic Turtle Item Class */
/***********************************************************************************/ /***********************************************************************************/
@ -47,63 +50,40 @@ class RsTurtleItem: public RsItem
/* Specific packets */ /* Specific packets */
/***********************************************************************************/ /***********************************************************************************/
class RsTurtleSearchResultItem: public RsTurtleItem // Class hierarchy is
{ //
public: // RsTurtleItem
RsTurtleSearchResultItem(uint8_t subtype) : RsTurtleItem(subtype), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT) ;} // |
// +---- RsTurtleSearchRequestItem
// | |
// | +---- RsTurtleFileSearchRequestItem
// | | |
// | | +---- RsTurtleFileSearchRequestItem
// | | |
// | | +---- RsTurtleStringSearchRequestItem
// | | |
// | | +---- RsTurtleReqExpSearchRequestItem
// | |
// | +---- RsTurtleGxsSearchRequestItem
// |
// +---- RsTurtleSearchResultItem
// |
// +---- RsTurtleFTSearchResultItem
// |
// +---- RsTurtleGxsSearchResultItem
//
TurtleSearchRequestId request_id ; // Randomly generated request id. class RsTurtleSearchResultItem ;
uint16_t depth ; // The depth of a search result is obfuscated in this way:
// If the actual depth is 1, this field will be 1.
// If the actual depth is > 1, this field is a larger arbitrary integer.
virtual void clear() =0;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)=0;
protected:
};
class RsTurtleFTSearchResultItem: public RsTurtleSearchResultItem
{
public:
RsTurtleFTSearchResultItem() : RsTurtleSearchResultItem(RS_TURTLE_SUBTYPE_FT_SEARCH_RESULT){}
TurtleSearchRequestId request_id ; // Randomly generated request id.
uint16_t depth ; // The depth of a search result is obfuscated in this way:
// If the actual depth is 1, this field will be 1.
// If the actual depth is > 1, this field is a larger arbitrary integer.
std::list<TurtleFileInfo> result ;
void clear() { result.clear() ; }
protected:
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
};
class RsTurtleGxsSearchResultItem: public RsTurtleSearchResultItem
{
public:
RsTurtleGxsSearchResultItem() : RsTurtleSearchResultItem(RS_TURTLE_SUBTYPE_GXS_SEARCH_RESULT){}
TurtleSearchRequestId request_id ; // Randomly generated request id.
uint16_t depth ; // The depth of a search result is obfuscated in this way:
// If the actual depth is 1, this field will be 1.
// If the actual depth is > 1, this field is a larger arbitrary integer.
std::list<TurtleGxsInfo> result ;
void clear() { result.clear() ; }
protected:
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
};
class RsTurtleSearchRequestItem: public RsTurtleItem class RsTurtleSearchRequestItem: public RsTurtleItem
{ {
public: public:
RsTurtleSearchRequestItem(uint32_t subtype) : RsTurtleItem(subtype), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_REQUEST) ;} RsTurtleSearchRequestItem(uint32_t subtype) : RsTurtleItem(subtype), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_REQUEST) ;}
virtual ~RsTurtleSearchRequestItem() {}
virtual RsTurtleSearchRequestItem *clone() const = 0 ; // used for cloning in routing methods virtual RsTurtleSearchRequestItem *clone() const = 0 ; // used for cloning in routing methods
virtual void performLocalSearch(std::list<TurtleFileInfo>&) const = 0 ; // abstracts the search method virtual void performLocalSearch(TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>&) const = 0 ; // abstracts the search method
virtual std::string GetKeywords() = 0; virtual std::string GetKeywords() = 0;
@ -111,28 +91,40 @@ class RsTurtleSearchRequestItem: public RsTurtleItem
uint16_t depth ; // Used for limiting search depth. uint16_t depth ; // Used for limiting search depth.
}; };
class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem class RsTurtleFileSearchRequestItem: public RsTurtleSearchRequestItem
{ {
public: public:
RsTurtleStringSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) {} RsTurtleFileSearchRequestItem(uint32_t subtype) : RsTurtleSearchRequestItem(subtype) {}
virtual ~RsTurtleFileSearchRequestItem() {}
virtual void performLocalSearch(TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>&) const ; // abstracts the search method
virtual void search(std::list<TurtleFileInfo> &) const =0;
};
class RsTurtleStringSearchRequestItem: public RsTurtleFileSearchRequestItem
{
public:
RsTurtleStringSearchRequestItem() : RsTurtleFileSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) {}
virtual ~RsTurtleStringSearchRequestItem() {}
std::string match_string ; // string to match std::string match_string ; // string to match
std::string GetKeywords() { return match_string; } std::string GetKeywords() { return match_string; }
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleStringSearchRequestItem(*this) ; } virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleStringSearchRequestItem(*this) ; }
virtual void performLocalSearch(std::list<TurtleFileInfo>&) const ;
void clear() { match_string.clear() ; } void clear() { match_string.clear() ; }
protected: protected:
virtual void search(std::list<TurtleFileInfo> &) const ;
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem class RsTurtleRegExpSearchRequestItem: public RsTurtleFileSearchRequestItem
{ {
public: public:
RsTurtleRegExpSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST) {} RsTurtleRegExpSearchRequestItem() : RsTurtleFileSearchRequestItem(RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST) {}
virtual ~RsTurtleRegExpSearchRequestItem() {}
RsRegularExpression::LinearizedExpression expr ; // Reg Exp in linearised mode RsRegularExpression::LinearizedExpression expr ; // Reg Exp in linearised mode
@ -145,13 +137,82 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
} }
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; } virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; }
virtual void performLocalSearch(std::list<TurtleFileInfo>&) const ;
void clear() { expr = RsRegularExpression::LinearizedExpression(); } void clear() { expr = RsRegularExpression::LinearizedExpression(); }
protected:
virtual void search(std::list<TurtleFileInfo> &) const ;
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
};
class RsTurtleGxsSearchRequestItem: public RsTurtleSearchRequestItem
{
public:
RsTurtleGxsSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_GXS_SEARCH_REQUEST) {}
virtual ~RsTurtleGxsSearchRequestItem() {}
virtual void performLocalSearch(TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>&) const ; // abstracts the search method
std::string match_string ; // string to match
uint16_t service_id ; // searvice to search
std::string GetKeywords() { return match_string; }
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleGxsSearchRequestItem(*this) ; }
void clear() { match_string.clear() ; }
protected: protected:
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleSearchResultItem: public RsTurtleItem
{
public:
RsTurtleSearchResultItem(uint8_t subtype) : RsTurtleItem(subtype), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT) ;}
TurtleSearchRequestId request_id ; // Randomly generated request id.
uint16_t depth ; // The depth of a search result is obfuscated in this way:
// If the actual depth is 1, this field will be 1.
// If the actual depth is > 1, this field is a larger arbitrary integer.
virtual void clear() =0;
virtual uint32_t count() const =0;
virtual void pop() =0;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)=0;
virtual RsTurtleSearchResultItem *duplicate() const =0;
};
class RsTurtleFTSearchResultItem: public RsTurtleSearchResultItem
{
public:
RsTurtleFTSearchResultItem() : RsTurtleSearchResultItem(RS_TURTLE_SUBTYPE_FT_SEARCH_RESULT){}
std::list<TurtleFileInfo> result ;
void clear() { result.clear() ; }
uint32_t count() const { return result.size() ; }
virtual void pop() { result.pop_back() ;}
virtual RsTurtleSearchResultItem *duplicate() const { return new RsTurtleFTSearchResultItem(*this) ; }
protected:
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
};
class RsTurtleGxsSearchResultItem: public RsTurtleSearchResultItem
{
public:
RsTurtleGxsSearchResultItem() : RsTurtleSearchResultItem(RS_TURTLE_SUBTYPE_GXS_SEARCH_RESULT){}
std::list<TurtleGxsInfo> result ;
void clear() { result.clear() ; }
uint32_t count() const { return result.size() ; }
virtual void pop() { result.pop_back() ;}
virtual RsTurtleSearchResultItem *duplicate() const { return new RsTurtleGxsSearchResultItem(*this) ; }
protected:
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
};
/***********************************************************************************/ /***********************************************************************************/
/* Turtle Tunnel Item classes */ /* Turtle Tunnel Item classes */
/***********************************************************************************/ /***********************************************************************************/

View File

@ -563,6 +563,11 @@ void NotifyQt::notifyChatCleared(const ChatId& chat_id)
emit chatCleared(chat_id); emit chatCleared(chat_id);
} }
void NotifyQt::notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleGxsInfo>& found_groups)
{
std::cerr << "(EE) missing code to handle GXS turtle search result." << std::endl;
}
void NotifyQt::notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files) void NotifyQt::notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files)
{ {
{ {

View File

@ -47,6 +47,7 @@ class NotifyQt: public QObject, public NotifyClient
virtual void notifyCustomState(const std::string& peer_id, const std::string& status_string); virtual void notifyCustomState(const std::string& peer_id, const std::string& status_string);
virtual void notifyHashingInfo(uint32_t type, const std::string& fileinfo); virtual void notifyHashingInfo(uint32_t type, const std::string& fileinfo);
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& found_files); virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& found_files);
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleGxsInfo>& found_groups);
virtual void notifyPeerHasNewAvatar(std::string peer_id) ; virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
virtual void notifyOwnAvatarChanged() ; virtual void notifyOwnAvatarChanged() ;
virtual void notifyChatLobbyEvent(uint64_t /* lobby id */, uint32_t /* event type */, const RsGxsId & /*nickname*/, const std::string& /* any string */) ; virtual void notifyChatLobbyEvent(uint64_t /* lobby id */, uint32_t /* event type */, const RsGxsId & /*nickname*/, const std::string& /* any string */) ;