2024-11-25 21:19:38 +08:00
2025-01-04 10:06:59 +08:00
2025-02-14 16:04:00 +08:00
2025-02-14 16:04:00 +08:00
2024-01-27 16:53:24 +08:00
2025-02-14 16:04:00 +08:00
2024-03-27 21:46:15 +08:00
2024-12-12 19:42:55 +08:00
2024-12-20 22:42:40 +08:00
2024-12-20 22:42:40 +08:00
2024-01-19 07:30:49 +08:00
2024-09-27 12:40:40 +08:00
2024-12-28 20:04:34 +08:00

PeerGuard

Another p2p network library in Go. Committed to direct communication between devices.
[简体中文]

Features

  • Elegantly simple architecture (pgcli & pgmap & OpenID Connect)
  • NAT traversal with high success rate (STUN & UPnP & PortScan & BirthdayParadox)
  • Full support for IPv4/IPv6 dual stack
  • Easy-to-use library (net.PacketConn)
  • Transport layer security (curve25519 & chacha20poly1305 for end-to-end encryption)
  • RDT protocol for reliable data transfer
  • Cross-platform compatibility (linux/windows/macOS/iOS/android)

Get Started

Note

Time synchronization between nodes is crucial; the difference should not exceed 5 seconds

p2p vpn

# node1
pgcli vpn -s wss://synf.in/pg -4 100.64.0.1/24
# node2
pgcli vpn -s wss://synf.in/pg -4 100.64.0.2/24

Advanced

Deploy the peermap server

1. run the pgmap daemon

$ pgmap -l 127.0.0.1:9987 --secret-key 5172554832d76672d1959a5ac63c5ab9 \
    --stun stun.miwifi.com:3478 --stun stunserver.stunprotocol.org:3478

2. wrap pgmap as an https server

$ caddy reverse-proxy --from https://synf.in/pg --to 127.0.0.1:9987

p2p file sharing

# share
$ pgcli share -s wss://synf.in/pg ~/my-show.pptx
ShareURL: pg://DJX2csRurJ3DvKeh63JebVHFDqVhnFjckdVhToAAiPYf/0/my-show.pptx
# download
$ pgcli download -s wss://synf.in/pg pg://DJX2csRurJ3DvKeh63JebVHFDqVhnFjckdVhToAAiPYf/0/my-show.pptx

Shortcut pgvpn

ln -sf /usr/sbin/pgcli /usr/sbin/pgvpn

You can now use pgvpn instead of pgcli vpn.

Use IPC to query the found peers.

pgvpn --peers

Rootless mode VPN

pgvpn -s wss://synf.in/pg -4 100.64.0.1/24 --proxy-listen 127.0.0.1:4090 --forward tcp://127.0.0.1:80 --forward udp://8.8.8.8:53

Uses pre-shared secret file instead of OIDC auth

first

$ export PG_SECRET_KEY=5172554832d76672d1959a5ac63c5ab9
$ export PG_SERVER=wss://synf.in/pg
$ pgcli admin secret --network "<email>" --duration 24h > psns.json

then

sudo pgcli vpn -s wss://synf.in/pg -4 100.64.0.1/24 -f psns.json

License

GNU General Public License v3.0

Contributing

Contributions welcome! Have an improvement? Submit a pull request.

Note

I also maintain a closed-source version, and contributions to the open-source project may be included in the closed-source version.

Description
Go 中的 P2P 网络库。致力于设备🌍之间的直接通信,帖子地址: https://www.v2ex.com/t/1025195
Readme GPL-3.0 1.5 MiB
Languages
Go 93.1%
Vue 3.1%
JavaScript 1.8%
CSS 0.9%
Makefile 0.9%
Other 0.2%