mirror of
https://github.com/openp2p-cn/openp2p.git
synced 2026-05-08 15:03:32 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2af77668fe | ||
|
|
215feb8721 | ||
|
|
4a115fb3fa | ||
|
|
0fb3bc4e26 | ||
|
|
df23b30d2b |
15
README-ZH.md
15
README-ZH.md
@@ -23,7 +23,7 @@
|
||||
### 5. 跨平台
|
||||
因为轻量,所以很容易支持各个平台。支持主流的操作系统:Windows,Linux,MacOS;和主流的cpu架构:386、amd64、arm、arm64、mipsle、mipsle64、mips、mips64
|
||||
### 6. 高效
|
||||
P2P直连可以让你的设备跑满带宽。不论你的设备在任何网络环境,无论NAT1-4(Cone或Symmetric),UPNP,IPv6都支持。依靠Quic协议优秀的拥塞算法,能在糟糕的网络环境获得高带宽低延时。
|
||||
P2P直连可以让你的设备跑满带宽。不论你的设备在任何网络环境,无论NAT1-4(Cone或Symmetric),UDP或TCP打洞,UPNP,IPv6都支持。依靠Quic协议优秀的拥塞算法,能在糟糕的网络环境获得高带宽低延时。
|
||||
|
||||
### 7. 二次开发
|
||||
基于OpenP2P只需数行代码,就能让原来只能局域网通信的程序,变成任何内网都能通信
|
||||
@@ -103,15 +103,15 @@ go mod tidy
|
||||
go build
|
||||
```
|
||||
|
||||
## TODO
|
||||
## RoadMap
|
||||
近期计划:
|
||||
1. 支持IPv6(100%)
|
||||
2. 支持随系统自动启动,安装成系统服务(100%)
|
||||
3. 提供一些免费服务器给特别差的网络,如广电网络(100%)
|
||||
4. 建立网站,用户可以在网站管理所有P2PApp和设备。查看设备在线状态,升级,增删查改重启P2PApp等(100%)
|
||||
1. ~~支持IPv6~~(100%)
|
||||
2. ~~支持随系统自动启动,安装成系统服务~~(100%)
|
||||
3. ~~提供一些免费服务器给特别差的网络,如广电网络~~(100%)
|
||||
4. ~~建立网站,用户可以在网站管理所有P2PApp和设备。查看设备在线状态,升级,增删查改重启P2PApp等~~(100%)
|
||||
5. 建立公众号,用户可在微信公众号管理所有P2PApp和设备
|
||||
6. 客户端提供WebUI
|
||||
7. 支持自有服务器高并发连接
|
||||
7. 支持自有服务器,开源服务器程序
|
||||
8. 共享节点调度模型优化,对不同的运营商优化
|
||||
9. 方便二次开发,提供API和lib
|
||||
10. 应用层支持UDP协议,实现很简单,但UDP应用较少暂不急(100%)
|
||||
@@ -119,6 +119,7 @@ go build
|
||||
12. 支持Android系统,让旧手机焕发青春变成移动网关
|
||||
13. 支持Windows网上邻居共享文件
|
||||
14. 内网直连优化,用处不大,估计就用户测试时用到
|
||||
15. ~~支持UPNP~~(100%)
|
||||
|
||||
远期计划:
|
||||
1. 利用区块链技术去中心化,让共享设备的用户有收益,从而促进更多用户共享,达到正向闭环。
|
||||
|
||||
17
README.md
17
README.md
@@ -25,7 +25,7 @@ The code is open source, the P2P tunnel uses TLS1.3+AES double encryption, and t
|
||||
Benefit from lightweight, it easily supports most of major OS, like Windows, Linux, MacOS, also most of CPU architecture, like 386、amd64、arm、arm64、mipsle、mipsle64、mips、mips64.
|
||||
|
||||
### 6. Efficient
|
||||
P2P direct connection lets your devices make good use of bandwidth. Your device can be connected in any network environments, even supports NAT1-4 (Cone or Symmetric),UPNP,IPv6. Relying on the excellent congestion algorithm of the Quic protocol, high bandwidth and low latency can be obtained in a bad network environment.
|
||||
P2P direct connection lets your devices make good use of bandwidth. Your device can be connected in any network environments, even supports NAT1-4 (Cone or Symmetric),UDP or TCP punching,UPNP,IPv6. Relying on the excellent congestion algorithm of the Quic protocol, high bandwidth and low latency can be obtained in a bad network environment.
|
||||
|
||||
### 7. Integration
|
||||
Your applicaiton can call OpenP2P with a few code to make any internal networks communicate with each other.
|
||||
@@ -111,22 +111,23 @@ go mod tidy
|
||||
go build
|
||||
```
|
||||
|
||||
## TODO
|
||||
## RoadMap
|
||||
Short-Term:
|
||||
1. Support IPv6.(100%)
|
||||
2. Support auto run when system boot, setup system service.(100%)
|
||||
3. Provide free servers to some low-performance network.(100%)
|
||||
4. Build website, users can manage all P2PApp and devices via it. View devices' online status, upgrade, restart or CURD P2PApp .(100%)
|
||||
1. ~~Support IPv6.~~(100%)
|
||||
2. ~~Support auto run when system boot, setup system service.~~(100%)
|
||||
3. ~~Provide free servers to some low-performance network.~~(100%)
|
||||
4. ~~Build website, users can manage all P2PApp and devices via it. View devices' online status, upgrade, restart or CURD P2PApp .~~(100%)
|
||||
5. Provide wechat official account, user can manage P2PApp nodes and deivce as same as website.
|
||||
6. Provide WebUI on client side.
|
||||
7. Support high concurrency on server side.
|
||||
7. Support private server, open source server program.
|
||||
8. Optimize our share scheduling model for different network operators.
|
||||
9. Provide REST APIs and libary for secondary development.
|
||||
10. Support UDP at application layer, it is easy to implement but not urgent due to only a few applicaitons using UDP protocol.(100%)
|
||||
10. ~~Support UDP at application layer, it is easy to implement but not urgent due to only a few applicaitons using UDP protocol.~~(100%)
|
||||
11. Support KCP protocol underlay, currently support Quic only. KCP focus on delay optimization,which has been widely used as game accelerator,it can sacrifice part of bandwidth to reduce timelag.
|
||||
12. Support Android platform, let the phones to be mobile gateway.
|
||||
13. Support SMB Windows neighborhood.
|
||||
14. Direct connection on intranet, for testing.
|
||||
15. ~~Support UPNP.~~(100%)
|
||||
|
||||
|
||||
Long-Term:
|
||||
|
||||
14
common.go
14
common.go
@@ -17,6 +17,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const MinNodeNameLen = 8
|
||||
|
||||
func getmac(ip string) string {
|
||||
//get mac relative to the ip address which connected to the mq.
|
||||
ifaces, err := net.Interfaces()
|
||||
@@ -156,7 +158,7 @@ func execOutput(name string, args ...string) string {
|
||||
|
||||
func defaultNodeName() string {
|
||||
name, _ := os.Hostname()
|
||||
for len(name) < 8 {
|
||||
for len(name) < MinNodeNameLen {
|
||||
name = fmt.Sprintf("%s%d", name, rand.Int()%10)
|
||||
}
|
||||
return name
|
||||
@@ -200,3 +202,13 @@ func parseMajorVer(ver string) int {
|
||||
func IsIPv6(address string) bool {
|
||||
return strings.Count(address, ":") >= 2
|
||||
}
|
||||
|
||||
var letters = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-")
|
||||
|
||||
func randStr(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ func parseParams(subCommand string) {
|
||||
gConf.Network.ServerHost = *serverHost
|
||||
}
|
||||
if *node != "" {
|
||||
if len(*node) < 8 {
|
||||
if len(*node) < MinNodeNameLen {
|
||||
gLog.Println(LvERROR, ErrNodeTooShort)
|
||||
os.Exit(9)
|
||||
}
|
||||
|
||||
BIN
doc/images/p2p-debug.png
Normal file
BIN
doc/images/p2p-debug.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
BIN
doc/images/release-debug.png
Normal file
BIN
doc/images/release-debug.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
BIN
doc/images/vs2022-remote-debug-attach.png
Normal file
BIN
doc/images/vs2022-remote-debug-attach.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
73
doc/remote-debug-golang.md
Normal file
73
doc/remote-debug-golang.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# 1. 环境
|
||||
golang1.18.1
|
||||
调试端: win10+vscode
|
||||
被调试端: ubuntu20.04LTS+dlv
|
||||
## dlv安装
|
||||
参考官方文档https://github.com/go-delve/delve/tree/master/Documentation/installation
|
||||
```
|
||||
go install github.com/go-delve/delve/cmd/dlv@latest
|
||||
```
|
||||
|
||||
## 被调试端
|
||||
```
|
||||
cd /your-src-path #要确保两端源码一致
|
||||
dlv debug --headless --listen=:2345 --api-version=2
|
||||
# 如果失败可查看更多日志
|
||||
# dlv debug --headless --listen=:2345 --api-version=2 --log --log-output=rpc,dap,debugger
|
||||
```
|
||||
|
||||
## 调试端(vscode)
|
||||
```
|
||||
打开vscode,修改launch.json,增加下面远程调试配置
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "RemoteDebug",
|
||||
"type": "go",
|
||||
"request": "attach",
|
||||
"mode": "remote",
|
||||
"port": 2345,
|
||||
"host": "192.168.3.29",
|
||||
}
|
||||
]
|
||||
}
|
||||
按F5启动调试
|
||||
```
|
||||
|
||||
## 没有公网IP或不在同一个局域网,无法直连如何调试
|
||||
到https://openp2p.cn/注册一个用户获得token,两端安装一个客户端程序,可将被调试端的2345端口,通过p2p连接映射到调试端本地。
|
||||
p2p连接可通过web配置 https://github.com/openp2p-cn/openp2p/blob/master/README-ZH.md#%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8
|
||||
|
||||
也可以手动下载https://github.com/openp2p-cn/openp2p/releases 通过命令行手动配置
|
||||
|
||||
```
|
||||
# 注意替换下面YOUR-开头的参数改成自己的
|
||||
./openp2p -node YOUR-DEBUG-SERVER -token YOUR-TOKEN
|
||||
|
||||
openp2p.exe -node YOUR-DEBUG-CLIENT -token YOUR-TOKEN -peernode YOUR-DEBUG-SERVER -dstport 2345 -srcport 2345
|
||||
|
||||
2022/04/22 11:07:26 25680 INFO LISTEN ON PORT tcp:2345 START
|
||||
#显示这条日志说明成功了
|
||||
```
|
||||
|
||||
p2p端口映射完成后,把vscode的配置改成本地127.0.0.1,一样可以顺利调试。
|
||||
```
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "RemoteDebug",
|
||||
"type": "go",
|
||||
"request": "attach",
|
||||
"mode": "remote",
|
||||
"port": 2345,
|
||||
"host": "127.0.0.1",
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# 参考
|
||||
https://github.com/golang/vscode-go/blob/master/docs/debugging.md#remote-debugging
|
||||
50
doc/remote-debug-vscpp.md
Normal file
50
doc/remote-debug-vscpp.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# 1. 环境
|
||||
visual studio 2022
|
||||
调试端: win10
|
||||
被调试端: win10
|
||||
## 程序编译
|
||||
一般远程调试我会选择release版本,然后将优化去掉即可,这样更接近真实版本。
|
||||

|
||||
|
||||
```
|
||||
go install github.com/go-delve/delve/cmd/dlv@latest
|
||||
```
|
||||
|
||||
## 运行远程调试器
|
||||
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Remote Debugger 拷贝到目标机器
|
||||
|
||||
如果调试x64程序则cd到Remote Debugger\x64目录
|
||||
|
||||
管理员方式打开cmd,执行
|
||||
```
|
||||
netsh advfirewall set allprofiles state off
|
||||
msvsmon.exe /noauth /anyuser /silent
|
||||
```
|
||||
|
||||
## visual studio
|
||||
|
||||
Attach远程进程,按下Ctrl+Atl+P
|
||||
|
||||

|
||||
|
||||
|
||||
## 没有公网IP或不在同一个局域网,无法直连如何调试
|
||||
到 https://openp2p.cn/ 注册一个用户获得token,两端安装一个客户端程序,可将被调试端的2345端口,通过p2p连接映射到调试端本地。
|
||||
p2p连接可通过web配置 https://github.com/openp2p-cn/openp2p/blob/master/README-ZH.md#%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8
|
||||
|
||||
也可以手动下载https://github.com/openp2p-cn/openp2p/releases 通过命令行手动配置
|
||||
|
||||
```
|
||||
# 注意替换下面YOUR-开头的参数改成自己的
|
||||
./openp2p -node YOUR-DEBUG-SERVER -token YOUR-TOKEN
|
||||
|
||||
openp2p.exe -node YOUR-DEBUG-CLIENT -token YOUR-TOKEN -peernode YOUR-DEBUG-SERVER -dstport 4026 -srcport 4026
|
||||
|
||||
2022/04/22 11:07:26 25680 INFO LISTEN ON PORT tcp:4026 START
|
||||
#显示这条日志说明成功了
|
||||
```
|
||||
|
||||

|
||||
|
||||
可以顺利远程调试
|
||||
```
|
||||
@@ -102,6 +102,7 @@ func installByFilename() {
|
||||
return
|
||||
}
|
||||
gLog.Println(LvINFO, "install end")
|
||||
gLog.Println(LvINFO, "Visit WebUI on https://console.openp2p.cn")
|
||||
fmt.Println("Press the Any Key to exit")
|
||||
fmt.Scanln()
|
||||
os.Exit(0)
|
||||
|
||||
@@ -136,6 +136,7 @@ func (pn *P2PNetwork) runAll() {
|
||||
}
|
||||
config.nextRetryTime = time.Now().Add(time.Second * time.Duration(increase)) // exponential increase retry time. 1.3^x
|
||||
config.connectTime = time.Now()
|
||||
config.peerToken = pn.config.Token
|
||||
gConf.mtx.Unlock() // AddApp will take a period of time
|
||||
err := pn.AddApp(*config)
|
||||
gConf.mtx.Lock()
|
||||
@@ -459,10 +460,10 @@ func (pn *P2PNetwork) init() error {
|
||||
}
|
||||
gLog.Println(LvDEBUG, "detect NAT type:", pn.config.natType, " publicIP:", pn.config.publicIP)
|
||||
gatewayURL := fmt.Sprintf("%s:%d", pn.config.ServerHost, pn.config.ServerPort)
|
||||
forwardPath := "/openp2p/v1/login"
|
||||
uri := "/openp2p/v1/login"
|
||||
config := tls.Config{InsecureSkipVerify: true} // let's encrypt root cert "DST Root CA X3" expired at 2021/09/29. many old system(windows server 2008 etc) will not trust our cert
|
||||
websocket.DefaultDialer.TLSClientConfig = &config
|
||||
u := url.URL{Scheme: "wss", Host: gatewayURL, Path: forwardPath}
|
||||
u := url.URL{Scheme: "wss", Host: gatewayURL, Path: uri}
|
||||
q := u.Query()
|
||||
q.Add("node", pn.config.Node)
|
||||
q.Add("token", fmt.Sprintf("%d", pn.config.Token))
|
||||
@@ -543,9 +544,12 @@ func (pn *P2PNetwork) handleMessage(t int, msg []byte) {
|
||||
pn.config.User = rsp.User
|
||||
gConf.setToken(rsp.Token)
|
||||
gConf.setUser(rsp.User)
|
||||
if len(rsp.Node) >= MinNodeNameLen {
|
||||
gConf.setNode(rsp.Node)
|
||||
}
|
||||
gConf.save()
|
||||
pn.localTs = time.Now().Unix()
|
||||
gLog.Printf(LvINFO, "login ok. user=%s,Server ts=%d, local ts=%d", rsp.User, rsp.Ts, pn.localTs)
|
||||
gLog.Printf(LvINFO, "login ok. user=%s,node=%s,Server ts=%d, local ts=%d", rsp.User, rsp.Node, rsp.Ts, pn.localTs)
|
||||
}
|
||||
case MsgHeartbeat:
|
||||
gLog.Printf(LvDEBUG, "P2PNetwork heartbeat ok")
|
||||
|
||||
@@ -33,7 +33,7 @@ type P2PTunnel struct {
|
||||
|
||||
func (t *P2PTunnel) requestPeerInfo() error {
|
||||
// request peer info
|
||||
t.pn.write(MsgQuery, MsgQueryPeerInfoReq, &QueryPeerInfoReq{t.pn.config.Token, t.config.PeerNode})
|
||||
t.pn.write(MsgQuery, MsgQueryPeerInfoReq, &QueryPeerInfoReq{t.config.peerToken, t.config.PeerNode})
|
||||
head, body := t.pn.read("", MsgQuery, MsgQueryPeerInfoRsp, time.Second*10)
|
||||
if head == nil {
|
||||
return ErrPeerOffline
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const OpenP2PVersion = "3.1.0"
|
||||
const OpenP2PVersion = "3.4.0"
|
||||
const ProducnName string = "openp2p"
|
||||
const LeastSupportVersion = "3.0.0"
|
||||
|
||||
@@ -148,7 +148,7 @@ const (
|
||||
PublicIPEchoTimeout = time.Second * 1
|
||||
NatTestTimeout = time.Second * 10
|
||||
ClientAPITimeout = time.Second * 10
|
||||
MaxDirectTry = 5
|
||||
MaxDirectTry = 3
|
||||
)
|
||||
|
||||
// NATNone has public ip
|
||||
@@ -246,6 +246,7 @@ type LoginRsp struct {
|
||||
Error int `json:"error,omitempty"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
User string `json:"user,omitempty"`
|
||||
Node string `json:"node,omitempty"`
|
||||
Token uint64 `json:"token,omitempty"`
|
||||
Ts int64 `json:"ts,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user