From 0119024392a6ce906456d2f4cc2a6e509897c891 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 2 Nov 2022 21:23:16 -0700 Subject: [PATCH] chore: move common stuff to common.go --- .../pktconns/udphop/{parse.go => common.go} | 23 +++++++++++++++++++ pkg/transport/pktconns/udphop/server.go | 20 ---------------- 2 files changed, 23 insertions(+), 20 deletions(-) rename pkg/transport/pktconns/udphop/{parse.go => common.go} (70%) diff --git a/pkg/transport/pktconns/udphop/parse.go b/pkg/transport/pktconns/udphop/common.go similarity index 70% rename from pkg/transport/pktconns/udphop/parse.go rename to pkg/transport/pktconns/udphop/common.go index 386a4d5..cfe13e5 100644 --- a/pkg/transport/pktconns/udphop/parse.go +++ b/pkg/transport/pktconns/udphop/common.go @@ -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 +} diff --git a/pkg/transport/pktconns/udphop/server.go b/pkg/transport/pktconns/udphop/server.go index 02af6fa..ecc13a2 100644 --- a/pkg/transport/pktconns/udphop/server.go +++ b/pkg/transport/pktconns/udphop/server.go @@ -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 {