Compare commits

..

3 Commits

Author SHA1 Message Date
TenderIronh
2af77668fe auto adjust node name 2022-09-13 20:47:32 +08:00
TenderIronh
215feb8721 doc 2022-08-08 23:19:47 +08:00
TenderIronh
4a115fb3fa doc remote debug 2022-08-08 23:10:37 +08:00
12 changed files with 161 additions and 19 deletions

View File

@@ -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. 利用区块链技术去中心化,让共享设备的用户有收益,从而促进更多用户共享,达到正向闭环。

View File

@@ -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:

View File

@@ -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)
}

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View 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
View File

@@ -0,0 +1,50 @@
# 1. 环境
visual studio 2022
调试端: win10
被调试端: win10
## 程序编译
一般远程调试我会选择release版本然后将优化去掉即可这样更接近真实版本。
![image](/doc/images/release-debug.png)
```
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
![image](/doc/images/vs2022-remote-debug-attach.png)
## 没有公网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
#显示这条日志说明成功了
```
![image](/doc/images/p2p-debug.png)
可以顺利远程调试
```

View File

@@ -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)

View File

@@ -460,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))
@@ -544,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")

View File

@@ -10,7 +10,7 @@ import (
"time"
)
const OpenP2PVersion = "3.2.0"
const OpenP2PVersion = "3.4.0"
const ProducnName string = "openp2p"
const LeastSupportVersion = "3.0.0"
@@ -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"`
}