mirror of
https://github.com/openziti/zrok.git
synced 2025-06-24 19:51:32 +02:00
starting on udpTunnel (#306)
This commit is contained in:
parent
876651c9fe
commit
12fad0d74c
60
endpoints/udpTunnel/backend.go
Normal file
60
endpoints/udpTunnel/backend.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
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/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())
|
||||||
|
_ = conn.Close()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user