mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
set PublicIp6 and sort IPs
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -185,6 +186,7 @@ func getDefaultFriendlyName() string {
|
||||
}
|
||||
}
|
||||
if len(list) > 0 {
|
||||
sort.Strings(list)
|
||||
return ret + " " + list[0]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,12 @@ func (bt *BTServer) configure() {
|
||||
}
|
||||
|
||||
log.Println("Client config:", settings.BTsets)
|
||||
|
||||
// set public IPv6
|
||||
bt.config.PublicIp6 = getPublicIp6()
|
||||
if bt.config.PublicIp6 != nil {
|
||||
log.Println("PublicIp6:", bt.config.PublicIp6)
|
||||
}
|
||||
}
|
||||
|
||||
func (bt *BTServer) GetTorrent(hash torrent.InfoHash) *Torrent {
|
||||
@@ -139,3 +145,29 @@ func (bt *BTServer) RemoveTorrent(hash torrent.InfoHash) {
|
||||
torr.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func getPublicIp6() net.IP {
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.Println("Error get public IPv6")
|
||||
return nil
|
||||
}
|
||||
for _, i := range ifaces {
|
||||
addrs, _ := i.Addrs()
|
||||
if i.Flags&net.FlagUp == net.FlagUp {
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
if !ip.IsLoopback() && !ip.IsPrivate() && ip.To4 == nil && ip.To16 != nil {
|
||||
return ip
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sort"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-contrib/location"
|
||||
@@ -29,7 +30,7 @@ func Start(port string) {
|
||||
log.TLogln("Start TorrServer")
|
||||
ips := getLocalIps()
|
||||
if len(ips) > 0 {
|
||||
log.TLogln("IP:", ips)
|
||||
log.TLogln("IPs:", ips)
|
||||
}
|
||||
err := BTS.Connect()
|
||||
if err != nil {
|
||||
@@ -107,5 +108,6 @@ func getLocalIps() []string {
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Strings(list)
|
||||
return list
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user