PageRenderTime 127ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llregionpresenceverifier.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 153 lines | 106 code | 18 blank | 29 comment | 8 complexity | 6593ce9a9627f2281bf9ede554b294ba MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llregionpresenceverifier.cpp
  3. * @brief
  4. *
  5. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "llregionpresenceverifier.h"
  28. #include "llhttpclientinterface.h"
  29. #include <sstream>
  30. #include "net.h"
  31. #include "message.h"
  32. namespace boost
  33. {
  34. void intrusive_ptr_add_ref(LLRegionPresenceVerifier::Response* p)
  35. {
  36. ++p->mReferenceCount;
  37. }
  38. void intrusive_ptr_release(LLRegionPresenceVerifier::Response* p)
  39. {
  40. if(p && 0 == --p->mReferenceCount)
  41. {
  42. delete p;
  43. }
  44. }
  45. };
  46. LLRegionPresenceVerifier::Response::~Response()
  47. {
  48. }
  49. LLRegionPresenceVerifier::RegionResponder::RegionResponder(const std::string&
  50. uri,
  51. ResponsePtr data,
  52. S32 retry_count) :
  53. mUri(uri),
  54. mSharedData(data),
  55. mRetryCount(retry_count)
  56. {
  57. }
  58. //virtual
  59. LLRegionPresenceVerifier::RegionResponder::~RegionResponder()
  60. {
  61. }
  62. void LLRegionPresenceVerifier::RegionResponder::result(const LLSD& content)
  63. {
  64. std::string host = content["private_host"].asString();
  65. U32 port = content["private_port"].asInteger();
  66. LLHost destination(host, port);
  67. LLUUID id = content["region_id"];
  68. lldebugs << "Verifying " << destination.getString() << " is region " << id << llendl;
  69. std::stringstream uri;
  70. uri << "http://" << destination.getString() << "/state/basic/";
  71. mSharedData->getHttpClient().get(
  72. uri.str(),
  73. new VerifiedDestinationResponder(mUri, mSharedData, content, mRetryCount));
  74. }
  75. void LLRegionPresenceVerifier::RegionResponder::error(U32 status,
  76. const std::string& reason)
  77. {
  78. // TODO: babbage: distinguish between region presence service and
  79. // region verification errors?
  80. mSharedData->onRegionVerificationFailed();
  81. }
  82. LLRegionPresenceVerifier::VerifiedDestinationResponder::VerifiedDestinationResponder(const std::string& uri, ResponsePtr data, const LLSD& content,
  83. S32 retry_count):
  84. mUri(uri),
  85. mSharedData(data),
  86. mContent(content),
  87. mRetryCount(retry_count)
  88. {
  89. }
  90. //virtual
  91. LLRegionPresenceVerifier::VerifiedDestinationResponder::~VerifiedDestinationResponder()
  92. {
  93. }
  94. void LLRegionPresenceVerifier::VerifiedDestinationResponder::result(const LLSD& content)
  95. {
  96. LLUUID actual_region_id = content["region_id"];
  97. LLUUID expected_region_id = mContent["region_id"];
  98. lldebugs << "Actual region: " << content << llendl;
  99. lldebugs << "Expected region: " << mContent << llendl;
  100. if (mSharedData->checkValidity(content) &&
  101. (actual_region_id == expected_region_id))
  102. {
  103. mSharedData->onRegionVerified(mContent);
  104. }
  105. else if (mRetryCount > 0)
  106. {
  107. retry();
  108. }
  109. else
  110. {
  111. llwarns << "Simulator verification failed. Region: " << mUri << llendl;
  112. mSharedData->onRegionVerificationFailed();
  113. }
  114. }
  115. void LLRegionPresenceVerifier::VerifiedDestinationResponder::retry()
  116. {
  117. LLSD headers;
  118. headers["Cache-Control"] = "no-cache, max-age=0";
  119. llinfos << "Requesting region information, get uncached for region "
  120. << mUri << llendl;
  121. --mRetryCount;
  122. mSharedData->getHttpClient().get(mUri, new RegionResponder(mUri, mSharedData, mRetryCount), headers);
  123. }
  124. void LLRegionPresenceVerifier::VerifiedDestinationResponder::error(U32 status, const std::string& reason)
  125. {
  126. if(mRetryCount > 0)
  127. {
  128. retry();
  129. }
  130. else
  131. {
  132. llwarns << "Failed to contact simulator for verification. Region: " << mUri << llendl;
  133. mSharedData->onRegionVerificationFailed();
  134. }
  135. }