Chore: code adjustments

This commit is contained in:
Dreamacro 2020-06-07 16:54:41 +08:00
parent 8f32e6a60f
commit 2dece02df6
3 changed files with 8 additions and 5 deletions

View File

@ -81,6 +81,9 @@ port: 7890
# port of SOCKS5 # port of SOCKS5
socks-port: 7891 socks-port: 7891
# (HTTP and SOCKS5 in one port)
# mixed-port: 7890
# redir port for Linux and macOS # redir port for Linux and macOS
# redir-port: 7892 # redir-port: 7892
@ -394,4 +397,4 @@ https://clash.gitbook.io/
- [x] Redir proxy - [x] Redir proxy
- [x] UDP support - [x] UDP support
- [x] Connection manager - [x] Connection manager
- [ ] Event API - ~~[ ] Event API~~

View File

@ -70,8 +70,8 @@ func (t *Trojan) StreamConn(conn net.Conn) (net.Conn, error) {
func (t *Trojan) WriteHeader(w io.Writer, command Command, socks5Addr []byte) error { func (t *Trojan) WriteHeader(w io.Writer, command Command, socks5Addr []byte) error {
buf := bufPool.Get().(*bytes.Buffer) buf := bufPool.Get().(*bytes.Buffer)
defer buf.Reset()
defer bufPool.Put(buf) defer bufPool.Put(buf)
defer buf.Reset()
buf.Write(t.hexPassword) buf.Write(t.hexPassword)
buf.Write(crlf) buf.Write(crlf)
@ -92,8 +92,8 @@ func (t *Trojan) PacketConn(conn net.Conn) net.PacketConn {
func writePacket(w io.Writer, socks5Addr, payload []byte) (int, error) { func writePacket(w io.Writer, socks5Addr, payload []byte) (int, error) {
buf := bufPool.Get().(*bytes.Buffer) buf := bufPool.Get().(*bytes.Buffer)
defer buf.Reset()
defer bufPool.Put(buf) defer bufPool.Put(buf)
defer buf.Reset()
buf.Write(socks5Addr) buf.Write(socks5Addr)
binary.Write(buf, binary.BigEndian, uint16(len(payload))) binary.Write(buf, binary.BigEndian, uint16(len(payload)))

View File

@ -23,8 +23,8 @@ const (
type NetWork int type NetWork int
func (n *NetWork) String() string { func (n NetWork) String() string {
if *n == TCP { if n == TCP {
return "tcp" return "tcp"
} }
return "udp" return "udp"