-
Notifications
You must be signed in to change notification settings - Fork 0
Add start endpoint and decouple IPC from tunnel lifecycle #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6203774
add start endpoint
atavism 4681415
clean-ups
atavism 88ec392
Add InitIPC
atavism 0265b6d
use basePath
atavism d2be529
Add comments
atavism c9c750c
code review updates
atavism a238ce4
clean-up
atavism f9a3ff3
code review updates
atavism 7e114b1
update slog.Error call to fix tests
atavism b56c020
Remove unused, add comments
atavism b7ccaec
Remove unused, add comments
atavism 87fe370
Merge remote-tracking branch 'origin/main' into atavism/radiance-ipc-…
atavism File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package vpn | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/getlantern/radiance/common" | ||
"github.com/getlantern/radiance/vpn/ipc" | ||
"github.com/sagernet/sing-box/experimental/clashapi" | ||
"github.com/sagernet/sing-box/experimental/libbox" | ||
) | ||
|
||
var platIfceProvider func() libbox.PlatformInterface | ||
|
||
// closedSvc is a stub service used while the tunnel is down | ||
type closedSvc struct{} | ||
|
||
func (closedSvc) Ctx() context.Context { return context.Background() } | ||
func (closedSvc) Status() string { return ipc.StatusClosed } | ||
func (closedSvc) ClashServer() *clashapi.Server { return nil } | ||
func (closedSvc) Close() error { return nil } | ||
|
||
// InitIPC starts the long-lived IPC server and hooks it up to establishConnection | ||
func InitIPC(basePath string, provider func() libbox.PlatformInterface) error { | ||
if ipcServer != nil { | ||
// already started | ||
return nil | ||
} | ||
platIfceProvider = provider | ||
if runtime.GOOS != "windows" && basePath != "" { | ||
ipc.SetSocketPath(basePath) | ||
} | ||
|
||
ipcServer = ipc.NewServer(closedSvc{}) | ||
// start tunnel via IPC. How /service/start brings the tunnel up | ||
ipcServer.SetStartFn(func(ctx context.Context, group, tag string) (ipc.Service, error) { | ||
path := basePath | ||
if path == "" { | ||
path = common.DataPath() | ||
} | ||
|
||
_ = newSplitTunnel(path) | ||
|
||
opts, err := buildOptions(group, path) | ||
if err != nil { | ||
return nil, fmt.Errorf("build options: %w", err) | ||
} | ||
|
||
var pi libbox.PlatformInterface | ||
if platIfceProvider != nil { | ||
pi = platIfceProvider() | ||
} | ||
|
||
if err := establishConnection(group, tag, opts, path, pi); err != nil { | ||
return nil, err | ||
} | ||
return tInstance, nil | ||
}) | ||
return ipcServer.Start(basePath) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.