mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-05 06:06:52 +00:00
module
This commit is contained in:
@@ -12,25 +12,25 @@ type Handshake struct {
|
||||
core.NpsPlugin
|
||||
}
|
||||
|
||||
func (handshake *Handshake) Run(ctx context.Context, config map[string]string) error {
|
||||
func (handshake *Handshake) Run(ctx context.Context, config map[string]string) (context.Context, error) {
|
||||
clientConn := handshake.GetClientConn(ctx)
|
||||
buf := make([]byte, 2)
|
||||
if _, err := io.ReadFull(clientConn, buf); err != nil {
|
||||
return errors.New("negotiation err while read 2 bytes from client connection: " + err.Error())
|
||||
return ctx, errors.New("negotiation err while read 2 bytes from client connection: " + err.Error())
|
||||
}
|
||||
|
||||
if version := buf[0]; version != 5 {
|
||||
return errors.New("only support socks5")
|
||||
return ctx, errors.New("only support socks5")
|
||||
}
|
||||
nMethods := buf[1]
|
||||
|
||||
methods := make([]byte, nMethods)
|
||||
|
||||
if n, err := clientConn.Read(methods); n != int(nMethods) || err != nil {
|
||||
return errors.New(fmt.Sprintf("read methods error, need %d , read %d, error %s", nMethods, n, err.Error()))
|
||||
return ctx, errors.New(fmt.Sprintf("read methods error, need %d , read %d, error %s", nMethods, n, err.Error()))
|
||||
} else {
|
||||
context.WithValue(ctx, "methods", methods[:n])
|
||||
ctx = context.WithValue(ctx, "methods", methods[:n])
|
||||
}
|
||||
|
||||
return nil
|
||||
return ctx, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user