mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 14:11:37 +00:00
Make changes based on review comments
This commit is contained in:
parent
57eb6eaeb0
commit
917ca6c1c5
@ -87,7 +87,7 @@ func Difference(a, b []string) []string {
|
|||||||
mb[x] = true
|
mb[x] = true
|
||||||
}
|
}
|
||||||
for _, x := range a {
|
for _, x := range a {
|
||||||
if _, ok := mb[x]; !ok {
|
if !mb[x] {
|
||||||
ab = append(ab, x)
|
ab = append(ab, x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -676,7 +676,7 @@ func (a *admin) getData_getPeers() []admin_nodeInfo {
|
|||||||
{"bytes_sent", atomic.LoadUint64(&p.bytesSent)},
|
{"bytes_sent", atomic.LoadUint64(&p.bytesSent)},
|
||||||
{"bytes_recvd", atomic.LoadUint64(&p.bytesRecvd)},
|
{"bytes_recvd", atomic.LoadUint64(&p.bytesRecvd)},
|
||||||
{"proto", p.intf.info.linkType},
|
{"proto", p.intf.info.linkType},
|
||||||
{"endpoint", p.intf.info.remote},
|
{"endpoint", p.intf.name},
|
||||||
{"box_pub_key", hex.EncodeToString(p.box[:])},
|
{"box_pub_key", hex.EncodeToString(p.box[:])},
|
||||||
}
|
}
|
||||||
peerInfos = append(peerInfos, info)
|
peerInfos = append(peerInfos, info)
|
||||||
|
@ -54,8 +54,7 @@ func (a *awdl) init(l *link) error {
|
|||||||
a.mutex.Unlock()
|
a.mutex.Unlock()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for e := range a.reconfigure {
|
||||||
e := <-a.reconfigure
|
|
||||||
e <- nil
|
e <- nil
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -105,7 +105,7 @@ func (l *link) call(uri string, sintf string) error {
|
|||||||
case "tcp":
|
case "tcp":
|
||||||
l.tcp.call(u.Host, nil, sintf)
|
l.tcp.call(u.Host, nil, sintf)
|
||||||
case "socks":
|
case "socks":
|
||||||
l.tcp.call(pathtokens[0], &u.Host, sintf)
|
l.tcp.call(pathtokens[0], u.Host, sintf)
|
||||||
default:
|
default:
|
||||||
return errors.New("unknown call scheme: " + u.Scheme)
|
return errors.New("unknown call scheme: " + u.Scheme)
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,13 @@ func (t *tcp) listener(l *tcpListener, listenaddr string) {
|
|||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
// And here we go!
|
// And here we go!
|
||||||
accepted := make(chan bool)
|
accepted := make(chan bool)
|
||||||
defer l.listener.Close()
|
defer func() {
|
||||||
|
t.link.core.log.Infoln("Stopping TCP listener on:", l.listener.Addr().String())
|
||||||
|
l.listener.Close()
|
||||||
|
t.mutex.Lock()
|
||||||
|
delete(t.listeners, listenaddr)
|
||||||
|
t.mutex.Unlock()
|
||||||
|
}()
|
||||||
t.link.core.log.Infoln("Listening for TCP on:", l.listener.Addr().String())
|
t.link.core.log.Infoln("Listening for TCP on:", l.listener.Addr().String())
|
||||||
for {
|
for {
|
||||||
var sock net.Conn
|
var sock net.Conn
|
||||||
@ -178,13 +184,8 @@ func (t *tcp) listener(l *tcpListener, listenaddr string) {
|
|||||||
t.link.core.log.Errorln("Failed to accept connection:", err)
|
t.link.core.log.Errorln("Failed to accept connection:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go t.handler(sock, true)
|
go t.handler(sock, true, nil)
|
||||||
case <-l.stop:
|
case <-l.stop:
|
||||||
t.link.core.log.Infoln("Stopping TCP listener on:", l.listener.Addr().String())
|
|
||||||
l.listener.Close()
|
|
||||||
t.mutex.Lock()
|
|
||||||
delete(t.listeners, listenaddr)
|
|
||||||
t.mutex.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,8 +231,12 @@ func (t *tcp) call(saddr string, options interface{}, sintf string) {
|
|||||||
if sintf != "" {
|
if sintf != "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
dialerdst, er := net.ResolveTCPAddr("tcp", socksaddr)
|
||||||
|
if er != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
var dialer proxy.Dialer
|
var dialer proxy.Dialer
|
||||||
dialer, err = proxy.SOCKS5("tcp", socksaddr, nil, proxy.Direct)
|
dialer, err = proxy.SOCKS5("tcp", dialerdst.String(), nil, proxy.Direct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -246,6 +251,7 @@ func (t *tcp) call(saddr string, options interface{}, sintf string) {
|
|||||||
addr: saddr,
|
addr: saddr,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
t.handler(conn, false, dialerdst.String())
|
||||||
} else {
|
} else {
|
||||||
dialer := net.Dialer{
|
dialer := net.Dialer{
|
||||||
Control: t.tcpContext,
|
Control: t.tcpContext,
|
||||||
@ -302,12 +308,12 @@ func (t *tcp) call(saddr string, options interface{}, sintf string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
t.handler(conn, false, nil)
|
||||||
}
|
}
|
||||||
t.handler(conn, false)
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tcp) handler(sock net.Conn, incoming bool) {
|
func (t *tcp) handler(sock net.Conn, incoming bool, options interface{}) {
|
||||||
defer sock.Close()
|
defer sock.Close()
|
||||||
t.setExtraOptions(sock)
|
t.setExtraOptions(sock)
|
||||||
stream := stream{}
|
stream := stream{}
|
||||||
@ -315,8 +321,16 @@ func (t *tcp) handler(sock net.Conn, incoming bool) {
|
|||||||
local, _, _ := net.SplitHostPort(sock.LocalAddr().String())
|
local, _, _ := net.SplitHostPort(sock.LocalAddr().String())
|
||||||
remote, _, _ := net.SplitHostPort(sock.RemoteAddr().String())
|
remote, _, _ := net.SplitHostPort(sock.RemoteAddr().String())
|
||||||
remotelinklocal := net.ParseIP(remote).IsLinkLocalUnicast()
|
remotelinklocal := net.ParseIP(remote).IsLinkLocalUnicast()
|
||||||
name := "tcp://" + sock.RemoteAddr().String()
|
var name string
|
||||||
link, err := t.link.core.link.create(&stream, name, "tcp", local, remote, incoming, remotelinklocal)
|
var proto string
|
||||||
|
if socksaddr, issocks := options.(string); issocks {
|
||||||
|
name = "socks://" + socksaddr + "/" + sock.RemoteAddr().String()
|
||||||
|
proto = "socks"
|
||||||
|
} else {
|
||||||
|
name = "tcp://" + sock.RemoteAddr().String()
|
||||||
|
proto = "tcp"
|
||||||
|
}
|
||||||
|
link, err := t.link.core.link.create(&stream, name, proto, local, remote, incoming, remotelinklocal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.link.core.log.Println(err)
|
t.link.core.log.Println(err)
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user