summaryrefslogtreecommitdiff
path: root/indra/llmessage/message.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage/message.cpp')
-rw-r--r--indra/llmessage/message.cpp592
1 files changed, 322 insertions, 270 deletions
diff --git a/indra/llmessage/message.cpp b/indra/llmessage/message.cpp
index c1731532ca..2f0d815be5 100644
--- a/indra/llmessage/message.cpp
+++ b/indra/llmessage/message.cpp
@@ -2,30 +2,25 @@
* @file message.cpp
* @brief LLMessageSystem class implementation
*
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlife.com/developers/opensource/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlife.com/developers/opensource/flossexception
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -58,13 +53,16 @@
#include "llerrorlegacy.h"
#include "llfasttimer.h"
#include "llhttpclient.h"
+#include "llhttpnodeadapter.h"
#include "llhttpsender.h"
#include "llmd5.h"
#include "llmessagebuilder.h"
#include "llmessageconfig.h"
+#include "lltemplatemessagedispatcher.h"
#include "llpumpio.h"
#include "lltemplatemessagebuilder.h"
#include "lltemplatemessagereader.h"
+#include "lltrustedmessageservice.h"
#include "llmessagetemplate.h"
#include "llmessagetemplateparser.h"
#include "llsd.h"
@@ -82,6 +80,7 @@
#include "v3math.h"
#include "v4math.h"
#include "lltransfertargetvfile.h"
+#include "llmemtype.h"
// Constants
//const char* MESSAGE_LOG_FILENAME = "message.log";
@@ -141,52 +140,6 @@ namespace
};
}
-
-class LLTrustedMessageService : public LLHTTPNode
-{
- virtual bool validate(const std::string& name, LLSD& context) const
- { return true; }
-
- virtual void post(LLHTTPNode::ResponsePtr response,
- const LLSD& context,
- const LLSD& input) const;
-};
-
-//virtual
-void LLTrustedMessageService::post(LLHTTPNode::ResponsePtr response,
- const LLSD& context,
- const LLSD& input) const
-{
- std::string name = context["request"]["wildcard"]["message-name"];
- std::string senderIP = context["request"]["remote-host"];
- std::string senderPort = context["request"]["headers"]
- ["x-secondlife-udp-listen-port"];
-
- LLSD message_data;
- std::string sender = senderIP + ":" + senderPort;
- message_data["sender"] = sender;
- message_data["body"] = input;
-
- // untrusted senders should not have access to the trusted message
- // service, but this can happen in development, so check and warn
- LLMessageConfig::SenderTrust trust =
- LLMessageConfig::getSenderTrustedness(name);
- if ((trust == LLMessageConfig::TRUSTED ||
- (trust == LLMessageConfig::NOT_SET &&
- gMessageSystem->isTrustedMessage(name)))
- && !gMessageSystem->isTrustedSender(LLHost(sender)))
- {
- LL_WARNS("Messaging") << "trusted message POST to /trusted-message/"
- << name << " from unknown or untrusted sender "
- << sender << llendl;
- response->status(403, "Unknown or untrusted sender");
- }
- else
- {
- LLMessageSystem::dispatch(name, message_data, response);
- }
-}
-
class LLMessageHandlerBridge : public LLHTTPNode
{
virtual bool validate(const std::string& name, LLSD& context) const
@@ -222,9 +175,6 @@ void LLMessageHandlerBridge::post(LLHTTPNode::ResponsePtr response,
LLHTTPRegistration<LLMessageHandlerBridge>
gHTTPRegistrationMessageWildcard("/message/<message-name>");
-LLHTTPRegistration<LLTrustedMessageService>
- gHTTPRegistrationTrustedMessageWildcard("/trusted-message/<message-name>");
-
//virtual
LLUseCircuitCodeResponder::~LLUseCircuitCodeResponder()
{
@@ -286,14 +236,19 @@ void LLMessageSystem::init()
}
// Read file and build message templates
-LLMessageSystem::LLMessageSystem(const char *filename, U32 port,
+LLMessageSystem::LLMessageSystem(const std::string& filename, U32 port,
S32 version_major,
S32 version_minor,
S32 version_patch,
- bool failure_is_fatal)
+ bool failure_is_fatal,
+ const F32 circuit_heartbeat_interval, const F32 circuit_timeout) :
+ mCircuitInfo(circuit_heartbeat_interval, circuit_timeout),
+ mLastMessageFromTrustedMessageService(false)
{
init();
+ mSendSize = 0;
+
mSystemVersionMajor = version_major;
mSystemVersionMinor = version_minor;
mSystemVersionPatch = version_patch;
@@ -303,6 +258,9 @@ LLMessageSystem::LLMessageSystem(const char *filename, U32 port,
// default to not accepting packets from not alive circuits
mbProtected = TRUE;
+ // default to blocking trusted connections on a public interface if one is specified
+ mBlockUntrustedInterface = true;
+
mSendPacketFailureCount = 0;
mCircuitPrintFreq = 60.f; // seconds
@@ -361,15 +319,16 @@ LLMessageSystem::LLMessageSystem(const char *filename, U32 port,
mMaxMessageTime = 1.f;
mTrueReceiveSize = 0;
+
+ mReceiveTime = 0.f;
}
// Read file and build message templates
-void LLMessageSystem::loadTemplateFile(const char* filename,
- bool failure_is_fatal)
+void LLMessageSystem::loadTemplateFile(const std::string& filename, bool failure_is_fatal)
{
- if(!filename)
+ if(filename.empty())
{
LL_ERRS("Messaging") << "No template filename specified" << llendl;
mbError = TRUE;
@@ -438,7 +397,9 @@ void LLMessageSystem::clearReceiveState()
mCurrentRecvPacketID = 0;
mIncomingCompressedSize = 0;
mLastSender.invalidate();
+ mLastReceivingIF.invalidate();
mMessageReader->clearMessage();
+ mLastMessageFromTrustedMessageService = false;
}
@@ -471,6 +432,17 @@ bool LLMessageSystem::isTrustedSender(const LLHost& host) const
return cdp->getTrusted();
}
+void LLMessageSystem::receivedMessageFromTrustedSender()
+{
+ mLastMessageFromTrustedMessageService = true;
+}
+
+bool LLMessageSystem::isTrustedSender() const
+{
+ return mLastMessageFromTrustedMessageService ||
+ isTrustedSender(getSender());
+}
+
static LLMessageSystem::message_template_name_map_t::const_iterator
findTemplate(const LLMessageSystem::message_template_name_map_t& templates,
std::string name)
@@ -587,6 +559,7 @@ BOOL LLMessageSystem::checkMessages( S64 frame_count )
receive_size = mTrueReceiveSize;
mLastSender = mPacketRing.getLastSender();
+ mLastReceivingIF = mPacketRing.getLastReceivingInterface();
if (receive_size < (S32) LL_MINIMUM_VALID_PACKET_SIZE)
{
@@ -692,9 +665,9 @@ BOOL LLMessageSystem::checkMessages( S64 frame_count )
{
std::ostringstream str;
str << "MSG: <- " << host;
- char buffer[MAX_STRING]; /* Flawfinder: ignore*/
- snprintf(buffer, MAX_STRING, "\t%6d\t%6d\t%6d ", receive_size, (mIncomingCompressedSize ? mIncomingCompressedSize : receive_size), mCurrentRecvPacketID); /* Flawfinder: ignore */
- str << buffer << "(unknown)"
+ std::string tbuf;
+ tbuf = llformat( "\t%6d\t%6d\t%6d ", receive_size, (mIncomingCompressedSize ? mIncomingCompressedSize : receive_size), mCurrentRecvPacketID);
+ str << tbuf << "(unknown)"
<< (recv_reliable ? " reliable" : "")
<< " resent "
<< ((acks > 0) ? "acks" : "")
@@ -710,11 +683,16 @@ BOOL LLMessageSystem::checkMessages( S64 frame_count )
// UseCircuitCode can be a valid, off-circuit packet.
// But we don't want to acknowledge UseCircuitCode until the circuit is
// available, which is why the acknowledgement test is done above. JC
-
+ bool trusted = cdp && cdp->getTrusted();
valid_packet = mTemplateMessageReader->validateMessage(
buffer,
receive_size,
- host);
+ host,
+ trusted);
+ if (!valid_packet)
+ {
+ clearReceiveState();
+ }
// UseCircuitCode is allowed in even from an invalid circuit, so that
// we can toss circuits around.
@@ -742,24 +720,9 @@ BOOL LLMessageSystem::checkMessages( S64 frame_count )
valid_packet = FALSE;
}
- if (
- valid_packet &&
- mTemplateMessageReader->isBanned(cdp && cdp->getTrusted()))
- {
- LL_WARNS("Messaging") << "LLMessageSystem::checkMessages "
- << "received banned message "
- << mTemplateMessageReader->getMessageName()
- << " from "
- << ((cdp && cdp->getTrusted()) ? "trusted " : "untrusted ")
- << host << llendl;
- clearReceiveState();
- valid_packet = FALSE;
- }
-
if( valid_packet )
{
logValidMsg(cdp, host, recv_reliable, recv_resent, (BOOL)(acks>0) );
-
valid_packet = mTemplateMessageReader->readMessage(buffer, host);
}
@@ -769,95 +732,6 @@ BOOL LLMessageSystem::checkMessages( S64 frame_count )
if (valid_packet)
{
- // enable this for output of message names
- //LL_INFOS("Messaging") << "< \"" << mTemplateMessageReader->getMessageName()
- //<< "\"" << llendl;
-
- /* Code for dumping the complete contents of a message. Keep for future use in optimizing messages.
- if( 1 )
- {
- static char* object_update = LLMessageStringTable::getInstance()->getString("ObjectUpdate");
- if(object_update == mTemplateMessageReader->getMessageName() )
- {
- LL_INFOS("Messaging") << "ObjectUpdate:" << llendl;
- U32 i;
- LL_INFOS("Messaging") << " Zero Encoded: " << zero_unexpanded_size << llendl;
- for( i = 0; i<zero_unexpanded_size; i++ )
- {
- LL_INFOS("Messaging") << " " << i << ": " << (U32) zero_unexpanded_buffer[i] << llendl;
- }
- LL_INFOS("Messaging") << "" << llendl;
-
- LL_INFOS("Messaging") << " Zero Unencoded: " << receive_size << llendl;
- for( i = 0; i<receive_size; i++ )
- {
- LL_INFOS("Messaging") << " " << i << ": " << (U32) buffer[i] << llendl;
- }
- LL_INFOS("Messaging") << "" << llendl;
-
- LL_INFOS("Messaging") << " Blocks and variables: " << llendl;
- S32 byte_count = 0;
- for (LLMessageTemplate::message_block_map_t::iterator
- iter = mCurrentRMessageTemplate->mMemberBlocks.begin(),
- end = mCurrentRMessageTemplate->mMemberBlocks.end();
- iter != end; iter++)
- {
- LLMessageBlock* block = iter->second;
- const char* block_name = block->mName;
- for (LLMsgBlkData::msg_var_data_map_t::iterator
- iter = block->mMemberVariables.begin(),
- end = block->mMemberVariables.end();
- iter != end; iter++)
- {
- const char* var_name = iter->first;
-
- if( getNumberOfBlocksFast( block_name ) < 1 )
- {
- LL_INFOS("Messaging") << var_name << " has no blocks" << llendl;
- }
- for( S32 blocknum = 0; blocknum < getNumberOfBlocksFast( block_name ); blocknum++ )
- {
- char *bnamep = (char *)block_name + blocknum; // this works because it's just a hash. The bnamep is never derefference
- char *vnamep = (char *)var_name;
-
- LLMsgBlkData *msg_block_data = mCurrentRMessageData->mMemberBlocks[bnamep];
-
- char errmsg[1024];
- if (!msg_block_data)
- {
- sprintf(errmsg, "Block %s #%d not in message %s", block_name, blocknum, mCurrentRMessageData->mName);
- LL_ERRS("Messaging") << errmsg << llendl;
- }
-
- LLMsgVarData vardata = msg_block_data->mMemberVarData[vnamep];
-
- if (!vardata.getName())
- {
- sprintf(errmsg, "Variable %s not in message %s block %s", vnamep, mCurrentRMessageData->mName, bnamep);
- LL_ERRS("Messaging") << errmsg << llendl;
- }
-
- const S32 vardata_size = vardata.getSize();
- if( vardata_size )
- {
- for( i = 0; i < vardata_size; i++ )
- {
- byte_count++;
- LL_INFOS("Messaging") << block_name << " " << var_name << " [" << blocknum << "][" << i << "]= " << (U32)(((U8*)vardata.getData())[i]) << llendl;
- }
- }
- else
- {
- LL_INFOS("Messaging") << block_name << " " << var_name << " [" << blocknum << "] 0 bytes" << llendl;
- }
- }
- }
- }
- LL_INFOS("Messaging") << "Byte count =" << byte_count << llendl;
- }
- }
- */
-
mPacketsIn++;
mBytesIn += mTrueReceiveSize;
@@ -885,9 +759,6 @@ BOOL LLMessageSystem::checkMessages( S64 frame_count )
mInvalidOnCircuitPackets++;
}
}
-
- // Code for dumping the complete contents of a message
- // delete [] zero_unexpanded_buffer;
}
} while (!valid_packet && receive_size > 0);
@@ -922,6 +793,7 @@ S32 LLMessageSystem::getReceiveBytes() const
void LLMessageSystem::processAcks()
{
+ LLMemType mt_pa(LLMemType::MTYPE_MESSAGE_PROCESS_ACKS);
F64 mt_sec = getMessageTimeSeconds();
{
gTransferManager.updateTransfers();
@@ -990,7 +862,7 @@ void LLMessageSystem::processAcks()
}
}
-void LLMessageSystem::copyMessageRtoS()
+void LLMessageSystem::copyMessageReceivedToSend()
{
// NOTE: babbage: switch builder to match reader to avoid
// converting message format
@@ -1007,6 +879,94 @@ void LLMessageSystem::copyMessageRtoS()
mMessageReader->copyToBuilder(*mMessageBuilder);
}
+LLSD LLMessageSystem::getReceivedMessageLLSD() const
+{
+ LLSDMessageBuilder builder;
+ mMessageReader->copyToBuilder(builder);
+ return builder.getMessage();
+}
+
+LLSD LLMessageSystem::getBuiltMessageLLSD() const
+{
+ LLSD result;
+ if (mLLSDMessageBuilder == mMessageBuilder)
+ {
+ result = mLLSDMessageBuilder->getMessage();
+ }
+ else
+ {
+ // TODO: implement as below?
+ llerrs << "Message not built as LLSD." << llendl;
+ }
+ return result;
+}
+
+LLSD LLMessageSystem::wrapReceivedTemplateData() const
+{
+ if(mMessageReader == mTemplateMessageReader)
+ {
+ LLTemplateMessageBuilder builder(mMessageTemplates);
+ builder.newMessage(mMessageReader->getMessageName());
+ mMessageReader->copyToBuilder(builder);
+ U8 buffer[MAX_BUFFER_SIZE];
+ const U8 offset_to_data = 0;
+ U32 size = builder.buildMessage(buffer, MAX_BUFFER_SIZE,
+ offset_to_data);
+ std::vector<U8> binary_data(buffer, buffer+size);
+ LLSD wrapped_data = LLSD::emptyMap();
+ wrapped_data["binary-template-data"] = binary_data;
+ return wrapped_data;
+ }
+ else
+ {
+ return getReceivedMessageLLSD();
+ }
+}
+
+LLSD LLMessageSystem::wrapBuiltTemplateData() const
+{
+ LLSD result;
+ if (mLLSDMessageBuilder == mMessageBuilder)
+ {
+ result = getBuiltMessageLLSD();
+ }
+ else
+ {
+ U8 buffer[MAX_BUFFER_SIZE];
+ const U8 offset_to_data = 0;
+ U32 size = mTemplateMessageBuilder->buildMessage(
+ buffer, MAX_BUFFER_SIZE,
+ offset_to_data);
+ std::vector<U8> binary_data(buffer, buffer+size);
+ LLSD wrapped_data = LLSD::emptyMap();
+ wrapped_data["binary-template-data"] = binary_data;
+ result = wrapped_data;
+ }
+ return result;
+}
+
+LLStoredMessagePtr LLMessageSystem::getReceivedMessage() const
+{
+ const std::string& name = mMessageReader->getMessageName();
+ LLSD message = wrapReceivedTemplateData();
+
+ return LLStoredMessagePtr(new LLStoredMessage(name, message));
+}
+
+LLStoredMessagePtr LLMessageSystem::getBuiltMessage() const
+{
+ const std::string& name = mMessageBuilder->getMessageName();
+ LLSD message = wrapBuiltTemplateData();
+
+ return LLStoredMessagePtr(new LLStoredMessage(name, message));
+}
+
+S32 LLMessageSystem::sendMessage(const LLHost &host, LLStoredMessagePtr message)
+{
+ return sendMessage(host, message->mName.c_str(), message->mMessage);
+}
+
+
void LLMessageSystem::clearMessage()
{
mSendReliable = FALSE;
@@ -1019,6 +979,11 @@ void LLMessageSystem::nextBlockFast(const char *blockname)
mMessageBuilder->nextBlock(blockname);
}
+void LLMessageSystem::nextBlock(const char *blockname)
+{
+ nextBlockFast(LLMessageStringTable::getInstance()->getString(blockname));
+}
+
BOOL LLMessageSystem::isSendFull(const char* blockname)
{
char* stringTableName = NULL;
@@ -1098,19 +1063,19 @@ S32 LLMessageSystem::sendReliable( const LLHost &host,
void LLMessageSystem::forwardMessage(const LLHost &host)
{
- copyMessageRtoS();
+ copyMessageReceivedToSend();
sendMessage(host);
}
void LLMessageSystem::forwardReliable(const LLHost &host)
{
- copyMessageRtoS();
+ copyMessageReceivedToSend();
sendReliable(host);
}
void LLMessageSystem::forwardReliable(const U32 circuit_code)
{
- copyMessageRtoS();
+ copyMessageReceivedToSend();
sendReliable(findHost(circuit_code));
}
@@ -1121,7 +1086,7 @@ S32 LLMessageSystem::forwardReliable( const LLHost &host,
void (*callback)(void **,S32),
void ** callback_data)
{
- copyMessageRtoS();
+ copyMessageReceivedToSend();
return sendReliable(host, retries, ping_based_timeout, timeout, callback, callback_data);
}
@@ -1188,7 +1153,7 @@ LLHTTPClient::ResponderPtr LLMessageSystem::createResponder(const std::string& n
return new LLFnPtrResponder(
NULL,
NULL,
- mMessageBuilder->getMessageName());
+ name);
}
}
@@ -1384,8 +1349,8 @@ S32 LLMessageSystem::sendMessage(const LLHost &host)
{
std::ostringstream str;
str << "MSG: -> " << host;
- char buffer[MAX_STRING]; /* Flawfinder: ignore */
- snprintf(buffer, MAX_STRING, "\t%6d\t%6d\t%6d ", mSendSize, buffer_length, cdp->getPacketOutID()); /* Flawfinder: ignore */
+ std::string buffer;
+ buffer = llformat( "\t%6d\t%6d\t%6d ", mSendSize, buffer_length, cdp->getPacketOutID());
str << buffer
<< mMessageBuilder->getMessageName()
<< (mSendReliable ? " reliable " : "");
@@ -1413,8 +1378,8 @@ void LLMessageSystem::logMsgFromInvalidCircuit( const LLHost& host, BOOL recv_re
{
std::ostringstream str;
str << "MSG: <- " << host;
- char buffer[MAX_STRING]; /* Flawfinder: ignore */
- snprintf(buffer, MAX_STRING, "\t%6d\t%6d\t%6d ", mMessageReader->getMessageSize(), (mIncomingCompressedSize ? mIncomingCompressedSize: mMessageReader->getMessageSize()), mCurrentRecvPacketID); /* Flawfinder: ignore */
+ std::string buffer;
+ buffer = llformat( "\t%6d\t%6d\t%6d ", mMessageReader->getMessageSize(), (mIncomingCompressedSize ? mIncomingCompressedSize: mMessageReader->getMessageSize()), mCurrentRecvPacketID);
str << buffer
<< nullToEmpty(mMessageReader->getMessageName())
<< (recv_reliable ? " reliable" : "")
@@ -1449,13 +1414,6 @@ S32 LLMessageSystem::sendMessage(
LL_WARNS("Messaging") << "trying to send message to invalid host" << llendl;
return 0;
}
- newMessage(name);
- if (mMessageBuilder != mLLSDMessageBuilder)
- {
- LL_WARNS("Messaging") << "trying to send llsd message when builder is not LLSD!"
- << llendl;
- return 0;
- }
const LLHTTPSender& sender = LLHTTPSender::getSender(host);
sender.send(host, name, message, createResponder(name));
@@ -1518,8 +1476,8 @@ void LLMessageSystem::logValidMsg(LLCircuitData *cdp, const LLHost& host, BOOL r
{
std::ostringstream str;
str << "MSG: <- " << host;
- char buffer[MAX_STRING]; /* Flawfinder: ignore */
- snprintf(buffer, MAX_STRING, "\t%6d\t%6d\t%6d ", mMessageReader->getMessageSize(), (mIncomingCompressedSize ? mIncomingCompressedSize : mMessageReader->getMessageSize()), mCurrentRecvPacketID); /* Flawfinder: ignore */
+ std::string buffer;
+ buffer = llformat( "\t%6d\t%6d\t%6d ", mMessageReader->getMessageSize(), (mIncomingCompressedSize ? mIncomingCompressedSize : mMessageReader->getMessageSize()), mCurrentRecvPacketID);
str << buffer
<< nullToEmpty(mMessageReader->getMessageName())
<< (recv_reliable ? " reliable" : "")
@@ -2092,20 +2050,18 @@ void LLMessageSystem::processUseCircuitCode(LLMessageSystem* msg,
// static
void LLMessageSystem::processError(LLMessageSystem* msg, void**)
{
- char buffer[MTUBYTES];
S32 error_code = 0;
msg->getS32("Data", "Code", error_code);
std::string error_token;
- msg->getString("Data", "Token", MTUBYTES, buffer);
- error_token.assign(buffer);
+ msg->getString("Data", "Token", error_token);
+
LLUUID error_id;
msg->getUUID("Data", "ID", error_id);
std::string error_system;
- msg->getString("Data", "System", MTUBYTES, buffer);
- error_system.assign(buffer);
+ msg->getString("Data", "System", error_system);
+
std::string error_message;
- msg->getString("Data", "Message", MTUBYTES, buffer);
- error_message.assign(buffer);
+ msg->getString("Data", "Message", error_message);
LL_WARNS("Messaging") << "Message error from " << msg->getSender() << " - "
<< error_code << " " << error_token << " " << error_id << " \""
@@ -2166,6 +2122,15 @@ void LLMessageSystem::dispatch(
handler->post(responsep, context, message);
}
+//static
+void LLMessageSystem::dispatchTemplate(const std::string& msg_name,
+ const LLSD& message,
+ LLHTTPNode::ResponsePtr responsep)
+{
+ LLTemplateMessageDispatcher dispatcher(*(gMessageSystem->mTemplateMessageReader));
+ dispatcher.dispatch(msg_name, message, responsep);
+}
+
static void check_for_unrecognized_messages(
const char* type,
const LLSD& map,
@@ -2348,6 +2313,23 @@ void process_create_trusted_circuit(LLMessageSystem *msg, void **)
return;
}
+ U32 untrusted_interface = msg->getUntrustedInterface().getAddress();
+ U32 last_interface = msg->getReceivingInterface().getAddress();
+ if ( ( untrusted_interface != INVALID_HOST_IP_ADDRESS ) && ( untrusted_interface == last_interface ) )
+ {
+ if( msg->getBlockUntrustedInterface() )
+ {
+ LL_WARNS("Messaging") << "Ignoring CreateTrustedCircuit on public interface from host: "
+ << msg->getSender() << llendl;
+ return;
+ }
+ else
+ {
+ LL_WARNS("Messaging") << "Processing CreateTrustedCircuit on public interface from host: "
+ << msg->getSender() << llendl;
+ }
+ }
+
char their_digest[MD5HEX_STR_SIZE]; /* Flawfinder: ignore */
S32 size = msg->getSizeFast(_PREHASH_DataBlock, _PREHASH_Digest);
if(size != MD5HEX_STR_BYTES)
@@ -2404,6 +2386,24 @@ void process_deny_trusted_circuit(LLMessageSystem *msg, void **)
// Don't respond to requests that use the same end point ID
return;
}
+
+ U32 untrusted_interface = msg->getUntrustedInterface().getAddress();
+ U32 last_interface = msg->getReceivingInterface().getAddress();
+ if ( ( untrusted_interface != INVALID_HOST_IP_ADDRESS ) && ( untrusted_interface == last_interface ) )
+ {
+ if( msg->getBlockUntrustedInterface() )
+ {
+ LL_WARNS("Messaging") << "Ignoring DenyTrustedCircuit on public interface from host: "
+ << msg->getSender() << llendl;
+ return;
+ }
+ else
+ {
+ LL_WARNS("Messaging") << "Processing DenyTrustedCircuit on public interface from host: "
+ << msg->getSender() << llendl;
+ }
+ }
+
// Assume that we require trust to proceed, so resend.
// This catches the case where a circuit that was trusted
@@ -2421,7 +2421,8 @@ void process_deny_trusted_circuit(LLMessageSystem *msg, void **)
void dump_prehash_files()
{
U32 i;
- LLFILE* fp = LLFile::fopen("../../indra/llmessage/message_prehash.h", "w"); /* Flawfinder: ignore */
+ std::string filename("../../indra/llmessage/message_prehash.h");
+ LLFILE* fp = LLFile::fopen(filename, "w"); /* Flawfinder: ignore */
if (fp)
{
fprintf(
@@ -2430,7 +2431,7 @@ void dump_prehash_files()
" * @file message_prehash.h\n"
" * @brief header file of externs of prehashed variables plus defines.\n"
" *\n"
- " * $LicenseInfo:firstyear=2003&license=viewergpl$"
+ " * $LicenseInfo:firstyear=2003&license=viewerlgpl$"
" * $/LicenseInfo$"
" */\n\n"
"#ifndef LL_MESSAGE_PREHASH_H\n#define LL_MESSAGE_PREHASH_H\n\n");
@@ -2451,7 +2452,8 @@ void dump_prehash_files()
fprintf(fp, "\n\n#endif\n");
fclose(fp);
}
- fp = LLFile::fopen("../../indra/llmessage/message_prehash.cpp", "w"); /* Flawfinder: ignore */
+ filename = std::string("../../indra/llmessage/message_prehash.cpp");
+ fp = LLFile::fopen(filename, "w"); /* Flawfinder: ignore */
if (fp)
{
fprintf(
@@ -2460,7 +2462,7 @@ void dump_prehash_files()
" * @file message_prehash.cpp\n"
" * @brief file of prehashed variables\n"
" *\n"
- " * $LicenseInfo:firstyear=2003&license=viewergpl$"
+ " * $LicenseInfo:firstyear=2003&license=viewerlgpl$"
" * $/LicenseInfo$"
" */\n\n"
"/**\n"
@@ -2490,15 +2492,19 @@ bool start_messaging_system(
bool b_dump_prehash_file,
const std::string& secret,
const LLUseCircuitCodeResponder* responder,
- bool failure_is_fatal)
+ bool failure_is_fatal,
+ const F32 circuit_heartbeat_interval,
+ const F32 circuit_timeout)
{
gMessageSystem = new LLMessageSystem(
- template_name.c_str(),
+ template_name,
port,
version_major,
version_minor,
version_patch,
- failure_is_fatal);
+ failure_is_fatal,
+ circuit_heartbeat_interval,
+ circuit_timeout);
g_shared_secret.assign(secret);
if (!gMessageSystem)
@@ -2587,79 +2593,79 @@ void LLMessageSystem::stopLogging()
void LLMessageSystem::summarizeLogs(std::ostream& str)
{
- char buffer[MAX_STRING]; /* Flawfinder: ignore */
- char tmp_str[MAX_STRING]; /* Flawfinder: ignore */
+ std::string buffer;
+ std::string tmp_str;
F32 run_time = mMessageSystemTimer.getElapsedTimeF32();
str << "START MESSAGE LOG SUMMARY" << std::endl;
- snprintf(buffer, MAX_STRING, "Run time: %12.3f seconds", run_time); /* Flawfinder: ignore */
+ buffer = llformat( "Run time: %12.3f seconds", run_time);
// Incoming
str << buffer << std::endl << "Incoming:" << std::endl;
- U64_to_str(mTotalBytesIn, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total bytes received: %20s (%5.2f kbits per second)", tmp_str, ((F32)mTotalBytesIn * 0.008f) / run_time); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(mTotalBytesIn);
+ buffer = llformat( "Total bytes received: %20s (%5.2f kbits per second)", tmp_str.c_str(), ((F32)mTotalBytesIn * 0.008f) / run_time);
str << buffer << std::endl;
- U64_to_str(mPacketsIn, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total packets received: %20s (%5.2f packets per second)", tmp_str, ((F32) mPacketsIn / run_time)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(mPacketsIn);
+ buffer = llformat( "Total packets received: %20s (%5.2f packets per second)", tmp_str.c_str(), ((F32) mPacketsIn / run_time));
str << buffer << std::endl;
- snprintf(buffer, MAX_STRING, "Average packet size: %20.0f bytes", (F32)mTotalBytesIn / (F32)mPacketsIn); /* Flawfinder: ignore */
+ buffer = llformat( "Average packet size: %20.0f bytes", (F32)mTotalBytesIn / (F32)mPacketsIn);
str << buffer << std::endl;
- U64_to_str(mReliablePacketsIn, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total reliable packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mReliablePacketsIn)/((F32) mPacketsIn + 1)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(mReliablePacketsIn);
+ buffer = llformat( "Total reliable packets: %20s (%5.2f%%)", tmp_str.c_str(), 100.f * ((F32) mReliablePacketsIn)/((F32) mPacketsIn + 1));
str << buffer << std::endl;
- U64_to_str(mCompressedPacketsIn, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total compressed packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mCompressedPacketsIn)/((F32) mPacketsIn + 1)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(mCompressedPacketsIn);
+ buffer = llformat( "Total compressed packets: %20s (%5.2f%%)", tmp_str.c_str(), 100.f * ((F32) mCompressedPacketsIn)/((F32) mPacketsIn + 1));
str << buffer << std::endl;
S64 savings = mUncompressedBytesIn - mCompressedBytesIn;
- U64_to_str(savings, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total compression savings: %20s bytes", tmp_str); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(savings);
+ buffer = llformat( "Total compression savings: %20s bytes", tmp_str.c_str());
str << buffer << std::endl;
- U64_to_str(savings/(mCompressedPacketsIn +1), tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Avg comp packet savings: %20s (%5.2f : 1)", tmp_str, ((F32) mUncompressedBytesIn)/((F32) mCompressedBytesIn+1)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(savings/(mCompressedPacketsIn +1));
+ buffer = llformat( "Avg comp packet savings: %20s (%5.2f : 1)", tmp_str.c_str(), ((F32) mUncompressedBytesIn)/((F32) mCompressedBytesIn+1));
str << buffer << std::endl;
- U64_to_str(savings/(mPacketsIn+1), tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Avg overall comp savings: %20s (%5.2f : 1)", tmp_str, ((F32) mTotalBytesIn + (F32) savings)/((F32) mTotalBytesIn + 1.f)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(savings/(mPacketsIn+1));
+ buffer = llformat( "Avg overall comp savings: %20s (%5.2f : 1)", tmp_str.c_str(), ((F32) mTotalBytesIn + (F32) savings)/((F32) mTotalBytesIn + 1.f));
// Outgoing
str << buffer << std::endl << std::endl << "Outgoing:" << std::endl;
- U64_to_str(mTotalBytesOut, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total bytes sent: %20s (%5.2f kbits per second)", tmp_str, ((F32)mTotalBytesOut * 0.008f) / run_time ); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(mTotalBytesOut);
+ buffer = llformat( "Total bytes sent: %20s (%5.2f kbits per second)", tmp_str.c_str(), ((F32)mTotalBytesOut * 0.008f) / run_time );
str << buffer << std::endl;
- U64_to_str(mPacketsOut, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total packets sent: %20s (%5.2f packets per second)", tmp_str, ((F32)mPacketsOut / run_time)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(mPacketsOut);
+ buffer = llformat( "Total packets sent: %20s (%5.2f packets per second)", tmp_str.c_str(), ((F32)mPacketsOut / run_time));
str << buffer << std::endl;
- snprintf(buffer, MAX_STRING, "Average packet size: %20.0f bytes", (F32)mTotalBytesOut / (F32)mPacketsOut); /* Flawfinder: ignore */
+ buffer = llformat( "Average packet size: %20.0f bytes", (F32)mTotalBytesOut / (F32)mPacketsOut);
str << buffer << std::endl;
- U64_to_str(mReliablePacketsOut, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total reliable packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mReliablePacketsOut)/((F32) mPacketsOut + 1)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(mReliablePacketsOut);
+ buffer = llformat( "Total reliable packets: %20s (%5.2f%%)", tmp_str.c_str(), 100.f * ((F32) mReliablePacketsOut)/((F32) mPacketsOut + 1));
str << buffer << std::endl;
- U64_to_str(mCompressedPacketsOut, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total compressed packets: %20s (%5.2f%%)", tmp_str, 100.f * ((F32) mCompressedPacketsOut)/((F32) mPacketsOut + 1)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(mCompressedPacketsOut);
+ buffer = llformat( "Total compressed packets: %20s (%5.2f%%)", tmp_str.c_str(), 100.f * ((F32) mCompressedPacketsOut)/((F32) mPacketsOut + 1));
str << buffer << std::endl;
savings = mUncompressedBytesOut - mCompressedBytesOut;
- U64_to_str(savings, tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Total compression savings: %20s bytes", tmp_str); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(savings);
+ buffer = llformat( "Total compression savings: %20s bytes", tmp_str.c_str());
str << buffer << std::endl;
- U64_to_str(savings/(mCompressedPacketsOut +1), tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Avg comp packet savings: %20s (%5.2f : 1)", tmp_str, ((F32) mUncompressedBytesOut)/((F32) mCompressedBytesOut+1)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(savings/(mCompressedPacketsOut +1));
+ buffer = llformat( "Avg comp packet savings: %20s (%5.2f : 1)", tmp_str.c_str(), ((F32) mUncompressedBytesOut)/((F32) mCompressedBytesOut+1));
str << buffer << std::endl;
- U64_to_str(savings/(mPacketsOut+1), tmp_str, sizeof(tmp_str));
- snprintf(buffer, MAX_STRING, "Avg overall comp savings: %20s (%5.2f : 1)", tmp_str, ((F32) mTotalBytesOut + (F32) savings)/((F32) mTotalBytesOut + 1.f)); /* Flawfinder: ignore */
+ tmp_str = U64_to_str(savings/(mPacketsOut+1));
+ buffer = llformat( "Avg overall comp savings: %20s (%5.2f : 1)", tmp_str.c_str(), ((F32) mTotalBytesOut + (F32) savings)/((F32) mTotalBytesOut + 1.f));
str << buffer << std::endl << std::endl;
- snprintf(buffer, MAX_STRING, "SendPacket failures: %20d", mSendPacketFailureCount); /* Flawfinder: ignore */
+ buffer = llformat( "SendPacket failures: %20d", mSendPacketFailureCount);
str << buffer << std::endl;
- snprintf(buffer, MAX_STRING, "Dropped packets: %20d", mDroppedPackets); /* Flawfinder: ignore */
+ buffer = llformat( "Dropped packets: %20d", mDroppedPackets);
str << buffer << std::endl;
- snprintf(buffer, MAX_STRING, "Resent packets: %20d", mResentPackets); /* Flawfinder: ignore */
+ buffer = llformat( "Resent packets: %20d", mResentPackets);
str << buffer << std::endl;
- snprintf(buffer, MAX_STRING, "Failed reliable resends: %20d", mFailedResendPackets); /* Flawfinder: ignore */
+ buffer = llformat( "Failed reliable resends: %20d", mFailedResendPackets);
str << buffer << std::endl;
- snprintf(buffer, MAX_STRING, "Off-circuit rejected packets: %17d", mOffCircuitPackets); /* Flawfinder: ignore */
+ buffer = llformat( "Off-circuit rejected packets: %17d", mOffCircuitPackets);
str << buffer << std::endl;
- snprintf(buffer, MAX_STRING, "On-circuit invalid packets: %17d", mInvalidOnCircuitPackets); /* Flawfinder: ignore */
+ buffer = llformat( "On-circuit invalid packets: %17d", mInvalidOnCircuitPackets);
str << buffer << std::endl << std::endl;
str << "Decoding: " << std::endl;
- snprintf(buffer, MAX_STRING, "%35s%10s%10s%10s%10s", "Message", "Count", "Time", "Max", "Avg"); /* Flawfinder: ignore */
+ buffer = llformat( "%35s%10s%10s%10s%10s", "Message", "Count", "Time", "Max", "Avg");
str << buffer << std:: endl;
F32 avg;
for (message_template_name_map_t::const_iterator iter = mMessageTemplates.begin(),
@@ -2670,14 +2676,14 @@ void LLMessageSystem::summarizeLogs(std::ostream& str)
if(mt->mTotalDecoded > 0)
{
avg = mt->mTotalDecodeTime / (F32)mt->mTotalDecoded;
- snprintf(buffer, MAX_STRING, "%35s%10u%10f%10f%10f", mt->mName, mt->mTotalDecoded, mt->mTotalDecodeTime, mt->mMaxDecodeTimePerMsg, avg); /* Flawfinder: ignore */
+ buffer = llformat( "%35s%10u%10f%10f%10f", mt->mName, mt->mTotalDecoded, mt->mTotalDecodeTime, mt->mMaxDecodeTimePerMsg, avg);
str << buffer << std::endl;
}
}
str << "END MESSAGE LOG SUMMARY" << std::endl;
}
-void end_messaging_system()
+void end_messaging_system(bool print_summary)
{
gTransferManager.cleanup();
LLTransferTargetVFile::updateQueue(true); // shutdown LLTransferTargetVFile
@@ -2685,9 +2691,12 @@ void end_messaging_system()
{
gMessageSystem->stopLogging();
- std::ostringstream str;
- gMessageSystem->summarizeLogs(str);
- LL_INFOS("Messaging") << str.str().c_str() << llendl;
+ if (print_summary)
+ {
+ std::ostringstream str;
+ gMessageSystem->summarizeLogs(str);
+ LL_INFOS("Messaging") << str.str().c_str() << llendl;
+ }
delete gMessageSystem;
gMessageSystem = NULL;
@@ -3936,22 +3945,41 @@ void LLMessageSystem::getString(const char *block, const char *var,
blocknum);
}
-S32 LLMessageSystem::getNumberOfBlocksFast(const char *blockname)
+void LLMessageSystem::getStringFast(const char *block, const char *var,
+ std::string& outstr, S32 blocknum)
+{
+ mMessageReader->getString(block, var, outstr, blocknum);
+}
+
+void LLMessageSystem::getString(const char *block, const char *var,
+ std::string& outstr, S32 blocknum )
+{
+ getStringFast(LLMessageStringTable::getInstance()->getString(block),
+ LLMessageStringTable::getInstance()->getString(var), outstr,
+ blocknum);
+}
+
+BOOL LLMessageSystem::has(const char *blockname) const
+{
+ return getNumberOfBlocks(blockname) > 0;
+}
+
+S32 LLMessageSystem::getNumberOfBlocksFast(const char *blockname) const
{
return mMessageReader->getNumberOfBlocks(blockname);
}
-S32 LLMessageSystem::getNumberOfBlocks(const char *blockname)
+S32 LLMessageSystem::getNumberOfBlocks(const char *blockname) const
{
return getNumberOfBlocksFast(LLMessageStringTable::getInstance()->getString(blockname));
}
-S32 LLMessageSystem::getSizeFast(const char *blockname, const char *varname)
+S32 LLMessageSystem::getSizeFast(const char *blockname, const char *varname) const
{
return mMessageReader->getSize(blockname, varname);
}
-S32 LLMessageSystem::getSize(const char *blockname, const char *varname)
+S32 LLMessageSystem::getSize(const char *blockname, const char *varname) const
{
return getSizeFast(LLMessageStringTable::getInstance()->getString(blockname),
LLMessageStringTable::getInstance()->getString(varname));
@@ -3959,13 +3987,13 @@ S32 LLMessageSystem::getSize(const char *blockname, const char *varname)
// size in bytes of variable length data
S32 LLMessageSystem::getSizeFast(const char *blockname, S32 blocknum,
- const char *varname)
+ const char *varname) const
{
return mMessageReader->getSize(blockname, blocknum, varname);
}
S32 LLMessageSystem::getSize(const char *blockname, S32 blocknum,
- const char *varname)
+ const char *varname) const
{
return getSizeFast(LLMessageStringTable::getInstance()->getString(blockname), blocknum,
LLMessageStringTable::getInstance()->getString(varname));
@@ -3992,6 +4020,7 @@ void LLMessageSystem::setTimeDecodesSpamThreshold( F32 seconds )
// TODO: babbage: move gServicePump in to LLMessageSystem?
bool LLMessageSystem::checkAllMessages(S64 frame_count, LLPumpIO* http_pump)
{
+ LLMemType mt_cam(LLMemType::MTYPE_MESSAGE_CHECK_ALL);
if(checkMessages(frame_count))
{
return true;
@@ -4001,3 +4030,26 @@ bool LLMessageSystem::checkAllMessages(S64 frame_count, LLPumpIO* http_pump)
http_pump->callback();
return (mPacketsIn - packetsIn) > 0;
}
+
+void LLMessageSystem::banUdpMessage(const std::string& name)
+{
+ message_template_name_map_t::iterator itt = mMessageTemplates.find(
+ LLMessageStringTable::getInstance()->getString(name.c_str())
+ );
+ if(itt != mMessageTemplates.end())
+ {
+ itt->second->banUdp();
+ }
+ else
+ {
+ llwarns << "Attempted to ban an unknown message: " << name << "." << llendl;
+ }
+}
+const LLHost& LLMessageSystem::getSender() const
+{
+ return mLastSender;
+}
+
+LLHTTPRegistration<LLHTTPNodeAdapter<LLTrustedMessageService> >
+ gHTTPRegistrationTrustedMessageWildcard("/trusted-message/<message-name>");
+