mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-12 07:19:53 +00:00
chore: minor code adjustments
This commit is contained in:
parent
a2bc061e74
commit
cdbfa0fca2
@ -1,31 +0,0 @@
|
|||||||
package auth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os/exec"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CmdAuthProvider struct {
|
|
||||||
Cmd string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *CmdAuthProvider) Auth(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string) {
|
|
||||||
cmd := exec.Command(p.Cmd, addr.String(), string(auth), strconv.Itoa(int(sSend)), strconv.Itoa(int(sRecv)))
|
|
||||||
out, err := cmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
if _, ok := err.(*exec.ExitError); ok {
|
|
||||||
return false, strings.TrimSpace(string(out))
|
|
||||||
} else {
|
|
||||||
logrus.WithFields(logrus.Fields{
|
|
||||||
"error": err,
|
|
||||||
}).Error("Failed to execute auth command")
|
|
||||||
return false, "internal error"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return true, strings.TrimSpace(string(out))
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,10 +6,34 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CmdAuthProvider struct {
|
||||||
|
Cmd string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *CmdAuthProvider) Auth(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string) {
|
||||||
|
cmd := exec.Command(p.Cmd, addr.String(), string(auth), strconv.Itoa(int(sSend)), strconv.Itoa(int(sRecv)))
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := err.(*exec.ExitError); ok {
|
||||||
|
return false, strings.TrimSpace(string(out))
|
||||||
|
} else {
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"error": err,
|
||||||
|
}).Error("Failed to execute auth command")
|
||||||
|
return false, "internal error"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true, strings.TrimSpace(string(out))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type HTTPAuthProvider struct {
|
type HTTPAuthProvider struct {
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
URL string
|
URL string
|
@ -47,7 +47,7 @@ func startTUN(config *clientConfig, client *core.Client, errChan chan error) {
|
|||||||
tcpSendBufferSize, err = units.RAMInBytes(config.TUN.TCPSendBufferSize)
|
tcpSendBufferSize, err = units.RAMInBytes(config.TUN.TCPSendBufferSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"err": err,
|
"error": err,
|
||||||
"tcp-sndbuf": config.TUN.TCPSendBufferSize,
|
"tcp-sndbuf": config.TUN.TCPSendBufferSize,
|
||||||
}).Fatal("Failed to parse tcp-sndbuf in the TUN config")
|
}).Fatal("Failed to parse tcp-sndbuf in the TUN config")
|
||||||
}
|
}
|
||||||
@ -61,13 +61,13 @@ func startTUN(config *clientConfig, client *core.Client, errChan chan error) {
|
|||||||
tcpReceiveBufferSize, err = units.RAMInBytes(config.TUN.TCPReceiveBufferSize)
|
tcpReceiveBufferSize, err = units.RAMInBytes(config.TUN.TCPReceiveBufferSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"err": err,
|
"error": err,
|
||||||
"tcp-rcvbuf": config.TUN.TCPReceiveBufferSize,
|
"tcp-rcvbuf": config.TUN.TCPReceiveBufferSize,
|
||||||
}).Fatal("Failed to parse tcp-rcvbuf in the TUN config")
|
}).Fatal("Failed to parse tcp-rcvbuf in the TUN config")
|
||||||
}
|
}
|
||||||
if (tcpReceiveBufferSize != 0 && tcpReceiveBufferSize < tcp.MinBufferSize) || tcpReceiveBufferSize > tcp.MaxBufferSize {
|
if (tcpReceiveBufferSize != 0 && tcpReceiveBufferSize < tcp.MinBufferSize) || tcpReceiveBufferSize > tcp.MaxBufferSize {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"err": err,
|
"error": err,
|
||||||
"tcp-rcvbuf": config.TUN.TCPReceiveBufferSize,
|
"tcp-rcvbuf": config.TUN.TCPReceiveBufferSize,
|
||||||
}).Fatal("Invalid tcp-rcvbuf in the TUN config")
|
}).Fatal("Invalid tcp-rcvbuf in the TUN config")
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,10 @@ var rootCmd = &cobra.Command{
|
|||||||
logrus.SetFormatter(&nested.Formatter{
|
logrus.SetFormatter(&nested.Formatter{
|
||||||
FieldsOrder: []string{
|
FieldsOrder: []string{
|
||||||
"version", "url",
|
"version", "url",
|
||||||
"config", "file", "mode",
|
"config", "file", "mode", "protocol",
|
||||||
|
"cert", "key",
|
||||||
"addr", "src", "dst", "session", "action", "interface",
|
"addr", "src", "dst", "session", "action", "interface",
|
||||||
|
"tcp-sndbuf", "tcp-rcvbuf",
|
||||||
"retry", "interval",
|
"retry", "interval",
|
||||||
"code", "msg", "error",
|
"code", "msg", "error",
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user