mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
consolidated txer (#305)
This commit is contained in:
parent
e432dfdb28
commit
fdc038c12d
@ -63,58 +63,6 @@ func (b *Backend) handle(conn net.Conn) {
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
go b.rxer(conn, rConn)
|
||||
go b.txer(conn, rConn)
|
||||
}
|
||||
|
||||
func (b *Backend) rxer(conn, rConn net.Conn) {
|
||||
logrus.Infof("started '%v' <=> '%v'", conn.RemoteAddr(), rConn.RemoteAddr())
|
||||
defer logrus.Warnf("exited '%v' <=> '%v'", conn.RemoteAddr(), rConn.RemoteAddr())
|
||||
|
||||
buf := make([]byte, 10240)
|
||||
for {
|
||||
if rxsz, err := conn.Read(buf); err == nil {
|
||||
if txsz, err := rConn.Write(buf[:rxsz]); err == nil {
|
||||
if txsz != rxsz {
|
||||
logrus.Errorf("short write '%v' (%d != %d)", rConn.RemoteAddr(), txsz, rxsz)
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("error writing '%v': %v", rConn.RemoteAddr(), err)
|
||||
_ = rConn.Close()
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("read error '%v': %v", rConn.RemoteAddr(), err)
|
||||
_ = rConn.Close()
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) txer(conn, rConn net.Conn) {
|
||||
logrus.Infof("started '%v' <=> '%v'", conn.RemoteAddr(), rConn.RemoteAddr())
|
||||
defer logrus.Warnf("exited '%v' <=> '%v'", conn.RemoteAddr(), rConn.RemoteAddr())
|
||||
|
||||
buf := make([]byte, 10240)
|
||||
for {
|
||||
if rxsz, err := rConn.Read(buf); err == nil {
|
||||
if txsz, err := conn.Write(buf[:rxsz]); err == nil {
|
||||
if txsz != rxsz {
|
||||
logrus.Errorf("short write '%v' (%d != %d)", conn.RemoteAddr(), txsz, rxsz)
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("error writing '%v': %v", conn.RemoteAddr(), err)
|
||||
_ = rConn.Close()
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("read error '%v': %v", conn.RemoteAddr(), err)
|
||||
_ = rConn.Close()
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
go txer(conn, rConn)
|
||||
go txer(rConn, conn)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package tcpTunnel
|
||||
import (
|
||||
"github.com/openziti/sdk-golang/ziti"
|
||||
"github.com/openziti/sdk-golang/ziti/config"
|
||||
"github.com/openziti/sdk-golang/ziti/edge"
|
||||
"github.com/openziti/transport/v2"
|
||||
"github.com/openziti/zrok/model"
|
||||
"github.com/openziti/zrok/zrokdir"
|
||||
@ -64,63 +63,11 @@ func (f *Frontend) Stop() {
|
||||
|
||||
func (f *Frontend) accept(conn transport.Conn) {
|
||||
if zConn, err := f.zCtx.Dial(f.cfg.ShrToken); err == nil {
|
||||
go f.rxer(conn, zConn)
|
||||
go f.txer(conn, zConn)
|
||||
go txer(conn, zConn)
|
||||
go 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()
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Frontend) rxer(conn transport.Conn, zConn edge.Conn) {
|
||||
logrus.Infof("started '%v' <=> '%v'", conn.RemoteAddr(), zConn.RemoteAddr())
|
||||
defer logrus.Warnf("exited '%v' <=> '%v'", conn.RemoteAddr(), zConn.RemoteAddr())
|
||||
|
||||
buf := make([]byte, 10240)
|
||||
for {
|
||||
if rxsz, err := conn.Read(buf); err == nil {
|
||||
if txsz, err := zConn.Write(buf[:rxsz]); err == nil {
|
||||
if txsz != rxsz {
|
||||
logrus.Errorf("short write '%v' (%d != %d)", zConn.RemoteAddr(), txsz, rxsz)
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("error writing '%v': %v", zConn.RemoteAddr(), err)
|
||||
_ = zConn.Close()
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("read error '%v': %v", zConn.RemoteAddr(), err)
|
||||
_ = zConn.Close()
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Frontend) txer(conn transport.Conn, zConn edge.Conn) {
|
||||
logrus.Infof("started '%v' <=> '%v'", conn.RemoteAddr(), zConn.RemoteAddr())
|
||||
defer logrus.Warnf("exited '%v' <=> '%v'", conn.RemoteAddr(), zConn.RemoteAddr())
|
||||
|
||||
buf := make([]byte, 10240)
|
||||
for {
|
||||
if rxsz, err := zConn.Read(buf); err == nil {
|
||||
if txsz, err := conn.Write(buf[:rxsz]); err == nil {
|
||||
if txsz != rxsz {
|
||||
logrus.Errorf("short write '%v' (%d != %d)'", conn.RemoteAddr(), txsz, rxsz)
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("error writing '%v': %v", conn.RemoteAddr(), err)
|
||||
_ = zConn.Close()
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("read error '%v': %v", conn.RemoteAddr(), err)
|
||||
_ = zConn.Close()
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
endpoints/tcpTunnel/txer.go
Normal file
37
endpoints/tcpTunnel/txer.go
Normal file
@ -0,0 +1,37 @@
|
||||
package tcpTunnel
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"net"
|
||||
)
|
||||
|
||||
const bufSz = 10240
|
||||
|
||||
func txer(from, to net.Conn) {
|
||||
logrus.Infof("started '%v' -> '%v'", from.RemoteAddr(), to.RemoteAddr())
|
||||
defer logrus.Warnf("exited '%v' -> '%v'", from.RemoteAddr(), to.RemoteAddr())
|
||||
|
||||
buf := make([]byte, bufSz)
|
||||
for {
|
||||
if rxsz, err := from.Read(buf); err == nil {
|
||||
if txsz, err := to.Write(buf[:rxsz]); err == nil {
|
||||
if txsz != rxsz {
|
||||
logrus.Errorf("short write '%v' -> '%v' (%d != %d)", from.RemoteAddr(), to.RemoteAddr(), txsz, rxsz)
|
||||
_ = to.Close()
|
||||
_ = from.Close()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("write error '%v' -> '%v': %v", from.RemoteAddr(), to.RemoteAddr(), err)
|
||||
_ = to.Close()
|
||||
_ = from.Close()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("read error '%v' -> '%v': %v", from.RemoteAddr(), to.RemoteAddr(), err)
|
||||
_ = to.Close()
|
||||
_ = from.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user