add tun/tap

This commit is contained in:
ginuerzh
2021-12-20 22:00:08 +08:00
parent a853d99d92
commit e21c35a47f
73 changed files with 1867 additions and 614 deletions

View File

@ -1,11 +1,12 @@
package relay
import (
"math"
"strings"
"time"
"github.com/go-gost/gost/pkg/auth"
md "github.com/go-gost/gost/pkg/metadata"
mdata "github.com/go-gost/gost/pkg/metadata"
)
type metadata struct {
@ -17,7 +18,7 @@ type metadata struct {
noDelay bool
}
func (h *relayHandler) parseMetadata(md md.Metadata) (err error) {
func (h *relayHandler) parseMetadata(md mdata.Metadata) (err error) {
const (
users = "users"
readTimeout = "readTimeout"
@ -27,7 +28,7 @@ func (h *relayHandler) parseMetadata(md md.Metadata) (err error) {
noDelay = "nodelay"
)
if auths := md.GetStrings(users); len(auths) > 0 {
if auths := mdata.GetStrings(md, users); len(auths) > 0 {
authenticator := auth.NewLocalAuthenticator(nil)
for _, auth := range auths {
ss := strings.SplitN(auth, ":", 2)
@ -40,20 +41,15 @@ func (h *relayHandler) parseMetadata(md md.Metadata) (err error) {
h.md.authenticator = authenticator
}
h.md.readTimeout = md.GetDuration(readTimeout)
h.md.retryCount = md.GetInt(retryCount)
h.md.enableBind = md.GetBool(enableBind)
h.md.noDelay = md.GetBool(noDelay)
h.md.udpBufferSize = md.GetInt(udpBufferSize)
if h.md.udpBufferSize > 0 {
if h.md.udpBufferSize < 512 {
h.md.udpBufferSize = 512 // min buffer size
}
if h.md.udpBufferSize > 65*1024 {
h.md.udpBufferSize = 65 * 1024 // max buffer size
}
h.md.readTimeout = mdata.GetDuration(md, readTimeout)
h.md.retryCount = mdata.GetInt(md, retryCount)
h.md.enableBind = mdata.GetBool(md, enableBind)
h.md.noDelay = mdata.GetBool(md, noDelay)
if bs := mdata.GetInt(md, udpBufferSize); bs > 0 {
h.md.udpBufferSize = int(math.Min(math.Max(float64(bs), 512), 64*1024))
} else {
h.md.udpBufferSize = 1024 // default buffer size
h.md.udpBufferSize = 1024
}
return
}