npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

p2p-transfer

v1.0.1

Published

🚀 Pure CLI P2P file transfer tool using WebTorrent and BitTorrent DHT. Transfer files between different networks without public IP.

Readme

P2P Transfer - 点对点文件传输工具

🚀 基于 WebTorrent 和 BitTorrent DHT 的纯命令行点对点文件传输工具,支持跨局域网直传。

✨ 功能特性

  • 🌐 纯命令行 - 无需 Web UI 或浏览器,终端直接操作
  • 🔧 零配置 - 一条命令发送,一条命令接收
  • 👶 小白友好 - 语义化命令,带进度条和速度显示
  • 速度最大化 - DHT + 可配置 Tracker 订阅,最大化节点发现
  • 🔒 跨网络传输 - 不同局域网之间传输,无需公网 IP
  • 📦 大文件支持 - 自动分块处理任意大小文件
  • ⚙️ 灵活配置 - 支持自定义 Tracker 列表和远程订阅更新

🚀 快速开始

安装

# 通过 npm 全局安装
npm install -g p2p-transfer

# 或者使用 npx 直接运行
npx p2p-transfer share <file>

基础用法

发送文件(在发送方机器上):

p2p share ~/movies/vacation.mp4

接收文件(在接收方机器上):

p2p get "magnet:?xt=urn:btih:abc123..."

📖 详细用法

share 命令 - 分享文件

p2p share <文件路径> [选项]

选项:
  -v, --verbose    显示详细日志

示例:

p2p share ~/documents/report.pdf
p2p share ./large-video.mp4 --verbose

输出示例:

🚀 初始化 P2P 分享...
📁 文件: report.pdf
📊 大小: 2.5 MB
🔗 Trackers: 9 个

✅ 分享成功!

🔗 Magnet 链接 (复制发送给接收方):
magnet:?xt=urn:btih:abc123def456...

📋 BTIH Hash: abc123def456

⏳ 等待连接中... (按 Ctrl+C 停止)

get 命令 - 下载文件

p2p get <magnet链接> [保存目录] [选项]

参数:
  magnet             Magnet 链接
  path               保存目录(默认:当前目录)

选项:
  -v, --verbose    显示详细日志

示例:

p2p get "magnet:?xt=urn:btih:abc123..." ~/Downloads
p2p get "magnet:?xt=urn:btih:abc123..." ./my-files

输出示例:

📥 初始化 P2P 下载...

✅ 找到文件!

📁 文件名: report.pdf
📊 总大小: 2.5 MB
📋 Hash: abc123def456
📁 保存到: ~/Downloads

📥 下载进度 |████████████░░░░| 45% | 1.1 MB/2.5 MB | 5.2 MB/s | ETA: 00:00:03

✅ 下载完成!
⏱️  总耗时: 2.50 秒
📁 保存位置: ~/Downloads/report.pdf

config 命令 - 配置管理

p2p config <子命令>

子命令:
  show          显示当前配置
  add <tracker> 添加新的 Tracker
  remove <url>  移除指定 Tracker
  set-url <url> 设置远程订阅地址
  update        从订阅地址更新 Trackers
  reset         重置配置为默认值

示例:

# 查看当前配置
p2p config show

# 添加新的 Tracker
p2p config add udp://tracker.example.com:8080/announce

# 移除 Tracker
p2p config remove udp://tracker.example.com:8080/announce

# 更新远程订阅地址
p2p config set-url https://example.com/trackers.txt

# 从远程订阅更新 Trackers
p2p config update

# 重置配置
p2p config reset

配置文件位置: ~/.p2p-transfer/config.json

info 命令 - 显示帮助信息

p2p info

🎯 工作原理

┌─────────────────┐         ┌─────────────────┐
│    发送方       │   P2P   │    接收方       │
│                 │◄───────►│                 │
│  1. 播种文件    │   DHT   │  2. 下载文件    │
│  3. 生成链接    │         │  4. 解析链接    │
│  4. 分享链接    │         │  5. 开始下载    │
└─────────────────┘         └─────────────────┘
  1. 发送方运行 p2p share <file> 开始播种文件
  2. 生成包含文件哈希和 Tracker 地址的唯一 Magnet URI
  3. 接收方使用收到的链接运行 p2p get <magnet>
  4. DHT + Trackers 自动发现节点
  5. 建立 P2P 连接进行直接传输

🔧 技术细节

  • 协议: BitTorrent
  • 节点发现: DHT (分布式哈希表)
  • Trackers: 9 个公共 Tracker,支持远程订阅更新
  • 无需公网 IP: 支持 NAT 和防火墙穿透

默认 Trackers

- udp://tracker.opentrackr.org:1337/announce
- udp://tracker.openbittorrent.com:6969/announce
- udp://tracker.coppersurfer.tk:6969/announce
- udp://tracker.publicbt.com:80/announce
- udp://tracker.bitsearch.to:1337/announce
- wss://tracker.btorrent.xyz
- wss://tracker.openwebtorrent.com
- wss://tracker.webtorrent.io
- wss://tracker.files.fm:7073/announce

远程订阅地址

默认订阅地址:https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt

运行 p2p config update 可从该地址自动更新 Tracker 列表。

💡 使用场景

  • NAS 到本地: 从 NAS 传输文件到电脑
  • 跨网络传输: 不同网络之间共享文件(家用 ↔ 办公室)
  • 快速分享: 无需先上传到云端
  • 大文件传输: 适合无大小限制的大文件
  • 离线分享: 无需服务器支持(通过 DHT)
  • 远程协作: 团队成员之间直接传输文件

⚙️ 系统要求

  • Node.js >= 18.0.0
  • npm >= 8.0.0
  • 支持的系统:macOS / Linux / Windows (WSL)

📦 从源码安装

git clone https://gitcode.com/yunqiang_wu/p2p-transfer.git
cd p2p-transfer
npm install

# 运行
node p2p.js share <file>

# 或者链接到全局
npm link
p2p share <file>

🌟 高级用法

Linux 环境安装

对于 Linux 用户,可能需要安装编译工具:

# Ubuntu/Debian
sudo apt update && sudo apt install -y build-essential python3

# CentOS/RHEL
sudo yum groupinstall -y "Development Tools" && sudo yum install -y python3

# 然后安装
npm install -g p2p-transfer

或者使用自动安装脚本:

curl -fsSL https://raw.githubusercontent.com/yunqiang_wu/p2p-transfer/main/install-linux.sh | bash

作为项目依赖使用

npm install p2p-transfer

然后在代码中使用:

import { shareFile, getFile } from 'p2p-transfer';

await shareFile('/path/to/file');
await getFile('magnet:?xt=urn:btih:...', './downloads');

🐛 故障排除

无法连接到节点?

  1. 检查防火墙: 确保允许 UDP/TCP 出站连接
  2. 稍等片刻: DHT 节点发现可能需要 1-2 分钟
  3. 使用详细模式: p2p share <file> -v
  4. 更新 Trackers: p2p config update

下载速度慢?

  1. 等待更多节点: 速度随种子数增加而提升
  2. 检查网络: 某些网络有限制
  3. 尝试其他网络: 某些 ISP 限制 BitTorrent

连接问题?

  • 确保双方都有互联网访问
  • 检查 Magnet 链接是否完整(无截断)
  • 尝试重启发送方和接收方

Linux 安装失败?

# 安装编译依赖
sudo apt install build-essential python3
npm install -g p2p-transfer

🤝 贡献指南

欢迎贡献代码!请查看 CONTRIBUTING.md 了解详细信息。

📄 许可证

MIT License - 详见 LICENSE 文件。

🙏 致谢

📈 开发路线图

  • [ ] 添加 WebRTC 支持,支持浏览器端分享
  • [ ] 实现暂停/续传功能
  • [ ] 添加多文件分享支持
  • [ ] 实现带宽限制
  • [ ] 添加加密选项
  • [ ] 创建 GUI 版本

📞 支持


Made with ❤️ for the P2P community