platform: Implement set underlying networks for android
This commit is contained in:
@@ -78,6 +78,10 @@ func (s *platformInterfaceStub) Interfaces() ([]adapter.NetworkInterface, error)
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
|
||||
func (s *platformInterfaceStub) SetUnderlyingNetworks(networks []adapter.NetworkInterface) error {
|
||||
return os.ErrInvalid
|
||||
}
|
||||
|
||||
func (s *platformInterfaceStub) UnderNetworkExtension() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ type PlatformInterface interface {
|
||||
StartDefaultInterfaceMonitor(listener InterfaceUpdateListener) error
|
||||
CloseDefaultInterfaceMonitor(listener InterfaceUpdateListener) error
|
||||
GetInterfaces() (NetworkInterfaceIterator, error)
|
||||
SetUnderlyingNetworks(networks RawNetworkIterator) error
|
||||
UnderNetworkExtension() bool
|
||||
IncludeAllNetworks() bool
|
||||
ReadWIFIState() *WIFIState
|
||||
@@ -50,6 +51,8 @@ type NetworkInterface struct {
|
||||
Type int32
|
||||
DNSServer StringIterator
|
||||
Metered bool
|
||||
|
||||
RawNetwork RawNetwork
|
||||
}
|
||||
|
||||
type WIFIState struct {
|
||||
@@ -66,6 +69,11 @@ type NetworkInterfaceIterator interface {
|
||||
HasNext() bool
|
||||
}
|
||||
|
||||
type RawNetworkIterator interface {
|
||||
Next() RawNetwork
|
||||
HasNext() bool
|
||||
}
|
||||
|
||||
type Notification struct {
|
||||
Identifier string
|
||||
TypeName string
|
||||
|
||||
@@ -15,6 +15,7 @@ type Interface interface {
|
||||
OpenTun(options *tun.Options, platformOptions option.TunPlatformOptions) (tun.Tun, error)
|
||||
CreateDefaultInterfaceMonitor(logger logger.Logger) tun.DefaultInterfaceMonitor
|
||||
Interfaces() ([]adapter.NetworkInterface, error)
|
||||
SetUnderlyingNetworks(networks []adapter.NetworkInterface) error
|
||||
UnderNetworkExtension() bool
|
||||
IncludeAllNetworks() bool
|
||||
ClearDNSCache()
|
||||
|
||||
3
experimental/libbox/raw_network_android.go
Normal file
3
experimental/libbox/raw_network_android.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package libbox
|
||||
|
||||
type RawNetwork interface{}
|
||||
7
experimental/libbox/raw_network_stub.go
Normal file
7
experimental/libbox/raw_network_stub.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build !android
|
||||
|
||||
package libbox
|
||||
|
||||
type RawNetwork interface {
|
||||
stub()
|
||||
}
|
||||
@@ -206,11 +206,18 @@ func (w *platformInterfaceWrapper) Interfaces() ([]adapter.NetworkInterface, err
|
||||
DNSServers: iteratorToArray[string](netInterface.DNSServer),
|
||||
Expensive: netInterface.Metered || isDefault && w.isExpensive,
|
||||
Constrained: isDefault && w.isConstrained,
|
||||
RawNetwork: netInterface.RawNetwork,
|
||||
})
|
||||
}
|
||||
return interfaces, nil
|
||||
}
|
||||
|
||||
func (w *platformInterfaceWrapper) SetUnderlyingNetworks(networks []adapter.NetworkInterface) error {
|
||||
return w.iif.SetUnderlyingNetworks(newIterator(common.Map(networks, func(it adapter.NetworkInterface) RawNetwork {
|
||||
return it.RawNetwork.(RawNetwork)
|
||||
})))
|
||||
}
|
||||
|
||||
func (w *platformInterfaceWrapper) UnderNetworkExtension() bool {
|
||||
return w.iif.UnderNetworkExtension()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user