Skip to content

Commit

Permalink
install mode and improve relay
Browse files Browse the repository at this point in the history
  • Loading branch information
TenderIronh committed Dec 9, 2021
1 parent a2387fe commit f12059d
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 89 deletions.
8 changes: 6 additions & 2 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ P2P直连可以让你的设备跑满带宽。不论你的设备在任何网络
基于OpenP2P只需数行代码,就能让原来只能局域网通信的程序,变成任何内网都能通信

## 快速入门

> :warning: 本文所有命令, Windows环境使用"openp2p.exe", Linux环境使用"./openp2p"

以一个最常见的例子说明OpenP2P如何使用:远程办公,在家里连入办公室Windows电脑。
相信很多人在疫情下远程办公是刚需。
1. 先确认办公室电脑已开启远程桌面功能(如何开启参考官方说明https://docs.microsoft.com/zh-cn/windows-server/remote/remote-desktop-services/clients/remote-desktop-allow-access)
2. 在办公室下载最新的[OpenP2P](https://gitee.com/tenderiron/openp2p/releases/),解压出来,在命令行执行
```
openp2p.exe -d -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
openp2p.exe install -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
```

> :warning: **切记将标记大写的参数改成自己的**
Expand Down Expand Up @@ -114,7 +118,7 @@ TODO或ISSUE里如果有你擅长的领域,或者你有特别好的主意,
它是一个中国人发起的项目,更懂国内网络环境,更懂用户需求,更好的企业级支持
## 技术交流
QQ群:16947733
邮箱:[email protected] 271357901@qq.com
邮箱:[email protected] tenderiron@139.com

## 免责声明
本项目开源供大家学习和免费使用,禁止用于非法用途,任何不当使用本项目或意外造成的损失,本项目及相关人员不会承担任何责任。
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Your applicaiton can call OpenP2P with a few code to make any internal networks
A common scenario to introduce OpenP2P: remote work. At home connects to office's Linux PC .
Under the outbreak of covid-19 pandemic, surely remote work becomes a fundamental demand.

> :warning: all commands in this doc, Windows env uses "openp2p.exe", Linux env uses "./openp2p"

1. Make sure your office device(Linux) has opened the access of ssh.
```
netstat -nl | grep 22
Expand All @@ -36,7 +39,7 @@ Under the outbreak of covid-19 pandemic, surely remote work becomes a fundamenta
2. Download the latest version of [OpenP2P](https://github.com/openp2p-cn/openp2p/releases),unzip the downloaded package, and execute below command line.
```
tar xvf openp2p0.95.3.linux-amd64.tar.gz
openp2p -d -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
./openp2p install -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
```

> :warning: **Must change the parameters marked in uppercase to your own**
Expand Down
50 changes: 32 additions & 18 deletions USAGE-ZH.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
# 详细运行参数说明
> :warning: 本文所有命令, Windows环境使用"openp2p.exe", Linux环境使用"./openp2p"
## 监听

## 安装和监听
```
openp2p.exe -d -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
./openp2p install -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
./openp2p -d -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
# 注意Windows系统把“./openp2p” 换成“openp2p.exe”
```
>* -d daemon模式,推荐使用。发现worker进程意外退出就会自动启动新的worker进程
>* -node 独一无二的节点名字,唯一标识
>* -user 独一无二的用户名字,该节点属于这个user
>* -password 密码
>* -sharebandwidth 作为共享节点时提供带宽,默认10mbps. 如果是光纤大带宽,设置越大效果越好
>* -loglevel 需要查看更多调试日志,设置0;默认是1
>* -noshare 不共享,该节点只在私有的P2P网络使用。不加入共享的P2P网络,这样也意味着无法使用别人的共享节点
>* install: 安装模式【推荐】,会安装成系统服务,这样它就能随系统自动启动
>* -d: daemon模式。发现worker进程意外退出就会自动启动新的worker进程
>* -node: 独一无二的节点名字,唯一标识
>* -user: 独一无二的用户名字,该节点属于这个user
>* -password: 密码
>* -sharebandwidth: 作为共享节点时提供带宽,默认10mbps. 如果是光纤大带宽,设置越大效果越好
>* -loglevel: 需要查看更多调试日志,设置0;默认是1
>* -noshare: 不共享,该节点只在私有的P2P网络使用。不加入共享的P2P网络,这样也意味着无法使用别人的共享节点
## 连接
```
openp2p.exe -d -node HOMEPC123 -user USERNAME1 -password PASSWORD1 -peernode OFFICEPC1 -dstip 127.0.0.1 -dstport 3389 -srcport 23389 -protocol tcp
./openp2p -d -node HOMEPC123 -user USERNAME1 -password PASSWORD1 -peernode OFFICEPC1 -dstip 127.0.0.1 -dstport 3389 -srcport 23389 -protocol tcp
使用配置文件,建立多个P2PApp
./openp2p -d -f
./openp2p -f
```
>* -peernode 目标节点名字
>* -dstip 目标服务地址,默认本机127.0.0.1
>* -dstport 目标服务端口,常见的如windows远程桌面3389,Linux ssh 22
>* -protocol 目标服务协议 tcp、udp
>* -peeruser 目标用户,如果是同一个用户下的节点,则无需设置
>* -peerpassword 目标密码,如果是同一个用户下的节点,则无需设置
>* -f 配置文件,如果希望配置多个P2PApp参考[config.json](/config.json)
>* -peernode: 目标节点名字
>* -dstip: 目标服务地址,默认本机127.0.0.1
>* -dstport: 目标服务端口,常见的如windows远程桌面3389,Linux ssh 22
>* -protocol: 目标服务协议 tcp、udp
>* -peeruser: 目标用户,如果是同一个用户下的节点,则无需设置
>* -peerpassword: 目标密码,如果是同一个用户下的节点,则无需设置
>* -f: 配置文件,如果希望配置多个P2PApp参考[config.json](/config.json)
## 升级客户端
```
# update local client
openp2p update
./openp2p update
# update remote client
curl --insecure 'https://openp2p.cn:27182/api/v1/device/YOUR-NODE-NAME/update?user=&password='
```
Expand All @@ -38,4 +47,9 @@ Linux系统(Ubuntu和CentOS7)的防火墙默认配置均不会有影响,
systemctl stop firewalld.service
systemctl start firewalld.service
firewall-cmd --state
```

## 卸载
```
./openp2p uninstall
```
51 changes: 33 additions & 18 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
# Parameters details

## Listen
> :warning: all commands in this doc, Windows env uses "openp2p.exe", Linux env uses "./openp2p"

## Install and Listen
```
openp2p.exe -d -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
./openp2p install -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
Or
./openp2p -d -node OFFICEPC1 -user USERNAME1 -password PASSWORD1
```
>* -d daemon mode is recommand. When the worker process is found to exit unexpectedly, a new worker process will be automatically started
>* -node Unique node name, unique identification
>* -user Unique user name, the node belongs to this user
>* -password Password
>* -sharebandwidth Provides bandwidth when used as a shared node, the default is 10mbps. If it is a large bandwidth of optical fiber, the larger the setting, the better the effect
>* -loglevel Need to view more debug logs, set 0; the default is 1
>* -noshare Not shared, the node is only used in a private P2P network. Do not join the shared P2P network, which also means that you CAN NOT use other people’s shared nodes
>* install: [recommand] will install as system service. So it will autorun when system booting.
>* -d: daemon mode run once. When the worker process is found to exit unexpectedly, a new worker process will be automatically started
>* -node: Unique node name, unique identification
>* -user: Unique user name, the node belongs to this user
>* -password: Password
>* -sharebandwidth: Provides bandwidth when used as a shared node, the default is 10mbps. If it is a large bandwidth of optical fiber, the larger the setting, the better the effect
>* -loglevel: Need to view more debug logs, set 0; the default is 1
>* -noshare: Not shared, the node is only used in a private P2P network. Do not join the shared P2P network, which also means that you CAN NOT use other people’s shared nodes
## Connect
```
openp2p.exe -d -node HOMEPC123 -user USERNAME1 -password PASSWORD1 -peernode OFFICEPC1 -dstip 127.0.0.1 -dstport 3389 -srcport 23389 -protocol tcp
./openp2p -d -node HOMEPC123 -user USERNAME1 -password PASSWORD1 -peernode OFFICEPC1 -dstip 127.0.0.1 -dstport 3389 -srcport 23389 -protocol tcp
Create multiple P2PApp by config file
./openp2p -d -f
./openp2p -f
```
>* -peernode Target node name
>* -dstip Target service address, default local 127.0.0.1
>* -dstport Target service port, such as windows remote desktop 3389, Linux ssh 22
>* -protocol Target service protocol tcp, udp
>* -peeruser The target user, if it is a node under the same user, no need to set
>* -peerpassword The target password, if it is a node under the same user, no need to set
>* -f Configuration file, if you want to configure multiple P2PApp refer to [config.json](/config.json)
>* -peernode: Target node name
>* -dstip: Target service address, default local 127.0.0.1
>* -dstport: Target service port, such as windows remote desktop 3389, Linux ssh 22
>* -protocol: Target service protocol tcp, udp
>* -peeruser: The target user, if it is a node under the same user, no need to set
>* -peerpassword: The target password, if it is a node under the same user, no need to set
>* -f: Configuration file, if you want to configure multiple P2PApp refer to [config.json](/config.json)
## Client update
```
# update local client
openp2p update
./openp2p update
# update remote client
curl --insecure 'https://openp2p.cn:27182/api/v1/device/YOUR-NODE-NAME/update?user=&password='
```
Expand All @@ -38,4 +48,9 @@ The default firewall configuration of Linux system (Ubuntu and CentOS7) will not
systemctl stop firewalld.service
systemctl start firewalld.service
firewall-cmd --state
```

## Uninstall
```
./openp2p uninstall
```
9 changes: 5 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type AppConfig struct {
shareBandwidth int
}

// TODO: add loglevel, maxlogfilesize
type Config struct {
Network NetworkConfig `json:"network"`
Apps []AppConfig `json:"apps"`
Expand All @@ -45,10 +46,10 @@ func (c *Config) add(app AppConfig) {
c.Apps = append(c.Apps, app)
}

// func (c *Config) save() {
// data, _ := json.MarshalIndent(c, "", "")
// ioutil.WriteFile("config.json", data, 0644)
// }
func (c *Config) save() {
data, _ := json.MarshalIndent(c, "", "")
ioutil.WriteFile("config.json", data, 0644)
}

func (c *Config) load() error {
data, err := ioutil.ReadFile("config.json")
Expand Down
Loading

0 comments on commit f12059d

Please sign in to comment.