chore: move common stuff to common.go

This commit is contained in:
Toby 2022-11-02 21:23:16 -07:00
parent 6ac5e0e455
commit 0119024392
2 changed files with 23 additions and 20 deletions

View File

@ -6,6 +6,11 @@ import (
"strings"
)
const (
packetQueueSize = 1024
udpBufferSize = 2048
)
// parseAddr parses the listen address and returns the host and ports.
// Format: "host:port1,port2,port3,..."
func parseAddr(addr string) (host string, ports []uint16, err error) {
@ -27,3 +32,21 @@ func parseAddr(addr string) (host string, ports []uint16, err error) {
}
return
}
type udpHopAddr struct {
listen string
}
func (a *udpHopAddr) Network() string {
return "udp-hop"
}
func (a *udpHopAddr) String() string {
return a.listen
}
type udpPacket struct {
buf []byte
n int
addr net.Addr
}

View File

@ -12,8 +12,6 @@ import (
)
const (
packetQueueSize = 1024
udpBufferSize = 2048
addrMapEntryTTL = time.Minute
)
@ -32,29 +30,11 @@ type ObfsUDPHopServerPacketConn struct {
bufPool sync.Pool
}
type udpPacket struct {
buf []byte
n int
addr net.Addr
}
type addrMapEntry struct {
index int
last time.Time
}
type udpHopAddr struct {
listen string
}
func (a *udpHopAddr) Network() string {
return "udp-hop"
}
func (a *udpHopAddr) String() string {
return a.listen
}
func NewObfsUDPHopServerPacketConn(listen string, obfs obfs.Obfuscator) (*ObfsUDPHopServerPacketConn, error) {
host, ports, err := parseAddr(listen)
if err != nil {