Update svn properties. Minor formatting cleanup.
parent
279e0061c5
commit
75f6f6e3ff
|
@ -1,30 +1,29 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Contributors, http://opensimulator.org/
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* * Neither the name of the OpenSim Project nor the
|
* * Neither the name of the OpenSim Project nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* 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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -72,7 +71,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
private int proxyOffset;
|
private int proxyOffset;
|
||||||
private string proxyURL;
|
private string proxyURL;
|
||||||
private SceneManager sceneManager;
|
private SceneManager sceneManager;
|
||||||
private string serializeDir;
|
private string serializeDir;
|
||||||
|
|
||||||
private TcpServer mTcpServer;
|
private TcpServer mTcpServer;
|
||||||
private TcpClient mTcpClient;
|
private TcpClient mTcpClient;
|
||||||
|
@ -81,7 +80,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
{
|
{
|
||||||
m_log.Info("[BALANCER] "+"Entering Initialize()");
|
m_log.Info("[BALANCER] "+"Entering Initialize()");
|
||||||
|
|
||||||
StartTcpServer();
|
StartTcpServer();
|
||||||
ClientView.SynchronizeClient = new ClientView.SynchronizeClientHandler(SynchronizePackets);
|
ClientView.SynchronizeClient = new ClientView.SynchronizeClientHandler(SynchronizePackets);
|
||||||
AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve);
|
AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve);
|
||||||
|
|
||||||
|
@ -113,10 +112,10 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
private void StartTcpServer()
|
private void StartTcpServer()
|
||||||
{
|
{
|
||||||
Thread server_thread = new Thread(new ThreadStart(
|
Thread server_thread = new Thread(new ThreadStart(
|
||||||
delegate {
|
delegate {
|
||||||
mTcpServer = new TcpServer(10001);
|
mTcpServer = new TcpServer(10001);
|
||||||
mTcpServer.start();
|
mTcpServer.start();
|
||||||
}));
|
}));
|
||||||
server_thread.Start();
|
server_thread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,67 +125,67 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
|
|
||||||
private XmlRpcResponse GetStatus(XmlRpcRequest request)
|
private XmlRpcResponse GetStatus(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
XmlRpcResponse response = new XmlRpcResponse();
|
XmlRpcResponse response = new XmlRpcResponse();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_log.Info("[BALANCER] "+"Entering RegionStatus()");
|
m_log.Info("[BALANCER] "+"Entering RegionStatus()");
|
||||||
|
|
||||||
int src_port = (int)request.Params[0];
|
int src_port = (int)request.Params[0];
|
||||||
Scene scene = null;
|
Scene scene = null;
|
||||||
// try to get the scene object
|
// try to get the scene object
|
||||||
RegionInfo src_region = SearchRegionFromPortNum(src_port);
|
RegionInfo src_region = SearchRegionFromPortNum(src_port);
|
||||||
if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false)
|
if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false)
|
||||||
{
|
{
|
||||||
m_log.Error("[BALANCER] "+"The Scene is not found");
|
m_log.Error("[BALANCER] "+"The Scene is not found");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
// serialization of client's informations
|
// serialization of client's informations
|
||||||
List<ScenePresence> presences = scene.GetScenePresences();
|
List<ScenePresence> presences = scene.GetScenePresences();
|
||||||
int get_scene_presence = presences.Count;
|
int get_scene_presence = presences.Count;
|
||||||
int get_scene_presence_filter = 0;
|
int get_scene_presence_filter = 0;
|
||||||
foreach (ScenePresence pre in presences)
|
foreach (ScenePresence pre in presences)
|
||||||
{
|
{
|
||||||
ClientView client = (ClientView) pre.ControllingClient;
|
ClientView client = (ClientView) pre.ControllingClient;
|
||||||
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
||||||
if(client.PacketProcessingEnabled==true) {
|
if(client.PacketProcessingEnabled==true) {
|
||||||
get_scene_presence_filter++;
|
get_scene_presence_filter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<ScenePresence> avatars = scene.GetAvatars();
|
List<ScenePresence> avatars = scene.GetAvatars();
|
||||||
int get_avatar = avatars.Count;
|
int get_avatar = avatars.Count;
|
||||||
int get_avatar_filter = 0;
|
int get_avatar_filter = 0;
|
||||||
string avatar_names = "";
|
string avatar_names = "";
|
||||||
foreach (ScenePresence pre in avatars)
|
foreach (ScenePresence pre in avatars)
|
||||||
{
|
{
|
||||||
ClientView client = (ClientView) pre.ControllingClient;
|
ClientView client = (ClientView) pre.ControllingClient;
|
||||||
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
||||||
if(client.PacketProcessingEnabled==true) {
|
if(client.PacketProcessingEnabled==true) {
|
||||||
get_avatar_filter++;
|
get_avatar_filter++;
|
||||||
avatar_names += pre.Firstname + " " + pre.Lastname + "; ";
|
avatar_names += pre.Firstname + " " + pre.Lastname + "; ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Hashtable responseData = new Hashtable();
|
Hashtable responseData = new Hashtable();
|
||||||
responseData["get_scene_presence_filter"] = get_scene_presence_filter;
|
responseData["get_scene_presence_filter"] = get_scene_presence_filter;
|
||||||
responseData["get_scene_presence"] = get_scene_presence;
|
responseData["get_scene_presence"] = get_scene_presence;
|
||||||
responseData["get_avatar_filter"] = get_avatar_filter;
|
responseData["get_avatar_filter"] = get_avatar_filter;
|
||||||
responseData["get_avatar"] = get_avatar;
|
responseData["get_avatar"] = get_avatar;
|
||||||
responseData["avatar_names"] = avatar_names;
|
responseData["avatar_names"] = avatar_names;
|
||||||
response.Value = responseData;
|
response.Value = responseData;
|
||||||
|
|
||||||
m_log.Info("[BALANCER] "+"Exiting RegionStatus()");
|
m_log.Info("[BALANCER] "+"Exiting RegionStatus()");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
m_log.Error("[BALANCER] "+e.ToString());
|
m_log.Error("[BALANCER] "+e.ToString());
|
||||||
m_log.Error("[BALANCER] "+e.StackTrace);
|
m_log.Error("[BALANCER] "+e.StackTrace);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private XmlRpcResponse SerializeRegion(XmlRpcRequest request)
|
private XmlRpcResponse SerializeRegion(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_log.Info("[BALANCER] "+"Entering SerializeRegion()");
|
m_log.Info("[BALANCER] "+"Entering SerializeRegion()");
|
||||||
|
|
||||||
|
@ -431,7 +430,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
//scene.Backup();
|
//scene.Backup();
|
||||||
|
|
||||||
m_log.InfoFormat("[BALANCER] "+"region serialization completed [{0}]",
|
m_log.InfoFormat("[BALANCER] "+"region serialization completed [{0}]",
|
||||||
src_region.RegionID.ToString());
|
src_region.RegionID.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SerializeClient(int idx, Scene scene, ScenePresence pre, string export_dir)
|
private void SerializeClient(int idx, Scene scene, ScenePresence pre, string export_dir)
|
||||||
|
@ -499,7 +498,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
DeserializeClient(dst_region, import_dir);
|
DeserializeClient(dst_region, import_dir);
|
||||||
|
|
||||||
m_log.InfoFormat("[BALANCER] "+"region deserialization completed [{0}]",
|
m_log.InfoFormat("[BALANCER] "+"region deserialization completed [{0}]",
|
||||||
dst_region.ToString());
|
dst_region.ToString());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -527,19 +526,19 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
|
|
||||||
// restore the scene presence
|
// restore the scene presence
|
||||||
/*
|
/*
|
||||||
files = Directory.GetFiles(import_dir, "Presence_*.bin");
|
files = Directory.GetFiles(import_dir, "Presence_*.bin");
|
||||||
Array.Sort(files);
|
Array.Sort(files);
|
||||||
|
|
||||||
foreach (string filename in files)
|
|
||||||
{
|
|
||||||
sp = (ScenePresence)Util.DeserializeFromFile(filename);
|
|
||||||
Console.WriteLine("agent id = {0}", sp.m_uuid);
|
|
||||||
|
|
||||||
scene.m_restorePresences.Add(sp.m_uuid, sp);
|
foreach (string filename in files)
|
||||||
File.Delete(filename);
|
{
|
||||||
|
sp = (ScenePresence)Util.DeserializeFromFile(filename);
|
||||||
|
Console.WriteLine("agent id = {0}", sp.m_uuid);
|
||||||
|
|
||||||
m_log.InfoFormat("[BALANCER] "+"scene presence deserialized [{0}]", sp.m_uuid);
|
scene.m_restorePresences.Add(sp.m_uuid, sp);
|
||||||
}
|
File.Delete(filename);
|
||||||
|
|
||||||
|
m_log.InfoFormat("[BALANCER] "+"scene presence deserialized [{0}]", sp.m_uuid);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
for (int i = 0; ; i++)
|
for (int i = 0; ; i++)
|
||||||
{
|
{
|
||||||
|
@ -576,18 +575,18 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
|
|
||||||
udpserv.RestoreClient(agentdata, data.userEP, data.proxyEP);
|
udpserv.RestoreClient(agentdata, data.userEP, data.proxyEP);
|
||||||
|
|
||||||
// waiting for the scene-presense restored
|
// waiting for the scene-presense restored
|
||||||
lock (scene.m_restorePresences)
|
lock (scene.m_restorePresences)
|
||||||
{
|
{
|
||||||
Monitor.Wait(scene.m_restorePresences, 3000);
|
Monitor.Wait(scene.m_restorePresences, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scene.ClientManager.TryGetClient(circuit_code, out controller))
|
if (scene.ClientManager.TryGetClient(circuit_code, out controller))
|
||||||
{
|
{
|
||||||
m_log.InfoFormat("[BALANCER] " + "get client [{0}]", circuit_code);
|
m_log.InfoFormat("[BALANCER] " + "get client [{0}]", circuit_code);
|
||||||
controller.SetClientInfo(data);
|
controller.SetClientInfo(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
File.Delete(fname);
|
File.Delete(fname);
|
||||||
|
|
||||||
m_log.InfoFormat("[BALANCER] " + "client info deserialized [{0}]", circuit_code);
|
m_log.InfoFormat("[BALANCER] " + "client info deserialized [{0}]", circuit_code);
|
||||||
|
@ -622,7 +621,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
Console.WriteLine("scene found.");
|
Console.WriteLine("scene found.");
|
||||||
|
|
||||||
if ((sceneManager.CurrentScene != null)
|
if ((sceneManager.CurrentScene != null)
|
||||||
&& (sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID))
|
&& (sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID))
|
||||||
{
|
{
|
||||||
sceneManager.TrySetCurrentScene("..");
|
sceneManager.TrySetCurrentScene("..");
|
||||||
}
|
}
|
||||||
|
@ -671,10 +670,10 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
{
|
{
|
||||||
// stopping clientview thread
|
// stopping clientview thread
|
||||||
if (((ClientView)controller).PacketProcessingEnabled)
|
if (((ClientView)controller).PacketProcessingEnabled)
|
||||||
{
|
{
|
||||||
controller.Stop();
|
controller.Stop();
|
||||||
((ClientView)controller).PacketProcessingEnabled = false;
|
((ClientView)controller).PacketProcessingEnabled = false;
|
||||||
}
|
}
|
||||||
// teminateing clientview thread
|
// teminateing clientview thread
|
||||||
controller.Terminate();
|
controller.Terminate();
|
||||||
m_log.Info("[BALANCER] "+"client thread stopped");
|
m_log.Info("[BALANCER] "+"client thread stopped");
|
||||||
|
@ -698,90 +697,90 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
|
|
||||||
private XmlRpcResponse SplitRegion(XmlRpcRequest request)
|
private XmlRpcResponse SplitRegion(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int myID = (int) request.Params[0];
|
int myID = (int) request.Params[0];
|
||||||
int numRegions = (int) request.Params[1];
|
int numRegions = (int) request.Params[1];
|
||||||
regionPortList = new int[numRegions];
|
regionPortList = new int[numRegions];
|
||||||
sceneURL = new string[numRegions];
|
sceneURL = new string[numRegions];
|
||||||
tcpClientList = new TcpClient[numRegions];
|
tcpClientList = new TcpClient[numRegions];
|
||||||
|
|
||||||
for(int i=0; i<numRegions; i++)
|
for(int i=0; i<numRegions; i++)
|
||||||
|
{
|
||||||
|
regionPortList[i]=(int) request.Params[i+2];
|
||||||
|
sceneURL[i]=(string) request.Params[i+2+numRegions];
|
||||||
|
}
|
||||||
|
|
||||||
|
string hostname;
|
||||||
|
|
||||||
|
for(int i=0; i<numRegions; i++)
|
||||||
|
{
|
||||||
|
hostname = sceneURL[i].Split(new char[] { '/', ':' })[3];
|
||||||
|
m_log.InfoFormat("[SPLITSCENE] "+"creating tcp client host:{0}", hostname);
|
||||||
|
tcpClientList[i] = new TcpClient(hostname, 10001);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMaster = (myID == 0);
|
||||||
|
|
||||||
|
isLocalNeighbour = new bool[numRegions];
|
||||||
|
for(int i=0; i<numRegions; i++) isLocalNeighbour[i] = (sceneURL[i] == sceneURL[myID]);
|
||||||
|
|
||||||
|
RegionInfo region = SearchRegionFromPortNum(regionPortList[myID]);
|
||||||
|
|
||||||
|
//Console.WriteLine("\n === SplitRegion {0}\n", region.RegionID);
|
||||||
|
|
||||||
|
Scene scene;
|
||||||
|
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
||||||
|
{
|
||||||
|
// Disable event updates, backups etc in the slave(s)
|
||||||
|
if (isMaster) {
|
||||||
|
scene.Region_Status = RegionStatus.Up;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scene.Region_Status = RegionStatus.SlaveScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Console.WriteLine("=== SplitRegion {0}: Scene found, status {1}", region.RegionID, scene.Region_Status);
|
||||||
|
|
||||||
|
// Disabling half of the avatars in master, and the other half in slave
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
List<ScenePresence> presences = scene.GetScenePresences();
|
||||||
|
presences.Sort();
|
||||||
|
foreach (ScenePresence pre in presences)
|
||||||
|
{
|
||||||
|
// Divide the presences evenly over the set of subscenes
|
||||||
|
ClientView client = (ClientView) pre.ControllingClient;
|
||||||
|
client.PacketProcessingEnabled = (( (i + myID) % sceneURL.Length) == 0);
|
||||||
|
|
||||||
|
m_log.InfoFormat("[SPLITSCENE] === SplitRegion {0}: SP.PacketEnabled {1}", region.RegionID, client.PacketProcessingEnabled);
|
||||||
|
|
||||||
|
if (!client.PacketProcessingEnabled)
|
||||||
{
|
{
|
||||||
regionPortList[i]=(int) request.Params[i+2];
|
// stopping clientview thread
|
||||||
sceneURL[i]=(string) request.Params[i+2+numRegions];
|
client.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
string hostname;
|
++i;
|
||||||
|
|
||||||
for(int i=0; i<numRegions; i++)
|
|
||||||
{
|
|
||||||
hostname = sceneURL[i].Split(new char[] { '/', ':' })[3];
|
|
||||||
m_log.InfoFormat("[SPLITSCENE] "+"creating tcp client host:{0}", hostname);
|
|
||||||
tcpClientList[i] = new TcpClient(hostname, 10001);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isMaster = (myID == 0);
|
|
||||||
|
|
||||||
isLocalNeighbour = new bool[numRegions];
|
|
||||||
for(int i=0; i<numRegions; i++) isLocalNeighbour[i] = (sceneURL[i] == sceneURL[myID]);
|
|
||||||
|
|
||||||
RegionInfo region = SearchRegionFromPortNum(regionPortList[myID]);
|
|
||||||
|
|
||||||
//Console.WriteLine("\n === SplitRegion {0}\n", region.RegionID);
|
|
||||||
|
|
||||||
Scene scene;
|
|
||||||
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
|
||||||
{
|
|
||||||
// Disable event updates, backups etc in the slave(s)
|
|
||||||
if (isMaster) {
|
|
||||||
scene.Region_Status = RegionStatus.Up;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
scene.Region_Status = RegionStatus.SlaveScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Console.WriteLine("=== SplitRegion {0}: Scene found, status {1}", region.RegionID, scene.Region_Status);
|
|
||||||
|
|
||||||
// Disabling half of the avatars in master, and the other half in slave
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
List<ScenePresence> presences = scene.GetScenePresences();
|
|
||||||
presences.Sort();
|
|
||||||
foreach (ScenePresence pre in presences)
|
|
||||||
{
|
|
||||||
// Divide the presences evenly over the set of subscenes
|
|
||||||
ClientView client = (ClientView) pre.ControllingClient;
|
|
||||||
client.PacketProcessingEnabled = (( (i + myID) % sceneURL.Length) == 0);
|
|
||||||
|
|
||||||
m_log.InfoFormat("[SPLITSCENE] === SplitRegion {0}: SP.PacketEnabled {1}", region.RegionID, client.PacketProcessingEnabled);
|
|
||||||
|
|
||||||
if (!client.PacketProcessingEnabled)
|
|
||||||
{
|
|
||||||
// stopping clientview thread
|
|
||||||
client.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.splitID = myID;
|
|
||||||
scene.SynchronizeScene = new Scene.SynchronizeSceneHandler(SynchronizeScenes);
|
|
||||||
isSplit = true;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_log.Error("[SPLITSCENE] "+String.Format("Scene not found {0}", region.RegionID));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
m_log.Error("[SPLITSCENE] "+e.ToString());
|
|
||||||
m_log.Error("[SPLITSCENE] "+e.StackTrace);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new XmlRpcResponse();
|
scene.splitID = myID;
|
||||||
|
scene.SynchronizeScene = new Scene.SynchronizeSceneHandler(SynchronizeScenes);
|
||||||
|
isSplit = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.Error("[SPLITSCENE] "+String.Format("Scene not found {0}", region.RegionID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.Error("[SPLITSCENE] "+e.ToString());
|
||||||
|
m_log.Error("[SPLITSCENE] "+e.StackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new XmlRpcResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private XmlRpcResponse MergeRegions(XmlRpcRequest request)
|
private XmlRpcResponse MergeRegions(XmlRpcRequest request)
|
||||||
|
@ -794,40 +793,40 @@ presences.Sort();
|
||||||
string src_url = (string) request.Params[0];
|
string src_url = (string) request.Params[0];
|
||||||
int src_port = (int) request.Params[1];
|
int src_port = (int) request.Params[1];
|
||||||
|
|
||||||
RegionInfo region = SearchRegionFromPortNum(src_port);
|
RegionInfo region = SearchRegionFromPortNum(src_port);
|
||||||
|
|
||||||
simMain.ProxyCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset);
|
|
||||||
|
|
||||||
Scene scene;
|
simMain.ProxyCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset);
|
||||||
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
|
||||||
{
|
|
||||||
isSplit = false;
|
|
||||||
|
|
||||||
scene.SynchronizeScene = null;
|
Scene scene;
|
||||||
scene.Region_Status = RegionStatus.Up;
|
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
||||||
|
{
|
||||||
|
isSplit = false;
|
||||||
|
|
||||||
List<ScenePresence> presences = scene.GetScenePresences();
|
scene.SynchronizeScene = null;
|
||||||
foreach (ScenePresence pre in presences)
|
scene.Region_Status = RegionStatus.Up;
|
||||||
{
|
|
||||||
ClientView client = (ClientView) pre.ControllingClient;
|
|
||||||
if (!client.PacketProcessingEnabled)
|
|
||||||
{
|
|
||||||
client.Restart();
|
|
||||||
client.PacketProcessingEnabled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the slave scenes
|
|
||||||
for(int i=1; i<sceneURL.Length; i++)
|
|
||||||
{
|
|
||||||
string url = (sceneURL[i].Split('/')[2]).Split(':')[0]; // get URL part from EP
|
|
||||||
simMain.ProxyCommand(region.proxyUrl, "DeleteRegion", regionPortList[i] + proxyOffset, url);
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
simMain.XmlRpcCommand(sceneURL[i], "TerminateRegion", regionPortList[i]); // TODO: need + proxyOffset?
|
|
||||||
}
|
|
||||||
|
|
||||||
simMain.ProxyCommand(region.proxyUrl, "UnblockClientMessages", src_url, src_port + proxyOffset);
|
List<ScenePresence> presences = scene.GetScenePresences();
|
||||||
|
foreach (ScenePresence pre in presences)
|
||||||
|
{
|
||||||
|
ClientView client = (ClientView) pre.ControllingClient;
|
||||||
|
if (!client.PacketProcessingEnabled)
|
||||||
|
{
|
||||||
|
client.Restart();
|
||||||
|
client.PacketProcessingEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the slave scenes
|
||||||
|
for(int i=1; i<sceneURL.Length; i++)
|
||||||
|
{
|
||||||
|
string url = (sceneURL[i].Split('/')[2]).Split(':')[0]; // get URL part from EP
|
||||||
|
simMain.ProxyCommand(region.proxyUrl, "DeleteRegion", regionPortList[i] + proxyOffset, url);
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
simMain.XmlRpcCommand(sceneURL[i], "TerminateRegion", regionPortList[i]); // TODO: need + proxyOffset?
|
||||||
|
}
|
||||||
|
|
||||||
|
simMain.ProxyCommand(region.proxyUrl, "UnblockClientMessages", src_url, src_port + proxyOffset);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -835,7 +834,7 @@ presences.Sort();
|
||||||
m_log.Error("[BALANCER] "+e.StackTrace);
|
m_log.Error("[BALANCER] "+e.StackTrace);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new XmlRpcResponse();
|
return new XmlRpcResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -870,11 +869,11 @@ presences.Sort();
|
||||||
{
|
{
|
||||||
ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == scenePresenceID; });
|
ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == scenePresenceID; });
|
||||||
|
|
||||||
if (pre == null)
|
if (pre == null)
|
||||||
{
|
{
|
||||||
m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePhysics] ScenePresence is missing... ({0})", scenePresenceID.ToString());
|
m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePhysics] ScenePresence is missing... ({0})", scenePresenceID.ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// m_log.Info("[SPLITSCENE] "+"LocalUpdatePhysics [region:{0}, client:{1}]",
|
// m_log.Info("[SPLITSCENE] "+"LocalUpdatePhysics [region:{0}, client:{1}]",
|
||||||
// regionID.ToString(), pre.UUID.ToString());
|
// regionID.ToString(), pre.UUID.ToString());
|
||||||
|
@ -905,56 +904,56 @@ presences.Sort();
|
||||||
// Because data changes by the physics simulation when the client doesn't move,
|
// Because data changes by the physics simulation when the client doesn't move,
|
||||||
// if MovementFlag is false, It is necessary to synchronize.
|
// if MovementFlag is false, It is necessary to synchronize.
|
||||||
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true)
|
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true)
|
||||||
if(client.PacketProcessingEnabled==true)
|
if(client.PacketProcessingEnabled==true)
|
||||||
{
|
{
|
||||||
//m_log.Info("[SPLITSCENE] "+String.Format("Client moving in {0} {1}", scene.RegionInfo.RegionID, pre.AbsolutePosition));
|
//m_log.Info("[SPLITSCENE] "+String.Format("Client moving in {0} {1}", scene.RegionInfo.RegionID, pre.AbsolutePosition));
|
||||||
|
|
||||||
for (int i = 0; i < sceneURL.Length; i++)
|
for (int i = 0; i < sceneURL.Length; i++)
|
||||||
{
|
{
|
||||||
if (i == scene.splitID)
|
if (i == scene.splitID)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isLocalNeighbour[i])
|
if(isLocalNeighbour[i])
|
||||||
{
|
{
|
||||||
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Local) [region:{0}=>{1}, client:{2}]",
|
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Local) [region:{0}=>{1}, client:{2}]",
|
||||||
// scene.RegionInfo.RegionID, regionPortList[i], pre.UUID.ToString());
|
// scene.RegionInfo.RegionID, regionPortList[i], pre.UUID.ToString());
|
||||||
LocalUpdatePhysics(regionPortList[i], pre.UUID, pre.AbsolutePosition, pre.Velocity, pre.PhysicsActor.Flying);
|
LocalUpdatePhysics(regionPortList[i], pre.UUID, pre.AbsolutePosition, pre.Velocity, pre.PhysicsActor.Flying);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Remote) [region port:{0}, client:{1}, position:{2}, velocity:{3}, flying:{4}]",
|
//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(),
|
// regionPortList[i], pre.UUID.ToString(), pre.AbsolutePosition.ToString(),
|
||||||
// pre.Velocity.ToString(), pre.PhysicsActor.Flying);
|
// pre.Velocity.ToString(), pre.PhysicsActor.Flying);
|
||||||
|
|
||||||
|
|
||||||
simMain.XmlRpcCommand(sceneURL[i], "UpdatePhysics",
|
simMain.XmlRpcCommand(sceneURL[i], "UpdatePhysics",
|
||||||
regionPortList[i], pre.UUID.GetBytes(),
|
regionPortList[i], pre.UUID.GetBytes(),
|
||||||
pre.AbsolutePosition.GetBytes(), pre.Velocity.GetBytes(),
|
pre.AbsolutePosition.GetBytes(), pre.Velocity.GetBytes(),
|
||||||
pre.PhysicsActor.Flying);
|
pre.PhysicsActor.Flying);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
byte[] buff = new byte[12+12+1];
|
byte[] buff = new byte[12+12+1];
|
||||||
|
|
||||||
Buffer.BlockCopy(pre.AbsolutePosition.GetBytes(), 0, buff, 0, 12);
|
Buffer.BlockCopy(pre.AbsolutePosition.GetBytes(), 0, buff, 0, 12);
|
||||||
Buffer.BlockCopy(pre.Velocity.GetBytes(), 0, buff, 12, 12);
|
Buffer.BlockCopy(pre.Velocity.GetBytes(), 0, buff, 12, 12);
|
||||||
buff[24] = (byte)((pre.PhysicsActor.Flying)?1:0);
|
buff[24] = (byte)((pre.PhysicsActor.Flying)?1:0);
|
||||||
|
|
||||||
// create header
|
// create header
|
||||||
InternalPacketHeader header = new InternalPacketHeader();
|
InternalPacketHeader header = new InternalPacketHeader();
|
||||||
|
|
||||||
header.type = 1;
|
header.type = 1;
|
||||||
header.throttlePacketType = 0;
|
header.throttlePacketType = 0;
|
||||||
header.numbytes = buff.Length;
|
header.numbytes = buff.Length;
|
||||||
header.agent_id = pre.UUID.UUID;
|
header.agent_id = pre.UUID.UUID;
|
||||||
header.region_port = regionPortList[i];
|
header.region_port = regionPortList[i];
|
||||||
|
|
||||||
//Send
|
//Send
|
||||||
tcpClientList[i].send(header, buff);
|
tcpClientList[i].send(header, buff);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ++i;
|
// ++i;
|
||||||
}
|
}
|
||||||
|
@ -968,41 +967,41 @@ presences.Sort();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene localScene = (Scene)scene;
|
Scene localScene = (Scene)scene;
|
||||||
|
|
||||||
for (int i = 0; i < sceneURL.Length; i++)
|
for (int i = 0; i < sceneURL.Length; i++)
|
||||||
{
|
{
|
||||||
if (i == localScene.splitID)
|
if (i == localScene.splitID)
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isLocalNeighbour[i])
|
|
||||||
{
|
{
|
||||||
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Local) [type:{0}, client:{1}]",
|
continue;
|
||||||
// packet.Type.ToString(), agentID.ToString());
|
|
||||||
LocalUpdatePacket(regionPortList[i], agentID, packet, throttlePacketType);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if(isLocalNeighbour[i])
|
||||||
{
|
{
|
||||||
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Remote) [type:{0}, client:{1}]",
|
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Local) [type:{0}, client:{1}]",
|
||||||
// packet.Type.ToString(), agentID.ToString());
|
// packet.Type.ToString(), agentID.ToString());
|
||||||
// to bytes
|
LocalUpdatePacket(regionPortList[i], agentID, packet, throttlePacketType);
|
||||||
byte[] buff = packet.ToBytes();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Remote) [type:{0}, client:{1}]",
|
||||||
|
// packet.Type.ToString(), agentID.ToString());
|
||||||
|
// to bytes
|
||||||
|
byte[] buff = packet.ToBytes();
|
||||||
|
|
||||||
// create header
|
// create header
|
||||||
InternalPacketHeader header = new InternalPacketHeader();
|
InternalPacketHeader header = new InternalPacketHeader();
|
||||||
|
|
||||||
header.type = 0;
|
header.type = 0;
|
||||||
header.throttlePacketType = (int)throttlePacketType;
|
header.throttlePacketType = (int)throttlePacketType;
|
||||||
header.numbytes = buff.Length;
|
header.numbytes = buff.Length;
|
||||||
header.agent_id = agentID.UUID;
|
header.agent_id = agentID.UUID;
|
||||||
header.region_port = regionPortList[i];
|
header.region_port = regionPortList[i];
|
||||||
|
|
||||||
//Send
|
//Send
|
||||||
tcpClientList[i].send(header, buff);
|
tcpClientList[i].send(header, buff);
|
||||||
|
|
||||||
PacketPool.Instance.ReturnPacket(packet);
|
PacketPool.Instance.ReturnPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1022,20 +1021,20 @@ presences.Sort();
|
||||||
{
|
{
|
||||||
ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == agentID; });
|
ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == agentID; });
|
||||||
|
|
||||||
if (pre == null)
|
if (pre == null)
|
||||||
{
|
{
|
||||||
m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePacket] ScenePresence is missing... ({0})", agentID.ToString());
|
m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePacket] ScenePresence is missing... ({0})", agentID.ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((ClientView)pre.ControllingClient).PacketProcessingEnabled==true)
|
if (((ClientView)pre.ControllingClient).PacketProcessingEnabled==true)
|
||||||
{
|
{
|
||||||
pre.ControllingClient.OutPacket(packet, throttlePacketType);
|
pre.ControllingClient.OutPacket(packet, throttlePacketType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PacketPool.Instance.ReturnPacket(packet);
|
PacketPool.Instance.ReturnPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,22 +1060,22 @@ presences.Sort();
|
||||||
// packetEnd = buff.Length;
|
// packetEnd = buff.Length;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//m_log.Info("[SPLITSCENE] "+"PacketPool.Instance : {0}", (PacketPool.Instance == null)?"null":"not null");
|
//m_log.Info("[SPLITSCENE] "+"PacketPool.Instance : {0}", (PacketPool.Instance == null)?"null":"not null");
|
||||||
//m_log.Info("[SPLITSCENE] "+"buff length={0}", buff.Length);
|
//m_log.Info("[SPLITSCENE] "+"buff length={0}", buff.Length);
|
||||||
|
|
||||||
packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero);
|
packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero);
|
||||||
|
|
||||||
LocalUpdatePacket(header.region_port, new LLUUID(header.agent_id),
|
LocalUpdatePacket(header.region_port, new LLUUID(header.agent_id),
|
||||||
packet, (ThrottleOutPacketType)header.throttlePacketType);
|
packet, (ThrottleOutPacketType)header.throttlePacketType);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
m_log.Error("[SPLITSCENE] "+e.ToString());
|
m_log.Error("[SPLITSCENE] "+e.ToString());
|
||||||
m_log.Error("[SPLITSCENE] "+e.StackTrace);
|
m_log.Error("[SPLITSCENE] "+e.StackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,29 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Contributors, http://opensimulator.org/
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* * Neither the name of the OpenSim Project nor the
|
* * Neither the name of the OpenSim Project nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* 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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -35,196 +34,197 @@ using System.Text;
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
|
||||||
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
public class AsynchronousClient {
|
public class AsynchronousClient {
|
||||||
private static ManualResetEvent connectDone = new ManualResetEvent(false);
|
private static ManualResetEvent connectDone = new ManualResetEvent(false);
|
||||||
private static ManualResetEvent sendDone = new ManualResetEvent(false);
|
private static ManualResetEvent sendDone = new ManualResetEvent(false);
|
||||||
private static ManualResetEvent receiveDone = new ManualResetEvent(false);
|
private static ManualResetEvent receiveDone = new ManualResetEvent(false);
|
||||||
private static String response = String.Empty;
|
private static String response = String.Empty;
|
||||||
|
|
||||||
public static Socket StartClient(string hostname, int port) {
|
public static Socket StartClient(string hostname, int port) {
|
||||||
try {
|
try {
|
||||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(hostname);
|
IPHostEntry ipHostInfo = Dns.GetHostEntry(hostname);
|
||||||
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
||||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
|
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
|
||||||
|
|
||||||
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
client.BeginConnect( remoteEP, new AsyncCallback(ConnectCallback), client);
|
client.BeginConnect( remoteEP, new AsyncCallback(ConnectCallback), client);
|
||||||
connectDone.WaitOne();
|
connectDone.WaitOne();
|
||||||
/*
|
/*
|
||||||
Send(client,"This is a test<EOF>");
|
Send(client,"This is a test<EOF>");
|
||||||
sendDone.WaitOne();
|
sendDone.WaitOne();
|
||||||
Receive(client);
|
Receive(client);
|
||||||
receiveDone.WaitOne();
|
receiveDone.WaitOne();
|
||||||
client.Shutdown(SocketShutdown.Both);
|
client.Shutdown(SocketShutdown.Both);
|
||||||
client.Close();
|
client.Close();
|
||||||
*/
|
*/
|
||||||
return client;
|
return client;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
throw new Exception("socket error !!");
|
throw new Exception("socket error !!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ConnectCallback(IAsyncResult ar) {
|
private static void ConnectCallback(IAsyncResult ar) {
|
||||||
try {
|
try {
|
||||||
Socket client = (Socket) ar.AsyncState;
|
Socket client = (Socket) ar.AsyncState;
|
||||||
client.EndConnect(ar);
|
client.EndConnect(ar);
|
||||||
Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString());
|
Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString());
|
||||||
connectDone.Set();
|
connectDone.Set();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public static void Receive(Socket client) {
|
public static void Receive(Socket client) {
|
||||||
try {
|
try {
|
||||||
StateObject state = new StateObject();
|
StateObject state = new StateObject();
|
||||||
state.workSocket = client;
|
state.workSocket = client;
|
||||||
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
|
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void ReceiveCallback( IAsyncResult ar ) {
|
|
||||||
try {
|
|
||||||
StateObject state = (StateObject) ar.AsyncState;
|
|
||||||
Socket client = state.workSocket;
|
|
||||||
|
|
||||||
int bytesRead = client.EndReceive(ar);
|
|
||||||
if (bytesRead > 0) {
|
|
||||||
state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));
|
|
||||||
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0, new AsyncCallback(ReceiveCallback), state);
|
|
||||||
} else {
|
|
||||||
if (state.sb.Length > 1) {
|
|
||||||
response = state.sb.ToString();
|
|
||||||
}
|
|
||||||
receiveDone.Set();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Console.WriteLine(e.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public static void Send(Socket client, byte[] byteData) {
|
|
||||||
client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SendCallback(IAsyncResult ar) {
|
|
||||||
try {
|
|
||||||
Socket client = (Socket) ar.AsyncState;
|
|
||||||
int bytesSent = client.EndSend(ar);
|
|
||||||
//Console.WriteLine("Sent {0} bytes to server.", bytesSent);
|
|
||||||
sendDone.Set();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Console.WriteLine(e.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InternalPacketHeader
|
|
||||||
{
|
|
||||||
private byte[] buffer = new byte[32];
|
|
||||||
public int type;
|
|
||||||
public int throttlePacketType;
|
|
||||||
public int numbytes;
|
|
||||||
public Guid agent_id;
|
|
||||||
public int region_port;
|
|
||||||
|
|
||||||
public void FromBytes(byte[] bytes)
|
|
||||||
{
|
|
||||||
int i = 0; // offset
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
|
||||||
this.throttlePacketType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
|
||||||
this.numbytes = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
|
||||||
this.agent_id = new Guid(
|
|
||||||
bytes[i++] | (bytes[i++] << 8) | (bytes[i++] << 16) | bytes[i++] << 24,
|
|
||||||
(short)(bytes[i++] | (bytes[i++] << 8)),
|
|
||||||
(short)(bytes[i++] | (bytes[i++] << 8)),
|
|
||||||
bytes[i++], bytes[i++], bytes[i++], bytes[i++],
|
|
||||||
bytes[i++], bytes[i++], bytes[i++], bytes[i++]);
|
|
||||||
this.region_port = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
|
||||||
{
|
private static void ReceiveCallback( IAsyncResult ar ) {
|
||||||
throw new Exception("bad format!!!");
|
try {
|
||||||
|
StateObject state = (StateObject) ar.AsyncState;
|
||||||
|
Socket client = state.workSocket;
|
||||||
|
|
||||||
|
int bytesRead = client.EndReceive(ar);
|
||||||
|
if (bytesRead > 0) {
|
||||||
|
state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));
|
||||||
|
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0, new AsyncCallback(ReceiveCallback), state);
|
||||||
|
} else {
|
||||||
|
if (state.sb.Length > 1) {
|
||||||
|
response = state.sb.ToString();
|
||||||
|
}
|
||||||
|
receiveDone.Set();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public static void Send(Socket client, byte[] byteData) {
|
||||||
|
client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SendCallback(IAsyncResult ar) {
|
||||||
|
try {
|
||||||
|
Socket client = (Socket) ar.AsyncState;
|
||||||
|
int bytesSent = client.EndSend(ar);
|
||||||
|
//Console.WriteLine("Sent {0} bytes to server.", bytesSent);
|
||||||
|
sendDone.Set();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] ToBytes()
|
public class InternalPacketHeader
|
||||||
{
|
{
|
||||||
int i = 0;
|
private byte[] buffer = new byte[32];
|
||||||
this.buffer[i++] = (byte)(this.type % 256);
|
public int type;
|
||||||
this.buffer[i++] = (byte)((this.type >> 8) % 256);
|
public int throttlePacketType;
|
||||||
this.buffer[i++] = (byte)((this.type >> 16) % 256);
|
public int numbytes;
|
||||||
this.buffer[i++] = (byte)((this.type >> 24) % 256);
|
public Guid agent_id;
|
||||||
|
public int region_port;
|
||||||
|
|
||||||
this.buffer[i++] = (byte)(this.throttlePacketType % 256);
|
public void FromBytes(byte[] bytes)
|
||||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 8) % 256);
|
{
|
||||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 16) % 256);
|
int i = 0; // offset
|
||||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 24) % 256);
|
try
|
||||||
|
{
|
||||||
|
this.type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||||
|
this.throttlePacketType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||||
|
this.numbytes = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||||
|
this.agent_id = new Guid(
|
||||||
|
bytes[i++] | (bytes[i++] << 8) | (bytes[i++] << 16) | bytes[i++] << 24,
|
||||||
|
(short)(bytes[i++] | (bytes[i++] << 8)),
|
||||||
|
(short)(bytes[i++] | (bytes[i++] << 8)),
|
||||||
|
bytes[i++], bytes[i++], bytes[i++], bytes[i++],
|
||||||
|
bytes[i++], bytes[i++], bytes[i++], bytes[i++]);
|
||||||
|
this.region_port = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw new Exception("bad format!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.buffer[i++] = (byte)(this.numbytes % 256);
|
public byte[] ToBytes()
|
||||||
this.buffer[i++] = (byte)((this.numbytes >> 8) % 256);
|
{
|
||||||
this.buffer[i++] = (byte)((this.numbytes >> 16) % 256);
|
int i = 0;
|
||||||
this.buffer[i++] = (byte)((this.numbytes >> 24) % 256);
|
this.buffer[i++] = (byte)(this.type % 256);
|
||||||
|
this.buffer[i++] = (byte)((this.type >> 8) % 256);
|
||||||
|
this.buffer[i++] = (byte)((this.type >> 16) % 256);
|
||||||
|
this.buffer[i++] = (byte)((this.type >> 24) % 256);
|
||||||
|
|
||||||
// no endian care
|
this.buffer[i++] = (byte)(this.throttlePacketType % 256);
|
||||||
Buffer.BlockCopy(agent_id.ToByteArray(), 0, this.buffer, i, 16); i += 16;
|
this.buffer[i++] = (byte)((this.throttlePacketType >> 8) % 256);
|
||||||
|
this.buffer[i++] = (byte)((this.throttlePacketType >> 16) % 256);
|
||||||
|
this.buffer[i++] = (byte)((this.throttlePacketType >> 24) % 256);
|
||||||
|
|
||||||
this.buffer[i++] = (byte)(this.region_port % 256);
|
this.buffer[i++] = (byte)(this.numbytes % 256);
|
||||||
this.buffer[i++] = (byte)((this.region_port >> 8) % 256);
|
this.buffer[i++] = (byte)((this.numbytes >> 8) % 256);
|
||||||
this.buffer[i++] = (byte)((this.region_port >> 16) % 256);
|
this.buffer[i++] = (byte)((this.numbytes >> 16) % 256);
|
||||||
this.buffer[i++] = (byte)((this.region_port >> 24) % 256);
|
this.buffer[i++] = (byte)((this.numbytes >> 24) % 256);
|
||||||
|
|
||||||
return this.buffer;
|
// no endian care
|
||||||
}
|
Buffer.BlockCopy(agent_id.ToByteArray(), 0, this.buffer, i, 16); i += 16;
|
||||||
}
|
|
||||||
public class TcpClient {
|
|
||||||
|
|
||||||
public static int internalPacketHeaderSize = 4*4 + 16*1;
|
this.buffer[i++] = (byte)(this.region_port % 256);
|
||||||
|
this.buffer[i++] = (byte)((this.region_port >> 8) % 256);
|
||||||
|
this.buffer[i++] = (byte)((this.region_port >> 16) % 256);
|
||||||
|
this.buffer[i++] = (byte)((this.region_port >> 24) % 256);
|
||||||
|
|
||||||
private string mHostname;
|
return this.buffer;
|
||||||
private int mPort;
|
}
|
||||||
private Socket mConnection;
|
}
|
||||||
public TcpClient(string hostname, int port) {
|
|
||||||
this.mHostname = hostname;
|
public class TcpClient {
|
||||||
this.mPort = port;
|
|
||||||
this.mConnection = null;
|
public static int internalPacketHeaderSize = 4*4 + 16*1;
|
||||||
}
|
|
||||||
public void connect() {
|
private string mHostname;
|
||||||
this.mConnection = AsynchronousClient.StartClient(mHostname, mPort);
|
private int mPort;
|
||||||
}
|
private Socket mConnection;
|
||||||
|
public TcpClient(string hostname, int port) {
|
||||||
|
this.mHostname = hostname;
|
||||||
|
this.mPort = port;
|
||||||
|
this.mConnection = null;
|
||||||
|
}
|
||||||
|
public void connect() {
|
||||||
|
this.mConnection = AsynchronousClient.StartClient(mHostname, mPort);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
public void recevie() {
|
public void recevie() {
|
||||||
if (mConnection == null) {
|
if (mConnection == null) {
|
||||||
throw new Exception("client not initialized");
|
throw new Exception("client not initialized");
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AsynchronousClient.Receive(this.mConnection);
|
AsynchronousClient.Receive(this.mConnection);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
mConnection = null;
|
mConnection = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
public void send(InternalPacketHeader header, byte[] packet) {
|
public void send(InternalPacketHeader header, byte[] packet) {
|
||||||
|
|
||||||
lock (this)
|
lock (this)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (mConnection == null) {
|
if (mConnection == null) {
|
||||||
// throw new Exception("client not initialized");
|
// throw new Exception("client not initialized");
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
AsynchronousClient.Send(this.mConnection, header.ToBytes());
|
AsynchronousClient.Send(this.mConnection, header.ToBytes());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
|
@ -233,8 +233,8 @@ for (int i = 0; i < 10; i++)
|
||||||
}
|
}
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
*/
|
*/
|
||||||
AsynchronousClient.Send(this.mConnection, packet);
|
AsynchronousClient.Send(this.mConnection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,29 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Contributors, http://opensimulator.org/
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* * Neither the name of the OpenSim Project nor the
|
* * Neither the name of the OpenSim Project nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* 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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -38,182 +37,180 @@ using OpenSim.Framework.Console;
|
||||||
|
|
||||||
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
|
|
||||||
public class StateObject {
|
public class StateObject {
|
||||||
public Socket workSocket = null;
|
public Socket workSocket = null;
|
||||||
public const int BufferSize = 2048;
|
public const int BufferSize = 2048;
|
||||||
public byte[] buffer = new byte[BufferSize];
|
public byte[] buffer = new byte[BufferSize];
|
||||||
public MemoryStream ms_ptr = new MemoryStream();
|
public MemoryStream ms_ptr = new MemoryStream();
|
||||||
public InternalPacketHeader header = null;
|
public InternalPacketHeader header = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AsynchronousSocketListener {
|
public class AsynchronousSocketListener {
|
||||||
public static string data = null;
|
public static string data = null;
|
||||||
public static ManualResetEvent allDone = new ManualResetEvent(false);
|
public static ManualResetEvent allDone = new ManualResetEvent(false);
|
||||||
|
|
||||||
#region KIRYU
|
#region KIRYU
|
||||||
public delegate void PacketRecieveHandler(InternalPacketHeader header, byte[] buff);
|
public delegate void PacketRecieveHandler(InternalPacketHeader header, byte[] buff);
|
||||||
public static PacketRecieveHandler PacketHandler = null;
|
public static PacketRecieveHandler PacketHandler = null;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public AsynchronousSocketListener() { }
|
public AsynchronousSocketListener() { }
|
||||||
|
|
||||||
public static void StartListening(int port) {
|
public static void StartListening(int port) {
|
||||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
|
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
|
||||||
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
||||||
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
|
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
|
||||||
|
|
||||||
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
|
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
|
||||||
try {
|
try {
|
||||||
listener.Bind(localEndPoint);
|
listener.Bind(localEndPoint);
|
||||||
listener.Listen(100);
|
listener.Listen(100);
|
||||||
while (true) {
|
while (true) {
|
||||||
allDone.Reset();
|
allDone.Reset();
|
||||||
listener.BeginAccept( new AsyncCallback(AcceptCallback), listener );
|
listener.BeginAccept( new AsyncCallback(AcceptCallback), listener );
|
||||||
allDone.WaitOne();
|
allDone.WaitOne();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Console.WriteLine("\nPress ENTER to continue...");
|
Console.WriteLine("\nPress ENTER to continue...");
|
||||||
Console.Read();
|
Console.Read();
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AcceptCallback(IAsyncResult ar) {
|
public static void AcceptCallback(IAsyncResult ar) {
|
||||||
allDone.Set();
|
allDone.Set();
|
||||||
Socket listener = (Socket) ar.AsyncState;
|
Socket listener = (Socket) ar.AsyncState;
|
||||||
Socket handler = listener.EndAccept(ar);
|
Socket handler = listener.EndAccept(ar);
|
||||||
StateObject state = new StateObject();
|
StateObject state = new StateObject();
|
||||||
state.workSocket = handler;
|
state.workSocket = handler;
|
||||||
handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ReadCallback(IAsyncResult ar) {
|
public static void ReadCallback(IAsyncResult ar) {
|
||||||
String content = String.Empty;
|
String content = String.Empty;
|
||||||
StateObject state = (StateObject) ar.AsyncState;
|
StateObject state = (StateObject) ar.AsyncState;
|
||||||
Socket handler = state.workSocket;
|
Socket handler = state.workSocket;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
int bytesRead = handler.EndReceive(ar);
|
||||||
int bytesRead = handler.EndReceive(ar);
|
|
||||||
|
//MainLog.Instance.Verbose("TCPSERVER", "Received packet [{0}]", bytesRead);
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", "Received packet [{0}]", bytesRead);
|
|
||||||
|
|
||||||
if (bytesRead > 0) {
|
|
||||||
state.ms_ptr.Write(state.buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", "Connection terminated");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
long rest_size = state.ms_ptr.Length;
|
if (bytesRead > 0) {
|
||||||
long current_pos = 0;
|
state.ms_ptr.Write(state.buffer, 0, bytesRead);
|
||||||
while (rest_size > TcpClient.internalPacketHeaderSize) {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//MainLog.Instance.Verbose("TCPSERVER", "Connection terminated");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((state.header == null) && (rest_size >= TcpClient.internalPacketHeaderSize))
|
long rest_size = state.ms_ptr.Length;
|
||||||
{
|
long current_pos = 0;
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", "Processing header");
|
while (rest_size > TcpClient.internalPacketHeaderSize) {
|
||||||
|
|
||||||
// reading header
|
if ((state.header == null) && (rest_size >= TcpClient.internalPacketHeaderSize))
|
||||||
state.header = new InternalPacketHeader();
|
{
|
||||||
|
//MainLog.Instance.Verbose("TCPSERVER", "Processing header");
|
||||||
|
|
||||||
byte[] headerbytes = new byte[TcpClient.internalPacketHeaderSize];
|
// reading header
|
||||||
state.ms_ptr.Position = current_pos;
|
state.header = new InternalPacketHeader();
|
||||||
state.ms_ptr.Read(headerbytes, 0, TcpClient.internalPacketHeaderSize);
|
|
||||||
state.ms_ptr.Seek(0, SeekOrigin.End);
|
|
||||||
state.header.FromBytes(headerbytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((state.header != null) && (rest_size >= state.header.numbytes + TcpClient.internalPacketHeaderSize))
|
byte[] headerbytes = new byte[TcpClient.internalPacketHeaderSize];
|
||||||
{
|
state.ms_ptr.Position = current_pos;
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", "Processing body");
|
state.ms_ptr.Read(headerbytes, 0, TcpClient.internalPacketHeaderSize);
|
||||||
|
state.ms_ptr.Seek(0, SeekOrigin.End);
|
||||||
|
state.header.FromBytes(headerbytes);
|
||||||
|
}
|
||||||
|
|
||||||
// reading body
|
if ((state.header != null) && (rest_size >= state.header.numbytes + TcpClient.internalPacketHeaderSize))
|
||||||
byte[] packet = new byte[state.header.numbytes];
|
{
|
||||||
state.ms_ptr.Position = current_pos + TcpClient.internalPacketHeaderSize;
|
//MainLog.Instance.Verbose("TCPSERVER", "Processing body");
|
||||||
state.ms_ptr.Read(packet, 0, state.header.numbytes);
|
|
||||||
|
// reading body
|
||||||
|
byte[] packet = new byte[state.header.numbytes];
|
||||||
|
state.ms_ptr.Position = current_pos + TcpClient.internalPacketHeaderSize;
|
||||||
|
state.ms_ptr.Read(packet, 0, state.header.numbytes);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for(int i=0; i<state.header.numbytes; i++) {
|
for(int i=0; i<state.header.numbytes; i++) {
|
||||||
System.Console.Write(packet[i] + " ");
|
System.Console.Write(packet[i] + " ");
|
||||||
}
|
}
|
||||||
System.Console.WriteLine();
|
System.Console.WriteLine();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
state.ms_ptr.Seek(0, SeekOrigin.End);
|
state.ms_ptr.Seek(0, SeekOrigin.End);
|
||||||
// call loadbarancer function
|
// call loadbarancer function
|
||||||
if (PacketHandler != null)
|
if (PacketHandler != null)
|
||||||
{
|
{
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", "calling PacketHandler");
|
//MainLog.Instance.Verbose("TCPSERVER", "calling PacketHandler");
|
||||||
PacketHandler(state.header, packet);
|
PacketHandler(state.header, packet);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", "PacketHandler not found");
|
//MainLog.Instance.Verbose("TCPSERVER", "PacketHandler not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_size = state.header.numbytes + TcpClient.internalPacketHeaderSize;
|
int read_size = state.header.numbytes + TcpClient.internalPacketHeaderSize;
|
||||||
state.header = null;
|
state.header = null;
|
||||||
|
|
||||||
rest_size -= read_size;
|
rest_size -= read_size;
|
||||||
current_pos += read_size;
|
current_pos += read_size;
|
||||||
|
|
||||||
if (rest_size < TcpClient.internalPacketHeaderSize) {
|
if (rest_size < TcpClient.internalPacketHeaderSize) {
|
||||||
|
|
||||||
byte[] rest_bytes = new byte[rest_size];
|
byte[] rest_bytes = new byte[rest_size];
|
||||||
state.ms_ptr.Position = read_size;
|
state.ms_ptr.Position = read_size;
|
||||||
state.ms_ptr.Read(rest_bytes, 0, (int)rest_size);
|
state.ms_ptr.Read(rest_bytes, 0, (int)rest_size);
|
||||||
state.ms_ptr.Close();
|
state.ms_ptr.Close();
|
||||||
state.ms_ptr = new MemoryStream();
|
state.ms_ptr = new MemoryStream();
|
||||||
state.ms_ptr.Write(rest_bytes, 0, (int)rest_size);
|
state.ms_ptr.Write(rest_bytes, 0, (int)rest_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // while (true)
|
} // while (true)
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", e.ToString());
|
//MainLog.Instance.Verbose("TCPSERVER", e.ToString());
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", e.StackTrace);
|
//MainLog.Instance.Verbose("TCPSERVER", e.StackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Send(Socket handler, String data) {
|
private static void Send(Socket handler, String data) {
|
||||||
byte[] byteData = Encoding.ASCII.GetBytes(data);
|
byte[] byteData = Encoding.ASCII.GetBytes(data);
|
||||||
handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
|
handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendCallback(IAsyncResult ar) {
|
private static void SendCallback(IAsyncResult ar) {
|
||||||
try {
|
try {
|
||||||
Socket handler = (Socket) ar.AsyncState;
|
Socket handler = (Socket) ar.AsyncState;
|
||||||
int bytesSent = handler.EndSend(ar);
|
int bytesSent = handler.EndSend(ar);
|
||||||
//Console.WriteLine("Sent {0} bytes to client.", bytesSent);
|
//Console.WriteLine("Sent {0} bytes to client.", bytesSent);
|
||||||
handler.Shutdown(SocketShutdown.Both);
|
handler.Shutdown(SocketShutdown.Both);
|
||||||
handler.Close();
|
handler.Close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TcpServer {
|
public class TcpServer {
|
||||||
private int mPort = 11000;
|
private int mPort = 11000;
|
||||||
public TcpServer() {
|
public TcpServer() {
|
||||||
}
|
}
|
||||||
public TcpServer(int port) {
|
public TcpServer(int port) {
|
||||||
mPort = port;
|
mPort = port;
|
||||||
}
|
}
|
||||||
public void start() {
|
public void start() {
|
||||||
AsynchronousSocketListener.StartListening(mPort);
|
AsynchronousSocketListener.StartListening(mPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace OpenSim.ApplicationPlugins.RegionMonitor
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
// start monitor thread (remoting module)
|
// start monitor thread (remoting module)
|
||||||
m_mointorThread = new Thread(new ThreadStart(StartMonitor));
|
m_mointorThread = new Thread(new ThreadStart(StartMonitor));
|
||||||
|
|
|
@ -1,30 +1,29 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Contributors, http://opensimulator.org/
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* * Neither the name of the OpenSim Project nor the
|
* * Neither the name of the OpenSim Project nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* 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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -255,7 +254,7 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
public EndPoint clientEP;
|
public EndPoint clientEP;
|
||||||
public EndPoint senderEP;
|
public EndPoint senderEP;
|
||||||
public IPEndPoint serverIP;
|
public IPEndPoint serverIP;
|
||||||
public byte[] recvBuffer = new byte[4096];
|
public byte[] recvBuffer = new byte[4096];
|
||||||
|
|
||||||
public ServerData()
|
public ServerData()
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,12 +84,12 @@
|
||||||
<Project name="OpenSim.Tests.Common" path="OpenSim/Tests/Common" type="Library">
|
<Project name="OpenSim.Tests.Common" path="OpenSim/Tests/Common" type="Library">
|
||||||
<Configuration name="Debug">
|
<Configuration name="Debug">
|
||||||
<Options>
|
<Options>
|
||||||
<OutputPath>../../../bin/</OutputPath>
|
<OutputPath>../../../bin/</OutputPath>
|
||||||
</Options>
|
</Options>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
<Configuration name="Release">
|
<Configuration name="Release">
|
||||||
<Options>
|
<Options>
|
||||||
<OutputPath>../../../bin/</OutputPath>
|
<OutputPath>../../../bin/</OutputPath>
|
||||||
</Options>
|
</Options>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
|
|
||||||
|
@ -107,12 +107,12 @@
|
||||||
<Project name="OpenSim.Framework.Tests" path="OpenSim/Tests/OpenSim/Framework" type="Library">
|
<Project name="OpenSim.Framework.Tests" path="OpenSim/Tests/OpenSim/Framework" type="Library">
|
||||||
<Configuration name="Debug">
|
<Configuration name="Debug">
|
||||||
<Options>
|
<Options>
|
||||||
<OutputPath>../../../../bin/</OutputPath>
|
<OutputPath>../../../../bin/</OutputPath>
|
||||||
</Options>
|
</Options>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
<Configuration name="Release">
|
<Configuration name="Release">
|
||||||
<Options>
|
<Options>
|
||||||
<OutputPath>../../../../bin/</OutputPath>
|
<OutputPath>../../../../bin/</OutputPath>
|
||||||
</Options>
|
</Options>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ def binary_or_text(file):
|
||||||
|
|
||||||
property_map = {
|
property_map = {
|
||||||
".bat" : script,
|
".bat" : script,
|
||||||
|
".cgi" : textfile,
|
||||||
".config" : textfile,
|
".config" : textfile,
|
||||||
".cs" : textfile,
|
".cs" : textfile,
|
||||||
".csproj" : textfile,
|
".csproj" : textfile,
|
||||||
|
@ -64,6 +65,7 @@ property_map = {
|
||||||
".php" : script,
|
".php" : script,
|
||||||
".pidb" : binary,
|
".pidb" : binary,
|
||||||
".pl" : script,
|
".pl" : script,
|
||||||
|
".pm" : textfile,
|
||||||
".png" : binary,
|
".png" : binary,
|
||||||
".py" : script,
|
".py" : script,
|
||||||
".rb" : script,
|
".rb" : script,
|
||||||
|
|
Loading…
Reference in New Issue