udp #5

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

View File

@ -6,6 +6,8 @@ import (
"mpbl3p/tcp" "mpbl3p/tcp"
"mpbl3p/tun" "mpbl3p/tun"
"mpbl3p/udp" "mpbl3p/udp"
"mpbl3p/udp/congestion"
"time"
) )
// TODO: Delete this code as soon as an alternative is available // TODO: Delete this code as soon as an alternative is available
@ -87,6 +89,10 @@ func buildUdp(p *proxy.Proxy, peer Peer) error {
f, err := udp.InitiateFlow( f, err := udp.InitiateFlow(
fmt.Sprintf("%s:", peer.LocalHost), fmt.Sprintf("%s:", peer.LocalHost),
fmt.Sprintf("%s:%d", peer.RemoteHost, peer.RemotePort), fmt.Sprintf("%s:%d", peer.RemoteHost, peer.RemotePort),
UselessMac{},
UselessMac{},
congestion.NewNewReno(),
time.Duration(peer.KeepAlive)*time.Second,
) )
if err != nil { if err != nil {
@ -99,7 +105,13 @@ func buildUdp(p *proxy.Proxy, peer Peer) error {
return nil return nil
} }
err := udp.NewListener(p, fmt.Sprintf("%s:%d", peer.LocalHost, peer.LocalPort), UselessMac{}) err := udp.NewListener(
p,
fmt.Sprintf("%s:%d", peer.LocalHost, peer.LocalPort),
UselessMac{},
UselessMac{},
congestion.NewNewReno(),
)
if err != nil { if err != nil {
return err return err
} }

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"log" "log"
"mpbl3p/config"
"mpbl3p/proxy" "mpbl3p/proxy"
"mpbl3p/shared" "mpbl3p/shared"
"net" "net"
@ -44,6 +43,8 @@ type Flow struct {
isAlive bool isAlive bool
congestion Congestion congestion Congestion
v proxy.MacVerifier
inboundDatagrams chan []byte inboundDatagrams chan []byte
} }
@ -53,6 +54,7 @@ func (f Flow) String() string {
func InitiateFlow( func InitiateFlow(
local, remote string, local, remote string,
v proxy.MacVerifier,
g proxy.MacGenerator, g proxy.MacGenerator,
c Congestion, c Congestion,
keepalive time.Duration, keepalive time.Duration,
@ -60,7 +62,7 @@ func InitiateFlow(
f := InitiatedFlow{ f := InitiatedFlow{
Local: local, Local: local,
Remote: remote, Remote: remote,
Flow: newFlow(c), Flow: newFlow(c, v),
g: g, g: g,
keepalive: keepalive, keepalive: keepalive,
} }
@ -68,10 +70,11 @@ func InitiateFlow(
return &f, nil return &f, nil
} }
func newFlow(c Congestion) Flow { func newFlow(c Congestion, v proxy.MacVerifier) Flow {
return Flow{ return Flow{
inboundDatagrams: make(chan []byte), inboundDatagrams: make(chan []byte),
congestion: c, congestion: c,
v: v,
} }
} }
@ -196,8 +199,8 @@ func (f *Flow) Produce(v proxy.MacVerifier) (proxy.Packet, error) {
func (f *Flow) handleDatagram(p []byte) { func (f *Flow) handleDatagram(p []byte) {
// TODO: Fix with security // TODO: Fix with security
// 12 bytes for header + the MAC + a timestamp // 12 bytes for header + the MAC + a timestamp
if len(p) == 12+(config.UselessMac{}).CodeLength()+8 { if len(p) == 12+f.v.CodeLength()+8 {
b, err := proxy.StripMac(<-f.inboundDatagrams, config.UselessMac{}) b, err := proxy.StripMac(<-f.inboundDatagrams, f.v)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return return

View File

@ -60,7 +60,7 @@ func NewListener(p *proxy.Proxy, local string, v proxy.MacVerifier, g proxy.MacG
continue continue
} }
f := newFlow(c) f := newFlow(c, v)
f.writer = pconn f.writer = pconn
f.raddr = *addr f.raddr = *addr