diff --git a/internal/engine/experiment/smtp/smtp.go b/internal/engine/experiment/smtp/smtp.go index 97c183f..568db04 100644 --- a/internal/engine/experiment/smtp/smtp.go +++ b/internal/engine/experiment/smtp/smtp.go @@ -8,7 +8,6 @@ import ( "net" "net/smtp" "net/url" - "strconv" "time" "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" @@ -26,9 +25,6 @@ var ( // errInvalidScheme indicates that the scheme is invalid errInvalidScheme = errors.New("scheme must be smtp(s)") - - // errInvalidPort indicates that the port provided could not be parsed as an int - errInvalidPort = errors.New("Port number is not a valid integer") ) const ( @@ -37,14 +33,16 @@ const ( ) // Config contains the experiment config. -type Config struct { +type Config struct{} + +type RuntimeConfig struct { host string port string forced_tls bool noop_count uint8 } -func config(input model.MeasurementTarget) (*Config, error) { +func config(input model.MeasurementTarget) (*RuntimeConfig, error) { if input == "" { // TODO: static input data (eg. gmail/riseup..) return nil, errNoInputProvided @@ -68,16 +66,11 @@ func config(input model.MeasurementTarget) (*Config, error) { port = "465" } } else { - // Check that requested port is a valid integer - _, err := strconv.Atoi(parsed.Port()) - if err != nil { - return nil, errInvalidPort - } else { - port = parsed.Port() - } + // Valid port is checked by URL parsing + port = parsed.Port() } - valid_config := Config{ + valid_config := RuntimeConfig{ host: parsed.Hostname(), forced_tls: parsed.Scheme == "smtps", port: port, @@ -321,7 +314,6 @@ func (m Measurer) Run( ctx context.Context, sess model.ExperimentSession, measurement *model.Measurement, callbacks model.ExperimentCallbacks, ) error { - log := sess.Logger() trace := measurexlite.NewTrace(0, measurement.MeasurementStartTimeSaved) @@ -372,7 +364,7 @@ func (m Measurer) Run( } // Try EHLO + NoOps - if !tcp_session.smtp("localhost", 10) { + if !tcp_session.smtp("localhost", config.noop_count) { continue } } else { @@ -386,7 +378,7 @@ func (m Measurer) Run( continue } - if !tcp_session.smtp("localhost", 10) { + if !tcp_session.smtp("localhost", config.noop_count) { continue } }