Skip to content

Commit

Permalink
Add debug() function and (normally disabled) calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
fragglet committed Sep 1, 2021
1 parent f5ccd0e commit 8ec2bc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions qproxy/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type reliableSharder struct {

func (s *reliableSharder) stateTransition(from, to state) {
if s.state == from {
debug("state %d -> %d", from, to)
s.state = to
}
}
Expand All @@ -92,6 +93,7 @@ func (s *reliableSharder) sendUpstream(rm *reliableMessage) error {
if err != nil {
return err
}
debug("send to upstream: seq=%d, len=%d", rm.Sequence, len(data))
return s.txUpstream(data)
}

Expand All @@ -100,6 +102,7 @@ func (s *reliableSharder) sendDownstream(rm *reliableMessage) error {
if err != nil {
return err
}
debug("send to downstream: seq=%d, len=%d", rm.Sequence, len(data))
// TODO: Save and retransmit after timeout
return s.txDownstream(data)
}
Expand Down Expand Up @@ -163,6 +166,7 @@ func (s *reliableSharder) receiveFromUpstream(msg []byte) (bool, error) {
if err := rm.UnmarshalBinary(msg); err != nil {
return false, err
}
debug("from upstream: flags=%d seq=%d, len=%d", rm.Flags, rm.Sequence, len(msg))
// We have received a reliable data fragment from upstream.
if rm.Sequence == s.rxseq {
s.stateTransition(stateEOMAcked, stateReceiving)
Expand Down Expand Up @@ -202,6 +206,7 @@ func (s *reliableSharder) receiveFromDownstream(msg []byte) (bool, error) {
if err := rm.UnmarshalBinary(msg); err != nil {
return false, err
}
debug("from downstream: flags=%d seq=%d, len=%d", rm.Flags, rm.Sequence, len(msg))

// We have received an ack from downstream.
if rm.Sequence == s.txack {
Expand Down
7 changes: 6 additions & 1 deletion qproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ type Config struct {
IdleTimeout time.Duration
}

func debug(fmt string, args ...interface{}) {
//log.Printf(fmt, args...)
}

type connection struct {
p *Proxy
rs reliableSharder
rs reliableSharder
ipxAddr *ipx.HeaderAddr
conn *net.UDPConn
lastRXTime time.Time
Expand Down Expand Up @@ -264,6 +268,7 @@ func (p *Proxy) garbageCollect() {
expiredConns := []ipx.HeaderAddr{}
for addr, c := range p.conns {
if now.Sub(c.lastRXTime) > p.config.IdleTimeout {
debug("timeout for %s: idle %s", c.conn.RemoteAddr(), now.Sub(c.lastRXTime))
expiredConns = append(expiredConns, addr)
}
}
Expand Down

0 comments on commit 8ec2bc7

Please sign in to comment.