backend request information (#314)

This commit is contained in:
Michael Quigley 2023-04-25 15:16:05 -04:00
parent bf0fbb0e35
commit 980d0dead7
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 9 additions and 1 deletions

View File

@ -177,6 +177,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
IdentityPath: zif,
EndpointAddress: target,
ShrToken: resp.Payload.ShrToken,
RequestsChan: requestsChan,
}
be, err := tcpTunnel.NewBackend(cfg)
if err != nil {

View File

@ -15,6 +15,7 @@ type BackendConfig struct {
IdentityPath string
EndpointAddress string
ShrToken string
RequestsChan chan *endpoints.Request
}
type Backend struct {
@ -56,11 +57,17 @@ func (b *Backend) Run() error {
}
func (b *Backend) handle(conn net.Conn) {
logrus.Infof("handling '%v'", conn.RemoteAddr())
logrus.Debugf("handling '%v'", conn.RemoteAddr())
if rAddr, err := net.ResolveTCPAddr("tcp", b.cfg.EndpointAddress); err == nil {
if rConn, err := net.DialTCP("tcp", nil, rAddr); err == nil {
go endpoints.TXer(conn, rConn)
go endpoints.TXer(rConn, conn)
b.cfg.RequestsChan <- &endpoints.Request{
Stamp: time.Now(),
RemoteAddr: conn.RemoteAddr().String(),
Method: "OPEN",
Path: rAddr.String(),
}
} else {
logrus.Errorf("error dialing '%v': %v", b.cfg.EndpointAddress, err)
_ = conn.Close()