Skip to content

Commit

Permalink
chore: optimize codes (golint) and github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nadoo committed Dec 25, 2021
1 parent 40f75ef commit 5b1a127
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ jobs:
days-before-stale: 90
days-before-close: 5
exempt-issue-labels: "bug,enhancement"
exempt-pr-labels: "bug,enhancement"

4 changes: 1 addition & 3 deletions proxy/tproxy/tproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"golang.org/x/sys/unix"
)

const IPV6_RECVORIGDSTADDR = 0x4a

// ref: https://github.com/LiamHaworth/go-tproxy/blob/master/tproxy_udp.go
// MIT License by @LiamHaworth

Expand Down Expand Up @@ -65,7 +63,7 @@ func ReadFromUDP(conn *net.UDPConn, b []byte) (int, *net.UDPAddr, *net.UDPAddr,
port := binary.BigEndian.Uint16(msg.Data[2:4])
return n, addr, &net.UDPAddr{IP: ip, Port: int(port)}, nil
}
if msg.Header.Level == syscall.SOL_IPV6 && msg.Header.Type == IPV6_RECVORIGDSTADDR {
if msg.Header.Level == syscall.SOL_IPV6 && msg.Header.Type == unix.IPV6_RECVORIGDSTADDR {
ip := net.IP(msg.Data[8:24])
port := binary.BigEndian.Uint16(msg.Data[2:4])
return n, addr, &net.UDPAddr{IP: ip, Port: int(port)}, nil
Expand Down
5 changes: 5 additions & 0 deletions proxy/vmess/chunk_size_parser.go → proxy/vmess/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ type ChunkSizeDecoder interface {
Decode([]byte) (uint16, error)
}

// ShakeSizeParser implements ChunkSizeEncoder & ChunkSizeDecoder.
type ShakeSizeParser struct {
shake sha3.ShakeHash
buffer [2]byte
}

// NewShakeSizeParser returns a new ShakeSizeParser.
func NewShakeSizeParser(nonce []byte) *ShakeSizeParser {
shake := sha3.NewShake128()
shake.Write(nonce)
Expand All @@ -31,6 +33,7 @@ func NewShakeSizeParser(nonce []byte) *ShakeSizeParser {
}
}

// SizeBytes implements ChunkSizeEncoder method.
func (*ShakeSizeParser) SizeBytes() int32 {
return 2
}
Expand All @@ -40,12 +43,14 @@ func (s *ShakeSizeParser) next() uint16 {
return binary.BigEndian.Uint16(s.buffer[:])
}

// Decode implements ChunkSizeDecoder method.
func (s *ShakeSizeParser) Decode(b []byte) (uint16, error) {
mask := s.next()
size := binary.BigEndian.Uint16(b)
return mask ^ size, nil
}

// Encode implements ChunkSizeEncoder method.
func (s *ShakeSizeParser) Encode(size uint16, b []byte) []byte {
mask := s.next()
binary.BigEndian.PutUint16(b, mask^size)
Expand Down

0 comments on commit 5b1a127

Please sign in to comment.