Skip to content

Commit

Permalink
fix udp payload reading
Browse files Browse the repository at this point in the history
  • Loading branch information
p4gefau1t committed May 28, 2020
1 parent c1fbc67 commit 901ed91
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions protocol/trojan/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ func (i *TrojanPacketSession) ReadPacket() (*protocol.Request, []byte, error) {
lengthBuf := [2]byte{}
_, err := io.ReadFull(i.conn, lengthBuf[:])
if err != nil {
return req, nil, common.NewError("failed to read length")
return req, nil, common.NewError("Failed to read length")
}
length := binary.BigEndian.Uint16(lengthBuf[:])
packet := make([]byte, length)
n, err := i.conn.Read(packet)
return req, packet[:n], err
_, err = io.ReadFull(i.conn, packet)
if err != nil {
return req, nil, common.NewError("Failed to read payload")
}
return req, packet[:], err
}

func (i *TrojanPacketSession) WritePacket(req *protocol.Request, packet []byte) (int, error) {
Expand Down

0 comments on commit 901ed91

Please sign in to comment.