Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15)

Unified Diff: src/pkg/exp/ssh/transport.go

Issue 5132041: code review 5132041: exp/ssh: move common code to common.go (Closed)
Patch Set: diff -r 41d5abd18c57 https://go.googlecode.com/hg/ Created 13 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/pkg/exp/ssh/server.go ('K') | « src/pkg/exp/ssh/server.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/exp/ssh/transport.go
===================================================================
--- a/src/pkg/exp/ssh/transport.go
+++ b/src/pkg/exp/ssh/transport.go
@@ -10,10 +10,13 @@
"crypto/aes"
"crypto/cipher"
"crypto/hmac"
+ "crypto/rand"
"crypto/subtle"
"hash"
"io"
+ "net"
"os"
+ "sync"
)
const (
@@ -29,7 +32,8 @@
macAlgo string
compressionAlgo string
- Close func() os.Error
+ Close func() os.Error
+ RemoteAddr func() net.Addr
}
// reader represents the incoming connection state.
@@ -40,6 +44,7 @@
// writer represnts the outgoing connection state.
type writer struct {
+ *sync.Mutex // protects writer.Writer from concurrent writes
*bufio.Writer
paddingMultiple int
rand io.Reader
@@ -126,6 +131,9 @@
// Encrypt and send a packet of data to the remote peer.
func (w *writer) writePacket(packet []byte) os.Error {
+ w.Mutex.Lock()
+ defer w.Mutex.Unlock()
+
paddingLength := paddingMultiple - (5+len(packet))%paddingMultiple
if paddingLength < 4 {
paddingLength += paddingMultiple
@@ -190,6 +198,31 @@
return err
}
+// Send a message to the remote peer
+func (t *transport) sendMessage(typ uint8, msg interface{}) os.Error {
+ packet := marshal(typ, msg)
+ return t.writePacket(packet)
+}
+
+func newTransport(conn net.Conn) *transport {
+ return &transport{
+ reader: reader{
+ Reader: bufio.NewReader(conn),
+ },
+ writer: writer{
+ Writer: bufio.NewWriter(conn),
+ rand: rand.Reader,
+ Mutex: new(sync.Mutex),
+ },
+ Close: func() os.Error {
+ return conn.Close()
+ },
+ RemoteAddr: func() net.Addr {
+ return conn.RemoteAddr()
+ },
+ }
+}
+
type direction struct {
ivTag []byte
keyTag []byte
« src/pkg/exp/ssh/server.go ('K') | « src/pkg/exp/ssh/server.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b