Added comment wrt. mutex lock scope in WritePacket

This commit is contained in:
Russ Magee 2018-05-04 14:40:06 -07:00
parent a49a5d4cc2
commit 925e83bbba

View file

@ -449,6 +449,14 @@ func (c Conn) WritePacket(b []byte, op byte) (n int, err error) {
var hmacOut []uint8 var hmacOut []uint8
var payloadLen uint32 var payloadLen uint32
// N.B. Originally this Lock() surrounded only the
// calls to binary.Write(c.c ..) however there appears
// to be some other unshareable state in the Conn
// struct that must be protected to serialize main and
// chaff data written to it.
//
// Would be nice to determine if the mutex scope
// could be tightened.
c.Rwmut.Lock() c.Rwmut.Lock()
{ {
log.Printf(" :>ptext:\r\n%s\r\n", hex.Dump(b)) log.Printf(" :>ptext:\r\n%s\r\n", hex.Dump(b))
@ -506,8 +514,6 @@ func (c *Conn) Chaff(enable bool, msecsMin int, msecsMax int, szMax int) {
} }
// Helper routine to spawn a chaffing goroutine for each Conn // Helper routine to spawn a chaffing goroutine for each Conn
// TODO: if/when server->client chaffing is added, server must
// todo: ensure this is turned off on client hangup
func (c *Conn) chaffHelper(szMax int) { func (c *Conn) chaffHelper(szMax int) {
go func() { go func() {
for { for {
@ -519,7 +525,7 @@ func (c *Conn) chaffHelper(szMax int) {
_, _ = rand.Read(chaff) _, _ = rand.Read(chaff)
_, err := c.WritePacket(chaff, CSOChaff) _, err := c.WritePacket(chaff, CSOChaff)
if err != nil { if err != nil {
log.Println("[ *** error writing chaff - end chaffing *** ]") log.Println("[ *** error - chaffHelper quitting *** ]")
break break
} }
} }