273b70bacc
## Checklist - [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md) - [x] reference issue for this pull request: https://github.com/ooni/probe/issues/1885 - [x] related ooni/spec pull request: N/A Location of the issue tracker: https://github.com/ooni/probe ## Description This PR contains a set of changes to move important interfaces and data types into the `./internal/model` package. The criteria for including an interface or data type in here is roughly that the type should be important and used by several packages. We are especially interested to move more interfaces here to increase modularity. An additional side effect is that, by reading this package, one should be able to understand more quickly how different parts of the codebase interact with each other. This is what I want to move in `internal/model`: - [x] most important interfaces from `internal/netxlite` - [x] everything that was previously part of `internal/engine/model` - [x] mocks from `internal/netxlite/mocks` should also be moved in here as a subpackage
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
)
|
|
|
|
// TODO(bassosimone): maybe keep track of which measurements
|
|
// could not be submitted by a specific submitter?
|
|
|
|
// Submitter submits a measurement to the OONI collector.
|
|
type Submitter interface {
|
|
// Submit submits the measurement and updates its
|
|
// report ID field in case of success.
|
|
Submit(ctx context.Context, m *model.Measurement) error
|
|
}
|
|
|
|
// SubmitterSession is the Submitter's view of the Session.
|
|
type SubmitterSession interface {
|
|
// NewSubmitter creates a new probeservices Submitter.
|
|
NewSubmitter(ctx context.Context) (Submitter, error)
|
|
}
|
|
|
|
// SubmitterConfig contains settings for NewSubmitter.
|
|
type SubmitterConfig struct {
|
|
// Enabled is true if measurement submission is enabled.
|
|
Enabled bool
|
|
|
|
// Session is the current session.
|
|
Session SubmitterSession
|
|
|
|
// Logger is the logger to be used.
|
|
Logger model.Logger
|
|
}
|
|
|
|
// NewSubmitter creates a new submitter instance. Depending on
|
|
// whether submission is enabled or not, the returned submitter
|
|
// instance migh just be a stub implementation.
|
|
func NewSubmitter(ctx context.Context, config SubmitterConfig) (Submitter, error) {
|
|
if !config.Enabled {
|
|
return stubSubmitter{}, nil
|
|
}
|
|
subm, err := config.Session.NewSubmitter(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return realSubmitter{subm: subm, logger: config.Logger}, nil
|
|
}
|
|
|
|
type stubSubmitter struct{}
|
|
|
|
func (stubSubmitter) Submit(ctx context.Context, m *model.Measurement) error {
|
|
return nil
|
|
}
|
|
|
|
var _ Submitter = stubSubmitter{}
|
|
|
|
type realSubmitter struct {
|
|
subm Submitter
|
|
logger model.Logger
|
|
}
|
|
|
|
func (rs realSubmitter) Submit(ctx context.Context, m *model.Measurement) error {
|
|
rs.logger.Info("submitting measurement to OONI collector; please be patient...")
|
|
return rs.subm.Submit(ctx, m)
|
|
}
|