# Stream protocol

The stream protocol is built on top of the unified socket abstraction, and is used to run reliable, TCP-like communication.

Overall, we steal the same construction as the streams used in `sosistab2`, except without any multiplexing on top of the same fingerprint-dock-fingerprint-dock 4-tuple.

## Taking ownership of sockets

A socket can be passed into either a listener (for the server) or connected to a server (for the client).

## Opening streams

While connecting to the server, the client sends a SYN message to the server endpoint.

The server responds with SYN-ACK, and the connection is now open.

A random stream-ID must be chosen.

## Sending data

Data is sent as usual. The stream-ID must stay the same.

## Closing the connection

When the connection is closed, FIN or RST is sent.

The underlying socket (or forwarding table entry) of each connection must be kept alive for at least 60 seconds, even after the connection is closed. A loop then responds to every incoming packet that is not itself an RST with an RST. This is so that the dock number is kept occupied, and so that the other side realizes that the connection is closed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.earendil.network/wiki/protocols/stream-protocol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
