add config
This commit is contained in:
@ -8,12 +8,13 @@ import (
|
||||
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
"github.com/xtaci/tcpraw"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("ftcp", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -24,7 +25,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -10,12 +10,13 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("h2", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
net.Listener
|
||||
@ -26,7 +27,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -9,12 +9,13 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("http2", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -25,7 +26,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -8,14 +8,15 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
"github.com/xtaci/kcp-go/v5"
|
||||
"github.com/xtaci/smux"
|
||||
"github.com/xtaci/tcpraw"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("kcp", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -25,7 +26,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -11,6 +11,7 @@ var (
|
||||
|
||||
// Listener is a server listener, just like a net.Listener.
|
||||
type Listener interface {
|
||||
Init(Metadata) error
|
||||
net.Listener
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,12 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("obfs-http", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -21,7 +22,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -9,11 +9,12 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("obfs-tls", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -21,7 +22,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -5,11 +5,18 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Addr string
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
type Option func(opts *Options)
|
||||
|
||||
func AddrOption(addr string) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Addr = addr
|
||||
}
|
||||
}
|
||||
|
||||
func LoggerOption(logger logger.Logger) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Logger = logger
|
||||
|
@ -8,12 +8,13 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("quic", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -23,7 +24,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -9,24 +8,27 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("tcp", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
addr string
|
||||
md metadata
|
||||
net.Listener
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
}
|
||||
return &Listener{
|
||||
addr: options.Addr,
|
||||
logger: options.Logger,
|
||||
}
|
||||
}
|
||||
@ -37,7 +39,7 @@ func (l *Listener) Init(md listener.Metadata) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
laddr, err := net.ResolveTCPAddr("tcp", l.md.addr)
|
||||
laddr, err := net.ResolveTCPAddr("tcp", l.addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -59,13 +61,6 @@ func (l *Listener) Init(md listener.Metadata) (err error) {
|
||||
}
|
||||
|
||||
func (l *Listener) parseMetadata(md listener.Metadata) (m metadata, err error) {
|
||||
if val, ok := md[addr]; ok {
|
||||
m.addr = val
|
||||
} else {
|
||||
err = errors.New("missing address")
|
||||
return
|
||||
}
|
||||
|
||||
m.keepAlive = true
|
||||
if val, ok := md[keepAlive]; ok {
|
||||
m.keepAlive, _ = strconv.ParseBool(val)
|
||||
|
@ -3,7 +3,6 @@ package tcp
|
||||
import "time"
|
||||
|
||||
const (
|
||||
addr = "addr"
|
||||
keepAlive = "keepAlive"
|
||||
keepAlivePeriod = "keepAlivePeriod"
|
||||
)
|
||||
@ -13,7 +12,6 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
addr string
|
||||
keepAlive bool
|
||||
keepAlivePeriod time.Duration
|
||||
}
|
||||
|
@ -9,11 +9,12 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("tls", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -21,7 +22,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -8,12 +8,13 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("mtls", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -23,7 +24,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -8,11 +8,12 @@ import (
|
||||
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("udp", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -23,7 +24,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -9,12 +9,14 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("ws", NewListener)
|
||||
registry.RegisterListener("wss", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -26,7 +28,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
@ -9,13 +9,15 @@ import (
|
||||
"github.com/go-gost/gost/pkg/components/internal/utils"
|
||||
"github.com/go-gost/gost/pkg/components/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
"github.com/go-gost/gost/pkg/registry"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
var (
|
||||
_ listener.Listener = (*Listener)(nil)
|
||||
)
|
||||
func init() {
|
||||
registry.RegisterListener("mws", NewListener)
|
||||
registry.RegisterListener("mwss", NewListener)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
md metadata
|
||||
@ -27,7 +29,7 @@ type Listener struct {
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) *Listener {
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
options := &listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
|
Reference in New Issue
Block a user