dialer: add bind device

This commit is contained in:
ginuerzh
2022-03-02 21:36:27 +08:00
parent ffdf11e89e
commit b96d37d4cc
29 changed files with 348 additions and 225 deletions

View File

@ -64,11 +64,14 @@ func (d *quicDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialO
opt(options)
}
netd := options.NetDialer
if netd == nil {
netd = dialer.DefaultNetDialer
host := d.md.host
if host == "" {
host = options.Host
}
conn, err = netd.Dial(ctx, "udp", "")
if h, _, _ := net.SplitHostPort(host); h != "" {
host = h
}
conn, err = options.NetDialer.Dial(ctx, "udp", "")
if err != nil {
return nil, err
}

View File

@ -12,6 +12,7 @@ type metadata struct {
handshakeTimeout time.Duration
cipherKey []byte
host string
}
func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
@ -21,6 +22,7 @@ func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
maxIdleTimeout = "maxIdleTimeout"
cipherKey = "cipherKey"
host = "host"
)
d.md.handshakeTimeout = mdata.GetDuration(md, handshakeTimeout)
@ -32,5 +34,7 @@ func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
d.md.keepAlive = mdata.GetBool(md, keepAlive)
d.md.handshakeTimeout = mdata.GetDuration(md, handshakeTimeout)
d.md.maxIdleTimeout = mdata.GetDuration(md, maxIdleTimeout)
d.md.host = mdata.GetString(md, host)
return
}