-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(miniooni): minimal JavaScript-ing capabilities (#1437)
This diff implements part of my SplinterCon JavaScript demo (#1423). We only include minimal functionality here. The bare minimum to be useful when doing research. Closes ooni/probe#2647. Because this is experimental code and there's no commitment to productionize it, I have decided to create a specific subpackage `internal/x` that should host our in-tree experiments. (I will also mode `dslx` in there.)
- Loading branch information
1 parent
fdce52c
commit 7a2c9fd
Showing
51 changed files
with
2,926 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/apex/log" | ||
"github.com/ooni/probe-cli/v3/internal/runtimex" | ||
"github.com/ooni/probe-cli/v3/internal/x/dsljavascript" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// registerJavaScript registers the javascript subcommand | ||
func registerJavaScript(rootCmd *cobra.Command, globalOptions *Options) { | ||
subCmd := &cobra.Command{ | ||
Use: "javascript", | ||
Short: "Very experimental command to run JavaScript snippets", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
runtimex.Assert(len(args) == 1, "expected exactly one argument") | ||
javaScriptMain(args[0]) | ||
}, | ||
} | ||
rootCmd.AddCommand(subCmd) | ||
} | ||
|
||
func javaScriptMain(scriptPath string) { | ||
// TODO(bassosimone): for an initial prototype, using a local directory is | ||
// good, but, if we make this more production ready, we probably need to define | ||
// a specific location under the $OONI_HOME. | ||
config := &dsljavascript.VMConfig{ | ||
Logger: log.Log, | ||
ScriptBaseDir: filepath.Join(".", "./javascript"), | ||
} | ||
|
||
log.Warnf("The javascript subcommand is highly experimental and may be removed") | ||
log.Warnf("or heavily modified without prior notice. For more information, for now") | ||
log.Warnf("see https://github.com/bassosimone/2023-12-09-ooni-javascript.") | ||
|
||
runtimex.Try0(dsljavascript.RunScript(config, scriptPath)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package x contains highly experimental packages. | ||
package x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dslengine | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/measurexlite" | ||
"github.com/ooni/probe-cli/v3/internal/model" | ||
"github.com/ooni/probe-cli/v3/internal/x/dslvm" | ||
) | ||
|
||
// NewRuntimeMeasurexLite creates a [Runtime] using [measurexlite] to collect [*Observations]. | ||
func NewRuntimeMeasurexLite(logger model.Logger, zeroTime time.Time, options ...Option) *RuntimeMeasurexLite { | ||
values := newOptionValues(options...) | ||
|
||
rt := &RuntimeMeasurexLite{ | ||
MinimalRuntime: NewMinimalRuntime(logger, zeroTime, options...), | ||
netx: values.netx, | ||
} | ||
|
||
return rt | ||
} | ||
|
||
// RuntimeMeasurexLite uses [measurexlite] to collect [*Observations.] | ||
type RuntimeMeasurexLite struct { | ||
*MinimalRuntime | ||
netx model.MeasuringNetwork | ||
} | ||
|
||
// NewTrace implements Runtime. | ||
func (p *RuntimeMeasurexLite) NewTrace(index int64, zeroTime time.Time, tags ...string) dslvm.Trace { | ||
trace := measurexlite.NewTrace(index, zeroTime, tags...) | ||
trace.Netx = p.netx | ||
return trace | ||
} | ||
|
||
var _ dslvm.Runtime = &RuntimeMeasurexLite{} |
Oops, something went wrong.