1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-04 23:40:26 +08:00
This commit is contained in:
源文雨
2022-04-12 16:45:54 +08:00
parent 1838d0b914
commit 1de5be51f0

View File

@@ -2,12 +2,14 @@ package head
import (
"encoding/binary"
"encoding/hex"
"errors"
"net"
"unsafe"
"github.com/fumiama/WireGold/helper"
blake2b "github.com/minio/blake2b-simd"
"github.com/sirupsen/logrus"
)
// Packet 是发送和接收的最小单位
@@ -137,5 +139,6 @@ func (p *Packet) FillHash() {
// IsVaildHash 验证 packet 合法性
func (p *Packet) IsVaildHash() bool {
sum := blake2b.New256().Sum(p.Data)
logrus.Debugln("[packet] sum really:", hex.EncodeToString(sum), "sum in hash:", hex.EncodeToString(p.Hash[:]))
return *(*[32]byte)(*(*unsafe.Pointer)(unsafe.Pointer(&sum))) == p.Hash
}