Skip to content

Commit

Permalink
More comments from Richard
Browse files Browse the repository at this point in the history
  • Loading branch information
ekr committed Mar 4, 2018
1 parent 9093445 commit e54b69f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
57 changes: 30 additions & 27 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,20 @@ func (p *pipeConn) RemoteAddr() net.Addr { return nil }
func (p *pipeConn) SetDeadline(t time.Time) error { return nil }
func (p *pipeConn) SetReadDeadline(t time.Time) error { return nil }
func (p *pipeConn) SetWriteDeadline(t time.Time) error { return nil }
func (p *pipeConn) Left() int { return p.r.Len() }
func (p *pipeConn) Empty() bool { return p.r.Len() == 0 }

type bufferedConn struct {
autoflush bool
buffer bytes.Buffer
w net.Conn
ctr int
lossPattern map[int]bool
autoflush bool
buffer bytes.Buffer
w net.Conn
writeCounter int
lostWrite map[int]bool
}

func (b *bufferedConn) Write(buf []byte) (int, error) {
ctr := b.ctr
b.ctr++
if ok := b.lossPattern[ctr]; ok {
ctr := b.writeCounter
b.writeCounter++
if b.lostWrite[ctr] {
fmt.Println("Losing write ", ctr)
return 0, nil
}
Expand Down Expand Up @@ -135,9 +135,9 @@ func (p *bufferedConn) SetWriteDeadline(t time.Time) error { return nil }
func (b *bufferedConn) SetAutoflush() {
b.autoflush = true
}
func (b *bufferedConn) Left() int {
func (b *bufferedConn) Empty() bool {
p := b.w.(*pipeConn)
return p.Left()
return p.Empty()
}

func (b *bufferedConn) Flush() error {
Expand All @@ -155,7 +155,7 @@ func (b *bufferedConn) Flush() error {
}

func (b *bufferedConn) Lose(m int) {
b.lossPattern[m] = true
b.lostWrite[m] = true
}

func (b *bufferedConn) Clear() {
Expand All @@ -164,7 +164,10 @@ func (b *bufferedConn) Clear() {

func newBufferedConn(p net.Conn) *bufferedConn {
return &bufferedConn{
false, bytes.Buffer{}, p, 0, make(map[int]bool, 0),
autoflush: false,
buffer: bytes.Buffer{},
w: p,
lostWrite: make(map[int]bool, 0),
}
}

Expand All @@ -177,7 +180,7 @@ var (
psk PreSharedKey
psks *PSKMapCache

basicConfig, dtlsConfig, nbConfig, nbConfigDTLS, hrrConfig, alpnConfig, pskConfig, pskDTLSConfig, pskECDHEConfig, pskDHEConfig, resumptionConfig, ffdhConfig, x25519Config *Config
basicConfig, dtlsConfig, nbConfig, nbDTLSConfig, hrrConfig, alpnConfig, pskConfig, pskDTLSConfig, pskECDHEConfig, pskDHEConfig, resumptionConfig, ffdhConfig, x25519Config *Config
)

func init() {
Expand Down Expand Up @@ -238,7 +241,7 @@ func init() {
InsecureSkipVerify: true,
}

nbConfigDTLS = &Config{
nbDTLSConfig = &Config{
ServerName: serverName,
Certificates: certificates,
NonBlocking: true,
Expand Down Expand Up @@ -867,7 +870,7 @@ func test0xRTT(t *testing.T, name string, p testInstanceState) {
client.Handshake() // This sends CH
zdata := []byte("ABC")
n, err := client.Write(zdata) // This should succeeed
assertNotError(t, err, "Client was able to write")
assertNotError(t, err, "Client was not able to write")
assertEquals(t, n, len(zdata))
hsUntilBlocked(t, server, sbConn) // Read CH and early data.
tmp := make([]byte, 10)
Expand Down Expand Up @@ -1274,8 +1277,8 @@ func TestNonblockingHandshakeAndDataFlowDTLS(t *testing.T) {
cbConn := newBufferedConn(cConn)
sbConn := newBufferedConn(sConn)

client := Client(cbConn, nbConfigDTLS)
server := Server(sbConn, nbConfigDTLS)
client := Client(cbConn, nbDTLSConfig)
server := Server(sbConn, nbDTLSConfig)

var clientAlert, serverAlert Alert

Expand Down Expand Up @@ -1344,8 +1347,8 @@ func TestTimeoutAndRetransmissionDTLS(t *testing.T) {
cbConn := newBufferedConn(cConn)
sbConn := newBufferedConn(sConn)

client := Client(cbConn, nbConfigDTLS)
server := Server(sbConn, nbConfigDTLS)
client := Client(cbConn, nbDTLSConfig)
server := Server(sbConn, nbDTLSConfig)

var clientAlert, serverAlert Alert

Expand Down Expand Up @@ -1451,7 +1454,7 @@ func checkTimersEqualLabels(t *testing.T, c *Conn, labels []string) {

func hsUntilBlocked(t *testing.T, c *Conn, b *bufferedConn) {
// First run until we have consumed all the data
for b.Left() > 0 {
for !b.Empty() {
alert := c.Handshake()
switch alert {
default:
Expand Down Expand Up @@ -1529,8 +1532,8 @@ func TestAckDTLSNormal(t *testing.T) {
cbConn.SetAutoflush()
sbConn.SetAutoflush()

client := Client(cbConn, nbConfigDTLS)
server := Server(sbConn, nbConfigDTLS)
client := Client(cbConn, nbDTLSConfig)
server := Server(sbConn, nbDTLSConfig)

// Send ClientHello
hsUntilBlocked(t, client, cbConn)
Expand Down Expand Up @@ -1570,8 +1573,8 @@ func TestAckDTLSLoseEE(t *testing.T) {
cbConn.SetAutoflush()
sbConn.SetAutoflush()

client := Client(cbConn, nbConfigDTLS)
server := Server(sbConn, nbConfigDTLS)
client := Client(cbConn, nbDTLSConfig)
server := Server(sbConn, nbDTLSConfig)

// Send ClientHello
hsUntilBlocked(t, client, cbConn)
Expand Down Expand Up @@ -1645,8 +1648,8 @@ func TestDTLSOutOfEpochHSFail(t *testing.T) {
cbConn.SetAutoflush()
sbConn.SetAutoflush()

client := Client(cbConn, nbConfigDTLS)
server := Server(sbConn, nbConfigDTLS)
client := Client(cbConn, nbDTLSConfig)
server := Server(sbConn, nbDTLSConfig)

hsUntilBlocked(t, client, cbConn)
hsUntilBlocked(t, server, sbConn)
Expand Down
4 changes: 0 additions & 4 deletions dtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"time"
)

// This file is a placeholder. DTLS-specific stuff (timer management,
// ACKs, retransmits, etc. will eventually go here.
const (
initialMtu = 1200
initialTimeout = 100
Expand Down Expand Up @@ -130,8 +128,6 @@ func (h *HandshakeContext) processAck(data []byte) error {
return nil
}

type connTimerCb func(c *Conn) error

func (c *Conn) GetDTLSTimeout() (bool, time.Duration) {
return c.hsCtx.timers.remaining()
}
Expand Down
2 changes: 1 addition & 1 deletion timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type timerSet struct {
}

func newTimerSet() *timerSet {
return &timerSet{nil}
return &timerSet{}
}

func (ts *timerSet) start(label string, cb timerCb, delayMs uint32) *timer {
Expand Down

0 comments on commit e54b69f

Please sign in to comment.