mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 10:14:35 +00:00
distinct v6 and v4 tunnel in gui and cli (#1373)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useTimeAgo } from '@vueuse/core'
|
import { useTimeAgo } from '@vueuse/core'
|
||||||
import { IPv4 } from 'ip-num/IPNumber'
|
import { IPv4 } from 'ip-num/IPNumber'
|
||||||
import { NetworkInstance, type NodeInfo, type PeerRoutePair } from '../types/network'
|
import { NetworkInstance, type TunnelInfo, type NodeInfo, type PeerRoutePair } from '../types/network'
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||||
import { ipv4InetToString, ipv4ToString, ipv6ToString } from '../modules/utils';
|
import { ipv4InetToString, ipv4ToString, ipv6ToString } from '../modules/utils';
|
||||||
@@ -106,8 +106,30 @@ function ipFormat(info: PeerRoutePair) {
|
|||||||
return ip ? `${IPv4.fromNumber(ip.address.addr)}/${ip.network_length}` : ''
|
return ip ? `${IPv4.fromNumber(ip.address.addr)}/${ip.network_length}` : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function oneTunnelProto(tunnel?: TunnelInfo): string {
|
||||||
|
if (!tunnel)
|
||||||
|
return ''
|
||||||
|
|
||||||
|
const local_addr = tunnel.local_addr
|
||||||
|
let isIPv6 = false;
|
||||||
|
if (local_addr?.url) {
|
||||||
|
try {
|
||||||
|
const urlObj = new URL(local_addr.url, 'http://dummy');
|
||||||
|
// IPv6 addresses in URLs are enclosed in brackets and contain ':'
|
||||||
|
isIPv6 = /^\[.*:.*\]$/.test(urlObj.hostname);
|
||||||
|
} catch (e) {
|
||||||
|
// fallback to original check if URL parsing fails
|
||||||
|
isIPv6 = local_addr.url.indexOf('[') >= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isIPv6)
|
||||||
|
return `${tunnel.tunnel_type}6`
|
||||||
|
else
|
||||||
|
return tunnel.tunnel_type
|
||||||
|
}
|
||||||
|
|
||||||
function tunnelProto(info: PeerRoutePair) {
|
function tunnelProto(info: PeerRoutePair) {
|
||||||
return [...new Set(info.peer?.conns.map(c => c.tunnel?.tunnel_type))].join(',')
|
return [...new Set(info.peer?.conns.map(c => oneTunnelProto(c.tunnel)))].join(',')
|
||||||
}
|
}
|
||||||
|
|
||||||
const myNodeInfo = computed(() => {
|
const myNodeInfo = computed(() => {
|
||||||
|
|||||||
@@ -246,10 +246,14 @@ export interface PeerRoutePair {
|
|||||||
peer?: PeerInfo
|
peer?: PeerInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UrlPb {
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface TunnelInfo {
|
export interface TunnelInfo {
|
||||||
tunnel_type: string
|
tunnel_type: string
|
||||||
local_addr: string
|
local_addr: UrlPb
|
||||||
remote_addr: string
|
remote_addr: UrlPb
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PeerConnStats {
|
export interface PeerConnStats {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use url::Host;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/cli.rs"));
|
include!(concat!(env!("OUT_DIR"), "/cli.rs"));
|
||||||
|
|
||||||
impl PeerRoutePair {
|
impl PeerRoutePair {
|
||||||
@@ -70,6 +72,25 @@ impl PeerRoutePair {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_tunnel_ipv6(tunnel_info: &super::common::TunnelInfo) -> bool {
|
||||||
|
let Some(local_addr) = &tunnel_info.local_addr else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
let u: url::Url = local_addr.clone().into();
|
||||||
|
u.host()
|
||||||
|
.map(|h| matches!(h, Host::Ipv6(_)))
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_tunnel_proto_str(tunnel_info: &super::common::TunnelInfo) -> String {
|
||||||
|
if Self::is_tunnel_ipv6(tunnel_info) {
|
||||||
|
format!("{}6", tunnel_info.tunnel_type)
|
||||||
|
} else {
|
||||||
|
tunnel_info.tunnel_type.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_conn_protos(&self) -> Option<Vec<String>> {
|
pub fn get_conn_protos(&self) -> Option<Vec<String>> {
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
let p = self.peer.as_ref()?;
|
let p = self.peer.as_ref()?;
|
||||||
@@ -78,8 +99,9 @@ impl PeerRoutePair {
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
// insert if not exists
|
// insert if not exists
|
||||||
if !ret.contains(&tunnel_info.tunnel_type) {
|
let tunnel_type = Self::get_tunnel_proto_str(tunnel_info);
|
||||||
ret.push(tunnel_info.tunnel_type.clone());
|
if !ret.contains(&tunnel_type) {
|
||||||
|
ret.push(tunnel_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user