lib/tcp.js
/*
 * carries the key exchange process between the communicating nodes
 * @param connection {Socket}: the socket to between the nodes
 * @return {Promise}: a promise of the shared secret
 */
carries the key exchange process between the communicating nodes
@param connection {Socket}: the socket to between the nodes
@return {Promise}: a promise of the shared secret
carries the key exchange process between the communicating nodes @param connection { Socket } : the socket to between the nodes @return { Promise } : a promise of the shared secret
function exchangeKeyOver(connection) {
    return new Promise(function(resolve, reject) {
        var hostId = connection.path + ":" + connection.port;
        try {
            var dhObj = cs.diffieHellman();
            var sharedPrime = dhObj.prime;
            var publicKey = dhObj.publicKey;
            connection.emit('KEY-EXT:PARAMS', {prime: sharedPrime, key: publicKey});
            connection.on('KEY-EXT:PUBLIC', function(data) {
                if(!data.error) {
                    var sharedSecret = dhObj.computeSecret(data.key);
                    resolve({connection: connection, secret: sharedSecret});
                }
                else {
                    reject(new Error(hostId + " " + data.error));
                }
            });
        }
        catch(error) { reject(new Error(hostId + " " + error.message)); }
    });
}
function exchangeKeyOver ( connection ) { return new Promise ( function ( resolve , reject ) { var hostId = connection . path + ":" + connection . port ; try { var dhObj = cs . diffieHellman ( ) ; var sharedPrime = dhObj . prime ; var publicKey = dhObj . publicKey ; connection . emit ( 'KEY-EXT:PARAMS' , { prime : sharedPrime , key : publicKey } ) ; connection . on ( 'KEY-EXT:PUBLIC' , function ( data ) { if ( ! data . error ) { var sharedSecret = dhObj . computeSecret ( data . key ) ; resolve ( { connection : connection , secret : sharedSecret } ) ; } else { reject ( new Error ( hostId + " " + data . error ) ) ; } } ) ; } catch ( error ) { reject ( new Error ( hostId + " " + error . message ) ) ; } } ) ; }
carries the key exchange process between the communicating nodes
 @param connection {Socket}: the socket to between the nodes
 @return {Promise}: a promise of the shared secret
carries the key exchange process between the communicating nodes @param connection { Socket } : the socket to between the nodes @return { Promise } : a promise of the shared secret