From f5c63cde56eb35c0125a0545f084441cdd4340ab Mon Sep 17 00:00:00 2001 From: Keuin Date: Tue, 11 Jul 2023 22:56:07 +0800 Subject: Refactor: move data structures to a separate package to avoid circular dependency. --- bilibili/netprobe.go | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) (limited to 'bilibili/netprobe.go') diff --git a/bilibili/netprobe.go b/bilibili/netprobe.go index 419cc20..3c9ad4a 100644 --- a/bilibili/netprobe.go +++ b/bilibili/netprobe.go @@ -2,44 +2,19 @@ package bilibili import ( "context" - "fmt" + "github.com/keuin/slbr/types" "net" ) -type IpNetType string - -var ( - IPv6Net IpNetType = "ipv6" - IPv4Net IpNetType = "ipv4" - IP64 IpNetType = "any" -) - -// GetDialNetString returns the string accepted by net.Dialer::DialContext -func (t IpNetType) GetDialNetString() string { - switch t { - case IPv4Net: - return "tcp4" - case IPv6Net: - return "tcp6" - case IP64: - return "tcp" - } - return "" -} - -func (t IpNetType) String() string { - return fmt.Sprintf("%s(%s)", string(t), t.GetDialNetString()) -} - type netContext = func(context.Context, string, string) (net.Conn, error) type netProbe struct { - list []IpNetType + list []types.IpNetType i int } -func newNetProbe(protocols []IpNetType) netProbe { - var netList []IpNetType +func newNetProbe(protocols []types.IpNetType) netProbe { + var netList []types.IpNetType netList = append(netList, protocols...) return netProbe{ list: netList, @@ -47,9 +22,9 @@ func newNetProbe(protocols []IpNetType) netProbe { } } -func (p *netProbe) NextNetworkType(dialer net.Dialer) (netContext, IpNetType) { +func (p *netProbe) NextNetworkType(dialer net.Dialer) (netContext, types.IpNetType) { if p.i >= len(p.list) { - return nil, IP64 + return nil, types.IP64 } network := p.list[p.i] p.i++ -- cgit v1.2.3