Unverified Commit 20781608 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #49 from libp2p/fix/mem

avoid holding the message writer longer than necessary
parents a158134b 60cfa732
...@@ -52,7 +52,6 @@ type secureSession struct { ...@@ -52,7 +52,6 @@ type secureSession struct {
msgio.ReadWriteCloser msgio.ReadWriteCloser
insecure net.Conn insecure net.Conn
insecureM msgio.ReadWriter
localKey ci.PrivKey localKey ci.PrivKey
localPeer peer.ID localPeer peer.ID
...@@ -89,7 +88,6 @@ func newSecureSession(ctx context.Context, local peer.ID, key ci.PrivKey, insecu ...@@ -89,7 +88,6 @@ func newSecureSession(ctx context.Context, local peer.ID, key ci.PrivKey, insecu
} }
s.insecure = insecure s.insecure = insecure
s.insecureM = msgio.NewReadWriter(insecure)
s.remotePeer = remotePeer s.remotePeer = remotePeer
handshakeCtx, cancel := context.WithTimeout(ctx, HandshakeTimeout) // remove handshakeCtx, cancel := context.WithTimeout(ctx, HandshakeTimeout) // remove
...@@ -136,6 +134,7 @@ func (s *secureSession) runHandshake(ctx context.Context) error { ...@@ -136,6 +134,7 @@ func (s *secureSession) runHandshake(ctx context.Context) error {
} }
func (s *secureSession) runHandshakeSync() error { func (s *secureSession) runHandshakeSync() error {
insecureM := msgio.NewReadWriter(s.insecure)
// ============================================================================= // =============================================================================
// step 1. Propose -- propose cipher suite + send pubkeys + nonce // step 1. Propose -- propose cipher suite + send pubkeys + nonce
...@@ -170,11 +169,11 @@ func (s *secureSession) runHandshakeSync() error { ...@@ -170,11 +169,11 @@ func (s *secureSession) runHandshakeSync() error {
} }
// Send Propose packet and Receive their Propose packet // Send Propose packet and Receive their Propose packet
proposeInBytes, err := readWriteMsg(s.insecureM, proposeOutBytes) proposeInBytes, err := readWriteMsg(insecureM, proposeOutBytes)
if err != nil { if err != nil {
return err return err
} }
defer s.insecureM.ReleaseMsg(proposeInBytes) defer insecureM.ReleaseMsg(proposeInBytes)
// Parse their propose packet // Parse their propose packet
proposeIn := new(pb.Propose) proposeIn := new(pb.Propose)
...@@ -281,11 +280,11 @@ func (s *secureSession) runHandshakeSync() error { ...@@ -281,11 +280,11 @@ func (s *secureSession) runHandshakeSync() error {
} }
// Send Exchange packet and receive their Exchange packet // Send Exchange packet and receive their Exchange packet
exchangeInBytes, err := readWriteMsg(s.insecureM, exchangeOutBytes) exchangeInBytes, err := readWriteMsg(insecureM, exchangeOutBytes)
if err != nil { if err != nil {
return err return err
} }
defer s.insecureM.ReleaseMsg(exchangeInBytes) defer insecureM.ReleaseMsg(exchangeInBytes)
// Parse their Exchange packet. // Parse their Exchange packet.
exchangeIn := new(pb.Exchange) exchangeIn := new(pb.Exchange)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment