fix dtls connection
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"github.com/go-gost/core/dialer"
|
||||
"github.com/go-gost/core/logger"
|
||||
md "github.com/go-gost/core/metadata"
|
||||
xdtls "github.com/go-gost/x/internal/util/dtls"
|
||||
"github.com/go-gost/x/registry"
|
||||
"github.com/pion/dtls/v2"
|
||||
)
|
||||
@ -65,5 +66,9 @@ func (d *dtlsDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialO
|
||||
MTU: d.md.mtu,
|
||||
}
|
||||
|
||||
return dtls.ClientWithContext(ctx, conn, &config)
|
||||
c, err := dtls.ClientWithContext(ctx, conn, &config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return xdtls.Conn(c, d.md.bufferSize), nil
|
||||
}
|
||||
|
@ -7,18 +7,22 @@ import (
|
||||
mdutil "github.com/go-gost/core/metadata/util"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultBufferSize = 1200
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
mtu int
|
||||
bufferSize int
|
||||
flightInterval time.Duration
|
||||
}
|
||||
|
||||
func (d *dtlsDialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
mtu = "mtu"
|
||||
flightInterval = "flightInterval"
|
||||
)
|
||||
|
||||
d.md.mtu = mdutil.GetInt(md, mtu)
|
||||
d.md.flightInterval = mdutil.GetDuration(md, flightInterval)
|
||||
d.md.mtu = mdutil.GetInt(md, "dtls.mtu", "mtu")
|
||||
d.md.bufferSize = mdutil.GetInt(md, "dtls.bufferSize", "bufferSize")
|
||||
if d.md.bufferSize <= 0 {
|
||||
d.md.bufferSize = defaultBufferSize
|
||||
}
|
||||
d.md.flightInterval = mdutil.GetDuration(md, "dtls.flightInterval", "flightInterval")
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user