mirror of https://github.com/cbeuw/Cloak
Fix a stuck mutex
This commit is contained in:
parent
ae4fc917b6
commit
e7aa4cd04b
|
|
@ -58,10 +58,10 @@ func (sb *switchboard) removeConn(connId uint32) {
|
|||
|
||||
// a pointer to connId is passed here so that the switchboard can reassign it
|
||||
func (sb *switchboard) send(data []byte, connId *uint32) (int, error) {
|
||||
var conn net.Conn
|
||||
sb.connsM.RLock()
|
||||
defer sb.connsM.RUnlock()
|
||||
var conn net.Conn
|
||||
conn, ok := sb.conns[*connId]
|
||||
sb.connsM.RUnlock()
|
||||
if ok {
|
||||
return conn.Write(data)
|
||||
} else {
|
||||
|
|
@ -72,13 +72,11 @@ func (sb *switchboard) send(data []byte, connId *uint32) (int, error) {
|
|||
// in particular if newConnId is removed between the RUnlock and RLock, conns[newConnId] will return
|
||||
// a nil pointer. To prevent this we must get newConnId and the reference to conn itself in one single mutex
|
||||
// protection
|
||||
sb.connsM.RLock()
|
||||
if atomic.LoadUint32(&sb.broken) == 1 || len(sb.conns) == 0 {
|
||||
return 0, errBrokenSwitchboard
|
||||
}
|
||||
newConnId := rand.Intn(len(sb.conns))
|
||||
conn = sb.conns[uint32(newConnId)]
|
||||
sb.connsM.RUnlock()
|
||||
return conn.Write(data)
|
||||
}
|
||||
|
||||
|
|
@ -86,11 +84,11 @@ func (sb *switchboard) send(data []byte, connId *uint32) (int, error) {
|
|||
|
||||
func (sb *switchboard) assignRandomConn() (uint32, error) {
|
||||
sb.connsM.RLock()
|
||||
defer sb.connsM.RUnlock()
|
||||
if atomic.LoadUint32(&sb.broken) == 1 || len(sb.conns) == 0 {
|
||||
return 0, errBrokenSwitchboard
|
||||
}
|
||||
connId := rand.Intn(len(sb.conns))
|
||||
sb.connsM.RUnlock()
|
||||
return uint32(connId), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,12 +161,6 @@ func parseClientHello(data []byte) (ret *ClientHello, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func xor(a []byte, b []byte) {
|
||||
for i := range a {
|
||||
a[i] ^= b[i]
|
||||
}
|
||||
}
|
||||
|
||||
func composeServerHello(sessionId []byte, sharedSecret []byte, sessionKey []byte) ([]byte, error) {
|
||||
nonce := make([]byte, 12)
|
||||
rand.Read(nonce)
|
||||
|
|
|
|||
Loading…
Reference in New Issue