Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ LINUX_LIB_ARM64 := $(BIN_DIR)/linux-arm64/$(LANTERN_LIB_NAME).so
LINUX_LIB_BUILD := $(BIN_DIR)/linux/$(LINUX_LIB)
LINUX_INSTALLER_DEB := $(INSTALLER_NAME)$(if $(BUILD_TYPE),-$(BUILD_TYPE)).deb
LINUX_INSTALLER_RPM := $(INSTALLER_NAME)$(if $(BUILD_TYPE),-$(BUILD_TYPE)).rpm
LINUX_SERVICE_NAME := lanternsvc
LINUX_SERVICE_SRC := ./$(LANTERN_CORE)/cmd/lanternsvc
LINUX_SERVICE_BUILD_AMD64 := $(BIN_DIR)/linux-amd64/$(LINUX_SERVICE_NAME)
LINUX_SERVICE_BUILD_ARM64 := $(BIN_DIR)/linux-arm64/$(LINUX_SERVICE_NAME)
LINUX_PKG_ROOT := linux/packaging
LINUX_PKG_USR_LIB_LANTERN := $(LINUX_PKG_ROOT)/usr/lib/lantern
LINUX_PKG_SYSTEMD_DIR := $(LINUX_PKG_ROOT)/usr/lib/systemd/system
LINUX_SYSTEMD_UNIT_SRC := $(LANTERN_CORE)/linux/packaging/systemd/lantern.service
LINUX_SYSTEMD_UNIT_DST := $(LINUX_PKG_SYSTEMD_DIR)/lantern.service

ifeq ($(OS),Windows_NT)
PS := powershell -NoProfile -ExecutionPolicy Bypass -Command
Expand Down Expand Up @@ -256,18 +265,48 @@ linux: linux-amd64
mkdir -p $(BIN_DIR)/linux
cp $(LINUX_LIB_AMD64) $(LINUX_LIB_BUILD)

.PHONY: linux-service-amd64 linux-service-arm64 stage-linux-service

linux-service-amd64: $(GO_SOURCES)
$(call MKDIR_P,$(dir $(LINUX_SERVICE_BUILD_AMD64)))
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 \
go build -v -trimpath -tags "$(TAGS)" \
-ldflags "-w -s $(EXTRA_LDFLAGS)" \
-o $(LINUX_SERVICE_BUILD_AMD64) $(LINUX_SERVICE_SRC)
@echo "Built Linux service: $(LINUX_SERVICE_BUILD_AMD64)"

linux-service-arm64: $(GO_SOURCES)
$(call MKDIR_P,$(dir $(LINUX_SERVICE_BUILD_ARM64)))
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 \
go build -v -trimpath -tags "$(TAGS)" \
-ldflags "-w -s $(EXTRA_LDFLAGS)" \
-o $(LINUX_SERVICE_BUILD_ARM64) $(LINUX_SERVICE_SRC)
@echo "Built Linux service: $(LINUX_SERVICE_BUILD_ARM64)"

stage-linux-service: linux-service-amd64
@echo "Staging systemd unit + service binary $(LINUX_PKG_ROOT)..."
$(call MKDIR_P,$(LINUX_PKG_USR_LIB_LANTERN))
$(call COPY_FILE,$(LINUX_SERVICE_BUILD_AMD64),$(LINUX_PKG_USR_LIB_LANTERN)/$(LINUX_SERVICE_NAME))
$(call MKDIR_P,$(LINUX_PKG_SYSTEMD_DIR))
$(call COPY_FILE,$(LINUX_SYSTEMD_UNIT_SRC),$(LINUX_SYSTEMD_UNIT_DST))

.PHONY: linux-debug
linux-debug:
@echo "Building Flutter app (debug) for Linux..."
flutter build linux --debug

.PHONY: linux-release
linux-release: clean linux pubget gen
.PHONY: linux-release
linux-release: clean linux pubget gen stage-linux-service
@echo "Building Flutter app (release) for Linux..."
flutter build linux --release $(DART_DEFINES)

cp $(LINUX_LIB_BUILD) build/linux/x64/release/bundle
patchelf --set-rpath '$$ORIGIN' build/linux/x64/release/bundle/lantern || true

flutter_distributor package --build-dart-define=BUILD_TYPE=$(BUILD_TYPE) \
--build-dart-define=VERSION=$(VERSION) --platform linux --targets "deb,rpm" --skip-clean

mv $(DIST_OUT)/$(APP_VERSION)/lantern-$(APP_VERSION)-linux.rpm $(LINUX_INSTALLER_RPM)
mv $(DIST_OUT)/$(APP_VERSION)/lantern-$(APP_VERSION)-linux.deb $(LINUX_INSTALLER_DEB)

Expand Down
18 changes: 17 additions & 1 deletion distribute_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,27 @@ releases:
build_args:
dart-define:
APP_ENV: dev
# See full documentation: https://fastforge.dev/makers/exe

- name: windows-exe
package:
platform: windows
target: exe
build_args:
dart-define:
APP_ENV: dev

- name: linux-deb
package:
platform: linux
target: deb
build_args:
dart-define:
APP_ENV: dev

- name: linux-rpm
package:
platform: linux
target: rpm
build_args:
dart-define:
APP_ENV: dev
307 changes: 153 additions & 154 deletions go.mod

Large diffs are not rendered by default.

751 changes: 362 additions & 389 deletions go.sum

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions lantern-core/cmd/lanternsvc/main_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build linux

package main

import (
"flag"
"log"
"log/slog"
"os"
"os/signal"
"syscall"
"time"

"github.com/sagernet/sing-box/experimental/libbox"

"github.com/getlantern/radiance/common"
"github.com/getlantern/radiance/vpn"
)

var (
dataPath = flag.String("data-path", "$HOME/.lantern", "Path to store data")
logPath = flag.String("log-path", "$HOME/.lantern", "Path to store logs")
logLevel = flag.String("log-level", "info", "Logging level (trace, debug, info, warn, error)")
)

func main() {
flag.Parse()

dp := os.ExpandEnv(*dataPath)
lp := os.ExpandEnv(*logPath)

slog.Info("Starting lanternsvc (radiance daemon)", "version", common.Version, "dataPath", dp, "logPath", lp)

platIfceProvider := func() libbox.PlatformInterface { return nil }
ipcServer, err := vpn.InitIPC(dp, lp, *logLevel, platIfceProvider)
if err != nil {
log.Fatalf("Failed to initialize IPC: %v\n", err)
}
defer ipcServer.Close()

// Wait for a signal to gracefully shut down.
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh

slog.Info("Shutting down...")
time.AfterFunc(15*time.Second, func() {
log.Fatal("Failed to shut down in time, forcing exit.")
})

status, _ := vpn.GetStatus()
if status.TunnelOpen {
vpn.Disconnect()
}
}
73 changes: 0 additions & 73 deletions lantern-core/ffi/ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,41 +251,6 @@ func reportIssue(emailC, typeC, descC, deviceC, modelC, logPathC *C.char) *C.cha
return C.CString("ok")
}

// startVPN initializes and starts the VPN server if it is not already running.
//
//export startVPN
func startVPN(_logDir, _dataDir, _locale *C.char) *C.char {
slog.Debug("startVPN called")
sendStatusToPort(Connecting)
if err := vpn_tunnel.StartVPN(nil, &utils.Opts{
DataDir: C.GoString(_dataDir),
Locale: C.GoString(_locale),
}); err != nil {
err = fmt.Errorf("unable to start vpn server: %v", err)
sendStatusToPort(Disconnected)
return C.CString(err.Error())
}
sendStatusToPort(Connected)
slog.Debug("VPN server started successfully")
return C.CString("ok")
}

// stopVPN stops the VPN server if it is running.
//
//export stopVPN
func stopVPN() *C.char {
slog.Debug("stopVPN called")
sendStatusToPort(Disconnecting)
if err := vpn_tunnel.StopVPN(); err != nil {
err = fmt.Errorf("unable to stop vpn server: %v", err)
sendStatusToPort(Connected)
return C.CString(err.Error())
}
sendStatusToPort(Disconnected)
slog.Debug("VPN server stopped successfully")
return C.CString("ok")
}

// getAutoLocation returns the auto location in JSON format.
//
//export getAutoLocation
Expand Down Expand Up @@ -345,29 +310,6 @@ func getAvailableServers() *C.char {
return C.CString(string(c.GetAvailableServers()))
}

// connectToServer sets the private server with the given tag.
// connectToServer connects to a specific VPN server identified by the location type and tag.
// connectToServer will open and start the VPN tunnel if it is not already running.
//
//export connectToServer
func connectToServer(_location, _tag, _logDir, _dataDir, _locale *C.char) *C.char {
tag := C.GoString(_tag)
locationType := C.GoString(_location)

// Valid location types are:
// auto,
// privateServer,
// lanternLocation;
if err := vpn_tunnel.ConnectToServer(locationType, tag, nil, &utils.Opts{
DataDir: C.GoString(_dataDir),
Locale: C.GoString(_locale),
}); err != nil {
return SendError(fmt.Errorf("Error setting private server: %v", err))
}
slog.Debug("Private server set with tag", "tag", tag)
return C.CString("ok")
}

func sendStatusToPort(status VPNStatus) {
slog.Debug("sendStatusToPort called", "status", status)
if statusPort == 0 {
Expand All @@ -383,21 +325,6 @@ func sendStatusToPort(status VPNStatus) {

}

// isVPNConnected checks if the VPN server is running and connected.
//
//export isVPNConnected
func isVPNConnected() C.int {
connected := vpn_tunnel.IsVPNRunning()
slog.Debug("isVPNConnected called, connected:", "connected", connected)
if connected {
sendStatusToPort(Connected)
return 1
} else {
sendStatusToPort(Disconnected)
return 0
}
}

// APIS
// Get user data from the local config
//
Expand Down
Loading
Loading