// IfsSequin.decl - Sequin - Declarations
// Copyright Xerox Corporation 1979, 1980

// Last modified by Wobber, March 31, 1981  10:34 AM
// Last modified by Butterfield, February 16, 1979  12:33 PM
// Last modified by Taft, June 27, 1979  9:10 AM

get "Pup0.decl"; get "Pup1.decl"; 

//---------------------------------------------------------------------------
manifest
//---------------------------------------------------------------------------
[
typeLeaf = 260b
socketLeaf = 43b

leafEventInterval = 10;  // 100 milliseconds between LeafEvents
reaperInterval = 500;    // time between reaper scans, 5 seconds.
minuteTimer = 6000/reaperInterval;
defaultLockTimeout = 10 * minuteTimer;    //  10 min timeout from openState
defaultConnTimeout = 12*60 * minuteTimer; // 12 hr timeout from timedOutState.
brokenConnTimeout = defaultLockTimeout;   // 10 minutes if with a brokenLeaf
haltTimeout = defaultLockTimeout;   // 10 minutes if with a brokenLeaf
activityTimeout = 500;   // 5 seconds to allow for retransmit activity
maxOutputVPBIs = 8;   // Maximum allocate not yet sent.
maxInputVPBIs = 8;
vpbiPerPage = 8;
logVPBIPerPage = 3;
logMaxPages = 16-logVPBIPerPage;

sequinStateError = -1;
sequinData = 0; sequinAck = 1; sequinNop = 2; sequinRestart = 3;
sequinCheck = 4; sequinOpen = 5; sequinBreak = 6; sequinClose = 7;
sequinClosed = 8; sequinDestroy = 9; sequinDallying = 10; sequinQuit = 11;
sequinBroken = 12; sequinRetransmit = 13; sequinStifle = 14;

openState = 0; brokenState = 1; closedState = 2; dallyingState = 3;
destroyedState = 4; timedOutState = 5;

maxGetAheadVPBIs = 64; equal = 0; ahead = 1; duplicate = 2; outOfRange = 3;
lastVPBIPage = 256;   // *** Number of VPBI pages, should be multiple of 16.
lenVPBIPageBitMap = lastVPBIPage/16;
]

//---------------------------------------------------------------------------
structure Queue: [ head word; tail word ]
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
structure AllocInfo:  // VPBI allocation information
//---------------------------------------------------------------------------
[
vPageQ: @Queue;
nextVPage word;        // pre-allocated page
allocWord word = [ allocLock byte; nextVPBI byte; ] 
nextOffset word;       // offset of next vpbi
ancientQ @Queue;
]
manifest lenAllocInfo = size AllocInfo/16

//---------------------------------------------------------------------------
structure SCB:  // Sequin control block
//---------------------------------------------------------------------------
[
leafCtx word
sequinCtx word
sequinFeedCtx word
sequinQ: @Queue  // Queue of Leaf's Sequins (sequenced sockets)
haltFlag byte    // Tells other ctxs to quit.
ctxCount byte	 // Count of active Leaf ctxs
reaperTimer word // Timer for running of reaper.
activityWord word = [ ancientScan byte; normalScan byte; ]
outputSequinQ: @Queue  // Queue of actively outputting sequins
inputSequinQ: @Queue  // Queue of sequins with input to be processed
returnPBIQ: @Queue   // CompletePup returns pbis to here.
outputAllocInfo @AllocInfo
inputAllocInfo @AllocInfo
vpbiPageBitMap word lenVPBIPageBitMap;

staticParams word =
vpbiDiskWrites word 2;
vpbiDiskReads word 2;
vpbiWrites word 2;
vpbiReads word 2;
reaperCycles word 2;
normalScans word 2;
ancientScans word 2;
acceptedRFCs word 2;
refusedRFCs word 2;
]
manifest lenSCB = size SCB/16
manifest sequinSS = 1300b
manifest sequinFeedSS = 1300b

//---------------------------------------------------------------------------
structure ReapState: [ current word; reaped word; ]
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
structure Sequin:
//---------------------------------------------------------------------------
[
link word   // sequin queue link
port @Port  // public part
pupDataBytes word   // sequin pup length in bytes
timerCount word
haltTimerCount word
lockTimeout word   // timeout for file locks, in units of 5 seconds
connTimeout word   // timeout for connection, in units of 5 seconds
unam word;  // logged-in user name
lock word   // locks out the Reaper when ANYTHING goes on in sequin.
outputLink word   // active output sequin thread
inputLink word   // active input sequin thread
fhQ @Queue    // file handle queue
control byte; retransmitting bit 1; ancientVPBIs bit 1;
brokenLeaf bit 1; state bit 5;
allocate byte; allocated byte;
allocateSequence word;   // send sequence of last allocated pbi
sendSequence word;
ackedState @ReapState;
receiveSequence word;
inputState @ReapState;
retransmitIndex byte; unreturnedPBIs byte;
retransmitVec word;   // Pointer to vector of retransmit VPBI id's
freeOutputSlot byte; freeInputSlot byte;
lastPutVPBIID word; lastSendVPBIID word; lastInputVPBIID word;
outputVec↑0,maxOutputVPBIs word;   // Vector for vpbi output
inputVec↑0,maxInputVPBIs word;   // Vector for vpbi input
]
manifest lenSequin = size Sequin/16

//---------------------------------------------------------------------------
structure SequinID:
//---------------------------------------------------------------------------
[ allocate byte; receiveSequence byte; control byte; sendSequence byte ]

//---------------------------------------------------------------------------
structure VPBIID: [ page bit logMaxPages; index bit logVPBIPerPage; ]
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
structure VPageHeader:     // Header on virtual pbi page
//---------------------------------------------------------------------------
[
vpbiTable word vpbiPerPage;   // table of vpbi offsets within page.
vPage word;           // number of page itself.
link word;            // chain to next page number.
allocInfo word;       // pointer to allocation information block.
vpbiCount word;       // count of allocated vpbis
ancient byte;         // marks this page as ancient
lockCount byte;       // count of times this page locked.
time word;
vpbis word;           // start of vpbis on this page.
]
manifest lenVPageHeader = size VPageHeader/16

//---------------------------------------------------------------------------
structure VPBI:     // Virtual pbi
//---------------------------------------------------------------------------
[
sequin word;        // points to sequin.
vpbiID @VPBIID;     // ID of this vpbi.
locked bit 1; output bit 1; released bit 1; ancient bit 1;
pageOffset bit 12;  // points back to beginning of page.
sequence word;      // 16 bit sequnece number.
backChain word;     // backwards chain pointer.
pbi @PBI;
]
manifest lenVPBIOverhead = offset VPBI.pbi.pup/16
manifest pbiOffset = offset VPBI.pbi/16