mirror of https://github.com/cbeuw/Cloak
Fix accidentally removed tx qos
This commit is contained in:
parent
b313b34d06
commit
8967819830
|
|
@ -64,12 +64,15 @@ func (sb *switchboard) removeConn(connId uint32) {
|
||||||
|
|
||||||
// a pointer to connId is passed here so that the switchboard can reassign it
|
// a pointer to connId is passed here so that the switchboard can reassign it
|
||||||
func (sb *switchboard) send(data []byte, connId *uint32) (int, error) {
|
func (sb *switchboard) send(data []byte, connId *uint32) (int, error) {
|
||||||
|
sb.Valve.rxWait(len(data))
|
||||||
sb.connsM.RLock()
|
sb.connsM.RLock()
|
||||||
defer sb.connsM.RUnlock()
|
defer sb.connsM.RUnlock()
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
conn, ok := sb.conns[*connId]
|
conn, ok := sb.conns[*connId]
|
||||||
if ok {
|
if ok {
|
||||||
return conn.Write(data)
|
n, err := conn.Write(data)
|
||||||
|
sb.Valve.AddTx(int64(n))
|
||||||
|
return n, err
|
||||||
} else {
|
} else {
|
||||||
// do not call assignRandomConn() here.
|
// do not call assignRandomConn() here.
|
||||||
// we'll have to do connsM.RLock() after we get a new connId from assignRandomConn, in order to
|
// we'll have to do connsM.RLock() after we get a new connId from assignRandomConn, in order to
|
||||||
|
|
@ -86,7 +89,9 @@ func (sb *switchboard) send(data []byte, connId *uint32) (int, error) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, errBrokenSwitchboard
|
return 0, errBrokenSwitchboard
|
||||||
} else {
|
} else {
|
||||||
return conn.Write(data)
|
n, err := conn.Write(data)
|
||||||
|
sb.Valve.AddTx(int64(n))
|
||||||
|
return n, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package multiplex
|
package multiplex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/cbeuw/Cloak/internal/util"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -9,18 +10,13 @@ func BenchmarkSwitchboard_Send(b *testing.B) {
|
||||||
seshConfig := &SessionConfig{
|
seshConfig := &SessionConfig{
|
||||||
Obfuscator: nil,
|
Obfuscator: nil,
|
||||||
Valve: nil,
|
Valve: nil,
|
||||||
UnitRead: nil,
|
UnitRead: util.ReadTLS,
|
||||||
}
|
}
|
||||||
sesh := MakeSession(0, seshConfig)
|
sesh := MakeSession(0, seshConfig)
|
||||||
sbConfig := &switchboardConfig{
|
|
||||||
Valve: UNLIMITED_VALVE,
|
|
||||||
unordered: false,
|
|
||||||
strategy: 0,
|
|
||||||
}
|
|
||||||
sb := makeSwitchboard(sesh, sbConfig)
|
|
||||||
hole := newBlackHole()
|
hole := newBlackHole()
|
||||||
sb.addConn(hole)
|
sesh.sb.addConn(hole)
|
||||||
connId, err := sb.assignRandomConn()
|
connId, err := sesh.sb.assignRandomConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error("failed to get a random conn", err)
|
b.Error("failed to get a random conn", err)
|
||||||
return
|
return
|
||||||
|
|
@ -29,7 +25,7 @@ func BenchmarkSwitchboard_Send(b *testing.B) {
|
||||||
rand.Read(data)
|
rand.Read(data)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
n, err := sb.send(data, &connId)
|
n, err := sesh.sb.send(data, &connId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
return
|
return
|
||||||
|
|
@ -37,3 +33,34 @@ func BenchmarkSwitchboard_Send(b *testing.B) {
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSwitchboard_TxCredit(t *testing.T) {
|
||||||
|
seshConfig := &SessionConfig{
|
||||||
|
Obfuscator: nil,
|
||||||
|
Valve: MakeValve(1<<20, 1<<20),
|
||||||
|
UnitRead: util.ReadTLS,
|
||||||
|
}
|
||||||
|
sesh := MakeSession(0, seshConfig)
|
||||||
|
hole := newBlackHole()
|
||||||
|
sesh.sb.addConn(hole)
|
||||||
|
connId, err := sesh.sb.assignRandomConn()
|
||||||
|
if err != nil {
|
||||||
|
t.Error("failed to get a random conn", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data := make([]byte, 1000)
|
||||||
|
rand.Read(data)
|
||||||
|
|
||||||
|
n, err := sesh.sb.send(data[:10], &connId)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n != 10 {
|
||||||
|
t.Errorf("wanted to send %v, got %v", 10, n)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if *sesh.sb.Valve.(*LimitedValve).tx != 10 {
|
||||||
|
t.Error("tx credit didn't increase by 10")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue