fix shadowsocks connector
This commit is contained in:
parent
5b11cc9b9e
commit
99540014d0
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type quicSession struct {
|
type quicSession struct {
|
||||||
session quic.Connection
|
session quic.EarlyConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *quicSession) GetConn() (*quicConn, error) {
|
func (session *quicSession) GetConn() (*quicConn, error) {
|
||||||
|
@ -117,7 +117,7 @@ func (d *icmpDialer) initSession(ctx context.Context, addr net.Addr, conn net.Pa
|
|||||||
tlsCfg := d.options.TLSConfig
|
tlsCfg := d.options.TLSConfig
|
||||||
tlsCfg.NextProtos = []string{"http/3", "quic/v1"}
|
tlsCfg.NextProtos = []string{"http/3", "quic/v1"}
|
||||||
|
|
||||||
session, err := quic.DialContext(ctx, conn, addr, addr.String(), tlsCfg, quicConfig)
|
session, err := quic.DialEarlyContext(ctx, conn, addr, addr.String(), tlsCfg, quicConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func (c *shadowCipher) PacketConn(conn net.PacketConn) net.PacketConn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ShadowCipher(method, password string, key string) (core.Cipher, error) {
|
func ShadowCipher(method, password string, key string) (core.Cipher, error) {
|
||||||
if method == "" && password == "" {
|
if method == "" || password == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,14 +37,15 @@ func ShadowCipher(method, password string, key string) (core.Cipher, error) {
|
|||||||
// we wrap around it to make io.Copy happy.
|
// we wrap around it to make io.Copy happy.
|
||||||
type shadowConn struct {
|
type shadowConn struct {
|
||||||
net.Conn
|
net.Conn
|
||||||
wbuf *bytes.Buffer
|
wbuf bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShadowConn(conn net.Conn, header []byte) net.Conn {
|
func ShadowConn(conn net.Conn, header []byte) net.Conn {
|
||||||
return &shadowConn{
|
c := &shadowConn{
|
||||||
Conn: conn,
|
Conn: conn,
|
||||||
wbuf: bytes.NewBuffer(header),
|
|
||||||
}
|
}
|
||||||
|
c.wbuf.Write(header)
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *shadowConn) Write(b []byte) (n int, err error) {
|
func (c *shadowConn) Write(b []byte) (n int, err error) {
|
||||||
|
@ -20,7 +20,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type icmpListener struct {
|
type icmpListener struct {
|
||||||
ln quic.Listener
|
ln quic.EarlyListener
|
||||||
cqueue chan net.Conn
|
cqueue chan net.Conn
|
||||||
errChan chan error
|
errChan chan error
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
@ -71,7 +71,7 @@ func (l *icmpListener) Init(md md.Metadata) (err error) {
|
|||||||
tlsCfg := l.options.TLSConfig
|
tlsCfg := l.options.TLSConfig
|
||||||
tlsCfg.NextProtos = []string{"http/3", "quic/v1"}
|
tlsCfg.NextProtos = []string{"http/3", "quic/v1"}
|
||||||
|
|
||||||
ln, err := quic.Listen(conn, tlsCfg, config)
|
ln, err := quic.ListenEarly(conn, tlsCfg, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func (l *icmpListener) listenLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *icmpListener) mux(ctx context.Context, session quic.Connection) {
|
func (l *icmpListener) mux(ctx context.Context, session quic.EarlyConnection) {
|
||||||
defer session.CloseWithError(0, "closed")
|
defer session.CloseWithError(0, "closed")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user