// PupNameServ.decl

// Last modified February 11, 1979  12:39 AM by Boggs

get "PupMiscServ.decl"

manifest
[
lenCacheZone = 256	// room for ~20 cache entries
lenString = 128

nameStatsVersion = 1
]

//----------------------------------------------------------------------------
structure Queue:	// Singly linked list, usually maintained FIFO
//----------------------------------------------------------------------------
[
head word		// -> first thing; 0 if queue is empty
tail word		// -> last thing; undefined if queue is empty
]

//----------------------------------------------------------------------------
structure Stats:
//----------------------------------------------------------------------------
[
version word		// = nameStatsVersion
nameReqs word 2		// number of requests for name lookup
dirReqs word 2		// number of requests to send directory
cacheHits word 2	// number of name cache hits
cacheMisses word 2	// number of name cache misses
]

//----------------------------------------------------------------------------
structure NS:		// 'global frame' for Name Server
//----------------------------------------------------------------------------
[
ctx word		// -> NameServ CTX

stats @Stats

locks word =
   [
   blank bit 11
   globalLocks bit 2 =	// module wide locks
      [
      internalLock bit	// set by LockNameServ()
      externalLock bit	// set by ptNameLockRequest
      ]
   localLocks bit 3 =
      [
      lkupLock bit	// a name lookup is in progress
      rcvrLock bit	// a ReceiveNetDir ctx is active
      sendLock bit	// a SendNetDir ctx is active
      ]
   ]

bcstTimer word		// counts 5 second intervals
bcstInterval word	// dir bcst interval in units of 5 seconds
reqPort @Port		// port of guy who wants our directory
doneQ @Queue		// transient ctxs queue up here for destruction

name word		// -> file name
header word		// -> Hdr
stream word		// -> stream onto directory file
fp word 5		// 5 = lFP (getting AltoFileSys.d breaks the compiler)

cacheZone word		// -> storage zone of size lenCacheZone
cneQ @Queue		// queue of CNEs

firstNamePos word	// position of first name
lastNamePos word	// position of last name

freeAddrQ @Queue	// temporary queues used during name lookup
oldAddrQ @Queue
newAddrQ @Queue

firstPBI word		// -> pbi used a temp buffer
secondPBI word		// -> pbi used a temp buffer
]
manifest
[
lenNS = size NS/16
lkupLock = 4
rcvrLock = 2
sendLock = 1
]

//----------------------------------------------------------------------------
structure NCTX:		// Name Context
//----------------------------------------------------------------------------
[
blank word 3
lockMask word		// used to set and clear bits in NS.localLocks
]
manifest NCTXextra = size NCTX/16 - 3

//----------------------------------------------------------------------------
structure Hdr:		// Network directory header
//----------------------------------------------------------------------------
[
numNames word
firstName word
numAddrs word
firstAddr word
sizeEntrySpace word
firstEntry word
version word		// version number
]
manifest lenHdr = size Hdr/16

//----------------------------------------------------------------------------
structure Attr:		// Network directory attribute block
//----------------------------------------------------------------------------
[
name word		// -> string
value word		// -> string
]

//----------------------------------------------------------------------------
structure Entry:	// Network directory entry block
//----------------------------------------------------------------------------
[
nameListHdr word
addrListHdr word
numAttrs word
attr↑1,1 @Attr
]
manifest addrOffset = offset Entry.addrListHdr/16

//----------------------------------------------------------------------------
structure Addr:		// Network directory address block
//----------------------------------------------------------------------------
[
link word
entry word
port @Port
numAttrs word
attr↑1,1 @Attr
]
//assume no attributes
manifest lenAddr = offset Addr.numAttrs/16

//----------------------------------------------------------------------------
structure Name:		// Network directory name block
//----------------------------------------------------------------------------
[
link word
entry word
string @String
]
manifest lenNameHeader = offset Name.string/16

//----------------------------------------------------------------------------
structure CNE:		// Cache Name Entry
//----------------------------------------------------------------------------
[
link word		// -> next name in cache
cae word		// -> cache address entry
string @String		// the name string itself
]
manifest lenCNEHeader = offset CNE.string/16

//----------------------------------------------------------------------------
structure CAE:		// Cache Address Entry
//----------------------------------------------------------------------------
[
link word		// -> next address for same name
port @Port
]
manifest lenCAE = size CAE/16