fix metadata
This commit is contained in:
@ -1,22 +1,10 @@
|
||||
package ftcp
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
md "github.com/go-gost/core/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
dialTimeout = "dialTimeout"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultDialTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
dialTimeout time.Duration
|
||||
}
|
||||
type metadata struct{}
|
||||
|
||||
func (d *ftcpDialer) parseMetadata(md md.Metadata) (err error) {
|
||||
return
|
||||
|
@ -123,13 +123,16 @@ func (d *h2Dialer) Dial(ctx context.Context, address string, opts ...dialer.Dial
|
||||
req := &http.Request{
|
||||
Method: http.MethodConnect,
|
||||
URL: &url.URL{Scheme: "https", Host: host},
|
||||
Header: make(http.Header),
|
||||
Header: d.md.header,
|
||||
ProtoMajor: 2,
|
||||
ProtoMinor: 0,
|
||||
Body: pr,
|
||||
Host: host,
|
||||
// ContentLength: -1,
|
||||
}
|
||||
if req.Header == nil {
|
||||
req.Header = make(http.Header)
|
||||
}
|
||||
if d.md.path != "" {
|
||||
req.Method = http.MethodGet
|
||||
req.URL.Path = d.md.path
|
||||
|
@ -1,23 +1,33 @@
|
||||
package h2
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
mdx "github.com/go-gost/x/metadata"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
host string
|
||||
path string
|
||||
host string
|
||||
path string
|
||||
header http.Header
|
||||
}
|
||||
|
||||
func (d *h2Dialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
host = "host"
|
||||
path = "path"
|
||||
host = "host"
|
||||
path = "path"
|
||||
header = "header"
|
||||
)
|
||||
|
||||
d.md.host = mdx.GetString(md, host)
|
||||
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
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import (
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
}
|
||||
type metadata struct{}
|
||||
|
||||
func (d *http2Dialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
return
|
||||
|
@ -13,7 +13,6 @@ type metadata struct {
|
||||
handshakeTimeout time.Duration
|
||||
|
||||
cipherKey []byte
|
||||
host string
|
||||
}
|
||||
|
||||
func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@ -23,7 +22,6 @@ func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
maxIdleTimeout = "maxIdleTimeout"
|
||||
|
||||
cipherKey = "cipherKey"
|
||||
host = "host"
|
||||
)
|
||||
|
||||
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.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)
|
||||
|
||||
d.md.host = mdx.GetString(md, host)
|
||||
return
|
||||
}
|
||||
|
@ -24,17 +24,19 @@ type sshDialer struct {
|
||||
sessionMutex sync.Mutex
|
||||
logger logger.Logger
|
||||
md metadata
|
||||
options dialer.Options
|
||||
}
|
||||
|
||||
func NewDialer(opts ...dialer.Option) dialer.Dialer {
|
||||
options := &dialer.Options{}
|
||||
options := dialer.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
opt(&options)
|
||||
}
|
||||
|
||||
return &sshDialer{
|
||||
sessions: make(map[string]*sshSession),
|
||||
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,
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||
}
|
||||
if d.md.user != nil {
|
||||
config.User = d.md.user.Username()
|
||||
if password, _ := d.md.user.Password(); password != "" {
|
||||
if d.options.Auth != nil {
|
||||
config.User = d.options.Auth.Username()
|
||||
if password, _ := d.options.Auth.Password(); password != "" {
|
||||
config.Auth = []ssh.AuthMethod{
|
||||
ssh.Password(password),
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package ssh
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/core/metadata"
|
||||
@ -13,27 +11,16 @@ import (
|
||||
|
||||
type metadata struct {
|
||||
handshakeTimeout time.Duration
|
||||
user *url.Userinfo
|
||||
signer ssh.Signer
|
||||
}
|
||||
|
||||
func (d *sshDialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
handshakeTimeout = "handshakeTimeout"
|
||||
user = "user"
|
||||
privateKeyFile = "privateKeyFile"
|
||||
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 != "" {
|
||||
data, err := ioutil.ReadFile(key)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user