added initial typing of forwarders, now only tcp

This commit is contained in:
2026-03-26 17:17:18 +02:00
parent e05d610882
commit 230022f856
8 changed files with 115 additions and 68 deletions

View File

@@ -11,7 +11,13 @@ import (
"helmet/app/logger"
)
const (
TCP = "tcp"
UDP = "udp"
)
type Forwarder struct {
Type string `json:"type" yaml:"type"`
listen net.Listener `json:"-" yaml:"-"`
ctx context.Context `json:"-" yaml:"-"`
cancel context.CancelFunc `json:"-" yaml:"-"`
@@ -21,7 +27,7 @@ type Forwarder struct {
log *logger.Logger
}
func NewForwarder(ctx context.Context, lport, dport uint32, addrs ...string) (*Forwarder, error) {
func NewForwarder(ctx context.Context, typ string, lport, dport uint32, addrs ...string) (*Forwarder, error) {
ctx, cancel := context.WithCancel(context.Background())
forw := &Forwarder{
Dests: make([]*Destination, 0),
@@ -29,6 +35,7 @@ func NewForwarder(ctx context.Context, lport, dport uint32, addrs ...string) (*F
Dport: dport,
ctx: ctx,
cancel: cancel,
Type: typ,
}
id := strconv.FormatUint(uint64(lport), 10)
forw.log = logger.NewLogger("forwarder:" + id)
@@ -50,7 +57,7 @@ func NewForwarder(ctx context.Context, lport, dport uint32, addrs ...string) (*F
return forw, err
}
func (forw *Forwarder) Listen(wg *sync.WaitGroup) {
func (forw *Forwarder) ListenTCP(wg *sync.WaitGroup) {
forw.log.Debugf("Start listening on %d", forw.Lport)
defer wg.Done()
for {