Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

refactor(intra): use outline-sdk as the network stack #125

Merged
merged 5 commits into from
Sep 28, 2023

Conversation

jyyi1
Copy link
Contributor

@jyyi1 jyyi1 commented Sep 8, 2023

This PR replaces the go-tun2socks/core with outline-sdk/* in the Intra project, and removes the dependency on tunnel.Tunnel, making the intra package a standalone Go package that can be copied to other locations, such as the Intra repository.

I kept the signatures of all exported interfaces the same. We can refactor them after we move the code to the Intra repository.

Related PR: Jigsaw-Code/outline-sdk#66

intra/android/tun2socks.go Outdated Show resolved Hide resolved
intra/stream_dialer.go Outdated Show resolved Hide resolved
@fortuna fortuna self-requested a review September 8, 2023 19:23
go.mod Outdated
@@ -8,16 +8,16 @@ require (
github.com/Jigsaw-Code/outline-sdk v0.0.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update this to v0.0.6 to make sure it's still compatible.

intra/tunnel.go Outdated Show resolved Hide resolved
intra/android/tun2socks.go Outdated Show resolved Hide resolved
intra/tunnel.go Outdated
core.RegisterOutputFn(tunWriter.Write)
t := &intratunnel{
Tunnel: tunnel.NewTunnel(tunWriter, core.NewLWIPStack()),
func NewTunnel(fakedns string, dohdns doh.Transport, tun io.Closer, protector protect.Protector, listener Listener) (t *Tunnel, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IPDevice should be independent of the TUN device.
Remove the tun input.

Also, remove the Disconnect() method. You are already exposing Close().

In the relay code, you can close the tun device once the IPDevice closes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was trying to keep all interface unchanged. Disconnect() is exposed to Java as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite confusing to have both, and it complicates our code. To figure out why we need to pass the tun device is mind-boggling.

It's not a requirement to preserve the old interface, especially for Intra. That requirement only gets in our way.

We need to prioritize not having to worry about the Go backend interface, as that's a major productivity hurdle. That was the point of moving the code to the client repo too (which I understand will happen separately). Perhaps it makes sense to move the code first before future changes. For the Outline integration, let's move the code first (without changes, but proper build), before changing it. I believe that will work better, as it allows use to change the backend and frontend at once.

We can leave the clean up to another PR, but if we want Intra to be a model to copy, we should simplify and clean up the legacy interfaces, so people don't spread bad practices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed offline, in this PR, let's focus on "refactoring" without changing the old interface. Then I'll copy the code to the Intra repository without any code modification (but with Gradle build script). After that, we can further redesign the interface (e.g. use IntraDevice, and only export one single package instead of five).

return t.sni.Configure(f, suffix, strings.ToLower(country))
}

func (t *Tunnel) Disconnect() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the refactor planning comment above.

intra/android/tun2socks.go Show resolved Hide resolved
}

func isErrClosed(err error) bool {
return errors.Is(err, os.ErrClosed) || errors.Is(err, fs.ErrClosed) || errors.Is(err, network.ErrClosed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we return network.ErrClosed on Reads? I thought we would just return ErrClosed on writes, and return EOF on reads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not us, it's the tun device (os.File) that doesn't conform with go's rules, it will return os.ErrClosed. But I expanded to more similar ErrClosed errors here.

intra/packet_proxy.go Outdated Show resolved Hide resolved
intra/packet_proxy.go Outdated Show resolved Hide resolved
intra/packet_proxy.go Outdated Show resolved Hide resolved
@jyyi1 jyyi1 requested a review from fortuna September 19, 2023 22:01
@jyyi1
Copy link
Contributor Author

jyyi1 commented Sep 26, 2023

@fortuna , this PR is ready for review. Thanks.

@jyyi1 jyyi1 merged commit 37e9419 into master Sep 28, 2023
7 checks passed
@jyyi1 jyyi1 deleted the junyi/use-sdk-for-intra branch September 28, 2023 20:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants