增加 rust 与 bore 笔记

This commit is contained in:
2022-04-21 18:57:43 +08:00
parent 5968189cd3
commit 1448da0af1
3 changed files with 114 additions and 0 deletions

View File

@ -22,4 +22,11 @@
"pasteImage.path": "${currentFileDir}/images",
"pasteImage.showFilePathConfirmInputBox": true,
"prettier.singleQuote": false,
"spellright.language": [
"zh-CN"
],
"spellright.documentTypes": [
"latex",
"plaintext"
],
}

73
rust/bore.md Normal file
View File

@ -0,0 +1,73 @@
---
tags: #rust #network #bore
---
# [bore](https://github.com/ekzhang/bore)
`Rust` 中的一个现代、简单的 `TCP` 隧道,它将本地端口暴露给远程服务器,绕过标准 `NAT` 。这就是它所做的一切:不多也不少。
## 安装
> 需要有rust环境rust环境安装参照 [[install-rust]] 。
```bash
cargo install bore-cli
```
*安装的时候会从 `github``crates.io-index` ,要上 `github` 啊,可恶,根本上不去。*
## 服务端使用
先在云服务器把防火墙打开想要开放的端口,以及开放 `bore` 的对外端口 `7835`
客户端是通过连接 `7835` 来进行握手,然后才从其它端口建立连接。
然后直接运行 `bore server` 就可以开始监听了。
```
$ bore server
2022-04-21T07:08:49.256539Z INFO bore_cli::server: server listening addr=0.0.0.0:7835
```
## 客户端使用
确认要映射的端口,服务端地址
```
$ bore local 22 --to hostname
```
直接这样连的话,端口是随机分配的,要指定端口需要使用 `--port <port>` 命令行参数。
```
$ bore local 22 --to jie65535.top --port 9022
2022-04-21T09:11:39.835236Z INFO bore_cli::client: connected to server remote_port=9022
2022-04-21T09:11:39.835322Z INFO bore_cli::client: listening at jie65535.top:9022
```
## 服务端帮助
```
bore-server 0.3.0
Runs the remote proxy server
USAGE:
bore server [OPTIONS]
OPTIONS:
-h, --help Print help information
--min-port <MIN_PORT> Minimum TCP port number to accept [default: 1024]
-s, --secret <SECRET> Optional secret for authentication [env: BORE_SECRET]
-V, --version Print version information
```
## 客户端帮助
```
bore-local 0.3.0
Starts a local proxy to the remote server
USAGE:
bore local [OPTIONS] --to <TO> <LOCAL_PORT>
ARGS:
<LOCAL_PORT> The local port to expose
OPTIONS:
-h, --help Print help information
-l, --local-host <HOST> The local host to expose [default: localhost]
-p, --port <PORT> Optional port on the remote server to select [default: 0]
-s, --secret <SECRET> Optional secret for authentication [env: BORE_SECRET]
-t, --to <TO> Address of the remote server to expose local ports to
-V, --version Print version information
```

34
rust/install-rust.md Normal file
View File

@ -0,0 +1,34 @@
---
tags: #rust
---
# 安装Rust环境
从`https://sh.rustup.rs`获取安装脚本,执行脚本安装
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env && rustup default nightly && rustup update
```
建议切换到`nightly`通道,更新使用。
---
## 更换国内源
使用时发现它还得上github获取索引如果访问github有困难可以换源。
`~/.cargo/` 目录下 `touch config`,添加如下内容:
```
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
```
就可以更改为国内源
要通过系统 `git` 访问 `github` 的话,还可以加上以下内容
```
[net]
git-fetch-with-cli = true
```
如果有 `Cargo` 不支持的特殊身份验证要求,将其设置为 `true` 会很有帮助。否则会使用 `cargo` 自带的 `git`