mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
support socks proxy in peer url and decouple explicit tor/i2p routing
This commit is contained in:
parent
769b058004
commit
7756891510
5 changed files with 74 additions and 61 deletions
|
@ -8,9 +8,13 @@ package yggdrasil
|
|||
|
||||
import _ "golang.org/x/net/ipv6" // TODO put this somewhere better
|
||||
|
||||
import "golang.org/x/net/proxy"
|
||||
|
||||
import "fmt"
|
||||
import "net"
|
||||
import "net/url"
|
||||
import "log"
|
||||
import "strings"
|
||||
import "regexp"
|
||||
|
||||
// Core
|
||||
|
@ -307,6 +311,54 @@ func (c *Core) DEBUG_maybeSendUDPKeys(saddr string) {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
func (c *Core) DEBUG_addPeer(addr string) {
|
||||
u, err := url.Parse(addr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(u.Opaque) == 0 {
|
||||
switch strings.ToLower(u.Scheme) {
|
||||
case "tcp":
|
||||
c.DEBUG_addTCPConn(u.Host)
|
||||
case "udp":
|
||||
c.DEBUG_maybeSendUDPKeys(u.Host)
|
||||
case "socks":
|
||||
c.DEBUG_addSOCKSConn(u.Host, u.Path[1:])
|
||||
default:
|
||||
panic("invalid peer: " + addr)
|
||||
}
|
||||
} else {
|
||||
// no url scheme provided
|
||||
addr = strings.ToLower(addr)
|
||||
if strings.HasPrefix(addr, "udp:") {
|
||||
c.DEBUG_maybeSendUDPKeys(addr[4:])
|
||||
} else {
|
||||
if strings.HasPrefix(addr, "tcp:") {
|
||||
addr = addr[4:]
|
||||
}
|
||||
c.DEBUG_addTCPConn(addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Core) DEBUG_addSOCKSConn(socksaddr, peeraddr string) {
|
||||
go func() {
|
||||
dialer, err := proxy.SOCKS5("tcp", socksaddr, nil, proxy.Direct)
|
||||
if err == nil {
|
||||
conn, err := dialer.Dial("tcp", peeraddr)
|
||||
if err == nil {
|
||||
c.tcp.callWithConn(&wrappedConn{
|
||||
c: conn,
|
||||
raddr: &wrappedAddr{
|
||||
network: "tcp",
|
||||
addr: peeraddr,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
//*
|
||||
func (c *Core) DEBUG_setupAndStartGlobalTCPInterface(addrport string) {
|
||||
iface := tcpInterface{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue