mirror of
https://github.com/go-i2p/go-gitlooseleaf.git
synced 2025-07-03 17:59:45 -04:00
Use metadialer instead of reproducing code from elsewhere
This commit is contained in:
5
go.mod
5
go.mod
@ -1,17 +1,18 @@
|
|||||||
module github.com/go-i2p/go-gittisane
|
module github.com/go-i2p/go-gittisane
|
||||||
|
|
||||||
go 1.23.5
|
go 1.24.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15
|
github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15
|
||||||
|
github.com/go-i2p/go-meta-dialer v0.0.0-20250501024057-715e91be3cfe
|
||||||
github.com/go-i2p/go-meta-listener v0.0.4-0.20250501044535-ab41cecda529
|
github.com/go-i2p/go-meta-listener v0.0.4-0.20250501044535-ab41cecda529
|
||||||
github.com/go-i2p/onramp v0.33.92
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cretz/bine v0.2.0 // indirect
|
github.com/cretz/bine v0.2.0 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
github.com/go-i2p/i2pkeys v0.33.10-0.20241113193422-e10de5e60708 // indirect
|
github.com/go-i2p/i2pkeys v0.33.10-0.20241113193422-e10de5e60708 // indirect
|
||||||
|
github.com/go-i2p/onramp v0.33.92 // indirect
|
||||||
github.com/go-i2p/sam3 v0.33.9 // indirect
|
github.com/go-i2p/sam3 v0.33.9 // indirect
|
||||||
github.com/opd-ai/wileedot v0.0.0-20241217172720-521d4175e624 // indirect
|
github.com/opd-ai/wileedot v0.0.0-20241217172720-521d4175e624 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -6,6 +6,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
|
|||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15 h1:ASjMbwlepoDQfrhv+H2B5ICBPJU5ES1JzmOxzPDx3YQ=
|
github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15 h1:ASjMbwlepoDQfrhv+H2B5ICBPJU5ES1JzmOxzPDx3YQ=
|
||||||
github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15/go.mod h1:4jjmVRhvKj47sQ6B6wdDhN1IrEZunE6KwkYLQx/BeVE=
|
github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15/go.mod h1:4jjmVRhvKj47sQ6B6wdDhN1IrEZunE6KwkYLQx/BeVE=
|
||||||
|
github.com/go-i2p/go-meta-dialer v0.0.0-20250501024057-715e91be3cfe h1:9Rxw2KtMCRKZHI4WavUAaatzKmc64V6kiYvcyTMHjeU=
|
||||||
|
github.com/go-i2p/go-meta-dialer v0.0.0-20250501024057-715e91be3cfe/go.mod h1:++xHSOvnGymRSyFbi9A9hztcfwKfU6/nJAtVxrNo8Zo=
|
||||||
github.com/go-i2p/go-meta-listener v0.0.4-0.20250501044535-ab41cecda529 h1:NjoB0lFjeIumL2r4h+ychfelK6Fnjsi2Lt9ia9exvf8=
|
github.com/go-i2p/go-meta-listener v0.0.4-0.20250501044535-ab41cecda529 h1:NjoB0lFjeIumL2r4h+ychfelK6Fnjsi2Lt9ia9exvf8=
|
||||||
github.com/go-i2p/go-meta-listener v0.0.4-0.20250501044535-ab41cecda529/go.mod h1:wF/MCCfB40gZyT9WtuYWQkUOPrnoTzA+NG0zpsy3s4M=
|
github.com/go-i2p/go-meta-listener v0.0.4-0.20250501044535-ab41cecda529/go.mod h1:wF/MCCfB40gZyT9WtuYWQkUOPrnoTzA+NG0zpsy3s4M=
|
||||||
github.com/go-i2p/i2pkeys v0.0.0-20241108200332-e4f5ccdff8c4/go.mod h1:m5TlHjPZrU5KbTd7Lr+I2rljyC6aJ88HdkeMQXV0U0E=
|
github.com/go-i2p/i2pkeys v0.0.0-20241108200332-e4f5ccdff8c4/go.mod h1:m5TlHjPZrU5KbTd7Lr+I2rljyC6aJ88HdkeMQXV0U0E=
|
||||||
|
@ -2,43 +2,10 @@ package graceful
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-i2p/onramp"
|
metadialer "github.com/go-i2p/go-meta-dialer"
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
Garlic, GarlicErr = onramp.NewGarlic("git-looseleaf", "127.0.0.1:7656", onramp.OPT_WIDE)
|
|
||||||
Onion, OnionErr = onramp.NewOnion("git-looseleaf")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Dial(network, addr string) (net.Conn, error) {
|
func Dial(network, addr string) (net.Conn, error) {
|
||||||
// convert the addr to a URL
|
return metadialer.Dial(network, addr)
|
||||||
url, err := url.Parse(addr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// get the domain name
|
|
||||||
domain := url.Hostname()
|
|
||||||
// get the top-level domain
|
|
||||||
fr := strings.Split(domain, ".")
|
|
||||||
tld := fr[len(fr)-1]
|
|
||||||
switch tld {
|
|
||||||
case "i2p":
|
|
||||||
if GarlicErr != nil {
|
|
||||||
return nil, GarlicErr
|
|
||||||
}
|
|
||||||
// I2P is a special case, we need to use the garlic dialer
|
|
||||||
return Garlic.Dial("i2p", addr)
|
|
||||||
case "onion":
|
|
||||||
if OnionErr != nil {
|
|
||||||
return nil, OnionErr
|
|
||||||
}
|
|
||||||
// Onion is a special case, we need to use the onion dialer
|
|
||||||
return Onion.Dial("onion", addr)
|
|
||||||
default:
|
|
||||||
// For everything else, we can use the default dialer
|
|
||||||
return net.Dial(network, addr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user