aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs16
-rw-r--r--OpenSim/Framework/WebUtil.cs240
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs64
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs4
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs2
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs553
6 files changed, 378 insertions, 501 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index 3343f60..86ad7aa 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -346,9 +346,15 @@ namespace OpenSim.Framework.Servers.HttpServer
346 /// <param name="response"></param> 346 /// <param name="response"></param>
347 public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response) 347 public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response)
348 { 348 {
349 string reqnum = "unknown";
350 int tickstart = Environment.TickCount;
351
349 try 352 try
350 { 353 {
351 //m_log.Debug("[BASE HTTP SERVER]: Handling request to " + request.RawUrl); 354 // OpenSim.Framework.WebUtil.OSHeaderRequestID
355 if (request.Headers["opensim-request-id"] != null)
356 reqnum = String.Format("{0}:{1}",request.RemoteIPEndPoint,request.Headers["opensim-request-id"]);
357 // m_log.DebugFormat("[BASE HTTP SERVER]: <{0}> handle request for {1}",reqnum,request.RawUrl);
352 358
353 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true); 359 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true);
354 360
@@ -576,6 +582,14 @@ namespace OpenSim.Framework.Servers.HttpServer
576 m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e); 582 m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e);
577 SendHTML500(response); 583 SendHTML500(response);
578 } 584 }
585 finally
586 {
587 // Every month or so this will wrap and give bad numbers, not really a problem
588 // since its just for reporting, 200ms limit can be adjusted
589 int tickdiff = Environment.TickCount - tickstart;
590 if (tickdiff > 200)
591 m_log.InfoFormat("[BASE HTTP SERVER]: slow request <{0}> for {1} took {2} ms",reqnum,request.RawUrl,tickdiff);
592 }
579 } 593 }
580 594
581 private bool TryGetStreamHandler(string handlerKey, out IRequestHandler streamHandler) 595 private bool TryGetStreamHandler(string handlerKey, out IRequestHandler streamHandler)
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index 1c856af..d88d095 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -50,6 +50,16 @@ namespace OpenSim.Framework
50 LogManager.GetLogger( 50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType); 51 MethodBase.GetCurrentMethod().DeclaringType);
52 52
53 private static int m_requestNumber = 0;
54
55 // this is the header field used to communicate the local request id
56 // used for performance and debugging
57 public const string OSHeaderRequestID = "opensim-request-id";
58
59 // number of milliseconds a call can take before it is considered
60 // a "long" call for warning & debugging purposes
61 public const int LongCallTime = 200;
62
53 /// <summary> 63 /// <summary>
54 /// Send LLSD to an HTTP client in application/llsd+json form 64 /// Send LLSD to an HTTP client in application/llsd+json form
55 /// </summary> 65 /// </summary>
@@ -123,26 +133,186 @@ namespace OpenSim.Framework
123 } 133 }
124 134
125 /// <summary> 135 /// <summary>
136 /// PUT JSON-encoded data to a web service that returns LLSD or
137 /// JSON data
138 /// </summary>
139 public static OSDMap PutToService(string url, OSDMap data)
140 {
141 return ServiceOSDRequest(url,data,"PUT",10000);
142 }
143
144 public static OSDMap PostToService(string url, OSDMap data)
145 {
146 return ServiceOSDRequest(url,data,"POST",10000);
147 }
148
149 public static OSDMap GetFromService(string url)
150 {
151 return ServiceOSDRequest(url,null,"GET",10000);
152 }
153
154 public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout)
155 {
156 int reqnum = m_requestNumber++;
157 // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method);
158
159 string errorMessage = "unknown error";
160 int tickstart = Util.EnvironmentTickCount();
161 int tickdata = 0;
162
163 try
164 {
165 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
166 request.Method = method;
167 request.Timeout = timeout;
168 request.KeepAlive = false;
169 request.MaximumAutomaticRedirections = 10;
170 request.ReadWriteTimeout = timeout / 4;
171 request.Headers[OSHeaderRequestID] = reqnum.ToString();
172
173 // If there is some input, write it into the request
174 if (data != null)
175 {
176 string strBuffer = OSDParser.SerializeJsonString(data);
177 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
178
179 request.ContentType = "application/json";
180 request.ContentLength = buffer.Length; //Count bytes to send
181 using (Stream requestStream = request.GetRequestStream())
182 requestStream.Write(buffer, 0, buffer.Length); //Send it
183 }
184
185 // capture how much time was spent writing, this may seem silly
186 // but with the number concurrent requests, this often blocks
187 tickdata = Util.EnvironmentTickCountSubtract(tickstart);
188
189 using (WebResponse response = request.GetResponse())
190 {
191 using (Stream responseStream = response.GetResponseStream())
192 {
193 string responseStr = null;
194 responseStr = responseStream.GetStreamString();
195 // m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
196 return CanonicalizeResults(responseStr);
197 }
198 }
199 }
200 catch (WebException we)
201 {
202 errorMessage = we.Message;
203 if (we.Status == WebExceptionStatus.ProtocolError)
204 {
205 HttpWebResponse webResponse = (HttpWebResponse)we.Response;
206 errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription);
207 }
208 }
209 catch (Exception ex)
210 {
211 errorMessage = ex.Message;
212 }
213 finally
214 {
215 // This just dumps a warning for any operation that takes more than 100 ms
216 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
217 if (tickdiff > LongCallTime)
218 m_log.InfoFormat("[WEB UTIL]: osd request <{0}> (URI:{1}, METHOD:{2}) took {3}ms overall, {4}ms writing",
219 reqnum,url,method,tickdiff,tickdata);
220 }
221
222 m_log.WarnFormat("[WEB UTIL] <{0}> osd request failed: {1}",reqnum,errorMessage);
223 return ErrorResponseMap(errorMessage);
224 }
225
226 /// <summary>
227 /// Since there are no consistencies in the way web requests are
228 /// formed, we need to do a little guessing about the result format.
229 /// Keys:
230 /// Success|success == the success fail of the request
231 /// _RawResult == the raw string that came back
232 /// _Result == the OSD unpacked string
233 /// </summary>
234 private static OSDMap CanonicalizeResults(string response)
235 {
236 OSDMap result = new OSDMap();
237
238 // Default values
239 result["Success"] = OSD.FromBoolean(true);
240 result["success"] = OSD.FromBoolean(true);
241 result["_RawResult"] = OSD.FromString(response);
242 result["_Result"] = new OSDMap();
243
244 if (response.Equals("true",System.StringComparison.OrdinalIgnoreCase))
245 return result;
246
247 if (response.Equals("false",System.StringComparison.OrdinalIgnoreCase))
248 {
249 result["Success"] = OSD.FromBoolean(false);
250 result["success"] = OSD.FromBoolean(false);
251 return result;
252 }
253
254 try
255 {
256 OSD responseOSD = OSDParser.Deserialize(response);
257 if (responseOSD.Type == OSDType.Map)
258 {
259 result["_Result"] = (OSDMap)responseOSD;
260 return result;
261 }
262 }
263 catch (Exception e)
264 {
265 // don't need to treat this as an error... we're just guessing anyway
266 m_log.DebugFormat("[WEB UTIL] couldn't decode <{0}>: {1}",response,e.Message);
267 }
268
269 return result;
270 }
271
272 /// <summary>
126 /// POST URL-encoded form data to a web service that returns LLSD or 273 /// POST URL-encoded form data to a web service that returns LLSD or
127 /// JSON data 274 /// JSON data
128 /// </summary> 275 /// </summary>
129 public static OSDMap PostToService(string url, NameValueCollection data) 276 public static OSDMap PostToService(string url, NameValueCollection data)
130 { 277 {
131 string errorMessage; 278 return ServiceFormRequest(url,data,10000);
279 }
280
281 public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout)
282 {
283 int reqnum = m_requestNumber++;
284 string method = (data != null && data["RequestMethod"] != null) ? data["RequestMethod"] : "unknown";
285 // m_log.DebugFormat("[WEB UTIL]: <{0}> start form request for {1}, method {2}",reqnum,url,method);
286
287 string errorMessage = "unknown error";
288 int tickstart = Util.EnvironmentTickCount();
289 int tickdata = 0;
132 290
133 try 291 try
134 { 292 {
135 string queryString = BuildQueryString(data); 293
136 byte[] requestData = System.Text.Encoding.UTF8.GetBytes(queryString);
137
138 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 294 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
139 request.Method = "POST"; 295 request.Method = "POST";
140 request.ContentLength = requestData.Length; 296 request.Timeout = timeout;
141 request.ContentType = "application/x-www-form-urlencoded"; 297 request.KeepAlive = false;
298 request.MaximumAutomaticRedirections = 10;
299 request.ReadWriteTimeout = timeout / 4;
300 request.Headers[OSHeaderRequestID] = reqnum.ToString();
301
302 if (data != null)
303 {
304 string queryString = BuildQueryString(data);
305 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString);
306
307 request.ContentLength = buffer.Length;
308 request.ContentType = "application/x-www-form-urlencoded";
309 using (Stream requestStream = request.GetRequestStream())
310 requestStream.Write(buffer, 0, buffer.Length);
311 }
142 312
143 Stream requestStream = request.GetRequestStream(); 313 // capture how much time was spent writing, this may seem silly
144 requestStream.Write(requestData, 0, requestData.Length); 314 // but with the number concurrent requests, this often blocks
145 requestStream.Close(); 315 tickdata = Util.EnvironmentTickCountSubtract(tickstart);
146 316
147 using (WebResponse response = request.GetResponse()) 317 using (WebResponse response = request.GetResponse())
148 { 318 {
@@ -150,34 +320,50 @@ namespace OpenSim.Framework
150 { 320 {
151 string responseStr = null; 321 string responseStr = null;
152 322
153 try 323 responseStr = responseStream.GetStreamString();
154 { 324 OSD responseOSD = OSDParser.Deserialize(responseStr);
155 responseStr = responseStream.GetStreamString(); 325 if (responseOSD.Type == OSDType.Map)
156 OSD responseOSD = OSDParser.Deserialize(responseStr); 326 return (OSDMap)responseOSD;
157 if (responseOSD.Type == OSDType.Map)
158 return (OSDMap)responseOSD;
159 else
160 errorMessage = "Response format was invalid.";
161 }
162 catch (Exception ex)
163 {
164 if (!String.IsNullOrEmpty(responseStr))
165 errorMessage = "Failed to parse the response:\n" + responseStr;
166 else
167 errorMessage = "Failed to retrieve the response: " + ex.Message;
168 }
169 } 327 }
170 } 328 }
171 } 329 }
330 catch (WebException we)
331 {
332 errorMessage = we.Message;
333 if (we.Status == WebExceptionStatus.ProtocolError)
334 {
335 HttpWebResponse webResponse = (HttpWebResponse)we.Response;
336 errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription);
337 }
338 }
172 catch (Exception ex) 339 catch (Exception ex)
173 { 340 {
174 m_log.Warn("POST to URL " + url + " failed: " + ex);
175 errorMessage = ex.Message; 341 errorMessage = ex.Message;
176 } 342 }
343 finally
344 {
345 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
346 if (tickdiff > LongCallTime)
347 m_log.InfoFormat("[WEB UTIL]: form request <{0}> (URI:{1}, METHOD:{2}) took {3}ms overall, {4}ms writing",
348 reqnum,url,method,tickdiff,tickdata);
349 }
177 350
178 return new OSDMap { { "Message", OSD.FromString("Service request failed. " + errorMessage) } }; 351 m_log.WarnFormat("[WEB UTIL]: <{0}> form request failed: {1}",reqnum,errorMessage);
352 return ErrorResponseMap(errorMessage);
179 } 353 }
180 354
355 /// <summary>
356 /// Create a response map for an error, trying to keep
357 /// the result formats consistent
358 /// </summary>
359 private static OSDMap ErrorResponseMap(string msg)
360 {
361 OSDMap result = new OSDMap();
362 result["Success"] = "False";
363 result["Message"] = OSD.FromString("Service request failed: " + msg);
364 return result;
365 }
366
181 #region Uri 367 #region Uri
182 368
183 /// <summary> 369 /// <summary>
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
index a1d9167..1aa3282 100644
--- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
@@ -283,46 +283,52 @@ namespace OpenSim.Services.Connectors.Hypergrid
283 283
284 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason) 284 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
285 { 285 {
286 HttpWebRequest AgentCreateRequest = null; 286 // m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: CreateAgent start");
287
287 myipaddress = String.Empty; 288 myipaddress = String.Empty;
288 reason = String.Empty; 289 reason = String.Empty;
289 290
290 if (SendRequest(destination, aCircuit, flags, out reason, out AgentCreateRequest)) 291 if (destination == null)
291 { 292 {
292 string response = GetResponse(AgentCreateRequest, out reason); 293 m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Given destination is null");
293 bool success = true; 294 return false;
294 UnpackResponse(response, out success, out reason, out myipaddress);
295 return success;
296 } 295 }
297 296
298 return false; 297 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/";
299 }
300
301 protected void UnpackResponse(string response, out bool result, out string reason, out string ipaddress)
302 {
303 result = true;
304 reason = string.Empty;
305 ipaddress = string.Empty;
306 298
307 if (!String.IsNullOrEmpty(response)) 299 try
308 { 300 {
309 try 301 OSDMap args = aCircuit.PackAgentCircuitData();
310 { 302
311 // we assume we got an OSDMap back 303 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
312 OSDMap r = Util.GetOSDMap(response); 304 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
313 result = r["success"].AsBoolean(); 305 args["destination_name"] = OSD.FromString(destination.RegionName);
314 reason = r["reason"].AsString(); 306 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
315 ipaddress = r["your_ip"].AsString(); 307 args["teleport_flags"] = OSD.FromString(flags.ToString());
316 } 308
317 catch (NullReferenceException e) 309 OSDMap result = WebUtil.PostToService(uri,args);
310 if (result["Success"].AsBoolean())
318 { 311 {
319 m_log.InfoFormat("[GATEKEEPER SERVICE CONNECTOR]: exception on UnpackResponse of DoCreateChildAgentCall {0}", e.Message); 312 OSDMap unpacked = (OSDMap)result["_Result"];
320 reason = "Internal error"; 313
321 result = false; 314 if (unpacked != null)
315 {
316 reason = unpacked["reason"].AsString();
317 myipaddress = unpacked["your_ip"].AsString();
318 return unpacked["success"].AsBoolean();
319 }
322 } 320 }
321
322 reason = result["Message"] != null ? result["Message"].AsString() : "error";
323 return false;
324 }
325 catch (Exception e)
326 {
327 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString());
328 reason = e.Message;
323 } 329 }
324 }
325
326 330
331 return false;
332 }
327 } 333 }
328} 334}
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
index 65a02df..810399c 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
@@ -159,9 +159,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
159 return false; 159 return false;
160 } 160 }
161 161
162// DEBUG ON 162 // m_log.DebugFormat("[SIMIAN AVATAR CONNECTOR] save appearance for {0}",userID);
163 m_log.WarnFormat("[SIMIAN AVATAR CONNECTOR] save appearance for {0}",userID);
164// DEBUG OFF
165 163
166 NameValueCollection requestArgs = new NameValueCollection 164 NameValueCollection requestArgs = new NameValueCollection
167 { 165 {
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
index 2f61538..9c72a61 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
@@ -305,7 +305,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
305 { "Enabled", "1" } 305 { "Enabled", "1" }
306 }; 306 };
307 307
308 m_log.WarnFormat("[SIMIAN GRID CONNECTOR] request regions by range {0} to {1}",minPosition.ToString(),maxPosition.ToString()); 308 //m_log.DebugFormat("[SIMIAN GRID CONNECTOR] request regions by range {0} to {1}",minPosition.ToString(),maxPosition.ToString());
309 309
310 310
311 OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs); 311 OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
index 4e3cfa5..f34c2bd 100644
--- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
@@ -75,469 +75,193 @@ namespace OpenSim.Services.Connectors.Simulation
75 return "agent/"; 75 return "agent/";
76 } 76 }
77 77
78 /// <summary>
79 ///
80 /// </summary>
78 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason) 81 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason)
79 { 82 {
80 HttpWebRequest AgentCreateRequest = null; 83 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent start");
81 reason = String.Empty; 84
82
83 if (SendRequest(destination, aCircuit, flags, out reason, out AgentCreateRequest))
84 {
85 string response = GetResponse(AgentCreateRequest, out reason);
86 bool success = true;
87 UnpackResponse(response, out success, out reason);
88 return success;
89 }
90
91 return false;
92 }
93
94
95 protected bool SendRequest(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason, out HttpWebRequest AgentCreateRequest)
96 {
97 reason = String.Empty; 85 reason = String.Empty;
98 AgentCreateRequest = null;
99
100 if (destination == null) 86 if (destination == null)
101 { 87 {
102 reason = "Destination is null";
103 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); 88 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null");
104 return false; 89 return false;
105 } 90 }
106 91
107 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/"; 92 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/";
108 93
109 AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
110 AgentCreateRequest.Method = "POST";
111 AgentCreateRequest.ContentType = "application/json";
112 AgentCreateRequest.Timeout = 10000;
113 //AgentCreateRequest.KeepAlive = false;
114 //AgentCreateRequest.Headers.Add("Authorization", authKey);
115
116 // Fill it in
117 OSDMap args = PackCreateAgentArguments(aCircuit, destination, flags);
118 if (args == null)
119 return false;
120
121 string strBuffer = "";
122 byte[] buffer = new byte[1];
123 try 94 try
124 { 95 {
125 strBuffer = OSDParser.SerializeJsonString(args); 96 OSDMap args = aCircuit.PackAgentCircuitData();
126 Encoding str = Util.UTF8;
127 buffer = str.GetBytes(strBuffer);
128 97
129 } 98 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
130 catch (Exception e) 99 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
131 { 100 args["destination_name"] = OSD.FromString(destination.RegionName);
132 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); 101 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
133 // ignore. buffer will be empty, caller should check. 102 args["teleport_flags"] = OSD.FromString(flags.ToString());
134 }
135 103
136 Stream os = null; 104 OSDMap result = WebUtil.PostToService(uri,args);
137 try 105 if (result["Success"].AsBoolean())
138 { // send the Post 106 return true;
139 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send 107
140 os = AgentCreateRequest.GetRequestStream(); 108 reason = result["Message"] != null ? result["Message"].AsString() : "error";
141 os.Write(buffer, 0, strBuffer.Length); //Send it
142 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}",
143 uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY);
144 }
145 //catch (WebException ex)
146 catch
147 {
148 //m_log.ErrorFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message);
149 reason = "cannot contact remote region";
150 return false; 109 return false;
151 } 110 }
152 finally
153 {
154 if (os != null)
155 os.Close();
156 }
157
158 return true;
159 }
160
161 protected string GetResponse(HttpWebRequest AgentCreateRequest, out string reason)
162 {
163 // Let's wait for the response
164 //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall");
165 reason = string.Empty;
166
167 WebResponse webResponse = null;
168 StreamReader sr = null;
169 string response = string.Empty;
170 try
171 {
172 webResponse = AgentCreateRequest.GetResponse();
173 if (webResponse == null)
174 {
175 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on DoCreateChildAgentCall post");
176 }
177 else
178 {
179
180 sr = new StreamReader(webResponse.GetResponseStream());
181 response = sr.ReadToEnd().Trim();
182 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response);
183 }
184 }
185 catch (WebException ex)
186 {
187 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
188 reason = "Destination did not reply";
189 return string.Empty;
190 }
191 finally
192 {
193 if (sr != null)
194 sr.Close();
195 }
196
197 return response;
198 }
199
200 protected void UnpackResponse(string response, out bool result, out string reason)
201 {
202 result = true;
203 reason = string.Empty;
204 if (!String.IsNullOrEmpty(response))
205 {
206 try
207 {
208 // we assume we got an OSDMap back
209 OSDMap r = Util.GetOSDMap(response);
210 result = r["success"].AsBoolean();
211 reason = r["reason"].AsString();
212 }
213 catch (NullReferenceException e)
214 {
215 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
216
217 // check for old style response
218 if (response.ToLower().StartsWith("true"))
219 result = true;
220
221 result = false;
222 }
223 }
224 }
225
226 protected virtual OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion destination, uint flags)
227 {
228 OSDMap args = null;
229 try
230 {
231 args = aCircuit.PackAgentCircuitData();
232 }
233 catch (Exception e) 111 catch (Exception e)
234 { 112 {
235 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); 113 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString());
236 return null; 114 reason = e.Message;
237 } 115 }
238 116
239 // Add the input arguments 117 return false;
240 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
241 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
242 args["destination_name"] = OSD.FromString(destination.RegionName);
243 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
244 args["teleport_flags"] = OSD.FromString(flags.ToString());
245
246 return args;
247 } 118 }
248 119
120 /// <summary>
121 /// Send complete data about an agent in this region to a neighbor
122 /// </summary>
249 public bool UpdateAgent(GridRegion destination, AgentData data) 123 public bool UpdateAgent(GridRegion destination, AgentData data)
250 { 124 {
251 return UpdateAgent(destination, (IAgentData)data); 125 return UpdateAgent(destination, (IAgentData)data);
252 } 126 }
253 127
128 /// <summary>
129 /// Send updated position information about an agent in this region to a neighbor
130 /// This operation may be called very frequently if an avatar is moving about in
131 /// the region.
132 /// </summary>
254 public bool UpdateAgent(GridRegion destination, AgentPosition data) 133 public bool UpdateAgent(GridRegion destination, AgentPosition data)
255 { 134 {
135 // we need a better throttle for these
136 // return false;
137
256 return UpdateAgent(destination, (IAgentData)data); 138 return UpdateAgent(destination, (IAgentData)data);
257 } 139 }
258 140
141 /// <summary>
142 /// This is the worker function to send AgentData to a neighbor region
143 /// </summary>
259 private bool UpdateAgent(GridRegion destination, IAgentData cAgentData) 144 private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
260 { 145 {
261 // Eventually, we want to use a caps url instead of the agentID 146 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: UpdateAgent start");
262 147
148 // Eventually, we want to use a caps url instead of the agentID
263 string uri = destination.ServerURI + AgentPath() + cAgentData.AgentID + "/"; 149 string uri = destination.ServerURI + AgentPath() + cAgentData.AgentID + "/";
264 150
265 HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
266 ChildUpdateRequest.Method = "PUT";
267 ChildUpdateRequest.ContentType = "application/json";
268 ChildUpdateRequest.Timeout = 30000;
269 //ChildUpdateRequest.KeepAlive = false;
270
271 // Fill it in
272 OSDMap args = null;
273 try
274 {
275 args = cAgentData.Pack();
276 }
277 catch (Exception e)
278 {
279 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message);
280 }
281 // Add the input arguments
282 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
283 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
284 args["destination_name"] = OSD.FromString(destination.RegionName);
285 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
286
287 string strBuffer = "";
288 byte[] buffer = new byte[1];
289 try
290 {
291 strBuffer = OSDParser.SerializeJsonString(args);
292 Encoding str = Util.UTF8;
293 buffer = str.GetBytes(strBuffer);
294
295 }
296 catch (Exception e)
297 {
298 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
299 // ignore. buffer will be empty, caller should check.
300 }
301
302 Stream os = null;
303 try
304 { // send the Post
305 ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send
306 os = ChildUpdateRequest.GetRequestStream();
307 os.Write(buffer, 0, strBuffer.Length); //Send it
308 //m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted AgentUpdate request to remote sim {0}", uri);
309 }
310 catch (WebException ex)
311 //catch
312 {
313 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on AgentUpdate {0}", ex.Message);
314
315 return false;
316 }
317 finally
318 {
319 if (os != null)
320 os.Close();
321 }
322
323 // Let's wait for the response
324 //m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate");
325
326 WebResponse webResponse = null;
327 StreamReader sr = null;
328 try 151 try
329 { 152 {
330 webResponse = ChildUpdateRequest.GetResponse(); 153 OSDMap args = cAgentData.Pack();
331 if (webResponse == null)
332 {
333 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post");
334 }
335 154
336 sr = new StreamReader(webResponse.GetResponseStream()); 155 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
337 //reply = sr.ReadToEnd().Trim(); 156 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
338 sr.ReadToEnd().Trim(); 157 args["destination_name"] = OSD.FromString(destination.RegionName);
339 sr.Close(); 158 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
340 //m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
341 159
160 OSDMap result = WebUtil.PutToService(uri,args);
161 return result["Success"].AsBoolean();
342 } 162 }
343 catch (WebException ex) 163 catch (Exception e)
344 {
345 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ChilAgentUpdate from {0}: {1}", uri, ex.Message);
346 // ignore, really
347 }
348 finally
349 { 164 {
350 if (sr != null) 165 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
351 sr.Close();
352 } 166 }
353 167
354 return true; 168 return false;
355 } 169 }
356 170
171 /// <summary>
172 /// Not sure what sequence causes this function to be invoked. The only calling
173 /// path is through the GET method
174 /// </summary>
357 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) 175 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
358 { 176 {
177 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: RetrieveAgent start");
178
359 agent = null; 179 agent = null;
180
360 // Eventually, we want to use a caps url instead of the agentID 181 // Eventually, we want to use a caps url instead of the agentID
361 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 182 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
362 183
363 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
364 request.Method = "GET";
365 request.Timeout = 10000;
366 //request.Headers.Add("authorization", ""); // coming soon
367
368 HttpWebResponse webResponse = null;
369 string reply = string.Empty;
370 StreamReader sr = null;
371 try 184 try
372 { 185 {
373 webResponse = (HttpWebResponse)request.GetResponse(); 186 OSDMap result = WebUtil.GetFromService(uri);
374 if (webResponse == null) 187 if (result["Success"].AsBoolean())
375 { 188 {
376 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get "); 189 // OSDMap args = Util.GetOSDMap(result["_RawResult"].AsString());
190 OSDMap args = (OSDMap)result["_Result"];
191 if (args != null)
192 {
193 agent = new CompleteAgentData();
194 agent.Unpack(args);
195 return true;
196 }
377 } 197 }
378
379 sr = new StreamReader(webResponse.GetResponseStream());
380 reply = sr.ReadToEnd().Trim();
381
382
383 } 198 }
384 catch (WebException ex) 199 catch (Exception e)
385 {
386 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message);
387 // ignore, really
388 return false;
389 }
390 finally
391 {
392 if (sr != null)
393 sr.Close();
394 }
395
396 if (webResponse.StatusCode == HttpStatusCode.OK)
397 { 200 {
398 // we know it's jason 201 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
399 OSDMap args = Util.GetOSDMap(reply);
400 if (args == null)
401 {
402 return false;
403 }
404
405 agent = new CompleteAgentData();
406 agent.Unpack(args);
407 return true;
408 } 202 }
409 203
410 return false; 204 return false;
411 } 205 }
412 206
207 /// <summary>
208 /// </summary>
413 public bool QueryAccess(GridRegion destination, UUID id) 209 public bool QueryAccess(GridRegion destination, UUID id)
414 { 210 {
211 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: QueryAccess start");
212
415 IPEndPoint ext = destination.ExternalEndPoint; 213 IPEndPoint ext = destination.ExternalEndPoint;
416 if (ext == null) return false; 214 if (ext == null) return false;
215
417 // Eventually, we want to use a caps url instead of the agentID 216 // Eventually, we want to use a caps url instead of the agentID
418 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 217 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
419 218
420 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
421 request.Method = "QUERYACCESS";
422 request.Timeout = 10000;
423 //request.Headers.Add("authorization", ""); // coming soon
424
425 HttpWebResponse webResponse = null;
426 string reply = string.Empty;
427 StreamReader sr = null;
428 try 219 try
429 { 220 {
430 webResponse = (HttpWebResponse)request.GetResponse(); 221 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"QUERYACCESS",10000);
431 if (webResponse == null) 222 return result["Success"].AsBoolean();
432 {
433 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent query ");
434 }
435
436 sr = new StreamReader(webResponse.GetResponseStream());
437 reply = sr.ReadToEnd().Trim();
438
439
440 }
441 catch (WebException ex)
442 {
443 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent query {0}", ex.Message);
444 // ignore, really
445 return false;
446 } 223 }
447 finally 224 catch (Exception e)
448 { 225 {
449 if (sr != null) 226 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] QueryAcess failed with exception; {0}",e.ToString());
450 sr.Close();
451 } 227 }
452 228
453 if (webResponse.StatusCode == HttpStatusCode.OK)
454 {
455 try
456 {
457 bool result;
458
459 result = bool.Parse(reply);
460
461 return result;
462 }
463 catch
464 {
465 return false;
466 }
467 }
468
469 return false; 229 return false;
470 } 230 }
471 231
232 /// <summary>
233 /// </summary>
472 public bool ReleaseAgent(UUID origin, UUID id, string uri) 234 public bool ReleaseAgent(UUID origin, UUID id, string uri)
473 { 235 {
474 WebRequest request = WebRequest.Create(uri); 236 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: ReleaseAgent start");
475 request.Method = "DELETE";
476 request.Timeout = 10000;
477 237
478 StreamReader sr = null;
479 try 238 try
480 { 239 {
481 WebResponse webResponse = request.GetResponse(); 240 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"DELETE",10000);
482 if (webResponse == null)
483 {
484 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on ReleaseAgent");
485 }
486
487 sr = new StreamReader(webResponse.GetResponseStream());
488 //reply = sr.ReadToEnd().Trim();
489 sr.ReadToEnd().Trim();
490 sr.Close();
491 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
492
493 }
494 catch (WebException ex)
495 {
496 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ReleaseAgent {0}", ex.Message);
497 return false;
498 } 241 }
499 finally 242 catch (Exception e)
500 { 243 {
501 if (sr != null) 244 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] ReleaseAgent failed with exception; {0}",e.ToString());
502 sr.Close();
503 } 245 }
504 246
505 return true; 247 return true;
506 } 248 }
507 249
250 /// <summary>
251 /// </summary>
508 public bool CloseAgent(GridRegion destination, UUID id) 252 public bool CloseAgent(GridRegion destination, UUID id)
509 { 253 {
510 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 254 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CloseAgent start");
511 255
512 WebRequest request = WebRequest.Create(uri); 256 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
513 request.Method = "DELETE";
514 request.Timeout = 10000;
515 257
516 StreamReader sr = null;
517 try 258 try
518 { 259 {
519 WebResponse webResponse = request.GetResponse(); 260 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"DELETE",10000);
520 if (webResponse == null)
521 {
522 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent delete ");
523 }
524
525 sr = new StreamReader(webResponse.GetResponseStream());
526 //reply = sr.ReadToEnd().Trim();
527 sr.ReadToEnd().Trim();
528 sr.Close();
529 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
530
531 }
532 catch (WebException ex)
533 {
534 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent delete from {0}: {1}", destination.RegionName, ex.Message);
535 return false;
536 } 261 }
537 finally 262 catch (Exception e)
538 { 263 {
539 if (sr != null) 264 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] CloseAgent failed with exception; {0}",e.ToString());
540 sr.Close();
541 } 265 }
542 266
543 return true; 267 return true;
@@ -552,97 +276,46 @@ namespace OpenSim.Services.Connectors.Simulation
552 return "object/"; 276 return "object/";
553 } 277 }
554 278
279 /// <summary>
280 ///
281 /// </summary>
555 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) 282 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall)
556 { 283 {
557 string uri 284 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateObject start");
558 = destination.ServerURI + ObjectPath() + sog.UUID + "/";
559 //m_log.Debug(" >>> DoCreateObjectCall <<< " + uri);
560
561 WebRequest ObjectCreateRequest = WebRequest.Create(uri);
562 ObjectCreateRequest.Method = "POST";
563 ObjectCreateRequest.ContentType = "application/json";
564 ObjectCreateRequest.Timeout = 10000;
565
566 OSDMap args = new OSDMap(2);
567 args["sog"] = OSD.FromString(sog.ToXml2());
568 args["extra"] = OSD.FromString(sog.ExtraToXmlString());
569 args["modified"] = OSD.FromBoolean(sog.HasGroupChanged);
570 string state = sog.GetStateSnapshot();
571 if (state.Length > 0)
572 args["state"] = OSD.FromString(state);
573 // Add the input general arguments
574 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
575 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
576 args["destination_name"] = OSD.FromString(destination.RegionName);
577 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
578
579 string strBuffer = "";
580 byte[] buffer = new byte[1];
581 try
582 {
583 strBuffer = OSDParser.SerializeJsonString(args);
584 Encoding str = Util.UTF8;
585 buffer = str.GetBytes(strBuffer);
586 285
587 } 286 string uri = destination.ServerURI + ObjectPath() + sog.UUID + "/";
588 catch (Exception e)
589 {
590 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of CreateObject: {0}", e.Message);
591 // ignore. buffer will be empty, caller should check.
592 }
593 287
594 Stream os = null;
595 try 288 try
596 { // send the Post
597 ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send
598 os = ObjectCreateRequest.GetRequestStream();
599 os.Write(buffer, 0, strBuffer.Length); //Send it
600 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateObject request to remote sim {0}", uri);
601 }
602 catch (WebException ex)
603 {
604 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on CreateObject {0}", ex.Message);
605 return false;
606 }
607 finally
608 { 289 {
609 if (os != null) 290 OSDMap args = new OSDMap(2);
610 os.Close();
611 }
612 291
613 // Let's wait for the response 292 args["sog"] = OSD.FromString(sog.ToXml2());
614 //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); 293 args["extra"] = OSD.FromString(sog.ExtraToXmlString());
294 args["modified"] = OSD.FromBoolean(sog.HasGroupChanged);
615 295
616 StreamReader sr = null; 296 string state = sog.GetStateSnapshot();
617 try 297 if (state.Length > 0)
618 { 298 args["state"] = OSD.FromString(state);
619 WebResponse webResponse = ObjectCreateRequest.GetResponse();
620 if (webResponse == null)
621 {
622 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: Null reply on CreateObject post");
623 return false;
624 }
625 299
626 sr = new StreamReader(webResponse.GetResponseStream()); 300 // Add the input general arguments
627 //reply = sr.ReadToEnd().Trim(); 301 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
628 sr.ReadToEnd().Trim(); 302 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
629 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", reply); 303 args["destination_name"] = OSD.FromString(destination.RegionName);
304 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
630 305
306 OSDMap result = WebUtil.PostToService(uri,args);
631 } 307 }
632 catch (WebException ex) 308 catch (Exception e)
633 {
634 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of CreateObject {0}", ex.Message);
635 return false;
636 }
637 finally
638 { 309 {
639 if (sr != null) 310 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] CreateObject failed with exception; {0}",e.ToString());
640 sr.Close();
641 } 311 }
642 312
643 return true; 313 return true;
644 } 314 }
645 315
316 /// <summary>
317 ///
318 /// </summary>
646 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) 319 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
647 { 320 {
648 // TODO, not that urgent 321 // TODO, not that urgent