Skip to content

Commit

Permalink
[refactor] use full ports.
Browse files Browse the repository at this point in the history
  • Loading branch information
peanut996 committed Dec 19, 2023
1 parent 57663e6 commit 9ed85bc
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions task/warping.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ var (

PingTimes = defaultPingTimes

commonIPv4Ports = []int{2408, 500, 1701, 4500}

commonIPv6Ports = []int{2408, 500, 1701, 4500}
ports = []int{
500, 854, 859, 864, 878, 880, 890, 891, 894, 903,
908, 928, 934, 939, 942, 943, 945, 946, 955, 968,
987, 988, 1002, 1010, 1014, 1018, 1070, 1074, 1180, 1387,
1701, 1843, 2371, 2408, 2506, 3138, 3476, 3581, 3854, 4177,
4198, 4233, 4500, 5279, 5956, 7103, 7152, 7156, 7281, 7559, 8319, 8742, 8854, 8886,
}

commonIPv4CIDRs = []string{
"162.159.192.0/24",
Expand Down Expand Up @@ -89,19 +93,6 @@ type MessageInitiation struct {
MAC2 [blake2s.Size128]byte
}

func NewMessageInitiation(msg *device.MessageInitiation) *MessageInitiation {
return &MessageInitiation{
Type: uint8(msg.Type),
Reserved: [3]byte{0, 0, 0},
Sender: msg.Sender,
Ephemeral: msg.Ephemeral,
Static: msg.Static,
Timestamp: msg.Timestamp,
MAC1: msg.MAC1,
MAC2: msg.MAC2,
}
}

type UDPAddr struct {
IP *net.IPAddr
Port int
Expand Down Expand Up @@ -196,12 +187,8 @@ func loadWarpIPRanges() (ipAddrs []*UDPAddr) {
}

func generateIPAddrs(ips []*net.IPAddr) (udpAddrs []*UDPAddr) {
rangePorts := commonIPv4Ports
if IPv6Mode {
rangePorts = commonIPv6Ports
}
if !ScanAllPort {
for _, port := range rangePorts {
for _, port := range ports {
udpAddrs = append(udpAddrs, generateSingleIPAddr(ips, port)...)
}
} else {
Expand Down Expand Up @@ -239,14 +226,14 @@ func (i *UDPAddr) ToUDPAddr() (addr *net.UDPAddr) {

func (w *Warping) warping(ip *UDPAddr) (received int, totalDelay time.Duration) {
fullAddress := ip.FullAddress()
conn, err := net.DialTimeout("udp", fullAddress, udpConnectTimeout)
con, err := net.DialTimeout("udp", fullAddress, udpConnectTimeout)
if err != nil {
return 0, 0
}
defer conn.Close()
defer con.Close()

for i := 0; i < PingTimes; i++ {
ok, rtt := handshake(conn)
ok, rtt := handshake(con)
if ok {
received++
totalDelay += rtt
Expand Down

0 comments on commit 9ed85bc

Please sign in to comment.