mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
Added in Libresapi: StateTokens to FileSharingHandler
This commit is contained in:
parent
55385d7602
commit
92df847ece
@ -21,8 +21,10 @@
|
||||
namespace resource_api
|
||||
{
|
||||
|
||||
FileSharingHandler::FileSharingHandler(StateTokenServer *sts, RsFiles *files):
|
||||
mStateTokenServer(sts), mRsFiles(files)
|
||||
FileSharingHandler::FileSharingHandler(StateTokenServer *sts, RsFiles *files,
|
||||
RsNotify* notify):
|
||||
mStateTokenServer(sts), mRsFiles(files), mNotify(notify),
|
||||
mMtx("FileSharingHandler Mtx")
|
||||
{
|
||||
addResourceHandler("*", this, &FileSharingHandler::handleWildcard);
|
||||
addResourceHandler("force_check", this, &FileSharingHandler::handleForceCheck);
|
||||
@ -40,7 +42,30 @@ FileSharingHandler::FileSharingHandler(StateTokenServer *sts, RsFiles *files):
|
||||
|
||||
addResourceHandler("download", this, &FileSharingHandler::handleDownload);
|
||||
|
||||
mStateToken = mStateTokenServer->getNewToken();
|
||||
mLocalDirStateToken = mStateTokenServer->getNewToken();
|
||||
mRemoteDirStateToken = mStateTokenServer->getNewToken();
|
||||
mNotify->registerNotifyClient(this);
|
||||
}
|
||||
|
||||
FileSharingHandler::~FileSharingHandler()
|
||||
{
|
||||
mNotify->unregisterNotifyClient(this);
|
||||
}
|
||||
|
||||
void FileSharingHandler::notifyListChange(int list, int /* type */)
|
||||
{
|
||||
if(list == NOTIFY_LIST_DIRLIST_LOCAL)
|
||||
{
|
||||
RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
|
||||
mStateTokenServer->discardToken(mLocalDirStateToken);
|
||||
mLocalDirStateToken = mStateTokenServer->getNewToken();
|
||||
}
|
||||
else if(list == NOTIFY_LIST_DIRLIST_FRIENDS)
|
||||
{
|
||||
RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
|
||||
mStateTokenServer->discardToken(mRemoteDirStateToken);
|
||||
mRemoteDirStateToken = mStateTokenServer->getNewToken();
|
||||
}
|
||||
}
|
||||
|
||||
void FileSharingHandler::handleWildcard(Request & /*req*/, Response & /*resp*/)
|
||||
@ -104,6 +129,7 @@ void FileSharingHandler::handleGetSharedDir(Request& req, Response& resp)
|
||||
<< makeKeyValue("name", dirDetails.name)
|
||||
<< makeKeyValue("path", dirDetails.path)
|
||||
<< makeKeyValue("hash", dirDetails.hash.toStdString())
|
||||
<< makeKeyValue("peer_id", dirDetails.id.toStdString())
|
||||
<< makeKeyValue("parent_reference", *reinterpret_cast<int*>(&dirDetails.parent))
|
||||
<< makeKeyValue("reference", *reinterpret_cast<int*>(&dirDetails.ref))
|
||||
<< makeKeyValue("count", static_cast<int>(dirDetails.count))
|
||||
@ -140,6 +166,8 @@ void FileSharingHandler::handleGetSharedDir(Request& req, Response& resp)
|
||||
<< makeKeyValueReference("contain_folders", contain_folders);
|
||||
}
|
||||
}
|
||||
|
||||
resp.mStateToken = mLocalDirStateToken;
|
||||
}
|
||||
|
||||
void FileSharingHandler::handleSetSharedDir(Request& req, Response& resp)
|
||||
@ -231,10 +259,16 @@ void FileSharingHandler::handleGetDirectoryParent(Request& req, Response& resp)
|
||||
|
||||
FileSearchFlags flags;
|
||||
if(remote)
|
||||
{
|
||||
flags |= RS_FILE_HINTS_REMOTE;
|
||||
resp.mStateToken = mRemoteDirStateToken;
|
||||
}
|
||||
|
||||
if(local)
|
||||
{
|
||||
flags |= RS_FILE_HINTS_LOCAL;
|
||||
resp.mStateToken = mLocalDirStateToken;
|
||||
}
|
||||
|
||||
DirDetails dirDetails;
|
||||
mRsFiles->RequestDirDetails(ref, dirDetails, flags);
|
||||
@ -282,6 +316,7 @@ void FileSharingHandler::handleGetDirectoryParent(Request& req, Response& resp)
|
||||
<< makeKeyValue("name", dirDetails.name)
|
||||
<< makeKeyValue("path", dirDetails.path)
|
||||
<< makeKeyValue("hash", dirDetails.hash.toStdString())
|
||||
<< makeKeyValue("peer_id", dirDetails.id.toStdString())
|
||||
<< makeKeyValue("parent_reference", *reinterpret_cast<int*>(&dirDetails.parent))
|
||||
<< makeKeyValue("reference", *reinterpret_cast<int*>(&dirDetails.ref))
|
||||
<< makeKeyValue("count", static_cast<int>(dirDetails.count))
|
||||
@ -334,10 +369,16 @@ void FileSharingHandler::handleGetDirectoryChilds(Request& req, Response& resp)
|
||||
|
||||
FileSearchFlags flags;
|
||||
if(remote)
|
||||
{
|
||||
flags |= RS_FILE_HINTS_REMOTE;
|
||||
resp.mStateToken = mRemoteDirStateToken;
|
||||
}
|
||||
|
||||
if(local)
|
||||
{
|
||||
flags |= RS_FILE_HINTS_LOCAL;
|
||||
resp.mStateToken = mLocalDirStateToken;
|
||||
}
|
||||
|
||||
DirDetails dirDetails;
|
||||
mRsFiles->RequestDirDetails(ref, dirDetails, flags);
|
||||
@ -385,6 +426,7 @@ void FileSharingHandler::handleGetDirectoryChilds(Request& req, Response& resp)
|
||||
<< makeKeyValue("name", dirDetails.name)
|
||||
<< makeKeyValue("path", dirDetails.path)
|
||||
<< makeKeyValue("hash", dirDetails.hash.toStdString())
|
||||
<< makeKeyValue("peer_id", dirDetails.id.toStdString())
|
||||
<< makeKeyValue("parent_reference", *reinterpret_cast<int*>(&dirDetails.parent))
|
||||
<< makeKeyValue("reference", *reinterpret_cast<int*>(&dirDetails.ref))
|
||||
<< makeKeyValue("count", static_cast<int>(dirDetails.count))
|
||||
|
@ -22,14 +22,21 @@
|
||||
#include "StateTokenServer.h"
|
||||
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rsnotify.h>
|
||||
#include <util/rsthreads.h>
|
||||
|
||||
namespace resource_api
|
||||
{
|
||||
|
||||
class FileSharingHandler: public ResourceRouter
|
||||
class FileSharingHandler: public ResourceRouter, NotifyClient
|
||||
{
|
||||
public:
|
||||
FileSharingHandler(StateTokenServer* sts, RsFiles* files);
|
||||
FileSharingHandler(StateTokenServer* sts, RsFiles* files, RsNotify* notify);
|
||||
~FileSharingHandler();
|
||||
|
||||
// from NotifyClient
|
||||
// note: this may get called from foreign threads
|
||||
virtual void notifyListChange(int list, int type);
|
||||
|
||||
private:
|
||||
void handleWildcard(Request& req, Response& resp);
|
||||
@ -48,10 +55,13 @@ private:
|
||||
|
||||
void handleDownload(Request& req, Response& resp);
|
||||
|
||||
StateToken mStateToken;
|
||||
StateToken mLocalDirStateToken;
|
||||
StateToken mRemoteDirStateToken;
|
||||
StateTokenServer* mStateTokenServer;
|
||||
RsMutex mMtx;
|
||||
|
||||
RsFiles* mRsFiles;
|
||||
RsNotify* mNotify;
|
||||
};
|
||||
|
||||
} // namespace resource_api
|
||||
|
Loading…
Reference in New Issue
Block a user