-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(head): use uniform head extract & crc64 -> md5
- Loading branch information
Showing
5 changed files
with
63 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package head | ||
|
||
import "encoding/binary" | ||
|
||
type PacketFlags uint16 | ||
|
||
func (pf PacketFlags) IsValid() bool { | ||
return pf&0x8000 == 0 | ||
} | ||
|
||
func (pf PacketFlags) DontFrag() bool { | ||
return pf&0x4000 == 0x4000 | ||
} | ||
|
||
func (pf PacketFlags) NoFrag() bool { | ||
return pf == 0x4000 | ||
} | ||
|
||
func (pf PacketFlags) IsSingle() bool { | ||
return pf == 0 | ||
} | ||
|
||
func (pf PacketFlags) ZeroOffset() bool { | ||
return pf&0x1fff == 0 | ||
} | ||
|
||
func (pf PacketFlags) Offset() uint16 { | ||
return uint16(pf << 3) | ||
} | ||
|
||
// Flags extract flags from raw data | ||
func Flags(data []byte) PacketFlags { | ||
return PacketFlags(binary.LittleEndian.Uint16(data[10:12])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package head | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/binary" | ||
) | ||
|
||
// CRC64 extract packet header checksum | ||
func CRC64(data []byte) uint64 { | ||
return binary.LittleEndian.Uint64(data[52:PacketHeadLen]) | ||
} | ||
|
||
// CalcCRC64 calculate packet header checksum | ||
func CalcCRC64(data []byte) uint64 { | ||
m := md5.Sum(data[:52]) | ||
return binary.LittleEndian.Uint64(m[:8]) | ||
} | ||
|
||
// Hash extract 32 bytes blake2b hash from raw bytes | ||
func Hash(data []byte) []byte { | ||
return data[20:52] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters