add sockopts config

This commit is contained in:
ginuerzh
2022-03-29 23:04:12 +08:00
parent 78089d8887
commit 47cfc087e9
11 changed files with 115 additions and 36 deletions

View File

@ -13,10 +13,15 @@ import (
"github.com/go-gost/core/resolver"
)
type SockOpts struct {
Mark int
}
type Router struct {
ifceName string
sockOpts *SockOpts
timeout time.Duration
retries int
ifceName string
chain Chainer
resolver resolver.Resolver
hosts hosts.HostMapper
@ -38,6 +43,11 @@ func (r *Router) WithInterface(ifceName string) *Router {
return r
}
func (r *Router) WithSockOpts(so *SockOpts) *Router {
r.sockOpts = so
return r
}
func (r *Router) WithChain(chain Chainer) *Router {
r.chain = chain
return r
@ -109,10 +119,11 @@ func (r *Router) dial(ctx context.Context, network, address string) (conn net.Co
if route == nil {
route = &Route{}
}
route.ifceName = r.ifceName
route.logger = r.logger
conn, err = route.Dial(ctx, network, address)
conn, err = route.Dial(ctx, network, address,
InterfaceDialOption(r.ifceName),
SockOptsDialOption(r.sockOpts),
)
if err == nil {
break
}