parent
f94293b454
commit
31aee78e79
25
chain.go
25
chain.go
@ -3,6 +3,7 @@ package gost
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -38,11 +39,13 @@ func NewChain(nodes ...Node) *Chain {
|
|||||||
// newRoute creates a chain route.
|
// newRoute creates a chain route.
|
||||||
// a chain route is the final route after node selection.
|
// a chain route is the final route after node selection.
|
||||||
func (c *Chain) newRoute(nodes ...Node) *Chain {
|
func (c *Chain) newRoute(nodes ...Node) *Chain {
|
||||||
chain := NewChain(nodes...)
|
route := NewChain(nodes...)
|
||||||
chain.isRoute = true
|
route.isRoute = true
|
||||||
chain.Interface = c.Interface
|
if !c.IsEmpty() {
|
||||||
chain.Mark = c.Mark
|
route.Interface = c.Interface
|
||||||
return chain
|
route.Mark = c.Mark
|
||||||
|
}
|
||||||
|
return route
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nodes returns the proxy nodes that the chain holds.
|
// Nodes returns the proxy nodes that the chain holds.
|
||||||
@ -140,6 +143,9 @@ func (c *Chain) dialWithOptions(ctx context.Context, network, address string, op
|
|||||||
if options == nil {
|
if options == nil {
|
||||||
options = &ChainOptions{}
|
options = &ChainOptions{}
|
||||||
}
|
}
|
||||||
|
if c == nil {
|
||||||
|
c = &Chain{}
|
||||||
|
}
|
||||||
route, err := c.selectRouteFor(address)
|
route, err := c.selectRouteFor(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -149,6 +155,9 @@ func (c *Chain) dialWithOptions(ctx context.Context, network, address string, op
|
|||||||
if address != "" {
|
if address != "" {
|
||||||
ipAddr = c.resolve(address, options.Resolver, options.Hosts)
|
ipAddr = c.resolve(address, options.Resolver, options.Hosts)
|
||||||
}
|
}
|
||||||
|
if ipAddr == "" {
|
||||||
|
return nil, fmt.Errorf("resolver: domain %s does not exists", address)
|
||||||
|
}
|
||||||
|
|
||||||
timeout := options.Timeout
|
timeout := options.Timeout
|
||||||
if timeout <= 0 {
|
if timeout <= 0 {
|
||||||
@ -225,9 +234,11 @@ func (*Chain) resolve(addr string, resolver Resolver, hosts *Hosts) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Logf("[resolver] %s: %v", host, err)
|
log.Logf("[resolver] %s: %v", host, err)
|
||||||
}
|
}
|
||||||
if len(ips) > 0 {
|
if len(ips) == 0 {
|
||||||
return net.JoinHostPort(ips[0].String(), port)
|
log.Logf("[resolver] %s: domain does not exists", host)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
return net.JoinHostPort(ips[0].String(), port)
|
||||||
}
|
}
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -10,7 +10,7 @@ require (
|
|||||||
github.com/go-gost/gosocks4 v0.0.1
|
github.com/go-gost/gosocks4 v0.0.1
|
||||||
github.com/go-gost/gosocks5 v0.3.0
|
github.com/go-gost/gosocks5 v0.3.0
|
||||||
github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7
|
github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7
|
||||||
github.com/go-gost/tls-dissector v0.0.2-0.20211125135007-2b5d5bd9c07e
|
github.com/go-gost/tls-dissector v0.0.2-0.20220408131628-aac992c27451
|
||||||
github.com/go-log/log v0.2.0
|
github.com/go-log/log v0.2.0
|
||||||
github.com/gobwas/glob v0.2.3
|
github.com/gobwas/glob v0.2.3
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
|
4
go.sum
4
go.sum
@ -58,8 +58,8 @@ github.com/go-gost/gosocks5 v0.3.0 h1:Hkmp9YDRBSCJd7xywW6dBPT6B9aQTkuWd+3WCheJiJ
|
|||||||
github.com/go-gost/gosocks5 v0.3.0/go.mod h1:1G6I7HP7VFVxveGkoK8mnprnJqSqJjdcASKsdUn4Pp4=
|
github.com/go-gost/gosocks5 v0.3.0/go.mod h1:1G6I7HP7VFVxveGkoK8mnprnJqSqJjdcASKsdUn4Pp4=
|
||||||
github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7 h1:itaaJhQJ19kUXEB4Igb0EbY8m+1Py2AaNNSBds/9gk4=
|
github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7 h1:itaaJhQJ19kUXEB4Igb0EbY8m+1Py2AaNNSBds/9gk4=
|
||||||
github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7/go.mod h1:lcX+23LCQ3khIeASBo+tJ/WbwXFO32/N5YN6ucuYTG8=
|
github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7/go.mod h1:lcX+23LCQ3khIeASBo+tJ/WbwXFO32/N5YN6ucuYTG8=
|
||||||
github.com/go-gost/tls-dissector v0.0.2-0.20211125135007-2b5d5bd9c07e h1:73NGqAs22ey3wJkIYVD/ACEoovuIuOlEzQTEoqrO5+U=
|
github.com/go-gost/tls-dissector v0.0.2-0.20220408131628-aac992c27451 h1:xj8gUZGYO3nb5+6Bjw9+tsFkA9sYynrOvDvvC4uDV2I=
|
||||||
github.com/go-gost/tls-dissector v0.0.2-0.20211125135007-2b5d5bd9c07e/go.mod h1:/9QfdewqmHdaE362Hv5nDaSWLx3pCmtD870d6GaquXs=
|
github.com/go-gost/tls-dissector v0.0.2-0.20220408131628-aac992c27451/go.mod h1:/9QfdewqmHdaE362Hv5nDaSWLx3pCmtD870d6GaquXs=
|
||||||
github.com/go-log/log v0.2.0 h1:z8i91GBudxD5L3RmF0KVpetCbcGWAV7q1Tw1eRwQM9Q=
|
github.com/go-log/log v0.2.0 h1:z8i91GBudxD5L3RmF0KVpetCbcGWAV7q1Tw1eRwQM9Q=
|
||||||
github.com/go-log/log v0.2.0/go.mod h1:xzCnwajcues/6w7lne3yK2QU7DBPW7kqbgPGG5AF65U=
|
github.com/go-log/log v0.2.0/go.mod h1:xzCnwajcues/6w7lne3yK2QU7DBPW7kqbgPGG5AF65U=
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
|
||||||
|
@ -7,6 +7,7 @@ description: |
|
|||||||
Wiki: https://v2.gost.run
|
Wiki: https://v2.gost.run
|
||||||
icon: gost.png
|
icon: gost.png
|
||||||
website: https://v2.gost.run
|
website: https://v2.gost.run
|
||||||
|
license: MIT
|
||||||
|
|
||||||
|
|
||||||
confinement: strict
|
confinement: strict
|
||||||
|
Loading…
Reference in New Issue
Block a user