Skip to content

Commit

Permalink
更新 TCP 协议。
Browse files Browse the repository at this point in the history
  • Loading branch information
jacky committed Apr 7, 2024
1 parent cdffb71 commit be2e87e
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 59 deletions.
62 changes: 32 additions & 30 deletions .obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"state": {
"type": "markdown",
"state": {
"file": "docs/Network/运输层:TCP.md",
"file": "docs/Tips/API.md",
"mode": "source",
"source": false
}
Expand Down Expand Up @@ -48,7 +48,7 @@
"state": {
"type": "search",
"state": {
"query": "",
"query": "PG",
"matchingCase": true,
"explainSearch": false,
"collapseAll": false,
Expand Down Expand Up @@ -85,7 +85,7 @@
"state": {
"type": "backlink",
"state": {
"file": "docs/Network/运输层:TCP.md",
"file": "docs/Tips/API.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
Expand All @@ -102,7 +102,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "docs/Network/运输层:TCP.md",
"file": "docs/Tips/API.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
Expand All @@ -125,7 +125,7 @@
"state": {
"type": "outline",
"state": {
"file": "docs/Network/运输层:TCP.md"
"file": "docs/Tips/API.md"
}
}
}
Expand All @@ -149,42 +149,44 @@
},
"active": "044546147249fa2a",
"lastOpenFiles": [
"docs/Network/Network Tips.md",
"docs/Network/运输层:UDP.md",
"docs/stylesheets/extra.css",
"mkdocs.yml",
"docs/Tips/小记.md",
"docs/Tips/API.md",
"docs/Network/运输层:TCP.md",
"docs/LocalFile/Picture/TCP-TCP中止连接半关闭.png",
"docs/Linux/Linux 清理 PG WAL 日志.md",
"docs/Tips/开发规范.md",
"docs/Tips/深度学习.md",
"docs/Linux/磁盘分区挂载.md",
"docs/Linux/curl.md",
"docs/LocalFile/Picture/TCP首部.png",
"docs/LocalFile/Picture/计算机网络-TCP首部.drawio.png",
"docs/OS/OS Tips.md",
"docs/Java/Tips.md",
"docs/LocalFile/Picture/TCP建立连接三向握手.png",
"docs/Network/网络层:IP.md",
"docs/Kafka/Kafka ACL.md",
"docs/Kafka/Kafka 主题与分区.md",
"docs/Kafka/Kafka 集群搭建.md",
"docs/Linux/Linux Tips.md",
"docs/Java/微服务优雅停机.md",
"docs/Java/微服务架构.md",
"docs/Python/第 4 章:流程控制.md",
"docs/Python/第 2 章:算术、字符串与变量.md",
"docs/Reading/2021.md",
"docs/Reading/2022.md",
"docs/Reading/2023.md",
"docs/Reading/读书计划.md",
"docs/Linux/Linux 清理 PG WAL 日志.md",
"docs/Tips/开发规范.md",
"docs/DM/达梦安装.md",
"docs/Network/网络层:IP.md",
"docs/Network/网络层:TCP.md",
"docs/Network/运输层:介绍.md",
"docs/Network/网络层:ICMP.md",
"docs/K8S/安装 Nginx Ingress.md",
"docs/K8S/安装 Kuboard 集群管理界面.md",
"docs/K8S/安装 Kubernetes 集群.md",
"docs/Java/Tips.md",
"docs/Docker/安装 Docker.md",
"docs/Docker/镜像操作.md",
"docs/Arts/侠客行-李白.md",
"docs/Arts/满江红-岳飞.md",
"docs/Algorithms/Base64 算法.md",
"docs/Algorithms/数据结构:图.md",
"docs/Linux/VIM.md",
"docs/Algorithms/求解算数表达式的值.md",
"docs/MySQL/逻辑备份 MySQL.md",
"mkdocs.yml",
"docs/stylesheets/extra.css",
"docs/LocalFile/Picture/TCP首部.png",
"docs/LocalFile/Picture/计算机网络-TCP首部.drawio.png",
"overrides/partials/footer.html",
"overrides/partials/comments.html",
"docs/index.html",
"docs/LocalFile/Picture/用户数据报的格式.png",
"docs/LocalFile/favicon.svg",
"template",
"docs/LocalFile/Picture/OSTips.png",
"docs/LocalFile/Picture/求解算数表达式的值-1.jpg"
"docs/LocalFile/Picture/求解算数表达式的值.jpg"
]
}
35 changes: 24 additions & 11 deletions docs/Algorithms/Base64 算法.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,32 @@ Padding (=)


**示例 1.** 字符串二进制位数刚好为 24 的整数倍 "yes"
```
1) 对应的字节数组为 {121, 101, 115} 转换为二进制:01111001 01100101 01110011
1) 对应的字节数组为 {121, 101, 115} 转换为二进制:01111001 01100101 01110011
2) 分成 6 位一组:011110 010110 010101 110011
2) 分成 6 位一组:011110 010110 010101 110011
3) 高位补 0:00011110 00010110 00010101 00110011
3) 高位补 0:00011110 00010110 00010101 00110011
4) 对应的十进制:30 22 21 51
4) 对应的十进制:30 22 21 51
5) 结果:eWVz
5) 结果:eWVz
**示例 2.** 字符串二进制位数不为 24 的整数倍 "y"
```

1) 对应的字节数组为 {121} 转换为二进制:01111001
**示例 2.** 字符串二进制位数不为 24 的整数倍 "y"
```
1) 对应的字节数组为 {121} 转换为二进制:01111001
2) 分成 6 位一组,不够的位补 0:011110 010000
2) 分成 6 位一组,不够的位补 0:011110 010000
3) 高位补 0:00011110 00010000 padding padding
3) 高位补 0:00011110 00010000 padding padding
4) 对应的十进制:30 8 padding padding
4) 对应的十进制:30 8 padding padding
5) 结果:eQ==
5) 结果:eQ==
```

一般 Base64 结果的字符串最多会有两个填充字符,因为数据的二进制通常码以字节为单位(8bit)存储,保证至少会有两个组(6bit)。

Expand All @@ -85,4 +89,13 @@ public class Test {
Base64.getUrlEncoder().withoutPadding().encodeToString(data);
}
}
```

## Linux base64 命令

需要注意的是 echo 输出会默认增加换行字符,使用 -n 选项取消换行符。
-n do not output the trailing newline
```shell
echo -n yes | base64
eWVz
```
2 changes: 1 addition & 1 deletion docs/Algorithms/求解算数表达式的值.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ comments: true

## 解析算术表达式字符串的元素
将算术表达式字符串中的各个元素(数字、操作符、括号)解析出来。
![元素](求解算数表达式的值-1.jpg)
![元素](../LocalFile/Picture/求解算数表达式的值.jpg)

从左到右解析字符串,并且将算术表达式转换为后缀表达式的时候也要从左到右进行处理,所以这里采用队列存储算术表达式的各个元素。代码如下(暂不支持处理负数):
```java
Expand Down
20 changes: 20 additions & 0 deletions docs/Linux/Linux Tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,23 @@ ssh-keygen -t rsa
who -b
```


## 查看操作系统信息

```
cat /etc/os-release
```

或者
```
ls-release -a
```
## 查看 CPU 信息
```
lscpu
```

或者
```
cat /proc/cpuinfo
```
15 changes: 9 additions & 6 deletions docs/Linux/Linux 清理 PG WAL 日志.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
如果 PG WAL 日志占用过多磁盘空间可以手动清理。

先找到 PG 进程

```
ps -ef | grep postgres

ls -l /proc/pg_pid
```

进入 pg 命令所在的目录

```
./pg_controldata /var/lib/postgresql/13/main/
```

输出

```
Latest checkpoint location: 7EE/3A9CFE0
Latest checkpoint's REDO location: 7EE/2B0E5F0
Latest checkpoint's REDO WAL file: 00000001000007EE00000002
清除 00000001000007EE00000002 之前的文件
```

清除 00000001000007EE00000002 之前的文件,注意有个空格在 wal 存储路径后面。
```
./pg_archivecleanup -d /var/lib/postgresql/13/main/pg_wal/ 00000001000007EE00000002

```

查看每个库数据占用的磁盘空间
```
Expand Down
3 changes: 3 additions & 0 deletions docs/Linux/定时任务.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
comments: true
---
Linux 有两种方式设置定时任务,分别是使用 crontab 命令和 Systemd timer。

## crontab
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/LocalFile/Picture/无序图.png
Binary file not shown.
Binary file removed docs/LocalFile/Picture/有向图.png
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
comments: true
---
备份采用 crontab 定时执行脚本的方式进行。

## 备份
Expand Down Expand Up @@ -34,7 +37,7 @@ then
mkdir -p $backup_dir;
fi

mysqldump --defaults-file=$cre_file $database_name | gzip > $backup_dir/$database_name-$dd.gz
mysqldump --single_transaction --master-data=2 --defaults-file=$cre_file $database_name | gzip > $backup_dir/$database_name-$dd.gz

echo "dump file: $backup_dir/$database_name-$dd.gz" >> $backup_dir/dump.log

Expand Down
5 changes: 5 additions & 0 deletions docs/Network/运输层:TCP.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ TCP 把在一个连接中要发送的所有数据字节都编上号。两个方
### 建立连接

**三向握手**
![](../LocalFile/Picture/TCP建立连接三向握手.png)

**客户端主动打开,C->S 发送报文,seq: x,SYN。**

客户端发送第一个报文段(SYN 报文段),在这个报文段中 SYN 标志置为 1。
Expand Down Expand Up @@ -121,6 +123,7 @@ SYN 报文段不携带任何数据,但是它要消耗一个序号,这个序
参与数据交换的双方中的任何一方都可以关闭连接,一般来说这是由客户端启动的。目前,大多数 TCP 实现允许连接终止时有两种选择:三向握手和具有办关闭属性的四向握手。

**三向握手**
![](../LocalFile/Picture/TCP中止连接三向握手.png)
**客户端主动关闭,C->S 发送报文,seq: x,FIN+ACK。**

客户端在收到进程的关闭命令后,就发送一个报文段,这是一个将 FIN 标志置 1 的报文段。
Expand All @@ -143,6 +146,8 @@ FIN 报文段可以包含客户端发送的最后一块数据。或者仅仅只
在 TCP 中,连接的一方可以停止发送数据,但是仍然可以接收数据,这就称为半关闭,half-close。

常见的情况是,客户端在在发送完所有的数据之后,可以把客户端到服务器方向的连接关闭。但是,从服务端到客户端连接可以是继续打开的,以便服务端处理完客户端的数据之后将处理结果发送给客户端。
![](../LocalFile/Picture/TCP-TCP中止连接半关闭.png)


**客户端主动关闭,C->S 发送报文,seq: x,ack: y,FIN+ACK。**

Expand Down
8 changes: 0 additions & 8 deletions docs/Tips/小记.md

This file was deleted.

4 changes: 4 additions & 0 deletions docs/Tips/开发规范.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

产品上名词术语确定以后,数据库字段注释、代码字段注释和接口文档说明等全局要保持一致。

### 每天查看服务日志

自己负责的服务要有个清单,每天巡查自己负责的服务 ERROR 日志。

## 数据库规范

### 账号
Expand Down
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ nav:
- 数据库:
- MySQL/MySQL Tips.md
- MySQL/安装 MySQL.md
- MySQL/备份 MySQL.md
- MySQL/逻辑备份 MySQL.md
- MySQL/物理备份 MySQL.md
- MySQL/MySQL 配置主从.md
- DM/达梦安装.md
- K8S:
Expand All @@ -59,7 +60,6 @@ nav:
- Linux:
- Linux/Linux Tips.md
- Linux/定时任务.md
- Linux/定时备份 MySQL.md
- Linux/文件与文件系统.md
- Linux/磁盘分区挂载.md
- Linux/Nginx 编译安装.md
Expand Down

0 comments on commit be2e87e

Please sign in to comment.