PageRenderTime 49ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llxfermanager.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 222 lines | 119 code | 35 blank | 68 comment | 0 complexity | 39abd0a82f1a70ae0b7a436955d1d2ac MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llxfermanager.h
  3. * @brief definition of LLXferManager class for a keeping track of
  4. * multiple xfers
  5. *
  6. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #ifndef LL_LLXFERMANAGER_H
  28. #define LL_LLXFERMANAGER_H
  29. /**
  30. * this manager keeps both a send list and a receive list; anything with a
  31. * LLXferManager can send and receive files via messages
  32. */
  33. //Forward declaration to avoid circular dependencies
  34. class LLXfer;
  35. class LLVFS;
  36. #include "llxfer.h"
  37. #include "message.h"
  38. #include "llassetstorage.h"
  39. #include "lldir.h"
  40. #include "lllinkedqueue.h"
  41. #include "llthrottle.h"
  42. class LLHostStatus
  43. {
  44. public:
  45. LLHost mHost;
  46. S32 mNumActive;
  47. S32 mNumPending;
  48. LLHostStatus() {mNumActive = 0; mNumPending = 0;};
  49. virtual ~LLHostStatus(){};
  50. };
  51. // Class stores ack information, to be put on list so we can throttle xfer rate.
  52. class LLXferAckInfo
  53. {
  54. public:
  55. LLXferAckInfo(U32 dummy = 0)
  56. {
  57. mID = 0;
  58. mPacketNum = -1;
  59. }
  60. U64 mID;
  61. S32 mPacketNum;
  62. LLHost mRemoteHost;
  63. };
  64. class LLXferManager
  65. {
  66. private:
  67. LLVFS *mVFS;
  68. protected:
  69. S32 mMaxOutgoingXfersPerCircuit;
  70. S32 mMaxIncomingXfers;
  71. BOOL mUseAckThrottling; // Use ack throttling to cap file xfer bandwidth
  72. LLLinkedQueue<LLXferAckInfo> mXferAckQueue;
  73. LLThrottle mAckThrottle;
  74. public:
  75. // This enumeration is useful in the requestFile() to specify if
  76. // an xfer must happen asap.
  77. enum
  78. {
  79. LOW_PRIORITY = FALSE,
  80. HIGH_PRIORITY = TRUE,
  81. };
  82. LLXfer *mSendList;
  83. LLXfer *mReceiveList;
  84. typedef std::list<LLHostStatus*> status_list_t;
  85. status_list_t mOutgoingHosts;
  86. private:
  87. protected:
  88. // implementation methods
  89. virtual void startPendingDownloads();
  90. virtual void addToList(LLXfer* xferp, LLXfer*& head, BOOL is_priority);
  91. std::multiset<std::string> mExpectedTransfers; // files that are authorized to transfer out
  92. std::multiset<std::string> mExpectedRequests; // files that are authorized to be downloaded on top of
  93. public:
  94. LLXferManager(LLVFS *vfs);
  95. virtual ~LLXferManager();
  96. virtual void init(LLVFS *vfs);
  97. virtual void cleanup();
  98. void setUseAckThrottling(const BOOL use);
  99. void setAckThrottleBPS(const F32 bps);
  100. // list management routines
  101. virtual LLXfer *findXfer(U64 id, LLXfer *list_head);
  102. virtual void removeXfer (LLXfer *delp, LLXfer **list_head);
  103. virtual U32 numActiveListEntries(LLXfer *list_head);
  104. virtual S32 numActiveXfers(const LLHost &host);
  105. virtual S32 numPendingXfers(const LLHost &host);
  106. virtual void changeNumActiveXfers(const LLHost &host, S32 delta);
  107. virtual void setMaxOutgoingXfersPerCircuit (S32 max_num);
  108. virtual void setMaxIncomingXfers(S32 max_num);
  109. virtual void updateHostStatus();
  110. virtual void printHostStatus();
  111. // general utility routines
  112. virtual void registerCallbacks(LLMessageSystem *mesgsys);
  113. virtual U64 getNextID ();
  114. virtual S32 encodePacketNum(S32 packet_num, BOOL is_eof);
  115. virtual S32 decodePacketNum(S32 packet_num);
  116. virtual BOOL isLastPacket(S32 packet_num);
  117. virtual U64 registerXfer(const void *datap, const S32 length);
  118. // file requesting routines
  119. // .. to file
  120. virtual void requestFile(const std::string& local_filename,
  121. const std::string& remote_filename,
  122. ELLPath remote_path,
  123. const LLHost& remote_host,
  124. BOOL delete_remote_on_completion,
  125. void (*callback)(void**,S32,LLExtStat), void** user_data,
  126. BOOL is_priority = FALSE,
  127. BOOL use_big_packets = FALSE);
  128. // .. to memory
  129. virtual void requestFile(const std::string& remote_filename,
  130. ELLPath remote_path,
  131. const LLHost &remote_host,
  132. BOOL delete_remote_on_completion,
  133. void (*callback)(void*, S32, void**, S32, LLExtStat),
  134. void** user_data,
  135. BOOL is_priority = FALSE);
  136. // vfile requesting
  137. // .. to vfile
  138. virtual void requestVFile(const LLUUID &local_id, const LLUUID& remote_id,
  139. LLAssetType::EType type, LLVFS* vfs,
  140. const LLHost& remote_host,
  141. void (*callback)(void**,S32,LLExtStat), void** user_data,
  142. BOOL is_priority = FALSE);
  143. /**
  144. When arbitrary files are requested to be transfered (by giving a dir of LL_PATH_NONE)
  145. they must be "expected", but having something pre-authorize them. This pair of functions
  146. maintains a pre-authorized list. The first function adds something to the list, the second
  147. checks if is authorized, removing it if so. In this way, a file is only authorized for
  148. a single use.
  149. */
  150. virtual void expectFileForTransfer(const std::string& filename);
  151. virtual bool validateFileForTransfer(const std::string& filename);
  152. /**
  153. Same idea, but for the viewer about to call InitiateDownload to track what it requested.
  154. */
  155. virtual void expectFileForRequest(const std::string& filename);
  156. virtual bool validateFileForRequest(const std::string& filename);
  157. /*
  158. // xfer request (may be memory or file)
  159. // .. to file
  160. virtual void requestXfer(const char *local_filename, U64 xfer_id,
  161. BOOL delete_remote_on_completion,
  162. const LLHost &remote_host, void (*callback)(void **,S32),void **user_data);
  163. // .. to memory
  164. virtual void requestXfer(U64 xfer_id,
  165. const LLHost &remote_host,
  166. BOOL delete_remote_on_completion,
  167. void (*callback)(void *, S32, void **, S32),void **user_data);
  168. */
  169. virtual void processReceiveData (LLMessageSystem *mesgsys, void **user_data);
  170. virtual void sendConfirmPacket (LLMessageSystem *mesgsys, U64 id, S32 packetnum, const LLHost &remote_host);
  171. // file sending routines
  172. virtual void processFileRequest (LLMessageSystem *mesgsys, void **user_data);
  173. virtual void processConfirmation (LLMessageSystem *mesgsys, void **user_data);
  174. virtual void retransmitUnackedPackets ();
  175. // error handling
  176. virtual void processAbort (LLMessageSystem *mesgsys, void **user_data);
  177. };
  178. extern LLXferManager* gXferManager;
  179. // initialization and garbage collection
  180. void start_xfer_manager(LLVFS *vfs);
  181. void cleanup_xfer_manager();
  182. // message system callbacks
  183. void process_confirm_packet (LLMessageSystem *mesgsys, void **user_data);
  184. void process_request_xfer (LLMessageSystem *mesgsys, void **user_data);
  185. void continue_file_receive(LLMessageSystem *mesgsys, void **user_data);
  186. void process_abort_xfer (LLMessageSystem *mesgsys, void **user_data);
  187. #endif