-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make use of buf.NewWithSize() in Trojan's PacketReader and PacketWriter
also fix a domain length check bug
- Loading branch information
1 parent
923d494
commit 8433420
Showing
4 changed files
with
74 additions
and
27 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package trojan_test | ||
|
||
import ( | ||
"crypto/rand" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
|
@@ -90,3 +91,48 @@ func TestUDPRequest(t *testing.T) { | |
t.Error("data: ", r) | ||
} | ||
} | ||
|
||
func TestLargeUDPRequest(t *testing.T) { | ||
user := &protocol.MemoryUser{ | ||
Email: "[email protected]", | ||
Account: toAccount(&Account{ | ||
Password: "password", | ||
}), | ||
} | ||
|
||
payload := make([]byte, 4096) | ||
common.Must2(rand.Read(payload)) | ||
data := buf.NewWithSize(int32(len(payload))) | ||
common.Must2(data.Write(payload)) | ||
|
||
buffer := buf.NewWithSize(2*data.Len() + 1) | ||
defer buffer.Release() | ||
|
||
destination := net.Destination{Network: net.Network_UDP, Address: net.LocalHostIP, Port: 1234} | ||
writer := &PacketWriter{Writer: &ConnWriter{Writer: buffer, Target: destination, Account: user.Account.(*MemoryAccount)}, Target: destination} | ||
common.Must(writer.WriteMultiBuffer(buf.MultiBuffer{data, data})) | ||
|
||
connReader := &ConnReader{Reader: buffer} | ||
common.Must(connReader.ParseHeader()) | ||
|
||
packetReader := &PacketReader{Reader: connReader} | ||
for i := 0; i < 2; i++ { | ||
p, err := packetReader.ReadMultiBufferWithMetadata() | ||
common.Must(err) | ||
|
||
if p.Buffer.IsEmpty() { | ||
t.Error("no request data") | ||
} | ||
|
||
if r := cmp.Diff(p.Target, destination); r != "" { | ||
t.Error("destination: ", r) | ||
} | ||
|
||
mb, decoded := buf.SplitFirst(p.Buffer) | ||
buf.ReleaseMulti(mb) | ||
|
||
if r := cmp.Diff(decoded.Bytes(), payload); r != "" { | ||
t.Error("data: ", r) | ||
} | ||
} | ||
} |