roughed in udpTunnel.Backend (#306)

This commit is contained in:
Michael Quigley 2023-04-21 13:35:58 -04:00
parent 12fad0d74c
commit a4684328b6
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 23 additions and 7 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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())

View File

@ -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())
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)
}
}