rxqchan*PktBuf// received packets for this Conn go here
rxqchan*PktBuf// received packets for this Conn go here
txerrchanerror// transmit errors for this Conn go back 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
closeOncesync.Once
closedchanstruct{}
closedchanstruct{}
}
}
// Buffer with packet data
// A role our end of NodeLink is intended to play
// XXX move me out of here
typeLinkRoleint
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
const(
const(
ConnServerConnRole=iota// connection created as server
LinkServerConnRole=iota// link created as server
ConnClient// connection created as client
LinkClient// link created as client
// for testing:
// for testing:
connNoRecvSendConnRole=1<<16// do not spawn serveRecv & serveSend
linkNoRecvSendConnRole=1<<16// do not spawn serveRecv & serveSend
connFlagsMaskConnRole=(1<<32-1)<<16
linkFlagsMaskConnRole=(1<<32-1)<<16
)
)
// Make a new NodeLink from already established net.Conn
// Make a new NodeLink from already established net.Conn
//
//
// role specifies how to treat conn - either as server or client one.
// 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
// Usually server role should be used for connections created via
// net.Listen/net.Accept and client role for connections created via net.Dial.
// net.Listen/net.Accept and client role for connections created via net.Dial.