Sponge
CS144's user-space TCP library
Classes | Functions
wrapping_integers.hh File Reference
#include <cstdint>
#include <ostream>
Include dependency graph for wrapping_integers.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  WrappingInt32
 A 32-bit integer, expressed relative to an arbitrary initial sequence number (ISN) More...
 

Functions

uint64_t unwrap (WrappingInt32 n, WrappingInt32 isn, uint64_t checkpoint)
 
WrappingInt32 wrap (uint64_t n, WrappingInt32 isn)
 
Helper functions
bool operator!= (WrappingInt32 a, WrappingInt32 b)
 Whether the two integers are not equal. More...
 
WrappingInt32 operator+ (WrappingInt32 a, uint32_t b)
 The point b steps past a. More...
 
WrappingInt32 operator- (WrappingInt32 a, uint32_t b)
 The point b steps before a. More...
 
int32_t operator- (WrappingInt32 a, WrappingInt32 b)
 The offset of a relative to b More...
 
std::ostreamoperator<< (std::ostream &os, WrappingInt32 a)
 Serializes the wrapping integer, a. More...
 
bool operator== (WrappingInt32 a, WrappingInt32 b)
 Whether the two integers are equal. More...
 

Function Documentation

◆ operator!=()

bool operator!= ( WrappingInt32  a,
WrappingInt32  b 
)
inline

Whether the two integers are not equal.

Definition at line 53 of file wrapping_integers.hh.

◆ operator+()

WrappingInt32 operator+ ( WrappingInt32  a,
uint32_t  b 
)
inline

The point b steps past a.

Definition at line 59 of file wrapping_integers.hh.

◆ operator-() [1/2]

WrappingInt32 operator- ( WrappingInt32  a,
uint32_t  b 
)
inline

The point b steps before a.

Definition at line 62 of file wrapping_integers.hh.

◆ operator-() [2/2]

int32_t operator- ( WrappingInt32  a,
WrappingInt32  b 
)
inline

The offset of a relative to b

Parameters
bthe starting point
athe ending point
Returns
the number of increments needed to get from b to a, negative if the number of decrements needed is less than or equal to the number of increments

Definition at line 47 of file wrapping_integers.hh.

◆ operator<<()

std::ostream& operator<< ( std::ostream os,
WrappingInt32  a 
)
inline

Serializes the wrapping integer, a.

Definition at line 56 of file wrapping_integers.hh.

◆ operator==()

bool operator== ( WrappingInt32  a,
WrappingInt32  b 
)
inline

Whether the two integers are equal.

Definition at line 50 of file wrapping_integers.hh.

◆ unwrap()

uint64_t unwrap ( WrappingInt32  n,
WrappingInt32  isn,
uint64_t  checkpoint 
)

Transform a 32-bit relative sequence number into a 64-bit absolute sequence number (zero-indexed)

Parameters
nThe relative sequence number
isnThe initial sequence number
checkpointA recent absolute sequence number
Returns
the absolute sequence number that wraps to n and is closest to checkpoint
Note
Each of the two streams of the TCP connection has its own ISN. One stream runs from the local TCPSender to the remote TCPReceiver and has one ISN, and the other stream runs from the remote TCPSender to the local TCPReceiver and has a different ISN.

◆ wrap()

WrappingInt32 wrap ( uint64_t  n,
WrappingInt32  isn 
)

Transform a 64-bit absolute sequence number (zero-indexed) into a 32-bit relative sequence number

Parameters
nthe absolute sequence number
isnthe initial sequence number
Returns
the relative sequence number