lltransfermanager.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  1. /**
  2. * @file lltransfermanager.cpp
  3. * @brief Improved transfer mechanism for moving data through the
  4. * message system.
  5. *
  6. * $LicenseInfo:firstyear=2004&license=viewergpl$
  7. *
  8. * Copyright (c) 2004-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "linden_common.h"
  34. #include "lltransfermanager.h"
  35. #include "lldatapacker.h"
  36. #include "llthrottle.h"
  37. #include "lltransfersourcefile.h"
  38. #include "lltransfersourceasset.h"
  39. #include "lltransfertargetfile.h"
  40. #include "lltransfertargetvfile.h"
  41. #include "llmessage.h"
  42. constexpr S32 MAX_PACKET_DATA_SIZE = 2048;
  43. constexpr S32 MAX_PARAMS_SIZE = 1024;
  44. LLTransferManager gTransferManager;
  45. LLTransferSource::stype_scfunc_map LLTransferSource::sSourceCreateMap;
  46. //
  47. // LLTransferManager implementation
  48. //
  49. LLTransferManager::LLTransferManager()
  50. : mValid(false)
  51. {
  52. for (S32 i = 0; i < LLTTT_NUM_TYPES; ++i)
  53. {
  54. mTransferBitsIn[i] = 0;
  55. mTransferBitsOut[i] = 0;
  56. }
  57. }
  58. LLTransferManager::~LLTransferManager()
  59. {
  60. if (mValid)
  61. {
  62. llwarns << "LLTransferManager should have been cleaned up by message system shutdown process"
  63. << llendl;
  64. cleanup();
  65. }
  66. }
  67. void LLTransferManager::init()
  68. {
  69. if (mValid)
  70. {
  71. llerrs << "Double initializing LLTransferManager !" << llendl;
  72. }
  73. mValid = true;
  74. // Register message system handlers
  75. LLMessageSystem* msg = gMessageSystemp;
  76. msg->setHandlerFunc("TransferRequest", processTransferRequest, NULL);
  77. msg->setHandlerFunc("TransferInfo", processTransferInfo, NULL);
  78. msg->setHandlerFunc("TransferPacket", processTransferPacket, NULL);
  79. msg->setHandlerFunc("TransferAbort", processTransferAbort, NULL);
  80. }
  81. void LLTransferManager::cleanup()
  82. {
  83. mValid = false;
  84. for (host_tc_map::iterator iter = mTransferConnections.begin(),
  85. end = mTransferConnections.end();
  86. iter != end; ++iter)
  87. {
  88. delete iter->second;
  89. }
  90. mTransferConnections.clear();
  91. }
  92. void LLTransferManager::updateTransfers()
  93. {
  94. host_tc_map::iterator iter = mTransferConnections.begin();
  95. while (iter != mTransferConnections.end())
  96. {
  97. host_tc_map::iterator cur = iter++;
  98. cur->second->updateTransfers();
  99. }
  100. }
  101. void LLTransferManager::cleanupConnection(const LLHost& host)
  102. {
  103. host_tc_map::iterator iter = mTransferConnections.find(host);
  104. if (iter == mTransferConnections.end())
  105. {
  106. // This can happen legitimately if we've never done a transfer, and
  107. // we're cleaning up a circuit.
  108. return;
  109. }
  110. LLTransferConnection* connp = iter->second;
  111. delete connp;
  112. mTransferConnections.erase(iter);
  113. }
  114. LLTransferConnection* LLTransferManager::getTransferConnection(const LLHost& host)
  115. {
  116. host_tc_map::iterator iter;
  117. iter = mTransferConnections.find(host);
  118. if (iter == mTransferConnections.end())
  119. {
  120. mTransferConnections[host] = new LLTransferConnection(host);
  121. return mTransferConnections[host];
  122. }
  123. return iter->second;
  124. }
  125. LLTransferSourceChannel* LLTransferManager::getSourceChannel(const LLHost& host,
  126. LLTransferChannelType type)
  127. {
  128. LLTransferConnection* tcp = getTransferConnection(host);
  129. return tcp ? tcp->getSourceChannel(type) : NULL;
  130. }
  131. LLTransferTargetChannel* LLTransferManager::getTargetChannel(const LLHost& host,
  132. LLTransferChannelType type)
  133. {
  134. LLTransferConnection* tcp = getTransferConnection(host);
  135. return tcp ? tcp->getTargetChannel(type) : NULL;
  136. }
  137. LLTransferSource* LLTransferManager::findTransferSource(const LLUUID& transfer_id)
  138. {
  139. // This linear traversal could screw us later if we do lots of searches for
  140. // sources. However, this ONLY happens right now in asset transfer
  141. // callbacks, so this should be relatively quick.
  142. LLTransferConnection* tcp;
  143. LLTransferSourceChannel* scp;
  144. LLTransferSource* sourcep;
  145. for (host_tc_map::iterator iter = mTransferConnections.begin(),
  146. end = mTransferConnections.end();
  147. iter != end; ++iter)
  148. {
  149. tcp = iter->second;
  150. for (LLTransferConnection::tsc_iter
  151. sc_iter = tcp->mTransferSourceChannels.begin(),
  152. sc_end = tcp->mTransferSourceChannels.end();
  153. sc_iter != sc_end; ++sc_iter)
  154. {
  155. scp = *sc_iter;
  156. if (scp)
  157. {
  158. sourcep = scp->findTransferSource(transfer_id);
  159. if (sourcep)
  160. {
  161. return sourcep;
  162. }
  163. }
  164. }
  165. }
  166. return NULL;
  167. }
  168. //
  169. // Message handlers
  170. //
  171. //static
  172. void LLTransferManager::processTransferRequest(LLMessageSystem* msgp, void**)
  173. {
  174. LLUUID transfer_id;
  175. LLTransferSourceType source_type;
  176. LLTransferChannelType channel_type;
  177. F32 priority;
  178. msgp->getUUID("TransferInfo", "TransferID", transfer_id);
  179. msgp->getS32("TransferInfo", "SourceType", (S32&)source_type);
  180. msgp->getS32("TransferInfo", "ChannelType", (S32&)channel_type);
  181. msgp->getF32("TransferInfo", "Priority", priority);
  182. LLTransferSourceChannel* tscp = gTransferManager.getSourceChannel(msgp->getSender(),
  183. channel_type);
  184. if (!tscp)
  185. {
  186. llwarns << "Source channel not found" << llendl;
  187. return;
  188. }
  189. if (tscp->findTransferSource(transfer_id))
  190. {
  191. llwarns << "Duplicate request for transfer " << transfer_id
  192. << ", aborting!" << llendl;
  193. return;
  194. }
  195. S32 size = msgp->getSize("TransferInfo", "Params");
  196. if (size < 0)
  197. {
  198. llwarns << "Bad TransferInfo block. Aborted." << llendl;
  199. return;
  200. }
  201. if (size > MAX_PARAMS_SIZE)
  202. {
  203. llwarns << "Params too big. Aborted." << llendl;
  204. return;
  205. }
  206. LL_DEBUGS("Messaging") << "Initiating transfer. Id: " << transfer_id
  207. << " - Source type: " << source_type
  208. << " - Channel type:" << channel_type
  209. << " - Priority:" << priority << LL_ENDL;
  210. LLTransferSource* tsp = LLTransferSource::createSource(source_type,
  211. transfer_id,
  212. priority);
  213. if (!tsp)
  214. {
  215. llwarns << "Couldn't create transfer source !" << llendl;
  216. return;
  217. }
  218. U8 tmp[MAX_PARAMS_SIZE];
  219. msgp->getBinaryData("TransferInfo", "Params", tmp, size);
  220. LLDataPackerBinaryBuffer dpb(tmp, MAX_PARAMS_SIZE);
  221. bool unpack_ok = tsp->unpackParams(dpb);
  222. if (!unpack_ok)
  223. {
  224. // This should only happen if the data is corrupt or incorrectly
  225. // packed.
  226. // *NOTE: We may want to call abortTransfer().
  227. llwarns << "Bad parameters !" << llendl;
  228. delete tsp;
  229. return;
  230. }
  231. tscp->addTransferSource(tsp);
  232. tsp->initTransfer();
  233. }
  234. //static
  235. void LLTransferManager::processTransferInfo(LLMessageSystem* msgp, void**)
  236. {
  237. //llinfos << "LLTransferManager::processTransferInfo" << llendl;
  238. LLUUID transfer_id;
  239. LLTransferTargetType target_type;
  240. LLTransferChannelType channel_type;
  241. LLTSCode status;
  242. S32 size;
  243. msgp->getUUID("TransferInfo", "TransferID", transfer_id);
  244. msgp->getS32("TransferInfo", "TargetType", (S32&)target_type);
  245. msgp->getS32("TransferInfo", "ChannelType", (S32&)channel_type);
  246. msgp->getS32("TransferInfo", "Status", (S32&)status);
  247. msgp->getS32("TransferInfo", "Size", size);
  248. LL_DEBUGS("Messaging") << "Processing info for transfer. Id: "
  249. << transfer_id << " - Target type:" << target_type
  250. << " - Channel type:" << channel_type << LL_ENDL;
  251. LLTransferTargetChannel* ttcp = gTransferManager.getTargetChannel(msgp->getSender(),
  252. channel_type);
  253. if (!ttcp)
  254. {
  255. llwarns << "Target channel not found" << llendl;
  256. // Should send a message to abort the transfer.
  257. return;
  258. }
  259. LLTransferTarget* ttp = ttcp->findTransferTarget(transfer_id);
  260. if (!ttp)
  261. {
  262. llwarns << "TransferInfo for unknown transfer ! Not able to handle this yet !"
  263. << llendl;
  264. // This could happen if we're doing a push transfer, although to avoid
  265. // confusion, maybe it should be a different message.
  266. return;
  267. }
  268. if (status != LLTS_OK)
  269. {
  270. llwarns << transfer_id << ": Non-ok status, cleaning up" << llendl;
  271. ttp->completionCallback(status);
  272. // Clean up the transfer.
  273. ttcp->deleteTransfer(ttp);
  274. return;
  275. }
  276. // Unpack the params
  277. S32 params_size = msgp->getSize("TransferInfo", "Params");
  278. if (params_size < 0)
  279. {
  280. llwarns << "Bad TransferInfo/Params. Aborted." << llendl;
  281. return;
  282. }
  283. if (params_size > MAX_PARAMS_SIZE)
  284. {
  285. llwarns << "TransferInfo/Params too big. Aborted." << llendl;
  286. return;
  287. }
  288. else if (params_size > 0)
  289. {
  290. U8 tmp[MAX_PARAMS_SIZE];
  291. msgp->getBinaryData("TransferInfo", "Params", tmp, params_size);
  292. LLDataPackerBinaryBuffer dpb(tmp, MAX_PARAMS_SIZE);
  293. if (!ttp->unpackParams(dpb))
  294. {
  295. // This should only happen if the data is corrupt or
  296. // incorrectly packed.
  297. llwarns << "Bad params." << llendl;
  298. ttp->abortTransfer();
  299. ttcp->deleteTransfer(ttp);
  300. return;
  301. }
  302. }
  303. LL_DEBUGS("Messaging") << "Receiving " << transfer_id << ", size " << size
  304. << " bytes" << LL_ENDL;
  305. ttp->setSize(size);
  306. ttp->setGotInfo(true);
  307. // OK, at this point we to handle any delayed transfer packets (which could
  308. // happen if this packet was lost)
  309. // This is a lame cut and paste of code down below. If we change the logic
  310. // down there, we HAVE to change the logic up here.
  311. while (true)
  312. {
  313. S32 packet_id = 0;
  314. U8 tmp_data[MAX_PACKET_DATA_SIZE];
  315. // See if we've got any delayed packets
  316. packet_id = ttp->getNextPacketID();
  317. if (ttp->mDelayedPacketMap.find(packet_id) != ttp->mDelayedPacketMap.end())
  318. {
  319. // Perhaps this stuff should be inside a method in LLTransferPacket?
  320. // I'm too lazy to do it now, though.
  321. LL_DEBUGS("Messaging") << "Playing back delayed packet " << packet_id
  322. << LL_ENDL;
  323. LLTransferPacket* packetp = ttp->mDelayedPacketMap[packet_id];
  324. // This is somewhat inefficient, but avoids us having to duplicate
  325. // code between the off-the-wire and delayed paths.
  326. packet_id = packetp->mPacketID;
  327. size = packetp->mSize;
  328. if (size)
  329. {
  330. if (packetp->mDatap && size < (S32)sizeof(tmp_data))
  331. {
  332. memcpy(tmp_data, packetp->mDatap, size);
  333. }
  334. }
  335. status = packetp->mStatus;
  336. ttp->mDelayedPacketMap.erase(packet_id);
  337. delete packetp;
  338. }
  339. else
  340. {
  341. // No matching delayed packet, we're done.
  342. break;
  343. }
  344. LLTSCode ret_code = ttp->dataCallback(packet_id, tmp_data, size);
  345. if (ret_code == LLTS_OK)
  346. {
  347. ttp->setLastPacketID(packet_id);
  348. }
  349. if (status != LLTS_OK)
  350. {
  351. if (status != LLTS_DONE)
  352. {
  353. llwarns << "Error in playback !" << llendl;
  354. }
  355. else
  356. {
  357. llinfos << "Replay finished for " << transfer_id << llendl;
  358. }
  359. // This transfer is done, either via error or not.
  360. ttp->completionCallback(status);
  361. ttcp->deleteTransfer(ttp);
  362. return;
  363. }
  364. }
  365. }
  366. //static
  367. void LLTransferManager::processTransferPacket(LLMessageSystem* msgp, void**)
  368. {
  369. LLUUID transfer_id;
  370. LLTransferChannelType channel_type;
  371. S32 packet_id;
  372. LLTSCode status;
  373. S32 size;
  374. msgp->getUUID("TransferData", "TransferID", transfer_id);
  375. msgp->getS32("TransferData", "ChannelType", (S32&)channel_type);
  376. msgp->getS32("TransferData", "Packet", packet_id);
  377. msgp->getS32("TransferData", "Status", (S32&)status);
  378. // Find the transfer associated with this packet.
  379. //llinfos << transfer_id << ":" << channel_type << llendl;
  380. LLTransferTargetChannel* ttcp =
  381. gTransferManager.getTargetChannel(msgp->getSender(), channel_type);
  382. if (!ttcp)
  383. {
  384. llwarns << "Target channel not found" << llendl;
  385. return;
  386. }
  387. LLTransferTarget* ttp = ttcp->findTransferTarget(transfer_id);
  388. if (!ttp)
  389. {
  390. llwarns_once << "Did not find matching transfer for " << transfer_id
  391. << " processing packet from " << msgp->getSender()
  392. << llendl;
  393. return;
  394. }
  395. size = msgp->getSize("TransferData", "Data");
  396. S32 msg_bytes = 0;
  397. if (msgp->getReceiveCompressedSize())
  398. {
  399. msg_bytes = msgp->getReceiveCompressedSize();
  400. }
  401. else
  402. {
  403. msg_bytes = msgp->getReceiveSize();
  404. }
  405. gTransferManager.addTransferBitsIn(ttcp->mChannelType, msg_bytes * 8);
  406. if (size < 0 || size > MAX_PACKET_DATA_SIZE)
  407. {
  408. llwarns << "Invalid transfer packet size " << size << llendl;
  409. return;
  410. }
  411. U8 tmp_data[MAX_PACKET_DATA_SIZE];
  412. if (size > 0)
  413. {
  414. // Only pull the data out if the size is > 0
  415. msgp->getBinaryData("TransferData", "Data", tmp_data, size);
  416. }
  417. if (!ttp->gotInfo() || ttp->getNextPacketID() != packet_id)
  418. {
  419. // Put this on a list of packets to be delivered later.
  420. if (!ttp->addDelayedPacket(packet_id, status, tmp_data, size))
  421. {
  422. // Whoops - failed to add a delayed packet for some reason.
  423. llwarns << "Too many delayed packets processing transfer "
  424. << transfer_id << " from " << msgp->getSender() << llendl;
  425. ttp->abortTransfer();
  426. ttcp->deleteTransfer(ttp);
  427. return;
  428. }
  429. #if LL_DEBUG // Spammy!
  430. constexpr S32 LL_TRANSFER_WARN_GAP = 10;
  431. if (!ttp->gotInfo())
  432. {
  433. llwarns << "Got data packet before information in transfer "
  434. << transfer_id << " from " << msgp->getSender()
  435. << ", got " << packet_id << llendl;
  436. }
  437. else if (packet_id - ttp->getNextPacketID() > LL_TRANSFER_WARN_GAP)
  438. {
  439. llwarns << "Out of order packet in transfer " << transfer_id
  440. << " from " << msgp->getSender() << ", got " << packet_id
  441. << " expecting " << ttp->getNextPacketID() << llendl;
  442. }
  443. #endif
  444. return;
  445. }
  446. // Loop through this until we're done with all delayed packets
  447. // NOTE: THERE IS A CUT AND PASTE OF THIS CODE IN THE TRANSFERINFO HANDLER
  448. // SO WE CAN PLAY BACK DELAYED PACKETS THERE !
  449. bool done = false;
  450. while (!done)
  451. {
  452. LLTSCode ret_code = ttp->dataCallback(packet_id, tmp_data, size);
  453. if (ret_code == LLTS_OK)
  454. {
  455. ttp->setLastPacketID(packet_id);
  456. }
  457. if (status != LLTS_OK)
  458. {
  459. if (status != LLTS_DONE)
  460. {
  461. llwarns << "Error in transfer!" << llendl;
  462. }
  463. else
  464. {
  465. LL_DEBUGS("Messaging") << "Transfer done for " << transfer_id
  466. << LL_ENDL;
  467. }
  468. // This transfer is done, either via error or not.
  469. ttp->completionCallback(status);
  470. ttcp->deleteTransfer(ttp);
  471. return;
  472. }
  473. // See if we've got any delayed packets
  474. packet_id = ttp->getNextPacketID();
  475. if (ttp->mDelayedPacketMap.find(packet_id) != ttp->mDelayedPacketMap.end())
  476. {
  477. // Perhaps this stuff should be inside a method in LLTransferPacket?
  478. // I'm too lazy to do it now, though.
  479. LL_DEBUGS("Messaging") << "Playing back delayed packet "
  480. << packet_id << LL_ENDL;
  481. LLTransferPacket* packetp = ttp->mDelayedPacketMap[packet_id];
  482. // This is somewhat inefficient, but avoids us having to duplicate
  483. // code between the off-the-wire and delayed paths.
  484. packet_id = packetp->mPacketID;
  485. size = packetp->mSize;
  486. if (size)
  487. {
  488. if (packetp->mDatap && size < (S32)sizeof(tmp_data))
  489. {
  490. memcpy(tmp_data, packetp->mDatap, size);
  491. }
  492. }
  493. status = packetp->mStatus;
  494. ttp->mDelayedPacketMap.erase(packet_id);
  495. delete packetp;
  496. }
  497. else
  498. {
  499. // No matching delayed packet, abort it.
  500. done = true;
  501. }
  502. }
  503. }
  504. //static
  505. void LLTransferManager::processTransferAbort(LLMessageSystem* msgp, void**)
  506. {
  507. LLUUID transfer_id;
  508. msgp->getUUID("TransferInfo", "TransferID", transfer_id);
  509. LLTransferChannelType channel_type;
  510. msgp->getS32("TransferInfo", "ChannelType", (S32&)channel_type);
  511. // See if it is a target that we're trying to abort. Find the transfer
  512. // associated with this packet.
  513. LLTransferTargetChannel* ttcp =
  514. gTransferManager.getTargetChannel(msgp->getSender(), channel_type);
  515. if (ttcp)
  516. {
  517. LLTransferTarget* ttp = ttcp->findTransferTarget(transfer_id);
  518. if (ttp)
  519. {
  520. ttp->abortTransfer();
  521. ttcp->deleteTransfer(ttp);
  522. return;
  523. }
  524. }
  525. // Hmm, not a target. Maybe it is a source.
  526. LLTransferSourceChannel* tscp =
  527. gTransferManager.getSourceChannel(msgp->getSender(), channel_type);
  528. if (tscp)
  529. {
  530. LLTransferSource* tsp = tscp->findTransferSource(transfer_id);
  531. if (tsp)
  532. {
  533. tsp->abortTransfer();
  534. tscp->deleteTransfer(tsp);
  535. return;
  536. }
  537. }
  538. llwarns << "Couldn't find transfer " << transfer_id << " to abort !"
  539. << llendl;
  540. }
  541. //static
  542. void LLTransferManager::reliablePacketCallback(void** user_data, S32 result)
  543. {
  544. LLUUID* transfer_idp = (LLUUID*)user_data;
  545. if (result && transfer_idp)
  546. {
  547. LLTransferSource* tsp =
  548. gTransferManager.findTransferSource(*transfer_idp);
  549. if (tsp)
  550. {
  551. llwarns << "Aborting reliable transfer " << *transfer_idp
  552. << " due to failed reliable resends !" << llendl;
  553. LLTransferSourceChannel* tscp = tsp->mChannelp;
  554. tsp->abortTransfer();
  555. tscp->deleteTransfer(tsp);
  556. }
  557. else
  558. {
  559. llwarns << "Aborting reliable transfer " << *transfer_idp
  560. << " but can't find the LLTransferSource object" << llendl;
  561. }
  562. }
  563. delete transfer_idp;
  564. }
  565. //
  566. // LLTransferConnection implementation
  567. //
  568. LLTransferConnection::LLTransferConnection(const LLHost& host)
  569. {
  570. mHost = host;
  571. }
  572. LLTransferConnection::~LLTransferConnection()
  573. {
  574. tsc_iter itersc;
  575. for (tsc_iter itersc = mTransferSourceChannels.begin(),
  576. endsc = mTransferSourceChannels.end();
  577. itersc != endsc; ++itersc)
  578. {
  579. delete *itersc;
  580. }
  581. mTransferSourceChannels.clear();
  582. for (ttc_iter itertc = mTransferTargetChannels.begin(),
  583. endtc = mTransferTargetChannels.end();
  584. itertc != endtc; ++itertc)
  585. {
  586. delete *itertc;
  587. }
  588. mTransferTargetChannels.clear();
  589. }
  590. void LLTransferConnection::updateTransfers()
  591. {
  592. // Do stuff for source transfers (basically, send data out).
  593. tsc_iter iter, cur;
  594. iter = mTransferSourceChannels.begin();
  595. while (iter != mTransferSourceChannels.end())
  596. {
  597. cur = iter++;
  598. (*cur)->updateTransfers();
  599. }
  600. // Do stuff for target transfers. Primarily, we should be aborting
  601. // transfers that are irredeemably broken (large packet gaps that do not
  602. // appear to be getting filled in, most likely). Probably should NOT be
  603. // doing timeouts for other things, as new priority scheme means that a
  604. // high priority transfer COULD block a transfer for a long time.
  605. }
  606. LLTransferSourceChannel* LLTransferConnection::getSourceChannel(LLTransferChannelType channel_type)
  607. {
  608. for (tsc_iter iter = mTransferSourceChannels.begin(),
  609. end = mTransferSourceChannels.end();
  610. iter != end; ++iter)
  611. {
  612. if ((*iter)->getChannelType() == channel_type)
  613. {
  614. return *iter;
  615. }
  616. }
  617. LLTransferSourceChannel* tscp = new LLTransferSourceChannel(channel_type,
  618. mHost);
  619. mTransferSourceChannels.push_back(tscp);
  620. return tscp;
  621. }
  622. LLTransferTargetChannel* LLTransferConnection::getTargetChannel(LLTransferChannelType channel_type)
  623. {
  624. for (ttc_iter iter = mTransferTargetChannels.begin(),
  625. end = mTransferTargetChannels.end();
  626. iter != end; ++iter)
  627. {
  628. if ((*iter)->getChannelType() == channel_type)
  629. {
  630. return *iter;
  631. }
  632. }
  633. LLTransferTargetChannel* ttcp = new LLTransferTargetChannel(channel_type,
  634. mHost);
  635. mTransferTargetChannels.push_back(ttcp);
  636. return ttcp;
  637. }
  638. //
  639. // LLTransferSourceChannel implementation
  640. //
  641. constexpr S32 DEFAULT_PACKET_SIZE = 1000;
  642. LLTransferSourceChannel::LLTransferSourceChannel(LLTransferChannelType channel_type,
  643. const LLHost& host)
  644. : mChannelType(channel_type),
  645. mHost(host),
  646. mTransferSources(LLTransferSource::sSetPriority, LLTransferSource::sGetPriority),
  647. mThrottleID(TC_ASSET)
  648. {
  649. }
  650. LLTransferSourceChannel::~LLTransferSourceChannel()
  651. {
  652. for (LLPriQueueMap<LLTransferSource*>::pqm_iter
  653. iter = mTransferSources.mMap.begin(),
  654. end = mTransferSources.mMap.end(); iter != end; ++iter)
  655. {
  656. // Just kill off all of the transfers
  657. if (iter->second)
  658. {
  659. iter->second->abortTransfer();
  660. delete iter->second;
  661. }
  662. }
  663. mTransferSources.mMap.clear();
  664. }
  665. void LLTransferSourceChannel::updatePriority(LLTransferSource* tsp,
  666. F32 priority)
  667. {
  668. mTransferSources.reprioritize(priority, tsp);
  669. }
  670. void LLTransferSourceChannel::updateTransfers()
  671. {
  672. // Actually, this should do the following:
  673. // - Decide if we can actually send data.
  674. // - If so, update priorities so we know who gets to send it.
  675. // - Send data from the sources, while updating until we've sent our
  676. // throttle allocation.
  677. LLMessageSystem* msg = gMessageSystemp;
  678. LLCircuitData* cdp = msg->mCircuitInfo.findCircuit(getHost());
  679. if (!cdp)
  680. {
  681. return;
  682. }
  683. if (cdp->isBlocked())
  684. {
  685. // *NOTE: We need to make sure that the throttle bits available gets
  686. // reset.
  687. // We DO NOT want to send any packets if they're blocked, they'll just
  688. // end up piling up on the other end.
  689. LL_DEBUGS("Messaging") << "Blocking transfers due to blocked circuit for "
  690. << getHost() << LL_ENDL;
  691. return;
  692. }
  693. const S32 throttle_id = mThrottleID;
  694. LLThrottleGroup& tg = cdp->getThrottleGroup();
  695. if (tg.checkOverflow(throttle_id, 0.f))
  696. {
  697. return;
  698. }
  699. LLPriQueueMap<LLTransferSource*>::pqm_iter iter, next;
  700. bool done = false;
  701. for (iter = mTransferSources.mMap.begin();
  702. iter != mTransferSources.mMap.end() && !done; )
  703. {
  704. next = iter;
  705. ++next;
  706. LLTransferSource* tsp = iter->second;
  707. U8* datap = NULL;
  708. S32 data_size = 0;
  709. bool delete_data = false;
  710. S32 packet_id = 0;
  711. S32 sent_bytes = 0;
  712. LLTSCode status = LLTS_OK;
  713. // Get the packetID for the next packet that we're transferring.
  714. packet_id = tsp->getNextPacketID();
  715. status = tsp->dataCallback(packet_id, DEFAULT_PACKET_SIZE, &datap,
  716. data_size, delete_data);
  717. if (status == LLTS_SKIP)
  718. {
  719. // We do not have any data, but we're not done, just go on. This
  720. // will presumably be used for streaming or async transfers that
  721. // are stalled waiting for data from another source.
  722. iter = next;
  723. continue;
  724. }
  725. LLUUID* cb_uuid = new LLUUID(tsp->getID());
  726. LLUUID transaction_id = tsp->getID();
  727. // Send the data now, even if it's an error.
  728. // The status code will tell the other end what to do.
  729. msg->newMessage("TransferPacket");
  730. msg->nextBlock("TransferData");
  731. msg->addUUID("TransferID", tsp->getID());
  732. msg->addS32("ChannelType", getChannelType());
  733. msg->addS32("Packet", packet_id); // *HACK: need a REAL packet id
  734. msg->addS32("Status", status);
  735. msg->addBinaryData("Data", datap, data_size);
  736. sent_bytes = msg->getCurrentSendTotal();
  737. msg->sendReliable(getHost(), LL_DEFAULT_RELIABLE_RETRIES, true, 0.f,
  738. LLTransferManager::reliablePacketCallback,
  739. (void**)cb_uuid);
  740. // Do bookkeeping for the throttle
  741. done = tg.throttleOverflow(throttle_id, sent_bytes * 8.f);
  742. gTransferManager.addTransferBitsOut(mChannelType, sent_bytes * 8);
  743. // Clean up our temporary data.
  744. if (delete_data)
  745. {
  746. delete[] datap;
  747. datap = NULL;
  748. }
  749. if (findTransferSource(transaction_id) == NULL)
  750. {
  751. // Warning ! In the case of an aborted transfer, the sendReliable
  752. // call above calls AbortTransfer which in turn calls
  753. // deleteTransfer which means that somewhere way down the chain our
  754. // current iter can get invalidated resulting in an infrequent sim
  755. // crash. This check gets us to a valid transfer source in this
  756. // event.
  757. iter = next;
  758. continue;
  759. }
  760. // Update the packet counter
  761. tsp->setLastPacketID(packet_id);
  762. switch (status)
  763. {
  764. case LLTS_OK:
  765. // We're OK, don't need to do anything. Keep sending data.
  766. break;
  767. case LLTS_ERROR:
  768. llwarns << "Error in transfer dataCallback!" << llendl;
  769. // fall through
  770. case LLTS_DONE:
  771. // We need to clean up this transfer source.
  772. LL_DEBUGS("Messaging") << tsp->getID() << " done" << LL_ENDL;
  773. tsp->completionCallback(status);
  774. delete tsp;
  775. mTransferSources.mMap.erase(iter);
  776. iter = next;
  777. break;
  778. default:
  779. llerrs << "Unknown transfer error code!" << llendl;
  780. }
  781. // At this point, we should do priority adjustment (since some
  782. // transfers like streaming transfers will adjust priority based on how
  783. // much they've sent and time, but I'm not going to bother yet. - djs.
  784. }
  785. }
  786. void LLTransferSourceChannel::addTransferSource(LLTransferSource* sourcep)
  787. {
  788. sourcep->mChannelp = this;
  789. mTransferSources.push(sourcep->getPriority(), sourcep);
  790. }
  791. LLTransferSource* LLTransferSourceChannel::findTransferSource(const LLUUID& transfer_id)
  792. {
  793. for (LLPriQueueMap<LLTransferSource*>::pqm_iter
  794. iter = mTransferSources.mMap.begin(),
  795. end = mTransferSources.mMap.end(); iter != end; ++iter)
  796. {
  797. LLTransferSource* tsp = iter->second;
  798. if (tsp->getID() == transfer_id)
  799. {
  800. return tsp;
  801. }
  802. }
  803. return NULL;
  804. }
  805. void LLTransferSourceChannel::deleteTransfer(LLTransferSource* tsp)
  806. {
  807. if (tsp)
  808. {
  809. for (LLPriQueueMap<LLTransferSource*>::pqm_iter
  810. iter = mTransferSources.mMap.begin(),
  811. end = mTransferSources.mMap.end(); iter != end; ++iter)
  812. {
  813. if (iter->second == tsp)
  814. {
  815. delete tsp;
  816. mTransferSources.mMap.erase(iter);
  817. return;
  818. }
  819. }
  820. llwarns << "Unable to find transfer source ID " << tsp->getID()
  821. << " to delete !" << llendl;
  822. }
  823. }
  824. //
  825. // LLTransferTargetChannel implementation
  826. //
  827. LLTransferTargetChannel::LLTransferTargetChannel(LLTransferChannelType type,
  828. const LLHost& host)
  829. : mChannelType(type),
  830. mHost(host)
  831. {
  832. }
  833. LLTransferTargetChannel::~LLTransferTargetChannel()
  834. {
  835. for (tt_iter iter = mTransferTargets.begin(), end = mTransferTargets.end();
  836. iter != end; ++iter)
  837. {
  838. // Abort all of the current transfers
  839. (*iter)->abortTransfer();
  840. delete *iter;
  841. }
  842. mTransferTargets.clear();
  843. }
  844. void LLTransferTargetChannel::requestTransfer(const LLTransferSourceParams& source_params,
  845. const LLTransferTargetParams& target_params,
  846. F32 priority)
  847. {
  848. LLUUID id;
  849. id.generate();
  850. LLTransferTarget* ttp = LLTransferTarget::createTarget(
  851. target_params.getType(),
  852. id,
  853. source_params.getType());
  854. if (!ttp)
  855. {
  856. llwarns << "Aborting due to target creation failure !" << llendl;
  857. return;
  858. }
  859. ttp->applyParams(target_params);
  860. addTransferTarget(ttp);
  861. sendTransferRequest(ttp, source_params, priority);
  862. }
  863. void LLTransferTargetChannel::sendTransferRequest(LLTransferTarget* targetp,
  864. const LLTransferSourceParams& params,
  865. F32 priority)
  866. {
  867. //
  868. // Pack the message with data which explains how to get the source, and
  869. // send it off to the source for this channel.
  870. //
  871. llassert(targetp);
  872. llassert(targetp->getChannel() == this);
  873. LLMessageSystem* msg = gMessageSystemp;
  874. msg->newMessage("TransferRequest");
  875. msg->nextBlock("TransferInfo");
  876. msg->addUUID("TransferID", targetp->getID());
  877. msg->addS32("SourceType", params.getType());
  878. msg->addS32("ChannelType", getChannelType());
  879. msg->addF32("Priority", priority);
  880. U8 tmp[MAX_PARAMS_SIZE];
  881. LLDataPackerBinaryBuffer dp(tmp, MAX_PARAMS_SIZE);
  882. params.packParams(dp);
  883. S32 len = dp.getCurrentSize();
  884. msg->addBinaryData("Params", tmp, len);
  885. msg->sendReliable(mHost);
  886. }
  887. void LLTransferTargetChannel::addTransferTarget(LLTransferTarget* targetp)
  888. {
  889. targetp->mChannelp = this;
  890. mTransferTargets.push_back(targetp);
  891. }
  892. LLTransferTarget* LLTransferTargetChannel::findTransferTarget(const LLUUID& transfer_id)
  893. {
  894. for (tt_iter iter = mTransferTargets.begin(),
  895. end = mTransferTargets.end();
  896. iter != end; ++iter)
  897. {
  898. LLTransferTarget* ttp = *iter;
  899. if (ttp && ttp->getID() == transfer_id)
  900. {
  901. return ttp;
  902. }
  903. }
  904. return NULL;
  905. }
  906. void LLTransferTargetChannel::deleteTransfer(LLTransferTarget* ttp)
  907. {
  908. if (ttp)
  909. {
  910. for (tt_iter iter = mTransferTargets.begin(),
  911. end = mTransferTargets.end();
  912. iter != end; ++iter)
  913. {
  914. if (*iter == ttp)
  915. {
  916. delete ttp;
  917. mTransferTargets.erase(iter);
  918. return;
  919. }
  920. }
  921. llwarns << "Unable to find transfer target ID " << ttp->getID()
  922. << " to delete !" << llendl;
  923. }
  924. }
  925. //
  926. // LLTransferSource implementation
  927. //
  928. LLTransferSource::LLTransferSource(LLTransferSourceType type,
  929. const LLUUID& transfer_id,
  930. F32 priority) :
  931. mType(type),
  932. mID(transfer_id),
  933. mChannelp(NULL),
  934. mPriority(priority),
  935. mSize(0),
  936. mLastPacketID(-1)
  937. {
  938. setPriority(priority);
  939. }
  940. void LLTransferSource::sendTransferStatus(LLTSCode status)
  941. {
  942. LLMessageSystem* msg = gMessageSystemp;
  943. msg->newMessage("TransferInfo");
  944. msg->nextBlock("TransferInfo");
  945. msg->addUUID("TransferID", getID());
  946. msg->addS32("TargetType", LLTTT_UNKNOWN);
  947. msg->addS32("ChannelType", mChannelp->getChannelType());
  948. msg->addS32("Status", status);
  949. msg->addS32("Size", mSize);
  950. U8 tmp[MAX_PARAMS_SIZE];
  951. LLDataPackerBinaryBuffer dp(tmp, MAX_PARAMS_SIZE);
  952. packParams(dp);
  953. S32 len = dp.getCurrentSize();
  954. msg->addBinaryData("Params", tmp, len);
  955. msg->sendReliable(mChannelp->getHost());
  956. // Abort if there was as asset system issue.
  957. if (status != LLTS_OK)
  958. {
  959. completionCallback(status);
  960. mChannelp->deleteTransfer(this);
  961. }
  962. }
  963. // This should never be called directly, the transfer manager is responsible
  964. // for aborting the transfer from the channel. I might want to rethink this in
  965. // the future, though.
  966. void LLTransferSource::abortTransfer()
  967. {
  968. // Send a message down, call the completion callback
  969. llinfos << "Aborting transfer " << getID() << " to "
  970. << mChannelp->getHost() << llendl;
  971. LLMessageSystem* msg = gMessageSystemp;
  972. msg->newMessage("TransferAbort");
  973. msg->nextBlock("TransferInfo");
  974. msg->addUUID("TransferID", getID());
  975. msg->addS32("ChannelType", mChannelp->getChannelType());
  976. msg->sendReliable(mChannelp->getHost());
  977. completionCallback(LLTS_ABORT);
  978. }
  979. //static
  980. void LLTransferSource::registerSourceType(LLTransferSourceType stype,
  981. LLTransferSourceCreateFunc func)
  982. {
  983. if (sSourceCreateMap.count(stype))
  984. {
  985. // Disallow changing what class handles a source type. Unclear when you
  986. // would want to do this and whether it would work.
  987. llwarns << "Reregistering source type " << stype << llendl;
  988. llassert(false);
  989. }
  990. else
  991. {
  992. sSourceCreateMap[stype] = func;
  993. }
  994. }
  995. //static
  996. LLTransferSource* LLTransferSource::createSource(LLTransferSourceType stype,
  997. const LLUUID& id,
  998. F32 priority)
  999. {
  1000. switch (stype)
  1001. {
  1002. #if 0 // *NOTE: The source file transfer mechanism is highly insecure and
  1003. // could lead to easy exploitation of a server process. I have removed
  1004. // all uses of it from the codebase. Phoenix.
  1005. case LLTST_FILE:
  1006. return new LLTransferSourceFile(id, priority);
  1007. #endif
  1008. case LLTST_ASSET:
  1009. return new LLTransferSourceAsset(id, priority);
  1010. default:
  1011. {
  1012. if (!sSourceCreateMap.count(stype))
  1013. {
  1014. // Use the callback to create the source type if it's not
  1015. // there.
  1016. llwarns << "Unknown transfer source type: " << stype
  1017. << llendl;
  1018. return NULL;
  1019. }
  1020. return (sSourceCreateMap[stype])(id, priority);
  1021. }
  1022. }
  1023. }
  1024. // static
  1025. void LLTransferSource::sSetPriority(LLTransferSource*& tsp, F32 priority)
  1026. {
  1027. tsp->setPriority(priority);
  1028. }
  1029. // static
  1030. F32 LLTransferSource::sGetPriority(LLTransferSource*& tsp)
  1031. {
  1032. return tsp->getPriority();
  1033. }
  1034. //
  1035. // LLTransferPacket implementation
  1036. //
  1037. LLTransferPacket::LLTransferPacket(S32 packet_id, LLTSCode status,
  1038. const U8* datap, S32 size)
  1039. : mPacketID(packet_id),
  1040. mStatus(status),
  1041. mDatap(NULL),
  1042. mSize(size)
  1043. {
  1044. if (size == 0)
  1045. {
  1046. return;
  1047. }
  1048. mDatap = new U8[size];
  1049. if (mDatap != NULL)
  1050. {
  1051. memcpy(mDatap, datap, size);
  1052. }
  1053. }
  1054. LLTransferPacket::~LLTransferPacket()
  1055. {
  1056. if (mDatap)
  1057. {
  1058. delete[] mDatap;
  1059. mDatap = NULL;
  1060. }
  1061. }
  1062. //
  1063. // LLTransferTarget implementation
  1064. //
  1065. LLTransferTarget::LLTransferTarget(LLTransferTargetType type,
  1066. const LLUUID& transfer_id,
  1067. LLTransferSourceType source_type)
  1068. : mType(type),
  1069. mSourceType(source_type),
  1070. mID(transfer_id),
  1071. mChannelp(NULL),
  1072. mGotInfo(false),
  1073. mSize(0),
  1074. mLastPacketID(-1)
  1075. {
  1076. }
  1077. LLTransferTarget::~LLTransferTarget()
  1078. {
  1079. // No actual cleanup of the transfer is done here, this is purely for
  1080. // memory cleanup. The completionCallback is guaranteed to get called
  1081. // before this happens.
  1082. for (tpm_iter iter = mDelayedPacketMap.begin(),
  1083. end = mDelayedPacketMap.end();
  1084. iter != end; ++iter)
  1085. {
  1086. delete iter->second;
  1087. }
  1088. mDelayedPacketMap.clear();
  1089. }
  1090. // This should never be called directly, the transfer manager is responsible for
  1091. // aborting the transfer from the channel. I might want to rethink this in the
  1092. // future, though.
  1093. void LLTransferTarget::abortTransfer()
  1094. {
  1095. // Send a message up, call the completion callback
  1096. llinfos << "Aborting transfer " << getID() << " from "
  1097. << mChannelp->getHost() << llendl;
  1098. LLMessageSystem* msg = gMessageSystemp;
  1099. msg->newMessage("TransferAbort");
  1100. msg->nextBlock("TransferInfo");
  1101. msg->addUUID("TransferID", getID());
  1102. msg->addS32("ChannelType", mChannelp->getChannelType());
  1103. msg->sendReliable(mChannelp->getHost());
  1104. completionCallback(LLTS_ABORT);
  1105. }
  1106. bool LLTransferTarget::addDelayedPacket(S32 packet_id, LLTSCode status,
  1107. U8* datap, S32 size)
  1108. {
  1109. constexpr transfer_packet_map::size_type LL_MAX_DELAYED_PACKETS = 100;
  1110. if (mDelayedPacketMap.size() > LL_MAX_DELAYED_PACKETS)
  1111. {
  1112. // too many delayed packets
  1113. return false;
  1114. }
  1115. if (mDelayedPacketMap.find(packet_id) != mDelayedPacketMap.end())
  1116. {
  1117. llwarns << "Packet Id " << packet_id
  1118. << " ALREADY in delayed packet map !" << llendl;
  1119. llassert(false);
  1120. return true;
  1121. }
  1122. LLTransferPacket* tpp = new LLTransferPacket(packet_id, status, datap,
  1123. size);
  1124. mDelayedPacketMap[packet_id] = tpp;
  1125. return true;
  1126. }
  1127. LLTransferTarget* LLTransferTarget::createTarget(LLTransferTargetType type,
  1128. const LLUUID& id,
  1129. LLTransferSourceType source_type)
  1130. {
  1131. switch (type)
  1132. {
  1133. case LLTTT_FILE:
  1134. return new LLTransferTargetFile(id, source_type);
  1135. case LLTTT_VFILE:
  1136. return new LLTransferTargetVFile(id, source_type);
  1137. default:
  1138. llwarns << "Unknown transfer target type: " << type << llendl;
  1139. return NULL;
  1140. }
  1141. }
  1142. LLTransferSourceParamsInvItem::LLTransferSourceParamsInvItem()
  1143. : LLTransferSourceParams(LLTST_SIM_INV_ITEM),
  1144. mAssetType(LLAssetType::AT_NONE)
  1145. {
  1146. }
  1147. void LLTransferSourceParamsInvItem::setAgentSession(const LLUUID& agent_id,
  1148. const LLUUID& session_id)
  1149. {
  1150. mAgentID = agent_id;
  1151. mSessionID = session_id;
  1152. }
  1153. void LLTransferSourceParamsInvItem::setInvItem(const LLUUID& owner_id,
  1154. const LLUUID& task_id,
  1155. const LLUUID& item_id)
  1156. {
  1157. mOwnerID = owner_id;
  1158. mTaskID = task_id;
  1159. mItemID = item_id;
  1160. }
  1161. void LLTransferSourceParamsInvItem::setAsset(const LLUUID& asset_id,
  1162. LLAssetType::EType asset_type)
  1163. {
  1164. mAssetID = asset_id;
  1165. mAssetType = asset_type;
  1166. }
  1167. void LLTransferSourceParamsInvItem::packParams(LLDataPacker& dp) const
  1168. {
  1169. LL_DEBUGS("Messaging") << "LLTransferSourceParamsInvItem::packParams()"
  1170. << LL_ENDL;
  1171. dp.packUUID(mAgentID, "AgentID");
  1172. dp.packUUID(mSessionID, "SessionID");
  1173. dp.packUUID(mOwnerID, "OwnerID");
  1174. dp.packUUID(mTaskID, "TaskID");
  1175. dp.packUUID(mItemID, "ItemID");
  1176. dp.packUUID(mAssetID, "AssetID");
  1177. dp.packS32(mAssetType, "AssetType");
  1178. }
  1179. bool LLTransferSourceParamsInvItem::unpackParams(LLDataPacker& dp)
  1180. {
  1181. S32 tmp_at;
  1182. dp.unpackUUID(mAgentID, "AgentID");
  1183. dp.unpackUUID(mSessionID, "SessionID");
  1184. dp.unpackUUID(mOwnerID, "OwnerID");
  1185. dp.unpackUUID(mTaskID, "TaskID");
  1186. dp.unpackUUID(mItemID, "ItemID");
  1187. dp.unpackUUID(mAssetID, "AssetID");
  1188. dp.unpackS32(tmp_at, "AssetType");
  1189. mAssetType = (LLAssetType::EType)tmp_at;
  1190. return true;
  1191. }
  1192. LLTransferSourceParamsEstate::LLTransferSourceParamsEstate()
  1193. : LLTransferSourceParams(LLTST_SIM_ESTATE),
  1194. mEstateAssetType(ET_NONE),
  1195. mAssetType(LLAssetType::AT_NONE)
  1196. {
  1197. }
  1198. void LLTransferSourceParamsEstate::setAgentSession(const LLUUID& agent_id,
  1199. const LLUUID& session_id)
  1200. {
  1201. mAgentID = agent_id;
  1202. mSessionID = session_id;
  1203. }
  1204. void LLTransferSourceParamsEstate::setEstateAssetType(EstateAssetType etype)
  1205. {
  1206. mEstateAssetType = etype;
  1207. }
  1208. void LLTransferSourceParamsEstate::setAsset(const LLUUID& asset_id,
  1209. LLAssetType::EType asset_type)
  1210. {
  1211. mAssetID = asset_id;
  1212. mAssetType = asset_type;
  1213. }
  1214. void LLTransferSourceParamsEstate::packParams(LLDataPacker& dp) const
  1215. {
  1216. dp.packUUID(mAgentID, "AgentID");
  1217. // *NOTE: We do not want to pass the session id from the server to the
  1218. // client, but I am not sure if anyone expects this value to be set on the
  1219. // client.
  1220. dp.packUUID(mSessionID, "SessionID");
  1221. dp.packS32(mEstateAssetType, "EstateAssetType");
  1222. }
  1223. bool LLTransferSourceParamsEstate::unpackParams(LLDataPacker& dp)
  1224. {
  1225. S32 tmp_et;
  1226. dp.unpackUUID(mAgentID, "AgentID");
  1227. dp.unpackUUID(mSessionID, "SessionID");
  1228. dp.unpackS32(tmp_et, "EstateAssetType");
  1229. mEstateAssetType = (EstateAssetType)tmp_et;
  1230. return true;
  1231. }