* Little more spring cleaning.
parent
375163a6fe
commit
de2ff8e626
|
@ -43,6 +43,8 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
|
|||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
#region IApplicationPlugin Members
|
||||
|
||||
public void Initialise(OpenSimMain openSim)
|
||||
{
|
||||
m_log.Info("[LOADREGIONS]: Load Regions addin being initialised");
|
||||
|
@ -66,7 +68,8 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
|
|||
|
||||
for (int i = 0; i < regionsToLoad.Length; i++)
|
||||
{
|
||||
m_log.Debug("[LOADREGIONS]: Creating Region: " + regionsToLoad[i].RegionName + " (ThreadID: " + Thread.CurrentThread.ManagedThreadId.ToString() + ")");
|
||||
m_log.Debug("[LOADREGIONS]: Creating Region: " + regionsToLoad[i].RegionName + " (ThreadID: " + Thread.CurrentThread.ManagedThreadId.ToString() +
|
||||
")");
|
||||
openSim.CreateRegion(regionsToLoad[i], true);
|
||||
}
|
||||
|
||||
|
@ -74,6 +77,12 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
|
|||
openSim.ModuleLoader.ClearCache();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void LoadRegionFromConfig(OpenSimMain openSim, ulong regionhandle)
|
||||
{
|
||||
m_log.Info("[LOADREGIONS]: Load Regions addin being initialised");
|
||||
|
@ -96,14 +105,11 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
|
|||
{
|
||||
if (regionhandle == regionsToLoad[i].RegionHandle)
|
||||
{
|
||||
m_log.Debug("[LOADREGIONS]: Creating Region: " + regionsToLoad[i].RegionName + " (ThreadID: " + Thread.CurrentThread.ManagedThreadId.ToString() + ")");
|
||||
m_log.Debug("[LOADREGIONS]: Creating Region: " + regionsToLoad[i].RegionName + " (ThreadID: " +
|
||||
Thread.CurrentThread.ManagedThreadId.ToString() + ")");
|
||||
openSim.CreateRegion(regionsToLoad[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,18 +53,24 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private OpenSimMain simMain;
|
||||
private BaseHttpServer commandServer;
|
||||
|
||||
private List<UDPServer> udpServers;
|
||||
private List<RegionInfo> regionData;
|
||||
private bool[] isLocalNeighbour;
|
||||
private bool isSplit = false;
|
||||
private TcpServer mTcpServer;
|
||||
private object padlock = new object();
|
||||
|
||||
private int proxyOffset;
|
||||
private string proxyURL;
|
||||
private List<RegionInfo> regionData;
|
||||
private int[] regionPortList;
|
||||
private SceneManager sceneManager;
|
||||
private string[] sceneURL;
|
||||
private string serializeDir;
|
||||
private OpenSimMain simMain;
|
||||
private TcpClient[] tcpClientList;
|
||||
private List<UDPServer> udpServers;
|
||||
|
||||
private TcpServer mTcpServer;
|
||||
#region IApplicationPlugin Members
|
||||
|
||||
public void Initialise(OpenSimMain openSim)
|
||||
{
|
||||
|
@ -77,11 +83,11 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
ClientView.SynchronizeClient = new ClientView.SynchronizeClientHandler(SynchronizePackets);
|
||||
AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve);
|
||||
|
||||
this.sceneManager = openSim.SceneManager;
|
||||
this.udpServers = openSim.UdpServers;
|
||||
this.regionData = openSim.RegionData;
|
||||
this.simMain = openSim;
|
||||
this.commandServer = openSim.HttpServer;
|
||||
sceneManager = openSim.SceneManager;
|
||||
udpServers = openSim.UdpServers;
|
||||
regionData = openSim.RegionData;
|
||||
simMain = openSim;
|
||||
commandServer = openSim.HttpServer;
|
||||
|
||||
proxyOffset = Int32.Parse(openSim.ConfigSource.Configs["Network"].GetString("proxy_offset", "0"));
|
||||
serializeDir = openSim.ConfigSource.Configs["Network"].GetString("serialize_dir", "/tmp/");
|
||||
|
@ -99,20 +105,23 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
m_log.Info("[BALANCER] " + "Exiting Initialize()");
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void StartTcpServer()
|
||||
{
|
||||
Thread server_thread = new Thread(new ThreadStart(
|
||||
delegate {
|
||||
delegate
|
||||
{
|
||||
mTcpServer = new TcpServer(10001);
|
||||
mTcpServer.start();
|
||||
}));
|
||||
server_thread.Start();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
private XmlRpcResponse GetStatus(XmlRpcRequest request)
|
||||
{
|
||||
XmlRpcResponse response = new XmlRpcResponse();
|
||||
|
@ -137,7 +146,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
{
|
||||
ClientView client = (ClientView) pre.ControllingClient;
|
||||
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
||||
if(client.PacketProcessingEnabled==true) {
|
||||
if (client.PacketProcessingEnabled == true)
|
||||
{
|
||||
get_scene_presence_filter++;
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +159,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
{
|
||||
ClientView client = (ClientView) pre.ControllingClient;
|
||||
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
||||
if(client.PacketProcessingEnabled==true) {
|
||||
if (client.PacketProcessingEnabled == true)
|
||||
{
|
||||
get_avatar_filter++;
|
||||
avatar_names += pre.Firstname + " " + pre.Lastname + "; ";
|
||||
}
|
||||
|
@ -664,12 +675,6 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
* This section implements scene splitting and synchronization
|
||||
*/
|
||||
|
||||
private bool[] isLocalNeighbour;
|
||||
private string[] sceneURL;
|
||||
private int[] regionPortList;
|
||||
private TcpClient[] tcpClientList;
|
||||
private bool isSplit = false;
|
||||
|
||||
private XmlRpcResponse SplitRegion(XmlRpcRequest request)
|
||||
{
|
||||
try
|
||||
|
@ -708,7 +713,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
||||
{
|
||||
// Disable event updates, backups etc in the slave(s)
|
||||
if (isMaster) {
|
||||
if (isMaster)
|
||||
{
|
||||
scene.Region_Status = RegionStatus.Up;
|
||||
}
|
||||
else
|
||||
|
@ -868,7 +874,6 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
}
|
||||
}
|
||||
|
||||
object padlock=new object();
|
||||
private void SynchronizeScenes(Scene scene)
|
||||
{
|
||||
if (!isSplit)
|
||||
|
|
|
@ -30,13 +30,17 @@ using System.Net;
|
|||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||
public class AsynchronousClient {
|
||||
namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||
{
|
||||
public class AsynchronousClient
|
||||
{
|
||||
private static ManualResetEvent connectDone = new ManualResetEvent(false);
|
||||
private static ManualResetEvent sendDone = new ManualResetEvent(false);
|
||||
|
||||
public static Socket StartClient(string hostname, int port) {
|
||||
try {
|
||||
public static Socket StartClient(string hostname, int port)
|
||||
{
|
||||
try
|
||||
{
|
||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(hostname);
|
||||
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
|
||||
|
@ -53,19 +57,25 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
client.Close();
|
||||
*/
|
||||
return client;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
throw new Exception("socket error !!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConnectCallback(IAsyncResult ar) {
|
||||
try {
|
||||
private static void ConnectCallback(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
Socket client = (Socket) ar.AsyncState;
|
||||
client.EndConnect(ar);
|
||||
Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString());
|
||||
connectDone.Set();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
@ -101,12 +111,16 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
}
|
||||
}
|
||||
*/
|
||||
public static void Send(Socket client, byte[] byteData) {
|
||||
|
||||
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 {
|
||||
private static void SendCallback(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
Socket client = (Socket) ar.AsyncState;
|
||||
int bytesSent = client.EndSend(ar);
|
||||
if (bytesSent > 0)
|
||||
|
@ -114,7 +128,9 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
//Console.WriteLine("Sent {0} bytes to server.", bytesSent);
|
||||
}
|
||||
sendDone.Set();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
@ -122,28 +138,28 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
|
||||
public class InternalPacketHeader
|
||||
{
|
||||
private byte[] buffer = new byte[32];
|
||||
public int type;
|
||||
public int throttlePacketType;
|
||||
public int numbytes;
|
||||
public Guid agent_id;
|
||||
private byte[] buffer = new byte[32];
|
||||
public int numbytes;
|
||||
public int region_port;
|
||||
public int throttlePacketType;
|
||||
public int type;
|
||||
|
||||
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(
|
||||
type = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
throttlePacketType = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
numbytes = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
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));
|
||||
region_port = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -154,48 +170,54 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
public byte[] ToBytes()
|
||||
{
|
||||
int i = 0;
|
||||
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);
|
||||
buffer[i++] = (byte) (type % 256);
|
||||
buffer[i++] = (byte) ((type >> 8) % 256);
|
||||
buffer[i++] = (byte) ((type >> 16) % 256);
|
||||
buffer[i++] = (byte) ((type >> 24) % 256);
|
||||
|
||||
this.buffer[i++] = (byte)(this.throttlePacketType % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 24) % 256);
|
||||
buffer[i++] = (byte) (throttlePacketType % 256);
|
||||
buffer[i++] = (byte) ((throttlePacketType >> 8) % 256);
|
||||
buffer[i++] = (byte) ((throttlePacketType >> 16) % 256);
|
||||
buffer[i++] = (byte) ((throttlePacketType >> 24) % 256);
|
||||
|
||||
this.buffer[i++] = (byte)(this.numbytes % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 24) % 256);
|
||||
buffer[i++] = (byte) (numbytes % 256);
|
||||
buffer[i++] = (byte) ((numbytes >> 8) % 256);
|
||||
buffer[i++] = (byte) ((numbytes >> 16) % 256);
|
||||
buffer[i++] = (byte) ((numbytes >> 24) % 256);
|
||||
|
||||
// no endian care
|
||||
Buffer.BlockCopy(agent_id.ToByteArray(), 0, this.buffer, i, 16); i += 16;
|
||||
Buffer.BlockCopy(agent_id.ToByteArray(), 0, buffer, i, 16);
|
||||
i += 16;
|
||||
|
||||
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);
|
||||
buffer[i++] = (byte) (region_port % 256);
|
||||
buffer[i++] = (byte) ((region_port >> 8) % 256);
|
||||
buffer[i++] = (byte) ((region_port >> 16) % 256);
|
||||
buffer[i++] = (byte) ((region_port >> 24) % 256);
|
||||
|
||||
return this.buffer;
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
public class TcpClient {
|
||||
|
||||
public class TcpClient
|
||||
{
|
||||
public static int internalPacketHeaderSize = 4 * 4 + 16 * 1;
|
||||
private Socket mConnection;
|
||||
|
||||
private string mHostname;
|
||||
private int mPort;
|
||||
private Socket mConnection;
|
||||
public TcpClient(string hostname, int port) {
|
||||
this.mHostname = hostname;
|
||||
this.mPort = port;
|
||||
this.mConnection = null;
|
||||
|
||||
public TcpClient(string hostname, int port)
|
||||
{
|
||||
mHostname = hostname;
|
||||
mPort = port;
|
||||
mConnection = null;
|
||||
}
|
||||
public void connect() {
|
||||
this.mConnection = AsynchronousClient.StartClient(mHostname, mPort);
|
||||
|
||||
public void connect()
|
||||
{
|
||||
mConnection = AsynchronousClient.StartClient(mHostname, mPort);
|
||||
}
|
||||
|
||||
/*
|
||||
public void recevie() {
|
||||
if (mConnection == null) {
|
||||
|
@ -212,17 +234,18 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
}
|
||||
}
|
||||
*/
|
||||
public void send(InternalPacketHeader header, byte[] packet) {
|
||||
|
||||
public void send(InternalPacketHeader header, byte[] packet)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
|
||||
if (mConnection == null) {
|
||||
if (mConnection == null)
|
||||
{
|
||||
// throw new Exception("client not initialized");
|
||||
connect();
|
||||
}
|
||||
|
||||
AsynchronousClient.Send(this.mConnection, header.ToBytes());
|
||||
AsynchronousClient.Send(mConnection, header.ToBytes());
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 10; i++)
|
||||
|
@ -231,7 +254,7 @@ for (int i = 0; i < 10; i++)
|
|||
}
|
||||
Console.WriteLine("");
|
||||
*/
|
||||
AsynchronousClient.Send(this.mConnection, packet);
|
||||
AsynchronousClient.Send(mConnection, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,42 +31,58 @@ using System.Net;
|
|||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||
|
||||
public class StateObject {
|
||||
public Socket workSocket = null;
|
||||
namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||
{
|
||||
public class StateObject
|
||||
{
|
||||
public const int BufferSize = 2048;
|
||||
public byte[] buffer = new byte[BufferSize];
|
||||
public MemoryStream ms_ptr = new MemoryStream();
|
||||
public InternalPacketHeader header = null;
|
||||
public MemoryStream ms_ptr = new MemoryStream();
|
||||
public Socket workSocket = null;
|
||||
}
|
||||
|
||||
public class AsynchronousSocketListener {
|
||||
public static string data = null;
|
||||
public class AsynchronousSocketListener
|
||||
{
|
||||
public static ManualResetEvent allDone = new ManualResetEvent(false);
|
||||
public static string data = null;
|
||||
|
||||
#region KIRYU
|
||||
|
||||
#region Delegates
|
||||
|
||||
public delegate void PacketRecieveHandler(InternalPacketHeader header, byte[] buff);
|
||||
public static PacketRecieveHandler PacketHandler = null;
|
||||
|
||||
#endregion
|
||||
|
||||
public AsynchronousSocketListener() { }
|
||||
public static PacketRecieveHandler PacketHandler = null;
|
||||
|
||||
public static void StartListening(int port) {
|
||||
#endregion
|
||||
|
||||
public AsynchronousSocketListener()
|
||||
{
|
||||
}
|
||||
|
||||
public static void StartListening(int port)
|
||||
{
|
||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
|
||||
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
||||
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
|
||||
|
||||
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
try {
|
||||
try
|
||||
{
|
||||
listener.Bind(localEndPoint);
|
||||
listener.Listen(100);
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
allDone.Reset();
|
||||
listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
|
||||
allDone.WaitOne();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
/*
|
||||
|
@ -75,7 +91,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
*/
|
||||
}
|
||||
|
||||
public static void AcceptCallback(IAsyncResult ar) {
|
||||
public static void AcceptCallback(IAsyncResult ar)
|
||||
{
|
||||
allDone.Set();
|
||||
Socket listener = (Socket) ar.AsyncState;
|
||||
Socket handler = listener.EndAccept(ar);
|
||||
|
@ -84,7 +101,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
||||
}
|
||||
|
||||
public static void ReadCallback(IAsyncResult ar) {
|
||||
public static void ReadCallback(IAsyncResult ar)
|
||||
{
|
||||
StateObject state = (StateObject) ar.AsyncState;
|
||||
Socket handler = state.workSocket;
|
||||
|
||||
|
@ -94,7 +112,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Received packet [{0}]", bytesRead);
|
||||
|
||||
if (bytesRead > 0) {
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
state.ms_ptr.Write(state.buffer, 0, bytesRead);
|
||||
}
|
||||
else
|
||||
|
@ -105,8 +124,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
|
||||
long rest_size = state.ms_ptr.Length;
|
||||
long current_pos = 0;
|
||||
while (rest_size > TcpClient.internalPacketHeaderSize) {
|
||||
|
||||
while (rest_size > TcpClient.internalPacketHeaderSize)
|
||||
{
|
||||
if ((state.header == null) && (rest_size >= TcpClient.internalPacketHeaderSize))
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Processing header");
|
||||
|
@ -155,8 +174,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
rest_size -= read_size;
|
||||
current_pos += read_size;
|
||||
|
||||
if (rest_size < TcpClient.internalPacketHeaderSize) {
|
||||
|
||||
if (rest_size < TcpClient.internalPacketHeaderSize)
|
||||
{
|
||||
byte[] rest_bytes = new byte[rest_size];
|
||||
state.ms_ptr.Position = read_size;
|
||||
state.ms_ptr.Read(rest_bytes, 0, (int) rest_size);
|
||||
|
@ -166,9 +185,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // while (true)
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -180,14 +197,21 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
|||
}
|
||||
}
|
||||
|
||||
public class TcpServer {
|
||||
public class TcpServer
|
||||
{
|
||||
private int mPort = 11000;
|
||||
public TcpServer() {
|
||||
|
||||
public TcpServer()
|
||||
{
|
||||
}
|
||||
public TcpServer(int port) {
|
||||
|
||||
public TcpServer(int port)
|
||||
{
|
||||
mPort = port;
|
||||
}
|
||||
public void start() {
|
||||
|
||||
public void start()
|
||||
{
|
||||
AsynchronousSocketListener.StartListening(mPort);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,9 +63,11 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
[Extension("/OpenSim/Startup")]
|
||||
public class RegionProxyPlugin : IApplicationPlugin
|
||||
{
|
||||
private ProxyServer proxy;
|
||||
private BaseHttpServer command_server;
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private BaseHttpServer command_server;
|
||||
private ProxyServer proxy;
|
||||
|
||||
#region IApplicationPlugin Members
|
||||
|
||||
public void Initialise(OpenSimMain openSim)
|
||||
{
|
||||
|
@ -91,6 +93,8 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private XmlRpcResponse Stop(XmlRpcRequest request)
|
||||
{
|
||||
try
|
||||
|
@ -107,12 +111,15 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
|
||||
private XmlRpcResponse AddPort(XmlRpcRequest request)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
int clientPort = (int) request.Params[0];
|
||||
int regionPort = (int) request.Params[1];
|
||||
string regionUrl = (string) request.Params[2];
|
||||
proxy.AddPort(clientPort, regionPort, regionUrl);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[PROXY]" + e.Message);
|
||||
m_log.Error("[PROXY]" + e.StackTrace);
|
||||
}
|
||||
|
@ -121,13 +128,16 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
|
||||
private XmlRpcResponse AddRegion(XmlRpcRequest request)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
int currentRegionPort = (int) request.Params[0];
|
||||
string currentRegionUrl = (string) request.Params[1];
|
||||
int newRegionPort = (int) request.Params[2];
|
||||
string newRegionUrl = (string) request.Params[3];
|
||||
proxy.AddRegion(currentRegionPort, currentRegionUrl, newRegionPort, newRegionUrl);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[PROXY]" + e.Message);
|
||||
m_log.Error("[PROXY]" + e.StackTrace);
|
||||
}
|
||||
|
@ -136,13 +146,16 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
|
||||
private XmlRpcResponse ChangeRegion(XmlRpcRequest request)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
int currentRegionPort = (int) request.Params[0];
|
||||
string currentRegionUrl = (string) request.Params[1];
|
||||
int newRegionPort = (int) request.Params[2];
|
||||
string newRegionUrl = (string) request.Params[3];
|
||||
proxy.ChangeRegion(currentRegionPort, currentRegionUrl, newRegionPort, newRegionUrl);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[PROXY]" + e.Message);
|
||||
m_log.Error("[PROXY]" + e.StackTrace);
|
||||
}
|
||||
|
@ -151,11 +164,14 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
|
||||
private XmlRpcResponse DeleteRegion(XmlRpcRequest request)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
int currentRegionPort = (int) request.Params[0];
|
||||
string currentRegionUrl = (string) request.Params[1];
|
||||
proxy.DeleteRegion(currentRegionPort, currentRegionUrl);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[PROXY]" + e.Message);
|
||||
m_log.Error("[PROXY]" + e.StackTrace);
|
||||
}
|
||||
|
@ -164,11 +180,14 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
|
||||
private XmlRpcResponse BlockClientMessages(XmlRpcRequest request)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
string regionUrl = (string) request.Params[0];
|
||||
int regionPort = (int) request.Params[1];
|
||||
proxy.BlockClientMessages(regionUrl, regionPort);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[PROXY]" + e.Message);
|
||||
m_log.Error("[PROXY]" + e.StackTrace);
|
||||
}
|
||||
|
@ -177,11 +196,14 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
|
||||
private XmlRpcResponse UnblockClientMessages(XmlRpcRequest request)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
string regionUrl = (string) request.Params[0];
|
||||
int regionPort = (int) request.Params[1];
|
||||
proxy.UnblockClientMessages(regionUrl, regionPort);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[PROXY]" + e.Message);
|
||||
m_log.Error("[PROXY]" + e.StackTrace);
|
||||
}
|
||||
|
@ -190,89 +212,13 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
}
|
||||
|
||||
|
||||
public class ProxyServer {
|
||||
protected AsyncCallback receivedData;
|
||||
protected ProxyMap proxy_map = new ProxyMap();
|
||||
public class ProxyServer
|
||||
{
|
||||
protected readonly ILog m_log;
|
||||
protected ProxyMap proxy_map = new ProxyMap();
|
||||
protected AsyncCallback receivedData;
|
||||
protected bool running;
|
||||
|
||||
protected class ProxyMap
|
||||
{
|
||||
public class RegionData
|
||||
{
|
||||
public bool isBlocked = false;
|
||||
public Queue storedMessages = new Queue();
|
||||
public List<EndPoint> regions = new List<EndPoint>();
|
||||
}
|
||||
|
||||
private Dictionary<EndPoint, RegionData> map;
|
||||
|
||||
public ProxyMap() {
|
||||
map = new Dictionary<EndPoint, RegionData>();
|
||||
}
|
||||
|
||||
public void Add(EndPoint client, EndPoint region)
|
||||
{
|
||||
if(map.ContainsKey(client))
|
||||
{
|
||||
map[client].regions.Add(region);
|
||||
}
|
||||
else
|
||||
{
|
||||
RegionData regions = new RegionData();
|
||||
map.Add(client, regions);
|
||||
regions.regions.Add(region);
|
||||
}
|
||||
}
|
||||
|
||||
public RegionData GetRegionData(EndPoint client)
|
||||
{
|
||||
return map[client];
|
||||
}
|
||||
|
||||
public EndPoint GetClient(EndPoint region)
|
||||
{
|
||||
foreach (KeyValuePair<EndPoint, RegionData> pair in map)
|
||||
{
|
||||
if(pair.Value.regions.Contains(region))
|
||||
{
|
||||
return pair.Key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected class ServerData {
|
||||
public Socket server;
|
||||
public EndPoint clientEP;
|
||||
public EndPoint senderEP;
|
||||
public IPEndPoint serverIP;
|
||||
public byte[] recvBuffer = new byte[4096];
|
||||
|
||||
public ServerData()
|
||||
{
|
||||
server = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected class StoredMessage
|
||||
{
|
||||
public byte[] buffer;
|
||||
public int length;
|
||||
public EndPoint senderEP;
|
||||
public ServerData sd;
|
||||
|
||||
public StoredMessage(byte[] buffer, int length, int maxLength, EndPoint senderEP, ServerData sd)
|
||||
{
|
||||
this.buffer = new byte[maxLength];
|
||||
this.length = length;
|
||||
for(int i=0; i<length; i++) this.buffer[i]=buffer[i];
|
||||
this.senderEP = senderEP;
|
||||
this.sd = sd;
|
||||
}
|
||||
}
|
||||
|
||||
public ProxyServer(ILog log)
|
||||
{
|
||||
m_log = log;
|
||||
|
@ -293,7 +239,8 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
ProxyMap.RegionData rd = proxy_map.GetRegionData(client);
|
||||
|
||||
rd.isBlocked = false;
|
||||
while(rd.storedMessages.Count > 0) {
|
||||
while (rd.storedMessages.Count > 0)
|
||||
{
|
||||
StoredMessage msg = (StoredMessage) rd.storedMessages.Dequeue();
|
||||
//m_log.Verbose("[PROXY]"+"Resending blocked message from {0}", msg.senderEP);
|
||||
SendMessage(msg.buffer, msg.length, msg.senderEP, msg.sd);
|
||||
|
@ -348,7 +295,6 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
|
||||
try
|
||||
{
|
||||
|
||||
m_log.InfoFormat("[PROXY] Opening UDP socket on {0}", sd.clientEP);
|
||||
sd.serverIP = new IPEndPoint(IPAddress.Parse("0.0.0.0"), ((IPEndPoint) sd.clientEP).Port);
|
||||
sd.server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||
|
@ -385,7 +331,6 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
{
|
||||
running = false;
|
||||
m_log.InfoFormat("[PROXY] Stopping the proxy server");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -471,7 +416,6 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
m_log.Error("[PROXY]" + e.StackTrace);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -480,7 +424,8 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
ProxyMap.RegionData rd = proxy_map.GetRegionData(sd.clientEP);
|
||||
foreach (EndPoint region in rd.regions)
|
||||
{
|
||||
if(rd.isBlocked) {
|
||||
if (rd.isBlocked)
|
||||
{
|
||||
rd.storedMessages.Enqueue(new StoredMessage(buffer, length, numBytes, senderEP, sd));
|
||||
}
|
||||
else
|
||||
|
@ -502,5 +447,100 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Nested type: ProxyMap
|
||||
|
||||
protected class ProxyMap
|
||||
{
|
||||
private Dictionary<EndPoint, RegionData> map;
|
||||
|
||||
public ProxyMap()
|
||||
{
|
||||
map = new Dictionary<EndPoint, RegionData>();
|
||||
}
|
||||
|
||||
public void Add(EndPoint client, EndPoint region)
|
||||
{
|
||||
if (map.ContainsKey(client))
|
||||
{
|
||||
map[client].regions.Add(region);
|
||||
}
|
||||
else
|
||||
{
|
||||
RegionData regions = new RegionData();
|
||||
map.Add(client, regions);
|
||||
regions.regions.Add(region);
|
||||
}
|
||||
}
|
||||
|
||||
public RegionData GetRegionData(EndPoint client)
|
||||
{
|
||||
return map[client];
|
||||
}
|
||||
|
||||
public EndPoint GetClient(EndPoint region)
|
||||
{
|
||||
foreach (KeyValuePair<EndPoint, RegionData> pair in map)
|
||||
{
|
||||
if (pair.Value.regions.Contains(region))
|
||||
{
|
||||
return pair.Key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
#region Nested type: RegionData
|
||||
|
||||
public class RegionData
|
||||
{
|
||||
public bool isBlocked = false;
|
||||
public List<EndPoint> regions = new List<EndPoint>();
|
||||
public Queue storedMessages = new Queue();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested type: ServerData
|
||||
|
||||
protected class ServerData
|
||||
{
|
||||
public EndPoint clientEP;
|
||||
public byte[] recvBuffer = new byte[4096];
|
||||
public EndPoint senderEP;
|
||||
public Socket server;
|
||||
public IPEndPoint serverIP;
|
||||
|
||||
public ServerData()
|
||||
{
|
||||
server = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested type: StoredMessage
|
||||
|
||||
protected class StoredMessage
|
||||
{
|
||||
public byte[] buffer;
|
||||
public int length;
|
||||
public ServerData sd;
|
||||
public EndPoint senderEP;
|
||||
|
||||
public StoredMessage(byte[] buffer, int length, int maxLength, EndPoint senderEP, ServerData sd)
|
||||
{
|
||||
this.buffer = new byte[maxLength];
|
||||
this.length = length;
|
||||
for (int i = 0; i < length; i++) this.buffer[i] = buffer[i];
|
||||
this.senderEP = senderEP;
|
||||
this.sd = sd;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue