This commit is contained in:
parent
d65e8d3571
commit
96b57f65ca
@ -6,6 +6,8 @@ import (
|
||||
"mpbl3p/tcp"
|
||||
"mpbl3p/tun"
|
||||
"mpbl3p/udp"
|
||||
"mpbl3p/udp/congestion"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 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(
|
||||
fmt.Sprintf("%s:", peer.LocalHost),
|
||||
fmt.Sprintf("%s:%d", peer.RemoteHost, peer.RemotePort),
|
||||
UselessMac{},
|
||||
UselessMac{},
|
||||
congestion.NewNewReno(),
|
||||
time.Duration(peer.KeepAlive)*time.Second,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@ -99,7 +105,13 @@ func buildUdp(p *proxy.Proxy, peer Peer) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
13
udp/flow.go
13
udp/flow.go
@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"mpbl3p/config"
|
||||
"mpbl3p/proxy"
|
||||
"mpbl3p/shared"
|
||||
"net"
|
||||
@ -44,6 +43,8 @@ type Flow struct {
|
||||
isAlive bool
|
||||
congestion Congestion
|
||||
|
||||
v proxy.MacVerifier
|
||||
|
||||
inboundDatagrams chan []byte
|
||||
}
|
||||
|
||||
@ -53,6 +54,7 @@ func (f Flow) String() string {
|
||||
|
||||
func InitiateFlow(
|
||||
local, remote string,
|
||||
v proxy.MacVerifier,
|
||||
g proxy.MacGenerator,
|
||||
c Congestion,
|
||||
keepalive time.Duration,
|
||||
@ -60,7 +62,7 @@ func InitiateFlow(
|
||||
f := InitiatedFlow{
|
||||
Local: local,
|
||||
Remote: remote,
|
||||
Flow: newFlow(c),
|
||||
Flow: newFlow(c, v),
|
||||
g: g,
|
||||
keepalive: keepalive,
|
||||
}
|
||||
@ -68,10 +70,11 @@ func InitiateFlow(
|
||||
return &f, nil
|
||||
}
|
||||
|
||||
func newFlow(c Congestion) Flow {
|
||||
func newFlow(c Congestion, v proxy.MacVerifier) Flow {
|
||||
return Flow{
|
||||
inboundDatagrams: make(chan []byte),
|
||||
congestion: c,
|
||||
v: v,
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,8 +199,8 @@ func (f *Flow) Produce(v proxy.MacVerifier) (proxy.Packet, error) {
|
||||
func (f *Flow) handleDatagram(p []byte) {
|
||||
// TODO: Fix with security
|
||||
// 12 bytes for header + the MAC + a timestamp
|
||||
if len(p) == 12+(config.UselessMac{}).CodeLength()+8 {
|
||||
b, err := proxy.StripMac(<-f.inboundDatagrams, config.UselessMac{})
|
||||
if len(p) == 12+f.v.CodeLength()+8 {
|
||||
b, err := proxy.StripMac(<-f.inboundDatagrams, f.v)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
|
@ -60,7 +60,7 @@ func NewListener(p *proxy.Proxy, local string, v proxy.MacVerifier, g proxy.MacG
|
||||
continue
|
||||
}
|
||||
|
||||
f := newFlow(c)
|
||||
f := newFlow(c, v)
|
||||
|
||||
f.writer = pconn
|
||||
f.raddr = *addr
|
||||
|
Loading…
Reference in New Issue
Block a user