fix metadata
This commit is contained in:
parent
1415462d23
commit
d011aefefd
@ -1,22 +1,10 @@
|
|||||||
package ftcp
|
package ftcp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
md "github.com/go-gost/core/metadata"
|
md "github.com/go-gost/core/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
type metadata struct{}
|
||||||
dialTimeout = "dialTimeout"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
defaultDialTimeout = 5 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
type metadata struct {
|
|
||||||
dialTimeout time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *ftcpDialer) parseMetadata(md md.Metadata) (err error) {
|
func (d *ftcpDialer) parseMetadata(md md.Metadata) (err error) {
|
||||||
return
|
return
|
||||||
|
@ -123,13 +123,16 @@ func (d *h2Dialer) Dial(ctx context.Context, address string, opts ...dialer.Dial
|
|||||||
req := &http.Request{
|
req := &http.Request{
|
||||||
Method: http.MethodConnect,
|
Method: http.MethodConnect,
|
||||||
URL: &url.URL{Scheme: "https", Host: host},
|
URL: &url.URL{Scheme: "https", Host: host},
|
||||||
Header: make(http.Header),
|
Header: d.md.header,
|
||||||
ProtoMajor: 2,
|
ProtoMajor: 2,
|
||||||
ProtoMinor: 0,
|
ProtoMinor: 0,
|
||||||
Body: pr,
|
Body: pr,
|
||||||
Host: host,
|
Host: host,
|
||||||
// ContentLength: -1,
|
// ContentLength: -1,
|
||||||
}
|
}
|
||||||
|
if req.Header == nil {
|
||||||
|
req.Header = make(http.Header)
|
||||||
|
}
|
||||||
if d.md.path != "" {
|
if d.md.path != "" {
|
||||||
req.Method = http.MethodGet
|
req.Method = http.MethodGet
|
||||||
req.URL.Path = d.md.path
|
req.URL.Path = d.md.path
|
||||||
|
@ -1,23 +1,33 @@
|
|||||||
package h2
|
package h2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
mdata "github.com/go-gost/core/metadata"
|
mdata "github.com/go-gost/core/metadata"
|
||||||
mdx "github.com/go-gost/x/metadata"
|
mdx "github.com/go-gost/x/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
type metadata struct {
|
type metadata struct {
|
||||||
host string
|
host string
|
||||||
path string
|
path string
|
||||||
|
header http.Header
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *h2Dialer) parseMetadata(md mdata.Metadata) (err error) {
|
func (d *h2Dialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
const (
|
const (
|
||||||
host = "host"
|
host = "host"
|
||||||
path = "path"
|
path = "path"
|
||||||
|
header = "header"
|
||||||
)
|
)
|
||||||
|
|
||||||
d.md.host = mdx.GetString(md, host)
|
d.md.host = mdx.GetString(md, host)
|
||||||
d.md.path = mdx.GetString(md, path)
|
d.md.path = mdx.GetString(md, path)
|
||||||
|
if m := mdx.GetStringMapString(md, header); len(m) > 0 {
|
||||||
|
h := http.Header{}
|
||||||
|
for k, v := range m {
|
||||||
|
h.Add(k, v)
|
||||||
|
}
|
||||||
|
d.md.header = h
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ import (
|
|||||||
mdata "github.com/go-gost/core/metadata"
|
mdata "github.com/go-gost/core/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
type metadata struct {
|
type metadata struct{}
|
||||||
}
|
|
||||||
|
|
||||||
func (d *http2Dialer) parseMetadata(md mdata.Metadata) (err error) {
|
func (d *http2Dialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
return
|
return
|
||||||
|
@ -13,7 +13,6 @@ type metadata struct {
|
|||||||
handshakeTimeout time.Duration
|
handshakeTimeout time.Duration
|
||||||
|
|
||||||
cipherKey []byte
|
cipherKey []byte
|
||||||
host string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
|
func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
@ -23,7 +22,6 @@ func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
|
|||||||
maxIdleTimeout = "maxIdleTimeout"
|
maxIdleTimeout = "maxIdleTimeout"
|
||||||
|
|
||||||
cipherKey = "cipherKey"
|
cipherKey = "cipherKey"
|
||||||
host = "host"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
|
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
|
||||||
@ -36,6 +34,5 @@ func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
|
|||||||
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
|
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
|
||||||
d.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)
|
d.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)
|
||||||
|
|
||||||
d.md.host = mdx.GetString(md, host)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -24,17 +24,19 @@ type sshDialer struct {
|
|||||||
sessionMutex sync.Mutex
|
sessionMutex sync.Mutex
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
md metadata
|
md metadata
|
||||||
|
options dialer.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDialer(opts ...dialer.Option) dialer.Dialer {
|
func NewDialer(opts ...dialer.Option) dialer.Dialer {
|
||||||
options := &dialer.Options{}
|
options := dialer.Options{}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(options)
|
opt(&options)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &sshDialer{
|
return &sshDialer{
|
||||||
sessions: make(map[string]*sshSession),
|
sessions: make(map[string]*sshSession),
|
||||||
logger: options.Logger,
|
logger: options.Logger,
|
||||||
|
options: options,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,9 +141,9 @@ func (d *sshDialer) initSession(ctx context.Context, addr string, conn net.Conn)
|
|||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||||
}
|
}
|
||||||
if d.md.user != nil {
|
if d.options.Auth != nil {
|
||||||
config.User = d.md.user.Username()
|
config.User = d.options.Auth.Username()
|
||||||
if password, _ := d.md.user.Password(); password != "" {
|
if password, _ := d.options.Auth.Password(); password != "" {
|
||||||
config.Auth = []ssh.AuthMethod{
|
config.Auth = []ssh.AuthMethod{
|
||||||
ssh.Password(password),
|
ssh.Password(password),
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@ package ssh
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
mdata "github.com/go-gost/core/metadata"
|
mdata "github.com/go-gost/core/metadata"
|
||||||
@ -13,27 +11,16 @@ import (
|
|||||||
|
|
||||||
type metadata struct {
|
type metadata struct {
|
||||||
handshakeTimeout time.Duration
|
handshakeTimeout time.Duration
|
||||||
user *url.Userinfo
|
|
||||||
signer ssh.Signer
|
signer ssh.Signer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *sshDialer) parseMetadata(md mdata.Metadata) (err error) {
|
func (d *sshDialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
const (
|
const (
|
||||||
handshakeTimeout = "handshakeTimeout"
|
handshakeTimeout = "handshakeTimeout"
|
||||||
user = "user"
|
|
||||||
privateKeyFile = "privateKeyFile"
|
privateKeyFile = "privateKeyFile"
|
||||||
passphrase = "passphrase"
|
passphrase = "passphrase"
|
||||||
)
|
)
|
||||||
|
|
||||||
if v := mdx.GetString(md, user); v != "" {
|
|
||||||
ss := strings.SplitN(v, ":", 2)
|
|
||||||
if len(ss) == 1 {
|
|
||||||
d.md.user = url.User(ss[0])
|
|
||||||
} else {
|
|
||||||
d.md.user = url.UserPassword(ss[0], ss[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if key := mdx.GetString(md, privateKeyFile); key != "" {
|
if key := mdx.GetString(md, privateKeyFile); key != "" {
|
||||||
data, err := ioutil.ReadFile(key)
|
data, err := ioutil.ReadFile(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
|||||||
github.com/docker/libcontainer v2.2.1+incompatible
|
github.com/docker/libcontainer v2.2.1+incompatible
|
||||||
github.com/gin-contrib/cors v1.3.1
|
github.com/gin-contrib/cors v1.3.1
|
||||||
github.com/gin-gonic/gin v1.7.7
|
github.com/gin-gonic/gin v1.7.7
|
||||||
github.com/go-gost/core v0.0.0-20220405145417-b88025ea6d67
|
github.com/go-gost/core v0.0.0-20220407150135-aeda8b11ca46
|
||||||
github.com/go-gost/gosocks4 v0.0.1
|
github.com/go-gost/gosocks4 v0.0.1
|
||||||
github.com/go-gost/gosocks5 v0.3.1-0.20211109033403-d894d75b7f09
|
github.com/go-gost/gosocks5 v0.3.1-0.20211109033403-d894d75b7f09
|
||||||
github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7
|
github.com/go-gost/relay v0.1.1-0.20211123134818-8ef7fd81ffd7
|
||||||
|
6
go.sum
6
go.sum
@ -119,10 +119,8 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm
|
|||||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
github.com/go-gost/core v0.0.0-20220405095520-c2f49e94443c h1:TzDyqefjnUVgdT6piHZgeXrVKXevawsMs0kmSZZhDR4=
|
github.com/go-gost/core v0.0.0-20220407150135-aeda8b11ca46 h1:5Bg5OiSt1thHi03n9oiKptsfYzvgpOHuoLi4eAQOSSs=
|
||||||
github.com/go-gost/core v0.0.0-20220405095520-c2f49e94443c/go.mod h1:/LzdiQ+0+3FMhyqw0phjFjXFdOa1fcQR5/bL/7ripCs=
|
github.com/go-gost/core v0.0.0-20220407150135-aeda8b11ca46/go.mod h1:bHVbCS9da6XtKNYMkMUVcck5UqDDUkyC37erVfs4GXQ=
|
||||||
github.com/go-gost/core v0.0.0-20220405145417-b88025ea6d67 h1:qKtSDjOdQcNNLUTifLtI12fcZm6STp9Lsp5Bj962Gx0=
|
|
||||||
github.com/go-gost/core v0.0.0-20220405145417-b88025ea6d67/go.mod h1:/LzdiQ+0+3FMhyqw0phjFjXFdOa1fcQR5/bL/7ripCs=
|
|
||||||
github.com/go-gost/gosocks4 v0.0.1 h1:+k1sec8HlELuQV7rWftIkmy8UijzUt2I6t+iMPlGB2s=
|
github.com/go-gost/gosocks4 v0.0.1 h1:+k1sec8HlELuQV7rWftIkmy8UijzUt2I6t+iMPlGB2s=
|
||||||
github.com/go-gost/gosocks4 v0.0.1/go.mod h1:3B6L47HbU/qugDg4JnoFPHgJXE43Inz8Bah1QaN9qCc=
|
github.com/go-gost/gosocks4 v0.0.1/go.mod h1:3B6L47HbU/qugDg4JnoFPHgJXE43Inz8Bah1QaN9qCc=
|
||||||
github.com/go-gost/gosocks5 v0.3.1-0.20211109033403-d894d75b7f09 h1:A95M6UWcfZgOuJkQ7QLfG0Hs5peWIUSysCDNz4pfe04=
|
github.com/go-gost/gosocks5 v0.3.1-0.20211109033403-d894d75b7f09 h1:A95M6UWcfZgOuJkQ7QLfG0Hs5peWIUSysCDNz4pfe04=
|
||||||
|
@ -62,7 +62,7 @@ func NewMetrics() metrics.Metrics {
|
|||||||
Name: string(metrics.MetricChainErrorsCounter),
|
Name: string(metrics.MetricChainErrorsCounter),
|
||||||
Help: "Total chain errors",
|
Help: "Total chain errors",
|
||||||
},
|
},
|
||||||
[]string{"host", "chain"}),
|
[]string{"host", "chain", "node"}),
|
||||||
},
|
},
|
||||||
histograms: map[metrics.MetricName]*prometheus.HistogramVec{
|
histograms: map[metrics.MetricName]*prometheus.HistogramVec{
|
||||||
metrics.MetricServiceRequestsDurationObserver: prometheus.NewHistogramVec(
|
metrics.MetricServiceRequestsDurationObserver: prometheus.NewHistogramVec(
|
||||||
|
Loading…
Reference in New Issue
Block a user