Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added IPv8 + libtorrent interface configuration options #8428

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,16 @@ def create_session(self, hops: int = 0) -> lt.session: # noqa: PLR0915
# Elric: Strip out the -rcX, -beta, -whatever tail on the version string.
ltsession = lt.session(lt.fingerprint("TL", 0, 0, 0, 0), flags=0) if hops == 0 else lt.session(flags=0)

libtorrent_if = self.config.get("libtorrent/listen_interface")
libtorrent_port = self.config.get("libtorrent/port")
logger.info("Libtorrent port: %d", libtorrent_port)
logger.info("Libtorrent ip+port set to %s:%d", libtorrent_if, libtorrent_port)
if hops == 0:
settings["user_agent"] = 'Tribler/' + VERSION_SUBDIR
enable_utp = self.config.get("libtorrent/utp")
settings["enable_outgoing_utp"] = enable_utp
settings["enable_incoming_utp"] = enable_utp
settings["prefer_rc4"] = True
settings["listen_interfaces"] = f"0.0.0.0:{libtorrent_port or 6881}"
settings["listen_interfaces"] = f"{libtorrent_if}:{libtorrent_port or 6881}"
else:
settings["enable_outgoing_utp"] = True
settings["enable_incoming_utp"] = True
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def rust_enhancements(session: Session) -> Generator[None, None, None]:
Attempt to import the IPv8 Rust anonymization backend.
"""
use_fallback = session.config.get("statistics")
if_specs = [ifc for ifc in session.config.configuration["ipv8"]["interfaces"] if ifc["interface"] == "UDPIPv4"]
if_specs = [ifc for ifc in session.config.get("ipv8/interfaces") if ifc["interface"] == "UDPIPv4"]

if not use_fallback:
try:
Expand Down
2 changes: 2 additions & 0 deletions src/tribler/tribler_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class LibtorrentConfig(TypedDict):
"""

socks_listen_ports: list[int]
listen_interface: str
port: int
proxy_type: int
proxy_server: str
Expand Down Expand Up @@ -194,6 +195,7 @@ class TriblerConfig(TypedDict):
"dht_discovery": DHTDiscoveryCommunityConfig(enabled=True),
"libtorrent": LibtorrentConfig(
socks_listen_ports=[0, 0, 0, 0, 0],
listen_interface="0.0.0.0",
port=0,
proxy_type=0,
proxy_server="",
Expand Down
2 changes: 2 additions & 0 deletions src/tribler/ui/public/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"Save": "Save",
"Tags": "Tags",
"ProxySettings": "Torrent proxy settings",
"P2PSettings": "Peer-to-Peer settings",
"LocalListeningInterface": "Local listening interface",
"Type": "Type",
"Server": "Server",
"Port": "Port",
Expand Down
2 changes: 2 additions & 0 deletions src/tribler/ui/public/locales/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"Save": "Guardar",
"Tags": "Etiquetas",
"ProxySettings": "Configuración del proxy torrent",
"P2PSettings": "Configuración de pares",
"LocalListeningInterface": "Interfaz de escucha local",
"Type": "Tipo",
"Server": "Servidor",
"Port": "Puerto",
Expand Down
2 changes: 2 additions & 0 deletions src/tribler/ui/public/locales/ko_KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"Save": "저장",
"Tags": "태그",
"ProxySettings": "토렌트 프록시 설정",
"P2PSettings": "피어 투 피어 설정",
"LocalListeningInterface": "로컬 청취 인터페이스",
"Type": "형식",
"Server": "서버",
"Port": "포트",
Expand Down
2 changes: 2 additions & 0 deletions src/tribler/ui/public/locales/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"EnableWatchFolder": "Ativar pasta monitorada (requer reinicialização)",
"Save": "Salvar",
"ProxySettings": "Configurações de proxy torrent",
"P2PSettings": "Configurações ponto a ponto",
"LocalListeningInterface": "Interface de escuta local",
"Type": "Tipo",
"Server": "Servidor",
"Port": "Porta",
Expand Down
2 changes: 2 additions & 0 deletions src/tribler/ui/public/locales/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"Save": "Сохранить",
"Tags": "Тэги",
"ProxySettings": "Подключение через внешний прокси",
"P2PSettings": "Одноранговые настройки",
"LocalListeningInterface": "Локальный интерфейс прослушивания",
"Type": "Тип",
"Server": "Сервер",
"Port": "Порт",
Expand Down
2 changes: 2 additions & 0 deletions src/tribler/ui/public/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"EnableWatchFolder": "启用监视文件夹(需要重新启动)",
"Save": "保存",
"ProxySettings": "种子代理设置",
"P2PSettings": "点对点设置",
"LocalListeningInterface": "本地听力接口",
"Type": "类型",
"Server": "服务器",
"Port": "端口",
Expand Down
3 changes: 2 additions & 1 deletion src/tribler/ui/src/models/settings.model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Settings {
interface: string;
ip: string;
port: number;
worker_threads: number;
worker_threads?: number;
}[];
keys: {
alias: string;
Expand Down Expand Up @@ -50,6 +50,7 @@ export interface Settings {
},
libtorrent: {
socks_listen_ports: number[];
listen_interface: string;
port: number;
proxy_type: number;
proxy_server: string;
Expand Down
92 changes: 92 additions & 0 deletions src/tribler/ui/src/pages/Settings/Connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@ import toast from 'react-hot-toast';
import SaveButton from "./SaveButton";


function injectOrUpdateIPv8If(entry: string, value: string, previous?: {interface: string, ip: string, port: number, worker_threads?: number}[]) {
let updatedOrRemoved = false;
let newIfs = [];
if (!!previous){
for (var e of previous){
if (e.interface == entry){
// If we had a previous entry:
// a. And now we have a new value: update!
// b. But now the entire interface is set to nothing: skip/remove!
if (!!value)
newIfs.push({...e, ip: value});
updatedOrRemoved = true;
} else {
// This wasn't modified, keep it.
newIfs.push(e);
}
}
}
if ((!updatedOrRemoved) && (!!value)) {
// We didn't update or remove, but we have a value set: add new!
newIfs.push(
{
interface: entry,
ip: value,
port: (entry == "UDPIPv4") ? 8090 : 8091
}
);
}
return newIfs;
}


export default function Connection() {
const { t } = useTranslation();
const [settings, setSettings] = useState<Settings>();
Expand All @@ -32,6 +64,46 @@ export default function Connection() {
return (
<div className="px-6 w-full">
<div className="grid grid-cols-2 gap-2 items-center">
<div className="pt-5 py-2 font-semibold col-span-2">{t('P2PSettings')}</div>

<Label htmlFor="ipv8_ipv4" className="whitespace-nowrap pr-5">
{t('LocalListeningInterface') + " IPv4"}
</Label>
<Input
id="ipv8_ipv4"
value={settings?.ipv8?.interfaces.filter((e) => e.interface == "UDPIPv4")?.[0]?.ip}
onChange={(event) => {
if (settings) {
setSettings({
...settings,
ipv8: {
...settings.ipv8,
interfaces: injectOrUpdateIPv8If("UDPIPv4", event.target.value, settings?.ipv8?.interfaces)
}
});
}
}}
/>

<Label htmlFor="ipv8_ipv6" className="whitespace-nowrap pr-5">
{t('LocalListeningInterface') + " IPv6"}
</Label>
<Input
id="ipv8_ipv6"
value={settings?.ipv8?.interfaces.filter((e) => e.interface == "UDPIPv6")?.[0]?.ip}
onChange={(event) => {
if (settings) {
setSettings({
...settings,
ipv8: {
...settings.ipv8,
interfaces: injectOrUpdateIPv8If("UDPIPv6", event.target.value, settings?.ipv8?.interfaces)
}
});
}
}}
/>

<div className="pt-5 py-2 font-semibold col-span-2">{t('ProxySettings')}</div>

<Label htmlFor="proxy_type" className="whitespace-nowrap pr-5">
Expand Down Expand Up @@ -145,6 +217,26 @@ export default function Connection() {


<div className="pt-5 py-2 font-semibold col-span-2">{t('BittorrentFeatures')}</div>

<Label htmlFor="libtorrent_ip" className="whitespace-nowrap pr-5">
{t('LocalListeningInterface')}
</Label>
<Input
id="libtorrent_ip"
value={settings?.libtorrent?.listen_interface}
onChange={(event) => {
if (settings) {
setSettings({
...settings,
libtorrent: {
...settings.libtorrent,
listen_interface: event.target.value
}
});
}
}}
/>

<Label htmlFor="utp" className="whitespace-nowrap pr-5">
{t('EnableUTP')}
</Label>
Expand Down