chore: optimize codes (golint) and github actions

This commit is contained in:
nadoo 2021-12-25 17:55:39 +08:00
parent 40f75ef38b
commit 5b1a127d04
3 changed files with 8 additions and 3 deletions

View File

@ -13,3 +13,5 @@ jobs:
days-before-stale: 90
days-before-close: 5
exempt-issue-labels: "bug,enhancement"
exempt-pr-labels: "bug,enhancement"

View File

@ -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
@ -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

View File

@ -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)
@ -31,6 +33,7 @@ func NewShakeSizeParser(nonce []byte) *ShakeSizeParser {
}
}
// SizeBytes implements ChunkSizeEncoder method.
func (*ShakeSizeParser) SizeBytes() int32 {
return 2
}
@ -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)