diff options
author | Yawning Angel <yawning@schwanenlied.me> | 2014-05-12 01:30:21 +0000 |
---|---|---|
committer | Yawning Angel <yawning@schwanenlied.me> | 2014-05-12 01:30:21 +0000 |
commit | cca49e01a387eddfab8160cfa5861816d3f6815a (patch) | |
tree | 087c37aa962f04003ad21b820bb741cba952e115 | |
parent | 9b6b3f825b47a5912ce03f85ab49da95323a1d7d (diff) |
Set a timeout on outgoing handshakes as well.
-rw-r--r-- | obfs4.go | 29 |
1 files changed, 13 insertions, 16 deletions
@@ -109,12 +109,16 @@ func (c *Obfs4Conn) clientHandshake(nodeID *ntor.NodeID, publicKey *ntor.PublicK if err != nil { return err } - _, err = c.conn.Write(blob) + + err = c.conn.SetDeadline(time.Now().Add(connectionTimeout * 2)) if err != nil { return err } - // XXX: Set the response timer. + _, err = c.conn.Write(blob) + if err != nil { + return err + } // Consume the server handshake. hsBuf := make([]byte, serverMaxHandshakeLength) @@ -133,12 +137,16 @@ func (c *Obfs4Conn) clientHandshake(nodeID *ntor.NodeID, publicKey *ntor.PublicK } _ = c.receiveBuffer.Next(n) + err = c.conn.SetDeadline(time.Time{}) + if err != nil { + return err + } + // Use the derived key material to intialize the link crypto. okm := ntor.Kdf(seed, framing.KeyLength*2) c.encoder = framing.NewEncoder(okm[:framing.KeyLength]) c.decoder = framing.NewDecoder(okm[framing.KeyLength:]) - // XXX: Kill the response timer. c.isOk = true return nil @@ -151,7 +159,7 @@ func (c *Obfs4Conn) serverHandshake(nodeID *ntor.NodeID, keypair *ntor.Keypair) } hs := newServerHandshake(nodeID, keypair) - err := c.conn.SetReadDeadline(time.Now().Add(connectionTimeout)) + err := c.conn.SetDeadline(time.Now().Add(connectionTimeout)) if err != nil { return err } @@ -172,10 +180,6 @@ func (c *Obfs4Conn) serverHandshake(nodeID *ntor.NodeID, keypair *ntor.Keypair) return err } c.receiveBuffer.Reset() - err = c.conn.SetReadDeadline(time.Time{}) - if err != nil { - return err - } // Use the derived key material to intialize the link crypto. okm := ntor.Kdf(seed, framing.KeyLength*2) @@ -185,12 +189,6 @@ func (c *Obfs4Conn) serverHandshake(nodeID *ntor.NodeID, keypair *ntor.Keypair) break } - // Ensure that writing the response completes quickly. - err = c.conn.SetWriteDeadline(time.Now().Add(connectionTimeout)) - if err != nil { - return err - } - // Generate/send the response. blob, err := hs.generateHandshake() if err != nil { @@ -203,8 +201,7 @@ func (c *Obfs4Conn) serverHandshake(nodeID *ntor.NodeID, keypair *ntor.Keypair) // TODO: Generate/send the PRNG seed. - // Disarm the write timer. - err = c.conn.SetWriteDeadline(time.Time{}) + err = c.conn.SetDeadline(time.Time{}) if err != nil { return err } |