PageRenderTime 42ms CodeModel.GetById 14ms app.highlight 24ms 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
  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
 27#include "linden_common.h"
 28
 29#include "llregionpresenceverifier.h"
 30#include "llhttpclientinterface.h"
 31#include <sstream>
 32#include "net.h"
 33#include "message.h"
 34
 35namespace boost
 36{
 37	void intrusive_ptr_add_ref(LLRegionPresenceVerifier::Response* p)
 38	{
 39		++p->mReferenceCount;
 40	}
 41	
 42	void intrusive_ptr_release(LLRegionPresenceVerifier::Response* p)
 43	{
 44		if(p && 0 == --p->mReferenceCount)
 45		{
 46			delete p;
 47		}
 48	}
 49};
 50
 51LLRegionPresenceVerifier::Response::~Response()
 52{
 53}
 54
 55LLRegionPresenceVerifier::RegionResponder::RegionResponder(const std::string&
 56														   uri,
 57														   ResponsePtr data,
 58														   S32 retry_count) :
 59	mUri(uri),
 60	mSharedData(data),
 61	mRetryCount(retry_count)
 62{
 63}
 64
 65//virtual
 66LLRegionPresenceVerifier::RegionResponder::~RegionResponder()
 67{
 68}
 69
 70void LLRegionPresenceVerifier::RegionResponder::result(const LLSD& content)
 71{
 72	std::string host = content["private_host"].asString();
 73	U32 port = content["private_port"].asInteger();
 74	LLHost destination(host, port);
 75	LLUUID id = content["region_id"];
 76
 77	lldebugs << "Verifying " << destination.getString() << " is region " << id << llendl;
 78
 79	std::stringstream uri;
 80	uri << "http://" << destination.getString() << "/state/basic/";
 81	mSharedData->getHttpClient().get(
 82		uri.str(),
 83		new VerifiedDestinationResponder(mUri, mSharedData, content, mRetryCount));
 84}
 85
 86void LLRegionPresenceVerifier::RegionResponder::error(U32 status,
 87													 const std::string& reason)
 88{
 89	// TODO: babbage: distinguish between region presence service and
 90	// region verification errors?
 91	mSharedData->onRegionVerificationFailed();
 92}
 93
 94LLRegionPresenceVerifier::VerifiedDestinationResponder::VerifiedDestinationResponder(const std::string& uri, ResponsePtr data, const LLSD& content,
 95	S32 retry_count):
 96	mUri(uri),
 97	mSharedData(data),
 98	mContent(content),
 99	mRetryCount(retry_count) 
100{
101}
102
103//virtual
104LLRegionPresenceVerifier::VerifiedDestinationResponder::~VerifiedDestinationResponder()
105{
106}
107
108void LLRegionPresenceVerifier::VerifiedDestinationResponder::result(const LLSD& content)
109{
110	LLUUID actual_region_id = content["region_id"];
111	LLUUID expected_region_id = mContent["region_id"];
112
113	lldebugs << "Actual region: " << content << llendl;
114	lldebugs << "Expected region: " << mContent << llendl;
115
116	if (mSharedData->checkValidity(content) &&
117		(actual_region_id == expected_region_id))
118	{
119		mSharedData->onRegionVerified(mContent);
120	}
121	else if (mRetryCount > 0)
122	{
123		retry();
124	}
125	else
126	{
127		llwarns << "Simulator verification failed. Region: " << mUri << llendl;
128		mSharedData->onRegionVerificationFailed();
129	}
130}
131
132void LLRegionPresenceVerifier::VerifiedDestinationResponder::retry()
133{
134	LLSD headers;
135	headers["Cache-Control"] = "no-cache, max-age=0";
136	llinfos << "Requesting region information, get uncached for region "
137			<< mUri << llendl;
138	--mRetryCount;
139	mSharedData->getHttpClient().get(mUri, new RegionResponder(mUri, mSharedData, mRetryCount), headers);
140}
141
142void LLRegionPresenceVerifier::VerifiedDestinationResponder::error(U32 status, const std::string& reason)
143{
144	if(mRetryCount > 0)
145	{
146		retry();
147	}
148	else
149	{
150		llwarns << "Failed to contact simulator for verification. Region: " << mUri << llendl;
151		mSharedData->onRegionVerificationFailed();
152	}
153}