Skip to content

Commit

Permalink
Merge pull request #473 from libp2p/marco/spec-ping
Browse files Browse the repository at this point in the history
Add ping spec
  • Loading branch information
MarcoPolo authored Nov 15, 2022
2 parents 29a6b49 + bdbb9a1 commit a2e3736
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ security, multiplexing, and other purposes.

The protocols described below all use [protocol buffers](https://developers.google.com/protocol-buffers/docs/proto?hl=en) (aka protobuf) to define message schemas. Version `proto2` is used unless stated otherwise.

- [ping][spec_ping] - Ping protocol
- [autonat][spec_autonat] - NAT detection
- [identify][spec_identify] - Exchange keys and addresses with other peers
- [kademlia][spec_kademlia] - The Kademlia Distributed Hash Table (DHT) subsystem
Expand Down Expand Up @@ -131,3 +132,4 @@ you feel an issue isn't the appropriate place for your topic, please join our
[spec_dcutr]: ./relay/DCUtR.md
[spec_webrtc]: ./webrtc/README.md
[spec_webtransport]: ./webtransport/README.md
[spec_ping]: ./ping/ping.md
62 changes: 62 additions & 0 deletions ping/ping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Ping <!-- omit in toc -->

| Lifecycle Stage | Maturity | Status | Latest Revision |
| --------------- | ------------------------ | ------ | --------------- |
| 3A | Recommendation | Active | r0, 2022-11-04 |

Authors: [@marcopolo]

Interest Group: [@marcopolo], [@mxinden], [@marten-seemann]

[@marcopolo]: https://github.com/mxinden
[@mxinden]: https://github.com/mxinden
[@marten-seemann]: https://github.com/marten-seemann

# Table of Contents <!-- omit in toc -->
- [Protocol](#protocol)
- [Diagram](#diagram)

# Protocol

The ping protocol is a simple request response protocol. The client opens a
stream, sends a payload of 32 random bytes, and the server responds with the
same 32 bytes on that stream. The client then measures the RTT from the time it
wrote the bytes to the time it received the bytes. The client MAY repeat the
process by sending another payload with random bytes on the same stream, so the
server SHOULD loop and echo the next payload. The client SHOULD close the write
side of the stream after sending the last payload, and the server SHOULD finish
writing the echoed payload and then exit the loop and close the stream.

The client MUST NOT keep more than one outbound stream for the ping protocol per
peer. The server SHOULD accept at most 2 streams per peer since cross stream
behavior is not linearizable for client and server. In other words, the client
closing stream A and then opening stream B, might be perceived by the server as
the client opening stream B and then closing stream A.

The protocol id is `/ipfs/ping/1.0.0`.

# Diagram

![Ping Protocol Diagram](./ping.svg)

<details>
<summary>Instructions to reproduce diagram</summary>

From the root, run: `plantuml -tsvg ping/ping.md`

```
@startuml
skinparam backgroundColor white
entity Client
entity Server
== /ipfs/ping/1.0.0 ==
loop until Client closes write
Client -> Server: 32 random bytes
Client <- Server: Same 32 random bytes
end
@enduml
```

</details>
22 changes: 22 additions & 0 deletions ping/ping.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a2e3736

Please sign in to comment.