Skip to content

Commit

Permalink
Reuse remote connection
Browse files Browse the repository at this point in the history
  • Loading branch information
yosebyte authored Dec 3, 2024
1 parent e481073 commit 61cc49c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions internal/tunnel/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ func Client(parsedURL *url.URL) error {
}
defer targetConn.Close()
targetConn.SetNoDelay(true)
log.Info("Target connection established, starting data exchange: [%v] <-> [%v]", linkAddr, targetAddr)
util.HandleConn(linkConn, targetConn)
remoteConn, err := net.DialTCP("tcp", nil, linkAddr)
if err != nil {
log.Error("Unable to dial target address: [%v], %v", linkAddr, err)
return
}
defer remoteConn.Close()
remoteConn.SetNoDelay(true)
log.Info("Target connection established, starting data exchange: [%v] <-> [%v]", remoteConn, targetAddr)
util.HandleConn(remoteConn, targetConn)
log.Info("Connection closed successfully")
}()
}
Expand Down
8 changes: 7 additions & 1 deletion internal/tunnel/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ func Server(parsedURL *url.URL, whiteList *sync.Map) error {
targetConn.Close()
return
}
remoteConn, err := linkListen.AcceptTCP()
if err != nil {
log.Error("Unable to accept connections form link address: [%v] %v", linkAddr, err)
return
}
defer remoteConn.Close()
log.Info("Starting data exchange: [%v] <-> [%v]", clientAddr, targetAddr)
util.HandleConn(linkConn, targetConn)
util.HandleConn(remoteConn, targetConn)
log.Info("Connection closed successfully")
}(targetConn)
}
Expand Down

0 comments on commit 61cc49c

Please sign in to comment.