ripping out udp support for initial v0.4

This commit is contained in:
Michael Quigley 2023-04-24 15:37:41 -04:00
parent 25b1469acc
commit bf0fbb0e35
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 26 additions and 211 deletions

View File

@ -4,7 +4,6 @@ import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/openziti/zrok/endpoints/tcpTunnel"
"github.com/openziti/zrok/endpoints/udpTunnel"
"github.com/openziti/zrok/rest_client_zrok"
"github.com/openziti/zrok/rest_client_zrok/share"
"github.com/openziti/zrok/rest_model_zrok"
@ -24,7 +23,6 @@ func init() {
type accessPrivateTunnelCommand struct {
bindAddress string
udp bool
cmd *cobra.Command
}
@ -36,7 +34,6 @@ func newAccessPrivateTunnelCommand() *accessPrivateTunnelCommand {
}
command := &accessPrivateTunnelCommand{cmd: cmd}
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private tunnel")
cmd.Flags().BoolVar(&command.udp, "udp", false, "Use UDP")
cmd.Run = command.run
return command
}
@ -78,21 +75,6 @@ func (cmd *accessPrivateTunnelCommand) run(_ *cobra.Command, args []string) {
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, args[0], zrok, auth)
os.Exit(0)
}()
if cmd.udp {
fe, err := udpTunnel.NewFrontend(&udpTunnel.FrontendConfig{
BindAddress: cmd.bindAddress,
IdentityName: "backend",
ShrToken: args[0],
})
if err != nil {
panic(err)
}
if err := fe.Run(); err != nil {
panic(err)
}
} else {
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
BindAddress: cmd.bindAddress,
IdentityName: "backend",
@ -104,7 +86,6 @@ func (cmd *accessPrivateTunnelCommand) run(_ *cobra.Command, args []string) {
if err := fe.Run(); err != nil {
panic(err)
}
}
for {
time.Sleep(30 * 24 * time.Hour)
}

View File

@ -8,7 +8,6 @@ import (
"github.com/openziti/zrok/endpoints"
"github.com/openziti/zrok/endpoints/proxy"
"github.com/openziti/zrok/endpoints/tcpTunnel"
"github.com/openziti/zrok/endpoints/udpTunnel"
"github.com/openziti/zrok/model"
"github.com/openziti/zrok/rest_client_zrok"
"github.com/openziti/zrok/rest_client_zrok/share"
@ -33,7 +32,6 @@ type sharePrivateCommand struct {
backendMode string
headless bool
insecure bool
udp bool
cmd *cobra.Command
}
@ -48,7 +46,6 @@ func newSharePrivateCommand() *sharePrivateCommand {
cmd.Flags().StringVar(&command.backendMode, "backend-mode", "proxy", "The backend mode {proxy, web, tunnel}")
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>")
cmd.Flags().BoolVar(&command.udp, "udp", false, "Enable UDP for tunnel backend")
cmd.Run = command.run
return command
}
@ -176,26 +173,6 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
}
case "tunnel":
if cmd.udp {
cfg := &udpTunnel.BackendConfig{
IdentityPath: zif,
EndpointAddress: target,
ShrToken: resp.Payload.ShrToken,
}
be, err := udpTunnel.NewBackend(cfg)
if err != nil {
if !panicInstead {
tui.Error("unable to create udp tunnel backend", err)
}
panic(err)
}
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running udp tunnel backend: %v", err)
}
}()
} else {
cfg := &tcpTunnel.BackendConfig{
IdentityPath: zif,
EndpointAddress: target,
@ -213,7 +190,6 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
logrus.Errorf("error running tunnel backend: %v", err)
}
}()
}
default:
tui.Error("invalid backend mode", nil)

View File

@ -1,74 +0,0 @@
package udpTunnel
import (
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/config"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/zrok/endpoints"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"net"
"time"
)
type BackendConfig struct {
IdentityPath string
EndpointAddress string
ShrToken string
}
type Backend struct {
cfg *BackendConfig
listener edge.Listener
}
func NewBackend(cfg *BackendConfig) (*Backend, error) {
options := ziti.ListenOptions{
ConnectTimeout: 5 * time.Minute,
MaxConnections: 64,
}
zcfg, err := config.NewFromFile(cfg.IdentityPath)
if err != nil {
return nil, errors.Wrap(err, "error loading config")
}
listener, err := ziti.NewContextWithConfig(zcfg).ListenWithOptions(cfg.ShrToken, &options)
if err != nil {
return nil, errors.Wrap(err, "error listening")
}
b := &Backend{
cfg: cfg,
listener: listener,
}
return b, nil
}
func (b *Backend) Run() error {
logrus.Info("started")
defer logrus.Info("exited")
for {
if conn, err := b.listener.Accept(); err == nil {
go b.handle(conn)
} else {
return errors.Wrap(err, "error accepting")
}
}
}
func (b *Backend) handle(conn net.Conn) {
logrus.Infof("handling '%v'", conn.RemoteAddr())
defer logrus.Infof("completed '%v'", conn.RemoteAddr())
if rAddr, err := net.ResolveUDPAddr("udp", b.cfg.EndpointAddress); err == nil {
if rConn, err := net.DialUDP("udp", nil, rAddr); err == nil {
go endpoints.TXer(conn, rConn)
go endpoints.TXer(rConn, conn)
} else {
logrus.Errorf("error dialing '%v': %v", rAddr, err)
_ = conn.Close()
return
}
} else {
logrus.Errorf("error resolving '%v': %v", b.cfg.EndpointAddress, err)
}
}

View File

@ -1,68 +0,0 @@
package udpTunnel
import (
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/config"
"github.com/openziti/zrok/endpoints"
"github.com/openziti/zrok/model"
"github.com/openziti/zrok/zrokdir"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"net"
)
type FrontendConfig struct {
BindAddress string
IdentityName string
ShrToken string
}
type Frontend struct {
cfg *FrontendConfig
zCtx ziti.Context
lAddr *net.UDPAddr
}
func NewFrontend(cfg *FrontendConfig) (*Frontend, error) {
lAddr, err := net.ResolveUDPAddr("udp", cfg.BindAddress)
if err != nil {
return nil, errors.Wrapf(err, "error resolving udp address '%v'", cfg.BindAddress)
}
zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.IdentityName)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from zrokdir", cfg.IdentityName)
}
zCfg, err := config.NewFromFile(zCfgPath)
if err != nil {
return nil, errors.Wrap(err, "error loading config")
}
zCfg.ConfigTypes = []string{model.ZrokProxyConfig}
zCtx := ziti.NewContextWithConfig(zCfg)
return &Frontend{
cfg: cfg,
zCtx: zCtx,
lAddr: lAddr,
}, nil
}
func (f *Frontend) Run() error {
for {
if conn, err := net.ListenUDP("udp", f.lAddr); err == nil {
go f.accept(conn)
logrus.Infof("accepted udp connection from '%v'", conn.RemoteAddr())
} else {
return err
}
}
}
func (f *Frontend) accept(conn *net.UDPConn) {
if zConn, err := f.zCtx.Dial(f.cfg.ShrToken); err == nil {
go endpoints.TXer(conn, zConn)
go endpoints.TXer(zConn, conn)
logrus.Infof("accepted '%v' <=> '%v'", conn.RemoteAddr(), zConn.RemoteAddr())
} else {
logrus.Errorf("error dialing '%v': %v", f.cfg.ShrToken, err)
_ = conn.Close()
}
}