2008-03-04 05:31:54 +00:00
|
|
|
/*
|
2008-03-04 06:02:48 +00:00
|
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of the OpenSim Project nor the
|
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2008-04-21 07:16:30 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Net;
|
|
|
|
using System.Reflection;
|
2008-03-04 05:31:54 +00:00
|
|
|
using System.Threading;
|
2008-04-21 07:16:30 +00:00
|
|
|
using libsecondlife;
|
|
|
|
using libsecondlife.Packets;
|
|
|
|
using log4net;
|
|
|
|
using Mono.Addins;
|
|
|
|
using Nwc.XmlRpc;
|
2008-03-04 05:31:54 +00:00
|
|
|
using OpenSim.Framework;
|
|
|
|
using OpenSim.Framework.Servers;
|
2008-05-02 16:41:35 +00:00
|
|
|
//using OpenSim.Region.ClientStack.LindenUDP;
|
2008-03-04 05:31:54 +00:00
|
|
|
using OpenSim.Region.ClientStack;
|
2008-05-02 16:41:35 +00:00
|
|
|
using OpenSim.Region.ClientStack.LindenUDP;
|
2008-04-21 07:16:30 +00:00
|
|
|
using OpenSim.Region.Environment.Scenes;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
[assembly : Addin]
|
|
|
|
[assembly : AddinDependency("OpenSim", "0.5")]
|
|
|
|
[assembly : AddinDependency("RegionProxy", "0.1")]
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|
|
|
{
|
|
|
|
[Extension("/OpenSim/Startup")]
|
|
|
|
public class LoadBalancerPlugin : IApplicationPlugin
|
|
|
|
{
|
2008-04-21 07:16:30 +00:00
|
|
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
private BaseHttpServer commandServer;
|
2008-04-29 14:10:26 +00:00
|
|
|
private bool[] isLocalNeighbour;
|
2008-05-01 18:04:42 +00:00
|
|
|
private bool isSplit = false;
|
2008-04-29 14:10:26 +00:00
|
|
|
private TcpServer mTcpServer;
|
2008-05-01 18:04:42 +00:00
|
|
|
private object padlock = new object();
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
private int proxyOffset;
|
|
|
|
private string proxyURL;
|
2008-04-29 14:10:26 +00:00
|
|
|
private List<RegionInfo> regionData;
|
|
|
|
private int[] regionPortList;
|
2008-03-04 05:31:54 +00:00
|
|
|
private SceneManager sceneManager;
|
2008-04-29 14:10:26 +00:00
|
|
|
private string[] sceneURL;
|
2008-03-04 06:02:48 +00:00
|
|
|
private string serializeDir;
|
2008-04-29 14:10:26 +00:00
|
|
|
private OpenSimMain simMain;
|
|
|
|
private TcpClient[] tcpClientList;
|
2008-05-02 16:41:35 +00:00
|
|
|
private List<IClientNetworkServer> m_clientServers;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
#region IApplicationPlugin Members
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
public void Initialise(OpenSimMain openSim)
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Entering Initialize()");
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-11 02:49:44 +00:00
|
|
|
proxyURL = openSim.ConfigSource.Configs["Network"].GetString("proxy_url", "");
|
2008-04-29 14:10:26 +00:00
|
|
|
if (proxyURL.Length == 0) return;
|
2008-03-11 02:49:44 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
StartTcpServer();
|
2008-05-02 16:41:35 +00:00
|
|
|
// BUG: This needs to be fixed
|
|
|
|
// TODO: YARLY.
|
|
|
|
// LLClientView.SynchronizeClient = new LLClientView.SynchronizeClientHandler(SynchronizePackets);
|
2008-05-01 18:04:42 +00:00
|
|
|
AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
sceneManager = openSim.SceneManager;
|
2008-05-02 16:41:35 +00:00
|
|
|
m_clientServers = openSim.UdpServers;
|
2008-04-29 14:10:26 +00:00
|
|
|
regionData = openSim.RegionData;
|
|
|
|
simMain = openSim;
|
|
|
|
commandServer = openSim.HttpServer;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
proxyOffset = Int32.Parse(openSim.ConfigSource.Configs["Network"].GetString("proxy_offset", "0"));
|
|
|
|
serializeDir = openSim.ConfigSource.Configs["Network"].GetString("serialize_dir", "/tmp/");
|
|
|
|
|
|
|
|
commandServer.AddXmlRPCHandler("SerializeRegion", SerializeRegion);
|
|
|
|
commandServer.AddXmlRPCHandler("DeserializeRegion_Move", DeserializeRegion_Move);
|
|
|
|
commandServer.AddXmlRPCHandler("DeserializeRegion_Clone", DeserializeRegion_Clone);
|
|
|
|
commandServer.AddXmlRPCHandler("TerminateRegion", TerminateRegion);
|
|
|
|
|
|
|
|
commandServer.AddXmlRPCHandler("SplitRegion", SplitRegion);
|
|
|
|
commandServer.AddXmlRPCHandler("MergeRegions", MergeRegions);
|
|
|
|
commandServer.AddXmlRPCHandler("UpdatePhysics", UpdatePhysics);
|
|
|
|
commandServer.AddXmlRPCHandler("GetStatus", GetStatus);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Exiting Initialize()");
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
public void Close()
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
private void StartTcpServer()
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
Thread server_thread = new Thread(new ThreadStart(
|
|
|
|
delegate
|
|
|
|
{
|
|
|
|
mTcpServer = new TcpServer(10001);
|
|
|
|
mTcpServer.start();
|
|
|
|
}));
|
|
|
|
server_thread.Start();
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private XmlRpcResponse GetStatus(XmlRpcRequest request)
|
|
|
|
{
|
2008-03-04 06:02:48 +00:00
|
|
|
XmlRpcResponse response = new XmlRpcResponse();
|
|
|
|
try
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Entering RegionStatus()");
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
int src_port = (int) request.Params[0];
|
2008-03-04 06:02:48 +00:00
|
|
|
Scene scene = null;
|
|
|
|
// try to get the scene object
|
|
|
|
RegionInfo src_region = SearchRegionFromPortNum(src_port);
|
|
|
|
if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false)
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + "The Scene is not found");
|
2008-03-04 06:02:48 +00:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
// serialization of client's informations
|
2008-03-04 05:31:54 +00:00
|
|
|
List<ScenePresence> presences = scene.GetScenePresences();
|
2008-03-04 06:02:48 +00:00
|
|
|
int get_scene_presence = presences.Count;
|
|
|
|
int get_scene_presence_filter = 0;
|
|
|
|
foreach (ScenePresence pre in presences)
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
2008-05-02 16:41:35 +00:00
|
|
|
IClientAPI client = pre.ControllingClient;
|
2008-03-04 05:31:54 +00:00
|
|
|
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
2008-05-02 16:41:35 +00:00
|
|
|
if (client.IsActive)
|
2008-04-29 14:10:26 +00:00
|
|
|
{
|
2008-03-04 06:02:48 +00:00
|
|
|
get_scene_presence_filter++;
|
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
2008-03-04 06:02:48 +00:00
|
|
|
List<ScenePresence> avatars = scene.GetAvatars();
|
|
|
|
int get_avatar = avatars.Count;
|
|
|
|
int get_avatar_filter = 0;
|
|
|
|
string avatar_names = "";
|
|
|
|
foreach (ScenePresence pre in avatars)
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
2008-05-02 16:41:35 +00:00
|
|
|
IClientAPI client = pre.ControllingClient;
|
2008-03-04 05:31:54 +00:00
|
|
|
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
2008-05-02 16:41:35 +00:00
|
|
|
if (client.IsActive)
|
2008-04-29 14:10:26 +00:00
|
|
|
{
|
2008-03-04 06:02:48 +00:00
|
|
|
get_avatar_filter++;
|
|
|
|
avatar_names += pre.Firstname + " " + pre.Lastname + "; ";
|
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
2008-04-29 14:10:26 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
Hashtable responseData = new Hashtable();
|
|
|
|
responseData["get_scene_presence_filter"] = get_scene_presence_filter;
|
|
|
|
responseData["get_scene_presence"] = get_scene_presence;
|
|
|
|
responseData["get_avatar_filter"] = get_avatar_filter;
|
|
|
|
responseData["get_avatar"] = get_avatar;
|
|
|
|
responseData["avatar_names"] = avatar_names;
|
|
|
|
response.Value = responseData;
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Exiting RegionStatus()");
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.StackTrace);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
2008-03-04 06:02:48 +00:00
|
|
|
return response;
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private XmlRpcResponse SerializeRegion(XmlRpcRequest request)
|
|
|
|
{
|
2008-03-04 06:02:48 +00:00
|
|
|
try
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Entering SerializeRegion()");
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
string src_url = (string) request.Params[0];
|
|
|
|
int src_port = (int) request.Params[1];
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
SerializeRegion(src_url, src_port);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Exiting SerializeRegion()");
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.StackTrace);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new XmlRpcResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
private XmlRpcResponse DeserializeRegion_Move(XmlRpcRequest request)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Entering DeserializeRegion_Move()");
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
string src_url = (string) request.Params[0];
|
|
|
|
int src_port = (int) request.Params[1];
|
|
|
|
string dst_url = (string) request.Params[2];
|
|
|
|
int dst_port = (int) request.Params[3];
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
DeserializeRegion_Move(src_port, dst_port, src_url, dst_url);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Exiting DeserializeRegion_Move()");
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.StackTrace);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new XmlRpcResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
private XmlRpcResponse DeserializeRegion_Clone(XmlRpcRequest request)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Entering DeserializeRegion_Clone()");
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
string src_url = (string) request.Params[0];
|
|
|
|
int src_port = (int) request.Params[1];
|
|
|
|
string dst_url = (string) request.Params[2];
|
|
|
|
int dst_port = (int) request.Params[3];
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
DeserializeRegion_Clone(src_port, dst_port, src_url, dst_url);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Exiting DeserializeRegion_Clone()");
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.StackTrace);
|
2008-03-04 05:31:54 +00:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new XmlRpcResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
private XmlRpcResponse TerminateRegion(XmlRpcRequest request)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Entering TerminateRegion()");
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
int src_port = (int) request.Params[0];
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
// backgroud
|
2008-05-01 18:04:42 +00:00
|
|
|
WaitCallback callback = new WaitCallback(TerminateRegion);
|
2008-03-04 05:31:54 +00:00
|
|
|
ThreadPool.QueueUserWorkItem(callback, src_port);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Exiting TerminateRegion()");
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.StackTrace);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new XmlRpcResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
// internal functions
|
|
|
|
|
|
|
|
private void SerializeRegion(string src_url, int src_port)
|
|
|
|
{
|
|
|
|
RegionInfo src_region = null;
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
// Processing of origin region
|
|
|
|
//------------------------------------------
|
|
|
|
|
|
|
|
// search origin region
|
|
|
|
src_region = SearchRegionFromPortNum(src_port);
|
|
|
|
|
|
|
|
if (src_region == null)
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + "Region not found");
|
2008-03-04 05:31:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-24 01:37:00 +00:00
|
|
|
Util.XmlRpcCommand(src_region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
// serialization of origin region's data
|
|
|
|
SerializeRegion(src_region, serializeDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DeserializeRegion_Move(int src_port, int dst_port, string src_url, string dst_url)
|
|
|
|
{
|
|
|
|
RegionInfo dst_region = null;
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
// Processing of destination region
|
|
|
|
//------------------------------------------
|
|
|
|
|
|
|
|
// import the source region's data
|
|
|
|
dst_region = DeserializeRegion(dst_port, true, serializeDir);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
Util.XmlRpcCommand(dst_region.proxyUrl, "ChangeRegion", src_port + proxyOffset, src_url, dst_port + proxyOffset, dst_url);
|
|
|
|
Util.XmlRpcCommand(dst_region.proxyUrl, "UnblockClientMessages", dst_url, dst_port + proxyOffset);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void DeserializeRegion_Clone(int src_port, int dst_port, string src_url, string dst_url)
|
|
|
|
{
|
|
|
|
RegionInfo dst_region = null;
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
// Processing of destination region
|
|
|
|
//------------------------------------------
|
|
|
|
|
|
|
|
// import the source region's data
|
|
|
|
dst_region = DeserializeRegion(dst_port, false, serializeDir);
|
|
|
|
|
|
|
|
// Decide who is in charge for each section
|
2008-05-01 18:04:42 +00:00
|
|
|
int[] port = new int[] {src_port, dst_port};
|
|
|
|
string[] url = new string[] {"http://" + src_url + ":" + commandServer.Port, "http://" + dst_url + ":" + commandServer.Port};
|
2008-04-29 14:10:26 +00:00
|
|
|
for (int i = 0; i < 2; i++) Util.XmlRpcCommand(url[i], "SplitRegion", i, 2, port[0], port[1], url[0], url[1]);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
// Enable the proxy
|
2008-04-29 14:10:26 +00:00
|
|
|
Util.XmlRpcCommand(dst_region.proxyUrl, "AddRegion", src_port + proxyOffset, src_url, dst_port + proxyOffset, dst_url);
|
|
|
|
Util.XmlRpcCommand(dst_region.proxyUrl, "UnblockClientMessages", dst_url, dst_port + proxyOffset);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void TerminateRegion(object param)
|
|
|
|
{
|
|
|
|
RegionInfo src_region = null;
|
2008-04-29 14:10:26 +00:00
|
|
|
int src_port = (int) param;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
// Processing of remove region
|
|
|
|
//------------------------------------------
|
|
|
|
|
|
|
|
// search origin region
|
|
|
|
src_region = SearchRegionFromPortNum(src_port);
|
|
|
|
|
|
|
|
if (src_region == null)
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + "Region not found");
|
2008-03-04 05:31:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isSplit = false;
|
|
|
|
|
|
|
|
// remove client resources
|
|
|
|
RemoveAllClientResource(src_region);
|
|
|
|
// remove old region
|
|
|
|
RemoveRegion(src_region.RegionID, src_region.InternalEndPoint.Port);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Region terminated");
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private RegionInfo SearchRegionFromPortNum(int portnum)
|
|
|
|
{
|
|
|
|
RegionInfo result = null;
|
|
|
|
|
|
|
|
foreach (RegionInfo rinfo in regionData)
|
|
|
|
{
|
|
|
|
if (rinfo.InternalEndPoint.Port == portnum)
|
|
|
|
{
|
|
|
|
// m_log.Info("BALANCER",
|
|
|
|
// "Region found. Internal Port = {0}, Handle={1}",
|
|
|
|
// rinfo.InternalEndPoint.Port, rinfo.RegionHandle);
|
|
|
|
result = rinfo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-05-02 16:41:35 +00:00
|
|
|
private IClientNetworkServer SearchUDPServerFromPortNum(int portnum)
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
2008-05-02 16:41:35 +00:00
|
|
|
return m_clientServers.Find(delegate(IClientNetworkServer server) { return (portnum + proxyOffset == ((IPEndPoint)server.Server.LocalEndPoint).Port); });
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void SerializeRegion(RegionInfo src_region, string export_dir)
|
|
|
|
{
|
|
|
|
Scene scene = null;
|
|
|
|
List<ScenePresence> presences;
|
|
|
|
string filename;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// try to get the scene object
|
|
|
|
if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false)
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + "The Scene is not found");
|
2008-03-04 05:31:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create export directory
|
|
|
|
DirectoryInfo dirinfo = new DirectoryInfo(export_dir);
|
|
|
|
if (!dirinfo.Exists)
|
|
|
|
{
|
|
|
|
dirinfo.Create();
|
|
|
|
}
|
|
|
|
|
|
|
|
// serialization of client's informations
|
|
|
|
presences = scene.GetScenePresences();
|
|
|
|
|
|
|
|
foreach (ScenePresence pre in presences)
|
|
|
|
{
|
|
|
|
SerializeClient(i, scene, pre, export_dir);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// serialization of region data
|
|
|
|
SearializableRegionInfo dst_region = new SearializableRegionInfo(src_region);
|
|
|
|
|
2008-05-01 18:04:42 +00:00
|
|
|
filename = export_dir + "RegionInfo_" + src_region.RegionID.ToString() + ".bin";
|
2008-03-04 05:31:54 +00:00
|
|
|
Util.SerializeToFile(filename, dst_region);
|
|
|
|
|
|
|
|
// backup current scene's entities
|
|
|
|
//scene.Backup();
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "region serialization completed [{0}]",
|
2008-03-04 06:02:48 +00:00
|
|
|
src_region.RegionID.ToString());
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 16:23:53 +00:00
|
|
|
private static void SerializeClient(int idx, Scene scene, ScenePresence pre, string export_dir)
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
|
|
|
string filename;
|
|
|
|
IClientAPI controller = null;
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "agent id : {0}", pre.UUID);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-14 15:28:34 +00:00
|
|
|
uint[] circuits = scene.ClientManager.GetAllCircuits(pre.UUID);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
foreach (uint code in circuits)
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "circuit code : {0}", code);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
if (scene.ClientManager.TryGetClient(code, out controller))
|
|
|
|
{
|
|
|
|
ClientInfo info = controller.GetClientInfo();
|
|
|
|
|
2008-05-01 18:04:42 +00:00
|
|
|
filename = export_dir + "ClientInfo-" + String.Format("{0:0000}", idx) + "_" + controller.CircuitCode.ToString() + ".bin";
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
Util.SerializeToFile(filename, info);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "client info serialized [filename={0}]", filename);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//filename = export_dir + "Presence_" + controller.AgentId.ToString() + ".bin";
|
|
|
|
filename = export_dir + "Presence_" + String.Format("{0:0000}", idx) + ".bin";
|
|
|
|
|
|
|
|
Util.SerializeToFile(filename, pre);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "scene presence serialized [filename={0}]", filename);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private RegionInfo DeserializeRegion(int dst_port, bool move_flag, string import_dir)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
string[] files = null;
|
2008-03-04 05:31:54 +00:00
|
|
|
RegionInfo dst_region = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// deserialization of region data
|
2008-05-01 18:04:42 +00:00
|
|
|
files = Directory.GetFiles(import_dir, "RegionInfo_*.bin");
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
foreach (string filename in files)
|
|
|
|
{
|
|
|
|
m_log.InfoFormat("[BALANCER] RegionInfo filename = [{0}]", filename);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
dst_region = new RegionInfo((SearializableRegionInfo) Util.DeserializeFromFile(filename));
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "RegionID = [{0}]", dst_region.RegionID.ToString());
|
|
|
|
m_log.InfoFormat("[BALANCER] " + "RegionHandle = [{0}]", dst_region.RegionHandle);
|
|
|
|
m_log.InfoFormat("[BALANCER] " + "ProxyUrl = [{0}]", dst_region.proxyUrl);
|
|
|
|
m_log.InfoFormat("[BALANCER] " + "OriginRegionID = [{0}]", dst_region.originRegionID.ToString());
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
CreateCloneRegion(dst_region, dst_port, true);
|
|
|
|
|
|
|
|
File.Delete(filename);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "region deserialized [{0}]", dst_region.RegionID);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// deserialization of client data
|
|
|
|
DeserializeClient(dst_region, import_dir);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "region deserialization completed [{0}]",
|
2008-03-04 06:02:48 +00:00
|
|
|
dst_region.ToString());
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.StackTrace);
|
2008-03-04 05:31:54 +00:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DeserializeClient(RegionInfo dst_region, string import_dir)
|
|
|
|
{
|
|
|
|
ScenePresence sp = null;
|
|
|
|
ClientInfo data = null;
|
|
|
|
Scene scene = null;
|
|
|
|
string[] files = null;
|
|
|
|
IClientAPI controller = null;
|
2008-05-02 16:41:35 +00:00
|
|
|
IClientNetworkServer udpserv = null;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
if (sceneManager.TryGetScene(dst_region.RegionID, out scene))
|
|
|
|
{
|
|
|
|
// search udpserver
|
|
|
|
udpserv = SearchUDPServerFromPortNum(scene.RegionInfo.InternalEndPoint.Port);
|
|
|
|
|
|
|
|
// restore the scene presence
|
2008-04-29 14:10:26 +00:00
|
|
|
for (int i = 0;; i++)
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
|
|
|
string filename = import_dir + "Presence_" + String.Format("{0:0000}", i) + ".bin";
|
|
|
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
sp = (ScenePresence) Util.DeserializeFromFile(filename);
|
2008-03-14 15:28:34 +00:00
|
|
|
Console.WriteLine("agent id = {0}", sp.UUID);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-14 15:28:34 +00:00
|
|
|
scene.m_restorePresences.Add(sp.UUID, sp);
|
2008-03-04 05:31:54 +00:00
|
|
|
File.Delete(filename);
|
|
|
|
|
2008-03-14 15:28:34 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "scene presence deserialized [{0}]", sp.UUID);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
// restore the ClientView
|
|
|
|
|
|
|
|
files = Directory.GetFiles(import_dir, "ClientInfo-" + String.Format("{0:0000}", i) + "_*.bin");
|
|
|
|
|
|
|
|
foreach (string fname in files)
|
|
|
|
{
|
|
|
|
int start = fname.IndexOf('_');
|
|
|
|
int end = fname.LastIndexOf('.');
|
|
|
|
uint circuit_code = uint.Parse(fname.Substring(start + 1, end - start - 1));
|
|
|
|
m_log.InfoFormat("[BALANCER] " + "client circuit code = {0}", circuit_code);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
data = (ClientInfo) Util.DeserializeFromFile(fname);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
AgentCircuitData agentdata = new AgentCircuitData(data.agentcircuit);
|
|
|
|
scene.AuthenticateHandler.AddNewCircuit(circuit_code, agentdata);
|
|
|
|
|
2008-05-02 16:41:35 +00:00
|
|
|
// BUG: Will only work with LLUDPServer.
|
|
|
|
// TODO: This needs to be abstracted and converted into IClientNetworkServer
|
|
|
|
if (udpserv is LLUDPServer)
|
|
|
|
{
|
|
|
|
((LLUDPServer) udpserv).RestoreClient(agentdata, data.userEP, data.proxyEP);
|
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
// waiting for the scene-presense restored
|
|
|
|
lock (scene.m_restorePresences)
|
|
|
|
{
|
|
|
|
Monitor.Wait(scene.m_restorePresences, 3000);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scene.ClientManager.TryGetClient(circuit_code, out controller))
|
|
|
|
{
|
|
|
|
m_log.InfoFormat("[BALANCER] " + "get client [{0}]", circuit_code);
|
|
|
|
controller.SetClientInfo(data);
|
|
|
|
}
|
|
|
|
|
2008-03-04 05:31:54 +00:00
|
|
|
File.Delete(fname);
|
|
|
|
|
|
|
|
m_log.InfoFormat("[BALANCER] " + "client info deserialized [{0}]", circuit_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
// backup new scene's entities
|
|
|
|
//scene.Backup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CreateCloneRegion(RegionInfo dst_region, int dst_port, bool createID_flag)
|
|
|
|
{
|
|
|
|
if (createID_flag)
|
|
|
|
{
|
|
|
|
dst_region.RegionID = LLUUID.Random();
|
|
|
|
}
|
|
|
|
|
|
|
|
// change RegionInfo (memory only)
|
|
|
|
dst_region.InternalEndPoint.Port = dst_port;
|
2008-05-01 18:04:42 +00:00
|
|
|
dst_region.ExternalHostName = proxyURL.Split(new char[] {'/', ':'})[3];
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
// Create new region
|
|
|
|
simMain.CreateRegion(dst_region, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RemoveRegion(LLUUID regionID, int port)
|
|
|
|
{
|
|
|
|
Scene killScene;
|
|
|
|
if (sceneManager.TryGetScene(regionID, out killScene))
|
|
|
|
{
|
|
|
|
Console.WriteLine("scene found.");
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
if ((sceneManager.CurrentScene != null)
|
2008-03-04 06:02:48 +00:00
|
|
|
&& (sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID))
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
|
|
|
sceneManager.TrySetCurrentScene("..");
|
|
|
|
}
|
|
|
|
|
|
|
|
m_log.Info("Removing region : " + killScene.RegionInfo.RegionName);
|
|
|
|
regionData.Remove(killScene.RegionInfo);
|
|
|
|
sceneManager.CloseScene(killScene);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shutting down the UDP server
|
2008-05-02 16:41:35 +00:00
|
|
|
IClientNetworkServer udpsvr = SearchUDPServerFromPortNum(port);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
if (udpsvr != null)
|
|
|
|
{
|
|
|
|
udpsvr.Server.Close();
|
2008-05-02 16:41:35 +00:00
|
|
|
m_clientServers.Remove(udpsvr);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
2008-04-29 14:10:26 +00:00
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
private void RemoveAllClientResource(RegionInfo src_region)
|
|
|
|
{
|
|
|
|
Scene scene = null;
|
|
|
|
List<ScenePresence> presences;
|
|
|
|
IClientAPI controller = null;
|
|
|
|
|
|
|
|
// try to get the scene object
|
|
|
|
if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false)
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + "The Scene is not found");
|
2008-03-04 05:31:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// serialization of client's informations
|
|
|
|
presences = scene.GetScenePresences();
|
|
|
|
|
|
|
|
// remove all scene presences
|
|
|
|
foreach (ScenePresence pre in presences)
|
|
|
|
{
|
2008-03-14 15:28:34 +00:00
|
|
|
uint[] circuits = scene.ClientManager.GetAllCircuits(pre.UUID);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
foreach (uint code in circuits)
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "circuit code : {0}", code);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
if (scene.ClientManager.TryGetClient(code, out controller))
|
|
|
|
{
|
|
|
|
// stopping clientview thread
|
2008-05-02 16:41:35 +00:00
|
|
|
if ((controller).IsActive)
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
2008-03-04 05:31:54 +00:00
|
|
|
controller.Stop();
|
2008-05-02 16:41:35 +00:00
|
|
|
(controller).IsActive = false;
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
// teminateing clientview thread
|
|
|
|
controller.Terminate();
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "client thread stopped");
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove scene presence
|
2008-03-14 15:28:34 +00:00
|
|
|
scene.RemoveClient(pre.UUID);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This section implements scene splitting and synchronization
|
|
|
|
*/
|
|
|
|
|
|
|
|
private XmlRpcResponse SplitRegion(XmlRpcRequest request)
|
|
|
|
{
|
2008-03-04 06:02:48 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
int myID = (int) request.Params[0];
|
|
|
|
int numRegions = (int) request.Params[1];
|
|
|
|
regionPortList = new int[numRegions];
|
|
|
|
sceneURL = new string[numRegions];
|
|
|
|
tcpClientList = new TcpClient[numRegions];
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
for (int i = 0; i < numRegions; i++)
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
regionPortList[i] = (int) request.Params[i + 2];
|
|
|
|
sceneURL[i] = (string) request.Params[i + 2 + numRegions];
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
string hostname;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
for (int i = 0; i < numRegions; i++)
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
hostname = sceneURL[i].Split(new char[] {'/', ':'})[3];
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[SPLITSCENE] " + "creating tcp client host:{0}", hostname);
|
2008-03-04 06:02:48 +00:00
|
|
|
tcpClientList[i] = new TcpClient(hostname, 10001);
|
|
|
|
}
|
2008-04-29 14:10:26 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
bool isMaster = (myID == 0);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
isLocalNeighbour = new bool[numRegions];
|
2008-04-29 14:10:26 +00:00
|
|
|
for (int i = 0; i < numRegions; i++) isLocalNeighbour[i] = (sceneURL[i] == sceneURL[myID]);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
RegionInfo region = SearchRegionFromPortNum(regionPortList[myID]);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
//Console.WriteLine("\n === SplitRegion {0}\n", region.RegionID);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
Scene scene;
|
|
|
|
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
|
|
|
{
|
|
|
|
// Disable event updates, backups etc in the slave(s)
|
2008-04-29 14:10:26 +00:00
|
|
|
if (isMaster)
|
|
|
|
{
|
2008-03-04 06:02:48 +00:00
|
|
|
scene.Region_Status = RegionStatus.Up;
|
|
|
|
}
|
2008-04-29 14:10:26 +00:00
|
|
|
else
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
|
|
|
scene.Region_Status = RegionStatus.SlaveScene;
|
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
//Console.WriteLine("=== SplitRegion {0}: Scene found, status {1}", region.RegionID, scene.Region_Status);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
// Disabling half of the avatars in master, and the other half in slave
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
int i = 0;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 09:39:58 +00:00
|
|
|
List<uint> circuits = scene.ClientManager.GetAllCircuitCodes();
|
|
|
|
circuits.Sort();
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-05-01 18:04:42 +00:00
|
|
|
IClientAPI controller = null;
|
|
|
|
|
2008-03-04 09:39:58 +00:00
|
|
|
foreach (uint code in circuits)
|
2008-03-04 10:12:39 +00:00
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.InfoFormat("[BALANCER] " + "circuit code : {0}", code);
|
2008-03-04 09:39:58 +00:00
|
|
|
|
|
|
|
if (scene.ClientManager.TryGetClient(code, out controller))
|
2008-03-04 10:12:39 +00:00
|
|
|
{
|
2008-03-04 09:39:58 +00:00
|
|
|
// Divide the presences evenly over the set of subscenes
|
2008-05-02 16:41:35 +00:00
|
|
|
LLClientView client = (LLClientView) controller;
|
|
|
|
client.IsActive = (((i + myID) % sceneURL.Length) == 0);
|
2008-03-04 09:39:58 +00:00
|
|
|
|
2008-05-02 16:41:35 +00:00
|
|
|
m_log.InfoFormat("[SPLITSCENE] === SplitRegion {0}: SP.PacketEnabled {1}", region.RegionID, client.IsActive);
|
2008-03-04 09:39:58 +00:00
|
|
|
|
2008-05-02 16:41:35 +00:00
|
|
|
if (!client.IsActive)
|
2008-03-04 10:12:39 +00:00
|
|
|
{
|
2008-03-04 09:39:58 +00:00
|
|
|
// stopping clientview thread
|
|
|
|
client.Stop();
|
2008-03-04 10:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2008-04-29 14:10:26 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
scene.splitID = myID;
|
2008-05-01 18:04:42 +00:00
|
|
|
scene.SynchronizeScene = new Scene.SynchronizeSceneHandler(SynchronizeScenes);
|
2008-03-04 06:02:48 +00:00
|
|
|
isSplit = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[SPLITSCENE] " + String.Format("Scene not found {0}", region.RegionID));
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[SPLITSCENE] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[SPLITSCENE] " + e.StackTrace);
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new XmlRpcResponse();
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private XmlRpcResponse MergeRegions(XmlRpcRequest request)
|
|
|
|
{
|
|
|
|
// This should only be called for the master scene
|
|
|
|
try
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[BALANCER] " + "Entering MergeRegions()");
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
string src_url = (string) request.Params[0];
|
|
|
|
int src_port = (int) request.Params[1];
|
2008-04-29 14:10:26 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
RegionInfo region = SearchRegionFromPortNum(src_port);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
Util.XmlRpcCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset);
|
2008-03-04 06:02:48 +00:00
|
|
|
|
|
|
|
Scene scene;
|
|
|
|
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
|
|
|
{
|
|
|
|
isSplit = false;
|
|
|
|
|
|
|
|
scene.SynchronizeScene = null;
|
|
|
|
scene.Region_Status = RegionStatus.Up;
|
|
|
|
|
|
|
|
List<ScenePresence> presences = scene.GetScenePresences();
|
|
|
|
foreach (ScenePresence pre in presences)
|
|
|
|
{
|
2008-05-02 16:41:35 +00:00
|
|
|
LLClientView client = (LLClientView) pre.ControllingClient;
|
|
|
|
if (!client.IsActive)
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
|
|
|
client.Restart();
|
2008-05-02 16:41:35 +00:00
|
|
|
client.IsActive = true;
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the slave scenes
|
2008-04-29 14:10:26 +00:00
|
|
|
for (int i = 1; i < sceneURL.Length; i++)
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
|
|
|
string url = (sceneURL[i].Split('/')[2]).Split(':')[0]; // get URL part from EP
|
2008-04-29 14:10:26 +00:00
|
|
|
Util.XmlRpcCommand(region.proxyUrl, "DeleteRegion", regionPortList[i] + proxyOffset, url);
|
2008-03-04 06:02:48 +00:00
|
|
|
Thread.Sleep(1000);
|
2008-04-29 14:10:26 +00:00
|
|
|
Util.XmlRpcCommand(sceneURL[i], "TerminateRegion", regionPortList[i]); // TODO: need + proxyOffset?
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
Util.XmlRpcCommand(region.proxyUrl, "UnblockClientMessages", src_url, src_port + proxyOffset);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[BALANCER] " + e.StackTrace);
|
2008-03-04 05:31:54 +00:00
|
|
|
throw e;
|
|
|
|
}
|
2008-03-04 06:02:48 +00:00
|
|
|
|
2008-03-04 05:31:54 +00:00
|
|
|
return new XmlRpcResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
private XmlRpcResponse UpdatePhysics(XmlRpcRequest request)
|
|
|
|
{
|
|
|
|
// this callback receives physic scene updates from the other sub-scenes (in split mode)
|
|
|
|
|
|
|
|
int regionPort = (int) request.Params[0];
|
|
|
|
LLUUID scenePresenceID = new LLUUID((byte[]) request.Params[1], 0);
|
|
|
|
LLVector3 position = new LLVector3((byte[]) request.Params[2], 0);
|
|
|
|
LLVector3 velocity = new LLVector3((byte[]) request.Params[3], 0);
|
|
|
|
bool flying = (bool) request.Params[4];
|
|
|
|
|
|
|
|
LocalUpdatePhysics(regionPort, scenePresenceID, position, velocity, flying);
|
|
|
|
|
|
|
|
return new XmlRpcResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LocalUpdatePhysics(int regionPort, LLUUID scenePresenceID, LLVector3 position, LLVector3 velocity, bool flying)
|
|
|
|
{
|
|
|
|
//m_log.Info("[SPLITSCENE] "+String.Format("UpdatePhysics called {0}", regionID));
|
|
|
|
|
|
|
|
//m_log.Info("[SPLITSCENE] "+"LocalUpdatePhysics [region port:{0}, client:{1}, position:{2}, velocity:{3}, flying:{4}]",
|
|
|
|
// regionPort, scenePresenceID.ToString(), position.ToString(),
|
|
|
|
// velocity.ToString(), flying);
|
|
|
|
|
|
|
|
RegionInfo region = SearchRegionFromPortNum(regionPort);
|
|
|
|
|
|
|
|
// Find and update the scene precense
|
|
|
|
Scene scene;
|
|
|
|
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == scenePresenceID; });
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
if (pre == null)
|
|
|
|
{
|
2008-03-04 05:31:54 +00:00
|
|
|
m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePhysics] ScenePresence is missing... ({0})", scenePresenceID.ToString());
|
|
|
|
return;
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
// m_log.Info("[SPLITSCENE] "+"LocalUpdatePhysics [region:{0}, client:{1}]",
|
|
|
|
// regionID.ToString(), pre.UUID.ToString());
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
pre.AbsolutePosition = position; // will set PhysicsActor.Position
|
2008-03-04 05:31:54 +00:00
|
|
|
pre.Velocity = velocity; // will set PhysicsActor.Velocity
|
|
|
|
pre.PhysicsActor.Flying = flying;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SynchronizeScenes(Scene scene)
|
|
|
|
{
|
|
|
|
if (!isSplit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
lock (padlock)
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
|
|
|
// Callback activated after a physics scene update
|
|
|
|
// int i = 0;
|
|
|
|
List<ScenePresence> presences = scene.GetScenePresences();
|
|
|
|
foreach (ScenePresence pre in presences)
|
|
|
|
{
|
2008-05-02 16:41:35 +00:00
|
|
|
LLClientView client = (LLClientView) pre.ControllingClient;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
// Because data changes by the physics simulation when the client doesn't move,
|
|
|
|
// if MovementFlag is false, It is necessary to synchronize.
|
|
|
|
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true)
|
2008-05-02 16:41:35 +00:00
|
|
|
if (client.IsActive == true)
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
|
|
|
//m_log.Info("[SPLITSCENE] "+String.Format("Client moving in {0} {1}", scene.RegionInfo.RegionID, pre.AbsolutePosition));
|
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
for (int i = 0; i < sceneURL.Length; i++)
|
|
|
|
{
|
|
|
|
if (i == scene.splitID)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-29 14:10:26 +00:00
|
|
|
|
|
|
|
if (isLocalNeighbour[i])
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
|
|
|
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Local) [region:{0}=>{1}, client:{2}]",
|
|
|
|
// scene.RegionInfo.RegionID, regionPortList[i], pre.UUID.ToString());
|
|
|
|
LocalUpdatePhysics(regionPortList[i], pre.UUID, pre.AbsolutePosition, pre.Velocity, pre.PhysicsActor.Flying);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Remote) [region port:{0}, client:{1}, position:{2}, velocity:{3}, flying:{4}]",
|
|
|
|
// regionPortList[i], pre.UUID.ToString(), pre.AbsolutePosition.ToString(),
|
|
|
|
// pre.Velocity.ToString(), pre.PhysicsActor.Flying);
|
|
|
|
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
Util.XmlRpcCommand(sceneURL[i], "UpdatePhysics",
|
2008-03-24 01:37:00 +00:00
|
|
|
regionPortList[i], pre.UUID.GetBytes(),
|
|
|
|
pre.AbsolutePosition.GetBytes(), pre.Velocity.GetBytes(),
|
|
|
|
pre.PhysicsActor.Flying);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
/*
|
2008-03-04 06:02:48 +00:00
|
|
|
byte[] buff = new byte[12+12+1];
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
Buffer.BlockCopy(pre.AbsolutePosition.GetBytes(), 0, buff, 0, 12);
|
|
|
|
Buffer.BlockCopy(pre.Velocity.GetBytes(), 0, buff, 12, 12);
|
|
|
|
buff[24] = (byte)((pre.PhysicsActor.Flying)?1:0);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
// create header
|
|
|
|
InternalPacketHeader header = new InternalPacketHeader();
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
header.type = 1;
|
|
|
|
header.throttlePacketType = 0;
|
|
|
|
header.numbytes = buff.Length;
|
|
|
|
header.agent_id = pre.UUID.UUID;
|
|
|
|
header.region_port = regionPortList[i];
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
//Send
|
|
|
|
tcpClientList[i].send(header, buff);
|
2008-03-04 05:31:54 +00:00
|
|
|
*/
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
// ++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool SynchronizePackets(IScene scene, Packet packet, LLUUID agentID, ThrottleOutPacketType throttlePacketType)
|
|
|
|
{
|
|
|
|
if (!isSplit)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
Scene localScene = (Scene) scene;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
for (int i = 0; i < sceneURL.Length; i++)
|
|
|
|
{
|
|
|
|
if (i == localScene.splitID)
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
2008-03-04 06:02:48 +00:00
|
|
|
continue;
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
2008-04-29 14:10:26 +00:00
|
|
|
|
|
|
|
if (isLocalNeighbour[i])
|
2008-03-04 05:31:54 +00:00
|
|
|
{
|
2008-03-04 06:02:48 +00:00
|
|
|
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Local) [type:{0}, client:{1}]",
|
|
|
|
// packet.Type.ToString(), agentID.ToString());
|
|
|
|
LocalUpdatePacket(regionPortList[i], agentID, packet, throttlePacketType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Remote) [type:{0}, client:{1}]",
|
|
|
|
// packet.Type.ToString(), agentID.ToString());
|
|
|
|
// to bytes
|
|
|
|
byte[] buff = packet.ToBytes();
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
// create header
|
|
|
|
InternalPacketHeader header = new InternalPacketHeader();
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
header.type = 0;
|
2008-04-29 14:10:26 +00:00
|
|
|
header.throttlePacketType = (int) throttlePacketType;
|
2008-03-04 06:02:48 +00:00
|
|
|
header.numbytes = buff.Length;
|
|
|
|
header.agent_id = agentID.UUID;
|
|
|
|
header.region_port = regionPortList[i];
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
//Send
|
|
|
|
tcpClientList[i].send(header, buff);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
PacketPool.Instance.ReturnPacket(packet);
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LocalUpdatePacket(int regionPort, LLUUID agentID, Packet packet, ThrottleOutPacketType throttlePacketType)
|
|
|
|
{
|
|
|
|
Scene scene;
|
|
|
|
|
|
|
|
RegionInfo region = SearchRegionFromPortNum(regionPort);
|
|
|
|
|
|
|
|
// m_log.Info("[SPLITSCENE] "+"LocalUpdatePacket [region port:{0}, client:{1}, packet type:{2}]",
|
|
|
|
// regionPort, agentID.ToString(), packet.GetType().ToString());
|
|
|
|
|
|
|
|
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
|
|
|
{
|
2008-04-29 14:10:26 +00:00
|
|
|
ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == agentID; });
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
if (pre == null)
|
|
|
|
{
|
2008-03-04 05:31:54 +00:00
|
|
|
m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePacket] ScenePresence is missing... ({0})", agentID.ToString());
|
|
|
|
return;
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
|
|
|
|
2008-05-02 16:41:35 +00:00
|
|
|
if (((LLClientView) pre.ControllingClient).IsActive)
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
|
|
|
pre.ControllingClient.OutPacket(packet, throttlePacketType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PacketPool.Instance.ReturnPacket(packet);
|
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SynchronizePacketRecieve(InternalPacketHeader header, byte[] buff)
|
|
|
|
{
|
|
|
|
// m_log.Info("[SPLITSCENE] "+"entering SynchronizePacketRecieve[type={0}]", header.type);
|
|
|
|
|
|
|
|
if (!isSplit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (header.type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
Packet packet = null;
|
|
|
|
byte[] zero = new byte[3000];
|
|
|
|
int packetEnd = 0;
|
|
|
|
|
|
|
|
// deserialize packet
|
|
|
|
packetEnd = buff.Length - 1;
|
|
|
|
// packetEnd = buff.Length;
|
|
|
|
|
|
|
|
try
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
2008-03-04 05:31:54 +00:00
|
|
|
//m_log.Info("[SPLITSCENE] "+"PacketPool.Instance : {0}", (PacketPool.Instance == null)?"null":"not null");
|
|
|
|
//m_log.Info("[SPLITSCENE] "+"buff length={0}", buff.Length);
|
|
|
|
|
|
|
|
packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero);
|
|
|
|
|
2008-04-29 14:10:26 +00:00
|
|
|
LocalUpdatePacket(header.region_port, new LLUUID(header.agent_id),
|
|
|
|
packet, (ThrottleOutPacketType) header.throttlePacketType);
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
catch (Exception e)
|
2008-03-04 06:02:48 +00:00
|
|
|
{
|
2008-05-01 18:04:42 +00:00
|
|
|
m_log.Error("[SPLITSCENE] " + e.ToString());
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Error("[SPLITSCENE] " + e.StackTrace);
|
2008-03-04 06:02:48 +00:00
|
|
|
}
|
2008-03-04 05:31:54 +00:00
|
|
|
|
2008-03-04 06:02:48 +00:00
|
|
|
break;
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
int regionPort = header.region_port;
|
|
|
|
LLUUID scenePresenceID = new LLUUID(header.agent_id);
|
|
|
|
LLVector3 position = new LLVector3(buff, 0);
|
|
|
|
LLVector3 velocity = new LLVector3(buff, 12);
|
2008-05-01 18:04:42 +00:00
|
|
|
bool flying = ((buff[24] == (byte) 1) ? true : false);
|
2008-03-04 05:31:54 +00:00
|
|
|
|
|
|
|
LocalUpdatePhysics(regionPort, scenePresenceID, position, velocity, flying);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-04-29 14:10:26 +00:00
|
|
|
m_log.Info("[SPLITSCENE] " + "Invalid type");
|
2008-03-04 05:31:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// m_log.Info("[SPLITSCENE] "+"exiting SynchronizePacketRecieve");
|
|
|
|
}
|
|
|
|
}
|
2008-05-01 18:04:42 +00:00
|
|
|
}
|