aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Communications
diff options
context:
space:
mode:
authorJeff Ames2008-12-30 01:08:07 +0000
committerJeff Ames2008-12-30 01:08:07 +0000
commit2be0f7a6f0b66e25b0d7e0e6cfee93f0c41b562b (patch)
treec39317267e7f1d634fc1a922ded51c6e48e329d1 /OpenSim/Region/Environment/Modules/Communications
parentChanging the default Comms module to be RESTComms, in case none is specified ... (diff)
downloadopensim-SC_OLD-2be0f7a6f0b66e25b0d7e0e6cfee93f0c41b562b.zip
opensim-SC_OLD-2be0f7a6f0b66e25b0d7e0e6cfee93f0c41b562b.tar.gz
opensim-SC_OLD-2be0f7a6f0b66e25b0d7e0e6cfee93f0c41b562b.tar.bz2
opensim-SC_OLD-2be0f7a6f0b66e25b0d7e0e6cfee93f0c41b562b.tar.xz
Update svn properties, minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Communications')
-rw-r--r--OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs280
-rw-r--r--OpenSim/Region/Environment/Modules/Communications/REST/HGInterregionComms.cs172
-rw-r--r--OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs592
3 files changed, 522 insertions, 522 deletions
diff --git a/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs b/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
index 6812e6d..dc2e3de 100644
--- a/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
+++ b/OpenSim/Region/Environment/Modules/Communications/Local/LocalInterregionComms.cs
@@ -1,140 +1,140 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.Collections; 28using System.Collections;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Net; 30using System.Net;
31using System.Net.Sockets; 31using System.Net.Sockets;
32using System.Reflection; 32using System.Reflection;
33using System.Threading; 33using System.Threading;
34using System.Xml; 34using System.Xml;
35using OpenMetaverse; 35using OpenMetaverse;
36using log4net; 36using log4net;
37using Nini.Config; 37using Nini.Config;
38using Nwc.XmlRpc; 38using Nwc.XmlRpc;
39using OpenSim.Framework; 39using OpenSim.Framework;
40using OpenSim.Framework.Communications.Cache; 40using OpenSim.Framework.Communications.Cache;
41using OpenSim.Region.Environment.Interfaces; 41using OpenSim.Region.Environment.Interfaces;
42using OpenSim.Region.Interfaces; 42using OpenSim.Region.Interfaces;
43using OpenSim.Region.Environment.Scenes; 43using OpenSim.Region.Environment.Scenes;
44 44
45namespace OpenSim.Region.Environment.Modules.Communications.Local 45namespace OpenSim.Region.Environment.Modules.Communications.Local
46{ 46{
47 public class LocalInterregionComms : IRegionModule, IInterregionCommsOut, IInterregionCommsIn 47 public class LocalInterregionComms : IRegionModule, IInterregionCommsOut, IInterregionCommsIn
48 { 48 {
49 private bool m_enabled = false; 49 private bool m_enabled = false;
50 50
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private List<Scene> m_sceneList = new List<Scene>(); 52 private List<Scene> m_sceneList = new List<Scene>();
53 53
54 #region Events 54 #region Events
55 public event ChildAgentUpdateReceived OnChildAgentUpdate; 55 public event ChildAgentUpdateReceived OnChildAgentUpdate;
56 56
57 #endregion /* Events */ 57 #endregion /* Events */
58 58
59 #region IRegionModule 59 #region IRegionModule
60 60
61 public void Initialise(Scene scene, IConfigSource config) 61 public void Initialise(Scene scene, IConfigSource config)
62 { 62 {
63 if (m_sceneList.Count == 0) 63 if (m_sceneList.Count == 0)
64 { 64 {
65 IConfig startupConfig = config.Configs["Communications"]; 65 IConfig startupConfig = config.Configs["Communications"];
66 66
67 if ((startupConfig == null) || 67 if ((startupConfig == null) ||
68 (startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTCommms") == "LocalComms")) 68 (startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTCommms") == "LocalComms"))
69 m_enabled = true; 69 m_enabled = true;
70 } 70 }
71 71
72 if (!m_enabled) 72 if (!m_enabled)
73 return; 73 return;
74 74
75 Init(scene); 75 Init(scene);
76 76
77 } 77 }
78 78
79 public void PostInitialise() 79 public void PostInitialise()
80 { 80 {
81 } 81 }
82 82
83 public void Close() 83 public void Close()
84 { 84 {
85 } 85 }
86 86
87 public string Name 87 public string Name
88 { 88 {
89 get { return "LocalInterregionCommsModule"; } 89 get { return "LocalInterregionCommsModule"; }
90 } 90 }
91 91
92 public bool IsSharedModule 92 public bool IsSharedModule
93 { 93 {
94 get { return true; } 94 get { return true; }
95 } 95 }
96 /// <summary> 96 /// <summary>
97 /// Can be called from other modules. 97 /// Can be called from other modules.
98 /// </summary> 98 /// </summary>
99 /// <param name="scene"></param> 99 /// <param name="scene"></param>
100 public void Init(Scene scene) 100 public void Init(Scene scene)
101 { 101 {
102 if (!m_sceneList.Contains(scene)) 102 if (!m_sceneList.Contains(scene))
103 { 103 {
104 lock (m_sceneList) 104 lock (m_sceneList)
105 { 105 {
106 m_sceneList.Add(scene); 106 m_sceneList.Add(scene);
107 if (m_enabled) 107 if (m_enabled)
108 scene.RegisterModuleInterface<IInterregionCommsOut>(this); 108 scene.RegisterModuleInterface<IInterregionCommsOut>(this);
109 scene.RegisterModuleInterface<IInterregionCommsIn>(this); 109 scene.RegisterModuleInterface<IInterregionCommsIn>(this);
110 } 110 }
111 111
112 } 112 }
113 } 113 }
114 114
115 #endregion /* IRegionModule */ 115 #endregion /* IRegionModule */
116 116
117 #region IInterregionComms 117 #region IInterregionComms
118 118
119 public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) 119 public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData)
120 { 120 {
121 lock (m_sceneList) 121 lock (m_sceneList)
122 { 122 {
123 foreach (Scene s in m_sceneList) 123 foreach (Scene s in m_sceneList)
124 { 124 {
125 if (s.RegionInfo.RegionHandle == regionHandle) 125 if (s.RegionInfo.RegionHandle == regionHandle)
126 { 126 {
127 //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); 127 //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate");
128 return s.IncomingChildAgentDataUpdate(cAgentData); 128 return s.IncomingChildAgentDataUpdate(cAgentData);
129 //if (OnChildAgentUpdate != null) 129 //if (OnChildAgentUpdate != null)
130 // return OnChildAgentUpdate(cAgentData); 130 // return OnChildAgentUpdate(cAgentData);
131 } 131 }
132 } 132 }
133 } 133 }
134 m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); 134 m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
135 return false; 135 return false;
136 } 136 }
137 137
138 #endregion /* IInterregionComms */ 138 #endregion /* IInterregionComms */
139 } 139 }
140} 140}
diff --git a/OpenSim/Region/Environment/Modules/Communications/REST/HGInterregionComms.cs b/OpenSim/Region/Environment/Modules/Communications/REST/HGInterregionComms.cs
index a553136..a94ca8b 100644
--- a/OpenSim/Region/Environment/Modules/Communications/REST/HGInterregionComms.cs
+++ b/OpenSim/Region/Environment/Modules/Communications/REST/HGInterregionComms.cs
@@ -1,86 +1,86 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.Collections; 28using System.Collections;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31using log4net; 31using log4net;
32using Nini.Config; 32using Nini.Config;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Communications; 34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Communications.Cache; 35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Region.Environment.Interfaces; 36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Interfaces; 37using OpenSim.Region.Interfaces;
38using OpenSim.Region.Environment.Scenes; 38using OpenSim.Region.Environment.Scenes;
39using OpenSim.Region.Environment.Scenes.Hypergrid; 39using OpenSim.Region.Environment.Scenes.Hypergrid;
40 40
41namespace OpenSim.Region.Environment.Modules.Communications.REST 41namespace OpenSim.Region.Environment.Modules.Communications.REST
42{ 42{
43 public class HGInterregionComms : RESTInterregionComms 43 public class HGInterregionComms : RESTInterregionComms
44 { 44 {
45 private static bool initialized = false; 45 private static bool initialized = false;
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 47
48 #region IRegionModule 48 #region IRegionModule
49 49
50 public override void Initialise(Scene scene, IConfigSource config) 50 public override void Initialise(Scene scene, IConfigSource config)
51 { 51 {
52 if (!initialized) 52 if (!initialized)
53 { 53 {
54 initialized = true; 54 initialized = true;
55 IConfig startupConfig = config.Configs["Communications"]; 55 IConfig startupConfig = config.Configs["Communications"];
56 if ((startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTCommms") == "HGRESTComms")) 56 if ((startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTCommms") == "HGRESTComms"))
57 { 57 {
58 m_enabled = true; 58 m_enabled = true;
59 InitOnce(scene); 59 InitOnce(scene);
60 } 60 }
61 } 61 }
62 62
63 if (!m_enabled) 63 if (!m_enabled)
64 return; 64 return;
65 65
66 InitEach(scene); 66 InitEach(scene);
67 } 67 }
68 68
69 public override string Name 69 public override string Name
70 { 70 {
71 get { return "HGInterregionCommsModule"; } 71 get { return "HGInterregionCommsModule"; }
72 } 72 }
73 73
74 #endregion /* IRegionModule */ 74 #endregion /* IRegionModule */
75 75
76 #region Misc 76 #region Misc
77 77
78 protected override ulong GetRegionHandle(RegionInfo region) 78 protected override ulong GetRegionHandle(RegionInfo region)
79 { 79 {
80 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(region.RegionHandle); 80 return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(region.RegionHandle);
81 } 81 }
82 82
83 #endregion /* Misc */ 83 #endregion /* Misc */
84 84
85 } 85 }
86} 86}
diff --git a/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs b/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
index 4c2308e..022f635 100644
--- a/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
+++ b/OpenSim/Region/Environment/Modules/Communications/REST/RESTInterregionComms.cs
@@ -1,296 +1,296 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.Collections; 28using System.Collections;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Net; 31using System.Net;
32using System.Net.Sockets; 32using System.Net.Sockets;
33using System.Reflection; 33using System.Reflection;
34using System.Threading; 34using System.Threading;
35using System.Xml; 35using System.Xml;
36using OpenMetaverse; 36using OpenMetaverse;
37using OpenMetaverse.StructuredData; 37using OpenMetaverse.StructuredData;
38using log4net; 38using log4net;
39using Nini.Config; 39using Nini.Config;
40using Nwc.XmlRpc; 40using Nwc.XmlRpc;
41using OpenSim.Framework; 41using OpenSim.Framework;
42using OpenSim.Framework.Communications; 42using OpenSim.Framework.Communications;
43using OpenSim.Framework.Communications.Cache; 43using OpenSim.Framework.Communications.Cache;
44using OpenSim.Region.Environment.Interfaces; 44using OpenSim.Region.Environment.Interfaces;
45using OpenSim.Region.Interfaces; 45using OpenSim.Region.Interfaces;
46using OpenSim.Region.Environment.Scenes; 46using OpenSim.Region.Environment.Scenes;
47using OpenSim.Region.Environment.Modules.Communications.Local; 47using OpenSim.Region.Environment.Modules.Communications.Local;
48 48
49namespace OpenSim.Region.Environment.Modules.Communications.REST 49namespace OpenSim.Region.Environment.Modules.Communications.REST
50{ 50{
51 public class RESTInterregionComms : IRegionModule, IInterregionCommsOut 51 public class RESTInterregionComms : IRegionModule, IInterregionCommsOut
52 { 52 {
53 private static bool initialized = false; 53 private static bool initialized = false;
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 55
56 protected bool m_enabled = false; 56 protected bool m_enabled = false;
57 protected Scene m_aScene; 57 protected Scene m_aScene;
58 // RESTInterregionComms does not care about local regions; it delegates that to the Local module 58 // RESTInterregionComms does not care about local regions; it delegates that to the Local module
59 protected LocalInterregionComms m_localBackend; 59 protected LocalInterregionComms m_localBackend;
60 60
61 protected CommunicationsManager m_commsManager; 61 protected CommunicationsManager m_commsManager;
62 62
63 #region IRegionModule 63 #region IRegionModule
64 64
65 public virtual void Initialise(Scene scene, IConfigSource config) 65 public virtual void Initialise(Scene scene, IConfigSource config)
66 { 66 {
67 if (!initialized) 67 if (!initialized)
68 { 68 {
69 initialized = true; 69 initialized = true;
70 IConfig startupConfig = config.Configs["Communications"]; 70 IConfig startupConfig = config.Configs["Communications"];
71 if ((startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTCommms") == "RESTComms")) 71 if ((startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTCommms") == "RESTComms"))
72 { 72 {
73 m_enabled = true; 73 m_enabled = true;
74 InitOnce(scene); 74 InitOnce(scene);
75 } 75 }
76 } 76 }
77 77
78 if (!m_enabled) 78 if (!m_enabled)
79 return; 79 return;
80 80
81 InitEach(scene); 81 InitEach(scene);
82 82
83 } 83 }
84 84
85 public virtual void PostInitialise() 85 public virtual void PostInitialise()
86 { 86 {
87 if (m_enabled) 87 if (m_enabled)
88 AddHTTPHandlers(); 88 AddHTTPHandlers();
89 } 89 }
90 90
91 public virtual void Close() 91 public virtual void Close()
92 { 92 {
93 } 93 }
94 94
95 public virtual string Name 95 public virtual string Name
96 { 96 {
97 get { return "RESTInterregionCommsModule"; } 97 get { return "RESTInterregionCommsModule"; }
98 } 98 }
99 99
100 public virtual bool IsSharedModule 100 public virtual bool IsSharedModule
101 { 101 {
102 get { return true; } 102 get { return true; }
103 } 103 }
104 104
105 protected virtual void InitEach(Scene scene) 105 protected virtual void InitEach(Scene scene)
106 { 106 {
107 m_localBackend.Init(scene); 107 m_localBackend.Init(scene);
108 scene.RegisterModuleInterface<IInterregionCommsOut>(this); 108 scene.RegisterModuleInterface<IInterregionCommsOut>(this);
109 } 109 }
110 110
111 protected virtual void InitOnce(Scene scene) 111 protected virtual void InitOnce(Scene scene)
112 { 112 {
113 m_localBackend = new LocalInterregionComms(); 113 m_localBackend = new LocalInterregionComms();
114 m_commsManager = scene.CommsManager; 114 m_commsManager = scene.CommsManager;
115 m_aScene = scene; 115 m_aScene = scene;
116 } 116 }
117 117
118 protected virtual void AddHTTPHandlers() 118 protected virtual void AddHTTPHandlers()
119 { 119 {
120 m_aScene.AddHTTPHandler("/ChildAgentUpdate/", ChildAgentUpdateHandler); 120 m_aScene.AddHTTPHandler("/ChildAgentUpdate/", ChildAgentUpdateHandler);
121 } 121 }
122 122
123 #endregion /* IRegionModule */ 123 #endregion /* IRegionModule */
124 124
125 #region IInterregionComms 125 #region IInterregionComms
126 126
127 public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) 127 public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData)
128 { 128 {
129 // Try local first 129 // Try local first
130 if (m_localBackend.SendChildAgentUpdate(regionHandle, cAgentData)) 130 if (m_localBackend.SendChildAgentUpdate(regionHandle, cAgentData))
131 return true; 131 return true;
132 132
133 // else do the remote thing 133 // else do the remote thing
134 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); 134 RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle);
135 if (regInfo != null) 135 if (regInfo != null)
136 { 136 {
137 return DoChildAgentUpdateCall(regInfo, cAgentData); 137 return DoChildAgentUpdateCall(regInfo, cAgentData);
138 } 138 }
139 139
140 return false; 140 return false;
141 141
142 } 142 }
143 143
144 protected bool DoChildAgentUpdateCall(RegionInfo region, AgentData cAgentData) 144 protected bool DoChildAgentUpdateCall(RegionInfo region, AgentData cAgentData)
145 { 145 {
146 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/ChildAgentUpdate/"; 146 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/ChildAgentUpdate/";
147 //Console.WriteLine(" >>> DoChildAgentUpdateCall <<< " + uri); 147 //Console.WriteLine(" >>> DoChildAgentUpdateCall <<< " + uri);
148 148
149 WebRequest ChildUpdateRequest = WebRequest.Create(uri); 149 WebRequest ChildUpdateRequest = WebRequest.Create(uri);
150 ChildUpdateRequest.Method = "PUT"; 150 ChildUpdateRequest.Method = "PUT";
151 ChildUpdateRequest.ContentType = "application/json"; 151 ChildUpdateRequest.ContentType = "application/json";
152 ChildUpdateRequest.Timeout = 10000; 152 ChildUpdateRequest.Timeout = 10000;
153 153
154 // Fill it in 154 // Fill it in
155 OSDMap args = null; 155 OSDMap args = null;
156 try 156 try
157 { 157 {
158 args = cAgentData.PackUpdateMessage(); 158 args = cAgentData.PackUpdateMessage();
159 } 159 }
160 catch (Exception e) 160 catch (Exception e)
161 { 161 {
162 m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message); 162 m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message);
163 } 163 }
164 // Add the regionhandle of the destination region 164 // Add the regionhandle of the destination region
165 ulong regionHandle = GetRegionHandle(region); 165 ulong regionHandle = GetRegionHandle(region);
166 args["destination_handle"] = OSD.FromString(regionHandle.ToString()); 166 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
167 167
168 string strBuffer = ""; 168 string strBuffer = "";
169 byte[] buffer = new byte[1]; 169 byte[] buffer = new byte[1];
170 try 170 try
171 { 171 {
172 strBuffer = OSDParser.SerializeJsonString(args); 172 strBuffer = OSDParser.SerializeJsonString(args);
173 System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); 173 System.Text.UTF8Encoding str = new System.Text.UTF8Encoding();
174 buffer = str.GetBytes(strBuffer); 174 buffer = str.GetBytes(strBuffer);
175 175
176 } 176 }
177 catch (Exception e) 177 catch (Exception e)
178 { 178 {
179 m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); 179 m_log.WarnFormat("[OSG2]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
180 // ignore. buffer will be empty, caller should check. 180 // ignore. buffer will be empty, caller should check.
181 } 181 }
182 182
183 Stream os = null; 183 Stream os = null;
184 try 184 try
185 { // send the Post 185 { // send the Post
186 ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send 186 ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send
187 os = ChildUpdateRequest.GetRequestStream(); 187 os = ChildUpdateRequest.GetRequestStream();
188 os.Write(buffer, 0, strBuffer.Length); //Send it 188 os.Write(buffer, 0, strBuffer.Length); //Send it
189 os.Close(); 189 os.Close();
190 //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri); 190 //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
191 } 191 }
192 catch (WebException ex) 192 catch (WebException ex)
193 { 193 {
194 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message); 194 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
195 195
196 return false; 196 return false;
197 } 197 }
198 198
199 // Let's wait for the response 199 // Let's wait for the response
200 //m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate"); 200 //m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate");
201 string reply = null; 201 string reply = null;
202 try 202 try
203 { 203 {
204 WebResponse webResponse = ChildUpdateRequest.GetResponse(); 204 WebResponse webResponse = ChildUpdateRequest.GetResponse();
205 if (webResponse == null) 205 if (webResponse == null)
206 { 206 {
207 m_log.Info("[REST COMMS]: Null reply on ChilAgentUpdate post"); 207 m_log.Info("[REST COMMS]: Null reply on ChilAgentUpdate post");
208 } 208 }
209 209
210 StreamReader sr = new StreamReader(webResponse.GetResponseStream()); 210 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
211 reply = sr.ReadToEnd().Trim(); 211 reply = sr.ReadToEnd().Trim();
212 sr.Close(); 212 sr.Close();
213 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply); 213 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
214 214
215 } 215 }
216 catch (WebException ex) 216 catch (WebException ex)
217 { 217 {
218 m_log.InfoFormat("[REST COMMS]: exception on reply of ChilAgentUpdate {0}", ex.Message); 218 m_log.InfoFormat("[REST COMMS]: exception on reply of ChilAgentUpdate {0}", ex.Message);
219 // ignore, really 219 // ignore, really
220 } 220 }
221 221
222 return true; 222 return true;
223 223
224 } 224 }
225 225
226 #endregion /* IInterregionComms */ 226 #endregion /* IInterregionComms */
227 227
228 #region Called from remote instances on this instance 228 #region Called from remote instances on this instance
229 229
230 public Hashtable ChildAgentUpdateHandler(Hashtable request) 230 public Hashtable ChildAgentUpdateHandler(Hashtable request)
231 { 231 {
232 //m_log.Debug("[CONNECTION DEBUGGING]: ChildDataUpdateHandler Called"); 232 //m_log.Debug("[CONNECTION DEBUGGING]: ChildDataUpdateHandler Called");
233 233
234 Hashtable responsedata = new Hashtable(); 234 Hashtable responsedata = new Hashtable();
235 responsedata["content_type"] = "text/html"; 235 responsedata["content_type"] = "text/html";
236 236
237 OSDMap args = null; 237 OSDMap args = null;
238 try 238 try
239 { 239 {
240 OSD buffer; 240 OSD buffer;
241 // We should pay attention to the content-type, but let's assume we know it's Json 241 // We should pay attention to the content-type, but let's assume we know it's Json
242 buffer = OSDParser.DeserializeJson((string)request["body"]); 242 buffer = OSDParser.DeserializeJson((string)request["body"]);
243 if (buffer.Type == OSDType.Map) 243 if (buffer.Type == OSDType.Map)
244 args = (OSDMap)buffer; 244 args = (OSDMap)buffer;
245 else 245 else
246 { 246 {
247 // uh? 247 // uh?
248 m_log.Debug("[REST COMMS]: Got OSD of type " + buffer.Type.ToString()); 248 m_log.Debug("[REST COMMS]: Got OSD of type " + buffer.Type.ToString());
249 } 249 }
250 } 250 }
251 catch (Exception ex) 251 catch (Exception ex)
252 { 252 {
253 m_log.InfoFormat("[REST COMMS]: exception on parse of ChildAgentUpdate message {0}", ex.Message); 253 m_log.InfoFormat("[REST COMMS]: exception on parse of ChildAgentUpdate message {0}", ex.Message);
254 responsedata["int_response_code"] = 400; 254 responsedata["int_response_code"] = 400;
255 responsedata["str_response_string"] = "false"; 255 responsedata["str_response_string"] = "false";
256 256
257 return responsedata; 257 return responsedata;
258 } 258 }
259 259
260 // retrieve the regionhandle 260 // retrieve the regionhandle
261 ulong regionhandle = 0; 261 ulong regionhandle = 0;
262 if (args["destination_handle"] != null) 262 if (args["destination_handle"] != null)
263 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); 263 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
264 264
265 AgentData agent = new AgentData(); 265 AgentData agent = new AgentData();
266 try 266 try
267 { 267 {
268 agent.UnpackUpdateMessage(args); 268 agent.UnpackUpdateMessage(args);
269 } 269 }
270 catch (Exception ex) 270 catch (Exception ex)
271 { 271 {
272 m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); 272 m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
273 } 273 }
274 //agent.Dump(); 274 //agent.Dump();
275 275
276 bool result = m_localBackend.SendChildAgentUpdate(regionhandle, agent); 276 bool result = m_localBackend.SendChildAgentUpdate(regionhandle, agent);
277 277
278 278
279 responsedata["int_response_code"] = 200; 279 responsedata["int_response_code"] = 200;
280 responsedata["str_response_string"] = result.ToString(); 280 responsedata["str_response_string"] = result.ToString();
281 return responsedata; 281 return responsedata;
282 } 282 }
283 283
284 #endregion 284 #endregion
285 285
286 #region Misc 286 #region Misc
287 287
288 protected virtual ulong GetRegionHandle(RegionInfo region) 288 protected virtual ulong GetRegionHandle(RegionInfo region)
289 { 289 {
290 return region.RegionHandle; 290 return region.RegionHandle;
291 } 291 }
292 292
293 #endregion /* Misc */ 293 #endregion /* Misc */
294 294
295 } 295 }
296} 296}