interface naming and write deadline
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jake Hillion 2020-11-02 17:24:15 +00:00
parent fda177d8a8
commit 22b5cc74e1
4 changed files with 17 additions and 5 deletions

View File

@ -26,7 +26,11 @@ func (c Configuration) Build() (*proxy.Proxy, error) {
p := proxy.NewProxy(0)
p.Generator = UselessMac{}
ss, err := tun.NewTun("nc%d", 1500)
if c.Host.InterfaceName == "" {
c.Host.InterfaceName = "nc%d"
}
ss, err := tun.NewTun(c.Host.InterfaceName, 1500)
if err != nil {
return nil, err
}

View File

@ -10,7 +10,8 @@ type Configuration struct {
}
type Host struct {
PrivateKey string `validate:"required"`
PrivateKey string `validate:"required"`
InterfaceName string
}
type Peer struct {

View File

@ -8,6 +8,7 @@ import (
"mpbl3p/shared"
"net"
"sync"
"time"
)
var ErrNotEnoughBytes = errors.New("not enough bytes")
@ -15,6 +16,7 @@ var ErrNotEnoughBytes = errors.New("not enough bytes")
type Conn interface {
Read(b []byte) (n int, err error)
Write(b []byte) (n int, err error)
SetWriteDeadline(time.Time) error
}
type InitiatedFlow struct {
@ -97,7 +99,11 @@ func (f *Flow) consumeMarshalled(data []byte) error {
binary.LittleEndian.PutUint32(prefixedData, uint32(len(data)))
copy(prefixedData[4:], data)
_, err := f.conn.Write(prefixedData)
err := f.conn.SetWriteDeadline(time.Now().Add(5*time.Second))
if err != nil {
return err
}
_, err = f.conn.Write(prefixedData)
return err
}

View File

@ -24,9 +24,10 @@ func NewListener(p *proxy.Proxy, local string, v proxy.MacVerifier) error {
panic(err)
}
fmt.Printf("received new connection `%v`\n", conn)
f := Flow{conn: conn, isAlive: true}
fmt.Printf("received new connection: %v\n", f)
p.AddConsumer(&f)
p.AddProducer(&f, v)
}