js/lib/Handshake.js
function (data) {
        var that = this;
        if (!data) {
            if (this._socketTimeout) {
                clearTimeout(this._socketTimeout);  //just in case
            }

            //waiting on data.
            //logger.log("server: waiting on hello");
            this._socketTimeout = setTimeout(function () {
                that.handshakeFail("get_hello timed out");
            }, 30 * 1000);

            return;
        }
        clearTimeout(this._socketTimeout);

        var env = this.client.parseMessage(data);
        var msg = (env && env.hello) ? env.hello : env;
        if (!msg) {
            this.handshakeFail("failed to parse hello");
            return;
        }
        this.client.recvCounter = msg.getId();
        //logger.log("server: got a good hello! Counter was: " + msg.getId());

        try {
            if (msg.getPayload) {
                var payload = msg.getPayload();
                if (payload.length > 0) {
                    var r = new buffers.BufferReader(payload);
                    this.client.spark_product_id = r.shiftUInt16();
                    this.client.product_firmware_version = r.shiftUInt16();
                    //logger.log('version of core firmware is ', this.client.spark_product_id, this.client.product_firmware_version);
                }
            }
            else {
                logger.log('msg object had no getPayload fn');
            }
        }
        catch (ex) {
            logger.log('error while parsing hello payload ', ex);
        }

//        //remind ourselves later that this key worked.
//        if (that.corePublicKeyWasUncertain) {
//            process.nextTick(function () {
//                try {
//					//set preferred key for device
//					//that.coreFullPublicKeyObject
//                }
//                catch (ex) {
//                    logger.error("error marking key as valid " + ex);
//                }
//            });
//        }


        this.stage++;
        this.nextStep();
    }
function (data) {
        var that = this;
        if (!data) {
            if (this._socketTimeout) {
                clearTimeout(this._socketTimeout);  //just in case
            }

            //waiting on data.
            //logger.log("server: waiting on hello");
            this._socketTimeout = setTimeout(function () {
                that.handshakeFail("get_hello timed out");
            }, 30 * 1000);

            return;
        }
        clearTimeout(this._socketTimeout);

        var env = this.client.parseMessage(data);
        var msg = (env && env.hello) ? env.hello : env;
        if (!msg) {
            this.handshakeFail("failed to parse hello");
            return;
        }
        this.client.recvCounter = msg.getId();
        //logger.log("server: got a good hello! Counter was: " + msg.getId());

        try {
            if (msg.getPayload) {
                var payload = msg.getPayload();
                if (payload.length > 0) {
                    var r = new buffers.BufferReader(payload);
                    this.client.spark_product_id = r.shiftUInt16();
                    this.client.product_firmware_version = r.shiftUInt16();
                    //logger.log('version of core firmware is ', this.client.spark_product_id, this.client.product_firmware_version);
                }
            }
            else {
                logger.log('msg object had no getPayload fn');
            }
        }
        catch (ex) {
            logger.log('error while parsing hello payload ', ex);
        }

//        //remind ourselves later that this key worked.
//        if (that.corePublicKeyWasUncertain) {
//            process.nextTick(function () {
//                try {
//					//set preferred key for device
//					//that.coreFullPublicKeyObject
//                }
//                catch (ex) {
//                    logger.error("error marking key as valid " + ex);
//                }
//            });
//        }


        this.stage++;
        this.nextStep();
    }
function ( data ) { var that = this ; if ( ! data ) { if ( this . _socketTimeout ) { clearTimeout ( this . _socketTimeout ) ; //just in case } //waiting on data. //logger.log("server: waiting on hello"); this . _socketTimeout = setTimeout ( function ( ) { that . handshakeFail ( "get_hello timed out" ) ; } , 30 * 1000 ) ; return ; } clearTimeout ( this . _socketTimeout ) ; var env = this . client . parseMessage ( data ) ; var msg = ( env && env . hello ) ? env . hello : env ; if ( ! msg ) { this . handshakeFail ( "failed to parse hello" ) ; return ; } this . client . recvCounter = msg . getId ( ) ; //logger.log("server: got a good hello! Counter was: " + msg.getId()); try { if ( msg . getPayload ) { var payload = msg . getPayload ( ) ; if ( payload . length > 0 ) { var r = new buffers . BufferReader ( payload ) ; this . client . spark_product_id = r . shiftUInt16 ( ) ; this . client . product_firmware_version = r . shiftUInt16 ( ) ; //logger.log('version of core firmware is ', this.client.spark_product_id, this.client.product_firmware_version); } } else { logger . log ( 'msg object had no getPayload fn' ) ; } } catch ( ex ) { logger . log ( 'error while parsing hello payload ' , ex ) ; } //        //remind ourselves later that this key worked. //        if (that.corePublicKeyWasUncertain) { //            process.nextTick(function () { //                try { //					//set preferred key for device //					//that.coreFullPublicKeyObject //                } //                catch (ex) { //                    logger.error("error marking key as valid " + ex); //                } //            }); //        } this . stage ++ ; this . nextStep ( ) ; }
receive a hello from the client, taking note of the counter
receive a hello from the client taking note of the counter