aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-19 03:03:19 -0400
committerpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-19 03:03:19 -0400
commit36bc4748543380a55b3d1c9de08cfd867f5707df (patch)
tree073cc3a37efc7d541bed5a0aa4312861a8a8a370
parentf3317eec17b78421d4bcfbaf2efc6216931a3643 (diff)
downloadAtlas-36bc4748543380a55b3d1c9de08cfd867f5707df.tar.gz
Atlas-36bc4748543380a55b3d1c9de08cfd867f5707df.zip
pkg/a2s: Explicit timeout error
-rw-r--r--pkg/a2s/a2s.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/pkg/a2s/a2s.go b/pkg/a2s/a2s.go
index 9d1d65d..04648c8 100644
--- a/pkg/a2s/a2s.go
+++ b/pkg/a2s/a2s.go
@@ -8,14 +8,18 @@ import (
"crypto/cipher"
"crypto/rand"
"encoding/binary"
+ "errors"
"fmt"
"net"
"net/netip"
+ "os"
"time"
)
const ProbeUID uint64 = 1000000001337
+var ErrTimeout = errors.New("connection timed out")
+
func Probe(addr netip.AddrPort, timeout time.Duration) error {
conn, err := net.DialUDP("udp", nil, net.UDPAddrFromAddrPort(addr))
if err != nil {
@@ -32,11 +36,17 @@ func Probe(addr netip.AddrPort, timeout time.Duration) error {
return fmt.Errorf("encrypt connection packet: %w", err)
}
if _, err := conn.Write(pkt); err != nil {
+ if errors.Is(err, os.ErrDeadlineExceeded) {
+ err = fmt.Errorf("%w: %v", ErrTimeout, err)
+ }
return fmt.Errorf("send connection packet: %w", err)
}
resp := make([]byte, 1500)
if n, err := conn.Read(resp); err != nil {
+ if errors.Is(err, os.ErrDeadlineExceeded) {
+ err = fmt.Errorf("%w: %v", ErrTimeout, err)
+ }
return fmt.Errorf("receive packet: %w", err)
} else {
resp = resp[:n]