Rename a variable and modify a test

This commit is contained in:
Qian Wang 2019-08-07 19:08:37 +01:00
parent 586cc5ebb6
commit 572fe8486a
2 changed files with 4 additions and 17 deletions

View File

@ -35,10 +35,10 @@ func MakeObfs(salsaKey [32]byte, payloadCipher cipher.AEAD) Obfser {
if len(buf) < usefulLen { if len(buf) < usefulLen {
return 0, errors.New("buffer is too small") return 0, errors.New("buffer is too small")
} }
used := buf[:usefulLen] useful := buf[:usefulLen] // tls header + payload + potential overhead
recordLayer := used[0:5] recordLayer := useful[0:5]
header := used[5 : 5+HEADER_LEN] header := useful[5 : 5+HEADER_LEN]
encryptedPayload := used[5+HEADER_LEN:] encryptedPayload := useful[5+HEADER_LEN:]
// header: [StreamID 4 bytes][Seq 4 bytes][Closing 1 byte][extraLen 1 bytes][random 2 bytes] // header: [StreamID 4 bytes][Seq 4 bytes][Closing 1 byte][extraLen 1 bytes][random 2 bytes]
putU32(header[0:4], f.StreamID) putU32(header[0:4], f.StreamID)

View File

@ -25,14 +25,10 @@ func BenchmarkRecvDataFromRemote(b *testing.B) {
sesh := MakeSession(0, UNLIMITED_VALVE, obfuscator, util.ReadTLS) sesh := MakeSession(0, UNLIMITED_VALVE, obfuscator, util.ReadTLS)
n, _ := sesh.Obfs(f, obfsBuf) n, _ := sesh.Obfs(f, obfsBuf)
originalHeader := make([]byte, 12)
copy(originalHeader, obfsBuf[5:17])
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
sesh.recvDataFromRemote(obfsBuf[:n]) sesh.recvDataFromRemote(obfsBuf[:n])
b.SetBytes(int64(n)) b.SetBytes(int64(n))
copy(obfsBuf[5:17], originalHeader)
} }
}) })
@ -41,15 +37,10 @@ func BenchmarkRecvDataFromRemote(b *testing.B) {
sesh := MakeSession(0, UNLIMITED_VALVE, obfuscator, util.ReadTLS) sesh := MakeSession(0, UNLIMITED_VALVE, obfuscator, util.ReadTLS)
n, _ := sesh.Obfs(f, obfsBuf) n, _ := sesh.Obfs(f, obfsBuf)
// because deobfs decrypts the header in-place, which alters the input
originalHeader := make([]byte, 12)
copy(originalHeader, obfsBuf[5:17])
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
sesh.recvDataFromRemote(obfsBuf[:n]) sesh.recvDataFromRemote(obfsBuf[:n])
b.SetBytes(int64(n)) b.SetBytes(int64(n))
copy(obfsBuf[5:17], originalHeader)
} }
}) })
@ -58,14 +49,10 @@ func BenchmarkRecvDataFromRemote(b *testing.B) {
sesh := MakeSession(0, UNLIMITED_VALVE, obfuscator, util.ReadTLS) sesh := MakeSession(0, UNLIMITED_VALVE, obfuscator, util.ReadTLS)
n, _ := sesh.Obfs(f, obfsBuf) n, _ := sesh.Obfs(f, obfsBuf)
originalHeader := make([]byte, 12)
copy(originalHeader, obfsBuf[5:17])
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
sesh.recvDataFromRemote(obfsBuf[:n]) sesh.recvDataFromRemote(obfsBuf[:n])
b.SetBytes(int64(n)) b.SetBytes(int64(n))
copy(obfsBuf[5:17], originalHeader)
} }
}) })