diff --git a/README-ZH.md b/README-ZH.md index a4ecb55..a75774d 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -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. 利用区块链技术去中心化,让共享设备的用户有收益,从而促进更多用户共享,达到正向闭环。 diff --git a/README.md b/README.md index f624ade..4b675bd 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/common.go b/common.go index 2444277..d860755 100644 --- a/common.go +++ b/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) +} diff --git a/config.go b/config.go index ad87755..52c7b7b 100644 --- a/config.go +++ b/config.go @@ -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) } diff --git a/p2pnetwork.go b/p2pnetwork.go index 915a551..71c4606 100644 --- a/p2pnetwork.go +++ b/p2pnetwork.go @@ -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") diff --git a/protocol.go b/protocol.go index 19e28bc..4487c7e 100644 --- a/protocol.go +++ b/protocol.go @@ -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"` }