js/clients/SparkCore.js
function (data) {
        var msg = messages.unwrap(data);
        if (!msg) {
            logger.error("routeMessage got a NULL coap message ", { coreID: this.getHexCoreID() });
            return;
        }

        this._lastMessageTime = new Date();

        //should be adequate
        var msgCode = msg.getCode();
        if ((msgCode > Message.Code.EMPTY) && (msgCode <= Message.Code.DELETE)) {
            //probably a request
            msg._type = messages.getRequestType(msg);
        }

        if (!msg._type) {
            msg._type = this.getResponseType(msg.getTokenString());
        }

        //console.log("core got message of type " + msg._type + " with token " + msg.getTokenString() + " " + messages.getRequestType(msg));

        if (msg.isAcknowledgement()) {
            if (!msg._type) {
                //no type, can't route it.
                msg._type = 'PingAck';
            }
            this.emit(('msg_' + msg._type).toLowerCase(), msg);
            return;
        }


        var nextPeerCounter = ++this.recvCounter;
        if (nextPeerCounter > 65535) {
            //TODO: clean me up! (I need settings, and maybe belong elsewhere)
            this.recvCounter = nextPeerCounter = 0;
        }

        if (msg.isEmpty() && msg.isConfirmable()) {
            this._lastCorePing = new Date();
            //var delta = (this._lastCorePing - this._connStartTime) / 1000.0;
            //logger.log("core ping @ ", delta, " seconds ", { coreID: this.getHexCoreID() });
            this.sendReply("PingAck", msg.getId());
            return;
        }

        if (!msg || (msg.getId() != nextPeerCounter)) {
            logger.log("got counter ", msg.getId(), " expecting ", nextPeerCounter, { coreID: this.getHexCoreID() });

            if (msg._type == "Ignored") {
                //don't ignore an ignore...
                this.disconnect("Got an Ignore");
                return;
            }

            //this.sendMessage("Ignored", null, {}, null, null);
            this.disconnect("Bad Counter");
            return;
        }

        this.emit(('msg_' + msg._type).toLowerCase(), msg);
    }
function (data) {
        var msg = messages.unwrap(data);
        if (!msg) {
            logger.error("routeMessage got a NULL coap message ", { coreID: this.getHexCoreID() });
            return;
        }

        this._lastMessageTime = new Date();

        //should be adequate
        var msgCode = msg.getCode();
        if ((msgCode > Message.Code.EMPTY) && (msgCode <= Message.Code.DELETE)) {
            //probably a request
            msg._type = messages.getRequestType(msg);
        }

        if (!msg._type) {
            msg._type = this.getResponseType(msg.getTokenString());
        }

        //console.log("core got message of type " + msg._type + " with token " + msg.getTokenString() + " " + messages.getRequestType(msg));

        if (msg.isAcknowledgement()) {
            if (!msg._type) {
                //no type, can't route it.
                msg._type = 'PingAck';
            }
            this.emit(('msg_' + msg._type).toLowerCase(), msg);
            return;
        }


        var nextPeerCounter = ++this.recvCounter;
        if (nextPeerCounter > 65535) {
            //TODO: clean me up! (I need settings, and maybe belong elsewhere)
            this.recvCounter = nextPeerCounter = 0;
        }

        if (msg.isEmpty() && msg.isConfirmable()) {
            this._lastCorePing = new Date();
            //var delta = (this._lastCorePing - this._connStartTime) / 1000.0;
            //logger.log("core ping @ ", delta, " seconds ", { coreID: this.getHexCoreID() });
            this.sendReply("PingAck", msg.getId());
            return;
        }

        if (!msg || (msg.getId() != nextPeerCounter)) {
            logger.log("got counter ", msg.getId(), " expecting ", nextPeerCounter, { coreID: this.getHexCoreID() });

            if (msg._type == "Ignored") {
                //don't ignore an ignore...
                this.disconnect("Got an Ignore");
                return;
            }

            //this.sendMessage("Ignored", null, {}, null, null);
            this.disconnect("Bad Counter");
            return;
        }

        this.emit(('msg_' + msg._type).toLowerCase(), msg);
    }
function ( data ) { var msg = messages . unwrap ( data ) ; if ( ! msg ) { logger . error ( "routeMessage got a NULL coap message " , { coreID : this . getHexCoreID ( ) } ) ; return ; } this . _lastMessageTime = new Date ( ) ; //should be adequate var msgCode = msg . getCode ( ) ; if ( ( msgCode > Message . Code . EMPTY ) && ( msgCode <= Message . Code . DELETE ) ) { //probably a request msg . _type = messages . getRequestType ( msg ) ; } if ( ! msg . _type ) { msg . _type = this . getResponseType ( msg . getTokenString ( ) ) ; } //console.log("core got message of type " + msg._type + " with token " + msg.getTokenString() + " " + messages.getRequestType(msg)); if ( msg . isAcknowledgement ( ) ) { if ( ! msg . _type ) { //no type, can't route it. msg . _type = 'PingAck' ; } this . emit ( ( 'msg_' + msg . _type ) . toLowerCase ( ) , msg ) ; return ; } var nextPeerCounter = ++ this . recvCounter ; if ( nextPeerCounter > 65535 ) { //TODO: clean me up! (I need settings, and maybe belong elsewhere) this . recvCounter = nextPeerCounter = 0 ; } if ( msg . isEmpty ( ) && msg . isConfirmable ( ) ) { this . _lastCorePing = new Date ( ) ; //var delta = (this._lastCorePing - this._connStartTime) / 1000.0; //logger.log("core ping @ ", delta, " seconds ", { coreID: this.getHexCoreID() }); this . sendReply ( "PingAck" , msg . getId ( ) ) ; return ; } if ( ! msg || ( msg . getId ( ) != nextPeerCounter ) ) { logger . log ( "got counter " , msg . getId ( ) , " expecting " , nextPeerCounter , { coreID : this . getHexCoreID ( ) } ) ; if ( msg . _type == "Ignored" ) { //don't ignore an ignore... this . disconnect ( "Got an Ignore" ) ; return ; } //this.sendMessage("Ignored", null, {}, null, null); this . disconnect ( "Bad Counter" ) ; return ; } this . emit ( ( 'msg_' + msg . _type ) . toLowerCase ( ) , msg ) ; }
Deals with messages coming from the core over our secure connection
@param data
Deals with messages coming from the core over our secure connection