docs: function Connection(connectPolicy) {
    Connection.super_.call(this);
  
    var options = connectPolicy.options;
    u.assertArguments(options, ['containerId', 'hostname']);
    this.policy = connectPolicy;
    this._transport = null;
    this.connected = false;
    this.connectedTo = null;
    this._buffer = new BufferList();
    this._heartbeatInterval = undefined;
  
    this.local = { open: new frames.OpenFrame(options) };
    this.remote = {};
  
    this._sslOptions = null;
    if (options.sslOptions) {
      this._sslOptions = options.sslOptions;
  
      if (options.sslOptions.keyFile) {
        this._sslOptions.key = fs.readFileSync(options.sslOptions.keyFile);
        delete this._sslOptions.keyFile;
      }
      if (options.sslOptions.certFile) {
        this._sslOptions.cert = fs.readFileSync(options.sslOptions.certFile);
        delete this._sslOptions.certFile;
      }
      if (options.sslOptions.caFile) {
        this._sslOptions.ca = fs.readFileSync(options.sslOptions.caFile);
        delete this._sslOptions.caFile;
      }
    }
  
    this._lastOutgoing = null; // To track whether heartbeat frame required.
    this._receivedHeader = false;
    this._sessions = {};
    var self = this;
    var stateMachine = {
      'DISCONNECTED': {
        connect: function(address, sasl) {
          self._connect(address, sasl);
          return this.START;
        }
      },
      'START': {
        connected: function(sasl) {
          if (sasl) {
            self.sasl = sasl;
            self.sasl.negotiate(self, self.address, function(e) { self._saslComplete(e); });
            return this.IN_SASL;
          } else {
            self.sendHeader();
            return this.HDR_SENT;
          }
        },
        headerReceived: function() { return this.HDR_RCVD; }
      },
      'IN_SASL': {
        success: function() {
          self.sendHeader();
          return this.HDR_SENT;
        }
      },
      'HDR_RCVD': {
        validVersion: function() {
          self.sendHeader();
          return this.HDR_EXCH;
        },
        invalidVersion: function() {
          self._terminate();
          return this.DISCONNECTING;
        }
      },
      'HDR_SENT': {
        validVersion: function() {
          return this.HDR_EXCH;
        },
        invalidVersion: function() {
          self._terminate();
          return this.DISCONNECTING;
        }
      },
      'HDR_EXCH': {
        sendOpen: function() {
          self._sendOpenFrame();
          return this.OPEN_SENT;
        },
        openReceived: function() {
          return this.OPEN_RCVD;
        }
      },
      'OPEN_RCVD': {
        sendOpen: function() {
          self._sendOpenFrame();
          return this.OPENED;
        }
      },
      'OPEN_SENT': {
        openReceived: function() {
          return this.OPENED;
        },
        sendClose: function() {
          self._terminate();
          return this.DISCONNECTED;
        }
      },
      'OPENED': {
        closeReceived: function() {
          return this.CLOSE_RCVD;
        },
        invalidOptions: function() {
          self._sendCloseFrame(ErrorCondition.ConnectionForced, 'Invalid options');
          return this.CLOSE_SENT;
        },
        sendClose: function() {
          self._sendCloseFrame();
          return this.CLOSE_SENT;
        }
      },
      'CLOSE_RCVD': {
        sendClose: function() {
          self._sendCloseFrame();
          self._terminate();
          return this.DISCONNECTED;
        }
      },
      'CLOSE_SENT': {
        closeReceived: function() {
          self._terminate();
          return this.DISCONNECTED;
        },
        disconnect: function() { return this.DISCONNECTED; }
      },
      'DISCONNECTING': {
        disconnected: function() {
          return this.DISCONNECTED;
        }
      }
    };
  
    var errorHandler = function(err) { self._processError(err); return this.DISCONNECTED; };
    var terminationHandler = function() { self._terminate(); return this.DISCONNECTED; };
    Object.keys(stateMachine).forEach(function(state) {
      if (state !== 'DISCONNECTED') {
        stateMachine[state].error = errorHandler;
        stateMachine[state].terminated = terminationHandler;
      }
    });
  
    this.connSM = new StateMachine(stateMachine).bind(function(event, oldState, newState) {
      debug('stateChange:', oldState, '=>', newState, ', reason:', event);
    });
  }