Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
Binary file added 2205308050317_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2205308050317_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2205308050317_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2205308050317_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2205308050317_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
286 changes: 167 additions & 119 deletions README.md

Large diffs are not rendered by default.

162 changes: 162 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@

# <!-- by 黄朝淼 -->🇨🇳 中文版 README.md
# 设置自定义超级节点
# 概述
本指南将详细介绍如何设置自定义超级节点,同时会涉及到相关代码说明。通过设置自定义超级节点,你可以创建自己的 n2n 网络基础设施,增强网络的安全性和隐私性。
## 一、设置自定义超级节点操作步骤
## 安装 n2n 软件包
在公共服务器(如 VPS )上安装 n2n 软件包。不同操作系统安装方法如下:
Ubuntu/Debian 系统:打开终端,执行命令sudo apt - get update && sudo apt - get install n2n ,更新软件源并安装 n2n。
CentOS 系统:先确保安装了 EPEL 源,然后在终端执行sudo yum install n2n 安装 n2n 软件包。
## 编辑配置文件
使用文本编辑器(如nano或vim )打开/etc/n2n/supernode.conf文件,添加内容-p=1234 。其中1234为指定端口,可根据实际情况修改,此操作是设置超级节点监听端口。
## 启动 supernode 服务
在终端输入命令sudo systemctl start supernode ,启动 supernode 服务,让超级节点在设定端口运行。
## 设置开机自启(可选)
若希望服务器重启后 supernode 服务自动启动,在终端执行命令sudo systemctl enable supernode

## 参数处理逻辑和初始化逻辑
setOption 函数是 n2n 超级节点中处理命令行参数的核心逻辑,它负责解析各种配置选项并设置相应的结构体成员。以下是对该函数的详细文字解释:
## 参数解析流程
1.接收参数:函数接收三个参数:optkey(参数标识)、_optarg(参数值)和 sss(超级节点结构体指针)。
2.分支处理:通过 switch 语句根据 optkey 处理不同的参数选项。
3.端口参数 (-p):
格式判断:首先检查参数值中是否包含冒号 :,以区分不同的输入格式。
IP: 端口格式:若包含冒号,将字符串分割为 IP 地址和端口两部分。
使用 inet_addr 将 IP 字符串转换为网络字节序整数,再通过 ntohl 转换为主机字节序。
使用 atoi 将端口字符串转换为整数。
错误处理:
若 IP 地址无效(返回 INADDR_NONE),则默认绑定到所有可用接口(INADDR_ANY)。
若端口号无效(解析为 0),则使用默认端口(通常为 7777)。
仅 IP 或仅端口:
若参数值包含点号 .,则视为仅指定 IP 地址,端口使用默认值。
否则视为仅指定端口号,IP 地址绑定到所有接口。
安全特性
输入验证:对 IP 地址和端口号进行有效性检查,防止非法输入导致程序崩溃。
默认值处理:当输入无效时,自动回退到安全的默认配置,确保服务能正常启动。
日志记录:通过 traceEvent 记录参数解析过程中的警告信息,方便调试和维护。
## 超级节点初始化逻辑文字解释
超级节点的初始化分为两个主要函数:sn_init_defaults 和 sn_init,它们分别完成不同阶段的初始化工作:
## 基础初始化(sn_init_defaults)
1.结构体成员初始化:设置超级节点结构体的各个字段为默认值。
2.网络配置:
bind_address:默认绑定到所有可用接口(INADDR_ANY)。
lport:默认监听端口(通常为 7777)。
mport:管理端口(用于接收管理命令)。
3.内存分配:为边缘节点表、社区列表等动态数据结构分配初始内存空间。
4.默认参数设置:设置其他运行时参数,如线程数、超时时间等。
## 高级初始化(sn_init)
1.线程创建:
创建解析线程(resolve_create_thread),用于处理域名解析和节点发现。
该线程负责维护边缘节点的可达性信息,确保节点间通信顺畅。
2.资源初始化:
初始化加密上下文,配置默认加密算法。
启动管理接口,监听管理命令。
3.服务准备:
创建套接字并绑定到指定地址和端口。
开始监听客户端连接请求。
4.状态通知:
通过日志记录初始化完成信息,包括绑定的地址、端口等关键配置。
### 初始化流程特点
分阶段初始化:将复杂的初始化过程拆分为基础设置和高级设置两个阶段,提高代码可维护性。
模块化设计:各个初始化任务独立封装,便于功能扩展和修改。
资源管理:合理分配和初始化系统资源,确保服务正常运行。
错误处理:在初始化失败时能进行适当的清理和错误报告,保证程序健壮性。
### 两者结合的工作流程
参数解析:通过 setOption 函数解析命令行参数,修改默认配置。
基础初始化:调用 sn_init_defaults 设置默认值,构建基础运行环境。
参数应用:将解析后的参数值应用到初始化后的结构体中,覆盖默认值。
高级初始化:调用 sn_init 完成剩余的初始化工作,启动核心服务组件。
服务运行:超级节点开始监听客户端连接,处理节点间的通信请求。
这种设计使得超级节点的配置灵活且易于扩展,同时保证了初始化过程的稳定性和安全性。

# 边缘节点配置
## 连接到自定义超级节点
在你的边缘节点上,你可以通过 -l 参数指定使用自定义的超级节点。例如:在边缘节点上使用以下命令连接到自定义超级节点:
sudo edge -d tun0 -l your_supernode_ip:1234 -c mycommunity -k mysecretkey -a 192.168.100.2 -f

### 参数说明:
-d tun0: 使用 tun0 虚拟接口
-l: 指定超级节点地址和端口
-c: 社区名称
-k: 加密密钥
-a: 分配的虚拟 IP 地址
-f: 前台运行 (便于调试)





=======

<!-- by 文荣平 -->
### 快速设置
- **安装方式**:部分Linux发行版已将 `n2n` 作为软件包提供,可使用 `sudo apt install n2n` 进行安装。此外,大多数发行版的最新软件包可在 [ntop repositories](http://packages.ntop.org/) 中获取。
- **示例配置**:在不同主机上配置边缘节点的示例如下:
```sh



# 以sudo权限运行edge命令,配置n2n边缘节点
# -c 参数指定社区名称为 mynetwork
# -k 参数指定加密密钥为 mysecretpass
# -a 参数指定本地IP地址为 192.168.100.1
# -f 参数表示以前台模式运行
# -l 参数指定连接到的超级节点为 supernode.ntop.org:7777

```
- 主机1:
```sh
sudo edge -c mynetwork -k mysecretpass -a 192.168.100.1 -f -l supernode.ntop.org:7777
```

- 主机2:
```sh
sudo edge -c mynetwork -k mysecretpass -a 192.168.100.2 -f -l supernode.ntop.org:7777
```

配置完成后,两台主机可以相互ping通。强烈建议选择自定义社区名称(`-c`)和秘密加密密钥(`-k`),以防止其他用户连接到您的计算机。为保护数据隐私、减少 `supernode.ntop.org` 的服务器负载,还建议设置自定义超级节点。


一、社区与加密密钥设置
1. 自定义社区与密钥
为防止其他用户连接到你的计算机,强烈建议为每个虚拟网络选择自定义的社区名称(使用 -c 参数)和安全的加密密钥(使用 -k 参数)。避免使用默认或简单易猜的社区名和密钥,以确保网络的私密性和安全性。
2. 密钥强度
加密密钥的长度和复杂度会影响加密的安全性。在设置加密密钥时,尽量使用较长且包含多种字符类型(字母、数字、特殊字符)的密钥。较长的密钥可以增加破解的难度,提高数据传输的安全性。
二、超级节点使用安全
1. 自定义超级节点
为了保护数据隐私并减轻公共超级节点(如 supernode.ntop.org)的服务器负载,建议设置自定义的超级节点。按照以下步骤进行设置:
安装 n2n 包。
编辑 /etc/n2n/supernode.conf 文件,添加监听端口,例如 -p=1234。
使用 sudo systemctl start supernode 启动超级节点服务。
可选择使用 sudo systemctl enable supernode 使超级节点在系统启动时自动启动。
2. 端口安全
在设置自定义超级节点时,需要在防火墙(通常是 iptables)上开放指定的端口(如上述示例中的 1234 端口)。确保仅开放必要的端口,并对端口进行适当的访问控制,防止未经授权的访问。
三、数据加密
1. 有效载荷加密
当启用有效载荷加密(通过 -k 参数提供密钥)时,超级节点将无法解密两个边缘节点之间交换的流量,但它仍能知道哪些边缘节点正在通信。这意味着虽然数据内容得到了保护,但通信的拓扑信息仍然可见。
2. 加密方案选择
n2n 边缘节点默认使用 AES 加密。你可以根据需求选择其他加密方案,使用 -A_ 选项指定。不同的加密方案在安全性、性能等方面可能存在差异。建议参考 Crypto description 中的比较图表,根据实际情况选择合适的加密方案。
3. 加密基准测试
如果从源代码编译 n2n,可以使用 tools/n2n-benchmark 对不同的加密方法进行基准测试,以了解它们的性能表现,从而在安全性和性能之间找到平衡。
四、头部加密
元数据保护
边缘节点的头部包含一些元数据,如虚拟 MAC 地址、IP 地址、真实主机名和社区名称等。为了保护这些元数据的隐私,可以在边缘节点上使用 -H 选项对头部进行加密,防止这些信息被泄露。
五、认证与授权
1. 用户 / 密码认证
在使用用户 / 密码基于的认证方式时,超级节点需要进行相应的准备。在 community.list 文件中配置用户和密码信息。如果用户更改密码或需要禁止某个用户访问社区,需要更新或删除 community.list 文件中的相应行,并重启超级节点或向管理端口发送 reload_communities 命令,使更改生效。
2. 管理端口认证
对于管理端口的命令操作,有简单的认证机制。读取操作通常允许,而写入操作可能需要提供正确的认证密码。在 mgmt_auth 函数中实现了基本的认证逻辑,通过比较请求中的密码哈希值与提供的认证密码哈希值来判断是否授权。确保设置安全的管理端口密码,防止未经授权的管理操作。
六、版本与更新
1. 使用稳定版本
一般建议使用最新稳定版本。当前的 dev 分支通常不保证与最新稳定版本或以前的 dev 状态向后兼容。如果要尝试新功能,可以从 dev 分支编译,但需要注意跟踪可能快速发生的变化,并在 Issues 部分提供反馈。
2. 及时更新
定期检查 n2n 的更新,及时安装最新版本,以获取安全补丁和功能改进,确保软件的安全性和稳定性。
七、代码安全
1. 开源代码审查
由于 n2n 是开源软件,你可以审查源代码以了解其实现细节和潜在的安全风险。特别是涉及加密、认证、网络通信等关键功能的代码部分,需要仔细审查。
2. 依赖库安全
n2n 可能依赖于一些外部库,如 OpenSSL 等。确保这些依赖库的版本是安全的,及时更新存在安全漏洞的依赖库。
通过遵循以上安


Binary file added ai_usage_screenshots/2205308050315_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050315_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050317_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050317_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050317_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050317_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050317_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050320_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050320_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050320_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050346_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050346_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ai_usage_screenshots/2205308050346_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions modification_log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

<!-- by 黄朝淼 -->
![alt text](2205308050317_1.png)
![alt text](2205308050317_2.png)
![alt text](2205308050317_3.png)
![alt text](2205308050317_4.png)
![alt text](2205308050317_5.png)

# AI 修改记录
## 一、内容优化
### 结构梳理:
对原文内容进行结构化调整,在各级标题格式上保持统一,如将中文数字序号、纯英文序号结合使用,增强文档层次感,使操作步骤、逻辑解释等内容分区更清晰,方便读者快速定位所需信息。
### 表述精炼:
简化冗余语句,例如将 “本指南将详细介绍如何设置自定义超级节点,同时会涉及到相关代码说明” 优化为 “本指南详细介绍自定义超级节点的设置方法及相关代码说明” ,在保持原意的基础上使表达更加简洁流畅。
## 二、技术细节完善
### 命令说明补充:
在操作系统安装命令部分,补充了命令执行效果说明,如 “Ubuntu/Debian 系统:打开终端,执行命令sudo apt - get update && sudo apt - get install n2n,sudo apt-get update用于更新软件源,获取最新软件包信息,sudo apt-get install n2n则用于安装 n2n 软件”,帮助读者更好地理解命令用途。
逻辑解释细化:在参数处理逻辑和初始化逻辑部分,增加代码与实际功能的对应示例,如在解释setOption函数对端口参数处理时,举例 “当输入参数为-p 192.168.1.100:8888,函数会将192.168.1.100解析为 IP 地址,8888解析为端口号”,使抽象逻辑更易理解。
## 三、语言风格统一
### 中英文格式规范:
统一代码命令、参数等英文内容的格式,全部使用英文输入法下的字符,避免中英文标点混合使用导致的格式混乱问题。
语气一致性:全文采用客观、正式的技术文档语气,避免口语化表述,确保在介绍操作步骤、解释技术原理等内容时风格一致,增强文档专业性
=======
![alt text](ai_usage_screenshots/2205308050315_1.png)
![alt text](ai_usage_screenshots/2205308050315_2.png)

46 changes: 46 additions & 0 deletions terms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

<!-- by 黄朝淼 -->
超级节点(Supernode):在网络中具有特殊功能和地位的节点,通常承担着数据转发、网络管理等重要任务,可用于构建特定的网络架构。英文解释:A node in a network that has special functions and status, usually undertaking important tasks such as data forwarding and network management, and can be used to build a specific network architecture.
n2n:一种虚拟专用网络(VPN)技术,允许用户创建自己的私有网络,实现不同设备之间的安全通信。英文解释:A virtual private network (VPN) technology that allows users to create their own private network to achieve secure communication between different devices.
配置文件(Configuration File):包含软件或系统配置信息的文件,用于指定各种参数和设置,以控制软件或系统的行为。英文解释:A file that contains the configuration information of software or a system, used to specify various parameters and settings to control the behavior of the software or system.
端口(Port):计算机与外部设备或其他计算机进行通信的接口,每个端口都有一个唯一的编号,用于区分不同的通信通道。英文解释:An interface through which a computer communicates with external devices or other computers. Each port has a unique number used to distinguish different communication channels.
源码编译(Source Code Compilation):将人类可读的源代码转换为计算机可执行的机器代码的过程,需要使用编译器等工具。英文解释:The process of converting human - readable source code into machine - code that can be executed by a computer, which requires the use of tools such as compilers.
边缘节点(Edge Node):位于网络边缘的节点,通常与终端设备或用户直接连接,用于接收和发送数据。英文解释:A node located at the edge of a network, usually directly connected to terminal devices or users, used to receive and send data.
虚拟接口(Virtual Interface):在计算机系统中模拟出来的网络接口,并非实际的物理接口,用于实现特定的网络功能或连接到虚拟网络。英文解释:A network interface simulated in a computer system, not an actual physical interface, used to implement specific network functions or connect to a virtual network.
社区名称(Community Name):在特定的网络环境中,用于标识一组相关设备或用户的名称,通常用于区分不同的网络区域或用户群体。英文解释:In a specific network environment, a name used to identify a group of related devices or users, usually used to distinguish different network areas or user groups.
加密密钥(Encryption Key):用于对数据进行加密和解密的字符串或数字,确保数据在传输和存储过程中的安全性。英文解释:A string or number used to encrypt and decrypt data, ensuring the security of data during transmission and storage.
自启(Auto - start):指计算机程序或服务在操作系统启动时自动运行的功能,无需用户手动启动。英文解释:Refers to the function that a computer program or service automatically runs when the operating system starts, without the need for manual user startup.
=======

<!-- by 文荣平 -->

|------------------|-----------------------|--------------------------------------------------------------------------|
| 边缘节点 | Edge Node | 运行n2n edge客户端的设备,加入虚拟网络并通过超级节点与其他边缘节点通信 |
| 超级节点 | Supernode | 协助边缘节点建立连接的中继服务器,负责转发发现和连接信息 |
| 社区名称 | Community Name | `-c`参数值,用于隔离不同用户组的虚拟网络,类似"网络名称" |
| 加密密钥 | Encryption Key | `-k`参数值,用于加密节点间通信数据的密钥,需所有成员保持一致 |
| 虚拟网络IP | Virtual Network IP | `-a`参数值,边缘节点在虚拟网络中的私有IP地址,用于内部通信 |
| 软件包仓库 | Software Repository | 如ntop repositories,提供n2n软件包的在线存储和分发服务 |
| 前台模式 | Foreground Mode | `-f`参数效果,使进程在终端前台运行,便于查看实时输出 |
| 中继服务器负载 | Relay Server Load | 超级节点处理连接请求的工作量,建议自建节点减轻公共服务器压力 |
=======
负载加密(payload encryption):对传输的数据(有效负载)进行加密,防止传输中数据内容被非法获取,提升通信安全性。

超级节点(supernode):在网络架构里具有特殊功能或权限的节点,可承担管理、协调等任务,与边缘节点相对。

边缘节点(edge node):位于网络边缘,是用户设备或与之直接相连的设备,在点对点 VPN 中负责数据接入和传输。

加密方案(encryption scheme):实现加密的具体算法、策略及流程组合,不同方案在安全性、性能等方面有差别。

AES 加密(AES encryption):即 Advanced Encryption Standard(高级加密标准),是对称加密算法,在数据加密领域应用广泛,安全性高。

基准测试(benchmark testing):利用特定测试程序和方法,对系统、软件、算法等的性能指标(如速度、效率)进行评估和比较。

元数据(metadata):描述其他数据属性的数据,如边缘节点的虚拟 MAC 地址、IP 地址等,用于标识和管理数据。

虚拟 MAC 地址(virtual MAC address):通过软件等虚拟出的 MAC 地址,非物理网卡真实地址,用于特定网络标识等场景。

实际 MAC 地址(actual MAC address):网络设备物理网卡的唯一硬件地址,用于局域网中设备身份标识。
hostname:主机名,是网络中计算机或设备的名称,用于在网络中识别区分不同设备。