From a3e8a5b58c7a2b3f91b1de53f12247a9477fb5d4 Mon Sep 17 00:00:00 2001 From: ain ghazal Date: Wed, 3 Apr 2024 15:50:20 +0200 Subject: [PATCH] move archival structs to internal/model --- internal/experiment/openvpn/archival.go | 54 --------------------- internal/experiment/openvpn/openvpn.go | 22 ++++----- internal/experiment/openvpn/openvpn_test.go | 30 ++++++------ internal/model/archival.go | 35 +++++++++++++ 4 files changed, 61 insertions(+), 80 deletions(-) delete mode 100644 internal/experiment/openvpn/archival.go diff --git a/internal/experiment/openvpn/archival.go b/internal/experiment/openvpn/archival.go deleted file mode 100644 index c10779217f..0000000000 --- a/internal/experiment/openvpn/archival.go +++ /dev/null @@ -1,54 +0,0 @@ -package openvpn - -// TODO(ainghazal): move to ooni internal archival package when consolidated. - -// OpenVPNOptions is a subset of [vpnconfig.OpenVPNOptions] that we want to include -// in the archived result. -type OpenVPNOptions struct { - Auth string `json:"auth,omitempty"` - Cipher string `json:"cipher,omitempty"` - Compression string `json:"compression,omitempty"` -} - -// ArchivalOpenVPNHandshakeResult contains the result of a OpenVPN handshake. -type ArchivalOpenVPNHandshakeResult struct { - BootstrapTime float64 `json:"bootstrap_time,omitempty"` - Endpoint string `json:"endpoint"` - IP string `json:"ip"` - Port int `json:"port"` - Transport string `json:"transport"` - Provider string `json:"provider"` - OpenVPNOptions OpenVPNOptions `json:"openvpn_options"` - Status ArchivalOpenVPNConnectStatus `json:"status"` - - // T0 can differ from StartTime because for TCP we take T0 *after* dialing has successfully completed. - // This might be counterintuitive, review. - T0 float64 `json:"t0,omitempty"` - T float64 `json:"t"` - Tags []string `json:"tags"` - TransactionID int64 `json:"transaction_id,omitempty"` -} - -// ArchivalOpenVPNConnectStatus is the status of ArchivalOpenVPNConnectResult. -type ArchivalOpenVPNConnectStatus struct { - Blocked *bool `json:"blocked,omitempty"` - Failure *string `json:"failure"` - Success bool `json:"success"` -} - -type ArchivalNetworkEvent struct { - // TODO(ainghazal): could properly propagate I/O errors during the handshake. - // Right now the network events WILL NOT append any RW error, but I think following - // other experiments one would expect such errors to be appended as failures in the operation. - // However, getting the start boundary for the failed operation might be tricky, - // I need to think about it. - Address string `json:"address,omitempty"` - Failure *string `json:"failure"` - NumBytes int64 `json:"num_bytes,omitempty"` - Operation string `json:"operation"` - Proto string `json:"proto,omitempty"` - T0 float64 `json:"t0,omitempty"` - T float64 `json:"t"` - TransactionID int64 `json:"transaction_id,omitempty"` - Tags []string `json:"tags,omitempty"` -} diff --git a/internal/experiment/openvpn/openvpn.go b/internal/experiment/openvpn/openvpn.go index 2dd0f99120..fe55f03806 100644 --- a/internal/experiment/openvpn/openvpn.go +++ b/internal/experiment/openvpn/openvpn.go @@ -40,10 +40,10 @@ type Config struct { // TestKeys contains the experiment's result. type TestKeys struct { - Success bool `json:"success"` - NetworkEvents []*vpntracex.Event `json:"network_events"` - TCPConnect []*model.ArchivalTCPConnectResult `json:"tcp_connect,omitempty"` - OpenVPNHandshake []*ArchivalOpenVPNHandshakeResult `json:"openvpn_handshake"` + Success bool `json:"success"` + NetworkEvents []*vpntracex.Event `json:"network_events"` + TCPConnect []*model.ArchivalTCPConnectResult `json:"tcp_connect,omitempty"` + OpenVPNHandshake []*model.ArchivalOpenVPNHandshakeResult `json:"openvpn_handshake"` } // NewTestKeys creates new openvpn TestKeys. @@ -52,15 +52,15 @@ func NewTestKeys() *TestKeys { Success: false, NetworkEvents: []*vpntracex.Event{}, TCPConnect: []*model.ArchivalTCPConnectResult{}, - OpenVPNHandshake: []*ArchivalOpenVPNHandshakeResult{}, + OpenVPNHandshake: []*model.ArchivalOpenVPNHandshakeResult{}, } } // SingleConnection contains the results of a single handshake. type SingleConnection struct { - TCPConnect *model.ArchivalTCPConnectResult `json:"tcp_connect,omitempty"` - OpenVPNHandshake *ArchivalOpenVPNHandshakeResult `json:"openvpn_handshake"` - NetworkEvents []*vpntracex.Event `json:"network_events"` + TCPConnect *model.ArchivalTCPConnectResult `json:"tcp_connect,omitempty"` + OpenVPNHandshake *model.ArchivalOpenVPNHandshakeResult `json:"openvpn_handshake"` + NetworkEvents []*vpntracex.Event `json:"network_events"` // TODO(ainghazal): make sure to document in the spec that these network events only cover the handshake. // TODO(ainghazal): in the future, we will want to store more operations under this struct for a single connection, // like pingResults or urlgetter calls. @@ -297,19 +297,19 @@ func (m *Measurer) connectAndHandshake( return &SingleConnection{ TCPConnect: trace.FirstTCPConnectOrNil(), - OpenVPNHandshake: &ArchivalOpenVPNHandshakeResult{ + OpenVPNHandshake: &model.ArchivalOpenVPNHandshakeResult{ BootstrapTime: bootstrapTime, Endpoint: endpoint.String(), IP: endpoint.IPAddr, Port: port, Transport: endpoint.Transport, Provider: endpoint.Provider, - OpenVPNOptions: OpenVPNOptions{ + OpenVPNOptions: model.ArchivalOpenVPNOptions{ Cipher: openvpnConfig.OpenVPNOptions().Cipher, Auth: openvpnConfig.OpenVPNOptions().Auth, Compression: string(openvpnConfig.OpenVPNOptions().Compress), }, - Status: ArchivalOpenVPNConnectStatus{ + Status: model.ArchivalOpenVPNConnectStatus{ Failure: &failure, Success: err == nil, }, diff --git a/internal/experiment/openvpn/openvpn_test.go b/internal/experiment/openvpn/openvpn_test.go index 2fff8bd9c5..0952d285fb 100644 --- a/internal/experiment/openvpn/openvpn_test.go +++ b/internal/experiment/openvpn/openvpn_test.go @@ -273,15 +273,15 @@ func TestAddConnectionTestKeys(t *testing.T) { Tags: []string{}, TransactionID: 1, }, - OpenVPNHandshake: &openvpn.ArchivalOpenVPNHandshakeResult{ + OpenVPNHandshake: &model.ArchivalOpenVPNHandshakeResult{ BootstrapTime: 1, Endpoint: "aa", IP: "1.1.1.1", Port: 1194, Transport: "tcp", Provider: "unknown", - OpenVPNOptions: openvpn.OpenVPNOptions{}, - Status: openvpn.ArchivalOpenVPNConnectStatus{}, + OpenVPNOptions: model.ArchivalOpenVPNOptions{}, + Status: model.ArchivalOpenVPNConnectStatus{}, T0: 0, T: 0, Tags: []string{}, @@ -305,10 +305,10 @@ func TestAddConnectionTestKeys(t *testing.T) { func TestAllConnectionsSuccessful(t *testing.T) { t.Run("all success", func(t *testing.T) { tk := openvpn.NewTestKeys() - tk.OpenVPNHandshake = []*openvpn.ArchivalOpenVPNHandshakeResult{ - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: true}}, - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: true}}, - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: true}}, + tk.OpenVPNHandshake = []*model.ArchivalOpenVPNHandshakeResult{ + {Status: model.ArchivalOpenVPNConnectStatus{Success: true}}, + {Status: model.ArchivalOpenVPNConnectStatus{Success: true}}, + {Status: model.ArchivalOpenVPNConnectStatus{Success: true}}, } if tk.AllConnectionsSuccessful() != true { t.Fatal("expected all connections successful") @@ -316,10 +316,10 @@ func TestAllConnectionsSuccessful(t *testing.T) { }) t.Run("one failure", func(t *testing.T) { tk := openvpn.NewTestKeys() - tk.OpenVPNHandshake = []*openvpn.ArchivalOpenVPNHandshakeResult{ - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: false}}, - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: true}}, - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: true}}, + tk.OpenVPNHandshake = []*model.ArchivalOpenVPNHandshakeResult{ + {Status: model.ArchivalOpenVPNConnectStatus{Success: false}}, + {Status: model.ArchivalOpenVPNConnectStatus{Success: true}}, + {Status: model.ArchivalOpenVPNConnectStatus{Success: true}}, } if tk.AllConnectionsSuccessful() != false { t.Fatal("expected false") @@ -327,10 +327,10 @@ func TestAllConnectionsSuccessful(t *testing.T) { }) t.Run("all failures", func(t *testing.T) { tk := openvpn.NewTestKeys() - tk.OpenVPNHandshake = []*openvpn.ArchivalOpenVPNHandshakeResult{ - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: false}}, - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: false}}, - {Status: openvpn.ArchivalOpenVPNConnectStatus{Success: false}}, + tk.OpenVPNHandshake = []*model.ArchivalOpenVPNHandshakeResult{ + {Status: model.ArchivalOpenVPNConnectStatus{Success: false}}, + {Status: model.ArchivalOpenVPNConnectStatus{Success: false}}, + {Status: model.ArchivalOpenVPNConnectStatus{Success: false}}, } if tk.AllConnectionsSuccessful() != false { t.Fatal("expected false") diff --git a/internal/model/archival.go b/internal/model/archival.go index ecef3c2427..86c2b52aec 100644 --- a/internal/model/archival.go +++ b/internal/model/archival.go @@ -392,3 +392,38 @@ type ArchivalNetworkEvent struct { TransactionID int64 `json:"transaction_id,omitempty"` Tags []string `json:"tags,omitempty"` } + +// +// OpenVPN +// + +// ArchivalOpenVPNHandshakeResult contains the result of a OpenVPN handshake. +type ArchivalOpenVPNHandshakeResult struct { + BootstrapTime float64 `json:"bootstrap_time,omitempty"` + Endpoint string `json:"endpoint"` + IP string `json:"ip"` + Port int `json:"port"` + Transport string `json:"transport"` + Provider string `json:"provider"` + OpenVPNOptions ArchivalOpenVPNOptions `json:"openvpn_options"` + Status ArchivalOpenVPNConnectStatus `json:"status"` + T0 float64 `json:"t0,omitempty"` + T float64 `json:"t"` + Tags []string `json:"tags"` + TransactionID int64 `json:"transaction_id,omitempty"` +} + +// ArchivalOpenVPNOptions is a subset of [vpnconfig.OpenVPNOptions] that we want to include +// in the archived result. +type ArchivalOpenVPNOptions struct { + Auth string `json:"auth,omitempty"` + Cipher string `json:"cipher,omitempty"` + Compression string `json:"compression,omitempty"` +} + +// ArchivalOpenVPNConnectStatus is the status of ArchivalOpenVPNConnectResult. +type ArchivalOpenVPNConnectStatus struct { + Blocked *bool `json:"blocked,omitempty"` + Failure *string `json:"failure"` + Success bool `json:"success"` +}