mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-26 07:11:08 -04:00
Expose more RsFiles via JSON API
FileInfo remove dead static members
This commit is contained in:
parent
4d30d4f32b
commit
afeb408f7a
2 changed files with 238 additions and 90 deletions
|
@ -192,8 +192,11 @@ public:
|
||||||
* This function returns an unspecified amount of bytes. Either as much data
|
* This function returns an unspecified amount of bytes. Either as much data
|
||||||
* as available or a sensible maximum. Expect a block size of around 1MiB.
|
* as available or a sensible maximum. Expect a block size of around 1MiB.
|
||||||
* To get more data, call this function repeatedly with different offsets.
|
* To get more data, call this function repeatedly with different offsets.
|
||||||
* jsonapi{development} note the missing @ the wrapper for this is written
|
*
|
||||||
* manually not autogenerated @see JsonApiServer.
|
* jsonapi{development}
|
||||||
|
* note the missing @ the wrapper for this is written manually not
|
||||||
|
* autogenerated @see JsonApiServer.
|
||||||
|
*
|
||||||
* @param[in] hash hash of the file. The file has to be available on this node
|
* @param[in] hash hash of the file. The file has to be available on this node
|
||||||
* or it has to be in downloading state.
|
* or it has to be in downloading state.
|
||||||
* @param[in] offset where the desired block starts
|
* @param[in] offset where the desired block starts
|
||||||
|
@ -240,13 +243,67 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool FileCancel(const RsFileHash& hash) = 0;
|
virtual bool FileCancel(const RsFileHash& hash) = 0;
|
||||||
|
|
||||||
virtual bool setDestinationDirectory(const RsFileHash& hash,const std::string& new_path) = 0;
|
/**
|
||||||
virtual bool setDestinationName(const RsFileHash& hash,const std::string& new_name) = 0;
|
* @brief Set destination directory for given file
|
||||||
virtual bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy) = 0;
|
* @jsonapi{development}
|
||||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
|
* @param[in] hash file identifier
|
||||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() = 0;
|
* @param[in] newPath
|
||||||
virtual uint32_t freeDiskSpaceLimit() const =0;
|
* @return false if some error occurred, true otherwise
|
||||||
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) =0;
|
*/
|
||||||
|
virtual bool setDestinationDirectory(
|
||||||
|
const RsFileHash& hash, const std::string& newPath ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set name for dowloaded file
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] hash file identifier
|
||||||
|
* @param[in] newName
|
||||||
|
* @return false if some error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool setDestinationName(
|
||||||
|
const RsFileHash& hash, const std::string& newName ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set chunk strategy for file, useful to set streaming mode to be
|
||||||
|
* able of see video or other media preview while it is still downloading
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] hash file identifier
|
||||||
|
* @param[in] newStrategy
|
||||||
|
* @return false if some error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool setChunkStrategy(
|
||||||
|
const RsFileHash& hash,
|
||||||
|
FileChunksInfo::ChunkStrategy newStrategy ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set default chunk strategy
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] strategy
|
||||||
|
*/
|
||||||
|
virtual void setDefaultChunkStrategy(
|
||||||
|
FileChunksInfo::ChunkStrategy strategy ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get default chunk strategy
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @return current default chunck strategy
|
||||||
|
*/
|
||||||
|
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get free disk space limit
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @return current current minimum free space on disk in MB
|
||||||
|
*/
|
||||||
|
virtual uint32_t freeDiskSpaceLimit() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set minimum free disk space limit
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] minimumFreeMB minimum free space in MB
|
||||||
|
*/
|
||||||
|
virtual void setFreeDiskSpaceLimit(uint32_t minimumFreeMB) = 0;
|
||||||
|
|
||||||
virtual bool FileControl(const RsFileHash& hash, uint32_t flags) = 0;
|
virtual bool FileControl(const RsFileHash& hash, uint32_t flags) = 0;
|
||||||
virtual bool FileClearCompleted() = 0;
|
virtual bool FileClearCompleted() = 0;
|
||||||
virtual void setDefaultEncryptionPolicy(uint32_t policy)=0; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
|
virtual void setDefaultEncryptionPolicy(uint32_t policy)=0; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
|
||||||
|
@ -267,21 +324,56 @@ public:
|
||||||
virtual bool changeDownloadSpeed(const RsFileHash& hash, int speed) = 0;
|
virtual bool changeDownloadSpeed(const RsFileHash& hash, int speed) = 0;
|
||||||
virtual bool getDownloadSpeed(const RsFileHash& hash, int & speed) = 0;
|
virtual bool getDownloadSpeed(const RsFileHash& hash, int & speed) = 0;
|
||||||
virtual bool clearDownload(const RsFileHash& hash) = 0;
|
virtual bool clearDownload(const RsFileHash& hash) = 0;
|
||||||
// virtual void getDwlDetails(std::list<DwlDetails> & details) = 0;
|
|
||||||
|
|
||||||
/***
|
/**
|
||||||
* Download / Upload Details.
|
* @brief Get incoming files list
|
||||||
***/
|
* @jsonapi{development}
|
||||||
virtual void FileDownloads(std::list<RsFileHash> &hashs) = 0;
|
* @param[out] hashs storage for files identifiers list
|
||||||
virtual bool FileUploads(std::list<RsFileHash> &hashs) = 0;
|
*/
|
||||||
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) = 0;
|
virtual void FileDownloads(std::list<RsFileHash>& hashs) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get outgoing files list
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[out] hashs storage for files identifiers list
|
||||||
|
* @return false if some error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool FileUploads(std::list<RsFileHash>& hashs) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get file details
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] hash file identifier
|
||||||
|
* @param[in] hintflags filtering hint (RS_FILE_HINTS_EXTRA|...|RS_FILE_HINTS_LOCAL)
|
||||||
|
* @param[out] info storage for file information
|
||||||
|
* @return true if file found, false otherwise
|
||||||
|
*/
|
||||||
|
virtual bool FileDetails(
|
||||||
|
const RsFileHash &hash, FileSearchFlags hintflags, FileInfo& info ) = 0;
|
||||||
|
|
||||||
virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) =0;
|
virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) =0;
|
||||||
|
|
||||||
/// Gives chunk details about the downloaded file with given hash.
|
/**
|
||||||
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) = 0 ;
|
* @brief Get chunk details about the downloaded file with given hash.
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] hash file identifier
|
||||||
|
* @param[out] info storage for file information
|
||||||
|
* @return true if file found, false otherwise
|
||||||
|
*/
|
||||||
|
virtual bool FileDownloadChunksDetails(
|
||||||
|
const RsFileHash& hash, FileChunksInfo& info) = 0;
|
||||||
|
|
||||||
/// details about the upload with given hash
|
/**
|
||||||
virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) = 0 ;
|
* @brief Get details about the upload with given hash
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] hash file identifier
|
||||||
|
* @param[in] peer_id peer identifier
|
||||||
|
* @param[out] map storage for chunk info
|
||||||
|
* @return true if file found, false otherwise
|
||||||
|
*/
|
||||||
|
virtual bool FileUploadChunksDetails(
|
||||||
|
const RsFileHash& hash, const RsPeerId& peer_id,
|
||||||
|
CompressedChunkMap& map ) = 0;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Extra List Access
|
* Extra List Access
|
||||||
|
|
|
@ -65,15 +65,25 @@ const uint32_t RS_CONFIG_DIRECTORY = 0x0002 ;
|
||||||
const uint32_t RS_PGP_DIRECTORY = 0x0003 ;
|
const uint32_t RS_PGP_DIRECTORY = 0x0003 ;
|
||||||
const uint32_t RS_DIRECTORY_COUNT = 0x0004 ;
|
const uint32_t RS_DIRECTORY_COUNT = 0x0004 ;
|
||||||
|
|
||||||
class TransferInfo
|
struct TransferInfo : RsSerializable
|
||||||
{
|
{
|
||||||
public:
|
/**** Need Some of these Fields ****/
|
||||||
/**** Need Some of these Fields ****/
|
RsPeerId peerId;
|
||||||
RsPeerId peerId;
|
std::string name; /* if has alternative name? */
|
||||||
std::string name; /* if has alternative name? */
|
double tfRate; /* kbytes */
|
||||||
double tfRate; /* kbytes */
|
int status; /* FT_STATE_... */
|
||||||
int status; /* FT_STATE_... */
|
uint64_t transfered ; // used when no chunkmap data is available
|
||||||
uint64_t transfered ; // used when no chunkmap data is available
|
|
||||||
|
/// @see RsSerializable
|
||||||
|
void serial_process(RsGenericSerializer::SerializeJob j,
|
||||||
|
RsGenericSerializer::SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RS_SERIAL_PROCESS(peerId);
|
||||||
|
RS_SERIAL_PROCESS(name);
|
||||||
|
RS_SERIAL_PROCESS(tfRate);
|
||||||
|
RS_SERIAL_PROCESS(status);
|
||||||
|
RS_SERIAL_PROCESS(transfered);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum QueueMove { QUEUE_TOP = 0x00,
|
enum QueueMove { QUEUE_TOP = 0x00,
|
||||||
|
@ -82,9 +92,11 @@ enum QueueMove { QUEUE_TOP = 0x00,
|
||||||
QUEUE_BOTTOM = 0x03
|
QUEUE_BOTTOM = 0x03
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DwlSpeed { SPEED_LOW = 0x00,
|
enum DwlSpeed : uint8_t
|
||||||
SPEED_NORMAL = 0x01,
|
{
|
||||||
SPEED_HIGH = 0x02
|
SPEED_LOW = 0x00,
|
||||||
|
SPEED_NORMAL = 0x01,
|
||||||
|
SPEED_HIGH = 0x02
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -171,54 +183,76 @@ const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK ( DIR_FLAGS_ANONYMOUS_DOW
|
||||||
const FileStorageFlags DIR_FLAGS_LOCAL ( 0x1000 );
|
const FileStorageFlags DIR_FLAGS_LOCAL ( 0x1000 );
|
||||||
const FileStorageFlags DIR_FLAGS_REMOTE ( 0x2000 );
|
const FileStorageFlags DIR_FLAGS_REMOTE ( 0x2000 );
|
||||||
|
|
||||||
class FileInfo
|
struct FileInfo : RsSerializable
|
||||||
{
|
{
|
||||||
/* old BaseInfo Entries */
|
FileInfo():
|
||||||
public:
|
mId(0), searchId(0), size(0), avail(0), rank(0), age(0),
|
||||||
|
queue_position(0), transfered(0), tfRate(0), downloadStatus(0),
|
||||||
|
priority(SPEED_NORMAL), lastTS(0) {}
|
||||||
|
|
||||||
FileInfo() : mId(0), searchId(0), size(0), avail(0), rank(0), age(0), queue_position(0),
|
/// Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file.
|
||||||
transfered(0), tfRate(0), downloadStatus(0), priority(SPEED_NORMAL), lastTS(0){}
|
FileStorageFlags storage_permission_flags;
|
||||||
// RsCertId id; /* key for matching everything */
|
|
||||||
|
|
||||||
FileStorageFlags storage_permission_flags; // Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file.
|
/// various flags from RS_FILE_HINTS_*
|
||||||
TransferRequestFlags transfer_info_flags ; // various flags from RS_FILE_HINTS_*
|
TransferRequestFlags transfer_info_flags;
|
||||||
|
|
||||||
/* allow this to be tweaked by the GUI Model */
|
/** allow this to be tweaked by the GUI Model
|
||||||
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
|
* (GUI) Model Id -> unique number
|
||||||
|
*/
|
||||||
|
mutable unsigned int mId;
|
||||||
|
|
||||||
/* Old FileInfo Entries */
|
|
||||||
public:
|
|
||||||
|
|
||||||
static const int kRsFiStatusNone = 0;
|
/// 0 if none
|
||||||
static const int kRsFiStatusStall = 1;
|
int searchId;
|
||||||
static const int kRsFiStatusProgress = 2;
|
|
||||||
static const int kRsFiStatusDone = 2;
|
|
||||||
|
|
||||||
/* FileInfo(); */
|
std::string path;
|
||||||
|
std::string fname;
|
||||||
|
RsFileHash hash;
|
||||||
|
std::string ext;
|
||||||
|
|
||||||
int searchId; /* 0 if none */
|
uint64_t size;
|
||||||
std::string path;
|
uint64_t avail; /// how much we have
|
||||||
std::string fname;
|
|
||||||
RsFileHash hash;
|
|
||||||
std::string ext;
|
|
||||||
|
|
||||||
uint64_t size;
|
double rank;
|
||||||
uint64_t avail; /* how much we have */
|
int age;
|
||||||
|
uint32_t queue_position;
|
||||||
|
|
||||||
double rank;
|
/* Transfer Stuff */
|
||||||
int age;
|
uint64_t transfered;
|
||||||
uint32_t queue_position ;
|
double tfRate; /// in kbytes
|
||||||
|
uint32_t downloadStatus; /// FT_STATE_DOWNLOADING & co. See rstypes.h
|
||||||
|
std::vector<TransferInfo> peers;
|
||||||
|
|
||||||
/* Transfer Stuff */
|
DwlSpeed priority;
|
||||||
uint64_t transfered;
|
time_t lastTS;
|
||||||
double tfRate; /* in kbytes */
|
|
||||||
uint32_t downloadStatus; // FT_STATE_DOWNLOADING & co. See rstypes.h
|
|
||||||
std::vector<TransferInfo> peers;
|
|
||||||
|
|
||||||
DwlSpeed priority ;
|
std::list<RsNodeGroupId> parent_groups;
|
||||||
time_t lastTS;
|
|
||||||
|
|
||||||
std::list<RsNodeGroupId> parent_groups ;
|
/// @see RsSerializable
|
||||||
|
void serial_process(RsGenericSerializer::SerializeJob j,
|
||||||
|
RsGenericSerializer::SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RS_SERIAL_PROCESS(storage_permission_flags);
|
||||||
|
RS_SERIAL_PROCESS(transfer_info_flags);
|
||||||
|
RS_SERIAL_PROCESS(mId);
|
||||||
|
RS_SERIAL_PROCESS(searchId);
|
||||||
|
RS_SERIAL_PROCESS(path);
|
||||||
|
RS_SERIAL_PROCESS(fname);
|
||||||
|
RS_SERIAL_PROCESS(hash);
|
||||||
|
RS_SERIAL_PROCESS(ext);
|
||||||
|
RS_SERIAL_PROCESS(size);
|
||||||
|
RS_SERIAL_PROCESS(avail);
|
||||||
|
RS_SERIAL_PROCESS(rank);
|
||||||
|
RS_SERIAL_PROCESS(age);
|
||||||
|
RS_SERIAL_PROCESS(queue_position);
|
||||||
|
RS_SERIAL_PROCESS(transfered);
|
||||||
|
RS_SERIAL_PROCESS(tfRate);
|
||||||
|
RS_SERIAL_PROCESS(downloadStatus);
|
||||||
|
RS_SERIAL_PROCESS(peers);
|
||||||
|
RS_SERIAL_PROCESS(priority);
|
||||||
|
RS_SERIAL_PROCESS(lastTS);
|
||||||
|
RS_SERIAL_PROCESS(parent_groups);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const FileInfo& info);
|
std::ostream &operator<<(std::ostream &out, const FileInfo& info);
|
||||||
|
@ -268,36 +302,58 @@ class FileDetail
|
||||||
|
|
||||||
class CompressedChunkMap ;
|
class CompressedChunkMap ;
|
||||||
|
|
||||||
class FileChunksInfo
|
struct FileChunksInfo : RsSerializable
|
||||||
{
|
{
|
||||||
public:
|
enum ChunkState : uint8_t
|
||||||
enum ChunkState { CHUNK_CHECKING=3, CHUNK_DONE=2, CHUNK_ACTIVE=1, CHUNK_OUTSTANDING=0 } ;
|
{
|
||||||
enum ChunkStrategy { CHUNK_STRATEGY_STREAMING, CHUNK_STRATEGY_RANDOM, CHUNK_STRATEGY_PROGRESSIVE } ;
|
CHUNK_OUTSTANDING = 0,
|
||||||
|
CHUNK_ACTIVE = 1,
|
||||||
|
CHUNK_DONE = 2,
|
||||||
|
CHUNK_CHECKING = 3
|
||||||
|
};
|
||||||
|
|
||||||
struct SliceInfo
|
enum ChunkStrategy : uint8_t
|
||||||
{
|
{
|
||||||
uint32_t start ;
|
CHUNK_STRATEGY_STREAMING,
|
||||||
uint32_t size ;
|
CHUNK_STRATEGY_RANDOM,
|
||||||
RsPeerId peer_id ;
|
CHUNK_STRATEGY_PROGRESSIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t file_size ; // real size of the file
|
struct SliceInfo
|
||||||
uint32_t chunk_size ; // size of chunks
|
{
|
||||||
uint32_t strategy ;
|
uint32_t start;
|
||||||
|
uint32_t size;
|
||||||
|
RsPeerId peer_id;
|
||||||
|
};
|
||||||
|
|
||||||
// dl state of chunks. Only the last chunk may have size < chunk_size
|
uint64_t file_size; /// real size of the file
|
||||||
std::vector<ChunkState> chunks ;
|
uint32_t chunk_size; /// size of chunks
|
||||||
|
ChunkStrategy strategy;
|
||||||
|
|
||||||
// For each source peer, gives the compressed bit map of have/don't have sate
|
/// dl state of chunks. Only the last chunk may have size < chunk_size
|
||||||
std::map<RsPeerId, CompressedChunkMap> compressed_peer_availability_maps ;
|
std::vector<ChunkState> chunks;
|
||||||
|
|
||||||
// For each chunk (by chunk number), gives the completion of the chunk.
|
/// For each source peer, gives the compressed bit map of have/don't have sate
|
||||||
//
|
std::map<RsPeerId, CompressedChunkMap> compressed_peer_availability_maps;
|
||||||
std::vector<std::pair<uint32_t,uint32_t> > active_chunks ;
|
|
||||||
|
|
||||||
// The list of pending requests, chunk per chunk (by chunk id)
|
/// For each chunk (by chunk number), gives the completion of the chunk.
|
||||||
//
|
std::vector<std::pair<uint32_t,uint32_t> > active_chunks;
|
||||||
std::map<uint32_t, std::vector<SliceInfo> > pending_slices ;
|
|
||||||
|
/// The list of pending requests, chunk per chunk (by chunk id)
|
||||||
|
std::map<uint32_t, std::vector<SliceInfo> > pending_slices;
|
||||||
|
|
||||||
|
/// @see RsSerializable
|
||||||
|
void serial_process(RsGenericSerializer::SerializeJob j,
|
||||||
|
RsGenericSerializer::SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RS_SERIAL_PROCESS(file_size);
|
||||||
|
RS_SERIAL_PROCESS(chunk_size);
|
||||||
|
RS_SERIAL_PROCESS(strategy);
|
||||||
|
RS_SERIAL_PROCESS(chunks);
|
||||||
|
RS_SERIAL_PROCESS(compressed_peer_availability_maps);
|
||||||
|
RS_SERIAL_PROCESS(active_chunks);
|
||||||
|
//RS_SERIAL_PROCESS(pending_slices);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompressedChunkMap : public RsSerializable
|
class CompressedChunkMap : public RsSerializable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue