This commit is contained in:
Neil Alexander 2018-05-27 22:13:37 +01:00
parent 707e23d392
commit 4c115de633
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
9 changed files with 363 additions and 108 deletions

View file

@ -16,6 +16,7 @@ import "errors"
import "sync"
import "fmt"
import "bufio"
import "golang.org/x/net/proxy"
const tcp_msgSize = 2048 + 65535 // TODO figure out what makes sense
@ -42,6 +43,32 @@ type tcpInfo struct {
remoteAddr string
}
func (iface *tcpInterface) getAddr() *net.TCPAddr {
return iface.serv.Addr().(*net.TCPAddr)
}
func (iface *tcpInterface) connect(addr string) {
iface.call(addr)
}
func (iface *tcpInterface) connectSOCKS(socksaddr, peeraddr string) {
go func() {
dialer, err := proxy.SOCKS5("tcp", socksaddr, nil, proxy.Direct)
if err == nil {
conn, err := dialer.Dial("tcp", peeraddr)
if err == nil {
iface.callWithConn(&wrappedConn{
c: conn,
raddr: &wrappedAddr{
network: "tcp",
addr: peeraddr,
},
})
}
}
}()
}
func (iface *tcpInterface) init(core *Core, addr string) (err error) {
iface.core = core
@ -51,7 +78,8 @@ func (iface *tcpInterface) init(core *Core, addr string) (err error) {
iface.conns = make(map[tcpInfo](chan struct{}))
go iface.listener()
}
return
return err
}
func (iface *tcpInterface) listener() {
@ -274,12 +302,14 @@ func (iface *tcpInterface) reader(sock net.Conn, in func([]byte)) {
sock.SetReadDeadline(timeout)
n, err := sock.Read(bs[len(frag):])
if err != nil || n == 0 {
// iface.core.log.Println(err)
break
}
frag = bs[:len(frag)+n]
for {
msg, ok, err := tcp_chop_msg(&frag)
if err != nil {
// iface.core.log.Println(err)
return
}
if !ok {