Refactor proxy encode/decode methods out of the PacketPool into
their own class.
0.6.0-stable
Melanie Thielker 2008-08-08 11:04:24 +00:00
parent 22f09fbd21
commit eaff580abe
3 changed files with 5 additions and 44 deletions

View File

@ -48,45 +48,6 @@ namespace OpenSim.Framework
get { return instance; }
}
public static void EncodeProxyMessage(byte[] bytes, ref int numBytes, EndPoint trueEP)
{
if (numBytes > 4090) // max UPD size = 4096
{
throw new Exception("ERROR: No space to encode the proxy EP");
}
ushort port = (ushort) ((IPEndPoint) trueEP).Port;
bytes[numBytes++] = (byte) (port % 256);
bytes[numBytes++] = (byte) (port / 256);
foreach (byte b in ((IPEndPoint) trueEP).Address.GetAddressBytes())
{
bytes[numBytes++] = b;
}
int x = numBytes;
DecodeProxyMessage(bytes, ref numBytes);
numBytes = x;
}
public static EndPoint DecodeProxyMessage(byte[] bytes, ref int numBytes)
{
// IPv4 Only
byte[] addr = new byte[4];
addr[3] = bytes[--numBytes];
addr[2] = bytes[--numBytes];
addr[1] = bytes[--numBytes];
addr[0] = bytes[--numBytes];
ushort port = (ushort) (bytes[--numBytes] * 256);
port += (ushort) bytes[--numBytes];
return (EndPoint) new IPEndPoint(new IPAddress(addr), (int) port);
}
public Packet GetPacket(PacketType type)
{
Packet packet;
@ -175,4 +136,4 @@ namespace OpenSim.Framework
*/
}
}
}
}

View File

@ -259,7 +259,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
epProxy = epSender;
if (proxyPortOffset != 0)
{
epSender = PacketPool.DecodeProxyMessage(RecvBuffer, ref numBytes);
epSender = ProxyCodec.DecodeProxyMessage(RecvBuffer, ref numBytes);
}
int packetEnd = numBytes - 1;
@ -463,7 +463,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (proxyPortOffset != 0)
{
//MainLog.Instance.Verbose("UDPSERVER", "SendPacketTo proxy " + proxyCircuits[circuitcode].ToString() + ": client " + sendto.ToString());
PacketPool.EncodeProxyMessage(buffer, ref size, sendto);
ProxyCodec.EncodeProxyMessage(buffer, ref size, sendto);
m_socket.SendTo(buffer, size, flags, proxyCircuits[circuitcode]);
}
else

View File

@ -404,7 +404,7 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
{
try
{
client = PacketPool.DecodeProxyMessage(buffer, ref numBytes);
client = ProxyCodec.DecodeProxyMessage(buffer, ref numBytes);
try
{
// This message comes from a region object, forward it to the its client
@ -432,7 +432,7 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
else
{
// This message comes from a client object, forward it to the the region(s)
PacketPool.EncodeProxyMessage(buffer, ref numBytes, senderEP);
ProxyCodec.EncodeProxyMessage(buffer, ref numBytes, senderEP);
ProxyMap.RegionData rd = proxy_map.GetRegionData(sd.clientEP);
foreach (EndPoint region in rd.regions)
{