修正内网解密错误bug

This commit is contained in:
cdyong 2016-07-20 15:08:38 +00:00
parent cb82f4eefb
commit 7ac17fa4e2
3 changed files with 43 additions and 41 deletions

View File

@ -97,7 +97,7 @@ bool HelloMessage::Read(Stream& ms)
void HelloMessage::Write(Stream& ms) const
{
BinaryPair bp(ms);
bp.Set("ErrorCode", ErrCode);
bp.Set("Ver", Version);
bp.Set("Type", Type);
bp.Set("Name", Name);

View File

@ -82,7 +82,7 @@ void TokenController::Open()
if (Opened) return;
assert(Socket, "还没有Socket呢");
if(!Port) Port = dynamic_cast<ITransport*>(Socket);
if (!Port) Port = dynamic_cast<ITransport*>(Socket);
assert(Port, "还没有传输口呢");
debug_printf("TokenNet::Inited 使用传输接口 ");
@ -244,9 +244,11 @@ bool TokenController::OnReceive(Message& msg)
debug_printf("TokenController::OnReceive 解密失败 Key:\r\n");
auto remote = (IPEndPoint*)msg.State;
remote->Show(false);
debug_printf(" Code 0x%02X Key: ",msg.Code);
debug_printf(" Code 0x%02X Key: ", msg.Code);
Key.Show(true);
return false;
msg.Length = 0;
return Controller::OnReceive(msg);
}
}
@ -272,7 +274,7 @@ bool TokenController::Send(Message& msg)
ShowMessage("Send", msg);
// 如果没有传输口处于打开状态,则发送失败
if(!Port->Open()) return false;
if (!Port->Open()) return false;
//byte buf[1472];
//Stream ms(buf, ArrayLength(buf));
@ -282,7 +284,7 @@ bool TokenController::Send(Message& msg)
msg.Write(ms);
// 握手不加密
if(msg.Code > 0x01 && Key.Length() > 0)
if (msg.Code > 0x01 && Key.Length() > 0)
{
ms.SetPosition(0);
if (!Encrypt(ms, Key)) return false;
@ -367,7 +369,7 @@ bool TokenController::StatSend(const Message& msg)
auto st = Stat;
// 统计请求
if(!msg.Reply && !msg.OneWay)
if (!msg.Reply && !msg.OneWay)
{
st->SendRequest++;
StatRequest(code);
@ -388,7 +390,7 @@ bool TokenController::StatSend(const Message& msg)
}
// 统计响应
if(msg.Reply)
if (msg.Reply)
{
st->SendReply++;
StatReply(msg.Code);
@ -402,7 +404,7 @@ bool TokenController::StatReceive(const Message& msg)
byte code = msg.Code;
auto st = Stat;
if(msg.Reply)
if (msg.Reply)
{
bool rs = false;
for (int i = 0; i < ArrayLength(_StatQueue); i++)
@ -576,13 +578,13 @@ String& TokenStat::ToStr(String& str) const
/*debug_printf("this=0x%08X _Last=0x%08X _Total=0x%08X ", this, _Last, _Total);
Percent().Show(true);*/
if(SendRequest > 0)
if (SendRequest > 0)
{
str = str + "发:" + Percent() + "% " + RecvReply;
if (RecvReplyAsync > 0) str = str + "+" + RecvReplyAsync;
str = str + "/" + SendRequest + " " + Speed() + "ms ";
}
if(RecvRequest > 0) str = str + "收:" + PercentReply() + "% " + SendReply + "/" + RecvRequest;
if (RecvRequest > 0) str = str + "收:" + PercentReply() + "% " + SendReply + "/" + RecvRequest;
if (Read > 0) str = str + " 读:" + (ReadReply * 100 / Read) + "% " + ReadReply + "/" + Read;
if (Write > 0) str = str + " 写:" + (WriteReply * 100 / Write) + "% " + WriteReply + "/" + Write;
if (Invoke > 0) str = str + " 调:" + (InvokeReply * 100 / Invoke) + " " + InvokeReply + "/" + Invoke;

View File

@ -48,15 +48,15 @@ void TokenSession::OnReceive(TokenMessage& msg)
TS("TokenSession::OnReceive");
LastActive = Sys.Ms();
if (Token == 0 && msg.Code > 2)
{
auto rs = msg.CreateReply();
rs.Code = 0x01;
rs.Error = true;
HelloMessage ext;
ext.ErrCode = 0xFF;
ext.Reply = true;
ext.WriteMessage(rs);
Control.Reply(rs);
@ -108,8 +108,8 @@ bool TokenSession::OnHello(TokenMessage& msg)
auto now = Sys.Ms();
auto crc = Crc::Hash(Buffer(&now, 8));
key = Buffer(&crc, 4);
debug_printf("creat key: ");
key.Show(true);
//通知其它内网,密码被修改了
}
ext2.Key = key;