Skip to content

Commit

Permalink
Merge pull request #659 from mirokuratczyk/passthrough-address
Browse files Browse the repository at this point in the history
Fix: log passthrough address when demux used
  • Loading branch information
rod-hynes authored Sep 26, 2023
2 parents c2e5931 + 7f3e8c3 commit b2279f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions psiphon/server/demux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net"
"time"

"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -319,3 +320,13 @@ func (conn *bufferedConn) Read(b []byte) (n int, err error) {

return conn.Conn.Read(b)
}

// GetMetrics implements the common.MetricsSource interface.
func (conn *bufferedConn) GetMetrics() common.LogFields {
// Relay any metrics from the underlying conn.
m, ok := conn.Conn.(common.MetricsSource)
if ok {
return m.GetMetrics()
}
return nil
}
19 changes: 18 additions & 1 deletion psiphon/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func TestTLSOSSH(t *testing.T) {
runServer(t,
&runServerConfig{
tunnelProtocol: "TLS-OSSH",
passthrough: true,
enableSSHAPIRequests: true,
requireAuthorization: true,
doTunneledWebRequest: true,
Expand Down Expand Up @@ -681,11 +682,15 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
}

var tunnelProtocolPassthroughAddresses map[string]string
var passthroughAddress *string

if runConfig.passthrough {
passthroughAddress = new(string)
*passthroughAddress = "x.x.x.x:x"

tunnelProtocolPassthroughAddresses = map[string]string{
// Tests do not trigger passthrough so set invalid IP and port.
runConfig.tunnelProtocol: "x.x.x.x:x",
runConfig.tunnelProtocol: *passthroughAddress,
}
}

Expand Down Expand Up @@ -1467,6 +1472,7 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
expectUDPDataTransfer,
expectQUICVersion,
expectDestinationBytesFields,
passthroughAddress,
logFields)
if err != nil {
t.Fatalf("invalid server tunnel log fields: %s", err)
Expand Down Expand Up @@ -1604,6 +1610,7 @@ func checkExpectedServerTunnelLogFields(
expectUDPDataTransfer bool,
expectQUICVersion string,
expectDestinationBytesFields bool,
expectPassthroughAddress *string,
fields map[string]interface{}) error {

// Limitations:
Expand Down Expand Up @@ -2063,6 +2070,16 @@ func checkExpectedServerTunnelLogFields(
}
}

if expectPassthroughAddress != nil {
name := "passthrough_address"
if fields[name] == nil {
return fmt.Errorf("missing expected field '%s'", name)
}
if fields[name] != *expectPassthroughAddress {
return fmt.Errorf("unexpected field value %s: %v != %v", name, fields[name], *expectPassthroughAddress)
}
}

if runConfig.doLogHostProvider {
name := "provider"
if fields[name] == nil {
Expand Down

0 comments on commit b2279f7

Please sign in to comment.