From b94f25e5aea969e46539acfcf0ec803f05513cf5 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Sun, 11 Nov 2018 11:45:37 -0800 Subject: [PATCH] Client lport disconn/reconn works, somewhat.. --- hkexnet/hkexnet.go | 8 +------- hkexnet/hkextun.go | 4 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/hkexnet/hkexnet.go b/hkexnet/hkexnet.go index 270ec11..18ded1f 100644 --- a/hkexnet/hkexnet.go +++ b/hkexnet/hkexnet.go @@ -816,7 +816,6 @@ func (hc Conn) Read(b []byte) (n int, err error) { // server side tunnel setup in response to client lport := binary.BigEndian.Uint16(payloadBytes[0:2]) rport := binary.BigEndian.Uint16(payloadBytes[2:4]) - logger.LogDebug(fmt.Sprintf("mapkey is %d", rport)) if _, ok := (*hc.tuns)[rport]; !ok { // tunnel first-time open logger.LogDebug(fmt.Sprintf("[Server] Got Initial CSOTunSetup [%d:%d]", lport, rport)) @@ -828,7 +827,6 @@ func (hc Conn) Read(b []byte) (n int, err error) { } else if ctrlStatOp == CSOTunSetupAck { lport := binary.BigEndian.Uint16(payloadBytes[0:2]) rport := binary.BigEndian.Uint16(payloadBytes[2:4]) - logger.LogDebug(fmt.Sprintf("mapkey is %d\n", rport)) if _, ok := (*hc.tuns)[rport]; !ok { // tunnel first-time open logger.LogDebug(fmt.Sprintf("[Client] Got Initial CSOTunSetupAck [%d:%d]", lport, rport)) @@ -843,27 +841,23 @@ func (hc Conn) Read(b []byte) (n int, err error) { // for client-side on lport. lport := binary.BigEndian.Uint16(payloadBytes[0:2]) rport := binary.BigEndian.Uint16(payloadBytes[2:4]) - logger.LogDebug(fmt.Sprintf("mapkey is %d\n", rport)) logger.LogDebug(fmt.Sprintf("[Client] Got CSOTunRefused [%d:%d]", lport, rport)) - (*hc.tuns)[rport].Ctl <- 'r' // client should NOT Listen() + //(*hc.tuns)[rport].Ctl <- 'r' // client should NOT Listen() } else if ctrlStatOp == CSOTunDisconn { // server side's rport has disconnected (server lost) lport := binary.BigEndian.Uint16(payloadBytes[0:2]) rport := binary.BigEndian.Uint16(payloadBytes[2:4]) - logger.LogDebug(fmt.Sprintf("mapkey is %d\n", rport)) logger.LogDebug(fmt.Sprintf("[Client] Got CSOTunDisconn [%d:%d]", lport, rport)) (*hc.tuns)[rport].Ctl <- 'x' // client should hangup on current lport conn } else if ctrlStatOp == CSOTunHangup { // client side's lport has hung up lport := binary.BigEndian.Uint16(payloadBytes[0:2]) rport := binary.BigEndian.Uint16(payloadBytes[2:4]) - logger.LogDebug(fmt.Sprintf("mapkey is %d\n", rport)) logger.LogDebug(fmt.Sprintf("[Server] Got CSOTunHangup [%d:%d]", lport, rport)) (*hc.tuns)[rport].Ctl <- 'h' // server should hang up on currently-dialled rport } else if ctrlStatOp == CSOTunData { lport := binary.BigEndian.Uint16(payloadBytes[0:2]) rport := binary.BigEndian.Uint16(payloadBytes[2:4]) - logger.LogDebug(fmt.Sprintf("mapkey is %d\n", rport)) //fmt.Printf("[Got CSOTunData: [lport %d:rport %d] data:%v\n", lport, rport, payloadBytes[4:]) if _, ok := (*hc.tuns)[rport]; ok { logger.LogDebug(fmt.Sprintf("[Writing data to rport [%d:%d]", lport, rport)) diff --git a/hkexnet/hkextun.go b/hkexnet/hkextun.go index 1947ce8..f5dcc57 100644 --- a/hkexnet/hkextun.go +++ b/hkexnet/hkextun.go @@ -173,6 +173,7 @@ func (hc *Conn) StartServerTunnel(lport, rport uint16) { weAreDialled := false for cmd := range t.Ctl { var c net.Conn + logger.LogDebug(fmt.Sprintf("[ServerTun] got Ctl '%c'. weAreDialled: %v", cmd, weAreDialled)) if cmd == 'd' && !weAreDialled { logger.LogDebug("[ServerTun] dialling...") c, err = net.Dial("tcp", fmt.Sprintf(":%d", rport)) @@ -253,8 +254,7 @@ func (hc *Conn) StartServerTunnel(lport, rport uint16) { } } else if cmd == 'h' { // client side has hung up - logger.LogDebug(fmt.Sprintf("[ServerTun] Client hung up: hanging up on rport %v", t)) - weAreDialled = false + logger.LogDebug(fmt.Sprintf("[ServerTun] Client hung up on rport %v", t)) } } // t.Ctl read loop logger.LogDebug("[ServerTun] Tunnel exiting t.Ctl read loop - channel closed??")