@@ -105,34 +105,42 @@ func (a *Application) Init(ctx context.Context, tunDevice tun.Device) error {
105105 a .logger .Infof ("P2P host initialized. My peer_id: %s" , p2pHost .ID ().String ())
106106 a .logger .Infof ("P2P listening on addresses: %v" , p2pHost .Addrs ())
107107
108- localIP , netMask := a .Conf .VPNLocalIPMask ()
109- interfaceName := a .Conf .VPNConfig .InterfaceName
110- vpnDevice , err := vpn .NewDevice (tunDevice , interfaceName , localIP , netMask )
111- if err != nil {
112- return fmt .Errorf ("failed to init vpn: %v" , err )
108+ if a .Conf .VPNConfig .DisableVPNInterface {
109+ a .logger .Info ("VPN interface is disabled from config" )
110+ } else {
111+ localIP , netMask := a .Conf .VPNLocalIPMask ()
112+ interfaceName := a .Conf .VPNConfig .InterfaceName
113+ a .vpnDevice , err = vpn .NewDevice (tunDevice , interfaceName , localIP , netMask )
114+ if err != nil {
115+ return fmt .Errorf ("failed to init vpn: %v" , err )
116+ }
117+ a .logger .Infof ("VPN interface created. Name: %s CIDR: %s" , interfaceName , & net.IPNet {IP : localIP , Mask : netMask })
118+
119+ a .Tunnel = service .NewTunnel (a .P2p , a .vpnDevice , a .Conf )
120+ go a .vpnDevice .ReadTUNPackets (a .Tunnel .HandleReadPackets )
113121 }
114- a .vpnDevice = vpnDevice
115- a .logger .Infof ("VPN interface created. Name: %s CIDR: %s" , interfaceName , & net.IPNet {IP : localIP , Mask : netMask })
116122
117123 a .P2p .Bootstrap ()
118124
119125 a .Dns = NewDNSService (a .Conf , a .Eventbus , a .ctx , a .logger )
120126 a .AuthStatus = service .NewAuthStatus (a .P2p , a .Conf , a .Eventbus )
121- a .Tunnel = service .NewTunnel (a .P2p , vpnDevice , a .Conf )
122- go vpnDevice .ReadTUNPackets (a .Tunnel .HandleReadPackets )
123127 a .SOCKS5 , err = service .NewSOCKS5 (a .P2p , a .Conf )
124128 if err != nil {
125129 return fmt .Errorf ("failed to init socks5: %v" , err )
126130 }
127131
128132 p2pHost .SetStreamHandler (protocol .GetStatusMethod , a .AuthStatus .StatusStreamHandler )
129133 p2pHost .SetStreamHandler (protocol .AuthMethod , a .AuthStatus .AuthStreamHandler )
130- p2pHost .SetStreamHandler (protocol .TunnelPacketMethod , a .Tunnel .StreamHandler )
134+ if a .Tunnel != nil {
135+ p2pHost .SetStreamHandler (protocol .TunnelPacketMethod , a .Tunnel .StreamHandler )
136+ }
131137 p2pHost .SetStreamHandler (protocol .Socks5PacketMethod , a .SOCKS5 .ProxyStreamHandler )
132138
133- awlevent .WrapSubscriptionToCallback (a .ctx , func (_ interface {}) {
134- a .Tunnel .RefreshPeersList ()
135- }, a .Eventbus , new (awlevent.KnownPeerChanged ))
139+ if a .Tunnel != nil {
140+ awlevent .WrapSubscriptionToCallback (a .ctx , func (_ interface {}) {
141+ a .Tunnel .RefreshPeersList ()
142+ }, a .Eventbus , new (awlevent.KnownPeerChanged ))
143+ }
136144
137145 handler := api .NewHandler (a .Conf , a .P2p , a .AuthStatus , a .Tunnel , a .SOCKS5 , a .LogBuffer , a .Dns )
138146 a .Api = handler
@@ -146,7 +154,7 @@ func (a *Application) Init(ctx context.Context, tunDevice tun.Device) error {
146154 go a .AuthStatus .BackgroundExchangeStatusInfo (a .ctx )
147155 go a .SOCKS5 .ServeConns (a .ctx )
148156
149- if useAwldns {
157+ if useAwldns && ! a . Conf . VPNConfig . DisableVPNInterface {
150158 interfaceName , err := a .vpnDevice .InterfaceName ()
151159 if err != nil {
152160 a .logger .Errorf ("failed to get TUN interface name: %v" , err )
0 commit comments