working commit
This commit is contained in:
+12
-12
@@ -30,7 +30,7 @@ func NewForwarder(ctx context.Context, lport, dport uint32, addrs ...string) (*F
|
|||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
id := strconv.FormatUint(uint64(lport), 10)
|
id := strconv.FormatUint(uint64(lport), 10)
|
||||||
forw.log = logger.NewLogger("forwarder:" + id)
|
forw.log = logger.NewLogger("forwarder:" + id)
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
dest := NewDestination(addr)
|
dest := NewDestination(addr)
|
||||||
@@ -38,7 +38,7 @@ func NewForwarder(ctx context.Context, lport, dport uint32, addrs ...string) (*F
|
|||||||
}
|
}
|
||||||
|
|
||||||
portinfo := ":" + strconv.FormatUint(uint64(forw.Lport), 10)
|
portinfo := ":" + strconv.FormatUint(uint64(forw.Lport), 10)
|
||||||
laddr, err := net.ResolveTCPAddr("tcp", portinfo)
|
laddr, err := net.ResolveTCPAddr("tcp", portinfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return forw, err
|
return forw, err
|
||||||
}
|
}
|
||||||
@@ -68,18 +68,18 @@ func (forw *Forwarder) Stop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Streamer struct {
|
type Streamer struct {
|
||||||
source string
|
source string
|
||||||
dest string
|
dest string
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStreamer(ctx context.Context) *Streamer {
|
func NewStreamer(ctx context.Context) *Streamer {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
return &Streamer{
|
return &Streamer{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (forw *Forwarder) handle(ctx context.Context, inconn net.Conn) {
|
func (forw *Forwarder) handle(ctx context.Context, inconn net.Conn) {
|
||||||
@@ -95,7 +95,7 @@ func (forw *Forwarder) handle(ctx context.Context, inconn net.Conn) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer outconn.Close()
|
defer outconn.Close()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go forw.stream(&wg, inconn, outconn)
|
go forw.stream(&wg, inconn, outconn)
|
||||||
|
|||||||
Reference in New Issue
Block a user