diff options
author | diva | 2009-04-01 23:35:48 +0000 |
---|---|---|
committer | diva | 2009-04-01 23:35:48 +0000 |
commit | 86c753a6bdce8788c6a23bebaf9a6015d5af238a (patch) | |
tree | 1cf7297e6e62cbaefa9d3bfa66fb089300545916 /OpenSim | |
parent | One more bit of refactoring, so this can be used outside region code. (diff) | |
download | opensim-SC-86c753a6bdce8788c6a23bebaf9a6015d5af238a.zip opensim-SC-86c753a6bdce8788c6a23bebaf9a6015d5af238a.tar.gz opensim-SC-86c753a6bdce8788c6a23bebaf9a6015d5af238a.tar.bz2 opensim-SC-86c753a6bdce8788c6a23bebaf9a6015d5af238a.tar.xz |
More refactoring. This time extracting the client-side of RESTInterregionComms into a RegionClient class.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/Communications/Clients/RegionClient.cs | 555 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs | 584 |
2 files changed, 606 insertions, 533 deletions
diff --git a/OpenSim/Framework/Communications/Clients/RegionClient.cs b/OpenSim/Framework/Communications/Clients/RegionClient.cs new file mode 100644 index 0000000..d98852b --- /dev/null +++ b/OpenSim/Framework/Communications/Clients/RegionClient.cs | |||
@@ -0,0 +1,555 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.StructuredData; | ||
37 | |||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Framework.Communications.Clients | ||
41 | { | ||
42 | public class RegionClient | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit) | ||
47 | { | ||
48 | // Eventually, we want to use a caps url instead of the agentID | ||
49 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/"; | ||
50 | //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri); | ||
51 | |||
52 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
53 | AgentCreateRequest.Method = "POST"; | ||
54 | AgentCreateRequest.ContentType = "application/json"; | ||
55 | AgentCreateRequest.Timeout = 10000; | ||
56 | //AgentCreateRequest.KeepAlive = false; | ||
57 | |||
58 | // Fill it in | ||
59 | OSDMap args = null; | ||
60 | try | ||
61 | { | ||
62 | args = aCircuit.PackAgentCircuitData(); | ||
63 | } | ||
64 | catch (Exception e) | ||
65 | { | ||
66 | m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message); | ||
67 | } | ||
68 | // Add the regionhandle of the destination region | ||
69 | ulong regionHandle = GetRegionHandle(region.RegionHandle); | ||
70 | args["destination_handle"] = OSD.FromString(regionHandle.ToString()); | ||
71 | |||
72 | string strBuffer = ""; | ||
73 | byte[] buffer = new byte[1]; | ||
74 | try | ||
75 | { | ||
76 | strBuffer = OSDParser.SerializeJsonString(args); | ||
77 | UTF8Encoding str = new UTF8Encoding(); | ||
78 | buffer = str.GetBytes(strBuffer); | ||
79 | |||
80 | } | ||
81 | catch (Exception e) | ||
82 | { | ||
83 | m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
84 | // ignore. buffer will be empty, caller should check. | ||
85 | } | ||
86 | |||
87 | Stream os = null; | ||
88 | try | ||
89 | { // send the Post | ||
90 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
91 | os = AgentCreateRequest.GetRequestStream(); | ||
92 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
93 | os.Close(); | ||
94 | //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri); | ||
95 | } | ||
96 | //catch (WebException ex) | ||
97 | catch | ||
98 | { | ||
99 | //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
100 | |||
101 | return false; | ||
102 | } | ||
103 | |||
104 | // Let's wait for the response | ||
105 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall"); | ||
106 | |||
107 | try | ||
108 | { | ||
109 | WebResponse webResponse = AgentCreateRequest.GetResponse(); | ||
110 | if (webResponse == null) | ||
111 | { | ||
112 | m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post"); | ||
113 | } | ||
114 | |||
115 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
116 | //reply = sr.ReadToEnd().Trim(); | ||
117 | sr.ReadToEnd().Trim(); | ||
118 | sr.Close(); | ||
119 | //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply); | ||
120 | |||
121 | } | ||
122 | catch (WebException ex) | ||
123 | { | ||
124 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
125 | // ignore, really | ||
126 | } | ||
127 | |||
128 | return true; | ||
129 | |||
130 | } | ||
131 | |||
132 | public bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData) | ||
133 | { | ||
134 | // Eventually, we want to use a caps url instead of the agentID | ||
135 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + cAgentData.AgentID + "/"; | ||
136 | //Console.WriteLine(" >>> DoChildAgentUpdateCall <<< " + uri); | ||
137 | |||
138 | HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
139 | ChildUpdateRequest.Method = "PUT"; | ||
140 | ChildUpdateRequest.ContentType = "application/json"; | ||
141 | ChildUpdateRequest.Timeout = 10000; | ||
142 | //ChildUpdateRequest.KeepAlive = false; | ||
143 | |||
144 | // Fill it in | ||
145 | OSDMap args = null; | ||
146 | try | ||
147 | { | ||
148 | args = cAgentData.Pack(); | ||
149 | } | ||
150 | catch (Exception e) | ||
151 | { | ||
152 | m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message); | ||
153 | } | ||
154 | // Add the regionhandle of the destination region | ||
155 | ulong regionHandle = GetRegionHandle(region.RegionHandle); | ||
156 | args["destination_handle"] = OSD.FromString(regionHandle.ToString()); | ||
157 | |||
158 | string strBuffer = ""; | ||
159 | byte[] buffer = new byte[1]; | ||
160 | try | ||
161 | { | ||
162 | strBuffer = OSDParser.SerializeJsonString(args); | ||
163 | UTF8Encoding str = new UTF8Encoding(); | ||
164 | buffer = str.GetBytes(strBuffer); | ||
165 | |||
166 | } | ||
167 | catch (Exception e) | ||
168 | { | ||
169 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); | ||
170 | // ignore. buffer will be empty, caller should check. | ||
171 | } | ||
172 | |||
173 | Stream os = null; | ||
174 | try | ||
175 | { // send the Post | ||
176 | ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
177 | os = ChildUpdateRequest.GetRequestStream(); | ||
178 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
179 | os.Close(); | ||
180 | //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri); | ||
181 | } | ||
182 | //catch (WebException ex) | ||
183 | catch | ||
184 | { | ||
185 | //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
186 | |||
187 | return false; | ||
188 | } | ||
189 | |||
190 | // Let's wait for the response | ||
191 | //m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate"); | ||
192 | |||
193 | try | ||
194 | { | ||
195 | WebResponse webResponse = ChildUpdateRequest.GetResponse(); | ||
196 | if (webResponse == null) | ||
197 | { | ||
198 | m_log.Info("[REST COMMS]: Null reply on ChilAgentUpdate post"); | ||
199 | } | ||
200 | |||
201 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
202 | //reply = sr.ReadToEnd().Trim(); | ||
203 | sr.ReadToEnd().Trim(); | ||
204 | sr.Close(); | ||
205 | //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply); | ||
206 | |||
207 | } | ||
208 | catch (WebException ex) | ||
209 | { | ||
210 | m_log.InfoFormat("[REST COMMS]: exception on reply of ChilAgentUpdate {0}", ex.Message); | ||
211 | // ignore, really | ||
212 | } | ||
213 | |||
214 | return true; | ||
215 | } | ||
216 | |||
217 | public bool DoRetrieveRootAgentCall(RegionInfo region, UUID id, out IAgentData agent) | ||
218 | { | ||
219 | agent = null; | ||
220 | // Eventually, we want to use a caps url instead of the agentID | ||
221 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() + "/"; | ||
222 | //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri); | ||
223 | |||
224 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
225 | request.Method = "GET"; | ||
226 | request.Timeout = 10000; | ||
227 | //request.Headers.Add("authorization", ""); // coming soon | ||
228 | |||
229 | HttpWebResponse webResponse = null; | ||
230 | string reply = string.Empty; | ||
231 | try | ||
232 | { | ||
233 | webResponse = (HttpWebResponse)request.GetResponse(); | ||
234 | if (webResponse == null) | ||
235 | { | ||
236 | m_log.Info("[REST COMMS]: Null reply on agent get "); | ||
237 | } | ||
238 | |||
239 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
240 | reply = sr.ReadToEnd().Trim(); | ||
241 | sr.Close(); | ||
242 | |||
243 | //Console.WriteLine("[REST COMMS]: ChilAgentUpdate reply was " + reply); | ||
244 | |||
245 | } | ||
246 | catch (WebException ex) | ||
247 | { | ||
248 | m_log.InfoFormat("[REST COMMS]: exception on reply of agent get {0}", ex.Message); | ||
249 | // ignore, really | ||
250 | return false; | ||
251 | } | ||
252 | |||
253 | if (webResponse.StatusCode == HttpStatusCode.OK) | ||
254 | { | ||
255 | // we know it's jason | ||
256 | OSDMap args = GetOSDMap(reply); | ||
257 | if (args == null) | ||
258 | { | ||
259 | //Console.WriteLine("[REST COMMS]: Error getting OSDMap from reply"); | ||
260 | return false; | ||
261 | } | ||
262 | |||
263 | agent = new CompleteAgentData(); | ||
264 | agent.Unpack(args); | ||
265 | return true; | ||
266 | } | ||
267 | |||
268 | //Console.WriteLine("[REST COMMS]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode); | ||
269 | return false; | ||
270 | } | ||
271 | |||
272 | public bool DoReleaseAgentCall(ulong regionHandle, UUID id, string uri) | ||
273 | { | ||
274 | //m_log.Debug(" >>> DoReleaseAgentCall <<< " + uri); | ||
275 | |||
276 | WebRequest request = WebRequest.Create(uri); | ||
277 | request.Method = "DELETE"; | ||
278 | request.Timeout = 10000; | ||
279 | |||
280 | try | ||
281 | { | ||
282 | WebResponse webResponse = request.GetResponse(); | ||
283 | if (webResponse == null) | ||
284 | { | ||
285 | m_log.Info("[REST COMMS]: Null reply on agent delete "); | ||
286 | } | ||
287 | |||
288 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
289 | //reply = sr.ReadToEnd().Trim(); | ||
290 | sr.ReadToEnd().Trim(); | ||
291 | sr.Close(); | ||
292 | //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply); | ||
293 | |||
294 | } | ||
295 | catch (WebException ex) | ||
296 | { | ||
297 | m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message); | ||
298 | // ignore, really | ||
299 | } | ||
300 | |||
301 | return true; | ||
302 | } | ||
303 | |||
304 | |||
305 | public bool DoCloseAgentCall(RegionInfo region, UUID id) | ||
306 | { | ||
307 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() + "/"; | ||
308 | |||
309 | //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri); | ||
310 | |||
311 | WebRequest request = WebRequest.Create(uri); | ||
312 | request.Method = "DELETE"; | ||
313 | request.Timeout = 10000; | ||
314 | |||
315 | try | ||
316 | { | ||
317 | WebResponse webResponse = request.GetResponse(); | ||
318 | if (webResponse == null) | ||
319 | { | ||
320 | m_log.Info("[REST COMMS]: Null reply on agent delete "); | ||
321 | } | ||
322 | |||
323 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
324 | //reply = sr.ReadToEnd().Trim(); | ||
325 | sr.ReadToEnd().Trim(); | ||
326 | sr.Close(); | ||
327 | //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply); | ||
328 | |||
329 | } | ||
330 | catch (WebException ex) | ||
331 | { | ||
332 | m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message); | ||
333 | // ignore, really | ||
334 | } | ||
335 | |||
336 | return true; | ||
337 | } | ||
338 | |||
339 | public bool DoCreateObjectCall(RegionInfo region, ISceneObject sog, bool allowScriptCrossing) | ||
340 | { | ||
341 | ulong regionHandle = GetRegionHandle(region.RegionHandle); | ||
342 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/object/" + sog.UUID + "/" + regionHandle.ToString() + "/"; | ||
343 | //m_log.Debug(" >>> DoCreateChildAgentCall <<< " + uri); | ||
344 | |||
345 | WebRequest ObjectCreateRequest = WebRequest.Create(uri); | ||
346 | ObjectCreateRequest.Method = "POST"; | ||
347 | ObjectCreateRequest.ContentType = "application/json"; | ||
348 | ObjectCreateRequest.Timeout = 10000; | ||
349 | |||
350 | OSDMap args = new OSDMap(2); | ||
351 | args["sog"] = OSD.FromString(sog.ToXmlString2()); | ||
352 | args["extra"] = OSD.FromString(sog.ExtraToXmlString()); | ||
353 | if (allowScriptCrossing) | ||
354 | { | ||
355 | string state = sog.GetStateSnapshot(); | ||
356 | if (state.Length > 0) | ||
357 | args["state"] = OSD.FromString(state); | ||
358 | } | ||
359 | |||
360 | string strBuffer = ""; | ||
361 | byte[] buffer = new byte[1]; | ||
362 | try | ||
363 | { | ||
364 | strBuffer = OSDParser.SerializeJsonString(args); | ||
365 | UTF8Encoding str = new UTF8Encoding(); | ||
366 | buffer = str.GetBytes(strBuffer); | ||
367 | |||
368 | } | ||
369 | catch (Exception e) | ||
370 | { | ||
371 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message); | ||
372 | // ignore. buffer will be empty, caller should check. | ||
373 | } | ||
374 | |||
375 | Stream os = null; | ||
376 | try | ||
377 | { // send the Post | ||
378 | ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
379 | os = ObjectCreateRequest.GetRequestStream(); | ||
380 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
381 | os.Close(); | ||
382 | m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri); | ||
383 | } | ||
384 | //catch (WebException ex) | ||
385 | catch | ||
386 | { | ||
387 | // m_log.InfoFormat("[REST COMMS]: Bad send on CreateObject {0}", ex.Message); | ||
388 | |||
389 | return false; | ||
390 | } | ||
391 | |||
392 | // Let's wait for the response | ||
393 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall"); | ||
394 | |||
395 | try | ||
396 | { | ||
397 | WebResponse webResponse = ObjectCreateRequest.GetResponse(); | ||
398 | if (webResponse == null) | ||
399 | { | ||
400 | m_log.Info("[REST COMMS]: Null reply on DoCreateObjectCall post"); | ||
401 | } | ||
402 | |||
403 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
404 | //reply = sr.ReadToEnd().Trim(); | ||
405 | sr.ReadToEnd().Trim(); | ||
406 | sr.Close(); | ||
407 | //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply); | ||
408 | |||
409 | } | ||
410 | catch (WebException ex) | ||
411 | { | ||
412 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObjectCall {0}", ex.Message); | ||
413 | // ignore, really | ||
414 | } | ||
415 | |||
416 | return true; | ||
417 | |||
418 | } | ||
419 | |||
420 | public bool DoHelloNeighbourCall(RegionInfo region, RegionInfo thisRegion) | ||
421 | { | ||
422 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/"; | ||
423 | //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); | ||
424 | |||
425 | WebRequest HelloNeighbourRequest = WebRequest.Create(uri); | ||
426 | HelloNeighbourRequest.Method = "POST"; | ||
427 | HelloNeighbourRequest.ContentType = "application/json"; | ||
428 | HelloNeighbourRequest.Timeout = 10000; | ||
429 | |||
430 | // Fill it in | ||
431 | OSDMap args = null; | ||
432 | try | ||
433 | { | ||
434 | args = thisRegion.PackRegionInfoData(); | ||
435 | } | ||
436 | catch (Exception e) | ||
437 | { | ||
438 | m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message); | ||
439 | } | ||
440 | // Add the regionhandle of the destination region | ||
441 | ulong regionHandle = GetRegionHandle(region.RegionHandle); | ||
442 | args["destination_handle"] = OSD.FromString(regionHandle.ToString()); | ||
443 | |||
444 | string strBuffer = ""; | ||
445 | byte[] buffer = new byte[1]; | ||
446 | try | ||
447 | { | ||
448 | strBuffer = OSDParser.SerializeJsonString(args); | ||
449 | UTF8Encoding str = new UTF8Encoding(); | ||
450 | buffer = str.GetBytes(strBuffer); | ||
451 | |||
452 | } | ||
453 | catch (Exception e) | ||
454 | { | ||
455 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message); | ||
456 | // ignore. buffer will be empty, caller should check. | ||
457 | } | ||
458 | |||
459 | Stream os = null; | ||
460 | try | ||
461 | { // send the Post | ||
462 | HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send | ||
463 | os = HelloNeighbourRequest.GetRequestStream(); | ||
464 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
465 | os.Close(); | ||
466 | //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri); | ||
467 | } | ||
468 | //catch (WebException ex) | ||
469 | catch | ||
470 | { | ||
471 | //m_log.InfoFormat("[REST COMMS]: Bad send on HelloNeighbour {0}", ex.Message); | ||
472 | |||
473 | return false; | ||
474 | } | ||
475 | |||
476 | // Let's wait for the response | ||
477 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); | ||
478 | |||
479 | try | ||
480 | { | ||
481 | WebResponse webResponse = HelloNeighbourRequest.GetResponse(); | ||
482 | if (webResponse == null) | ||
483 | { | ||
484 | m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post"); | ||
485 | } | ||
486 | |||
487 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
488 | //reply = sr.ReadToEnd().Trim(); | ||
489 | sr.ReadToEnd().Trim(); | ||
490 | sr.Close(); | ||
491 | //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); | ||
492 | |||
493 | } | ||
494 | catch (WebException ex) | ||
495 | { | ||
496 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message); | ||
497 | // ignore, really | ||
498 | } | ||
499 | |||
500 | return true; | ||
501 | |||
502 | } | ||
503 | |||
504 | #region Hyperlinks | ||
505 | |||
506 | public virtual ulong GetRegionHandle(ulong handle) | ||
507 | { | ||
508 | return handle; | ||
509 | } | ||
510 | |||
511 | public virtual bool IsHyperlink(ulong handle) | ||
512 | { | ||
513 | return false; | ||
514 | } | ||
515 | |||
516 | public virtual void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit) | ||
517 | { | ||
518 | } | ||
519 | |||
520 | public virtual void AdjustUserInformation(AgentCircuitData aCircuit) | ||
521 | { | ||
522 | } | ||
523 | |||
524 | #endregion /* Hyperlinks */ | ||
525 | |||
526 | public static OSDMap GetOSDMap(string data) | ||
527 | { | ||
528 | OSDMap args = null; | ||
529 | try | ||
530 | { | ||
531 | OSD buffer; | ||
532 | // We should pay attention to the content-type, but let's assume we know it's Json | ||
533 | buffer = OSDParser.DeserializeJson(data); | ||
534 | if (buffer.Type == OSDType.Map) | ||
535 | { | ||
536 | args = (OSDMap)buffer; | ||
537 | return args; | ||
538 | } | ||
539 | else | ||
540 | { | ||
541 | // uh? | ||
542 | System.Console.WriteLine("[REST COMMS]: Got OSD of type " + buffer.Type.ToString()); | ||
543 | return null; | ||
544 | } | ||
545 | } | ||
546 | catch (Exception ex) | ||
547 | { | ||
548 | System.Console.WriteLine("[REST COMMS]: exception on parse of REST message " + ex.Message); | ||
549 | return null; | ||
550 | } | ||
551 | } | ||
552 | |||
553 | |||
554 | } | ||
555 | } | ||
diff --git a/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs b/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs index 7d6a988..b507bdd 100644 --- a/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs +++ b/OpenSim/Region/CoreModules/Communications/REST/RESTInterregionComms.cs | |||
@@ -36,6 +36,7 @@ using OpenMetaverse; | |||
36 | using OpenMetaverse.StructuredData; | 36 | using OpenMetaverse.StructuredData; |
37 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Communications; | 38 | using OpenSim.Framework.Communications; |
39 | using OpenSim.Framework.Communications.Clients; | ||
39 | using OpenSim.Region.CoreModules.Communications.Local; | 40 | using OpenSim.Region.CoreModules.Communications.Local; |
40 | using OpenSim.Region.Framework.Interfaces; | 41 | using OpenSim.Region.Framework.Interfaces; |
41 | using OpenSim.Region.Framework.Scenes; | 42 | using OpenSim.Region.Framework.Scenes; |
@@ -55,6 +56,8 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
55 | 56 | ||
56 | protected CommunicationsManager m_commsManager; | 57 | protected CommunicationsManager m_commsManager; |
57 | 58 | ||
59 | protected RegionToRegionClient m_regionClient; | ||
60 | |||
58 | #region IRegionModule | 61 | #region IRegionModule |
59 | 62 | ||
60 | public virtual void Initialise(Scene scene, IConfigSource config) | 63 | public virtual void Initialise(Scene scene, IConfigSource config) |
@@ -112,6 +115,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
112 | m_localBackend = new LocalInterregionComms(); | 115 | m_localBackend = new LocalInterregionComms(); |
113 | m_commsManager = scene.CommsManager; | 116 | m_commsManager = scene.CommsManager; |
114 | m_aScene = scene; | 117 | m_aScene = scene; |
118 | m_regionClient = new RegionToRegionClient(m_aScene); | ||
115 | } | 119 | } |
116 | 120 | ||
117 | protected virtual void AddHTTPHandlers() | 121 | protected virtual void AddHTTPHandlers() |
@@ -141,9 +145,9 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
141 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); | 145 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); |
142 | if (regInfo != null) | 146 | if (regInfo != null) |
143 | { | 147 | { |
144 | SendUserInformation(regInfo, aCircuit); | 148 | m_regionClient.SendUserInformation(regInfo, aCircuit); |
145 | 149 | ||
146 | return DoCreateChildAgentCall(regInfo, aCircuit); | 150 | return m_regionClient.DoCreateChildAgentCall(regInfo, aCircuit); |
147 | } | 151 | } |
148 | //else | 152 | //else |
149 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | 153 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); |
@@ -163,7 +167,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
163 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); | 167 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); |
164 | if (regInfo != null) | 168 | if (regInfo != null) |
165 | { | 169 | { |
166 | return DoChildAgentUpdateCall(regInfo, cAgentData); | 170 | return m_regionClient.DoChildAgentUpdateCall(regInfo, cAgentData); |
167 | } | 171 | } |
168 | //else | 172 | //else |
169 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | 173 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); |
@@ -184,7 +188,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
184 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); | 188 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); |
185 | if (regInfo != null) | 189 | if (regInfo != null) |
186 | { | 190 | { |
187 | return DoChildAgentUpdateCall(regInfo, cAgentData); | 191 | return m_regionClient.DoChildAgentUpdateCall(regInfo, cAgentData); |
188 | } | 192 | } |
189 | //else | 193 | //else |
190 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | 194 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); |
@@ -205,7 +209,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
205 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); | 209 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); |
206 | if (regInfo != null) | 210 | if (regInfo != null) |
207 | { | 211 | { |
208 | return DoRetrieveRootAgentCall(regInfo, id, out agent); | 212 | return m_regionClient.DoRetrieveRootAgentCall(regInfo, id, out agent); |
209 | } | 213 | } |
210 | //else | 214 | //else |
211 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | 215 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); |
@@ -221,7 +225,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
221 | return true; | 225 | return true; |
222 | 226 | ||
223 | // else do the remote thing | 227 | // else do the remote thing |
224 | return DoReleaseAgentCall(regionHandle, id, uri); | 228 | return m_regionClient.DoReleaseAgentCall(regionHandle, id, uri); |
225 | } | 229 | } |
226 | 230 | ||
227 | 231 | ||
@@ -237,7 +241,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
237 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); | 241 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); |
238 | if (regInfo != null) | 242 | if (regInfo != null) |
239 | { | 243 | { |
240 | return DoCloseAgentCall(regInfo, id); | 244 | return m_regionClient.DoCloseAgentCall(regInfo, id); |
241 | } | 245 | } |
242 | //else | 246 | //else |
243 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | 247 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); |
@@ -264,7 +268,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
264 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); | 268 | RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); |
265 | if (regInfo != null) | 269 | if (regInfo != null) |
266 | { | 270 | { |
267 | return DoCreateObjectCall(regInfo, sog); | 271 | return m_regionClient.DoCreateObjectCall(regInfo, sog, m_aScene.m_allowScriptCrossings); |
268 | } | 272 | } |
269 | //else | 273 | //else |
270 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | 274 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); |
@@ -291,7 +295,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
291 | // Don't remote-call this instance; that's a startup hickup | 295 | // Don't remote-call this instance; that's a startup hickup |
292 | !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort))) | 296 | !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort))) |
293 | { | 297 | { |
294 | return DoHelloNeighbourCall(regInfo, thisRegion); | 298 | return m_regionClient.DoHelloNeighbourCall(regInfo, thisRegion); |
295 | } | 299 | } |
296 | //else | 300 | //else |
297 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | 301 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); |
@@ -300,472 +304,6 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
300 | 304 | ||
301 | #endregion /* IInterregionComms */ | 305 | #endregion /* IInterregionComms */ |
302 | 306 | ||
303 | #region DoWork functions for the above public interface | ||
304 | |||
305 | //------------------------------------------------------------------- | ||
306 | // Internal functions for the above public interface | ||
307 | //------------------------------------------------------------------- | ||
308 | |||
309 | public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit) | ||
310 | { | ||
311 | // Eventually, we want to use a caps url instead of the agentID | ||
312 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/"; | ||
313 | //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri); | ||
314 | |||
315 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
316 | AgentCreateRequest.Method = "POST"; | ||
317 | AgentCreateRequest.ContentType = "application/json"; | ||
318 | AgentCreateRequest.Timeout = 10000; | ||
319 | //AgentCreateRequest.KeepAlive = false; | ||
320 | |||
321 | // Fill it in | ||
322 | OSDMap args = null; | ||
323 | try | ||
324 | { | ||
325 | args = aCircuit.PackAgentCircuitData(); | ||
326 | } | ||
327 | catch (Exception e) | ||
328 | { | ||
329 | m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message); | ||
330 | } | ||
331 | // Add the regionhandle of the destination region | ||
332 | ulong regionHandle = GetRegionHandle(region.RegionHandle); | ||
333 | args["destination_handle"] = OSD.FromString(regionHandle.ToString()); | ||
334 | |||
335 | string strBuffer = ""; | ||
336 | byte[] buffer = new byte[1]; | ||
337 | try | ||
338 | { | ||
339 | strBuffer = OSDParser.SerializeJsonString(args); | ||
340 | UTF8Encoding str = new UTF8Encoding(); | ||
341 | buffer = str.GetBytes(strBuffer); | ||
342 | |||
343 | } | ||
344 | catch (Exception e) | ||
345 | { | ||
346 | m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
347 | // ignore. buffer will be empty, caller should check. | ||
348 | } | ||
349 | |||
350 | Stream os = null; | ||
351 | try | ||
352 | { // send the Post | ||
353 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
354 | os = AgentCreateRequest.GetRequestStream(); | ||
355 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
356 | os.Close(); | ||
357 | //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri); | ||
358 | } | ||
359 | //catch (WebException ex) | ||
360 | catch | ||
361 | { | ||
362 | //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
363 | |||
364 | return false; | ||
365 | } | ||
366 | |||
367 | // Let's wait for the response | ||
368 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall"); | ||
369 | |||
370 | try | ||
371 | { | ||
372 | WebResponse webResponse = AgentCreateRequest.GetResponse(); | ||
373 | if (webResponse == null) | ||
374 | { | ||
375 | m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post"); | ||
376 | } | ||
377 | |||
378 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
379 | //reply = sr.ReadToEnd().Trim(); | ||
380 | sr.ReadToEnd().Trim(); | ||
381 | sr.Close(); | ||
382 | //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply); | ||
383 | |||
384 | } | ||
385 | catch (WebException ex) | ||
386 | { | ||
387 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
388 | // ignore, really | ||
389 | } | ||
390 | |||
391 | return true; | ||
392 | |||
393 | } | ||
394 | |||
395 | public bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData) | ||
396 | { | ||
397 | // Eventually, we want to use a caps url instead of the agentID | ||
398 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + cAgentData.AgentID + "/"; | ||
399 | //Console.WriteLine(" >>> DoChildAgentUpdateCall <<< " + uri); | ||
400 | |||
401 | HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
402 | ChildUpdateRequest.Method = "PUT"; | ||
403 | ChildUpdateRequest.ContentType = "application/json"; | ||
404 | ChildUpdateRequest.Timeout = 10000; | ||
405 | //ChildUpdateRequest.KeepAlive = false; | ||
406 | |||
407 | // Fill it in | ||
408 | OSDMap args = null; | ||
409 | try | ||
410 | { | ||
411 | args = cAgentData.Pack(); | ||
412 | } | ||
413 | catch (Exception e) | ||
414 | { | ||
415 | m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message); | ||
416 | } | ||
417 | // Add the regionhandle of the destination region | ||
418 | ulong regionHandle = GetRegionHandle(region.RegionHandle); | ||
419 | args["destination_handle"] = OSD.FromString(regionHandle.ToString()); | ||
420 | |||
421 | string strBuffer = ""; | ||
422 | byte[] buffer = new byte[1]; | ||
423 | try | ||
424 | { | ||
425 | strBuffer = OSDParser.SerializeJsonString(args); | ||
426 | UTF8Encoding str = new UTF8Encoding(); | ||
427 | buffer = str.GetBytes(strBuffer); | ||
428 | |||
429 | } | ||
430 | catch (Exception e) | ||
431 | { | ||
432 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); | ||
433 | // ignore. buffer will be empty, caller should check. | ||
434 | } | ||
435 | |||
436 | Stream os = null; | ||
437 | try | ||
438 | { // send the Post | ||
439 | ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
440 | os = ChildUpdateRequest.GetRequestStream(); | ||
441 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
442 | os.Close(); | ||
443 | //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri); | ||
444 | } | ||
445 | //catch (WebException ex) | ||
446 | catch | ||
447 | { | ||
448 | //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
449 | |||
450 | return false; | ||
451 | } | ||
452 | |||
453 | // Let's wait for the response | ||
454 | //m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate"); | ||
455 | |||
456 | try | ||
457 | { | ||
458 | WebResponse webResponse = ChildUpdateRequest.GetResponse(); | ||
459 | if (webResponse == null) | ||
460 | { | ||
461 | m_log.Info("[REST COMMS]: Null reply on ChilAgentUpdate post"); | ||
462 | } | ||
463 | |||
464 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
465 | //reply = sr.ReadToEnd().Trim(); | ||
466 | sr.ReadToEnd().Trim(); | ||
467 | sr.Close(); | ||
468 | //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply); | ||
469 | |||
470 | } | ||
471 | catch (WebException ex) | ||
472 | { | ||
473 | m_log.InfoFormat("[REST COMMS]: exception on reply of ChilAgentUpdate {0}", ex.Message); | ||
474 | // ignore, really | ||
475 | } | ||
476 | |||
477 | return true; | ||
478 | } | ||
479 | |||
480 | public bool DoRetrieveRootAgentCall(RegionInfo region, UUID id, out IAgentData agent) | ||
481 | { | ||
482 | agent = null; | ||
483 | // Eventually, we want to use a caps url instead of the agentID | ||
484 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() + "/"; | ||
485 | //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri); | ||
486 | |||
487 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
488 | request.Method = "GET"; | ||
489 | request.Timeout = 10000; | ||
490 | //request.Headers.Add("authorization", ""); // coming soon | ||
491 | |||
492 | HttpWebResponse webResponse = null; | ||
493 | string reply = string.Empty; | ||
494 | try | ||
495 | { | ||
496 | webResponse = (HttpWebResponse)request.GetResponse(); | ||
497 | if (webResponse == null) | ||
498 | { | ||
499 | m_log.Info("[REST COMMS]: Null reply on agent get "); | ||
500 | } | ||
501 | |||
502 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
503 | reply = sr.ReadToEnd().Trim(); | ||
504 | sr.Close(); | ||
505 | |||
506 | //Console.WriteLine("[REST COMMS]: ChilAgentUpdate reply was " + reply); | ||
507 | |||
508 | } | ||
509 | catch (WebException ex) | ||
510 | { | ||
511 | m_log.InfoFormat("[REST COMMS]: exception on reply of agent get {0}", ex.Message); | ||
512 | // ignore, really | ||
513 | return false; | ||
514 | } | ||
515 | |||
516 | if (webResponse.StatusCode == HttpStatusCode.OK) | ||
517 | { | ||
518 | // we know it's jason | ||
519 | OSDMap args = GetOSDMap(reply); | ||
520 | if (args == null) | ||
521 | { | ||
522 | //Console.WriteLine("[REST COMMS]: Error getting OSDMap from reply"); | ||
523 | return false; | ||
524 | } | ||
525 | |||
526 | agent = new CompleteAgentData(); | ||
527 | agent.Unpack(args); | ||
528 | return true; | ||
529 | } | ||
530 | |||
531 | //Console.WriteLine("[REST COMMS]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode); | ||
532 | return false; | ||
533 | } | ||
534 | |||
535 | public bool DoReleaseAgentCall(ulong regionHandle, UUID id, string uri) | ||
536 | { | ||
537 | //m_log.Debug(" >>> DoReleaseAgentCall <<< " + uri); | ||
538 | |||
539 | WebRequest request = WebRequest.Create(uri); | ||
540 | request.Method = "DELETE"; | ||
541 | request.Timeout = 10000; | ||
542 | |||
543 | try | ||
544 | { | ||
545 | WebResponse webResponse = request.GetResponse(); | ||
546 | if (webResponse == null) | ||
547 | { | ||
548 | m_log.Info("[REST COMMS]: Null reply on agent delete "); | ||
549 | } | ||
550 | |||
551 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
552 | //reply = sr.ReadToEnd().Trim(); | ||
553 | sr.ReadToEnd().Trim(); | ||
554 | sr.Close(); | ||
555 | //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply); | ||
556 | |||
557 | } | ||
558 | catch (WebException ex) | ||
559 | { | ||
560 | m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message); | ||
561 | // ignore, really | ||
562 | } | ||
563 | |||
564 | return true; | ||
565 | } | ||
566 | |||
567 | |||
568 | public bool DoCloseAgentCall(RegionInfo region, UUID id) | ||
569 | { | ||
570 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() +"/"; | ||
571 | |||
572 | //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri); | ||
573 | |||
574 | WebRequest request = WebRequest.Create(uri); | ||
575 | request.Method = "DELETE"; | ||
576 | request.Timeout = 10000; | ||
577 | |||
578 | try | ||
579 | { | ||
580 | WebResponse webResponse = request.GetResponse(); | ||
581 | if (webResponse == null) | ||
582 | { | ||
583 | m_log.Info("[REST COMMS]: Null reply on agent delete "); | ||
584 | } | ||
585 | |||
586 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
587 | //reply = sr.ReadToEnd().Trim(); | ||
588 | sr.ReadToEnd().Trim(); | ||
589 | sr.Close(); | ||
590 | //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply); | ||
591 | |||
592 | } | ||
593 | catch (WebException ex) | ||
594 | { | ||
595 | m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message); | ||
596 | // ignore, really | ||
597 | } | ||
598 | |||
599 | return true; | ||
600 | } | ||
601 | |||
602 | public bool DoCreateObjectCall(RegionInfo region, ISceneObject sog) | ||
603 | { | ||
604 | ulong regionHandle = GetRegionHandle(region.RegionHandle); | ||
605 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/object/" + sog.UUID + "/" + regionHandle.ToString() + "/"; | ||
606 | //m_log.Debug(" >>> DoCreateChildAgentCall <<< " + uri); | ||
607 | |||
608 | WebRequest ObjectCreateRequest = WebRequest.Create(uri); | ||
609 | ObjectCreateRequest.Method = "POST"; | ||
610 | ObjectCreateRequest.ContentType = "application/json"; | ||
611 | ObjectCreateRequest.Timeout = 10000; | ||
612 | |||
613 | OSDMap args = new OSDMap(2); | ||
614 | args["sog"] = OSD.FromString(sog.ToXmlString2()); | ||
615 | args["extra"] = OSD.FromString(sog.ExtraToXmlString()); | ||
616 | if (m_aScene.m_allowScriptCrossings) | ||
617 | { | ||
618 | string state = sog.GetStateSnapshot(); | ||
619 | if (state.Length > 0) | ||
620 | args["state"] = OSD.FromString(state); | ||
621 | } | ||
622 | |||
623 | string strBuffer = ""; | ||
624 | byte[] buffer = new byte[1]; | ||
625 | try | ||
626 | { | ||
627 | strBuffer = OSDParser.SerializeJsonString(args); | ||
628 | UTF8Encoding str = new UTF8Encoding(); | ||
629 | buffer = str.GetBytes(strBuffer); | ||
630 | |||
631 | } | ||
632 | catch (Exception e) | ||
633 | { | ||
634 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message); | ||
635 | // ignore. buffer will be empty, caller should check. | ||
636 | } | ||
637 | |||
638 | Stream os = null; | ||
639 | try | ||
640 | { // send the Post | ||
641 | ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
642 | os = ObjectCreateRequest.GetRequestStream(); | ||
643 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
644 | os.Close(); | ||
645 | m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri); | ||
646 | } | ||
647 | //catch (WebException ex) | ||
648 | catch | ||
649 | { | ||
650 | // m_log.InfoFormat("[REST COMMS]: Bad send on CreateObject {0}", ex.Message); | ||
651 | |||
652 | return false; | ||
653 | } | ||
654 | |||
655 | // Let's wait for the response | ||
656 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall"); | ||
657 | |||
658 | try | ||
659 | { | ||
660 | WebResponse webResponse = ObjectCreateRequest.GetResponse(); | ||
661 | if (webResponse == null) | ||
662 | { | ||
663 | m_log.Info("[REST COMMS]: Null reply on DoCreateObjectCall post"); | ||
664 | } | ||
665 | |||
666 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
667 | //reply = sr.ReadToEnd().Trim(); | ||
668 | sr.ReadToEnd().Trim(); | ||
669 | sr.Close(); | ||
670 | //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply); | ||
671 | |||
672 | } | ||
673 | catch (WebException ex) | ||
674 | { | ||
675 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObjectCall {0}", ex.Message); | ||
676 | // ignore, really | ||
677 | } | ||
678 | |||
679 | return true; | ||
680 | |||
681 | } | ||
682 | |||
683 | public bool DoHelloNeighbourCall(RegionInfo region, RegionInfo thisRegion) | ||
684 | { | ||
685 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/"; | ||
686 | //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); | ||
687 | |||
688 | WebRequest HelloNeighbourRequest = WebRequest.Create(uri); | ||
689 | HelloNeighbourRequest.Method = "POST"; | ||
690 | HelloNeighbourRequest.ContentType = "application/json"; | ||
691 | HelloNeighbourRequest.Timeout = 10000; | ||
692 | |||
693 | // Fill it in | ||
694 | OSDMap args = null; | ||
695 | try | ||
696 | { | ||
697 | args = thisRegion.PackRegionInfoData(); | ||
698 | } | ||
699 | catch (Exception e) | ||
700 | { | ||
701 | m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message); | ||
702 | } | ||
703 | // Add the regionhandle of the destination region | ||
704 | ulong regionHandle = GetRegionHandle(region.RegionHandle); | ||
705 | args["destination_handle"] = OSD.FromString(regionHandle.ToString()); | ||
706 | |||
707 | string strBuffer = ""; | ||
708 | byte[] buffer = new byte[1]; | ||
709 | try | ||
710 | { | ||
711 | strBuffer = OSDParser.SerializeJsonString(args); | ||
712 | UTF8Encoding str = new UTF8Encoding(); | ||
713 | buffer = str.GetBytes(strBuffer); | ||
714 | |||
715 | } | ||
716 | catch (Exception e) | ||
717 | { | ||
718 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message); | ||
719 | // ignore. buffer will be empty, caller should check. | ||
720 | } | ||
721 | |||
722 | Stream os = null; | ||
723 | try | ||
724 | { // send the Post | ||
725 | HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send | ||
726 | os = HelloNeighbourRequest.GetRequestStream(); | ||
727 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
728 | os.Close(); | ||
729 | //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri); | ||
730 | } | ||
731 | //catch (WebException ex) | ||
732 | catch | ||
733 | { | ||
734 | //m_log.InfoFormat("[REST COMMS]: Bad send on HelloNeighbour {0}", ex.Message); | ||
735 | |||
736 | return false; | ||
737 | } | ||
738 | |||
739 | // Let's wait for the response | ||
740 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); | ||
741 | |||
742 | try | ||
743 | { | ||
744 | WebResponse webResponse = HelloNeighbourRequest.GetResponse(); | ||
745 | if (webResponse == null) | ||
746 | { | ||
747 | m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post"); | ||
748 | } | ||
749 | |||
750 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
751 | //reply = sr.ReadToEnd().Trim(); | ||
752 | sr.ReadToEnd().Trim(); | ||
753 | sr.Close(); | ||
754 | //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); | ||
755 | |||
756 | } | ||
757 | catch (WebException ex) | ||
758 | { | ||
759 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message); | ||
760 | // ignore, really | ||
761 | } | ||
762 | |||
763 | return true; | ||
764 | |||
765 | } | ||
766 | |||
767 | #endregion /* Do Work */ | ||
768 | |||
769 | #region Incoming calls from remote instances | 307 | #region Incoming calls from remote instances |
770 | 308 | ||
771 | /** | 309 | /** |
@@ -833,7 +371,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
833 | 371 | ||
834 | protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) | 372 | protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) |
835 | { | 373 | { |
836 | OSDMap args = GetOSDMap((string)request["body"]); | 374 | OSDMap args = RegionClient.GetOSDMap((string)request["body"]); |
837 | if (args == null) | 375 | if (args == null) |
838 | { | 376 | { |
839 | responsedata["int_response_code"] = 400; | 377 | responsedata["int_response_code"] = 400; |
@@ -858,7 +396,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
858 | } | 396 | } |
859 | 397 | ||
860 | // This is the meaning of POST agent | 398 | // This is the meaning of POST agent |
861 | AdjustUserInformation(aCircuit); | 399 | m_regionClient.AdjustUserInformation(aCircuit); |
862 | bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit); | 400 | bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit); |
863 | 401 | ||
864 | responsedata["int_response_code"] = 200; | 402 | responsedata["int_response_code"] = 200; |
@@ -867,7 +405,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
867 | 405 | ||
868 | protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata) | 406 | protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata) |
869 | { | 407 | { |
870 | OSDMap args = GetOSDMap((string)request["body"]); | 408 | OSDMap args = RegionClient.GetOSDMap((string)request["body"]); |
871 | if (args == null) | 409 | if (args == null) |
872 | { | 410 | { |
873 | responsedata["int_response_code"] = 400; | 411 | responsedata["int_response_code"] = 400; |
@@ -1042,7 +580,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
1042 | 580 | ||
1043 | protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle) | 581 | protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle) |
1044 | { | 582 | { |
1045 | OSDMap args = GetOSDMap((string)request["body"]); | 583 | OSDMap args = RegionClient.GetOSDMap((string)request["body"]); |
1046 | if (args == null) | 584 | if (args == null) |
1047 | { | 585 | { |
1048 | responsedata["int_response_code"] = 400; | 586 | responsedata["int_response_code"] = 400; |
@@ -1154,7 +692,7 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
1154 | 692 | ||
1155 | protected virtual void DoRegionPost(Hashtable request, Hashtable responsedata, UUID id) | 693 | protected virtual void DoRegionPost(Hashtable request, Hashtable responsedata, UUID id) |
1156 | { | 694 | { |
1157 | OSDMap args = GetOSDMap((string)request["body"]); | 695 | OSDMap args = RegionClient.GetOSDMap((string)request["body"]); |
1158 | if (args == null) | 696 | if (args == null) |
1159 | { | 697 | { |
1160 | responsedata["int_response_code"] = 400; | 698 | responsedata["int_response_code"] = 400; |
@@ -1190,32 +728,6 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
1190 | 728 | ||
1191 | #region Misc | 729 | #region Misc |
1192 | 730 | ||
1193 | public static OSDMap GetOSDMap(string data) | ||
1194 | { | ||
1195 | OSDMap args = null; | ||
1196 | try | ||
1197 | { | ||
1198 | OSD buffer; | ||
1199 | // We should pay attention to the content-type, but let's assume we know it's Json | ||
1200 | buffer = OSDParser.DeserializeJson(data); | ||
1201 | if (buffer.Type == OSDType.Map) | ||
1202 | { | ||
1203 | args = (OSDMap)buffer; | ||
1204 | return args; | ||
1205 | } | ||
1206 | else | ||
1207 | { | ||
1208 | // uh? | ||
1209 | Console.WriteLine("[REST COMMS]: Got OSD of type " + buffer.Type.ToString()); | ||
1210 | return null; | ||
1211 | } | ||
1212 | } | ||
1213 | catch (Exception ex) | ||
1214 | { | ||
1215 | Console.WriteLine("[REST COMMS]: exception on parse of REST message " + ex.Message); | ||
1216 | return null; | ||
1217 | } | ||
1218 | } | ||
1219 | 731 | ||
1220 | /// <summary> | 732 | /// <summary> |
1221 | /// Extract the param from an uri. | 733 | /// Extract the param from an uri. |
@@ -1251,45 +763,51 @@ namespace OpenSim.Region.CoreModules.Communications.REST | |||
1251 | 763 | ||
1252 | #endregion Misc | 764 | #endregion Misc |
1253 | 765 | ||
1254 | #region Hyperlinks | 766 | protected class RegionToRegionClient : RegionClient |
1255 | |||
1256 | protected virtual ulong GetRegionHandle(ulong handle) | ||
1257 | { | 767 | { |
1258 | if (m_aScene.SceneGridService is HGSceneCommunicationService) | 768 | Scene m_aScene = null; |
1259 | return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(handle); | ||
1260 | 769 | ||
1261 | return handle; | 770 | public RegionToRegionClient(Scene s) |
1262 | } | 771 | { |
772 | m_aScene = s; | ||
773 | } | ||
1263 | 774 | ||
1264 | protected virtual bool IsHyperlink(ulong handle) | 775 | public override ulong GetRegionHandle(ulong handle) |
1265 | { | 776 | { |
1266 | if (m_aScene.SceneGridService is HGSceneCommunicationService) | 777 | if (m_aScene.SceneGridService is HGSceneCommunicationService) |
1267 | return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.IsHyperlinkRegion(handle); | 778 | return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(handle); |
1268 | 779 | ||
1269 | return false; | 780 | return handle; |
1270 | } | 781 | } |
1271 | 782 | ||
1272 | protected virtual void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit) | 783 | public override bool IsHyperlink(ulong handle) |
1273 | { | ||
1274 | try | ||
1275 | { | 784 | { |
1276 | //if (IsHyperlink(regInfo.RegionHandle)) | ||
1277 | if (m_aScene.SceneGridService is HGSceneCommunicationService) | 785 | if (m_aScene.SceneGridService is HGSceneCommunicationService) |
786 | return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.IsHyperlinkRegion(handle); | ||
787 | |||
788 | return false; | ||
789 | } | ||
790 | |||
791 | public override void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit) | ||
792 | { | ||
793 | try | ||
1278 | { | 794 | { |
1279 | ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(regInfo, aCircuit); | 795 | if (m_aScene.SceneGridService is HGSceneCommunicationService) |
796 | { | ||
797 | ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(regInfo, aCircuit); | ||
798 | } | ||
1280 | } | 799 | } |
1281 | } | 800 | catch // Bad cast |
1282 | catch // Bad cast | 801 | { } |
1283 | { } | ||
1284 | 802 | ||
1285 | } | 803 | } |
1286 | 804 | ||
1287 | protected virtual void AdjustUserInformation(AgentCircuitData aCircuit) | 805 | public override void AdjustUserInformation(AgentCircuitData aCircuit) |
1288 | { | 806 | { |
1289 | if (m_aScene.SceneGridService is HGSceneCommunicationService) | 807 | if (m_aScene.SceneGridService is HGSceneCommunicationService) |
1290 | ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit); | 808 | ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit); |
809 | } | ||
1291 | } | 810 | } |
1292 | #endregion /* Hyperlinks */ | ||
1293 | 811 | ||
1294 | } | 812 | } |
1295 | } | 813 | } |