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