support for request logging in the socks implementation (#558)

This commit is contained in:
Michael Quigley 2024-02-08 14:05:29 -05:00
parent 3afbb6dc9a
commit 7380a907d2
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 13 additions and 1 deletions

View File

@ -41,7 +41,7 @@ func NewBackend(cfg *BackendConfig) (*Backend, error) {
return &Backend{ return &Backend{
cfg: cfg, cfg: cfg,
listener: listener, listener: listener,
server: &Server{}, server: &Server{Requests: cfg.Requests},
}, nil }, nil
} }

View File

@ -16,6 +16,7 @@ import (
"context" "context"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"github.com/openziti/zrok/endpoints"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"io" "io"
"net" "net"
@ -86,6 +87,9 @@ type Server struct {
// Username and Password, if set, are the credential clients must provide. // Username and Password, if set, are the credential clients must provide.
Username string Username string
Password string Password string
// For notifying user-facing components about activity
Requests chan *endpoints.Request
} }
func (s *Server) dial(ctx context.Context, network, addr string) (net.Conn, error) { func (s *Server) dial(ctx context.Context, network, addr string) (net.Conn, error) {
@ -171,6 +175,14 @@ func (c *Conn) handleRequest() error {
} }
c.request = req c.request = req
if c.srv.Requests != nil {
c.srv.Requests <- &endpoints.Request{
Stamp: time.Now(),
Method: "CONNECT",
Path: fmt.Sprintf("%v:%d", c.request.destination, c.request.port),
}
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
srv, err := c.srv.dial( srv, err := c.srv.dial(