00001
00032 #ifndef LL_MESSAGE_H
00033 #define LL_MESSAGE_H
00034
00035 #include <cstring>
00036 #include <set>
00037
00038 #if LL_LINUX
00039 #include <endian.h>
00040 #include <netinet/in.h>
00041 #endif
00042
00043 #if LL_SOLARIS
00044 #include <netinet/in.h>
00045 #endif
00046
00047 #if LL_WINDOWS
00048 #include "winsock2.h"
00049 #endif
00050
00051 #include "llerror.h"
00052 #include "net.h"
00053 #include "string_table.h"
00054 #include "llcircuit.h"
00055 #include "lltimer.h"
00056 #include "llpacketring.h"
00057 #include "llhost.h"
00058 #include "llhttpclient.h"
00059 #include "llhttpnode.h"
00060 #include "llpacketack.h"
00061 #include "message_prehash.h"
00062 #include "llstl.h"
00063 #include "llmsgvariabletype.h"
00064 #include "llmsgvariabletype.h"
00065
00066 const U32 MESSAGE_MAX_STRINGS_LENGTH = 64;
00067 const U32 MESSAGE_NUMBER_OF_HASH_BUCKETS = 8192;
00068
00069 const S32 MESSAGE_MAX_PER_FRAME = 400;
00070
00071 class LLMessageStringTable : public LLSingleton<LLMessageStringTable>
00072 {
00073 public:
00074 LLMessageStringTable();
00075 ~LLMessageStringTable();
00076
00077 char *getString(const char *str);
00078
00079 U32 mUsed;
00080 BOOL mEmpty[MESSAGE_NUMBER_OF_HASH_BUCKETS];
00081 char mString[MESSAGE_NUMBER_OF_HASH_BUCKETS][MESSAGE_MAX_STRINGS_LENGTH];
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 const S32 MAX_MESSAGE_INTERNAL_NAME_SIZE = 255;
00127 const S32 MAX_BUFFER_SIZE = NET_BUFFER_SIZE;
00128 const S32 MAX_BLOCKS = 255;
00129
00130 const U8 LL_ZERO_CODE_FLAG = 0x80;
00131 const U8 LL_RELIABLE_FLAG = 0x40;
00132 const U8 LL_RESENT_FLAG = 0x20;
00133 const U8 LL_ACK_FLAG = 0x10;
00134
00135
00136 const S32 LL_MINIMUM_VALID_PACKET_SIZE = LL_PACKET_ID_SIZE + 1;
00137 enum EPacketHeaderLayout
00138 {
00139 PHL_FLAGS = 0,
00140 PHL_PACKET_ID = 1,
00141 PHL_OFFSET = 5,
00142 PHL_NAME = 6
00143 };
00144
00145
00146 const S32 LL_DEFAULT_RELIABLE_RETRIES = 3;
00147 const F32 LL_MINIMUM_RELIABLE_TIMEOUT_SECONDS = 1.f;
00148 const F32 LL_MINIMUM_SEMIRELIABLE_TIMEOUT_SECONDS = 1.f;
00149 const F32 LL_PING_BASED_TIMEOUT_DUMMY = 0.0f;
00150
00151
00152
00153
00154 const F32 LL_SEMIRELIABLE_TIMEOUT_FACTOR = 5.f / 1000.f;
00155 const F32 LL_RELIABLE_TIMEOUT_FACTOR = 5.f / 1000.f;
00156 const F32 LL_FILE_XFER_TIMEOUT_FACTOR = 5.f / 1000.f;
00157 const F32 LL_LOST_TIMEOUT_FACTOR = 16.f / 1000.f;
00158 const F32 LL_MAX_LOST_TIMEOUT = 5.f;
00159
00160 const S32 MAX_MESSAGE_COUNT_NUM = 1024;
00161
00162
00163 class LLCircuit;
00164 class LLVector3;
00165 class LLVector4;
00166 class LLVector3d;
00167 class LLQuaternion;
00168 class LLSD;
00169 class LLUUID;
00170 class LLMessageSystem;
00171 class LLPumpIO;
00172
00173
00174 enum EMessageException
00175 {
00176 MX_UNREGISTERED_MESSAGE,
00177 MX_PACKET_TOO_SHORT,
00178 MX_RAN_OFF_END_OF_PACKET,
00179 MX_WROTE_PAST_BUFFER_SIZE
00180 };
00181 typedef void (*msg_exception_callback)(LLMessageSystem*,void*,EMessageException);
00182
00183
00184
00185 class LLMsgData;
00186 class LLMsgBlkData;
00187 class LLMessageTemplate;
00188
00189 class LLMessagePollInfo;
00190 class LLMessageBuilder;
00191 class LLTemplateMessageBuilder;
00192 class LLSDMessageBuilder;
00193 class LLMessageReader;
00194 class LLTemplateMessageReader;
00195 class LLSDMessageReader;
00196
00197
00198
00199 class LLUseCircuitCodeResponder
00200 {
00201 LOG_CLASS(LLMessageSystem);
00202
00203 public:
00204 virtual ~LLUseCircuitCodeResponder();
00205 virtual void complete(const LLHost& host, const LLUUID& agent) const = 0;
00206 };
00207
00208 class LLMessageSystem
00209 {
00210 private:
00211 U8 mSendBuffer[MAX_BUFFER_SIZE];
00212 S32 mSendSize;
00213
00214 public:
00215 LLPacketRing mPacketRing;
00216 LLReliablePacketParams mReliablePacketParams;
00217
00218
00219 BOOL mVerboseLog;
00220
00221 F32 mMessageFileVersionNumber;
00222
00223 typedef std::map<const char *, LLMessageTemplate*> message_template_name_map_t;
00224 typedef std::map<U32, LLMessageTemplate*> message_template_number_map_t;
00225
00226 private:
00227 message_template_name_map_t mMessageTemplates;
00228 message_template_number_map_t mMessageNumbers;
00229
00230 public:
00231 S32 mSystemVersionMajor;
00232 S32 mSystemVersionMinor;
00233 S32 mSystemVersionPatch;
00234 S32 mSystemVersionServer;
00235 U32 mVersionFlags;
00236
00237 BOOL mbProtected;
00238
00239 U32 mNumberHighFreqMessages;
00240 U32 mNumberMediumFreqMessages;
00241 U32 mNumberLowFreqMessages;
00242 S32 mPort;
00243 S32 mSocket;
00244
00245 U32 mPacketsIn;
00246 U32 mPacketsOut;
00247
00248 U64 mBytesIn;
00249 U64 mBytesOut;
00250
00251 U32 mCompressedPacketsIn;
00252 U32 mCompressedPacketsOut;
00253
00254 U32 mReliablePacketsIn;
00255 U32 mReliablePacketsOut;
00256
00257 U32 mDroppedPackets;
00258 U32 mResentPackets;
00259 U32 mFailedResendPackets;
00260 U32 mOffCircuitPackets;
00261 U32 mInvalidOnCircuitPackets;
00262
00263 S64 mUncompressedBytesIn;
00264 S64 mUncompressedBytesOut;
00265 S64 mCompressedBytesIn;
00266 S64 mCompressedBytesOut;
00267 S64 mTotalBytesIn;
00268 S64 mTotalBytesOut;
00269
00270 BOOL mSendReliable;
00271
00272 LLCircuit mCircuitInfo;
00273 F64 mCircuitPrintTime;
00274 F32 mCircuitPrintFreq;
00275
00276 std::map<U64, U32> mIPPortToCircuitCode;
00277 std::map<U32, U64> mCircuitCodeToIPPort;
00278 U32 mOurCircuitCode;
00279 S32 mSendPacketFailureCount;
00280 S32 mUnackedListDepth;
00281 S32 mUnackedListSize;
00282 S32 mDSMaxListDepth;
00283
00284 public:
00285
00286 LLMessageSystem(const char *filename, U32 port, S32 version_major,
00287 S32 version_minor, S32 version_patch);
00288
00289 ~LLMessageSystem();
00290
00291 BOOL isOK() const { return !mbError; }
00292 S32 getErrorCode() const { return mErrorCode; }
00293
00294
00295
00296
00297 void loadTemplateFile(const char* filename);
00298
00299
00300
00301 void setHandlerFuncFast(const char *name, void (*handler_func)(LLMessageSystem *msgsystem, void **user_data), void **user_data = NULL);
00302 void setHandlerFunc(const char *name, void (*handler_func)(LLMessageSystem *msgsystem, void **user_data), void **user_data = NULL)
00303 {
00304 setHandlerFuncFast(LLMessageStringTable::getInstance()->getString(name), handler_func, user_data);
00305 }
00306
00307
00308 void setExceptionFunc(EMessageException exception, msg_exception_callback func, void* data = NULL);
00309
00310
00311 BOOL callExceptionFunc(EMessageException exception);
00312
00313
00314
00315
00316 typedef void (*msg_timing_callback)(const char* hashed_name, F32 time, void* data);
00317 void setTimingFunc(msg_timing_callback func, void* data = NULL);
00318 msg_timing_callback getTimingCallback()
00319 {
00320 return mTimingCallback;
00321 }
00322 void* getTimingCallbackData()
00323 {
00324 return mTimingCallbackData;
00325 }
00326
00327
00328 BOOL isCircuitCodeKnown(U32 code) const;
00329
00330
00331
00332 bool addCircuitCode(U32 code, const LLUUID& session_id);
00333
00334 BOOL poll(F32 seconds);
00335 BOOL checkMessages( S64 frame_count = 0 );
00336 void processAcks();
00337
00338 BOOL isMessageFast(const char *msg);
00339 BOOL isMessage(const char *msg)
00340 {
00341 return isMessageFast(LLMessageStringTable::getInstance()->getString(msg));
00342 }
00343
00344 void dumpPacketToLog();
00345
00346 char *getMessageName();
00347
00348 const LLHost& getSender() const;
00349 U32 getSenderIP() const;
00350 U32 getSenderPort() const;
00351
00352
00353
00354
00355 const LLUUID& getSenderID() const;
00356
00357
00358
00359 const LLUUID& getSenderSessionID() const;
00360
00361
00362 void setMySessionID(const LLUUID& session_id) { mSessionID = session_id; }
00363 const LLUUID& getMySessionID() { return mSessionID; }
00364
00365 void newMessageFast(const char *name);
00366 void newMessage(const char *name);
00367
00368 void copyMessageRtoS();
00369 void clearMessage();
00370
00371 void nextBlockFast(const char *blockname);
00372 void nextBlock(const char *blockname)
00373 {
00374 nextBlockFast(LLMessageStringTable::getInstance()->getString(blockname));
00375 }
00376
00377 public:
00378 void addBinaryDataFast(const char *varname, const void *data, S32 size);
00379 void addBinaryData(const char *varname, const void *data, S32 size);
00380
00381 void addBOOLFast( const char* varname, BOOL b);
00382 void addBOOL( const char* varname, BOOL b);
00383 void addS8Fast( const char *varname, S8 s);
00384 void addS8( const char *varname, S8 s);
00385 void addU8Fast( const char *varname, U8 u);
00386 void addU8( const char *varname, U8 u);
00387 void addS16Fast( const char *varname, S16 i);
00388 void addS16( const char *varname, S16 i);
00389 void addU16Fast( const char *varname, U16 i);
00390 void addU16( const char *varname, U16 i);
00391 void addF32Fast( const char *varname, F32 f);
00392 void addF32( const char *varname, F32 f);
00393 void addS32Fast( const char *varname, S32 s);
00394 void addS32( const char *varname, S32 s);
00395 void addU32Fast( const char *varname, U32 u);
00396 void addU32( const char *varname, U32 u);
00397 void addU64Fast( const char *varname, U64 lu);
00398 void addU64( const char *varname, U64 lu);
00399 void addF64Fast( const char *varname, F64 d);
00400 void addF64( const char *varname, F64 d);
00401 void addVector3Fast( const char *varname, const LLVector3& vec);
00402 void addVector3( const char *varname, const LLVector3& vec);
00403 void addVector4Fast( const char *varname, const LLVector4& vec);
00404 void addVector4( const char *varname, const LLVector4& vec);
00405 void addVector3dFast( const char *varname, const LLVector3d& vec);
00406 void addVector3d( const char *varname, const LLVector3d& vec);
00407 void addQuatFast( const char *varname, const LLQuaternion& quat);
00408 void addQuat( const char *varname, const LLQuaternion& quat);
00409 void addUUIDFast( const char *varname, const LLUUID& uuid);
00410 void addUUID( const char *varname, const LLUUID& uuid);
00411 void addIPAddrFast( const char *varname, const U32 ip);
00412 void addIPAddr( const char *varname, const U32 ip);
00413 void addIPPortFast( const char *varname, const U16 port);
00414 void addIPPort( const char *varname, const U16 port);
00415 void addStringFast( const char* varname, const char* s);
00416 void addString( const char* varname, const char* s);
00417 void addStringFast( const char* varname, const std::string& s);
00418 void addString( const char* varname, const std::string& s);
00419
00420 S32 getCurrentSendTotal() const;
00421 TPACKETID getCurrentRecvPacketID() { return mCurrentRecvPacketID; }
00422
00423
00424
00425
00426
00427 BOOL isSendFull(const char* blockname = NULL);
00428 BOOL isSendFullFast(const char* blockname = NULL);
00429
00430 BOOL removeLastBlock();
00431
00432
00433
00434 S32 zeroCode(U8 **data, S32 *data_size);
00435 S32 zeroCodeExpand(U8 **data, S32 *data_size);
00436 S32 zeroCodeAdjustCurrentSendTotal();
00437
00438
00439 S32 sendReliable(const LLHost &host);
00440
00441
00442 S32 sendReliable(const U32 circuit) { return sendReliable(findHost(circuit)); }
00443
00444
00445 S32 sendReliable( const LLHost &host,
00446 S32 retries,
00447 BOOL ping_based_retries,
00448 F32 timeout,
00449 void (*callback)(void **,S32),
00450 void ** callback_data);
00451
00452 S32 sendSemiReliable( const LLHost &host,
00453 void (*callback)(void **,S32), void ** callback_data);
00454
00455
00456 S32 flushSemiReliable( const LLHost &host,
00457 void (*callback)(void **,S32), void ** callback_data);
00458
00459 S32 flushReliable( const LLHost &host );
00460
00461 void forwardMessage(const LLHost &host);
00462 void forwardReliable(const LLHost &host);
00463 void forwardReliable(const U32 circuit_code);
00464 S32 forwardReliable(
00465 const LLHost &host,
00466 S32 retries,
00467 BOOL ping_based_timeout,
00468 F32 timeout,
00469 void (*callback)(void **,S32),
00470 void ** callback_data);
00471
00472 LLHTTPClient::ResponderPtr createResponder(const std::string& name);
00473 S32 sendMessage(const LLHost &host);
00474 S32 sendMessage(const U32 circuit);
00475 S32 sendMessage(const LLHost &host, const char* name,
00476 const LLSD& message);
00477
00478
00479
00480 void getBinaryDataFast(const char *blockname, const char *varname, void *datap, S32 size, S32 blocknum = 0, S32 max_size = S32_MAX);
00481 void getBinaryData(const char *blockname, const char *varname, void *datap, S32 size, S32 blocknum = 0, S32 max_size = S32_MAX);
00482 void getBOOLFast( const char *block, const char *var, BOOL &data, S32 blocknum = 0);
00483 void getBOOL( const char *block, const char *var, BOOL &data, S32 blocknum = 0);
00484 void getS8Fast( const char *block, const char *var, S8 &data, S32 blocknum = 0);
00485 void getS8( const char *block, const char *var, S8 &data, S32 blocknum = 0);
00486 void getU8Fast( const char *block, const char *var, U8 &data, S32 blocknum = 0);
00487 void getU8( const char *block, const char *var, U8 &data, S32 blocknum = 0);
00488 void getS16Fast( const char *block, const char *var, S16 &data, S32 blocknum = 0);
00489 void getS16( const char *block, const char *var, S16 &data, S32 blocknum = 0);
00490 void getU16Fast( const char *block, const char *var, U16 &data, S32 blocknum = 0);
00491 void getU16( const char *block, const char *var, U16 &data, S32 blocknum = 0);
00492 void getS32Fast( const char *block, const char *var, S32 &data, S32 blocknum = 0);
00493 void getS32( const char *block, const char *var, S32 &data, S32 blocknum = 0);
00494 void getF32Fast( const char *block, const char *var, F32 &data, S32 blocknum = 0);
00495 void getF32( const char *block, const char *var, F32 &data, S32 blocknum = 0);
00496 void getU32Fast( const char *block, const char *var, U32 &data, S32 blocknum = 0);
00497 void getU32( const char *block, const char *var, U32 &data, S32 blocknum = 0);
00498 void getU64Fast( const char *block, const char *var, U64 &data, S32 blocknum = 0);
00499 void getU64( const char *block, const char *var, U64 &data, S32 blocknum = 0);
00500 void getF64Fast( const char *block, const char *var, F64 &data, S32 blocknum = 0);
00501 void getF64( const char *block, const char *var, F64 &data, S32 blocknum = 0);
00502 void getVector3Fast( const char *block, const char *var, LLVector3 &vec, S32 blocknum = 0);
00503 void getVector3( const char *block, const char *var, LLVector3 &vec, S32 blocknum = 0);
00504 void getVector4Fast( const char *block, const char *var, LLVector4 &vec, S32 blocknum = 0);
00505 void getVector4( const char *block, const char *var, LLVector4 &vec, S32 blocknum = 0);
00506 void getVector3dFast(const char *block, const char *var, LLVector3d &vec, S32 blocknum = 0);
00507 void getVector3d(const char *block, const char *var, LLVector3d &vec, S32 blocknum = 0);
00508 void getQuatFast( const char *block, const char *var, LLQuaternion &q, S32 blocknum = 0);
00509 void getQuat( const char *block, const char *var, LLQuaternion &q, S32 blocknum = 0);
00510 void getUUIDFast( const char *block, const char *var, LLUUID &uuid, S32 blocknum = 0);
00511 void getUUID( const char *block, const char *var, LLUUID &uuid, S32 blocknum = 0);
00512 void getIPAddrFast( const char *block, const char *var, U32 &ip, S32 blocknum = 0);
00513 void getIPAddr( const char *block, const char *var, U32 &ip, S32 blocknum = 0);
00514 void getIPPortFast( const char *block, const char *var, U16 &port, S32 blocknum = 0);
00515 void getIPPort( const char *block, const char *var, U16 &port, S32 blocknum = 0);
00516 void getStringFast( const char *block, const char *var, S32 buffer_size, char *buffer, S32 blocknum = 0);
00517 void getString( const char *block, const char *var, S32 buffer_size, char *buffer, S32 blocknum = 0);
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 bool generateDigestForNumberAndUUIDs(char* digest, const U32 number, const LLUUID &id1, const LLUUID &id2) const;
00528 bool generateDigestForWindowAndUUIDs(char* digest, const S32 window, const LLUUID &id1, const LLUUID &id2) const;
00529 bool isMatchingDigestForWindowAndUUIDs(const char* digest, const S32 window, const LLUUID &id1, const LLUUID &id2) const;
00530
00531 bool generateDigestForNumber(char* digest, const U32 number) const;
00532 bool generateDigestForWindow(char* digest, const S32 window) const;
00533 bool isMatchingDigestForWindow(const char* digest, const S32 window) const;
00534
00535 void showCircuitInfo();
00536 void getCircuitInfo(LLSD& info) const;
00537
00538 U32 getOurCircuitCode();
00539
00540 void enableCircuit(const LLHost &host, BOOL trusted);
00541 void disableCircuit(const LLHost &host);
00542
00543
00544
00545 void sendCreateTrustedCircuit(const LLHost& host, const LLUUID & id1, const LLUUID & id2);
00546
00547
00548
00549
00550
00551 void sendDenyTrustedCircuit(const LLHost &host);
00552
00554 bool isTrustedSender(const LLHost& host) const;
00555
00557 bool isTrustedMessage(const std::string& name) const;
00558
00560 bool isUntrustedMessage(const std::string& name) const;
00561
00562 private:
00563
00564 typedef std::set<LLHost> host_set_t;
00565 host_set_t mDenyTrustedCircuitSet;
00566
00567
00568
00569 void reallySendDenyTrustedCircuit(const LLHost &host);
00570
00571 public:
00572
00573
00574
00575 void establishBidirectionalTrust(const LLHost &host, S64 frame_count = 0);
00576
00577
00578 BOOL getCircuitTrust(const LLHost &host);
00579
00580 void setCircuitAllowTimeout(const LLHost &host, BOOL allow);
00581 void setCircuitTimeoutCallback(const LLHost &host, void (*callback_func)(const LLHost &host, void *user_data), void *user_data);
00582
00583 BOOL checkCircuitBlocked(const U32 circuit);
00584 BOOL checkCircuitAlive(const U32 circuit);
00585 BOOL checkCircuitAlive(const LLHost &host);
00586 void setCircuitProtection(BOOL b_protect);
00587 U32 findCircuitCode(const LLHost &host);
00588 LLHost findHost(const U32 circuit_code);
00589 void sanityCheck();
00590
00591 S32 getNumberOfBlocksFast(const char *blockname);
00592 S32 getNumberOfBlocks(const char *blockname);
00593 S32 getSizeFast(const char *blockname, const char *varname);
00594 S32 getSize(const char *blockname, const char *varname);
00595 S32 getSizeFast(const char *blockname, S32 blocknum,
00596 const char *varname);
00597 S32 getSize(const char *blockname, S32 blocknum, const char *varname);
00598
00599 void resetReceiveCounts();
00600 void dumpReceiveCounts();
00601 void dumpCircuitInfo();
00602
00603 BOOL isClear() const;
00604 S32 flush(const LLHost &host);
00605
00606 U32 getListenPort( void ) const;
00607
00608 void startLogging();
00609 void stopLogging();
00610 void summarizeLogs(std::ostream& str);
00611
00612 S32 getReceiveSize() const;
00613 S32 getReceiveCompressedSize() const { return mIncomingCompressedSize; }
00614 S32 getReceiveBytes() const;
00615
00616 S32 getUnackedListSize() const { return mUnackedListSize; }
00617
00618
00619
00620
00621
00622 friend std::ostream& operator<<(std::ostream& s, LLMessageSystem &msg);
00623
00624 void setMaxMessageTime(const F32 seconds);
00625 void setMaxMessageCounts(const S32 num);
00626
00627 static U64 getMessageTimeUsecs(const BOOL update = FALSE);
00628 static F64 getMessageTimeSeconds(const BOOL update = FALSE);
00629
00630 static void setTimeDecodes(BOOL b);
00631 static void setTimeDecodesSpamThreshold(F32 seconds);
00632
00633
00634
00635 static void processAddCircuitCode(LLMessageSystem* msg, void**);
00636 static void processUseCircuitCode(LLMessageSystem* msg, void**);
00637 static void processError(LLMessageSystem* msg, void**);
00638
00639
00640 static void dispatch(const std::string& msg_name,
00641 const LLSD& message);
00642 static void dispatch(const std::string& msg_name,
00643 const LLSD& message,
00644 LLHTTPNode::ResponsePtr responsep);
00645
00646 void setMessageBans(const LLSD& trusted, const LLSD& untrusted);
00647
00661 S32 sendError(
00662 const LLHost& host,
00663 const LLUUID& agent_id,
00664 S32 code,
00665 const std::string& token,
00666 const LLUUID& id,
00667 const std::string& system,
00668 const std::string& message,
00669 const LLSD& data);
00670
00671
00672 bool checkAllMessages(S64 frame_count, LLPumpIO* http_pump);
00673
00674 private:
00675
00676
00677
00678 typedef std::map<U32, LLUUID> code_session_map_t;
00679 code_session_map_t mCircuitCodes;
00680
00681
00682
00683 LLUUID mSessionID;
00684
00685 void addTemplate(LLMessageTemplate *templatep);
00686 void clearReceiveState();
00687 BOOL decodeTemplate( const U8* buffer, S32 buffer_size, LLMessageTemplate** msg_template );
00688
00689 void logMsgFromInvalidCircuit( const LLHost& sender, BOOL recv_reliable );
00690 void logTrustedMsgFromUntrustedCircuit( const LLHost& sender );
00691 void logValidMsg(LLCircuitData *cdp, const LLHost& sender, BOOL recv_reliable, BOOL recv_resent, BOOL recv_acks );
00692 void logRanOffEndOfPacket( const LLHost& sender );
00693
00694 class LLMessageCountInfo
00695 {
00696 public:
00697 U32 mMessageNum;
00698 U32 mMessageBytes;
00699 BOOL mInvalid;
00700 };
00701
00702 LLMessagePollInfo *mPollInfop;
00703
00704 U8 mEncodedRecvBuffer[MAX_BUFFER_SIZE];
00705 U8 mTrueReceiveBuffer[MAX_BUFFER_SIZE];
00706 S32 mTrueReceiveSize;
00707
00708
00709
00710 BOOL mbError;
00711 S32 mErrorCode;
00712
00713 F64 mResendDumpTime;
00714
00715 LLMessageCountInfo mMessageCountList[MAX_MESSAGE_COUNT_NUM];
00716 S32 mNumMessageCounts;
00717 F32 mReceiveTime;
00718 F32 mMaxMessageTime;
00719 S32 mMaxMessageCounts;
00720 F64 mMessageCountTime;
00721
00722 F64 mCurrentMessageTimeSeconds;
00723
00724
00725 typedef std::pair<msg_exception_callback, void*> exception_t;
00726 typedef std::map<EMessageException, exception_t> callbacks_t;
00727 callbacks_t mExceptionCallbacks;
00728
00729
00730 LLTimer mMessageSystemTimer;
00731
00732 static F32 mTimeDecodesSpamThreshold;
00733 static BOOL mTimeDecodes;
00734
00735 msg_timing_callback mTimingCallback;
00736 void* mTimingCallbackData;
00737
00738 void init();
00739
00740 LLHost mLastSender;
00741 S32 mIncomingCompressedSize;
00742 TPACKETID mCurrentRecvPacketID;
00743
00744 LLMessageBuilder* mMessageBuilder;
00745 LLTemplateMessageBuilder* mTemplateMessageBuilder;
00746 LLSDMessageBuilder* mLLSDMessageBuilder;
00747 LLMessageReader* mMessageReader;
00748 LLTemplateMessageReader* mTemplateMessageReader;
00749 LLSDMessageReader* mLLSDMessageReader;
00750
00751 friend class LLMessageHandlerBridge;
00752
00753 bool callHandler(const char *name, bool trustedSource,
00754 LLMessageSystem* msg);
00755
00756
00758 LLCircuitData* findCircuit(const LLHost& host, bool resetPacketId);
00759 };
00760
00761
00762
00763 extern LLMessageSystem *gMessageSystem;
00764
00765
00766
00767
00768 BOOL start_messaging_system(
00769 const std::string& template_name,
00770 U32 port,
00771 S32 version_major,
00772 S32 version_minor,
00773 S32 version_patch,
00774 BOOL b_dump_prehash_file,
00775 const std::string& secret,
00776 const LLUseCircuitCodeResponder* responder = NULL);
00777
00778 void end_messaging_system();
00779
00780 void null_message_callback(LLMessageSystem *msg, void **data);
00781
00782
00783
00784
00785
00786 #if !defined( LL_BIG_ENDIAN ) && !defined( LL_LITTLE_ENDIAN )
00787 #error Unknown endianness for htonmemcpy. Did you miss a common include?
00788 #endif
00789
00790 static inline void *htonmemcpy(void *vs, const void *vct, EMsgVariableType type, size_t n)
00791 {
00792 char *s = (char *)vs;
00793 const char *ct = (const char *)vct;
00794 #ifdef LL_BIG_ENDIAN
00795 S32 i, length;
00796 #endif
00797 switch(type)
00798 {
00799 case MVT_FIXED:
00800 case MVT_VARIABLE:
00801 case MVT_U8:
00802 case MVT_S8:
00803 case MVT_BOOL:
00804 case MVT_LLUUID:
00805 case MVT_IP_ADDR:
00806 case MVT_IP_PORT:
00807 return(memcpy(s,ct,n));
00808
00809 case MVT_U16:
00810 case MVT_S16:
00811 if (n != 2)
00812 {
00813 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00814 }
00815 #ifdef LL_BIG_ENDIAN
00816 *(s + 1) = *(ct);
00817 *(s) = *(ct + 1);
00818 return(vs);
00819 #else
00820 return(memcpy(s,ct,n));
00821 #endif
00822
00823 case MVT_U32:
00824 case MVT_S32:
00825 case MVT_F32:
00826 if (n != 4)
00827 {
00828 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00829 }
00830 #ifdef LL_BIG_ENDIAN
00831 *(s + 3) = *(ct);
00832 *(s + 2) = *(ct + 1);
00833 *(s + 1) = *(ct + 2);
00834 *(s) = *(ct + 3);
00835 return(vs);
00836 #else
00837 return(memcpy(s,ct,n));
00838 #endif
00839
00840 case MVT_U64:
00841 case MVT_S64:
00842 case MVT_F64:
00843 if (n != 8)
00844 {
00845 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00846 }
00847 #ifdef LL_BIG_ENDIAN
00848 *(s + 7) = *(ct);
00849 *(s + 6) = *(ct + 1);
00850 *(s + 5) = *(ct + 2);
00851 *(s + 4) = *(ct + 3);
00852 *(s + 3) = *(ct + 4);
00853 *(s + 2) = *(ct + 5);
00854 *(s + 1) = *(ct + 6);
00855 *(s) = *(ct + 7);
00856 return(vs);
00857 #else
00858 return(memcpy(s,ct,n));
00859 #endif
00860
00861 case MVT_LLVector3:
00862 case MVT_LLQuaternion:
00863 if (n != 12)
00864 {
00865 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00866 }
00867 #ifdef LL_BIG_ENDIAN
00868 htonmemcpy(s + 8, ct + 8, MVT_F32, 4);
00869 htonmemcpy(s + 4, ct + 4, MVT_F32, 4);
00870 return(htonmemcpy(s, ct, MVT_F32, 4));
00871 #else
00872 return(memcpy(s,ct,n));
00873 #endif
00874
00875 case MVT_LLVector3d:
00876 if (n != 24)
00877 {
00878 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00879 }
00880 #ifdef LL_BIG_ENDIAN
00881 htonmemcpy(s + 16, ct + 16, MVT_F64, 8);
00882 htonmemcpy(s + 8, ct + 8, MVT_F64, 8);
00883 return(htonmemcpy(s, ct, MVT_F64, 8));
00884 #else
00885 return(memcpy(s,ct,n));
00886 #endif
00887
00888 case MVT_LLVector4:
00889 if (n != 16)
00890 {
00891 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00892 }
00893 #ifdef LL_BIG_ENDIAN
00894 htonmemcpy(s + 12, ct + 12, MVT_F32, 4);
00895 htonmemcpy(s + 8, ct + 8, MVT_F32, 4);
00896 htonmemcpy(s + 4, ct + 4, MVT_F32, 4);
00897 return(htonmemcpy(s, ct, MVT_F32, 4));
00898 #else
00899 return(memcpy(s,ct,n));
00900 #endif
00901
00902 case MVT_U16Vec3:
00903 if (n != 6)
00904 {
00905 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00906 }
00907 #ifdef LL_BIG_ENDIAN
00908 htonmemcpy(s + 4, ct + 4, MVT_U16, 2);
00909 htonmemcpy(s + 2, ct + 2, MVT_U16, 2);
00910 return(htonmemcpy(s, ct, MVT_U16, 2));
00911 #else
00912 return(memcpy(s,ct,n));
00913 #endif
00914
00915 case MVT_U16Quat:
00916 if (n != 8)
00917 {
00918 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00919 }
00920 #ifdef LL_BIG_ENDIAN
00921 htonmemcpy(s + 6, ct + 6, MVT_U16, 2);
00922 htonmemcpy(s + 4, ct + 4, MVT_U16, 2);
00923 htonmemcpy(s + 2, ct + 2, MVT_U16, 2);
00924 return(htonmemcpy(s, ct, MVT_U16, 2));
00925 #else
00926 return(memcpy(s,ct,n));
00927 #endif
00928
00929 case MVT_S16Array:
00930 if (n % 2)
00931 {
00932 llerrs << "Size argument passed to htonmemcpy doesn't match swizzle type size" << llendl;
00933 }
00934 #ifdef LL_BIG_ENDIAN
00935 length = n % 2;
00936 for (i = 1; i < length; i++)
00937 {
00938 htonmemcpy(s + i*2, ct + i*2, MVT_S16, 2);
00939 }
00940 return(htonmemcpy(s, ct, MVT_S16, 2));
00941 #else
00942 return(memcpy(s,ct,n));
00943 #endif
00944
00945 default:
00946 return(memcpy(s,ct,n));
00947 }
00948 }
00949
00950 inline void *ntohmemcpy(void *s, const void *ct, EMsgVariableType type, size_t n)
00951 {
00952 return(htonmemcpy(s,ct,type, n));
00953 }
00954
00955
00956 inline const LLHost& LLMessageSystem::getSender() const {return mLastSender;}
00957
00958 inline U32 LLMessageSystem::getSenderIP() const
00959 {
00960 return mLastSender.getAddress();
00961 }
00962
00963 inline U32 LLMessageSystem::getSenderPort() const
00964 {
00965 return mLastSender.getPort();
00966 }
00967
00968
00969
00970
00971
00972 inline S32 LLMessageSystem::sendMessage(const U32 circuit)
00973 {
00974 return sendMessage(findHost(circuit));
00975 }
00976
00977 #endif