From a4684328b681d40445d506df79b913a49b92ab72 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 21 Apr 2023 13:35:58 -0400 Subject: [PATCH] roughed in udpTunnel.Backend (#306) --- endpoints/tcpTunnel/backend.go | 5 +++-- endpoints/tcpTunnel/frontend.go | 5 +++-- endpoints/{tcpTunnel => }/txer.go | 4 ++-- endpoints/udpTunnel/backend.go | 16 +++++++++++++++- 4 files changed, 23 insertions(+), 7 deletions(-) rename endpoints/{tcpTunnel => }/txer.go (94%) diff --git a/endpoints/tcpTunnel/backend.go b/endpoints/tcpTunnel/backend.go index 2bf18c16..0f5d44c5 100644 --- a/endpoints/tcpTunnel/backend.go +++ b/endpoints/tcpTunnel/backend.go @@ -5,6 +5,7 @@ import ( "github.com/openziti/sdk-golang/ziti/config" "github.com/openziti/sdk-golang/ziti/edge" "github.com/openziti/transport/v2/tcp" + "github.com/openziti/zrok/endpoints" "github.com/pkg/errors" "github.com/sirupsen/logrus" "net" @@ -63,6 +64,6 @@ func (b *Backend) handle(conn net.Conn) { _ = conn.Close() return } - go txer(conn, rConn) - go txer(rConn, conn) + go endpoints.TXer(conn, rConn) + go endpoints.TXer(rConn, conn) } diff --git a/endpoints/tcpTunnel/frontend.go b/endpoints/tcpTunnel/frontend.go index 3b61a922..d0ed7dcf 100644 --- a/endpoints/tcpTunnel/frontend.go +++ b/endpoints/tcpTunnel/frontend.go @@ -4,6 +4,7 @@ import ( "github.com/openziti/sdk-golang/ziti" "github.com/openziti/sdk-golang/ziti/config" "github.com/openziti/transport/v2" + "github.com/openziti/zrok/endpoints" "github.com/openziti/zrok/model" "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" @@ -63,8 +64,8 @@ func (f *Frontend) Stop() { func (f *Frontend) accept(conn transport.Conn) { if zConn, err := f.zCtx.Dial(f.cfg.ShrToken); err == nil { - go txer(conn, zConn) - go txer(zConn, conn) + 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) diff --git a/endpoints/tcpTunnel/txer.go b/endpoints/txer.go similarity index 94% rename from endpoints/tcpTunnel/txer.go rename to endpoints/txer.go index 774b126a..bd7e71f4 100644 --- a/endpoints/tcpTunnel/txer.go +++ b/endpoints/txer.go @@ -1,4 +1,4 @@ -package tcpTunnel +package endpoints import ( "github.com/sirupsen/logrus" @@ -8,7 +8,7 @@ import ( const bufSz = 10240 -func txer(from, to net.Conn) { +func TXer(from, to net.Conn) { logrus.Debugf("started '%v' -> '%v'", from.RemoteAddr(), to.RemoteAddr()) defer logrus.Debugf("exited '%v' -> '%v'", from.RemoteAddr(), to.RemoteAddr()) diff --git a/endpoints/udpTunnel/backend.go b/endpoints/udpTunnel/backend.go index 55cd40a4..8cb4b200 100644 --- a/endpoints/udpTunnel/backend.go +++ b/endpoints/udpTunnel/backend.go @@ -4,6 +4,7 @@ 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" @@ -56,5 +57,18 @@ func (b *Backend) Run() error { func (b *Backend) handle(conn net.Conn) { logrus.Infof("handling '%v'", conn.RemoteAddr()) - _ = conn.Close() + 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) + } }