Difference between revisions of "Unit TCP"

From Ultibo.org
Jump to: navigation, search
Line 1,144: Line 1,144:
 
| <code>NextSequence:LongWord;</code>
 
| <code>NextSequence:LongWord;</code>
 
| Next Sequence number to Receive (RCV.NXT)
 
| Next Sequence number to Receive (RCV.NXT)
 +
|-
 +
| <code>LastSequence:LongWord;</code>
 +
| Last Sequence number in Buffer (Including Unacknowledged data)
 
|-
 
|-
 
| <code>LastAcknowledge:LongWord;</code>
 
| <code>LastAcknowledge:LongWord;</code>
 
| Last Acknowledged number to Remote  
 
| Last Acknowledged number to Remote  
Note: NextSequence is the next byte we expect to Receive from Remote LastAcknowledge will be the first Unacknowledged Seqeunce number of the Remote. If LastAcknowledge equals NextSequence all segments have been Acknowledged.
+
Note: NextSequence is the next byte we expect to Receive from Remote. LastAcknowledge will be the first Unacknowledged Seqeunce number of the Remote. LastSequence is the last sequence we have received from the Remote. If NextSequence equals LastSequence and LastAcknowledge equals NextSequence all segments have been Acknowledged.
 
|-
 
|-
 
|colspan="2"|&nbsp;
 
|colspan="2"|&nbsp;
Line 1,166: Line 1,169:
 
| <code>WindowScale:Byte;</code>
 
| <code>WindowScale:Byte;</code>
 
| Local Window Scale
 
| Local Window Scale
 +
|-
 +
| <code>LastWindow:LongWord;</code>
 +
| Last Window value sent to Remote
 
|-
 
|-
 
|colspan="2"|&nbsp;
 
|colspan="2"|&nbsp;
Line 1,179: Line 1,185:
 
| <code>NoSack:Boolean;</code>
 
| <code>NoSack:Boolean;</code>
 
| Selective Ack not in use
 
| Selective Ack not in use
 +
|-
 +
| <code>function CheckIdle:Boolean;</code>
 +
| &nbsp;
 
|-
 
|-
 
|colspan="2"|&nbsp;
 
|colspan="2"|&nbsp;

Revision as of 02:03, 21 April 2017

Return to Unit Reference


Description


Ultibo TCP (Transmission Control Protocol) unit

Notes:

Segment handling:

Send adds new segments to the end of the list only accepts ACKs for whole segments.

Recv adds/inserts segments in correct SEQ order accepts overlapping segments only sends ACKs for whole segments.

Send will coalesce small data writes into larger segments if options allow this.

Recv will store the segments exactly as received.


TCP Send and Recv do not use a block buffer as per UDP etc. Instead the data for each Segment is stored in memory (TCP_MAX_MSS) allocated with the Segment. The Free and Used values still track the amount of data in the buffer but this method allows OOB data to be handled correctly.

TCP Sequence numbers are compared using modulo 2^32 arithmetic. The following calculations provide the neccessary handling of wraparound etc.

LT = (A - B) < 0

LEQ = (A - B) <= 0

GT = (A - B) > 0

GEQ = (A - B) >= 0


See GlobalSock.pas for actual functions that implement this.

Constants



[Expand]
TCP specific constants TCP_*


[Expand]
TCP socket state TCP_STATE_*


[Expand]
TCP header option TCPOPT_*


[Expand]
TCP header flag TCP_FLAG_*


[Expand]
TCP port TCP_PORT_*


Type definitions



TCP header

[Expand]

PTCPHeader = ^TTCPHeader;

TTCPHeader = packed record

TCP segment

[Expand]

PTCPSegment = ^TTCPSegment;

TTCPSegment = record


Class definitions



TCP protocol transport

[Expand]

TTCPProtocolTransport = class(TProtocolTransport)

TCP protocol

[Expand]

TTCPProtocol = class(TNetworkProtocol)

TCP socket

[Expand]

TTCPSocket = class(TProtocolSocket)

TCP state

[Expand]

TTCPState = class(TProtocolState)

TCP options

[Expand]

TTCPOptions = class(TProtocolOptions)

TCP send buffer

[Expand]

TTCPSendBuffer = class(TSocketBuffer)

TCP receive buffer

[Expand]

TTCPRecvBuffer = class(TSocketBuffer)


Public variables


None defined

Function declarations



Initialization functions

[Expand]
procedure TCPInit;
Description: To be documented


TCP functions

[Expand]
function CheckTCP(AFamily:Word; ABuffer:Pointer):Boolean;
Description: Verify that the packet is a valid TCP packet


[Expand]
function GetTCPHeaderOffset(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPHeaderLength(AFamily:Word; ABuffer:Pointer):Word;
Description: TO be documented


[Expand]
function GetTCPOptionsLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPDataOffset(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPDataLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function ChecksumTCPRecv(AFamily:Word; APseudo:PIPPseudo; ABuffer:Pointer; AOffset,ALength:Word):Word;
Description: Validate the Checksum of TCP Pseudo, Header and Data on Receive


[Expand]
function ChecksumTCPSend(AFamily:Word; APseudo:PIPPseudo; AHeader:PTCPHeader; AOptions,AData:Pointer; AOptionsLength,ADataLength:Word):Word;
Description: Checksum the TCP Pseudo, Header, Options and Data on Send


Return to Unit Reference