Skip to content

Commit

Permalink
auto adjust node name
Browse files Browse the repository at this point in the history
  • Loading branch information
TenderIronh committed Sep 13, 2022
1 parent 215feb8 commit 2af7766
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
13 changes: 7 additions & 6 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,23 @@ 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%)
11. 底层通信支持KCP协议,目前仅支持Quic;KCP专门对延时优化,被游戏加速器广泛使用,可以牺牲一定的带宽降低延时
12. 支持Android系统,让旧手机焕发青春变成移动网关
13. 支持Windows网上邻居共享文件
14. 内网直连优化,用处不大,估计就用户测试时用到
15. ~~支持UPNP~~(100%)

远期计划:
1. 利用区块链技术去中心化,让共享设备的用户有收益,从而促进更多用户共享,达到正向闭环。
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 13 additions & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 6 additions & 3 deletions p2pnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"`
}
Expand Down

0 comments on commit 2af7766

Please sign in to comment.