Skip to content

Commit

Permalink
Merge pull request #658 from mirokuratczyk/log-passthrough
Browse files Browse the repository at this point in the history
Fix: log passthrough_address
  • Loading branch information
rod-hynes authored Sep 25, 2023
2 parents ebd4fdc + cbefc17 commit c2e5931
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions psiphon/common/transforms/httpNormalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ func (t *HTTPNormalizer) SetWriteDeadline(tt time.Time) error {
return t.Conn.SetWriteDeadline(tt)
}

// GetMetrics implements the common.MetricsSource interface.
func (t *HTTPNormalizer) GetMetrics() common.LogFields {
// Relay any metrics from the underlying conn.
m, ok := t.Conn.(common.MetricsSource)
Expand Down
1 change: 1 addition & 0 deletions psiphon/common/transforms/httpTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (t *HTTPTransformer) Write(b []byte) (int, error) {
return n, err
}

// GetMetrics implements the common.MetricsSource interface.
func (t *HTTPTransformer) GetMetrics() common.LogFields {
// Relay any metrics from the underlying conn.
m, ok := t.Conn.(common.MetricsSource)
Expand Down
61 changes: 60 additions & 1 deletion psiphon/server/tlsTunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func ListenTLSTunnel(
return nil, errors.Trace(err)
}

return tris.NewListener(server.listener, server.tlsConfig), nil
listener = tris.NewListener(server.listener, server.tlsConfig)

return NewTLSTunnelListener(listener, server), nil
}

// NewTLSTunnelServer initializes a new TLSTunnelServer.
Expand Down Expand Up @@ -195,3 +197,60 @@ func (server *TLSTunnelServer) makeTLSTunnelConfig() (*tris.Config, error) {

return config, nil
}

// TLSTunnelListener implements the net.Listener interface. Accept returns a
// net.Conn which implements the common.MetricsSource interface.
type TLSTunnelListener struct {
net.Listener
server *TLSTunnelServer
}

// NewTLSTunnelListener initializes a new TLSTunnelListener.
func NewTLSTunnelListener(listener net.Listener, server *TLSTunnelServer) *TLSTunnelListener {
return &TLSTunnelListener{
Listener: listener,
server: server,
}
}

func (l *TLSTunnelListener) Accept() (net.Conn, error) {
conn, err := l.Listener.Accept()
if err != nil {
return nil, errors.Trace(err)
}

return NewTLSTunnelConn(conn, l.server), nil
}

// TLSTunnelConn implements the net.Conn and common.MetricsSource interfaces.
type TLSTunnelConn struct {
net.Conn
server *TLSTunnelServer
}

// NewTLSTunnelConn initializes a new TLSTunnelConn.
func NewTLSTunnelConn(conn net.Conn, server *TLSTunnelServer) *TLSTunnelConn {
return &TLSTunnelConn{
Conn: conn,
server: server,
}
}

// GetMetrics implements the common.MetricsSource interface.
func (conn *TLSTunnelConn) GetMetrics() common.LogFields {

var logFields common.LogFields

// Relay any metrics from the underlying conn.
if m, ok := conn.Conn.(common.MetricsSource); ok {
logFields = m.GetMetrics()
} else {
logFields = make(common.LogFields)
}

if conn.server.passthroughAddress != "" {
logFields["passthrough_address"] = conn.server.passthroughAddress
}

return logFields
}

0 comments on commit c2e5931

Please sign in to comment.