diff options
author | diva | 2009-06-14 15:45:28 +0000 |
---|---|---|
committer | diva | 2009-06-14 15:45:28 +0000 |
commit | 9ad33546ca6c6d3f7b7f60d5d2b5358c20e98f43 (patch) | |
tree | a203f56111da6102a6d42ca1400adc22fefca565 /OpenSim/Services | |
parent | Oops. Forgot to add this file. (diff) | |
download | opensim-SC-9ad33546ca6c6d3f7b7f60d5d2b5358c20e98f43.zip opensim-SC-9ad33546ca6c6d3f7b7f60d5d2b5358c20e98f43.tar.gz opensim-SC-9ad33546ca6c6d3f7b7f60d5d2b5358c20e98f43.tar.bz2 opensim-SC-9ad33546ca6c6d3f7b7f60d5d2b5358c20e98f43.tar.xz |
And this one too...
Diffstat (limited to 'OpenSim/Services')
-rw-r--r-- | OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs new file mode 100644 index 0000000..d6f5fe9 --- /dev/null +++ b/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs | |||
@@ -0,0 +1,166 @@ | |||
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 OpenSimulator 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 log4net; | ||
29 | using System; | ||
30 | using System.Collections; | ||
31 | using System.Collections.Generic; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Reflection; | ||
35 | using System.Text; | ||
36 | using Nini.Config; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Communications; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenMetaverse; | ||
42 | using OpenMetaverse.StructuredData; | ||
43 | |||
44 | namespace OpenSim.Services.Connectors | ||
45 | { | ||
46 | public class NeighbourServicesConnector : INeighbourService | ||
47 | { | ||
48 | private static readonly ILog m_log = | ||
49 | LogManager.GetLogger( | ||
50 | MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IGridServices m_MapService = null; | ||
53 | |||
54 | public NeighbourServicesConnector() | ||
55 | { | ||
56 | } | ||
57 | |||
58 | public NeighbourServicesConnector(IGridServices gridServices) | ||
59 | { | ||
60 | Initialise(gridServices); | ||
61 | } | ||
62 | |||
63 | public virtual void Initialise(IGridServices gridServices) | ||
64 | { | ||
65 | m_MapService = gridServices; | ||
66 | } | ||
67 | |||
68 | public virtual bool HelloNeighbour(ulong regionHandle, RegionInfo thisRegion) | ||
69 | { | ||
70 | RegionInfo regInfo = m_MapService.RequestNeighbourInfo(regionHandle); | ||
71 | if ((regInfo != null) && | ||
72 | // Don't remote-call this instance; that's a startup hickup | ||
73 | !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort))) | ||
74 | { | ||
75 | return DoHelloNeighbourCall(regInfo, thisRegion); | ||
76 | } | ||
77 | //else | ||
78 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | ||
79 | return false; | ||
80 | } | ||
81 | |||
82 | public bool DoHelloNeighbourCall(RegionInfo region, RegionInfo thisRegion) | ||
83 | { | ||
84 | string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/"; | ||
85 | //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); | ||
86 | |||
87 | WebRequest HelloNeighbourRequest = WebRequest.Create(uri); | ||
88 | HelloNeighbourRequest.Method = "POST"; | ||
89 | HelloNeighbourRequest.ContentType = "application/json"; | ||
90 | HelloNeighbourRequest.Timeout = 10000; | ||
91 | |||
92 | // Fill it in | ||
93 | OSDMap args = null; | ||
94 | try | ||
95 | { | ||
96 | args = thisRegion.PackRegionInfoData(); | ||
97 | } | ||
98 | catch (Exception e) | ||
99 | { | ||
100 | m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message); | ||
101 | } | ||
102 | // Add the regionhandle of the destination region | ||
103 | args["destination_handle"] = OSD.FromString(region.RegionHandle.ToString()); | ||
104 | |||
105 | string strBuffer = ""; | ||
106 | byte[] buffer = new byte[1]; | ||
107 | try | ||
108 | { | ||
109 | strBuffer = OSDParser.SerializeJsonString(args); | ||
110 | UTF8Encoding str = new UTF8Encoding(); | ||
111 | buffer = str.GetBytes(strBuffer); | ||
112 | |||
113 | } | ||
114 | catch (Exception e) | ||
115 | { | ||
116 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message); | ||
117 | // ignore. buffer will be empty, caller should check. | ||
118 | } | ||
119 | |||
120 | Stream os = null; | ||
121 | try | ||
122 | { // send the Post | ||
123 | HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send | ||
124 | os = HelloNeighbourRequest.GetRequestStream(); | ||
125 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
126 | os.Close(); | ||
127 | //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri); | ||
128 | } | ||
129 | //catch (WebException ex) | ||
130 | catch | ||
131 | { | ||
132 | //m_log.InfoFormat("[REST COMMS]: Bad send on HelloNeighbour {0}", ex.Message); | ||
133 | |||
134 | return false; | ||
135 | } | ||
136 | |||
137 | // Let's wait for the response | ||
138 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); | ||
139 | |||
140 | try | ||
141 | { | ||
142 | WebResponse webResponse = HelloNeighbourRequest.GetResponse(); | ||
143 | if (webResponse == null) | ||
144 | { | ||
145 | m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post"); | ||
146 | } | ||
147 | |||
148 | StreamReader sr = new StreamReader(webResponse.GetResponseStream()); | ||
149 | //reply = sr.ReadToEnd().Trim(); | ||
150 | sr.ReadToEnd().Trim(); | ||
151 | sr.Close(); | ||
152 | //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); | ||
153 | |||
154 | } | ||
155 | catch (WebException ex) | ||
156 | { | ||
157 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message); | ||
158 | // ignore, really | ||
159 | } | ||
160 | |||
161 | return true; | ||
162 | |||
163 | } | ||
164 | |||
165 | } | ||
166 | } | ||