sdlan-rs/docs/design.md

30 lines
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# sdlan-sn设计
服务端为单体应用,多个服务端可以同时启动,后面的服务端启动时,可以指定`--federation x.x.x.x:7655,y.y.y.y:7656`命令行参数来指定其他的服务端,服务端将其他服务端的信息保存在`federation`这个network里面。
比如有如下的结构:
```mermaid
graph TD
A[服务端1]
B[服务端2]
C[节点1]
D[节点2]
A .- B
A --- C
B --- D
```
服务端1和服务端2通过udp连接现在分别有个节点连接到对应的服务端
# sdlan设计
sdlan首先使用参数初始化自身然后加入一个多播组然后循环接收消息。
在收到Packet消息时候一方面检查来源等将合法的内容写入到tun设备同时需要查看对端在合适的实际向对端进行注册
* 首先从`known_peers`查找节点通过ip如果找不到通过sock
* 如果找到,就看当前注册的时间,如果时间过了,就从`known_peers`里面重新查找该节点如果是从节点直接p2p过来的就从`known_peers`删除,重新发送注册(加入到`pending_peers`然后发送register`
* 如果没找到,就直接注册(加入到`pending_peers`, 然后发送register
在重新注册过程中如果消息来自sn转发就通过配置的`register_ttl`判断需不需要端口猜测发送register给对端和sn.