2022-09-17 19:07:00 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2023-04-06 20:45:49 +00:00
|
|
|
"context"
|
2022-09-17 19:07:00 +00:00
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"golang.org/x/net/proxy"
|
|
|
|
)
|
|
|
|
|
|
|
|
type linkSOCKS struct {
|
|
|
|
*links
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *links) newLinkSOCKS() *linkSOCKS {
|
|
|
|
lt := &linkSOCKS{
|
|
|
|
links: l,
|
|
|
|
}
|
|
|
|
return lt
|
|
|
|
}
|
|
|
|
|
2023-04-06 20:45:49 +00:00
|
|
|
func (l *linkSOCKS) dial(url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
|
|
|
|
var proxyAuth *proxy.Auth
|
|
|
|
if url.User != nil && url.User.Username() != "" {
|
|
|
|
proxyAuth = &proxy.Auth{
|
|
|
|
User: url.User.Username(),
|
|
|
|
}
|
|
|
|
proxyAuth.Password, _ = url.User.Password()
|
2022-09-17 19:07:00 +00:00
|
|
|
}
|
|
|
|
dialer, err := proxy.SOCKS5("tcp", url.Host, proxyAuth, proxy.Direct)
|
|
|
|
if err != nil {
|
2023-04-06 20:45:49 +00:00
|
|
|
return nil, fmt.Errorf("failed to configure proxy")
|
2022-09-17 19:07:00 +00:00
|
|
|
}
|
|
|
|
pathtokens := strings.Split(strings.Trim(url.Path, "/"), "/")
|
2023-04-06 20:45:49 +00:00
|
|
|
return dialer.Dial("tcp", pathtokens[0])
|
2022-09-17 19:07:00 +00:00
|
|
|
}
|
|
|
|
|
2023-04-06 20:45:49 +00:00
|
|
|
func (l *linkSOCKS) listen(ctx context.Context, url *url.URL, _ string) (net.Listener, error) {
|
|
|
|
return nil, fmt.Errorf("SOCKS listener not supported")
|
2022-09-17 19:07:00 +00:00
|
|
|
}
|