Avatar CS Knowledge Wiki

18 幂等性与 TCP

Last time: “best effort” delivery as the service abstraction

Last time: “best effort” delivery as the service abstraction

  • Not delivered -> timeout + retransmit
  • Delivered n> 1 times -> transform operations to be idempotent
  • Delivered altered -> checksum or crypto
  • Delivered out of order -> sequence number

On top of this service abstraction, we can build:

  • VoIP
  • User Datagrams
  • VPN (IP-in-UDP/IP-in-IP/IPsec) Q: How does Netflix determine where an IP address is actually from? A: Netflix would look at the IP addresses provided by VPN services and ban those IP addresses.

Short get#

Short get: get(key) -> value

  • E.g. host: what is the IP address that corresponds to a host?
  • With package loss, it takes a longer time to reply, but would still give an answer
  • This service is “reliable” despite the fact that it is built on a unreliable “best effort” service abstraction
// Server 
void recv ( const string& service ) {
  UDPSocket sock; 
  sock.bind ( Address (“0”, service) ); 
  Address source (“0”); 
  string payload; 
  while (true) {
    sock.recv( source, payload);
    cout << “Message from” << source.to_string() << “: “ << payload << endl;
    if (payload == "best_class_ever" ) { 
      sock.sendto( source, "EE180");
    } 
  }
}
plaintext

By doing this, we implement a “reliable” service on top of an “unreliable” service abstraction, and this is also how many real-word reliable services are built (e.g. host).

  • And also: Domain Name System (DNS): what is the IP address of an internet domain name?
  • DHCP (Dynamic Host Configuration Protocol): what is the IP address I am supposed to use?

Set#

Set: (e.g. set the back door open)

Both short get and set (the back door open), you could say how ever many times you want and it does not change the ending state

But for pop(7), push(“hi”), it matters how many times you say it.

Idempotent: doing one time or more than one time does not change the ending state (GET PUT). The strategy we used above works for something idempotent, but not for non-idempotent action

POST#

Do a non-idempotent operation (POST):

By having a set of launched missiles, we make launch_missle idempotent

ByteStream: push, pop, peek needs to be transformed into idempotent operations, and this is achieved by TCP

image.png

What should be in the TCP Sender message to make these operations idempotent?

  • push (“abcd”) works iff each message is delivered exactly once
  • push(“abcd”) + message unique id, but the sender needs to keep a set of any message sent
  • Create a reassembler, first_index: 0, data: “abcd” first_index: 4, data: “efgh”, first_index = 8, FIN=true

image.png

Knowledge map

知识图谱

当前文档、同目录指南与引用关系。

准备中 全局图谱

正在构建知识图谱...

拖动节点 · 滚动缩放 · 点击打开

帮助与支持

这篇文档有帮助吗?

请给我们反馈以改进文档质量
(点击按钮后会打开邮箱)

帮助改进文档

所有文档均开源,发现问题或不清楚的地方?提交 PR 来帮助改进。

编辑此页面 了解如何贡献 →

需要更多帮助?

加入社区或直接联系获取支持

文件管理器 /
位置 /
内容
Knowledge explorer

知识图谱

全部知识 准备图谱...
文章 文档 标签 分类

正在加载知识网络...

拖动节点 · 滚动缩放 · 单击查看详情 · 双击打开页面
标签云 / Tag Cloud