Verified Commit 4705ec56 authored by Jeffrey H. Johnson's avatar Jeffrey H. Johnson
Browse files

Bugfixes and stylization, dead code removal

parent 5c2ff4cc
......@@ -22,10 +22,10 @@ import (
 
// Gfcp protocol constants
const (
GfcpRtoNdl = 10 // GfcpRtoNdl: NoDelay min RTO
GfcpRtoMin = 100 // GfcpRtoMin: Regular min RTO
GfcpRtoDef = 250
GfcpRtoMax = 45000
GfcpRtoNdl = 20 // GfcpRtoNdl: NoDelay min RTO
GfcpRtoMin = 220 // GfcpRtoMin: Regular min RTO
GfcpRtoDef = 340
GfcpRtoMax = 10000
GfcpCmdPush = 81 // GfcpCmdPush: Push data
GfcpCmdAck = 82 // GfcpCmdAck: Ack
GfcpCmdWask = 83 // GfcpCmdWask: Get Window Size
......@@ -34,15 +34,15 @@ const (
GfcpAskTell = 2 // GfcpAskTell: Need to send GfcpCmdWins
GfcpWndSnd = 64
GfcpWndRcv = 64
GfcpMtuDef = 1500
GfcpAckFast = 3
GfcpMtuDef = 1480
GfcpAckFast = 2
GfcpInterval = 70
GfcpOverhead = 24
GfcpDeadLink = 20
GfcpThreshInit = 2
GfcpThreshMin = 1
GfcpProbeInit = 5000 // 5s initial probe window
GfcpProbeLimit = 30000 // 30s hard probe timeout
GfcpDeadLink = 12
GfcpThreshInit = 3
GfcpThreshMin = 2
GfcpProbeInit = 7000 // 7s initial probe window
GfcpProbeLimit = 90000 // 90s hard probe timeout
)
 
type outputCallback func(
......@@ -149,8 +149,8 @@ func _itimediff(
return (int32)(later - earlier)
}
 
// GFcpSegment structure
type GFcpSegment struct {
// Segment structure
type Segment struct {
conv uint32
cmd uint8
frg uint8
......@@ -167,7 +167,7 @@ type GFcpSegment struct {
}
 
func (
GFcpSeg *GFcpSegment,
GFcpSeg *Segment,
) encode(
ptr []byte,
) []byte {
......@@ -224,10 +224,10 @@ type GFCP struct {
deadLink, incr uint32
fastresend int32
nocwnd, stream int32
sndQueue []GFcpSegment
rcvQueue []GFcpSegment
SndBuf []GFcpSegment
rcvBuf []GFcpSegment
sndQueue []Segment
rcvQueue []Segment
SndBuf []Segment
rcvBuf []Segment
acklist []ackItem
buffer []byte
reserved int
......@@ -272,7 +272,7 @@ func (
) newSegment(
size int,
) (
GFcpSeg GFcpSegment,
GFcpSeg Segment,
) {
GFcpSeg.data = KxmitBuf.Get().([]byte)[:size]
return
......@@ -281,7 +281,7 @@ func (
func (
GFcp *GFCP,
) delSegment(
GFcpSeg *GFcpSegment,
GFcpSeg *Segment,
) {
if GFcpSeg.data != nil {
KxmitBuf.Put(
......@@ -706,7 +706,7 @@ func (
func (
GFcp *GFCP,
) parseData(
newGFcpSeg GFcpSegment,
newGFcpSeg Segment,
) bool {
sn := newGFcpSeg.sn
if _itimediff(
......@@ -756,7 +756,7 @@ func (
} else {
GFcp.rcvBuf = append(
GFcp.rcvBuf,
GFcpSegment{},
Segment{},
)
copy(
GFcp.rcvBuf[insertIdx+1:],
......@@ -793,7 +793,7 @@ func (
}
 
// Input receives a (low-level) UDP packet, and determinines if
// a complete packet has processsedd (not by the FEC algorithm.)
// a full packet has been processsed (not by the FEC algorithm)
func (
GFcp *GFCP,
) Input(
......@@ -905,7 +905,7 @@ func (
sn,
GFcp.rcvNxt,
) >= 0 {
var GFcpSeg GFcpSegment
var GFcpSeg Segment
GFcpSeg.conv = conv
GFcpSeg.cmd = cmd
GFcpSeg.frg = frg
......@@ -928,7 +928,7 @@ func (
} else if cmd == GfcpCmdWask {
GFcp.probe |= GfcpAskTell
//} else if cmd == GfcpCmdWins {
// XXX(jhj) ???
// XXX(jhj) ??? FUCK YOU CHINKS
} else {
return -3
}
......@@ -1012,7 +1012,7 @@ func (
) Flush(
ackOnly bool,
) uint32 {
var GFcpSeg GFcpSegment
var GFcpSeg Segment
GFcpSeg.conv = GFcp.conv
GFcpSeg.cmd = GfcpCmdAck
GFcpSeg.wnd = GFcp.wndUnused()
......@@ -1165,71 +1165,71 @@ func (
GFcp.SndBuf,
)]
for k := range ref {
GFcpSegment := &ref[k]
Segment := &ref[k]
needsend := false
if GFcpSegment.acked == 1 {
if Segment.acked == 1 {
continue
}
if GFcpSegment.Kxmit == 0 {
if Segment.Kxmit == 0 {
needsend = true
GFcpSegment.rto = GFcp.rxRto
GFcpSegment.GFcpResendTs = current + GFcpSegment.rto
Segment.rto = GFcp.rxRto
Segment.GFcpResendTs = current + Segment.rto
} else if _itimediff(
current,
GFcpSegment.GFcpResendTs,
Segment.GFcpResendTs,
) >= 0 {
needsend = true
if GFcp.nodelay == 0 {
GFcpSegment.rto += GFcp.rxRto
Segment.rto += GFcp.rxRto
} else {
GFcpSegment.rto += GFcp.rxRto / 2
Segment.rto += GFcp.rxRto / 2
}
GFcpSegment.GFcpResendTs = current + GFcpSegment.rto
Segment.GFcpResendTs = current + Segment.rto
lost++
lostSegs++
} else if GFcpSegment.fastack >= resent {
} else if Segment.fastack >= resent {
needsend = true
GFcpSegment.fastack = 0
GFcpSegment.rto = GFcp.rxRto
GFcpSegment.GFcpResendTs = current + GFcpSegment.rto
Segment.fastack = 0
Segment.rto = GFcp.rxRto
Segment.GFcpResendTs = current + Segment.rto
change++
fastGFcpRestransmittedSegments++
} else if GFcpSegment.fastack > 0 && newSegsCount == 0 {
} else if Segment.fastack > 0 && newSegsCount == 0 {
needsend = true
GFcpSegment.fastack = 0
GFcpSegment.rto = GFcp.rxRto
GFcpSegment.GFcpResendTs = current + GFcpSegment.rto
Segment.fastack = 0
Segment.rto = GFcp.rxRto
Segment.GFcpResendTs = current + Segment.rto
change++
earlyGFcpRestransmittedSegments++
}
if needsend {
current = CurrentMs()
GFcpSegment.Kxmit++
GFcpSegment.ts = current
GFcpSegment.wnd = GFcpSeg.wnd
GFcpSegment.una = GFcpSeg.una
Segment.Kxmit++
Segment.ts = current
Segment.wnd = GFcpSeg.wnd
Segment.una = GFcpSeg.una
need := GfcpOverhead + len(
GFcpSegment.data,
Segment.data,
)
makeSpace(
need,
)
ptr = GFcpSegment.encode(
ptr = Segment.encode(
ptr,
)
copy(
ptr,
GFcpSegment.data,
Segment.data,
)
ptr = ptr[len(
GFcpSegment.data,
Segment.data,
):]
if GFcpSegment.Kxmit >= GFcp.deadLink {
if Segment.Kxmit >= GFcp.deadLink {
GFcp.state = 0xFFFFFFFF
}
}
if rto := _itimediff(
GFcpSegment.GFcpResendTs,
Segment.GFcpResendTs,
current,
); rto > 0 && rto < minrto {
minrto = rto
......@@ -1397,7 +1397,7 @@ func (
}
 
// SetMtu changes MTU size.
// Defult MTU is 1400 byes.
// Defult MTU is 1480 byes.
func (
GFcp *GFCP,
) SetMtu(
......@@ -1509,9 +1509,9 @@ func (
func (
GFcp *GFCP,
) removeFront(
q []GFcpSegment,
q []Segment,
n int,
) []GFcpSegment {
) []Segment {
if n > cap(
q,
)/2 {
......
......@@ -13,8 +13,6 @@ package gfcp // import "go.gridfinity.dev/gfcp"
import (
"crypto/rand"
"io"
hh "github.com/minio/highwayhash"
)
 
// Entropy defines a entropy source
......@@ -27,7 +25,7 @@ type Entropy interface {
 
// Nonce ...
type Nonce struct {
seed [hh.Size]byte
seed []byte
}
 
// Init ...
......@@ -54,10 +52,6 @@ func (
)
}
}
n.seed = hh.Sum(
n.seed[:],
n.seed[:],
)
copy(
nonce,
n.seed[:],
......
......@@ -490,9 +490,9 @@ func test(
ts1 = iclock() - ts1
 
names := []string{
"\n=== Test 1/3:\tConfiguration: Defaulted",
"\n=== Test 2/3:\tConfiguration: Normalize",
"\n=== Test 3/3:\tConfiguration: Optimized",
"=== Test 1/3:\tConfiguration: Default",
"=== Test 2/3:\tConfiguration: Regular",
"=== Test 3/3:\tConfiguration: Tweaked",
}
fmt.Printf(
"\n%s\n\t\tElapsed Time:\t%d ms",
......@@ -500,7 +500,7 @@ func test(
ts1,
)
fmt.Printf(
"\n\t\tAverage RTT:\t%d ms\n\t\tMaximum RTT:\t%d ms\n\n",
"\n\t\tAverage RTT:\t%d ms\n\t\tMaximum RTT:\t%d ms\n",
int(sumrtt/uint32(count)),
maxrtt,
)
......@@ -534,12 +534,12 @@ func BenchmarkFlush(
) {
})
GFcp.SndBuf = make(
[]gfcp.GFcpSegment,
1024,
[]gfcp.Segment,
2048,
)
for k := range GFcp.SndBuf {
GFcp.SndBuf[k].Kxmit = 1
GFcp.SndBuf[k].GFcpResendTs = gfcp.CurrentMs() + 10000
GFcp.SndBuf[k].GFcpResendTs = gfcp.CurrentMs() + 1000
}
b.ResetTimer()
b.ReportAllocs()
......
......@@ -47,13 +47,10 @@ func (
}
 
const (
nonceSize = 16
crcSize = 4
cryptHeaderSize = nonceSize + crcSize
// GFcpMtuLimit ...
GFcpMtuLimit = 9000
rxFECMulti = 3
acceptBacklog = 256
acceptBacklog = 1024
)
 
const (
......@@ -352,9 +349,7 @@ func (
)
}
 
if s.GFcp.WaitSnd() < int(
s.GFcp.sndWnd,
) {
if s.GFcp.WaitSnd() < int(s.GFcp.sndWnd) {
for _, b := range v {
n += len(
b)
......
......@@ -12,7 +12,7 @@ package gfcp_test
 
import (
"fmt"
"hash/fnv"
// "hash/fnv"
"io"
"log"
"net"
......@@ -25,7 +25,7 @@ import (
 
"go.gridfinity.dev/gfcp"
u "go.gridfinity.dev/leaktestfe"
"golang.org/x/crypto/pbkdf2"
// "golang.org/x/crypto/pbkdf2"
)
 
const (
......@@ -35,7 +35,7 @@ const (
portListerner = "127.0.0.1:9078"
)
 
var (
/*var (
key = []byte(
"testkey",
)
......@@ -46,7 +46,7 @@ var (
32,
fnv.New128a,
)
)
)*/
 
func init() {
go func() {
......@@ -86,14 +86,14 @@ func dialEcho() (
true,
)
sess.SetWindowSize(
1024,
1024,
1380,
1380,
)
sess.SetReadBuffer(
16 * 1024 * 1024,
64 * 1024 * 1024,
)
sess.SetWriteBuffer(
16 * 1024 * 1024,
64 * 1024 * 1024,
)
sess.SetStreamMode(
true,
......@@ -108,7 +108,7 @@ func dialEcho() (
1400,
)
sess.SetMtu(
1600,
9000,
)
sess.SetMtu(
1400,
......@@ -146,13 +146,14 @@ func dialSink() (
true,
)
sess.SetWindowSize(
1024, 1024,
1380,
1380,
)
sess.SetReadBuffer(
16 * 1024 * 1024,
64 * 1024 * 1024,
)
sess.SetWriteBuffer(
16 * 1024 * 1024,
64 * 1024 * 1024,
)
sess.SetStreamMode(
true,
......@@ -238,10 +239,10 @@ func echoServer() {
go func() {
GFcplistener := l.(*gfcp.Listener)
GFcplistener.SetReadBuffer(
4 * 1024 * 1024,
64 * 1024 * 1024,
)
GFcplistener.SetWriteBuffer(
4 * 1024 * 1024,
64 * 1024 * 1024,
)
GFcplistener.SetDSCP(
46,
......@@ -252,10 +253,10 @@ func echoServer() {
return
}
s.(*gfcp.UDPSession).SetReadBuffer(
4 * 1024 * 1024,
512 * 1024 * 1024,
)
s.(*gfcp.UDPSession).SetWriteBuffer(
4 * 1024 * 1024,
512 * 1024 * 1024,
)
go handleEcho(s.(*gfcp.UDPSession))
}
......@@ -272,10 +273,10 @@ func sinkServer() {
go func() {
GFcplistener := l.(*gfcp.Listener)
GFcplistener.SetReadBuffer(
4 * 1024 * 1024,
64 * 1024 * 1024,
)
GFcplistener.SetWriteBuffer(
4 * 1024 * 1024,
64 * 1024 * 1024,
)
GFcplistener.SetDSCP(
46,
......@@ -315,8 +316,8 @@ func handleEcho(
true,
)
conn.SetWindowSize(
4096,
4096,
8192,
8192,
)
conn.SetNoDelay(
1,
......@@ -328,7 +329,7 @@ func handleEcho(
46,
)
conn.SetMtu(
1400,
1480,
)
conn.SetACKNoDelay(
false,
......@@ -370,8 +371,8 @@ func handleSink(
true,
)
conn.SetWindowSize(
4096,
4096,
8192,
8192,
)
conn.SetNoDelay(
1,
......@@ -1036,6 +1037,9 @@ func TestSnsi(
t.Log(
gfcp.DefaultSnsi.ToSlice(),
)
t.Log(
"Resetting Snsi counters",
)
gfcp.DefaultSnsi.Reset()
t.Log(
gfcp.DefaultSnsi.ToSlice(),
......@@ -1058,17 +1062,17 @@ func TestListenerClose(
}
l.SetReadDeadline(
time.Now().Add(
time.Second,
3 * time.Second,
),
)
l.SetWriteDeadline(
time.Now().Add(
time.Second,
3 * time.Second,
),
)
l.SetDeadline(
time.Now().Add(
time.Second,
3 * time.Second,
),
)
time.Sleep(
......
......@@ -5,11 +5,9 @@ go 1.14
require (
github.com/klauspost/cpuid/v2 v2.0.3 // indirect
github.com/klauspost/reedsolomon v1.9.10
github.com/minio/highwayhash v1.0.1
github.com/pkg/errors v0.9.2-0.20201214064552-5dd12d0cfe7f
go.gridfinity.dev/leaktestfe v0.0.0-20210101234129-539e2e8b4621
go4.org v0.0.0-20201209231011-d4a079459e60
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20201224014010-6772e930b67b
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 // indirect
)
......@@ -74,8 +74,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0=
github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/pkg/errors v0.9.2-0.20201214064552-5dd12d0cfe7f h1:lJqhwddJVYAkyp72a4pwzMClI20xTwL7miDdm2W/KBM=
github.com/pkg/errors v0.9.2-0.20201214064552-5dd12d0cfe7f/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
......@@ -105,8 +103,6 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
......@@ -166,7 +162,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
......@@ -175,7 +170,6 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
......@@ -184,7 +178,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 h1:joucsQqXmyBVxViHCPFjG3hx8JzIFSaym3l3MM/Jsdg=
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment