Move network/environment to netenv
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// +build !server
|
// +build !server
|
||||||
|
|
||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -16,7 +16,7 @@ var (
|
|||||||
dbusConnLock sync.Mutex
|
dbusConnLock sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func getNameserversFromDbus() ([]Nameserver, error) {
|
func getNameserversFromDbus() ([]Nameserver, error) { //nolint:gocognit // TODO
|
||||||
// cmdline tool for exploring: gdbus introspect --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager
|
// cmdline tool for exploring: gdbus introspect --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager
|
||||||
|
|
||||||
var nameservers []Nameserver
|
var nameservers []Nameserver
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// +build !linux
|
// +build !linux
|
||||||
|
|
||||||
package environment
|
package netenv
|
||||||
|
|
||||||
func getNameserversFromDbus() ([]Nameserver, error) {
|
func getNameserversFromDbus() ([]Nameserver, error) {
|
||||||
var nameservers []Nameserver
|
var nameservers []Nameserver
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import "net"
|
import "net"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import "net"
|
import "net"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import "net"
|
import "net"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// +build root
|
// +build root
|
||||||
|
|
||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/safing/portbase/modules"
|
"github.com/safing/portbase/modules"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,19 +13,13 @@ var (
|
|||||||
module *modules.Module
|
module *modules.Module
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitSubModule initializes module specific things with the given module. Intended to be used as part of the "network" module.
|
func init() {
|
||||||
func InitSubModule(m *modules.Module) {
|
module = modules.Register("netenv", nil, start, nil)
|
||||||
module = m
|
|
||||||
module.RegisterEvent(networkChangedEvent)
|
module.RegisterEvent(networkChangedEvent)
|
||||||
module.RegisterEvent(onlineStatusChangedEvent)
|
module.RegisterEvent(onlineStatusChangedEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartSubModule starts module specific things with the given module. Intended to be used as part of the "network" module.
|
func start() error {
|
||||||
func StartSubModule() error {
|
|
||||||
if module == nil {
|
|
||||||
return errors.New("not initialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
module.StartServiceWorker(
|
module.StartServiceWorker(
|
||||||
"monitor network changes",
|
"monitor network changes",
|
||||||
0,
|
0,
|
||||||
11
netenv/main_test.go
Normal file
11
netenv/main_test.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package netenv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/safing/portmaster/core/pmtesting"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
pmtesting.TestMain(m, module)
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package environment
|
package netenv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package environment
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/safing/portbase/modules"
|
|
||||||
"github.com/safing/portmaster/core"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
// setup
|
|
||||||
tmpDir, err := core.InitForTesting()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup package
|
|
||||||
netModule := modules.Register("network", nil, nil, nil, "core")
|
|
||||||
InitSubModule(netModule)
|
|
||||||
err = StartSubModule()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// run tests
|
|
||||||
rv := m.Run()
|
|
||||||
|
|
||||||
// teardown
|
|
||||||
core.StopTesting()
|
|
||||||
_ = os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
// exit with test run return value
|
|
||||||
os.Exit(rv)
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package network
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/safing/portbase/modules"
|
"github.com/safing/portbase/modules"
|
||||||
"github.com/safing/portmaster/network/environment"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -10,8 +9,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
module = modules.Register("network", nil, start, nil, "core")
|
module = modules.Register("network", nil, start, nil, "core", "processes")
|
||||||
environment.InitSubModule(module)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func start() error {
|
func start() error {
|
||||||
@@ -22,5 +20,5 @@ func start() error {
|
|||||||
|
|
||||||
go cleaner()
|
go cleaner()
|
||||||
|
|
||||||
return environment.StartSubModule()
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user