]> git.meshlink.io Git - utcp/blobdiff - utcp_priv.h
Handle channel closure during a receive callback when the ringbuffer wraps.
[utcp] / utcp_priv.h
index 6c1386307e691ca79babe93f66b62108ada9a177..197fd2685a32416f46bc87652ddae5bb27664553 100644 (file)
 #define ACK 2
 #define FIN 4
 #define RST 8
+#define MF 16
 
+#define AUX_INIT 1
+#define AUX_FRAME 2
+#define AUX_SAK 3
+#define AUX_TIMESTAMP 4
+
+#define NSACKS 4
 #define DEFAULT_SNDBUFSIZE 4096
 #define DEFAULT_MAXSNDBUFSIZE 131072
+#define DEFAULT_RCVBUFSIZE 0
+#define DEFAULT_MAXRCVBUFSIZE 131072
+
+#define MAX_UNRELIABLE_SIZE 65536
+#define DEFAULT_MTU 1000
+
+#define USEC_PER_SEC 1000000L
+#define NSEC_PER_SEC 1000000000L
+#define DEFAULT_USER_TIMEOUT 60
+#define START_RTO (1 * USEC_PER_SEC)
+#define MAX_RTO (3 * USEC_PER_SEC)
 
 struct hdr {
        uint16_t src; // Source port
@@ -57,7 +75,7 @@ enum state {
        TIME_WAIT
 };
 
-static const char *strstate[] = {
+static const char *strstate[] __attribute__((unused)) = {
        [CLOSED] = "CLOSED",
        [LISTEN] = "LISTEN",
        [SYN_SENT] = "SYN_SENT",
@@ -71,52 +89,109 @@ static const char *strstate[] = {
        [TIME_WAIT] = "TIME_WAIT"
 };
 
+struct buffer {
+       char *data;
+       uint32_t offset;
+       uint32_t used;
+       uint32_t size;
+       uint32_t maxsize;
+};
+
+struct sack {
+       uint32_t offset;
+       uint32_t len;
+};
+
 struct utcp_connection {
        void *priv;
        struct utcp *utcp;
+       uint32_t flags;
+
        bool reapable;
+       bool do_poll;
 
-       bool nodelay;
-       bool keepalive;
+       // Callbacks
+
+       utcp_recv_t recv;
+       utcp_poll_t poll;
+
+       // TCP State
 
        uint16_t src;
        uint16_t dst;
        enum state state;
 
-       // The following two structures form the TCB
-
        struct {
                uint32_t una;
                uint32_t nxt;
                uint32_t wnd;
                uint32_t iss;
+
+               uint32_t last;
+               uint32_t cwnd;
+               uint32_t ssthresh;
        } snd;
 
        struct {
                uint32_t nxt;
-               uint32_t wnd;
                uint32_t irs;
        } rcv;
 
-       utcp_recv_t recv;
+       int dupack;
+
+       // Timers
+
+       struct timespec conn_timeout;
+       struct timespec rtrx_timeout;
+       struct timespec rtt_start;
+       uint32_t rtt_seq;
+
+       // RTT variables
+
+       uint32_t srtt; // usec
+       uint32_t rttvar; // usec
+       uint32_t rto; // usec
+
+       // Buffers
+
+       uint32_t prev_free;
+       struct buffer sndbuf;
+       struct buffer rcvbuf;
+       struct sack sacks[NSACKS];
+
+       // Per-socket options
 
-       struct timeval conn_timeout;
-       struct timeval rtrx_timeout;
+       bool nodelay;
+       bool keepalive;
+       bool shut_wr;
 
-       char *sndbuf;
-       uint32_t sndbufsize;
-       uint32_t maxsndbufsize;
+       // Congestion avoidance state
+
+       struct timespec tlast;
+       uint64_t bandwidth;
 };
 
 struct utcp {
        void *priv;
 
+       // Callbacks
+
        utcp_accept_t accept;
        utcp_pre_accept_t pre_accept;
+       utcp_retransmit_t retransmit;
        utcp_send_t send;
 
-       uint16_t mtu;
-       int timeout;
+       // Packet buffer
+
+       void *pkt;
+
+       // Global socket options
+
+       uint16_t mtu; // The maximum size of a UTCP packet, including headers.
+       uint16_t mss; // The maximum size of the payload of a UTCP packet.
+       int timeout; // sec
+
+       // Connection management
 
        struct utcp_connection **connections;
        int nconnections;