mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-09 14:10:00 +00:00
chore: small tweaks
This commit is contained in:
parent
3e5eccd6e3
commit
5efd0f8f44
@ -12,8 +12,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/apernet/hysteria/extras/transport/udphop"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -26,6 +24,7 @@ import (
|
|||||||
"github.com/apernet/hysteria/app/internal/utils"
|
"github.com/apernet/hysteria/app/internal/utils"
|
||||||
"github.com/apernet/hysteria/core/client"
|
"github.com/apernet/hysteria/core/client"
|
||||||
"github.com/apernet/hysteria/extras/obfs"
|
"github.com/apernet/hysteria/extras/obfs"
|
||||||
|
"github.com/apernet/hysteria/extras/transport/udphop"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client flags
|
// Client flags
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
package udphop
|
package udphop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInvalidPort = errors.New("invalid port")
|
type InvalidPortError struct {
|
||||||
|
PortStr string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e InvalidPortError) Error() string {
|
||||||
|
return fmt.Sprintf("%s is not a valid port number or range", e.PortStr)
|
||||||
|
}
|
||||||
|
|
||||||
// UDPHopAddr contains an IP address and a list of ports.
|
// UDPHopAddr contains an IP address and a list of ports.
|
||||||
type UDPHopAddr struct {
|
type UDPHopAddr struct {
|
||||||
@ -57,15 +63,15 @@ func ResolveUDPHopAddr(addr string) (*UDPHopAddr, error) {
|
|||||||
// Port range
|
// Port range
|
||||||
portRange := strings.Split(portStr, "-")
|
portRange := strings.Split(portStr, "-")
|
||||||
if len(portRange) != 2 {
|
if len(portRange) != 2 {
|
||||||
return nil, ErrInvalidPort
|
return nil, InvalidPortError{portStr}
|
||||||
}
|
}
|
||||||
start, err := strconv.ParseUint(portRange[0], 10, 16)
|
start, err := strconv.ParseUint(portRange[0], 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrInvalidPort
|
return nil, InvalidPortError{portStr}
|
||||||
}
|
}
|
||||||
end, err := strconv.ParseUint(portRange[1], 10, 16)
|
end, err := strconv.ParseUint(portRange[1], 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrInvalidPort
|
return nil, InvalidPortError{portStr}
|
||||||
}
|
}
|
||||||
if start > end {
|
if start > end {
|
||||||
start, end = end, start
|
start, end = end, start
|
||||||
@ -77,7 +83,7 @@ func ResolveUDPHopAddr(addr string) (*UDPHopAddr, error) {
|
|||||||
// Single port
|
// Single port
|
||||||
port, err := strconv.ParseUint(portStr, 10, 16)
|
port, err := strconv.ParseUint(portStr, 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrInvalidPort
|
return nil, InvalidPortError{portStr}
|
||||||
}
|
}
|
||||||
result.Ports = append(result.Ports, uint16(port))
|
result.Ports = append(result.Ports, uint16(port))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user