rxqchan*PktBuf// received packets for this Conn go here
txerrchanerror// transmit errors for this Conn go back here
// Conn has to be explicitly closed by user; it can also be closed by NodeLink.Close
// once because: Conn has to be explicitly closed by user; it can also
// be closed by NodeLink.Close .
closeOncesync.Once
closedchanstruct{}
}
// Buffer with packet data
// XXX move me out of here
typePktBufstruct{
Data[]byte// whole packet data including all headers XXX -> Buf ?
}
// Get pointer to packet header
func(pkt*PktBuf)Header()*PktHead{
// XXX check len(Data) < PktHead ? -> no, Data has to be allocated with cap >= PktHeadLen
return(*PktHead)(unsafe.Pointer(&pkt.Data[0]))
}
// Get packet payload
func(pkt*PktBuf)Payload()[]byte{
returnpkt.Data[PktHeadLen:]
}
typeConnRoleint
// A role our end of NodeLink is intended to play
typeLinkRoleint
const(
ConnServerConnRole=iota// connection created as server
ConnClient// connection created as client
LinkServerConnRole=iota// link created as server
LinkClient// link created as client
// for testing:
connNoRecvSendConnRole=1<<16// do not spawn serveRecv & serveSend
connFlagsMaskConnRole=(1<<32-1)<<16
linkNoRecvSendConnRole=1<<16// do not spawn serveRecv & serveSend
linkFlagsMaskConnRole=(1<<32-1)<<16
)
// Make a new NodeLink from already established net.Conn
//
// role specifies how to treat conn - either as server or client one.
// The difference in between client and server roles are in connid % 2 XXX text
// The difference in between client and server roles is only in how connection
// ids are allocated for connections initiated at our side: there is no overlap in identifiers if one side always allocates them as even and its peer as odd. in connId % 2 XXX text
//
// Usually server role should be used for connections created via
// net.Listen/net.Accept and client role for connections created via net.Dial.