mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-20 11:19:50 +00:00
chore: move common stuff to common.go
This commit is contained in:
parent
6ac5e0e455
commit
0119024392
@ -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
|
||||
}
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user