mirror of https://gogs.blitter.com/RLabs/xs
Moved mutex into hkexsh.Conn (hkexnet)
This commit is contained in:
parent
4d85236d16
commit
6d606bbbd9
|
@ -52,6 +52,7 @@ type Conn struct {
|
||||||
WinCh chan WinSize
|
WinCh chan WinSize
|
||||||
Rows uint16
|
Rows uint16
|
||||||
Cols uint16
|
Cols uint16
|
||||||
|
Rwmut sync.Mutex
|
||||||
r cipher.Stream //read cipherStream
|
r cipher.Stream //read cipherStream
|
||||||
rm hash.Hash
|
rm hash.Hash
|
||||||
w cipher.Stream //write cipherStream
|
w cipher.Stream //write cipherStream
|
||||||
|
|
|
@ -194,7 +194,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
m := &sync.Mutex{}
|
//m := &sync.Mutex{}
|
||||||
|
|
||||||
if isInteractive {
|
if isInteractive {
|
||||||
// Handle pty resizes (notify server side)
|
// Handle pty resizes (notify server side)
|
||||||
|
@ -213,9 +213,9 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
termSzPacket := fmt.Sprintf("%d %d", rows, cols)
|
termSzPacket := fmt.Sprintf("%d %d", rows, cols)
|
||||||
m.Lock()
|
conn.Rwmut.Lock()
|
||||||
conn.WritePacket([]byte(termSzPacket), hkexsh.CSOTermSize)
|
conn.WritePacket([]byte(termSzPacket), hkexsh.CSOTermSize)
|
||||||
m.Unlock()
|
conn.Rwmut.Unlock()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ch <- syscall.SIGWINCH // Initial resize.
|
ch <- syscall.SIGWINCH // Initial resize.
|
||||||
|
@ -226,13 +226,13 @@ func main() {
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for {
|
for {
|
||||||
m.Lock()
|
|
||||||
chaff := make([]byte, rand.Intn(512))
|
chaff := make([]byte, rand.Intn(512))
|
||||||
nextDurationMin := 1000 //ms
|
nextDurationMin := 1000 //ms
|
||||||
nextDuration := rand.Intn(5000-nextDurationMin) + nextDurationMin
|
nextDuration := rand.Intn(5000-nextDurationMin) + nextDurationMin
|
||||||
_, _ = rand.Read(chaff)
|
_, _ = rand.Read(chaff)
|
||||||
|
conn.Rwmut.Lock()
|
||||||
conn.WritePacket(chaff, hkexsh.CSOChaff)
|
conn.WritePacket(chaff, hkexsh.CSOChaff)
|
||||||
m.Unlock()
|
conn.Rwmut.Unlock()
|
||||||
time.Sleep(time.Duration(nextDuration) * time.Millisecond)
|
time.Sleep(time.Duration(nextDuration) * time.Millisecond)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -245,9 +245,9 @@ func main() {
|
||||||
// io.Copy() expects EOF so this will
|
// io.Copy() expects EOF so this will
|
||||||
// exit with outerr == nil
|
// exit with outerr == nil
|
||||||
//!_, outerr := io.Copy(conn, os.Stdin)
|
//!_, outerr := io.Copy(conn, os.Stdin)
|
||||||
_, outerr := func(m *sync.Mutex, conn *hkexsh.Conn, r io.Reader) (w int64, e error) {
|
_, outerr := func(conn *hkexsh.Conn, r io.Reader) (w int64, e error) {
|
||||||
return hkexsh.Copy(m, conn, r)
|
return hkexsh.Copy(&conn.Rwmut, conn, r)
|
||||||
}(m, conn, os.Stdin)
|
}(conn, os.Stdin)
|
||||||
|
|
||||||
if outerr != nil {
|
if outerr != nil {
|
||||||
log.Println(outerr)
|
log.Println(outerr)
|
||||||
|
|
Loading…
Reference in New Issue