Rod Hynes 6 месяцев назад
Родитель
Сommit
66b1cea627
3 измененных файлов с 31 добавлено и 19 удалено
  1. 3 2
      psiphon/common/dsl/api.go
  2. 20 14
      psiphon/common/dsl/dsl_test.go
  3. 8 3
      psiphon/common/dsl/relay.go

+ 3 - 2
psiphon/common/dsl/api.go

@@ -181,8 +181,9 @@ type GetOSLFileSpecsResponse struct {
 const MaxRelayPayloadSize = 65536
 
 const (
-	psiphonClientIPHeader        = "X-Psiphon-Client-Ip"
-	psiphonClientGeoIPDataHeader = "X-Psiphon-Client-Geoipdata"
+	PsiphonClientIPHeader        = "X-Psiphon-Client-Ip"
+	PsiphonClientGeoIPDataHeader = "X-Psiphon-Client-Geoipdata"
+	PsiphonHostIDHeader          = "X-Psiphon-Host-Id"
 
 	requestVersion                   = 1
 	requestTypeDiscoverServerEntries = 1

+ 20 - 14
psiphon/common/dsl/dsl_test.go

@@ -120,14 +120,11 @@ func TestDSLs(t *testing.T) {
 	}
 }
 
-var testClientIP = "192.168.0.1"
-var testClientGeoIPData = common.GeoIPData{
-	Country: "Country",
-	City:    "City",
-	ISP:     "ISP",
-	ASN:     "ASN",
-	ASO:     "ASO",
-}
+var (
+	testClientIP        = "192.168.0.1"
+	testClientGeoIPData = common.GeoIPData{"Country", "City", "ISP", "ASN", "ASO"}
+	testHostID          = "host_id"
+)
 
 func testDSLs(testConfig *testConfig) error {
 
@@ -169,6 +166,7 @@ func testDSLs(testConfig *testConfig) error {
 		CACertificates:              []*x509.Certificate{tlsConfig.CACertificate},
 		HostCertificate:             tlsConfig.relayCertificate,
 		DynamicServerListServiceURL: backend.getAddress(),
+		HostID:                      testHostID,
 	}
 
 	relay, err := NewRelay(relayConfig)
@@ -638,23 +636,31 @@ func (b *dslBackend) start(tlsConfig *tlsConfig) error {
 			}
 		}()
 
-		clientIPHeader, ok := r.Header[psiphonClientIPHeader]
+		clientIPHeader, ok := r.Header[PsiphonClientIPHeader]
 		if !ok {
-			return errors.Tracef("missing header: psiphonClientIPHeader")
+			return errors.Tracef("missing header: %s", PsiphonClientIPHeader)
 		}
 		if len(clientIPHeader) != 1 || clientIPHeader[0] != testClientIP {
-			return errors.Tracef("invalid header: psiphonClientIPHeader")
+			return errors.Tracef("invalid header: %s", PsiphonClientIPHeader)
 		}
 
-		clientGeoIPDataHeader, ok := r.Header[psiphonClientGeoIPDataHeader]
+		clientGeoIPDataHeader, ok := r.Header[PsiphonClientGeoIPDataHeader]
 		if !ok {
-			return errors.Tracef("missing header: psiphonClientGeoIPDataHeader")
+			return errors.Tracef("missing header: %s", PsiphonClientGeoIPDataHeader)
 		}
 		var geoIPData common.GeoIPData
 		if len(clientGeoIPDataHeader) != 1 ||
 			json.Unmarshal([]byte(clientGeoIPDataHeader[0]), &geoIPData) != nil ||
 			geoIPData != testClientGeoIPData {
-			return errors.Tracef("invalid header: psiphonClientGeoIPDataHeader")
+			return errors.Tracef("invalid header: %s", PsiphonClientGeoIPDataHeader)
+		}
+
+		hostIDHeader, ok := r.Header[PsiphonHostIDHeader]
+		if !ok {
+			return errors.Tracef("missing header: %s", PsiphonHostIDHeader)
+		}
+		if len(hostIDHeader) != 1 || hostIDHeader[0] != testHostID {
+			return errors.Tracef("invalid header: %s", PsiphonHostIDHeader)
 		}
 
 		request, err := io.ReadAll(r.Body)

+ 8 - 3
psiphon/common/dsl/relay.go

@@ -52,7 +52,9 @@ const (
 // RelayConfig specifies the configuration for a Relay.
 //
 // The CACertificates and HostCertificate parameters are used for mutually
-// authenticated TLS between the Relay and the DSL backend.
+// authenticated TLS between the Relay and the DSL backend. The HostID value
+// is sent to the DSL backend for logging, and should be populated with the
+// HostID in psiphond.config.
 type RelayConfig struct {
 	Logger common.Logger
 
@@ -60,6 +62,8 @@ type RelayConfig struct {
 	HostCertificate *tls.Certificate
 
 	DynamicServerListServiceURL string
+
+	HostID string
 }
 
 // Relay is an intermediary between a DSL client and the DSL backend which
@@ -311,8 +315,9 @@ func (r *Relay) handleRequest(
 		if err != nil {
 			return nil, errors.Trace(err)
 		}
-		httpRequest.Header.Set(psiphonClientIPHeader, clientIP)
-		httpRequest.Header.Set(psiphonClientGeoIPDataHeader, string(jsonGeoIPData))
+		httpRequest.Header.Set(PsiphonClientIPHeader, clientIP)
+		httpRequest.Header.Set(PsiphonClientGeoIPDataHeader, string(jsonGeoIPData))
+		httpRequest.Header.Set(PsiphonHostIDHeader, r.config.HostID)
 
 		startTime := time.Now()
 		httpResponse, err := r.httpClient.Do(httpRequest)