-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
137 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,2 +1,15 @@ | ||
github.com/sloweax/argparse v0.0.0-20241113001422-2d1c5ee3c102 h1:ybDRocc1hXRco/6a0jozEMm/6AJx1TUm59V/WHUlNpk= | ||
github.com/sloweax/argparse v0.0.0-20241113001422-2d1c5ee3c102/go.mod h1:N3Js6gWN6Be5Qgw143ULfhaTk8oZvrg/QxbrjKREq+Q= | ||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg= | ||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s= | ||
github.com/shadowsocks/go-shadowsocks2 v0.1.5 h1:PDSQv9y2S85Fl7VBeOMF9StzeXZyK1HakRm86CUbr28= | ||
github.com/shadowsocks/go-shadowsocks2 v0.1.5/go.mod h1:AGGpIoek4HRno4xzyFiAtLHkOpcoznZEkAccaI/rplM= | ||
github.com/sloweax/argparse v0.1.0 h1:7tzlOj2eFNAtaH8qKsca5VJPAALdd2Wg8IkvuGAJWr4= | ||
github.com/sloweax/argparse v0.1.0/go.mod h1:N3Js6gWN6Be5Qgw143ULfhaTk8oZvrg/QxbrjKREq+Q= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g= | ||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= | ||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= | ||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
This file contains 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 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,81 @@ | ||
package shadowsocks | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
|
||
"github.com/shadowsocks/go-shadowsocks2/core" | ||
"github.com/shadowsocks/go-shadowsocks2/socks" | ||
) | ||
|
||
type Dialer struct { | ||
cipher core.Cipher | ||
kwargs map[string]string | ||
network string | ||
address string | ||
} | ||
|
||
func (s *Dialer) Protocol() string { | ||
return "ss" | ||
} | ||
|
||
func (s *Dialer) KWArgs() map[string]string { | ||
return s.kwargs | ||
} | ||
|
||
func (s *Dialer) Network() string { | ||
return s.network | ||
} | ||
|
||
func (s *Dialer) String() string { | ||
return s.address | ||
} | ||
|
||
func (s *Dialer) DialContextWithConn(ctx context.Context, conn net.Conn, network, addr string) (net.Conn, error) { | ||
type result struct { | ||
net.Conn | ||
error | ||
} | ||
|
||
target := socks.ParseAddr(addr) | ||
if target == nil { | ||
return nil, fmt.Errorf("failed to parse address %q", addr) | ||
} | ||
|
||
c := make(chan result, 1) | ||
defer close(c) | ||
|
||
go func() { | ||
conn = s.cipher.StreamConn(conn) | ||
if _, err := conn.Write(target); err != nil { | ||
conn.Close() | ||
c <- result{error: err} | ||
} else { | ||
c <- result{Conn: conn} | ||
} | ||
}() | ||
|
||
select { | ||
case <-ctx.Done(): | ||
conn.Close() | ||
return nil, ctx.Err() | ||
case r := <-c: | ||
return r.Conn, r.error | ||
} | ||
} | ||
|
||
func NewDialer(network, address string, kwargs map[string]string, method, password string) (*Dialer, error) { | ||
d := new(Dialer) | ||
d.network = network | ||
d.address = address | ||
d.kwargs = kwargs | ||
|
||
cipher, err := core.PickCipher(method, nil, password) | ||
if err != nil { | ||
return nil, err | ||
} | ||
d.cipher = cipher | ||
|
||
return d, nil | ||
} |