added message logger / builder floaters
This commit is contained in:
@@ -48,6 +48,7 @@ set(llmessage_SOURCE_FILES
|
||||
llmail.cpp
|
||||
llmessagebuilder.cpp
|
||||
llmessageconfig.cpp
|
||||
llmessagelog.cpp
|
||||
llmessagereader.cpp
|
||||
llmessagetemplate.cpp
|
||||
llmessagetemplateparser.cpp
|
||||
@@ -138,6 +139,7 @@ set(llmessage_HEADER_FILES
|
||||
llmail.h
|
||||
llmessagebuilder.h
|
||||
llmessageconfig.h
|
||||
llmessagelog.h
|
||||
llmessagereader.h
|
||||
llmessagetemplate.h
|
||||
llmessagetemplateparser.h
|
||||
|
||||
@@ -1231,6 +1231,17 @@ void LLCircuit::getCircuitRange(
|
||||
first = mCircuitData.upper_bound(key);
|
||||
}
|
||||
|
||||
// <edit>
|
||||
std::vector<LLCircuitData*> LLCircuit::getCircuitDataList()
|
||||
{
|
||||
std::vector<LLCircuitData*> list;
|
||||
circuit_data_map::iterator end = mCircuitData.end();
|
||||
for(circuit_data_map::iterator iter = mCircuitData.begin(); iter != end; ++iter)
|
||||
list.push_back((*iter).second);
|
||||
return list;
|
||||
}
|
||||
// </edit>
|
||||
|
||||
TPACKETID LLCircuitData::nextPacketOutID()
|
||||
{
|
||||
mPacketsOut++;
|
||||
|
||||
@@ -331,6 +331,10 @@ public:
|
||||
const LLHost& key,
|
||||
circuit_data_map::iterator& first,
|
||||
circuit_data_map::iterator& end);
|
||||
|
||||
// <edit>
|
||||
std::vector<LLCircuitData*> getCircuitDataList();
|
||||
// </edit>
|
||||
|
||||
// Lists that optimize how many circuits we need to traverse a frame
|
||||
// HACK - this should become protected eventually, but stupid !@$@# message system/circuit classes are jumbling things up.
|
||||
|
||||
51
indra/llmessage/llmessagelog.cpp
Normal file
51
indra/llmessage/llmessagelog.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// <edit>
|
||||
#include "llmessagelog.h"
|
||||
|
||||
LLMessageLogEntry::LLMessageLogEntry(EType type, LLHost from_host, LLHost to_host, U8* data, S32 data_size)
|
||||
: mType(type),
|
||||
mFromHost(from_host),
|
||||
mToHost(to_host),
|
||||
mDataSize(data_size)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
mData = new U8[data_size];
|
||||
memcpy(mData, data, data_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
mData = NULL;
|
||||
}
|
||||
}
|
||||
LLMessageLogEntry::~LLMessageLogEntry()
|
||||
{
|
||||
// wtf, I'm not supposed to do this?
|
||||
//if(mData && mDataSize) delete[] mData;
|
||||
}
|
||||
U32 LLMessageLog::sMaxSize = 4096; // testzone fixme todo boom
|
||||
std::deque<LLMessageLogEntry> LLMessageLog::sDeque;
|
||||
void (*(LLMessageLog::sCallback))(LLMessageLogEntry);
|
||||
void LLMessageLog::setMaxSize(U32 size)
|
||||
{
|
||||
sMaxSize = size;
|
||||
while(sDeque.size() > sMaxSize)
|
||||
sDeque.pop_front();
|
||||
}
|
||||
void LLMessageLog::setCallback(void (*callback)(LLMessageLogEntry))
|
||||
{
|
||||
sCallback = callback;
|
||||
}
|
||||
void LLMessageLog::log(LLHost from_host, LLHost to_host, U8* data, S32 data_size)
|
||||
{
|
||||
LLMessageLogEntry entry = LLMessageLogEntry(LLMessageLogEntry::TEMPLATE, from_host, to_host, data, data_size);
|
||||
if(sCallback) sCallback(entry);
|
||||
if(!sMaxSize) return;
|
||||
sDeque.push_back(entry);
|
||||
if(sDeque.size() > sMaxSize)
|
||||
sDeque.pop_front();
|
||||
}
|
||||
std::deque<LLMessageLogEntry> LLMessageLog::getDeque()
|
||||
{
|
||||
return sDeque;
|
||||
}
|
||||
// </edit>
|
||||
40
indra/llmessage/llmessagelog.h
Normal file
40
indra/llmessage/llmessagelog.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// <edit>
|
||||
#ifndef LL_LLMESSAGELOG_H
|
||||
#define LL_LLMESSAGELOG_H
|
||||
#include "stdtypes.h"
|
||||
#include "llhost.h"
|
||||
#include <queue>
|
||||
#include <string.h>
|
||||
|
||||
class LLMessageSystem;
|
||||
class LLMessageLogEntry
|
||||
{
|
||||
public:
|
||||
enum EType
|
||||
{
|
||||
TEMPLATE,
|
||||
HTTP_REQUEST,
|
||||
HTTP_RESPONSE
|
||||
};
|
||||
LLMessageLogEntry(EType type, LLHost from_host, LLHost to_host, U8* data, S32 data_size);
|
||||
~LLMessageLogEntry();
|
||||
EType mType;
|
||||
LLHost mFromHost;
|
||||
LLHost mToHost;
|
||||
S32 mDataSize;
|
||||
U8* mData;
|
||||
};
|
||||
class LLMessageLog
|
||||
{
|
||||
public:
|
||||
static void setMaxSize(U32 size);
|
||||
static void setCallback(void (*callback)(LLMessageLogEntry));
|
||||
static void log(LLHost from_host, LLHost to_host, U8* data, S32 data_size);
|
||||
static std::deque<LLMessageLogEntry> getDeque();
|
||||
private:
|
||||
static U32 sMaxSize;
|
||||
static void (*sCallback)(LLMessageLogEntry);
|
||||
static std::deque<LLMessageLogEntry> sDeque;
|
||||
};
|
||||
#endif
|
||||
// </edit>
|
||||
@@ -449,7 +449,10 @@ S32 LLTemplateMessageReader::getMessageSize() const
|
||||
// Returns template for the message contained in buffer
|
||||
BOOL LLTemplateMessageReader::decodeTemplate(
|
||||
const U8* buffer, S32 buffer_size, // inputs
|
||||
LLMessageTemplate** msg_template ) // outputs
|
||||
// <edit>
|
||||
//LLMessageTemplate** msg_template ) // outputs
|
||||
LLMessageTemplate** msg_template, BOOL custom)
|
||||
// </edit>
|
||||
{
|
||||
const U8* header = buffer + LL_PACKET_ID_SIZE;
|
||||
|
||||
@@ -491,6 +494,9 @@ BOOL LLTemplateMessageReader::decodeTemplate(
|
||||
}
|
||||
else // bogus packet received (too short)
|
||||
{
|
||||
// <edit>
|
||||
if(!custom)
|
||||
// </edit>
|
||||
llwarns << "Packet with unusable length received (too short): "
|
||||
<< buffer_size << llendl;
|
||||
return(FALSE);
|
||||
@@ -503,9 +509,16 @@ BOOL LLTemplateMessageReader::decodeTemplate(
|
||||
}
|
||||
else
|
||||
{
|
||||
// <edit>
|
||||
if(!custom)
|
||||
{
|
||||
// </edit>
|
||||
llwarns << "Message #" << std::hex << num << std::dec
|
||||
<< " received but not registered!" << llendl;
|
||||
gMessageSystem->callExceptionFunc(MX_UNREGISTERED_MESSAGE);
|
||||
// <edit>
|
||||
}
|
||||
// </edit>
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
@@ -532,7 +545,9 @@ void LLTemplateMessageReader::logRanOffEndOfPacket( const LLHost& host, const S3
|
||||
}
|
||||
|
||||
// decode a given message
|
||||
BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender )
|
||||
//BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender )
|
||||
BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender, BOOL custom)
|
||||
// </edit>
|
||||
{
|
||||
llassert( mReceiveSize >= 0 );
|
||||
llassert( mCurrentRMessageTemplate);
|
||||
@@ -590,6 +605,9 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
|
||||
}
|
||||
else
|
||||
{
|
||||
// <edit>
|
||||
if(!custom)
|
||||
// </edit>
|
||||
llerrs << "Unknown block type" << llendl;
|
||||
return FALSE;
|
||||
}
|
||||
@@ -636,6 +654,9 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
|
||||
|
||||
if ((decode_pos + data_size) > mReceiveSize)
|
||||
{
|
||||
// <edit>
|
||||
if(!custom)
|
||||
// </edit>
|
||||
logRanOffEndOfPacket(sender, decode_pos, data_size);
|
||||
|
||||
// default to 0 length variable blocks
|
||||
@@ -672,6 +693,9 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
|
||||
// so, copy data pointer and set data size to fixed size
|
||||
if ((decode_pos + mvci.getSize()) > mReceiveSize)
|
||||
{
|
||||
// <edit>
|
||||
if(!custom)
|
||||
// </edit>
|
||||
logRanOffEndOfPacket(sender, decode_pos, mvci.getSize());
|
||||
|
||||
// default to 0s.
|
||||
@@ -699,7 +723,10 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
|
||||
lldebugs << "Empty message '" << mCurrentRMessageTemplate->mName << "' (no blocks)" << llendl;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// <edit>
|
||||
if(!custom)
|
||||
// </edit>
|
||||
{
|
||||
static LLTimer decode_timer;
|
||||
|
||||
@@ -755,11 +782,18 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
|
||||
BOOL LLTemplateMessageReader::validateMessage(const U8* buffer,
|
||||
S32 buffer_size,
|
||||
const LLHost& sender,
|
||||
bool trusted)
|
||||
bool trusted,
|
||||
// <edit>
|
||||
BOOL custom)
|
||||
// </edit>)
|
||||
{
|
||||
mReceiveSize = buffer_size;
|
||||
BOOL valid = decodeTemplate(buffer, buffer_size, &mCurrentRMessageTemplate );
|
||||
if(valid)
|
||||
// <edit>
|
||||
//BOOL valid = decodeTemplate(buffer, buffer_size, &mCurrentRMessageTemplate );
|
||||
BOOL valid = decodeTemplate(buffer, buffer_size, &mCurrentRMessageTemplate, custom );
|
||||
//if(result)
|
||||
if(valid && !custom)
|
||||
// </edit>
|
||||
{
|
||||
mCurrentRMessageTemplate->mReceiveCount++;
|
||||
//lldebugs << "MessageRecvd:"
|
||||
@@ -799,12 +833,21 @@ const char* LLTemplateMessageReader::getMessageName() const
|
||||
{
|
||||
if (!mCurrentRMessageTemplate)
|
||||
{
|
||||
llwarns << "no mCurrentRMessageTemplate" << llendl;
|
||||
// <edit>
|
||||
//llwarns << "no mCurrentRMessageTemplate" << llendl;
|
||||
// </edit>
|
||||
return "";
|
||||
}
|
||||
return mCurrentRMessageTemplate->mName;
|
||||
}
|
||||
|
||||
// <edit>
|
||||
LLMessageTemplate* LLTemplateMessageReader::getTemplate()
|
||||
{
|
||||
return mCurrentRMessageTemplate;
|
||||
}
|
||||
// </edit>
|
||||
|
||||
//virtual
|
||||
bool LLTemplateMessageReader::isTrusted() const
|
||||
{
|
||||
|
||||
@@ -101,11 +101,18 @@ public:
|
||||
|
||||
virtual const char* getMessageName() const;
|
||||
virtual S32 getMessageSize() const;
|
||||
|
||||
// <edit>
|
||||
LLMessageTemplate* getTemplate();
|
||||
// </edit>
|
||||
|
||||
virtual void copyToBuilder(LLMessageBuilder&) const;
|
||||
|
||||
BOOL validateMessage(const U8* buffer, S32 buffer_size,
|
||||
const LLHost& sender, bool trusted = false);
|
||||
BOOL validateMessage(const U8* buffer, S32 buffer_size,
|
||||
// <edit>
|
||||
// const LLHost& sender);
|
||||
const LLHost& sender, bool trusted = false, BOOL custom = FALSE);
|
||||
// </edit>
|
||||
BOOL readMessage(const U8* buffer, const LLHost& sender);
|
||||
|
||||
bool isTrusted() const;
|
||||
@@ -118,11 +125,19 @@ private:
|
||||
S32 size = 0, S32 blocknum = 0, S32 max_size = S32_MAX);
|
||||
|
||||
BOOL decodeTemplate(const U8* buffer, S32 buffer_size, // inputs
|
||||
LLMessageTemplate** msg_template ); // outputs
|
||||
// <edit>
|
||||
// LLMessageTemplate** msg_template ); // outputs
|
||||
LLMessageTemplate** msg_template, BOOL custom = FALSE);
|
||||
// </edit>
|
||||
|
||||
void logRanOffEndOfPacket( const LLHost& host, const S32 where, const S32 wanted );
|
||||
|
||||
BOOL decodeData(const U8* buffer, const LLHost& sender );
|
||||
// <edit>
|
||||
//BOOL decodeData(const U8* buffer, const LLHost& sender );
|
||||
public:
|
||||
BOOL decodeData(const U8* buffer, const LLHost& sender, BOOL custom = FALSE);
|
||||
private:
|
||||
// </edit>
|
||||
|
||||
S32 mReceiveSize;
|
||||
LLMessageTemplate* mCurrentRMessageTemplate;
|
||||
|
||||
@@ -87,6 +87,11 @@
|
||||
#include "v4math.h"
|
||||
#include "lltransfertargetvfile.h"
|
||||
|
||||
// <edit>
|
||||
#include "llrand.h"
|
||||
#include "llmessagelog.h"
|
||||
// </edit>
|
||||
|
||||
// Constants
|
||||
//const char* MESSAGE_LOG_FILENAME = "message.log";
|
||||
static const F32 CIRCUIT_DUMP_TIMEOUT = 30.f;
|
||||
@@ -562,6 +567,14 @@ BOOL LLMessageSystem::checkMessages( S64 frame_count )
|
||||
// If you want to dump all received packets into SecondLife.log, uncomment this
|
||||
//dumpPacketToLog();
|
||||
|
||||
// <edit>
|
||||
if(mTrueReceiveSize)
|
||||
{
|
||||
LLMessageLog::log(mLastSender, LLHost(16777343, mPort), buffer, mTrueReceiveSize);
|
||||
}
|
||||
// </edit>
|
||||
|
||||
|
||||
if (receive_size < (S32) LL_MINIMUM_VALID_PACKET_SIZE)
|
||||
{
|
||||
// A receive size of zero is OK, that means that there are no more packets available.
|
||||
@@ -1554,6 +1567,13 @@ void LLMessageSystem::getCircuitInfo(LLSD& info) const
|
||||
mCircuitInfo.getInfo(info);
|
||||
}
|
||||
|
||||
// <edit>
|
||||
LLCircuit* LLMessageSystem::getCircuit()
|
||||
{
|
||||
return &mCircuitInfo;
|
||||
}
|
||||
// </edit>
|
||||
|
||||
// returns whether the given host is on a trusted circuit
|
||||
BOOL LLMessageSystem::getCircuitTrust(const LLHost &host)
|
||||
{
|
||||
|
||||
@@ -231,11 +231,15 @@ class LLMessageSystem : public LLMessageSenderInterface
|
||||
typedef std::map<const char *, LLMessageTemplate*> message_template_name_map_t;
|
||||
typedef std::map<U32, LLMessageTemplate*> message_template_number_map_t;
|
||||
|
||||
private:
|
||||
// <edit>
|
||||
//private:
|
||||
// </edit>
|
||||
message_template_name_map_t mMessageTemplates;
|
||||
message_template_number_map_t mMessageNumbers;
|
||||
|
||||
public:
|
||||
// <edit>
|
||||
//public:
|
||||
// </edit>
|
||||
S32 mSystemVersionMajor;
|
||||
S32 mSystemVersionMinor;
|
||||
S32 mSystemVersionPatch;
|
||||
@@ -569,6 +573,9 @@ public:
|
||||
|
||||
void showCircuitInfo();
|
||||
void getCircuitInfo(LLSD& info) const;
|
||||
// <edit>
|
||||
LLCircuit* getCircuit();
|
||||
// </edit>
|
||||
|
||||
U32 getOurCircuitCode();
|
||||
|
||||
|
||||
@@ -55,6 +55,11 @@
|
||||
#include "llhost.h"
|
||||
#include "lltimer.h"
|
||||
#include "indra_constants.h"
|
||||
// <edit>
|
||||
#include "llmessagelog.h"
|
||||
#include "message.h"
|
||||
// </edit>
|
||||
|
||||
|
||||
#include "llsocks5.h"
|
||||
|
||||
@@ -421,6 +426,10 @@ S32 receive_packet(int hSocket, char * receiveBuffer)
|
||||
// Returns TRUE on success.
|
||||
BOOL send_packet(int hSocket, const char *sendBuffer, int size, U32 recipient, int nPort)
|
||||
{
|
||||
// <edit>
|
||||
LLMessageLog::log(LLHost(16777343, gMessageSystem->getListenPort()), LLHost(recipient, nPort), (U8*)sendBuffer, size);
|
||||
// </edit>
|
||||
|
||||
// Sends a packet to the address set in initNet
|
||||
//
|
||||
int nRet = 0;
|
||||
|
||||
Reference in New Issue
Block a user