-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat: create outline-fetch tool #45
Conversation
transport/split/stream_dialer.go
Outdated
defer func() { | ||
w.bytesCopied += written | ||
}() | ||
n, err := io.CopyN(w.writer, source, w.splitPoint-w.bytesCopied) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of splitting the traffic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because some bytes may had been copied already from previous writes, so you need to discount them to hit the splitPoint correctly.
transport/split/stream_dialer.go
Outdated
|
||
// NewStreamDialer creates a client that splits the outgoing strean at byte splitpoint. | ||
func NewStreamDialer(dialer transport.StreamDialer, splitPoint int64) (transport.StreamDialer, error) { | ||
if dialer == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also check splitPoint > 0
?
x/outline-fetch/main.go
Outdated
if err != nil { | ||
return nil, fmt.Errorf("failed to parse access key: %w", err) | ||
} | ||
switch accessKeyURL.Scheme { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we include this logic into the shared ParseAccessKey
? So the function could return different configs:
type Scheme uint
const (
Shadowsocks Scheme = 1 << iota
Socks5
Splitter
)
type Config interface {
}
type SSConfig interface {
Config
}
type Socks5Config interface {
Config
}
func ParseAccessKey(accessKey string, acceptedSchemes Scheme) (Scheme, Config) {
}
Also the shared NewOutlineStreamDialer(accessKey string, acceptedSchemes Scheme)
may also parse to different types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config parser should just output the dialer. No need for introducing intermediate configs.
x/outline-fetch/main.go
Outdated
log.Fatalf("Could not create dialer: %v", err) | ||
} | ||
httpClient := &http.Client{Transport: &http.Transport{DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { | ||
return dialer.Dial(ctx, addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to make sure network == "tcp"
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the split logic, so it doesn't depend on that PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jyyi1 please take another look. I've moves the examples into a subdirectory, and simplified the connectivity to be able to merge the config logic. I'll restore the extra connectivity information once we have tracing in place, but I don't want to block on that to submit the fetch tool, since it's a nice example and useful for testing strategies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LTGM. With some small comments.
x/examples/outline-fetch/main.go
Outdated
if err != nil { | ||
log.Fatalf("Could not create dialer: %v", err) | ||
} | ||
httpClient := &http.Client{Transport: &http.Transport{DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit can we separate this into multiple lines? It looks a little bit messy. But if go format
wraps it into a single line then just leave it as it is now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned up
Co-authored-by: J. Yi <[email protected]>
Co-authored-by: J. Yi <[email protected]>
This PR creates a command-line tool to fetch a web page given its URL and the transport config.
It also moves outline-connectivity to
x/examples
and shares the config code.Direct fetch:
Using a Shadowsocks server:
Using a SOCKS5 server: