udp #5

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

View File

@ -7,6 +7,7 @@ import (
type Packet interface {
Marshal() []byte
Contents() []byte
}
type SimplePacket struct {
@ -44,6 +45,10 @@ func (p SimplePacket) Marshal() []byte {
return append(p.Data, footer...)
}
func (p SimplePacket) Contents() []byte {
return p.Data
}
func AppendMac(b []byte, g MacGenerator) []byte {
mac := g.Generate(b)
b = append(b, mac...)

View File

@ -79,7 +79,7 @@ func (t *SourceSink) Sink(packet proxy.Packet) error {
t.upMu.Unlock()
}
_, err := t.tun.Write(packet.Marshal())
_, err := t.tun.Write(packet.Contents())
if err != nil {
switch err.(type) {
case *os.PathError:

View File

@ -12,7 +12,7 @@ import (
)
type PacketWriter interface {
WriteToUDP(b []byte, addr *net.UDPAddr) (int, error)
Write(b []byte) (int, error)
LocalAddr() net.Addr
}
@ -162,7 +162,7 @@ func (f *Flow) Consume(pp proxy.Packet, g proxy.MacGenerator) error {
b := p.Marshal()
b = proxy.AppendMac(b, g)
_, err := f.writer.WriteToUDP(b, &f.raddr)
_, err := f.writer.Write(b)
return err
}

View File

@ -35,3 +35,7 @@ func (p Packet) Marshal() []byte {
return append(header, data...)
}
func (p Packet) Contents() []byte {
return p.data.Contents()
}