aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
diff options
context:
space:
mode:
authordiva2009-02-20 03:39:50 +0000
committerdiva2009-02-20 03:39:50 +0000
commit33330297d603a66cc157baa21c81328edc893e51 (patch)
tree264c9cc750e08383d4f126a66e6def4176dc2fa9 /OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
parentUpdate svn properties, add copyright headers, minor formatting cleanup. (diff)
downloadopensim-SC_OLD-33330297d603a66cc157baa21c81328edc893e51.zip
opensim-SC_OLD-33330297d603a66cc157baa21c81328edc893e51.tar.gz
opensim-SC_OLD-33330297d603a66cc157baa21c81328edc893e51.tar.bz2
opensim-SC_OLD-33330297d603a66cc157baa21c81328edc893e51.tar.xz
THE BIG ANTI-REMOTING SCHLEP -- StartRemoting is no more. Sims in older versions will have a hard time communicating with sims on this release and later, especially if they haven't transitioned to RESTComms at all.
There's still some cleanup to do on assorted data structures, but the main functional change here is that sims no longer listen on remoting ports.
Diffstat (limited to 'OpenSim/Region/Communications/OGS1/OGS1GridServices.cs')
-rw-r--r--OpenSim/Region/Communications/OGS1/OGS1GridServices.cs913
1 files changed, 1 insertions, 912 deletions
diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
index 660e684..66da986 100644
--- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
+++ b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
@@ -31,9 +31,6 @@ using System.Collections.Generic;
31using System.Net; 31using System.Net;
32using System.Net.Sockets; 32using System.Net.Sockets;
33using System.Reflection; 33using System.Reflection;
34using System.Runtime.Remoting;
35using System.Runtime.Remoting.Channels;
36using System.Runtime.Remoting.Channels.Tcp;
37using System.Security.Authentication; 34using System.Security.Authentication;
38using log4net; 35using log4net;
39using Nwc.XmlRpc; 36using Nwc.XmlRpc;
@@ -45,7 +42,7 @@ using OpenSim.Region.Communications.Local;
45 42
46namespace OpenSim.Region.Communications.OGS1 43namespace OpenSim.Region.Communications.OGS1
47{ 44{
48 public class OGS1GridServices : IGridServices, IInterRegionCommunications 45 public class OGS1GridServices : IGridServices
49 { 46 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 48
@@ -99,7 +96,6 @@ namespace OpenSim.Region.Communications.OGS1
99 httpServer.AddXmlRPCHandler("check", PingCheckReply); 96 httpServer.AddXmlRPCHandler("check", PingCheckReply);
100 httpServer.AddXmlRPCHandler("land_data", LandData); 97 httpServer.AddXmlRPCHandler("land_data", LandData);
101 98
102 StartRemoting();
103 } 99 }
104 100
105 // see IGridServices 101 // see IGridServices
@@ -716,913 +712,6 @@ namespace OpenSim.Region.Communications.OGS1
716 return new XmlRpcResponse(); 712 return new XmlRpcResponse();
717 } 713 }
718 714
719 #region m_interRegion Comms
720
721 /// <summary>
722 /// Start listening for .net remoting calls from other regions.
723 /// </summary>
724 private void StartRemoting()
725 {
726 TcpChannel ch;
727 try
728 {
729 ch = new TcpChannel((int)NetworkServersInfo.RemotingListenerPort);
730 ChannelServices.RegisterChannel(ch, false); // Disabled security as Mono doesn't support this.
731 }
732 catch (Exception ex)
733 {
734 m_log.Error("[OGS1 GRID SERVICES]: Exception while attempting to listen on TCP port " + (int)NetworkServersInfo.RemotingListenerPort + ".");
735 throw (ex);
736 }
737
738 WellKnownServiceTypeEntry wellType =
739 new WellKnownServiceTypeEntry(typeof (OGS1InterRegionRemoting), "InterRegions",
740 WellKnownObjectMode.Singleton);
741 RemotingConfiguration.RegisterWellKnownServiceType(wellType);
742 InterRegionSingleton.Instance.OnArrival += TriggerExpectAvatarCrossing;
743 InterRegionSingleton.Instance.OnChildAgent += IncomingChildAgent;
744 InterRegionSingleton.Instance.OnPrimGroupArrival += IncomingPrim;
745 InterRegionSingleton.Instance.OnPrimGroupNear += TriggerExpectPrimCrossing;
746 InterRegionSingleton.Instance.OnRegionUp += TriggerRegionUp;
747 InterRegionSingleton.Instance.OnChildAgentUpdate += TriggerChildAgentUpdate;
748 InterRegionSingleton.Instance.OnTellRegionToCloseChildConnection += TriggerTellRegionToCloseChildConnection;
749 }
750
751 #region Methods called by regions in this instance
752
753 public bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
754 {
755 int failures = 0;
756 lock (m_deadRegionCache)
757 {
758 if (m_deadRegionCache.ContainsKey(regionHandle))
759 {
760 failures = m_deadRegionCache[regionHandle];
761 }
762 }
763 if (failures <= 3)
764 {
765 RegionInfo regInfo = null;
766 try
767 {
768 if (m_localBackend.ChildAgentUpdate(regionHandle, cAgentData))
769 {
770 return true;
771 }
772
773 regInfo = RequestNeighbourInfo(regionHandle);
774 if (regInfo != null)
775 {
776 //don't want to be creating a new link to the remote instance every time like we are here
777 bool retValue = false;
778
779
780 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
781 typeof(OGS1InterRegionRemoting),
782 "tcp://" + regInfo.RemotingAddress +
783 ":" + regInfo.RemotingPort +
784 "/InterRegions");
785
786 if (remObject != null)
787 {
788 retValue = remObject.ChildAgentUpdate(regionHandle, cAgentData);
789 }
790 else
791 {
792 m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
793 }
794 remObject = null;
795// m_log.Info("[INTER]: " +
796// gdebugRegionName +
797// ": OGS1 tried to Update Child Agent data on outside region and got " +
798// retValue.ToString());
799
800 return retValue;
801 }
802 NoteDeadRegion(regionHandle);
803
804 return false;
805 }
806 catch (RemotingException e)
807 {
808 NoteDeadRegion(regionHandle);
809
810 m_log.WarnFormat(
811 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
812 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
813 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
814
815 return false;
816 }
817 catch (SocketException e)
818 {
819 NoteDeadRegion(regionHandle);
820
821 m_log.WarnFormat(
822 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
823 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
824 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
825
826 return false;
827 }
828 catch (InvalidCredentialException e)
829 {
830 NoteDeadRegion(regionHandle);
831
832 m_log.WarnFormat(
833 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
834 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
835 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
836
837 return false;
838 }
839 catch (AuthenticationException e)
840 {
841 NoteDeadRegion(regionHandle);
842
843 m_log.WarnFormat(
844 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
845 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
846 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
847
848 return false;
849 }
850 catch (Exception e)
851 {
852 NoteDeadRegion(regionHandle);
853
854 m_log.WarnFormat("[OGS1 GRID SERVICES]: Unable to connect to adjacent region: {0} {1},{2}",
855 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
856 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
857
858 return false;
859 }
860 }
861 else
862 {
863 //m_log.Info("[INTERREGION]: Skipped Sending Child Update to a region because it failed too many times:" + regionHandle.ToString());
864 return false;
865 }
866 }
867
868 /// <summary>
869 /// Inform a region that a child agent will be on the way from a client.
870 /// </summary>
871 /// <param name="regionHandle"></param>
872 /// <param name="agentData"></param>
873 /// <returns></returns>
874 public bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
875 {
876 RegionInfo regInfo = null;
877 try
878 {
879 if (m_localBackend.InformRegionOfChildAgent(regionHandle, agentData))
880 {
881 return true;
882 }
883
884 regInfo = RequestNeighbourInfo(regionHandle);
885 if (regInfo != null)
886 {
887 //don't want to be creating a new link to the remote instance every time like we are here
888 bool retValue = false;
889
890 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
891 typeof(OGS1InterRegionRemoting),
892 "tcp://" + regInfo.RemotingAddress +
893 ":" + regInfo.RemotingPort +
894 "/InterRegions");
895
896 if (remObject != null)
897 {
898 retValue = remObject.InformRegionOfChildAgent(regionHandle, new sAgentCircuitData(agentData));
899 }
900 else
901 {
902 m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
903 }
904 remObject = null;
905 m_log.Info("[OGS1 GRID SERVICES]: " +
906 m_localBackend._gdebugRegionName + ": OGS1 tried to InformRegionOfChildAgent for " +
907 agentData.firstname + " " + agentData.lastname + " and got " +
908 retValue.ToString());
909
910 return retValue;
911 }
912 NoteDeadRegion(regionHandle);
913 return false;
914 }
915 catch (RemotingException e)
916 {
917 NoteDeadRegion(regionHandle);
918
919 m_log.WarnFormat(
920 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
921 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
922 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
923
924 return false;
925 }
926 catch (SocketException e)
927 {
928 NoteDeadRegion(regionHandle);
929
930 m_log.WarnFormat(
931 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
932 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
933 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
934
935 return false;
936 }
937 catch (InvalidCredentialException e)
938 {
939 NoteDeadRegion(regionHandle);
940
941 m_log.WarnFormat(
942 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
943 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
944 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
945
946 return false;
947 }
948 catch (AuthenticationException e)
949 {
950 NoteDeadRegion(regionHandle);
951
952 m_log.WarnFormat(
953 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
954 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
955 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
956
957 return false;
958 }
959 catch (Exception e)
960 {
961 NoteDeadRegion(regionHandle);
962
963 if (regInfo != null)
964 {
965 m_log.WarnFormat(
966 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
967 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
968 }
969 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
970
971 return false;
972 }
973 }
974
975 // UGLY!
976 public bool RegionUp(SerializableRegionInfo region, ulong regionhandle)
977 {
978 SerializableRegionInfo regInfo = null;
979 try
980 {
981 // You may ask why this is in here...
982 // The region asking the grid services about itself..
983 // And, surprisingly, the reason is.. it doesn't know
984 // it's own remoting port! How special.
985 RegionUpData regiondata = new RegionUpData(region.RegionLocX, region.RegionLocY, region.ExternalHostName, region.InternalEndPoint.Port);
986
987 region = new SerializableRegionInfo(RequestNeighbourInfo(region.RegionHandle));
988 region.RemotingAddress = region.ExternalHostName;
989 region.RemotingPort = NetworkServersInfo.RemotingListenerPort;
990 region.HttpPort = serversInfo.HttpListenerPort;
991
992 if (m_localBackend.RegionUp(region, regionhandle))
993 {
994 return true;
995 }
996
997 regInfo = new SerializableRegionInfo(RequestNeighbourInfo(regionhandle));
998 if (regInfo != null)
999 {
1000 // If we're not trying to remote to ourselves.
1001 if (regInfo.RemotingAddress != region.RemotingAddress && region.RemotingAddress != null)
1002 {
1003 //don't want to be creating a new link to the remote instance every time like we are here
1004 bool retValue = false;
1005
1006 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
1007 typeof(OGS1InterRegionRemoting),
1008 "tcp://" +
1009 regInfo.RemotingAddress +
1010 ":" + regInfo.RemotingPort +
1011 "/InterRegions");
1012
1013 if (remObject != null)
1014 {
1015 retValue = remObject.RegionUp(regiondata, regionhandle);
1016 }
1017 else
1018 {
1019 m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
1020 }
1021 remObject = null;
1022
1023 m_log.Info(
1024 "[INTER]: " + m_localBackend._gdebugRegionName + ": OGS1 tried to inform region I'm up");
1025
1026 return retValue;
1027 }
1028 else
1029 {
1030 // We're trying to inform ourselves via remoting.
1031 // This is here because we're looping over the listeners before we get here.
1032 // Odd but it should work.
1033 return true;
1034 }
1035 }
1036
1037 return false;
1038 }
1039 catch (RemotingException e)
1040 {
1041 m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region using tcp://" +
1042 regInfo.RemotingAddress +
1043 ":" + regInfo.RemotingPort +
1044 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
1045 " - Is this neighbor up?");
1046 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1047 return false;
1048 }
1049 catch (SocketException e)
1050 {
1051 m_log.Warn("[OGS1 GRID SERVICES]: Socket Error: Unable to connect to adjacent region using tcp://" +
1052 regInfo.RemotingAddress +
1053 ":" + regInfo.RemotingPort +
1054 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
1055 " - Is this neighbor up?");
1056 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1057 return false;
1058 }
1059 catch (InvalidCredentialException e)
1060 {
1061 m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
1062 regInfo.RemotingAddress +
1063 ":" + regInfo.RemotingPort +
1064 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
1065 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1066 return false;
1067 }
1068 catch (AuthenticationException e)
1069 {
1070 m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region using tcp://" +
1071 regInfo.RemotingAddress +
1072 ":" + regInfo.RemotingPort +
1073 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
1074 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1075 return false;
1076 }
1077 catch (Exception e)
1078 {
1079 // This line errors with a Null Reference Exception.. Why? @.@
1080 //m_log.Warn("Unknown exception: Unable to connect to adjacent region using tcp://" + regInfo.RemotingAddress +
1081 // ":" + regInfo.RemotingPort +
1082 //"/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY + " - This is likely caused by an incompatibility in the protocol between this sim and that one");
1083 m_log.Debug(e.ToString());
1084 return false;
1085 }
1086 }
1087
1088 /// <summary>
1089 ///
1090 /// </summary>
1091 /// <param name="regionHandle"></param>
1092 /// <param name="agentData"></param>
1093 /// <returns></returns>
1094 public bool InformRegionOfPrimCrossing(ulong regionHandle, UUID primID, string objData, int XMLMethod)
1095 {
1096 int failures = 0;
1097 lock (m_deadRegionCache)
1098 {
1099 if (m_deadRegionCache.ContainsKey(regionHandle))
1100 {
1101 failures = m_deadRegionCache[regionHandle];
1102 }
1103 }
1104 if (failures <= 1)
1105 {
1106 RegionInfo regInfo = null;
1107 try
1108 {
1109 if (m_localBackend.InformRegionOfPrimCrossing(regionHandle, primID, objData, XMLMethod))
1110 {
1111 return true;
1112 }
1113
1114 regInfo = RequestNeighbourInfo(regionHandle);
1115 if (regInfo != null)
1116 {
1117 //don't want to be creating a new link to the remote instance every time like we are here
1118 bool retValue = false;
1119
1120 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
1121 typeof(OGS1InterRegionRemoting),
1122 "tcp://" + regInfo.RemotingAddress +
1123 ":" + regInfo.RemotingPort +
1124 "/InterRegions");
1125
1126 if (remObject != null)
1127 {
1128 m_log.DebugFormat("[INTERREGION]: Sending prim crossing message for prim {0}", primID.ToString());
1129 retValue = remObject.InformRegionOfPrimCrossing(regionHandle, primID.Guid, objData, XMLMethod);
1130 m_log.DebugFormat("[INTERREGION]: Return from prim crossing message for prim {0}: {1}", primID.ToString(), retValue.ToString());
1131 }
1132 else
1133 {
1134 m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
1135 }
1136 remObject = null;
1137
1138 return retValue;
1139 }
1140 NoteDeadRegion(regionHandle);
1141 return false;
1142 }
1143 catch (RemotingException e)
1144 {
1145 NoteDeadRegion(regionHandle);
1146 m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
1147 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1148 return false;
1149 }
1150 catch (SocketException e)
1151 {
1152 NoteDeadRegion(regionHandle);
1153 m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
1154 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1155 return false;
1156 }
1157 catch (InvalidCredentialException e)
1158 {
1159 NoteDeadRegion(regionHandle);
1160 m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credential Exception: Invalid Credentials : " + regionHandle);
1161 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1162 return false;
1163 }
1164 catch (AuthenticationException e)
1165 {
1166 NoteDeadRegion(regionHandle);
1167 m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region: " + regionHandle);
1168 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1169 return false;
1170 }
1171 catch (Exception e)
1172 {
1173 NoteDeadRegion(regionHandle);
1174 m_log.Warn("[OGS1 GRID SERVICES]: Unknown exception: Unable to connect to adjacent region: " + regionHandle);
1175 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
1176 return false;
1177 }
1178 }
1179 else
1180 {
1181 return false;
1182 }
1183 }
1184
1185 /// <summary>
1186 ///
1187 /// </summary>
1188 /// <param name="regionHandle"></param>
1189 /// <param name="agentID"></param>
1190 /// <param name="position"></param>
1191 /// <returns></returns>
1192 public bool ExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying)
1193 {
1194 RegionInfo[] regions = m_regionsOnInstance.ToArray();
1195 bool banned = false;
1196
1197 for (int i = 0; i < regions.Length; i++)
1198 {
1199 if (regions[i] != null)
1200 {
1201 if (regions[i].RegionHandle == regionHandle)
1202 {
1203 if (regions[i].EstateSettings.IsBanned(agentID))
1204 {
1205 banned = true;
1206 break;
1207 }
1208 }
1209 }
1210 }
1211
1212 if (banned)
1213 return false;
1214
1215 RegionInfo regInfo = null;
1216 try
1217 {
1218 if (m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying))
1219 {
1220 return true;
1221 }
1222
1223 regInfo = RequestNeighbourInfo(regionHandle);
1224 if (regInfo != null)
1225 {
1226 bool retValue = false;
1227 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
1228 typeof (OGS1InterRegionRemoting),
1229 "tcp://" + regInfo.RemotingAddress +
1230 ":" + regInfo.RemotingPort +
1231 "/InterRegions");
1232
1233 if (remObject != null)
1234 {
1235 retValue =
1236 remObject.ExpectAvatarCrossing(regionHandle, agentID.Guid, new sLLVector3(position),
1237 isFlying);
1238 }
1239 else
1240 {
1241 m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
1242 }
1243 remObject = null;
1244
1245 return retValue;
1246 }
1247 //TODO need to see if we know about where this region is and use .net remoting
1248 // to inform it.
1249 NoteDeadRegion(regionHandle);
1250 return false;
1251 }
1252 catch (RemotingException e)
1253 {
1254 NoteDeadRegion(regionHandle);
1255
1256 m_log.WarnFormat(
1257 "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
1258 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
1259 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1260
1261 return false;
1262 }
1263 catch
1264 {
1265 NoteDeadRegion(regionHandle);
1266 return false;
1267 }
1268 }
1269
1270 public bool ExpectPrimCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isPhysical)
1271 {
1272 RegionInfo regInfo = null;
1273 try
1274 {
1275 if (m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical))
1276 {
1277 return true;
1278 }
1279
1280 regInfo = RequestNeighbourInfo(regionHandle);
1281 if (regInfo != null)
1282 {
1283 bool retValue = false;
1284 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
1285 typeof (OGS1InterRegionRemoting),
1286 "tcp://" + regInfo.RemotingAddress +
1287 ":" + regInfo.RemotingPort +
1288 "/InterRegions");
1289
1290 if (remObject != null)
1291 {
1292 retValue =
1293 remObject.ExpectAvatarCrossing(regionHandle, agentID.Guid, new sLLVector3(position),
1294 isPhysical);
1295 }
1296 else
1297 {
1298 m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
1299 }
1300 remObject = null;
1301
1302 return retValue;
1303 }
1304 //TODO need to see if we know about where this region is and use .net remoting
1305 // to inform it.
1306 NoteDeadRegion(regionHandle);
1307 return false;
1308 }
1309 catch (RemotingException e)
1310 {
1311 NoteDeadRegion(regionHandle);
1312 m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
1313 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1314 return false;
1315 }
1316 catch (SocketException e)
1317 {
1318 NoteDeadRegion(regionHandle);
1319 m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
1320 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1321 return false;
1322 }
1323 catch (InvalidCredentialException e)
1324 {
1325 NoteDeadRegion(regionHandle);
1326 m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credential Exception: Invalid Credentials : " + regionHandle);
1327 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1328 return false;
1329 }
1330 catch (AuthenticationException e)
1331 {
1332 NoteDeadRegion(regionHandle);
1333 m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region: " + regionHandle);
1334 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1335 return false;
1336 }
1337 catch (Exception e)
1338 {
1339 NoteDeadRegion(regionHandle);
1340 m_log.Warn("[OGS1 GRID SERVICES]: Unknown exception: Unable to connect to adjacent region: " + regionHandle);
1341 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
1342 return false;
1343 }
1344 }
1345
1346 public bool TellRegionToCloseChildConnection(ulong regionHandle, UUID agentID)
1347 {
1348 RegionInfo regInfo = null;
1349 try
1350 {
1351 if (m_localBackend.TriggerTellRegionToCloseChildConnection(regionHandle, agentID))
1352 {
1353 return true;
1354 }
1355
1356 regInfo = RequestNeighbourInfo(regionHandle);
1357 if (regInfo != null)
1358 {
1359 // bool retValue = false;
1360 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
1361 typeof(OGS1InterRegionRemoting),
1362 "tcp://" + regInfo.RemotingAddress +
1363 ":" + regInfo.RemotingPort +
1364 "/InterRegions");
1365
1366 if (remObject != null)
1367 {
1368 // retValue =
1369 remObject.TellRegionToCloseChildConnection(regionHandle, agentID.Guid);
1370 }
1371 else
1372 {
1373 m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
1374 }
1375 remObject = null;
1376
1377 return true;
1378 }
1379 //TODO need to see if we know about where this region is and use .net remoting
1380 // to inform it.
1381 NoteDeadRegion(regionHandle);
1382 return false;
1383 }
1384 catch (RemotingException)
1385 {
1386 NoteDeadRegion(regionHandle);
1387 m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region to tell it to close child agents: " + regInfo.RegionName +
1388 " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
1389 //m_log.Debug(e.ToString());
1390 return false;
1391 }
1392 catch (SocketException e)
1393 {
1394 NoteDeadRegion(regionHandle);
1395 m_log.Warn("[OGS1 GRID SERVICES]: Socket Error: Unable to connect to adjacent region using tcp://" +
1396 regInfo.RemotingAddress +
1397 ":" + regInfo.RemotingPort +
1398 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
1399 " - Is this neighbor up?");
1400 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1401 return false;
1402 }
1403 catch (InvalidCredentialException e)
1404 {
1405 NoteDeadRegion(regionHandle);
1406 m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
1407 regInfo.RemotingAddress +
1408 ":" + regInfo.RemotingPort +
1409 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
1410 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1411 return false;
1412 }
1413 catch (AuthenticationException e)
1414 {
1415 NoteDeadRegion(regionHandle);
1416 m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region using tcp://" +
1417 regInfo.RemotingAddress +
1418 ":" + regInfo.RemotingPort +
1419 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
1420 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1421 return false;
1422 }
1423 catch (WebException e)
1424 {
1425 NoteDeadRegion(regionHandle);
1426 m_log.Warn("[OGS1 GRID SERVICES]: WebException exception: Unable to connect to adjacent region using tcp://" +
1427 regInfo.RemotingAddress +
1428 ":" + regInfo.RemotingPort +
1429 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
1430 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
1431 return false;
1432 }
1433 catch (Exception e)
1434 {
1435 NoteDeadRegion(regionHandle);
1436 // This line errors with a Null Reference Exception.. Why? @.@
1437 //m_log.Warn("Unknown exception: Unable to connect to adjacent region using tcp://" + regInfo.RemotingAddress +
1438 // ":" + regInfo.RemotingPort +
1439 //"/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY + " - This is likely caused by an incompatibility in the protocol between this sim and that one");
1440 m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
1441 return false;
1442 }
1443 }
1444
1445 public bool AcknowledgeAgentCrossed(ulong regionHandle, UUID agentId)
1446 {
1447 return m_localBackend.AcknowledgeAgentCrossed(regionHandle, agentId);
1448 }
1449
1450 public bool AcknowledgePrimCrossed(ulong regionHandle, UUID primId)
1451 {
1452 return m_localBackend.AcknowledgePrimCrossed(regionHandle, primId);
1453 }
1454
1455 #endregion
1456
1457 #region Methods triggered by calls from external instances
1458
1459 /// <summary>
1460 ///
1461 /// </summary>
1462 /// <param name="regionHandle"></param>
1463 /// <param name="agentData"></param>
1464 /// <returns></returns>
1465 public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
1466 {
1467 //m_log.Info("[INTER]: " + gdebugRegionName + ": Incoming OGS1 Agent " + agentData.firstname + " " + agentData.lastname);
1468
1469 return m_localBackend.IncomingChildAgent(regionHandle, agentData);
1470 }
1471
1472 public bool TriggerRegionUp(RegionUpData regionData, ulong regionhandle)
1473 {
1474 m_log.Info(
1475 "[OGS1 GRID SERVICES]: " +
1476 m_localBackend._gdebugRegionName + "Incoming OGS1 RegionUpReport: " + "(" + regionData.X +
1477 "," + regionData.Y + "). Giving this region a fresh set of 'dead' tries");
1478
1479 RegionInfo nRegionInfo = new RegionInfo();
1480 nRegionInfo.SetEndPoint("127.0.0.1", regionData.PORT);
1481 nRegionInfo.ExternalHostName = regionData.IPADDR;
1482 nRegionInfo.RegionLocX = regionData.X;
1483 nRegionInfo.RegionLocY = regionData.Y;
1484
1485 lock (m_deadRegionCache)
1486 {
1487 if (m_deadRegionCache.ContainsKey(nRegionInfo.RegionHandle))
1488 {
1489 m_deadRegionCache.Remove(nRegionInfo.RegionHandle);
1490 }
1491 }
1492
1493 return m_localBackend.TriggerRegionUp(nRegionInfo, regionhandle);
1494 }
1495
1496 public bool TriggerChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
1497 {
1498 //m_log.Info("[INTER]: Incoming OGS1 Child Agent Data Update");
1499
1500 return m_localBackend.TriggerChildAgentUpdate(regionHandle, cAgentData);
1501 }
1502
1503 /// <summary>
1504 ///
1505 /// </summary>
1506 /// <param name="regionHandle"></param>
1507 /// <param name="agentData"></param>
1508 /// <returns></returns>
1509 public bool IncomingPrim(ulong regionHandle, UUID primID, string objData, int XMLMethod)
1510 {
1511 m_log.DebugFormat("[INTERREGION]: Got prim crosssing request for {0}", primID);
1512 m_localBackend.TriggerExpectPrim(regionHandle, primID, objData, XMLMethod);
1513
1514 return true;
1515 }
1516
1517 /// <summary>
1518 ///
1519 /// </summary>
1520 /// <param name="regionHandle"></param>
1521 /// <param name="agentID"></param>
1522 /// <param name="position"></param>
1523 /// <returns></returns>
1524 public bool TriggerExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying)
1525 {
1526 return m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
1527 }
1528
1529 public bool TriggerExpectPrimCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isPhysical)
1530 {
1531 return m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical);
1532 }
1533
1534 public bool TriggerTellRegionToCloseChildConnection(ulong regionHandle, UUID agentID)
1535 {
1536 return m_localBackend.TriggerTellRegionToCloseChildConnection(regionHandle, agentID);
1537 }
1538
1539 #endregion
1540
1541 #endregion
1542
1543 int timeOut = 10; //10 seconds
1544
1545 /// <summary>
1546 /// Check that a region is available for TCP comms. This is necessary for .NET remoting between regions.
1547 /// </summary>
1548 /// <param name="address"></param>
1549 /// <param name="port"></param>
1550 /// <param name="retry"></param>
1551 /// <returns></returns>
1552 public bool CheckRegion(string address, uint port, bool retry)
1553 {
1554 bool available = false;
1555 bool timed_out = true;
1556
1557 IPAddress ia = Util.GetHostFromDNS(address);
1558 IPEndPoint m_EndPoint;
1559 try
1560 {
1561 m_EndPoint = new IPEndPoint(ia, (int)port);
1562 }
1563 catch (Exception)
1564 {
1565 m_log.Debug("[OGS1 GRID SERVICES]: Invalid remoting address: " + address);
1566 return false;
1567 }
1568
1569 AsyncCallback callback = delegate(IAsyncResult iar)
1570 {
1571 timed_out = false;
1572
1573 Socket s = (Socket)iar.AsyncState;
1574 try
1575 {
1576 s.EndConnect(iar);
1577 available = true;
1578 }
1579 catch (Exception e)
1580 {
1581 m_log.DebugFormat(
1582 "[OGS1 GRID SERVICES]: Callback EndConnect exception: {0}:{1}", e.Message, e.StackTrace);
1583 }
1584
1585 s.Close();
1586 };
1587
1588 IAsyncResult ar;
1589
1590 try
1591 {
1592 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
1593 ar = socket.BeginConnect(m_EndPoint, callback, socket);
1594 ar.AsyncWaitHandle.WaitOne(timeOut * 1000, false);
1595 }
1596 catch (Exception e)
1597 {
1598 m_log.DebugFormat(
1599 "[OGS1 GRID SERVICES]: CheckRegion Socket Setup exception: {0}:{1}", e.Message, e.StackTrace);
1600
1601 return false;
1602 }
1603
1604 if (timed_out)
1605 {
1606 ar.AsyncWaitHandle.Close();
1607
1608 m_log.DebugFormat(
1609 "[OGS1 GRID SERVICES]: socket [{0}] timed out ({1}) waiting to obtain a connection.",
1610 m_EndPoint, timeOut * 1000);
1611
1612 if (retry)
1613 {
1614 return CheckRegion(address, port, false);
1615 }
1616 }
1617
1618 return available;
1619 }
1620
1621 public bool CheckRegion(string address, uint port)
1622 {
1623 return CheckRegion(address, port, true);
1624 }
1625
1626 public void NoteDeadRegion(ulong regionhandle) 715 public void NoteDeadRegion(ulong regionhandle)
1627 { 716 {
1628 lock (m_deadRegionCache) 717 lock (m_deadRegionCache)