46 lines
987 B
Go
46 lines
987 B
Go
package forward
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/go-gost/gost/pkg/connector"
|
|
md "github.com/go-gost/gost/pkg/metadata"
|
|
"github.com/go-gost/gost/pkg/registry"
|
|
)
|
|
|
|
func init() {
|
|
registry.ConnectorRegistry().Register("forward", NewConnector)
|
|
}
|
|
|
|
type forwardConnector struct {
|
|
options connector.Options
|
|
}
|
|
|
|
func NewConnector(opts ...connector.Option) connector.Connector {
|
|
options := connector.Options{}
|
|
for _, opt := range opts {
|
|
opt(&options)
|
|
}
|
|
|
|
return &forwardConnector{
|
|
options: options,
|
|
}
|
|
}
|
|
|
|
func (c *forwardConnector) Init(md md.Metadata) (err error) {
|
|
return nil
|
|
}
|
|
|
|
func (c *forwardConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
|
log := c.options.Logger.WithFields(map[string]any{
|
|
"remote": conn.RemoteAddr().String(),
|
|
"local": conn.LocalAddr().String(),
|
|
"network": network,
|
|
"address": address,
|
|
})
|
|
log.Infof("connect %s/%s", address, network)
|
|
|
|
return conn, nil
|
|
}
|