* 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);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
#region IApplicationPlugin Members
|
||||||
|
|
||||||
public void Initialise(OpenSimMain openSim)
|
public void Initialise(OpenSimMain openSim)
|
||||||
{
|
{
|
||||||
m_log.Info("[LOADREGIONS]: Load Regions addin being initialised");
|
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++)
|
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);
|
openSim.CreateRegion(regionsToLoad[i], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +77,12 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
|
||||||
openSim.ModuleLoader.ClearCache();
|
openSim.ModuleLoader.ClearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void LoadRegionFromConfig(OpenSimMain openSim, ulong regionhandle)
|
public void LoadRegionFromConfig(OpenSimMain openSim, ulong regionhandle)
|
||||||
{
|
{
|
||||||
m_log.Info("[LOADREGIONS]: Load Regions addin being initialised");
|
m_log.Info("[LOADREGIONS]: Load Regions addin being initialised");
|
||||||
|
@ -96,14 +105,11 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
|
||||||
{
|
{
|
||||||
if (regionhandle == regionsToLoad[i].RegionHandle)
|
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);
|
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 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private OpenSimMain simMain;
|
|
||||||
private BaseHttpServer commandServer;
|
private BaseHttpServer commandServer;
|
||||||
|
private bool[] isLocalNeighbour;
|
||||||
private List<UDPServer> udpServers;
|
private bool isSplit = false;
|
||||||
private List<RegionInfo> regionData;
|
private TcpServer mTcpServer;
|
||||||
|
private object padlock = new object();
|
||||||
|
|
||||||
private int proxyOffset;
|
private int proxyOffset;
|
||||||
private string proxyURL;
|
private string proxyURL;
|
||||||
|
private List<RegionInfo> regionData;
|
||||||
|
private int[] regionPortList;
|
||||||
private SceneManager sceneManager;
|
private SceneManager sceneManager;
|
||||||
|
private string[] sceneURL;
|
||||||
private string serializeDir;
|
private string serializeDir;
|
||||||
|
private OpenSimMain simMain;
|
||||||
|
private TcpClient[] tcpClientList;
|
||||||
|
private List<UDPServer> udpServers;
|
||||||
|
|
||||||
private TcpServer mTcpServer;
|
#region IApplicationPlugin Members
|
||||||
|
|
||||||
public void Initialise(OpenSimMain openSim)
|
public void Initialise(OpenSimMain openSim)
|
||||||
{
|
{
|
||||||
|
@ -77,11 +83,11 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
ClientView.SynchronizeClient = new ClientView.SynchronizeClientHandler(SynchronizePackets);
|
ClientView.SynchronizeClient = new ClientView.SynchronizeClientHandler(SynchronizePackets);
|
||||||
AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve);
|
AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve);
|
||||||
|
|
||||||
this.sceneManager = openSim.SceneManager;
|
sceneManager = openSim.SceneManager;
|
||||||
this.udpServers = openSim.UdpServers;
|
udpServers = openSim.UdpServers;
|
||||||
this.regionData = openSim.RegionData;
|
regionData = openSim.RegionData;
|
||||||
this.simMain = openSim;
|
simMain = openSim;
|
||||||
this.commandServer = openSim.HttpServer;
|
commandServer = openSim.HttpServer;
|
||||||
|
|
||||||
proxyOffset = Int32.Parse(openSim.ConfigSource.Configs["Network"].GetString("proxy_offset", "0"));
|
proxyOffset = Int32.Parse(openSim.ConfigSource.Configs["Network"].GetString("proxy_offset", "0"));
|
||||||
serializeDir = openSim.ConfigSource.Configs["Network"].GetString("serialize_dir", "/tmp/");
|
serializeDir = openSim.ConfigSource.Configs["Network"].GetString("serialize_dir", "/tmp/");
|
||||||
|
@ -99,20 +105,23 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
m_log.Info("[BALANCER] " + "Exiting Initialize()");
|
m_log.Info("[BALANCER] " + "Exiting Initialize()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private XmlRpcResponse GetStatus(XmlRpcRequest request)
|
private XmlRpcResponse GetStatus(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
XmlRpcResponse response = new XmlRpcResponse();
|
XmlRpcResponse response = new XmlRpcResponse();
|
||||||
|
@ -137,7 +146,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
{
|
{
|
||||||
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++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +159,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
{
|
{
|
||||||
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 + "; ";
|
||||||
}
|
}
|
||||||
|
@ -664,12 +675,6 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
* This section implements scene splitting and synchronization
|
* 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)
|
private XmlRpcResponse SplitRegion(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -708,7 +713,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
||||||
{
|
{
|
||||||
// Disable event updates, backups etc in the slave(s)
|
// Disable event updates, backups etc in the slave(s)
|
||||||
if (isMaster) {
|
if (isMaster)
|
||||||
|
{
|
||||||
scene.Region_Status = RegionStatus.Up;
|
scene.Region_Status = RegionStatus.Up;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -868,7 +874,6 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object padlock=new object();
|
|
||||||
private void SynchronizeScenes(Scene scene)
|
private void SynchronizeScenes(Scene scene)
|
||||||
{
|
{
|
||||||
if (!isSplit)
|
if (!isSplit)
|
||||||
|
|
|
@ -30,13 +30,17 @@ using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -53,19 +57,25 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendCallback(IAsyncResult ar) {
|
private static void SendCallback(IAsyncResult ar)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
Socket client = (Socket) ar.AsyncState;
|
Socket client = (Socket) ar.AsyncState;
|
||||||
int bytesSent = client.EndSend(ar);
|
int bytesSent = client.EndSend(ar);
|
||||||
if (bytesSent > 0)
|
if (bytesSent > 0)
|
||||||
|
@ -114,7 +128,9 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
//Console.WriteLine("Sent {0} bytes to server.", bytesSent);
|
//Console.WriteLine("Sent {0} bytes to server.", bytesSent);
|
||||||
}
|
}
|
||||||
sendDone.Set();
|
sendDone.Set();
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,28 +138,28 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
|
|
||||||
public class InternalPacketHeader
|
public class InternalPacketHeader
|
||||||
{
|
{
|
||||||
private byte[] buffer = new byte[32];
|
|
||||||
public int type;
|
|
||||||
public int throttlePacketType;
|
|
||||||
public int numbytes;
|
|
||||||
public Guid agent_id;
|
public Guid agent_id;
|
||||||
|
private byte[] buffer = new byte[32];
|
||||||
|
public int numbytes;
|
||||||
public int region_port;
|
public int region_port;
|
||||||
|
public int throttlePacketType;
|
||||||
|
public int type;
|
||||||
|
|
||||||
public void FromBytes(byte[] bytes)
|
public void FromBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
int i = 0; // offset
|
int i = 0; // offset
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
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));
|
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));
|
numbytes = (int) (bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||||
this.agent_id = new Guid(
|
agent_id = new Guid(
|
||||||
bytes[i++] | (bytes[i++] << 8) | (bytes[i++] << 16) | bytes[i++] << 24,
|
bytes[i++] | (bytes[i++] << 8) | (bytes[i++] << 16) | bytes[i++] << 24,
|
||||||
(short) (bytes[i++] | (bytes[i++] << 8)),
|
(short) (bytes[i++] | (bytes[i++] << 8)),
|
||||||
(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++],
|
||||||
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)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -154,48 +170,54 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
public byte[] ToBytes()
|
public byte[] ToBytes()
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
this.buffer[i++] = (byte)(this.type % 256);
|
buffer[i++] = (byte) (type % 256);
|
||||||
this.buffer[i++] = (byte)((this.type >> 8) % 256);
|
buffer[i++] = (byte) ((type >> 8) % 256);
|
||||||
this.buffer[i++] = (byte)((this.type >> 16) % 256);
|
buffer[i++] = (byte) ((type >> 16) % 256);
|
||||||
this.buffer[i++] = (byte)((this.type >> 24) % 256);
|
buffer[i++] = (byte) ((type >> 24) % 256);
|
||||||
|
|
||||||
this.buffer[i++] = (byte)(this.throttlePacketType % 256);
|
buffer[i++] = (byte) (throttlePacketType % 256);
|
||||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 8) % 256);
|
buffer[i++] = (byte) ((throttlePacketType >> 8) % 256);
|
||||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 16) % 256);
|
buffer[i++] = (byte) ((throttlePacketType >> 16) % 256);
|
||||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 24) % 256);
|
buffer[i++] = (byte) ((throttlePacketType >> 24) % 256);
|
||||||
|
|
||||||
this.buffer[i++] = (byte)(this.numbytes % 256);
|
buffer[i++] = (byte) (numbytes % 256);
|
||||||
this.buffer[i++] = (byte)((this.numbytes >> 8) % 256);
|
buffer[i++] = (byte) ((numbytes >> 8) % 256);
|
||||||
this.buffer[i++] = (byte)((this.numbytes >> 16) % 256);
|
buffer[i++] = (byte) ((numbytes >> 16) % 256);
|
||||||
this.buffer[i++] = (byte)((this.numbytes >> 24) % 256);
|
buffer[i++] = (byte) ((numbytes >> 24) % 256);
|
||||||
|
|
||||||
// no endian care
|
// 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);
|
buffer[i++] = (byte) (region_port % 256);
|
||||||
this.buffer[i++] = (byte)((this.region_port >> 8) % 256);
|
buffer[i++] = (byte) ((region_port >> 8) % 256);
|
||||||
this.buffer[i++] = (byte)((this.region_port >> 16) % 256);
|
buffer[i++] = (byte) ((region_port >> 16) % 256);
|
||||||
this.buffer[i++] = (byte)((this.region_port >> 24) % 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;
|
public static int internalPacketHeaderSize = 4 * 4 + 16 * 1;
|
||||||
|
private Socket mConnection;
|
||||||
|
|
||||||
private string mHostname;
|
private string mHostname;
|
||||||
private int mPort;
|
private int mPort;
|
||||||
private Socket mConnection;
|
|
||||||
public TcpClient(string hostname, int port) {
|
public TcpClient(string hostname, int port)
|
||||||
this.mHostname = hostname;
|
{
|
||||||
this.mPort = port;
|
mHostname = hostname;
|
||||||
this.mConnection = null;
|
mPort = port;
|
||||||
|
mConnection = null;
|
||||||
}
|
}
|
||||||
public void connect() {
|
|
||||||
this.mConnection = AsynchronousClient.StartClient(mHostname, mPort);
|
public void connect()
|
||||||
|
{
|
||||||
|
mConnection = AsynchronousClient.StartClient(mHostname, mPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public void recevie() {
|
public void recevie() {
|
||||||
if (mConnection == null) {
|
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)
|
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(mConnection, header.ToBytes());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
|
@ -231,7 +254,7 @@ for (int i = 0; i < 10; i++)
|
||||||
}
|
}
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
*/
|
*/
|
||||||
AsynchronousClient.Send(this.mConnection, packet);
|
AsynchronousClient.Send(mConnection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,42 +31,58 @@ using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
namespace OpenSim.ApplicationPlugins.LoadBalancer
|
||||||
|
{
|
||||||
public class StateObject {
|
public class StateObject
|
||||||
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 InternalPacketHeader header = null;
|
public InternalPacketHeader header = null;
|
||||||
|
public MemoryStream ms_ptr = new MemoryStream();
|
||||||
|
public Socket workSocket = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AsynchronousSocketListener {
|
public class AsynchronousSocketListener
|
||||||
public static string data = null;
|
{
|
||||||
public static ManualResetEvent allDone = new ManualResetEvent(false);
|
public static ManualResetEvent allDone = new ManualResetEvent(false);
|
||||||
|
public static string data = null;
|
||||||
|
|
||||||
#region KIRYU
|
#region KIRYU
|
||||||
|
|
||||||
|
#region Delegates
|
||||||
|
|
||||||
public delegate void PacketRecieveHandler(InternalPacketHeader header, byte[] buff);
|
public delegate void PacketRecieveHandler(InternalPacketHeader header, byte[] buff);
|
||||||
public static PacketRecieveHandler PacketHandler = null;
|
|
||||||
#endregion
|
#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());
|
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());
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -75,7 +91,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -84,7 +101,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
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)
|
||||||
|
{
|
||||||
StateObject state = (StateObject) ar.AsyncState;
|
StateObject state = (StateObject) ar.AsyncState;
|
||||||
Socket handler = state.workSocket;
|
Socket handler = state.workSocket;
|
||||||
|
|
||||||
|
@ -94,7 +112,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
|
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", "Received packet [{0}]", bytesRead);
|
//MainLog.Instance.Verbose("TCPSERVER", "Received packet [{0}]", bytesRead);
|
||||||
|
|
||||||
if (bytesRead > 0) {
|
if (bytesRead > 0)
|
||||||
|
{
|
||||||
state.ms_ptr.Write(state.buffer, 0, bytesRead);
|
state.ms_ptr.Write(state.buffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -105,8 +124,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
|
|
||||||
long rest_size = state.ms_ptr.Length;
|
long rest_size = state.ms_ptr.Length;
|
||||||
long current_pos = 0;
|
long current_pos = 0;
|
||||||
while (rest_size > TcpClient.internalPacketHeaderSize) {
|
while (rest_size > TcpClient.internalPacketHeaderSize)
|
||||||
|
{
|
||||||
if ((state.header == null) && (rest_size >= TcpClient.internalPacketHeaderSize))
|
if ((state.header == null) && (rest_size >= TcpClient.internalPacketHeaderSize))
|
||||||
{
|
{
|
||||||
//MainLog.Instance.Verbose("TCPSERVER", "Processing header");
|
//MainLog.Instance.Verbose("TCPSERVER", "Processing header");
|
||||||
|
@ -155,8 +174,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
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);
|
||||||
|
@ -166,9 +185,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // while (true)
|
} // while (true)
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -180,14 +197,21 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,11 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
[Extension("/OpenSim/Startup")]
|
[Extension("/OpenSim/Startup")]
|
||||||
public class RegionProxyPlugin : IApplicationPlugin
|
public class RegionProxyPlugin : IApplicationPlugin
|
||||||
{
|
{
|
||||||
private ProxyServer proxy;
|
|
||||||
private BaseHttpServer command_server;
|
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
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)
|
public void Initialise(OpenSimMain openSim)
|
||||||
{
|
{
|
||||||
|
@ -91,6 +93,8 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
private XmlRpcResponse Stop(XmlRpcRequest request)
|
private XmlRpcResponse Stop(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -107,12 +111,15 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
|
|
||||||
private XmlRpcResponse AddPort(XmlRpcRequest request)
|
private XmlRpcResponse AddPort(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
int clientPort = (int) request.Params[0];
|
int clientPort = (int) request.Params[0];
|
||||||
int regionPort = (int) request.Params[1];
|
int regionPort = (int) request.Params[1];
|
||||||
string regionUrl = (string) request.Params[2];
|
string regionUrl = (string) request.Params[2];
|
||||||
proxy.AddPort(clientPort, regionPort, regionUrl);
|
proxy.AddPort(clientPort, regionPort, regionUrl);
|
||||||
} catch(Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
m_log.Error("[PROXY]" + e.Message);
|
m_log.Error("[PROXY]" + e.Message);
|
||||||
m_log.Error("[PROXY]" + e.StackTrace);
|
m_log.Error("[PROXY]" + e.StackTrace);
|
||||||
}
|
}
|
||||||
|
@ -121,13 +128,16 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
|
|
||||||
private XmlRpcResponse AddRegion(XmlRpcRequest request)
|
private XmlRpcResponse AddRegion(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
int currentRegionPort = (int) request.Params[0];
|
int currentRegionPort = (int) request.Params[0];
|
||||||
string currentRegionUrl = (string) request.Params[1];
|
string currentRegionUrl = (string) request.Params[1];
|
||||||
int newRegionPort = (int) request.Params[2];
|
int newRegionPort = (int) request.Params[2];
|
||||||
string newRegionUrl = (string) request.Params[3];
|
string newRegionUrl = (string) request.Params[3];
|
||||||
proxy.AddRegion(currentRegionPort, currentRegionUrl, newRegionPort, newRegionUrl);
|
proxy.AddRegion(currentRegionPort, currentRegionUrl, newRegionPort, newRegionUrl);
|
||||||
} catch(Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
m_log.Error("[PROXY]" + e.Message);
|
m_log.Error("[PROXY]" + e.Message);
|
||||||
m_log.Error("[PROXY]" + e.StackTrace);
|
m_log.Error("[PROXY]" + e.StackTrace);
|
||||||
}
|
}
|
||||||
|
@ -136,13 +146,16 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
|
|
||||||
private XmlRpcResponse ChangeRegion(XmlRpcRequest request)
|
private XmlRpcResponse ChangeRegion(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
int currentRegionPort = (int) request.Params[0];
|
int currentRegionPort = (int) request.Params[0];
|
||||||
string currentRegionUrl = (string) request.Params[1];
|
string currentRegionUrl = (string) request.Params[1];
|
||||||
int newRegionPort = (int) request.Params[2];
|
int newRegionPort = (int) request.Params[2];
|
||||||
string newRegionUrl = (string) request.Params[3];
|
string newRegionUrl = (string) request.Params[3];
|
||||||
proxy.ChangeRegion(currentRegionPort, currentRegionUrl, newRegionPort, newRegionUrl);
|
proxy.ChangeRegion(currentRegionPort, currentRegionUrl, newRegionPort, newRegionUrl);
|
||||||
} catch(Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
m_log.Error("[PROXY]" + e.Message);
|
m_log.Error("[PROXY]" + e.Message);
|
||||||
m_log.Error("[PROXY]" + e.StackTrace);
|
m_log.Error("[PROXY]" + e.StackTrace);
|
||||||
}
|
}
|
||||||
|
@ -151,11 +164,14 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
|
|
||||||
private XmlRpcResponse DeleteRegion(XmlRpcRequest request)
|
private XmlRpcResponse DeleteRegion(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
int currentRegionPort = (int) request.Params[0];
|
int currentRegionPort = (int) request.Params[0];
|
||||||
string currentRegionUrl = (string) request.Params[1];
|
string currentRegionUrl = (string) request.Params[1];
|
||||||
proxy.DeleteRegion(currentRegionPort, currentRegionUrl);
|
proxy.DeleteRegion(currentRegionPort, currentRegionUrl);
|
||||||
} catch(Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
m_log.Error("[PROXY]" + e.Message);
|
m_log.Error("[PROXY]" + e.Message);
|
||||||
m_log.Error("[PROXY]" + e.StackTrace);
|
m_log.Error("[PROXY]" + e.StackTrace);
|
||||||
}
|
}
|
||||||
|
@ -164,11 +180,14 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
|
|
||||||
private XmlRpcResponse BlockClientMessages(XmlRpcRequest request)
|
private XmlRpcResponse BlockClientMessages(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
string regionUrl = (string) request.Params[0];
|
string regionUrl = (string) request.Params[0];
|
||||||
int regionPort = (int) request.Params[1];
|
int regionPort = (int) request.Params[1];
|
||||||
proxy.BlockClientMessages(regionUrl, regionPort);
|
proxy.BlockClientMessages(regionUrl, regionPort);
|
||||||
} catch(Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
m_log.Error("[PROXY]" + e.Message);
|
m_log.Error("[PROXY]" + e.Message);
|
||||||
m_log.Error("[PROXY]" + e.StackTrace);
|
m_log.Error("[PROXY]" + e.StackTrace);
|
||||||
}
|
}
|
||||||
|
@ -177,11 +196,14 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
|
|
||||||
private XmlRpcResponse UnblockClientMessages(XmlRpcRequest request)
|
private XmlRpcResponse UnblockClientMessages(XmlRpcRequest request)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
string regionUrl = (string) request.Params[0];
|
string regionUrl = (string) request.Params[0];
|
||||||
int regionPort = (int) request.Params[1];
|
int regionPort = (int) request.Params[1];
|
||||||
proxy.UnblockClientMessages(regionUrl, regionPort);
|
proxy.UnblockClientMessages(regionUrl, regionPort);
|
||||||
} catch(Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
m_log.Error("[PROXY]" + e.Message);
|
m_log.Error("[PROXY]" + e.Message);
|
||||||
m_log.Error("[PROXY]" + e.StackTrace);
|
m_log.Error("[PROXY]" + e.StackTrace);
|
||||||
}
|
}
|
||||||
|
@ -190,89 +212,13 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class ProxyServer {
|
public class ProxyServer
|
||||||
protected AsyncCallback receivedData;
|
{
|
||||||
protected ProxyMap proxy_map = new ProxyMap();
|
|
||||||
protected readonly ILog m_log;
|
protected readonly ILog m_log;
|
||||||
|
protected ProxyMap proxy_map = new ProxyMap();
|
||||||
|
protected AsyncCallback receivedData;
|
||||||
protected bool running;
|
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)
|
public ProxyServer(ILog log)
|
||||||
{
|
{
|
||||||
m_log = log;
|
m_log = log;
|
||||||
|
@ -293,7 +239,8 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
ProxyMap.RegionData rd = proxy_map.GetRegionData(client);
|
ProxyMap.RegionData rd = proxy_map.GetRegionData(client);
|
||||||
|
|
||||||
rd.isBlocked = false;
|
rd.isBlocked = false;
|
||||||
while(rd.storedMessages.Count > 0) {
|
while (rd.storedMessages.Count > 0)
|
||||||
|
{
|
||||||
StoredMessage msg = (StoredMessage) rd.storedMessages.Dequeue();
|
StoredMessage msg = (StoredMessage) rd.storedMessages.Dequeue();
|
||||||
//m_log.Verbose("[PROXY]"+"Resending blocked message from {0}", msg.senderEP);
|
//m_log.Verbose("[PROXY]"+"Resending blocked message from {0}", msg.senderEP);
|
||||||
SendMessage(msg.buffer, msg.length, msg.senderEP, msg.sd);
|
SendMessage(msg.buffer, msg.length, msg.senderEP, msg.sd);
|
||||||
|
@ -348,7 +295,6 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
m_log.InfoFormat("[PROXY] Opening UDP socket on {0}", sd.clientEP);
|
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.serverIP = new IPEndPoint(IPAddress.Parse("0.0.0.0"), ((IPEndPoint) sd.clientEP).Port);
|
||||||
sd.server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
sd.server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||||
|
@ -385,7 +331,6 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
m_log.InfoFormat("[PROXY] Stopping the proxy server");
|
m_log.InfoFormat("[PROXY] Stopping the proxy server");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -471,7 +416,6 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
m_log.Error("[PROXY]" + e.StackTrace);
|
m_log.Error("[PROXY]" + e.StackTrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -480,7 +424,8 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
||||||
ProxyMap.RegionData rd = proxy_map.GetRegionData(sd.clientEP);
|
ProxyMap.RegionData rd = proxy_map.GetRegionData(sd.clientEP);
|
||||||
foreach (EndPoint region in rd.regions)
|
foreach (EndPoint region in rd.regions)
|
||||||
{
|
{
|
||||||
if(rd.isBlocked) {
|
if (rd.isBlocked)
|
||||||
|
{
|
||||||
rd.storedMessages.Enqueue(new StoredMessage(buffer, length, numBytes, senderEP, sd));
|
rd.storedMessages.Enqueue(new StoredMessage(buffer, length, numBytes, senderEP, sd));
|
||||||
}
|
}
|
||||||
else
|
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