From e75ed159f6c99dfe313a62349045cd71e3019a9d Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Sun, 28 Oct 2018 21:46:29 -0700 Subject: [PATCH] two-way tunnel traffic working. Hangup/re-dial on server side needs work --- hkexnet/hkexnet.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hkexnet/hkexnet.go b/hkexnet/hkexnet.go index 992df53..bad08db 100644 --- a/hkexnet/hkexnet.go +++ b/hkexnet/hkexnet.go @@ -798,12 +798,19 @@ func (hc Conn) Read(b []byte) (n int, err error) { lport := binary.BigEndian.Uint16(payloadBytes) rport := binary.BigEndian.Uint16(payloadBytes[2:4]) fmt.Printf("[Got CSOTunData: [lport %d:rport %d] data:%v\n", lport, rport, payloadBytes[4:]) - hc.tuns[rport] <- payloadBytes[4:] + if hc.tuns[rport] == nil { + fmt.Printf("[Invalid rport:%d]\n", rport) + } else { + hc.tuns[rport] <- payloadBytes[4:] + } + fmt.Printf("[Done stuffing hc.tuns[rport]\n") } else if ctrlStatOp == CSOTunClose { lport := binary.BigEndian.Uint16(payloadBytes) rport := binary.BigEndian.Uint16(payloadBytes[2:4]) fmt.Printf("[Got CSOTunClose: [lport %d:rport %d]\n", lport, rport) - hc.tuns[rport] = nil + if hc.tuns[rport] != nil { + close(hc.tuns[rport]) + } } else { hc.dBuf.Write(payloadBytes) //log.Printf("hc.dBuf: %s\n", hex.Dump(hc.dBuf.Bytes()))