Skip to content

Commit

Permalink
move archival structs to internal/model
Browse files Browse the repository at this point in the history
  • Loading branch information
ainghazal committed Apr 3, 2024
1 parent e152ddd commit a3e8a5b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 80 deletions.
54 changes: 0 additions & 54 deletions internal/experiment/openvpn/archival.go

This file was deleted.

22 changes: 11 additions & 11 deletions internal/experiment/openvpn/openvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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,
},
Expand Down
30 changes: 15 additions & 15 deletions internal/experiment/openvpn/openvpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -305,32 +305,32 @@ 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")
}
})
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")
}
})
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")
Expand Down
35 changes: 35 additions & 0 deletions internal/model/archival.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit a3e8a5b

Please sign in to comment.