aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llcircuit.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/llcircuit.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/llmessage/llcircuit.h334
1 files changed, 334 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llcircuit.h b/linden/indra/llmessage/llcircuit.h
new file mode 100644
index 0000000..8021685
--- /dev/null
+++ b/linden/indra/llmessage/llcircuit.h
@@ -0,0 +1,334 @@
1/**
2 * @file llcircuit.h
3 * @brief Provides a method for tracking network circuit information
4 * for the UDP message system
5 *
6 * Copyright (c) 2001-2007, Linden Research, Inc.
7 *
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29#ifndef LL_LLCIRCUIT_H
30#define LL_LLCIRCUIT_H
31
32#include <map>
33#include <vector>
34
35#include "llerror.h"
36#include "linked_lists.h"
37
38#include "lltimer.h"
39#include "timing.h"
40#include "net.h"
41#include "llhost.h"
42#include "llpacketack.h"
43#include "lluuid.h"
44#include "llthrottle.h"
45
46//
47// Constants
48//
49const F32 PING_INTERVAL_MAX = 100.f;
50const F32 PING_INTERVAL_ALARM = 50.f;
51
52
53const F32 LL_AVERAGED_PING_ALPHA = 0.2f; // relaxation constant on ping running average
54const F32 LL_AVERAGED_PING_MAX = 2000; // msec
55const F32 LL_AVERAGED_PING_MIN = 100; // msec // IW: increased to avoid retransmits when a process is slow
56
57const U32 INITIAL_PING_VALUE_MSEC = 1000; // initial value for the ping delay, or for ping delay for an unknown circuit
58
59const TPACKETID LL_MAX_OUT_PACKET_ID = 0x01000000;
60const U8 LL_PACKET_ID_SIZE = 4;
61
62const S32 LL_MAX_RESENT_PACKETS_PER_FRAME = 100;
63const S32 LL_MAX_ACKED_PACKETS_PER_FRAME = 200;
64
65//
66// Prototypes and Predefines
67//
68class LLMessageSystem;
69class LLEncodedDatagramService;
70
71//
72// Classes
73//
74
75
76class LLCircuitData
77{
78public:
79 LLCircuitData(const LLHost &host, TPACKETID in_id);
80 ~LLCircuitData();
81
82 S32 resendUnackedPackets(const F64 now);
83 void clearDuplicateList(TPACKETID oldest_id);
84
85
86 void dumpResendCountAndReset(); // Used for tracking how many resends are being done on a circuit.
87
88
89
90 // Public because stupid message system callbacks uses it.
91 void pingTimerStart();
92 void pingTimerStop(const U8 ping_id);
93 void ackReliablePacket(TPACKETID packet_num);
94
95 // remote computer information
96 const LLUUID& getRemoteID() const { return mRemoteID; }
97 const LLUUID& getRemoteSessionID() const { return mRemoteSessionID; }
98 void setRemoteID(const LLUUID& id) { mRemoteID = id; }
99 void setRemoteSessionID(const LLUUID& id) { mRemoteSessionID = id; }
100
101 void setTrusted(BOOL t);
102
103 // The local end point ID is used when establishing a trusted circuit.
104 // no matching set function for getLocalEndPointID()
105 // mLocalEndPointID should only ever be setup in the LLCircuitData constructor
106 const LLUUID& getLocalEndPointID() const { return mLocalEndPointID; }
107
108 U32 getPingDelay() const;
109 S32 getPingsInTransit() const { return mPingsInTransit; }
110
111 // ACCESSORS
112 BOOL isAlive() const;
113 BOOL isBlocked() const;
114 BOOL getAllowTimeout() const;
115 F32 getPingDelayAveraged();
116 F32 getPingInTransitTime();
117 U32 getPacketsIn() const;
118 S32 getBytesIn() const;
119 S32 getBytesOut() const;
120 U32 getPacketsOut() const;
121 U32 getPacketsLost() const;
122 TPACKETID getPacketOutID() const;
123 BOOL getTrusted() const;
124 F32 getAgeInSeconds() const;
125 S32 getUnackedPacketCount() const { return mUnackedPacketCount; }
126 S32 getUnackedPacketBytes() const { return mUnackedPacketBytes; }
127 F64 getNextPingSendTime() const { return mNextPingSendTime; }
128
129 LLThrottleGroup &getThrottleGroup() { return mThrottles; }
130
131 class less
132 {
133 public:
134 bool operator()(const LLCircuitData* lhs, const LLCircuitData* rhs) const
135 {
136 if (lhs->getNextPingSendTime() < rhs->getNextPingSendTime())
137 {
138 return true;
139 }
140 else if (lhs->getNextPingSendTime() > rhs->getNextPingSendTime())
141 {
142 return false;
143 }
144 else return lhs > rhs;
145 }
146 };
147
148 //
149 // Debugging stuff (not necessary for operation)
150 //
151 void checkPeriodTime(); // Reset per-period counters if necessary.
152 friend std::ostream& operator<<(std::ostream& s, LLCircuitData &circuit);
153 const char* getInfoString() const;
154
155 friend class LLCircuit;
156 friend class LLMessageSystem;
157 friend class LLEncodedDatagramService;
158 friend void crash_on_spaceserver_timeout (const LLHost &host, void *); // HACK, so it has access to setAlive() so it can send a final shutdown message.
159protected:
160 TPACKETID nextPacketOutID();
161 void setPacketInID(TPACKETID id);
162 void checkPacketInID(TPACKETID id, BOOL receive_resent);
163 void setPingDelay(U32 ping);
164 BOOL checkCircuitTimeout(); // Return FALSE if the circuit is dead and should be cleaned up
165
166 void addBytesIn(S32 bytes);
167 void addBytesOut(S32 bytes);
168
169 U8 nextPingID() { mLastPingID++; return mLastPingID; }
170
171 BOOL updateWatchDogTimers(LLMessageSystem *msgsys); // Return FALSE if the circuit is dead and should be cleaned up
172
173 void addReliablePacket(S32 mSocket, U8 *buf_ptr, S32 buf_len, LLReliablePacketParams *params);
174 BOOL isDuplicateResend(TPACKETID packetnum);
175 // Call this method when a reliable message comes in - this will
176 // correctly place the packet in the correct list to be acked
177 // later. RAack = requested ack
178 BOOL collectRAck(TPACKETID packet_num);
179
180
181 void setTimeoutCallback(void (*callback_func)(const LLHost &host, void *user_data), void *user_data);
182
183
184
185 void setAlive(BOOL b_alive);
186 void setAllowTimeout(BOOL allow);
187
188protected:
189 // Identification for this circuit.
190 LLHost mHost;
191 LLUUID mRemoteID;
192 LLUUID mRemoteSessionID;
193
194 LLThrottleGroup mThrottles;
195
196 TPACKETID mWrapID;
197
198 // Current packet IDs of incoming/outgoing packets
199 // Used for packet sequencing/packet loss detection.
200 TPACKETID mPacketsOutID;
201 TPACKETID mPacketsInID;
202 TPACKETID mHighestPacketID;
203
204
205 // Callback and data to run in the case of a circuit timeout.
206 // Used primarily to try and reconnect to servers if they crash/die.
207 void (*mTimeoutCallback)(const LLHost &host, void *user_data);
208 void *mTimeoutUserData;
209
210 BOOL mTrusted; // Is this circuit trusted?
211 BOOL mbAllowTimeout; // Machines can "pause" circuits, forcing them not to be dropped
212
213 BOOL mbAlive; // Indicates whether a circuit is "alive", i.e. responded to pings
214
215 BOOL mBlocked; // Blocked is true if the circuit is hosed, i.e. far behind on pings
216
217 // Not sure what the difference between this and mLastPingSendTime is
218 F64 mPingTime; // Time at which a ping was sent.
219
220 F64 mLastPingSendTime; // Time we last sent a ping
221 F64 mLastPingReceivedTime; // Time we last received a ping
222 F64 mNextPingSendTime; // Time to try and send the next ping
223 S32 mPingsInTransit; // Number of pings in transit
224 U8 mLastPingID; // ID of the last ping that we sent out
225
226
227 // Used for determining the resend time for reliable resends.
228 U32 mPingDelay; // raw ping delay
229 F32 mPingDelayAveraged; // averaged ping delay (fast attack/slow decay)
230
231 typedef std::map<TPACKETID, U64> packet_time_map;
232
233 packet_time_map mPotentialLostPackets;
234 packet_time_map mRecentlyReceivedReliablePackets;
235 std::vector<TPACKETID> mAcks;
236
237 typedef std::map<TPACKETID, LLReliablePacket *> reliable_map;
238 typedef reliable_map::iterator reliable_iter;
239
240 reliable_map mUnackedPackets;
241 reliable_map mFinalRetryPackets;
242
243 S32 mUnackedPacketCount;
244 S32 mUnackedPacketBytes;
245
246
247 LLUUID mLocalEndPointID;
248
249 //
250 // These variables are being used for statistical and debugging purpose ONLY,
251 // as far as I can tell.
252 //
253
254 U32 mPacketsOut;
255 U32 mPacketsIn;
256 S32 mPacketsLost;
257 S32 mBytesIn;
258 S32 mBytesOut;
259
260 F32 mLastPeriodLength; // seconds
261 S32 mBytesInLastPeriod;
262 S32 mBytesOutLastPeriod;
263 S32 mBytesInThisPeriod;
264 S32 mBytesOutThisPeriod;
265 F32 mPeakBPSIn; // bits per second, max of all period bps
266 F32 mPeakBPSOut; // bits per second, max of all period bps
267 F64 mPeriodTime;
268 LLTimer mExistenceTimer; // initialized when circuit created, used to track bandwidth numbers
269
270 S32 mCurrentResendCount; // Number of resent packets since last spam
271};
272
273
274// Actually a singleton class -- the global messagesystem
275// has a single LLCircuit member.
276class LLCircuit
277{
278public:
279 // CREATORS
280 LLCircuit();
281 ~LLCircuit();
282
283 // ACCESSORS
284 LLCircuitData* findCircuit(const LLHost& host) const;
285 BOOL isCircuitAlive(const LLHost& host) const;
286
287 // MANIPULATORS
288 LLCircuitData *addCircuitData(const LLHost &host, TPACKETID in_id);
289 void removeCircuitData(const LLHost &host);
290
291 void updateWatchDogTimers(LLMessageSystem *msgsys);
292 void resendUnackedPackets(S32& unacked_list_length, S32& unacked_list_size);
293
294 // this method is called during the message system processAcks()
295 // to send out any acks that did not get sent already.
296 void sendAcks();
297
298 friend std::ostream& operator<<(std::ostream& s, LLCircuit &circuit);
299 const char* getInfoString() const;
300
301 void dumpResends();
302
303 typedef std::map<LLHost, LLCircuitData*> circuit_data_map;
304
305 /**
306 * @brief This method gets an iterator range starting after key in
307 * the circuit data map.
308 *
309 * @param key The the host before first.
310 * @param first[out] The first matching value after key. This
311 * value will equal end if there are no entries.
312 * @param end[out] The end of the iteration sequence.
313 */
314 void getCircuitRange(
315 const LLHost& key,
316 circuit_data_map::iterator& first,
317 circuit_data_map::iterator& end);
318
319 // Lists that optimize how many circuits we need to traverse a frame
320 // HACK - this should become protected eventually, but stupid !@$@# message system/circuit classes are jumbling things up.
321 circuit_data_map mUnackedCircuitMap; // Map of circuits with unacked data
322 circuit_data_map mSendAckMap; // Map of circuits which need to send acks
323protected:
324 circuit_data_map mCircuitData;
325
326 typedef std::set<LLCircuitData *, LLCircuitData::less> ping_set_t; // Circuits sorted by next ping time
327 ping_set_t mPingSet;
328
329 // This variable points to the last circuit data we found to
330 // optimize the many, many times we call findCircuit. This may be
331 // set in otherwise const methods, so it is declared mutable.
332 mutable LLCircuitData* mLastCircuit;
333};
334#endif