]> git.meshlink.io Git - utcp/blob - README
Update README.
[utcp] / README
1 This is a light-weight, user-space implementation of RFC 793 (TCP), without any
2 reliance on an IP layer.  It can be used to provide multiple in-order, reliable
3 streams on top of any datagram layer.
4
5 UTCP does not rely on a specific event system. Instead, the application feeds
6 it with incoming packets using utcp_recv(), and outgoing data for the streams
7 using utcp_send(). Most of the rest is handled by callbacks. The application
8 must however call utcp_timeout() regularly to have UTCP handle packet loss.
9
10 The application should run utcp_init() for every peer it wants to communicate
11 with.
12
13 DIFFERENCES FROM RFC 793:
14
15 * No checksum. UTCP requires the application to handle packet integrity.
16 * 32-bit window size. Big window sizes are the default.
17 * No ECN, PSH, URG
18
19 TODO v1.0:
20
21 * Implement send buffer
22 * Window scaling
23 * Handle retransmission
24
25 TODO v2.0:
26
27 * Nagle (add PSH back to signal receiver that now we want an immediate ACK?)
28 * NAK and SACK
29 * Congestion window scaling
30 * Timestamps?
31
32 Future ideas:
33
34 Fast open:
35         SYN + data?
36
37 Receive-only open:
38         SYN|FIN
39
40 Fast transaction:
41         SYN|FIN + request data ->
42         <- SYN|ACK|FIN + response data
43         ACK ->
44
45 Does this need special care or can we rely on higher level MACs?
46
47 INVARIANTS
48 ----------
49
50 - snd.una: the sequence number of the first byte we did not receive an ACK for
51 - snd.nxt: the sequence number of the first byte after the last one we ever sent
52 - snd.wnd: the number of bytes we have left in our (UTCP/application?) input buffer
53
54 - rcv.nxt: the sequence number of the first byte after the last one we passed up to the application
55 - rcv.wnd: the number of bytes the receives has left in its input buffer (may be more/less than our send buffer size)
56
57 - The only packets that do not have ACK set must either have SYN or RST set
58 - Only packets received with rcv.nxt <= hdr.seq <= rcv.nxt + rcv.wnd are valid, drop others.
59 - If it has ACK set, and it's higher than snd.una, update snd.una.
60   But don't update it past c->snd.next. (RST in that case?)
61
62 - SYN and FIN each count as one byte for the sequence numbering, but no actual byte is transferred in the payload.
63
64 STATES
65 ------
66
67 CLOSED: this connection is cloed, all packets received will result in RST.
68
69 LISTEN: (= no connection yet): only allow SYN packets, it application does not accept, return RST|ACK, else SYN|ACK.
70
71 SYN_SENT: we sent a SYN, now expecting SYN|ACK
72
73 SYN_RECEIVED: we received a SYN, sent back a SYN|ACK, now expecting an ACK
74
75 ESTABLISHED: SYN is acked, we can now send/receive normal data.
76
77 FIN_WAIT_1: we want to close the connection, and just sent a FIN, waiting for it to be ACKed.
78
79 FIN_WAIT_2: FIXME
80
81 CLOSE_WAIT: we received a FIN, we sent back an ACK
82
83 CLOSING: we had already sent a FIN, and we received a FIN back, now waiting for it to be ACKed.
84
85 LAST_ACK: we are waiting for the last ACK before we can CLOSE
86
87 TIME_WAIT: connection is in princple closed, but our last ACK might not have been received, so just wait a while to see if a FIN gets retransmitted so we can resend the ACK.
88
89 SEND PACKET
90 -----------
91
92 - Put the packet in the send buffer.
93 - Decide how much to send:
94   - Not more than receive window allows
95   - Not more that congestion window allows
96 - Segmentize and send the packets
97 - At the end, snd.nxt is advanced with the number of bytes sent
98 - Set the rtrx and conn timers if they have not been set
99
100 RETRANSMIT
101 ----------
102
103 - Decide how much to send:
104   - Not more than we have in the send buffer
105   - Not more than receive window allows
106   - Not more that congestion window allows
107 - Segmentize and send packets
108 - No advancement of sequence numbers happen
109 - Reset the rtrx timers
110
111 RECEIVE PACKET
112 --------------
113
114 - Drop invalid packets:
115   - Invalid flags or state
116   - hdr.seq not within our receive window
117   - hdr.ack ahead of snd.nxt
118 - Handle RST packets
119 - Advance snd.una?
120   - reset conn timer if so
121   - remove ACKed data from send buffer
122 - If snd.una == snd.nxt, clear rtrx and conn timer
123 - Process state changes due to SYN
124 - Send new data to application
125 - Process state changes due to FIN