mirror of
https://github.com/safing/portmaster
synced 2025-09-01 10:09:11 +00:00
Move network/environment to netenv
This commit is contained in:
parent
1a3f9a75da
commit
dc32e72b3a
21 changed files with 34 additions and 68 deletions
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"net"
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,6 +1,6 @@
|
|||
// +build !server
|
||||
|
||||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -16,7 +16,7 @@ var (
|
|||
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
|
||||
|
||||
var nameservers []Nameserver
|
|
@ -1,6 +1,6 @@
|
|||
// +build !linux
|
||||
|
||||
package environment
|
||||
package netenv
|
||||
|
||||
func getNameserversFromDbus() ([]Nameserver, error) {
|
||||
var nameservers []Nameserver
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"os"
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import "net"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"net"
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import "net"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"bufio"
|
|
@ -1,6 +1,6 @@
|
|||
// +build linux
|
||||
|
||||
package environment
|
||||
package netenv
|
||||
|
||||
import "testing"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import "net"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,6 +1,6 @@
|
|||
// +build root
|
||||
|
||||
package environment
|
||||
package netenv
|
||||
|
||||
import "testing"
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/safing/portbase/modules"
|
||||
)
|
||||
|
||||
|
@ -15,19 +13,13 @@ var (
|
|||
module *modules.Module
|
||||
)
|
||||
|
||||
// InitSubModule initializes module specific things with the given module. Intended to be used as part of the "network" module.
|
||||
func InitSubModule(m *modules.Module) {
|
||||
module = m
|
||||
func init() {
|
||||
module = modules.Register("netenv", nil, start, nil)
|
||||
module.RegisterEvent(networkChangedEvent)
|
||||
module.RegisterEvent(onlineStatusChangedEvent)
|
||||
}
|
||||
|
||||
// StartSubModule starts module specific things with the given module. Intended to be used as part of the "network" module.
|
||||
func StartSubModule() error {
|
||||
if module == nil {
|
||||
return errors.New("not initialized")
|
||||
}
|
||||
|
||||
func start() error {
|
||||
module.StartServiceWorker(
|
||||
"monitor network changes",
|
||||
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 (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package environment
|
||||
package netenv
|
||||
|
||||
import (
|
||||
"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 (
|
||||
"github.com/safing/portbase/modules"
|
||||
"github.com/safing/portmaster/network/environment"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -10,8 +9,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
module = modules.Register("network", nil, start, nil, "core")
|
||||
environment.InitSubModule(module)
|
||||
module = modules.Register("network", nil, start, nil, "core", "processes")
|
||||
}
|
||||
|
||||
func start() error {
|
||||
|
@ -22,5 +20,5 @@ func start() error {
|
|||
|
||||
go cleaner()
|
||||
|
||||
return environment.StartSubModule()
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue