Skip to content

Commit

Permalink
dilithium.TxPortal.tx. TxAlgorithm tweaks. (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Aug 24, 2021
1 parent c80469c commit 63dd143
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
8 changes: 7 additions & 1 deletion algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import "time"
// instance.
//
type TxAlgorithm interface {
Ready(int)
Tx(int)
Success(int)
DuplicateAck()
Retransmission(int)

// ProbeRTT will return bool when the transmitter is due to probe round trip time. It will also record that true
// response and will not return true again until the algorithm wants another RTT probe.
//
ProbeRTT() bool

UpdateRTT(rttMs int)
RetxMs() int
RxPortalSize() int
Expand All @@ -20,6 +25,7 @@ type TxAlgorithm interface {
// TxProfile defines all of the configurable values that are requested by a flow control algorithm.
//
type TxProfile struct {
MaxSegmentSize int
RetxBatchMs int
SendKeepalive bool
ConnectionTimeout time.Duration
Expand Down
47 changes: 47 additions & 0 deletions txportal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package dilithium
import (
"github.com/emirpasic/gods/trees/btree"
"github.com/emirpasic/gods/utils"
"github.com/openziti/dilithium/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"io"
"math"
"sync"
"time"
)
Expand Down Expand Up @@ -44,6 +48,49 @@ func (txp *TxPortal) start() {
}
}

func (txp *TxPortal) tx(p []byte, seq *util.Sequence) (n int, err error) {
txp.lock.Lock()
defer txp.lock.Unlock()

if txp.closed {
return -1, io.EOF
}

remaining := len(p)
n = 0
for remaining > 0 {
segmentSize := int(math.Min(float64(remaining), float64(txp.alg.Profile().MaxSegmentSize)))

var rtt *uint16
if txp.alg.ProbeRTT() {
now := time.Now()
rtt = new(uint16)
*rtt = uint16(now.UnixNano() / int64(time.Millisecond))
segmentSize -= 2
}

txp.alg.Tx(segmentSize)

wm, err := newData(seq.Next(), rtt, p[n:n+segmentSize], txp.pool)
if err != nil {
return 0, errors.Wrap(err, "new data")
}
txp.tree.Put(wm.Seq, wm)

if err := writeWireMessage(wm, txp.transport); err != nil {
return 0, errors.Wrap(err, "tx")
}
txp.lastTx = time.Now()

txp.monitor.add(wm)

n += segmentSize
remaining -= segmentSize
}

return n, nil
}

func (txp *TxPortal) keepaliveSender() {
logrus.Info("started")
defer logrus.Info("exited")
Expand Down
7 changes: 4 additions & 3 deletions westworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ func NewWestworldAlgorithm(pf *WestworldProfile, txPortal *TxPortal) TxAlgorithm
return &WestworldAlgorithm{pf, txPortal}
}

func (self *WestworldAlgorithm) Ready(size int) {
}

func (self *WestworldAlgorithm) Tx(size int) {
}

Expand All @@ -26,6 +23,10 @@ func (self *WestworldAlgorithm) DuplicateAck() {
func (self *WestworldAlgorithm) Retransmission(size int) {
}

func (self *WestworldAlgorithm) ProbeRTT() bool {
return false
}

func (self *WestworldAlgorithm) UpdateRTT(rttMs int) {
}

Expand Down

0 comments on commit 63dd143

Please sign in to comment.