Skip to content

Commit 9801f5b

Browse files
committed
fix: Android torrent playback error
1 parent b148ced commit 9801f5b

File tree

4 files changed

+49
-173
lines changed

4 files changed

+49
-173
lines changed

app/app.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package app
22

33
import (
4+
"context"
5+
"net"
6+
47
"github.com/anacrolix/torrent"
58
"github.com/gofiber/fiber/v2"
69
"github.com/gofiber/fiber/v2/log"
@@ -15,6 +18,9 @@ var (
1518
)
1619

1720
func init() {
21+
// 修复 Android 的 DNS 问题
22+
// https://github.com/YouROK/TorrServer/blob/34634649024b06921e7f2bb068da4a4ad35fabe4/server/cmd/main.go#L101-L120
23+
dnsResolve()
1824
var err error
1925
App = fiber.New()
2026

@@ -42,3 +48,24 @@ func init() {
4248
}
4349
log.Info("BT client started")
4450
}
51+
52+
func dnsResolve() {
53+
addrs, err := net.LookupHost("www.google.com")
54+
if len(addrs) == 0 {
55+
log.Error("Check dns failed", addrs, err)
56+
57+
fn := func(ctx context.Context, network, address string) (net.Conn, error) {
58+
d := net.Dialer{}
59+
return d.DialContext(ctx, "udp", "1.1.1.1:53")
60+
}
61+
62+
net.DefaultResolver = &net.Resolver{
63+
Dial: fn,
64+
}
65+
66+
addrs, err = net.LookupHost("www.google.com")
67+
log.Info("Check cloudflare dns", addrs, err)
68+
} else {
69+
log.Info("Check dns OK", addrs, err)
70+
}
71+
}

config/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package config
22

33
import "os"
44

5-
const VERSION = "0.0.2"
5+
const VERSION = "0.0.3"
66

77
var (
88
SECRET = getVar("SECRET", "")

go.mod

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ module github.com/miru-project/bt-server
22

33
go 1.19
44

5+
require (
6+
github.com/anacrolix/torrent v1.52.5
7+
github.com/gofiber/fiber/v2 v2.48.0
8+
)
9+
510
require (
611
crawshaw.io/sqlite v0.3.3-0.20220618202545-d1964889ea3c // indirect
712
github.com/RoaringBitmap/roaring v1.2.3 // indirect
@@ -20,48 +25,28 @@ require (
2025
github.com/anacrolix/multiless v0.3.0 // indirect
2126
github.com/anacrolix/stm v0.4.0 // indirect
2227
github.com/anacrolix/sync v0.4.0 // indirect
23-
github.com/anacrolix/torrent v1.52.5 // indirect
2428
github.com/anacrolix/upnp v0.1.3-0.20220123035249-922794e51c96 // indirect
2529
github.com/anacrolix/utp v0.1.0 // indirect
2630
github.com/andybalholm/brotli v1.0.5 // indirect
27-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
2831
github.com/bahlo/generic-list-go v0.2.0 // indirect
2932
github.com/benbjohnson/immutable v0.3.0 // indirect
3033
github.com/bits-and-blooms/bitset v1.2.2 // indirect
3134
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
3235
github.com/davecgh/go-spew v1.1.1 // indirect
3336
github.com/dustin/go-humanize v1.0.0 // indirect
3437
github.com/edsrzf/mmap-go v1.1.0 // indirect
35-
github.com/felixge/httpsnoop v1.0.3 // indirect
3638
github.com/go-logr/logr v1.2.3 // indirect
3739
github.com/go-logr/stdr v1.2.2 // indirect
38-
github.com/go-openapi/analysis v0.21.4 // indirect
39-
github.com/go-openapi/errors v0.20.4 // indirect
40-
github.com/go-openapi/jsonpointer v0.20.0 // indirect
41-
github.com/go-openapi/jsonreference v0.20.2 // indirect
42-
github.com/go-openapi/loads v0.21.2 // indirect
43-
github.com/go-openapi/runtime v0.26.0 // indirect
44-
github.com/go-openapi/spec v0.20.9 // indirect
45-
github.com/go-openapi/strfmt v0.21.7 // indirect
46-
github.com/go-openapi/swag v0.22.4 // indirect
47-
github.com/go-openapi/validate v0.22.1 // indirect
48-
github.com/gofiber/contrib/swagger v1.0.8 // indirect
49-
github.com/gofiber/fiber/v2 v2.48.0 // indirect
5040
github.com/google/btree v1.1.2 // indirect
5141
github.com/google/uuid v1.3.1 // indirect
52-
github.com/gorilla/handlers v1.5.1 // indirect
5342
github.com/gorilla/websocket v1.5.0 // indirect
5443
github.com/huandu/xstrings v1.3.2 // indirect
55-
github.com/josharian/intern v1.0.0 // indirect
5644
github.com/klauspost/compress v1.16.7 // indirect
5745
github.com/lispad/go-generics-tools v1.1.0 // indirect
58-
github.com/mailru/easyjson v0.7.7 // indirect
5946
github.com/mattn/go-colorable v0.1.13 // indirect
6047
github.com/mattn/go-isatty v0.0.19 // indirect
6148
github.com/mattn/go-runewidth v0.0.15 // indirect
62-
github.com/mitchellh/mapstructure v1.5.0 // indirect
6349
github.com/mschoch/smat v0.2.0 // indirect
64-
github.com/oklog/ulid v1.3.1 // indirect
6550
github.com/pion/datachannel v1.5.2 // indirect
6651
github.com/pion/dtls/v2 v2.2.4 // indirect
6752
github.com/pion/ice/v2 v2.2.6 // indirect
@@ -83,12 +68,12 @@ require (
8368
github.com/pkg/errors v0.9.1 // indirect
8469
github.com/rivo/uniseg v0.4.4 // indirect
8570
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 // indirect
71+
github.com/stretchr/testify v1.8.4 // indirect
8672
github.com/tidwall/btree v1.6.0 // indirect
8773
github.com/valyala/bytebufferpool v1.0.0 // indirect
8874
github.com/valyala/fasthttp v1.48.0 // indirect
8975
github.com/valyala/tcplisten v1.0.0 // indirect
9076
go.etcd.io/bbolt v1.3.6 // indirect
91-
go.mongodb.org/mongo-driver v1.12.1 // indirect
9277
go.opentelemetry.io/otel v1.14.0 // indirect
9378
go.opentelemetry.io/otel/trace v1.14.0 // indirect
9479
golang.org/x/crypto v0.7.0 // indirect
@@ -97,5 +82,4 @@ require (
9782
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
9883
golang.org/x/sys v0.11.0 // indirect
9984
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
100-
gopkg.in/yaml.v3 v3.0.1 // indirect
10185
)

0 commit comments

Comments
 (0)