udp #5

Merged
JakeHillion merged 16 commits from udp into develop 2020-11-28 16:53:00 +00:00
3 changed files with 54 additions and 2 deletions
Showing only changes of commit cc9d036f43 - Show all commits

View File

@ -85,13 +85,23 @@ func buildTcp(p *proxy.Proxy, peer Peer) error {
}
func buildUdp(p *proxy.Proxy, peer Peer) error {
var c udp.Congestion
switch peer.Congestion {
case "None":
c = congestion.NewNone()
default:
fallthrough
case "NewReno":
c = congestion.NewNewReno()
}
if peer.RemoteHost != "" {
f, err := udp.InitiateFlow(
fmt.Sprintf("%s:", peer.LocalHost),
fmt.Sprintf("%s:%d", peer.RemoteHost, peer.RemotePort),
UselessMac{},
UselessMac{},
congestion.NewNewReno(),
c,
time.Duration(peer.KeepAlive)*time.Second,
)
@ -110,7 +120,7 @@ func buildUdp(p *proxy.Proxy, peer Peer) error {
fmt.Sprintf("%s:%d", peer.LocalHost, peer.LocalPort),
UselessMac{},
UselessMac{},
congestion.NewNewReno(),
c,
)
if err != nil {
return err

View File

@ -24,6 +24,8 @@ type Peer struct {
RemoteHost string `validate:"required_with=RemotePort,omitempty,fqdn|ip"`
RemotePort uint `validate:"required_with=RemoteHost,omitempty,max=65535"`
Congestion string `validate:"oneof=NewReno None"`
KeepAlive uint
Timeout uint
RetryWait uint

40
udp/congestion/none.go Normal file
View File

@ -0,0 +1,40 @@
package congestion
import "time"
type None struct {
sequence chan uint32
}
func NewNone() *None {
c := None{
sequence: make(chan uint32),
}
go func() {
var s uint32
for {
if s == 0 {
continue
}
c.sequence <- s
s++
}
}()
return &c
}
func (c *None) Sequence() uint32 {
return <-c.sequence
}
func (c *None) ReceivedPacket(seq uint32) {}
func (c *None) ReceivedAck(uint32) {}
func (c *None) NextAck() uint32 { return 0 }
func (c *None) ReceivedNack(uint32) {}
func (c *None) NextNack() uint32 { return 0 }
func (c *None) AwaitEarlyUpdate(keepalive time.Duration) {
select {}
}