mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 06:00:25 +08:00
305 lines
9.0 KiB
Markdown
305 lines
9.0 KiB
Markdown
# MIN Packet Format
|
||
|
||
## 1. TLV
|
||
|
||
- 网络分组级别
|
||
|
||
0 ~ 49
|
||
|
||
| Type | TLV number | Description |
|
||
| :-----------------: | :--------: | :-----------: |
|
||
| PacketMINCommon | 0 | 通用MIN网络包 |
|
||
| PacketMINManagement | 1 | MIN网络管理包 |
|
||
| PacketMINIP | 2 | MIN网络IP包 |
|
||
|
||
- 网络包分区
|
||
|
||
50 ~ 99
|
||
|
||
| Type | TLV number | Description |
|
||
| :------------------------: | :--------: | :----------------------: |
|
||
| IdentifierField | 50 | 目的标识区 |
|
||
| SignatureField | 51 | 数字签名区 |
|
||
| ReadOnlyField | 52 | 只读数据区 |
|
||
| VariableField | 53 | 可变数据区 |
|
||
| VariableProtectField | 54 | 可变数据区中的受保护区 |
|
||
| VariableDangerousField | 55 | 可变数据区中的非受保护区 |
|
||
|
||
- 标识分配
|
||
|
||
100 ~ 199
|
||
|
||
| Type | TLV number | Description |
|
||
| ------------------------- | ---------- | ------------ |
|
||
| IdentifierComponent | 100 | 标识名称组件 |
|
||
| Identifier | 101 | 标识值 |
|
||
| IdentifierCommon | 102 | 身份标识 |
|
||
| IdentifierContentInterest | 103 | 内容兴趣标识 |
|
||
| IdentifierContentData | 104 | 内容数据标识 |
|
||
|
||
- 其它TLV组件
|
||
|
||
200 ~ 500
|
||
|
||
| Type | TLV number | Description |
|
||
| ---------------- | ---------- | -------------------------------------- |
|
||
| SignatureValue | 200 | 签名值 |
|
||
| SignatureInfo | 201 | 签名参数 |
|
||
| SignatureType | 202 | 签名类型 |
|
||
| TlvKeyLocator | 203 | 指示证书或公钥的位置 |
|
||
| Payload | 204 | 网络包负载 |
|
||
| CanBePrefix | 205 | 是否可以被较长的数据包前缀匹配 |
|
||
| MustBeRefresh | 206 | 是否强制只拉取新鲜的数据 |
|
||
| InterestLifeTime | 207 | 兴趣包生存期 |
|
||
| Nonce | 208 | 随机数 |
|
||
| HopLimit | 209 | 跳数限制 |
|
||
| FreshnessPeriod | 210 | 数据包新鲜时间 |
|
||
| CongestionMark | 211 | 拥塞标记 |
|
||
| TTL | 212 | Time to live |
|
||
| SliceNumber | 213 | 分片数量 |
|
||
| SliceSize | 214 | 分片大小 |
|
||
| LogicFaceId | 215 | 逻辑接口Id |
|
||
| RemoteAddr | 216 | 远端地址 |
|
||
| LocalAddr | 217 | 本地地址 |
|
||
| Mtu | 218 | 最大传输单元 |
|
||
| Ret | 219 | bool类型,成功或失败 |
|
||
| Origin | 220 | |
|
||
| Cost | 221 | 链路开销 |
|
||
| Expires | 222 | LogicFace超时时间,-1为不超时(never) |
|
||
|
||
## 2. Identifier
|
||
|
||
```
|
||
IdentifierComponent = 100 TLV-LENGTH
|
||
<Marker>
|
||
*OCTET
|
||
Marker = OCTET
|
||
|
||
Identifier = 101 TLV-LENGTH
|
||
*IdentifierComponent
|
||
```
|
||
|
||
- `*OCTET`:字符串
|
||
|
||
- `Marker`:单个字节,用于区分不同类型的IdentifierComponent,分配如下
|
||
|
||
| Marker value | Description |
|
||
| :----------: | :------------------------------------: |
|
||
| 0x00 | 普通的UTF-8编码的字符串 |
|
||
| 0x01 | 非负整数(可以用1、2、4、8个字节表示) |
|
||
| 0x02 | 任意字节数组 |
|
||
|
||
### 2.1 CommonIdentifier
|
||
|
||
```
|
||
CommonIdentifier = 102 TLV-LENGTH
|
||
<Identifier>
|
||
```
|
||
|
||
### 2.2 InterestIdentifier
|
||
|
||
```
|
||
InterestIdentifier = 103 TLV-LENGTH
|
||
<Identifier>
|
||
```
|
||
|
||
### 2.3 DataIdentifier
|
||
|
||
```
|
||
DataIdentifier = 104 TLV-LENGTH
|
||
<Identifier>
|
||
```
|
||
|
||
## 3. MIN Packet
|
||
|
||
### 3.1 CPacket
|
||
|
||
```
|
||
CPacket = 0 TLV-LENGTH
|
||
{ CommonIdentifier } => 标识区
|
||
{ Signature } => 签名区
|
||
{ => 只读区
|
||
<Payload>
|
||
}
|
||
{ => 可变区
|
||
{ => 受保护区
|
||
"Empty"
|
||
}
|
||
{ => 非受保护区
|
||
[TTL]
|
||
}
|
||
}
|
||
```
|
||
|
||
- `Payload`
|
||
|
||
```
|
||
Payload = PAYLOAD-TYPE TLV-LENGTH *OCTET
|
||
```
|
||
|
||
|
||
### 3.2 Interest
|
||
|
||
```
|
||
Interest = 0 TLV-LENGTH
|
||
{ InterestIdentifier } => 标识区
|
||
{ Signature } => 签名区
|
||
{ => 只读区
|
||
[CanBePrefix]
|
||
[MustBeRefresh]
|
||
[InterestLifeTime]
|
||
[Nonce]
|
||
[HopLimit]
|
||
<Payload>
|
||
}
|
||
{ => 可变区
|
||
{ => 受保护区
|
||
[CongestionMark]
|
||
}
|
||
{ => 非受保护区
|
||
"Empty"
|
||
}
|
||
}
|
||
```
|
||
|
||
- `CanBePrefix`
|
||
|
||
```
|
||
CanBePrefix = 203
|
||
TLV-LENGTH; == 0
|
||
```
|
||
|
||
- `MustBeFresh`
|
||
|
||
```
|
||
MustBeFresh = 204
|
||
TLV-LENGTH; == 0
|
||
```
|
||
|
||
- `InterestLifeTime`
|
||
|
||
```
|
||
InterestLifeTime = 205 TLV-LENGTH NoNegativeInteger
|
||
```
|
||
|
||
- `NonNegativeInteger` :非负整数
|
||
|
||
- `Nonce`
|
||
|
||
```
|
||
Nonce = 206
|
||
TLV-LENGTH; == 4
|
||
4OCTET
|
||
```
|
||
|
||
- `4OCTET`:四字节字符串
|
||
|
||
- `HopLimit`
|
||
|
||
```
|
||
HopLimit = 207
|
||
TLV-LENGTH; == 1
|
||
OCTET
|
||
```
|
||
|
||
- `OCTET`:1字节无符号整数
|
||
|
||
### 3.3 Data
|
||
|
||
```
|
||
Data = 0 TLV-LENGTH
|
||
{ DataIdentifier } => 标识区
|
||
{ Signature } => 签名区
|
||
{ => 只读区
|
||
[FreshnessPeriod]
|
||
<Payload>
|
||
}
|
||
{ => 可变区
|
||
{ => 受保护区
|
||
[CongestionMark]
|
||
}
|
||
{ => 非受保护区
|
||
"Empty"
|
||
}
|
||
}
|
||
```
|
||
|
||
### 3.4 ManagementPacket
|
||
|
||
- Request
|
||
|
||
```
|
||
ManagementRequestPacket = 1 TLV-LENGTH
|
||
{ InterestIdentifier } => 标识区
|
||
{ Signature } => 签名区
|
||
```
|
||
|
||
- Response
|
||
|
||
```
|
||
ManagementResponsePacket = 1 TLV-LENGTH
|
||
{ DataIdentifier } => 标识区
|
||
{ Signature } => 签名区
|
||
{ => 只读区
|
||
<Payload>
|
||
}
|
||
{ => 可变区
|
||
{ => 受保护区
|
||
"Empty"
|
||
}
|
||
{ => 非受保护区
|
||
"Empty"
|
||
}
|
||
}
|
||
```
|
||
|
||
- `SliceNumber`
|
||
|
||
```
|
||
SliceNumber = 205 TLV-LENGTH NoNegativeInteger
|
||
```
|
||
|
||
- `SliceSize`
|
||
|
||
```
|
||
SliceSize = 205 TLV-LENGTH NoNegativeInteger
|
||
```
|
||
|
||
|
||
## 4. Signature
|
||
|
||
```
|
||
Signature = SignatureInfo SignatureValue
|
||
|
||
SignatureInfo = 201 TLV-LENGTH
|
||
<SignatureType>
|
||
[KeyLocator]
|
||
|
||
SignatureValue = 200 TLV-LENGTH *OCTET
|
||
```
|
||
|
||
在MIN的包格式里面,一个签名 `Signature` 由两个连续的TLV块,`SignatureInfo` 和 `SignatureValue` 组成。
|
||
|
||
- **SignatureInfo**
|
||
|
||
`SignatureInfo` 中包含一个必选的子 TLV 块 `SignatureType`,它包含了签名的信息,其格式如下:
|
||
|
||
```
|
||
SignatureType = SIGNATURE-TYPE-TYPE TLV-LENGTH <NonNegativeInteger>
|
||
```
|
||
|
||
目前定义的 SignatureType的值如下:
|
||
|
||
| SignatureType Value | Description |
|
||
| :-----------------: | :----------------------------------------------------------: |
|
||
| 0 | SM2_WITH_SM3,在SM3 Hash摘要的基础上用SM2签名进行完整性和不可否任性保护 |
|
||
|
||
`SignatureInfo` 中还包含一个可选的TLV块 `KeyLocator` (虽说是可选,但是这个是为了后期扩展,目前为必选项),它指示了用于签名的证书或者公钥的位置,其格式如下:
|
||
|
||
```
|
||
KeyLocator = KEYLOCATOR-TYPE TLV-TYPE <Identifier>
|
||
```
|
||
|
||
- **SignatureValue**
|
||
|
||
`SignatureValue` 中包含了签名的值,是一串字节 |