mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-01 02:46:20 -05:00
fixed two-ways communication between client and server
This commit is contained in:
parent
aff7912f41
commit
25ddbe099d
@ -127,12 +127,8 @@ bool FsClient::sendItem(const std::string& address,uint16_t port,RsItem *item,st
|
|||||||
RsSerialiser *rss = new RsSerialiser(); // deleted by ~pqistreamer()
|
RsSerialiser *rss = new RsSerialiser(); // deleted by ~pqistreamer()
|
||||||
rss->addSerialType(fss);
|
rss->addSerialType(fss);
|
||||||
|
|
||||||
FsSerializer().serialise(item,data,&size);
|
// FsSerializer().serialise(item,data,&size);
|
||||||
write(CreateSocket,data,size); // shouldn't we use the pqistreamer in R/W mode instead?
|
// write(CreateSocket,data,size); // shouldn't we use the pqistreamer in R/W mode instead?
|
||||||
|
|
||||||
RsDbg() << "Item sent. Waiting for response..." ;
|
|
||||||
|
|
||||||
// Now attempt to read and deserialize anything that comes back from that connexion until it gets closed by the server.
|
|
||||||
|
|
||||||
FsBioInterface *bio = new FsBioInterface(CreateSocket); // deleted by ~pqistreamer()
|
FsBioInterface *bio = new FsBioInterface(CreateSocket); // deleted by ~pqistreamer()
|
||||||
|
|
||||||
@ -141,7 +137,10 @@ bool FsClient::sendItem(const std::string& address,uint16_t port,RsItem *item,st
|
|||||||
|
|
||||||
uint32_t ss;
|
uint32_t ss;
|
||||||
p.SendItem(item,ss);
|
p.SendItem(item,ss);
|
||||||
bool should_close = false;
|
|
||||||
|
RsDbg() << "Item sent. Waiting for response..." ;
|
||||||
|
|
||||||
|
// Now attempt to read and deserialize anything that comes back from that connexion until it gets closed by the server.
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
@ -157,28 +156,13 @@ bool FsClient::sendItem(const std::string& address,uint16_t port,RsItem *item,st
|
|||||||
std::cerr << "Got a response item: " << std::endl;
|
std::cerr << "Got a response item: " << std::endl;
|
||||||
std::cerr << *item << std::endl;
|
std::cerr << *item << std::endl;
|
||||||
|
|
||||||
should_close = true; // always close the socket after one packet
|
|
||||||
|
|
||||||
if(dynamic_cast<RsFriendServerStatusItem*>(item) != nullptr)
|
|
||||||
{
|
|
||||||
RsDbg() << "End of transmission. " ;
|
RsDbg() << "End of transmission. " ;
|
||||||
should_close = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bio->isactive()) // socket has probably closed
|
|
||||||
{
|
|
||||||
RsDbg() << "(client side) Socket has been closed by server.";
|
|
||||||
should_close =true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(should_close)
|
|
||||||
{
|
|
||||||
RsDbg() << " Stopping/killing pqistreamer" ;
|
RsDbg() << " Stopping/killing pqistreamer" ;
|
||||||
p.fullstop();
|
p.fullstop();
|
||||||
|
|
||||||
@ -187,7 +171,6 @@ bool FsClient::sendItem(const std::string& address,uint16_t port,RsItem *item,st
|
|||||||
CreateSocket=0;
|
CreateSocket=0;
|
||||||
|
|
||||||
RsDbg() << " Exiting loop." ;
|
RsDbg() << " Exiting loop." ;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,8 @@ void FriendServer::threadTick()
|
|||||||
|
|
||||||
void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *item)
|
void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *item)
|
||||||
{
|
{
|
||||||
|
// We always respond with exactly one item, be it an error item or a list of friends to connect to.
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RsDbg() << "Received a client publish item from " << item->PeerId() << ":";
|
RsDbg() << "Received a client publish item from " << item->PeerId() << ":";
|
||||||
@ -107,19 +109,6 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it
|
|||||||
mni->SendItem(status_item);
|
mni->SendItem(status_item);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close client connection from server side, to tell the client that nothing more is coming.
|
|
||||||
|
|
||||||
RsDbg() << "Sending end-of-stream item to " << item->PeerId() ;
|
|
||||||
|
|
||||||
RsFriendServerStatusItem *status_item = new RsFriendServerStatusItem;
|
|
||||||
status_item->status = RsFriendServerStatusItem::END_OF_TRANSMISSION;
|
|
||||||
status_item->PeerId(item->PeerId());
|
|
||||||
|
|
||||||
mni->SendItem(status_item);
|
|
||||||
|
|
||||||
RsDbg() << "Closing client connection." ;
|
|
||||||
mni->closeConnection(item->PeerId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, bool> FriendServer::computeListOfFriendInvites(uint32_t nb_reqs_invites, const RsPeerId &pid, const RsPgpFingerprint &fpr)
|
std::map<std::string, bool> FriendServer::computeListOfFriendInvites(uint32_t nb_reqs_invites, const RsPeerId &pid, const RsPgpFingerprint &fpr)
|
||||||
@ -332,7 +321,7 @@ void FriendServer::autoWash()
|
|||||||
|
|
||||||
std::list<RsPeerId> to_remove;
|
std::list<RsPeerId> to_remove;
|
||||||
|
|
||||||
for(std::map<RsPeerId,PeerInfo>::iterator it(mCurrentClientPeers.begin());it!=mCurrentClientPeers.end();)
|
for(std::map<RsPeerId,PeerInfo>::iterator it(mCurrentClientPeers.begin());it!=mCurrentClientPeers.end();++it)
|
||||||
if(it->second.last_connection_TS + MAXIMUM_PEER_INACTIVE_DELAY < now)
|
if(it->second.last_connection_TS + MAXIMUM_PEER_INACTIVE_DELAY < now)
|
||||||
{
|
{
|
||||||
RsDbg() << "Removing client peer " << it->first << " because it's inactive for more than " << MAXIMUM_PEER_INACTIVE_DELAY << " seconds." ;
|
RsDbg() << "Removing client peer " << it->first << " because it's inactive for more than " << MAXIMUM_PEER_INACTIVE_DELAY << " seconds." ;
|
||||||
|
@ -240,20 +240,22 @@ void FsNetworkInterface::locked_closeConnection(const RsPeerId& peer_id)
|
|||||||
|
|
||||||
if(!it->second.incoming_items.empty())
|
if(!it->second.incoming_items.empty())
|
||||||
{
|
{
|
||||||
RsErr() << " Trying to close an incoming connection with incoming items still pending! The items will be lost." << std::endl;
|
RsErr() << " Trying to close an incoming connection with incoming items still pending! The items will be lost:" << std::endl;
|
||||||
|
|
||||||
for(auto& item:it->second.incoming_items)
|
for(auto& item:it->second.incoming_items)
|
||||||
|
{
|
||||||
|
RsErr() << *item;
|
||||||
delete item;
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
it->second.incoming_items.clear();
|
it->second.incoming_items.clear();
|
||||||
}
|
}
|
||||||
// Close the socket and delete everything.
|
// Close the socket and delete everything.
|
||||||
|
|
||||||
|
close(it->second.socket);
|
||||||
it->second.pqi_thread->fullstop();
|
it->second.pqi_thread->fullstop();
|
||||||
it->second.bio->close();
|
it->second.bio->close();
|
||||||
|
|
||||||
close(it->second.socket);
|
|
||||||
|
|
||||||
delete it->second.pqi_thread;
|
delete it->second.pqi_thread;
|
||||||
|
|
||||||
mConnections.erase(it);
|
mConnections.erase(it);
|
||||||
|
Loading…
Reference in New Issue
Block a user